Skip to content

Commit

Permalink
load versions on build
Browse files Browse the repository at this point in the history
  • Loading branch information
rvagg committed Sep 17, 2015
1 parent 0272e0a commit 372fd2e
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 25 deletions.
35 changes: 19 additions & 16 deletions build.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 **/

Expand All @@ -43,18 +43,7 @@ function i18nJSON (lang) {
return finalJSON;
}

const source = {
project: {
versions,
currentVersion: versions[0].version,
banner: {
visible: false,
content: 'Important <a href="#">security release</a>, 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);
Expand Down Expand Up @@ -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 <a href="#">security release</a>, please update now!'
}
}
};

fs.readdir(path.join(__dirname, 'locale'), function (e, locales) {
locales.forEach(function (locale) {
buildlocale(source, locale);
});
});
});
}
Expand Down
37 changes: 28 additions & 9 deletions scripts/load-versions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '';
Expand All @@ -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'
Expand All @@ -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));
})
}

0 comments on commit 372fd2e

Please sign in to comment.