Skip to content
Open
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
12 changes: 12 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,15 @@ sls-sample-app-2.0.3.tgz
loopback-example-app*.tgz
_suite
_onto
intl/MSG.json
intl/de
intl/es
intl/fr
intl/it
intl/ja
intl/ko
intl/pt
intl/ru
intl/zh-Hans
intl/zh-Hant
intl/en/*.json
39 changes: 21 additions & 18 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ var Parser = require('posix-getopt').BasicParser;
var debug = require('debug')('strong-build');
var fmt = require('util').format;
var fs = require('fs');
var g = require('strong-globalize');
var git = require('./lib/git');
var path = require('path');
var pump = require('pump');
Expand All @@ -11,7 +12,7 @@ var vasync = require('vasync');
var zlib = require('zlib');

function printHelp($0, prn) {
var USAGE = fs.readFileSync(require.resolve('./sl-build.txt'), 'utf-8')
var USAGE = g.t('sl-build.txt')
.replace(/%MAIN%/g, $0)
.trim();

Expand All @@ -30,10 +31,10 @@ function runCommand(cmd, callback) {
}

function runWait(cmd, callback) {
console.log('Running `%s`', cmd);
g.log('Running `%s`', cmd);
runCommand(cmd, function(er, output) {
if (er) {
console.error('Error on `%s`:', cmd);
g.error('Error on `%s`:', cmd);
reportRunError(er, output);
return callback(er);
}
Expand All @@ -52,7 +53,7 @@ function runStep(cmd) {
function reportRunError(er, output) {
if (!er) return;

console.error('Failed to run `%s`:', er.message);
g.error('Failed to run `%s`:', er.message);
if (output && output !== '') {
process.stderr.write(output);
}
Expand Down Expand Up @@ -83,6 +84,8 @@ exports.build = function build(argv, callback) {
var pack;
var commit;

g.setRootDir(__dirname);

while ((option = parser.getopt()) !== undefined) {
switch (option.option) {
case 'v':
Expand All @@ -108,7 +111,7 @@ exports.build = function build(argv, callback) {
install = true;
break;
case 'b':
console.error('Warning: the --bundle option now does nothing and ' +
g.error('Warning: the --bundle option now does nothing and ' +
'should not be used');
break;
case 'p':
Expand All @@ -124,15 +127,15 @@ exports.build = function build(argv, callback) {
commit = false;
break;
default:
console.error('Invalid usage (near option \'%s\'), try `%s --help`.',
g.error('Invalid usage (near option \'%s\'), try `{{%s --help}}`.',
option.optopt, $0);
return callback(Error('usage'));
return callback(g.Error('usage'));
}
}

if (parser.optind() !== argv.length) {
console.error('Invalid usage (extra arguments), try `%s --help`.', $0);
return callback(Error('usage'));
g.error('Invalid usage (extra arguments), try `{{%s --help}}`.', $0);
return callback(g.Error('usage'));
}

// With no actions selected, do everything we can (onto requires an argument,
Expand All @@ -149,8 +152,8 @@ exports.build = function build(argv, callback) {
}

if (commit && !git.isGit()) {
console.error('Cannot perform commit on non-git working directory');
return callback(Error('usage'));
g.error('Cannot perform commit on {{non-git}} working directory');
return callback(g.Error('usage'));
}

var steps = [];
Expand Down Expand Up @@ -178,7 +181,7 @@ exports.build = function build(argv, callback) {
try {
git.ensureBranch(onto);
} catch (er) {
console.error('%s', er.message);
g.error('%s', er.message);
return callback(er);
}
return callback();
Expand All @@ -188,13 +191,13 @@ exports.build = function build(argv, callback) {
try {
var info = git.syncBranch(onto);
if (info.srcBranch && info.dstBranch) {
console.log('Merged source tree of `%s` onto `%s`',
g.log('Merged source tree of `%s` onto `%s`',
info.srcBranch, info.dstBranch);
} else {
console.log('Not merging HEAD into `%s`, already up to date.', onto);
g.log('Not merging {{HEAD}} into `%s`, already up to date.', onto);
}
} catch (er) {
console.error('%s', er.message);
g.error('%s', er.message);
return callback(er);
}
return callback();
Expand Down Expand Up @@ -223,17 +226,17 @@ exports.build = function build(argv, callback) {
var tarStream = strongPack(process.cwd());
var dstFile = fs.createWriteStream(dst, 'binary');
var gz = zlib.createGzip();
console.log('Packing application in to %s', dst);
g.log('Packing application in to %s', dst);
pump(tarStream, gz, dstFile, callback);
}

function doGitCommit(_, callback) {
try {
var info = git.commitAll(onto);
if (info.branch) {
console.log('Committed build products onto `%s`', info.branch);
g.log('Committed build products onto `%s`', info.branch);
} else {
console.log('Build products already up to date on `%s`', onto);
g.log('Build products already up to date on `%s`', onto);
}
} catch (er) {
console.error('%s', er.message);
Expand Down
22 changes: 22 additions & 0 deletions intl/en/sl-build.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
usage: {{%MAIN%}} [options]

Build a node application package.

With no options, the default depends on whether a git repository is detected or not.

If a {{git}} repository is detected the default is `{{--git}}`: install and commit the build results to the "{{deploy}}" branch, which will be created if it does not already exist.

If no {{git}} repository is detected the default is `{{--npm}}`: install and pack the build results into a `{{<package-name>-<version>.tgz}}` file.

Options:
{{-h,--help}} Print this message and exit.
{{-v,--version}} Print version and exit.
{{-n,--npm}} Same as `{{--install --pack}}`.
{{-g,--git}} Same as `{{--install --commit}}`.
{{-i,--install}} Install dependencies (without scripts, by default).
{{-s,--scripts}} If installing, run scripts (to build addons).
{{-p,--pack}} Pack into a publishable archive.

Git specific options:
{{-c,--commit}} Commit build output (branch specified by {{--onto}}).
{{--onto BRANCH}} Branch to commit build results to, created if necessary ("{{deploy}}", by default).
21 changes: 11 additions & 10 deletions lib/git.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ var debug = require('debug')('strong-build');
var lodash = require('lodash');
var path = require('path');
var shell = require('shelljs');
var g = require('strong-globalize');

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please keep requires alphabetized

var util = require('util');

function fmt() {
Expand All @@ -22,11 +23,11 @@ function execSync(cmd, error, noOutput) {

if (exec.code !== 0) {
var output = exec.output.replace('fatal: ', '');
console.log('Error on `%s`:\n %s', cmd, output);
g.log('Error on `%s`:\n %s', cmd, output);
throw Error(error);
}

console.log('Running `%s`', cmd);
g.log('Running `%s`', cmd);

// git on success may still write messages to stderr, and shelljs combines
// stdout and stderr (sucky). This effect commit-tree, for example, when dest
Expand Down Expand Up @@ -81,7 +82,7 @@ exports.ensureBranch = function ensureBranch(name) {
if (!info.ref)
execSync(
fmt('git branch "%s"', name),
fmt('Failed to create branch "%s"', name)
g.t('Failed to create branch "%s"', name)
);
};

Expand All @@ -102,7 +103,7 @@ exports.syncBranch = function gitSyncBranch(gitDstBranch) {

var gitSrcTreeSha = execSync(
'git log -1 --pretty=format:"%t" HEAD',
'Failed to parse branch `HEAD`, is this a git repository?'
g.t('Failed to parse branch `{{HEAD}}`, is this a git repository?')
);

// Commit the source tree to the head of the destination branch, and update
Expand All @@ -111,12 +112,12 @@ exports.syncBranch = function gitSyncBranch(gitDstBranch) {
var commitSha = execSync(
fmt('git commit-tree -p "%s" -p "%s" -m "%s" %s',
dst.ref, src.ref, message, gitSrcTreeSha),
fmt('Failed to commit `%s` onto `%s`', src.ref, gitDstBranch)
g.t('Failed to commit `%s` onto `%s`', src.ref, gitDstBranch)
);

execSync(
fmt('git update-ref "%s" %s', dst.ref, commitSha),
fmt('Failed to merge `%s` onto `%s`', src.ref, gitDstBranch)
g.t('Failed to merge `%s` onto `%s`', src.ref, gitDstBranch)
);

return {
Expand All @@ -130,17 +131,17 @@ exports.syncBranch = function gitSyncBranch(gitDstBranch) {
exports.commitAll = function gitCommitAll(gitDstBranch) {
execSync(
fmt('git add --force --all .'),
fmt('Failed to add build products')
g.t('Failed to add build products')
);
var treeSha = execSync(
fmt('git write-tree'),
fmt('Failed to stage build products for commit')
g.t('Failed to stage build products for commit')
);
var dst = resolveBranch(gitDstBranch);
var commitSha = execSync(
fmt('git commit-tree -p "%s" -m "Commit build products" %s',
dst.ref, treeSha),
fmt('Failed to create build products commit for `%s`', gitDstBranch),
g.t('Failed to create build products commit for `%s`', gitDstBranch),
true
);

Expand All @@ -151,7 +152,7 @@ exports.commitAll = function gitCommitAll(gitDstBranch) {

execSync(
fmt('git update-ref "%s" %s', dst.ref, commitSha),
fmt('Failed to commit build products to `%s`', gitDstBranch)
g.t('Failed to commit build products to `%s`', gitDstBranch)
);

return {
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@
"sl-build": "./bin/sl-build.js"
},
"dependencies": {
"cldr-data": "^28.0.3",
"debug": "^2.0.0",
"lodash": "^3.8.0",
"posix-getopt": "^1.0.0",
"pump": "^1.0.1",
"shelljs": "^0.4.0",
"strong-globalize": "^1.0.0",
"strong-pack": "^1.0.0",
"vasync": "^1.4.3"
},
Expand Down
27 changes: 0 additions & 27 deletions sl-build.txt

This file was deleted.

1 change: 1 addition & 0 deletions test/build-example.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ module.exports = function buildExample(fixture, args, callback) {
}
});

sh.cd(__dirname);
sh.rm('-rf', '_suite');
sh.cp('-Rf', fmt('fixtures/%s/*', fixture), '_suite');
sh.cd('_suite');
Expand Down
6 changes: 5 additions & 1 deletion test/test-build-install-nodeps.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,9 @@ var test = require('shelljs').test;
require('./build-example')('zero-dependency', ['-i'], function(er) {
debug('built with error?', er);
assert.ifError(er);
assert(!test('-d', 'node_modules'), 'no node_modules created');
if (process.versions.node.split('.')[0] === '5') {
assert(test('-d', 'node_modules'), 'node_modules created');
} else {
assert(!test('-d', 'node_modules'), 'no node_modules created');
}
});