diff --git a/scripts/release-post.js b/scripts/release-post.js new file mode 100755 index 0000000000000..87abeb230ad40 --- /dev/null +++ b/scripts/release-post.js @@ -0,0 +1,110 @@ +#!/usr/bin/env node + +'use strict'; + +const https = require('https'); +const fs = require('fs'); +const path = require('path'); +const extend = require('util')._extend; +const Handlebars = require('handlebars'); + +function download (url, cb) { + return new Promise(function (resolve, reject) { + let data = ''; + https.get(url, function (res) { + if (res.statusCode !== 200) { + return reject(new Error('Invalid status code (!= 200) while retrieving '+ url +': '+ res.statusCode)); + } + + res.on('data', function (chunk) { data += chunk; }); + res.on('end', function () { resolve(data); }); + }).on('error', function (err) { + reject(new Error('Error downloading file from %s: %s', url, err.message)); + }); + }); +} + +// matches a complete release section, support both old node and iojs releases: +// ## 2015-07-09, Version 0.12.7 (Stable) +// ## 2015-08-04, Version 3.0.0, @rvagg +const rxReleaseSection = /## \d{4}-\d{2}-\d{2}, Version ([^,( ]+)[\s\S]*?(?=## \d{4})/g; + +function findLatestVersion (cb) { + return download('https://nodejs.org/dist/index.json') + .then(JSON.parse) + .then(function (versions) { + return versions[0].version.substr(1); + }); +} + +function fetchDocs (version) { + return Promise.all([ fetchChangelog(version), fetchShasums(version) ]).then(function (results) { + const changelog = results[0]; + const shasums = results[1]; + + return { + version, + changelog, + shasums + }; + }); +} + +function fetchChangelog (version) { + return download('https://raw.githubusercontent.com/nodejs/node/master/CHANGELOG.md') + .then(function (data) { + let matches; + + while (matches = rxReleaseSection.exec(data)) { + const releaseVersion = matches[1]; + if (releaseVersion === version) { + return matches[0]; + } + } + + return Promise.reject(new Error('Couldnt find matching changelog for ' + version)); + }); +} + +function fetchShasums (version) { + return download(`https://nodejs.org/dist/v${version}/SHASUMS256.txt.asc`); +} + +function renderPost (results) { + const templateStr = fs.readFileSync(path.resolve(__dirname, 'release.hbs')).toString('utf8'); + const template = Handlebars.compile(templateStr, { noEscape: true }); + const view = extend({ + date: new Date().toISOString(), + versionSlug: slugify(results.version) + }, results); + + return extend({ + content: template(view) + }, results); +} + +function writeToFile (results) { + const filepath = path.resolve(__dirname, '..', 'locale', 'en', 'blog', 'release', `v${results.version}.md`); + + if (fs.existsSync(filepath)) { + return Promise.reject(new Error(`Release post for ${results.version} already exists!`)); + } + + fs.writeFileSync(filepath, results.content); + return Promise.resolve(filepath); +} + +function slugify (str) { + return str.replace(/\./g, '-'); +} + +findLatestVersion() + .then(fetchDocs) + .then(renderPost) + .then(writeToFile) + .then(function (filepath) { + console.log('Release post created:', filepath); + }, function (err) { + console.error('Some error occured here!', err.stack); + process.exit(1); + }); diff --git a/scripts/release.hbs b/scripts/release.hbs new file mode 100644 index 0000000000000..0cbf22777a59e --- /dev/null +++ b/scripts/release.hbs @@ -0,0 +1,49 @@ +--- +date: {{date}} +version: {{version}} +category: release +title: Node v{{version}} (Stable) +slug: node-v{{versionSlug}}-stable +layout: blog-post.hbs +--- + +{{changelog}} + +Windows 32-bit Installer: http://nodejs.org/dist/v{{version}}/node-v{{version}}-x86.msi + +Windows 64-bit Installer: http://nodejs.org/dist/v{{version}}/node-v{{version}}-x64.msi + +Windows 32-bit Binary: http://nodejs.org/dist/v{{version}}/win-x86/node.exe + +Windows 64-bit Binary: http://nodejs.org/dist/v{{version}}/win-x64/node.exe + +Mac OS X 64-bit Installer: http://nodejs.org/dist/v{{version}}/node-v{{version}}.pkg + +Mac OS X 64-bit Binary: http://nodejs.org/dist/v{{version}}/node-v{{version}}-darwin-x64.tar.gz + +Linux 32-bit Binary: http://nodejs.org/dist/v{{version}}/node-v{{version}}-linux-x86.tar.gz + +Linux 64-bit Binary: http://nodejs.org/dist/v{{version}}/node-v{{version}}-linux-x64.tar.gz + +SunOS 32-bit Binary: http://nodejs.org/dist/v{{version}}/node-v{{version}}-sunos-x86.tar.gz + +SunOS 64-bit Binary: http://nodejs.org/dist/v{{version}}/node-v{{version}}-sunos-x64.tar.gz + +ARMv6 32-bit Binary: http://nodejs.org/dist/v{{version}}/node-v{{version}}-linux-armv6l.tar.gz + +ARMv7 32-bit Binary: http://nodejs.org/dist/v{{version}}/node-v{{version}}-linux-armv7l.tar.gz + +ARMv8 64-bit Binary: http://nodejs.org/dist/v{{version}}/node-v{{version}}-linux-arm64.tar.gz + +Source Code: http://nodejs.org/dist/v{{version}}/node-v{{version}}.tar.gz + +Other release files: http://nodejs.org/dist/v{{version}}/ + +Website: http://nodejs.org/docs/v{{version}}/ + +Documentation: http://nodejs.org/docs/v{{version}}/api/ + +Shasums: +``` +{{shasums}} +```