Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

load versions on build #167

Merged
merged 1 commit into from
Sep 17, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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));
})
}