Skip to content

Commit fd14e76

Browse files
committed
Merge branch 'build-release-posts' into node-4.0-release
2 parents d1cb4c1 + aaa6aff commit fd14e76

File tree

2 files changed

+159
-0
lines changed

2 files changed

+159
-0
lines changed

scripts/release-post.js

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
#!/usr/bin/env node
2+
3+
'use strict';
4+
5+
const https = require('https');
6+
const fs = require('fs');
7+
const path = require('path');
8+
const extend = require('util')._extend;
9+
const Handlebars = require('handlebars');
10+
11+
function download (url, cb) {
12+
return new Promise(function (resolve, reject) {
13+
let data = '';
14+
https.get(url, function (res) {
15+
if (res.statusCode !== 200) {
16+
return reject(new Error('Invalid status code (!= 200) while retrieving '+ url +': '+ res.statusCode));
17+
}
18+
19+
res.on('data', function (chunk) { data += chunk; });
20+
res.on('end', function () { resolve(data); });
21+
}).on('error', function (err) {
22+
reject(new Error('Error downloading file from %s: %s', url, err.message));
23+
});
24+
});
25+
}
26+
27+
// matches a complete release section, support both old node and iojs releases:
28+
// ## 2015-07-09, Version 0.12.7 (Stable)
29+
// ## 2015-08-04, Version 3.0.0, @rvagg
30+
const rxReleaseSection = /## \d{4}-\d{2}-\d{2}, Version ([^,( ]+)[\s\S]*?(?=## \d{4})/g;
31+
32+
function findLatestVersion (cb) {
33+
return download('https://nodejs.org/dist/index.json')
34+
.then(JSON.parse)
35+
.then(function (versions) {
36+
return versions[0].version.substr(1);
37+
});
38+
}
39+
40+
function fetchDocs (version) {
41+
return Promise.all([ fetchChangelog(version), fetchShasums(version) ]).then(function (results) {
42+
const changelog = results[0];
43+
const shasums = results[1];
44+
45+
return {
46+
version,
47+
changelog,
48+
shasums
49+
};
50+
});
51+
}
52+
53+
function fetchChangelog (version) {
54+
return download('https://raw.githubusercontent.com/nodejs/node/master/CHANGELOG.md')
55+
.then(function (data) {
56+
let matches;
57+
58+
while (matches = rxReleaseSection.exec(data)) {
59+
const releaseVersion = matches[1];
60+
if (releaseVersion === version) {
61+
return matches[0];
62+
}
63+
}
64+
65+
return Promise.reject(new Error('Couldnt find matching changelog for ' + version));
66+
});
67+
}
68+
69+
function fetchShasums (version) {
70+
return download(`https://nodejs.org/dist/v${version}/SHASUMS256.txt.asc`);
71+
}
72+
73+
function renderPost (results) {
74+
const templateStr = fs.readFileSync(path.resolve(__dirname, 'release.hbs')).toString('utf8');
75+
const template = Handlebars.compile(templateStr, { noEscape: true });
76+
const view = extend({
77+
date: new Date().toISOString(),
78+
versionSlug: slugify(results.version)
79+
}, results);
80+
81+
return extend({
82+
content: template(view)
83+
}, results);
84+
}
85+
86+
function writeToFile (results) {
87+
const filepath = path.resolve(__dirname, '..', 'locale', 'en', 'blog', 'release', `v${results.version}.md`);
88+
89+
if (fs.existsSync(filepath)) {
90+
return Promise.reject(new Error(`Release post for ${results.version} already exists!`));
91+
}
92+
93+
fs.writeFileSync(filepath, results.content);
94+
return Promise.resolve(filepath);
95+
}
96+
97+
function slugify (str) {
98+
return str.replace(/\./g, '-');
99+
}
100+
101+
findLatestVersion()
102+
.then(fetchDocs)
103+
.then(renderPost)
104+
.then(writeToFile)
105+
.then(function (filepath) {
106+
console.log('Release post created:', filepath);
107+
}, function (err) {
108+
console.error('Some error occured here!', err.stack);
109+
process.exit(1);
110+
});

scripts/release.hbs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
---
2+
date: {{date}}
3+
version: {{version}}
4+
category: release
5+
title: Node v{{version}} (Stable)
6+
slug: node-v{{versionSlug}}-stable
7+
layout: blog-post.hbs
8+
---
9+
10+
{{changelog}}
11+
12+
Windows 32-bit Installer: http://nodejs.org/dist/v{{version}}/node-v{{version}}-x86.msi
13+
14+
Windows 64-bit Installer: http://nodejs.org/dist/v{{version}}/node-v{{version}}-x64.msi
15+
16+
Windows 32-bit Binary: http://nodejs.org/dist/v{{version}}/win-x86/node.exe
17+
18+
Windows 64-bit Binary: http://nodejs.org/dist/v{{version}}/win-x64/node.exe
19+
20+
Mac OS X 64-bit Installer: http://nodejs.org/dist/v{{version}}/node-v{{version}}.pkg
21+
22+
Mac OS X 64-bit Binary: http://nodejs.org/dist/v{{version}}/node-v{{version}}-darwin-x64.tar.gz
23+
24+
Linux 32-bit Binary: http://nodejs.org/dist/v{{version}}/node-v{{version}}-linux-x86.tar.gz
25+
26+
Linux 64-bit Binary: http://nodejs.org/dist/v{{version}}/node-v{{version}}-linux-x64.tar.gz
27+
28+
SunOS 32-bit Binary: http://nodejs.org/dist/v{{version}}/node-v{{version}}-sunos-x86.tar.gz
29+
30+
SunOS 64-bit Binary: http://nodejs.org/dist/v{{version}}/node-v{{version}}-sunos-x64.tar.gz
31+
32+
ARMv6 32-bit Binary: http://nodejs.org/dist/v{{version}}/node-v{{version}}-linux-armv6l.tar.gz
33+
34+
ARMv7 32-bit Binary: http://nodejs.org/dist/v{{version}}/node-v{{version}}-linux-armv7l.tar.gz
35+
36+
ARMv8 64-bit Binary: http://nodejs.org/dist/v{{version}}/node-v{{version}}-linux-arm64.tar.gz
37+
38+
Source Code: http://nodejs.org/dist/v{{version}}/node-v{{version}}.tar.gz
39+
40+
Other release files: http://nodejs.org/dist/v{{version}}/
41+
42+
Website: http://nodejs.org/docs/v{{version}}/
43+
44+
Documentation: http://nodejs.org/docs/v{{version}}/api/
45+
46+
Shasums:
47+
```
48+
{{shasums}}
49+
```

0 commit comments

Comments
 (0)