From 67b55610b73af28f1676b20913b084a51404b63c Mon Sep 17 00:00:00 2001 From: Igor Klopov Date: Thu, 7 Jul 2016 19:30:49 +0300 Subject: [PATCH] make a binary of `now` using enclosejs (#81) * make a binary of `now` using enclosejs * pin enclosejs version --- bin/now | 7 ++++++- enclose.js | 5 +++++ gulpfile.babel.js | 9 +++++++++ package.json | 4 +++- 4 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 enclose.js diff --git a/bin/now b/bin/now index e723245..f160437 100755 --- a/bin/now +++ b/bin/now @@ -39,7 +39,12 @@ if (commands.has(cmd)) { args = args.concat(process.argv.slice(2)); } -const bin = resolve(__dirname, 'now-' + cmd); +let bin = resolve(__dirname, 'now-' + cmd); +if (process.enclose) { + args.unshift("--entrypoint", bin); + bin = process.execPath; +} + const proc = spawn(bin, args, { stdio: 'inherit', customFds: [0, 1, 2] }); proc.on('close', (code) => exit(code)); proc.on('error', () => exit(1)); diff --git a/enclose.js b/enclose.js new file mode 100644 index 0000000..13bfb8f --- /dev/null +++ b/enclose.js @@ -0,0 +1,5 @@ +module.exports = { + scripts: [ + "build/bin/now-*" + ] +}; diff --git a/gulpfile.babel.js b/gulpfile.babel.js index d39cb28..bb3e7f8 100644 --- a/gulpfile.babel.js +++ b/gulpfile.babel.js @@ -3,6 +3,7 @@ import del from 'del'; import babel from 'gulp-babel'; import uglify from 'gulp-uglify'; import help from 'gulp-task-listing'; +import { exec as enclose } from 'enclose'; gulp.task('help', help); @@ -23,6 +24,14 @@ gulp.task('compile-bin', () => .pipe(uglify()) .pipe(gulp.dest('build/bin'))); +gulp.task('enclose', ['compile'], (cb) => { + enclose([ + 'build/bin/now', + '-c', 'enclose.js', + '-o', 'build/now' + ], cb); +}); + gulp.task('watch-lib', () => gulp.watch('lib/*.js', ['compile-lib'])); gulp.task('watch-bin', () => gulp.watch('bin/*', ['compile-bin'])); gulp.task('clean', () => del(['build'])); diff --git a/package.json b/package.json index 179073f..5f64116 100644 --- a/package.json +++ b/package.json @@ -83,6 +83,7 @@ "babel-preset-es2015": "6.9.0", "babel-register": "6.9.0", "del": "2.2.0", + "enclose": "2.1.0", "eslint": "2.12.0", "eslint-config-standard": "5.3.1", "eslint-plugin-promise": "1.3.2", @@ -97,7 +98,8 @@ "scripts": { "start": "gulp", "test": "ava", - "prepublish": "gulp compile" + "prepublish": "gulp compile", + "enclose": "gulp enclose" }, "ava": { "failFast": true,