diff --git a/build.js b/build.js
index 55311376df5aa..a6f9f26403e25 100755
--- a/build.js
+++ b/build.js
@@ -17,7 +17,7 @@ const ncp = require('ncp');
const filterStylusPartials = require('./scripts/plugins/filter-stylus-partials');
const mapHandlebarsPartials = require('./scripts/plugins/map-handlebars-partials');
-const versions = require('./source/versions');
+const loadVersions = require('./scripts/load-versions')
/** Build **/
@@ -43,18 +43,7 @@ function i18nJSON (lang) {
return finalJSON;
}
-const source = {
- project: {
- versions,
- currentVersion: versions[0].version,
- banner: {
- visible: false,
- content: 'Important security release, please update now!'
- }
- }
-};
-
-function buildlocale (locale) {
+function buildlocale (source, locale) {
console.time('[metalsmith] build/' + locale + ' finished');
const siteJSON = path.join(__dirname, 'locale', locale, 'site.json');
const metalsmith = Metalsmith(__dirname);
@@ -177,9 +166,23 @@ function copystatic () {
function fullbuild () {
copystatic();
- fs.readdir(path.join(__dirname, 'locale'), function (e, locales) {
- locales.forEach(function (locale) {
- buildlocale(locale);
+ loadVersions(function (err, versions) {
+ if (err) { throw err; }
+ const source = {
+ project: {
+ versions,
+ currentVersion: versions[0].version,
+ banner: {
+ visible: false,
+ content: 'Important security release, please update now!'
+ }
+ }
+ };
+
+ fs.readdir(path.join(__dirname, 'locale'), function (e, locales) {
+ locales.forEach(function (locale) {
+ buildlocale(source, locale);
+ });
});
});
}
diff --git a/scripts/load-versions.js b/scripts/load-versions.js
index d907967c0e0d7..4bc801d2eccb5 100755
--- a/scripts/load-versions.js
+++ b/scripts/load-versions.js
@@ -7,7 +7,18 @@ const semver = require('semver');
const map = require('map-async');
const https = require('https');
-map([ 'https://nodejs.org/dist/index.json', 'https://iojs.org/dist/index.json' ], download, munge);
+function loadVersions (callback) {
+ map(
+ [ 'https://nodejs.org/dist/index.json', 'https://iojs.org/dist/index.json' ],
+ download,
+ function (err, versions) {
+ if (err)
+ return callback(err);
+ versions = munge(versions);
+ callback(null, versions);
+ }
+ );
+}
function download (url, cb) {
let data = '';
@@ -26,13 +37,7 @@ function download (url, cb) {
});
}
-function munge (err, versions) {
- if (err) {
- console.error('Aborting due to download error from node or iojs');
- console.error(err.stack)
- return process.exit(1);
- }
-
+function munge (versions) {
versions[0].forEach(function (v) {
v.url = 'https://nodejs.org/dist/' + v.version + '/'
v.name = 'Node.js'
@@ -48,5 +53,19 @@ function munge (err, versions) {
return semver.compare(b.version, a.version);
});
- fs.writeFileSync(__dirname + '/../source/versions.json', JSON.stringify(allVersions, null, 2));
+ return allVersions;
}
+
+module.exports = loadVersions;
+
+if (require.main === module) {
+ loadVersions(function (err, versions) {
+ if (err) {
+ console.error('Aborting due to download error from node or iojs');
+ console.error(err.stack);
+ return process.exit(1);
+ }
+
+ fs.writeFileSync(__dirname + '/../source/versions.json', JSON.stringify(versions, null, 2));
+ })
+}
\ No newline at end of file