diff --git a/lib/artifacts.js b/lib/artifacts.js deleted file mode 100644 index 0ab3bc9..0000000 --- a/lib/artifacts.js +++ /dev/null @@ -1,99 +0,0 @@ -'use strict'; - -Object.defineProperty(exports, "__esModule", { - value: true -}); - -var _path = require('path'); - -var _fs = require('fs'); - -var _util = require('./util'); - -var _bluebird = require('bluebird'); - -var _mkdirp = require('mkdirp'); - -var _mkdirp2 = _interopRequireDefault(_mkdirp); - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } - -function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; } - -const mkdirpAsync = (0, _bluebird.promisify)(_mkdirp2.default); -const statAsync = (0, _bluebird.promisify)(_fs.stat); -const unlinkAsync = (0, _bluebird.promisify)(_fs.unlink); -const readdirAsync = (0, _bluebird.promisify)(_fs.readdir); - -function readDirAsync(dir) { - return readdirAsync(dir).map(file => { - const path = (0, _path.join)(dir, file); - return statAsync(path).then(s => s.isDirectory() ? readDirAsync(path) : path); - }).reduce((a, b) => a.concat(b), []); -} - -function maybeReadFileContents(file) { - return (0, _util.readFileAsync)(file, 'utf-8').catch(e => { - if (e.code === 'ENOENT') { - return ''; - } - throw e; - }); -} - -/** - * The artifacts step is where source patches are committed, or written as "artifacts" - * Steps: - * - A temporary directory is created in the downloaded source - * - On start, any files in that directory are restored into the source tree - * - After the patch functions have run, the temporary directory is emptied - * - Original versions of sources to be patched are written to the temporary directory - * - Finally, The patched files are written into source. - * - */ - -exports.default = (() => { - var _ref = _asyncToGenerator(function* (compiler, next) { - const { src } = compiler; - const temp = (0, _path.join)(src, 'nexe'); - yield mkdirpAsync(temp); - const tmpFiles = yield readDirAsync(temp); - - yield (0, _bluebird.map)(tmpFiles, (() => { - var _ref2 = _asyncToGenerator(function* (path) { - return compiler.writeFileAsync(path.replace(temp, ''), (yield (0, _util.readFileAsync)(path))); - }); - - return function (_x3) { - return _ref2.apply(this, arguments); - }; - })()); - - yield next(); - - yield (0, _bluebird.map)(tmpFiles, function (x) { - return unlinkAsync(x); - }); - return (0, _bluebird.map)(compiler.files, (() => { - var _ref3 = _asyncToGenerator(function* (file) { - const sourceFile = (0, _path.join)(src, file.filename); - const tempFile = (0, _path.join)(temp, file.filename); - const fileContents = yield maybeReadFileContents(sourceFile); - - yield mkdirpAsync((0, _path.dirname)(tempFile)); - yield (0, _util.writeFileAsync)(tempFile, fileContents); - yield compiler.writeFileAsync(file.filename, file.contents); - }); - - return function (_x4) { - return _ref3.apply(this, arguments); - }; - })()); - }); - - function artifacts(_x, _x2) { - return _ref.apply(this, arguments); - } - - return artifacts; -})(); \ No newline at end of file diff --git a/lib/cli.js b/lib/cli.js deleted file mode 100644 index aea34e1..0000000 --- a/lib/cli.js +++ /dev/null @@ -1,94 +0,0 @@ -'use strict'; - -Object.defineProperty(exports, "__esModule", { - value: true -}); - -var _path = require('path'); - -var _bluebird = require('bluebird'); - -var _fs = require('fs'); - -var _util = require('./util'); - -function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new _bluebird.Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return _bluebird.Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; } - -const isWindows = process.platform === 'win32'; - -function getStdIn() { - return new _bluebird.Promise(resolve => { - const bundle = []; - process.stdin.setEncoding('utf-8'); - process.stdin.on('data', x => bundle.push(x)); - process.stdin.once('end', () => resolve((0, _util.dequote)(Buffer.concat(bundle).toString()))); - process.stdin.resume(); - }); -} - -/** - * The "cli" step detects whether the process is in a tty. If it is then the input is read into memory. - * Otherwise, it is buffered from stdin. If no input options are passed in the tty, the package.json#main file is used. - * After all the build steps have run, the output (the executable) is written to a file or piped to stdout. - * - * Configuration: - * - compiler.options.input - file path to the input bundle. - * - fallbacks: stdin, package.json#main - * - compiler.options.output - file path to the output executable. - * - fallbacks: stdout, nexe_ + epoch + ext - * - * @param {*} compiler - * @param {*} next - */ - -exports.default = (() => { - var _ref = _asyncToGenerator(function* (compiler, next) { - const input = compiler.options.input; - const bundled = Boolean(compiler.input); - - if (bundled) { - yield next(); - } else if (!input && !process.stdin.isTTY) { - compiler.log.verbose('Buffering stdin as main module...'); - compiler.input = yield getStdIn(); - } else if (input) { - compiler.log.verbose('Reading input as main module: ' + input); - compiler.input = yield (0, _util.readFileAsync)((0, _path.normalize)(input)); - } else if (!compiler.options.empty) { - compiler.log.verbose('Resolving cwd as main module...'); - compiler.input = yield (0, _util.readFileAsync)(require.resolve(process.cwd())); - } - - if (!bundled) { - yield next(); - } - - const deliverable = yield compiler.getDeliverableAsync(); - - return new _bluebird.Promise(function (resolve, reject) { - deliverable.once('error', reject); - - if (!compiler.options.output && !process.stdout.isTTY) { - compiler.log.verbose('Writing result to stdout...'); - deliverable.pipe(process.stdout).once('error', reject); - resolve(); - } else { - compiler.log.verbose('Writing result to file...'); - const output = compiler.options.output || `${compiler.options.name}${isWindows ? '.exe' : ''}`; - deliverable.pipe((0, _fs.createWriteStream)((0, _path.normalize)(output))).once('error', reject).once('close', function (e) { - if (e) { - reject(e); - } else { - resolve(compiler.log.info('Executable written: ' + output)); - } - }); - } - }); - }); - - function cli(_x, _x2) { - return _ref.apply(this, arguments); - } - - return cli; -})(); \ No newline at end of file diff --git a/lib/compiler.js b/lib/compiler.js deleted file mode 100644 index 0e8c718..0000000 --- a/lib/compiler.js +++ /dev/null @@ -1,111 +0,0 @@ -'use strict'; - -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.NexeCompiler = undefined; - -var _path = require('path'); - -var _bluebird = require('bluebird'); - -var _fs = require('fs'); - -var _child_process = require('child_process'); - -var _logger = require('./logger'); - -var logger = _interopRequireWildcard(_logger); - -var _util = require('./util'); - -function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } } - -function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new _bluebird.Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return _bluebird.Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; } - -const isWindows = process.platform === 'win32'; -const isBsd = Boolean(~process.platform.indexOf('bsd')); -const make = isWindows ? 'vcbuild.bat' : isBsd ? 'gmake' : 'make'; -const configure = isWindows ? 'configure' : './configure'; - -class NexeCompiler { - constructor(options) { - var _this = this; - - this.options = options; - logger.setLevel(options.loglevel); - this.log = logger; - this.python = options.python; - this.configure = options.configure; - this.make = isWindows ? options.vcBuild : options.make; - this.src = (0, _path.join)(options.temp, options.version); - this.env = Object.assign({}, process.env); - this.files = []; - - this.readFileAsync = (() => { - var _ref = _asyncToGenerator(function* (file) { - let cachedFile = _this.files.find(function (x) { - return (0, _path.normalize)(x.filename) === (0, _path.normalize)(file); - }); - if (!cachedFile) { - cachedFile = { - filename: file, - contents: yield (0, _util.readFileAsync)((0, _path.join)(_this.src, file), 'utf-8').catch({ code: 'ENOENT' }, function () { - return ''; - }) - }; - _this.files.push(cachedFile); - } - return cachedFile; - }); - - return function (_x) { - return _ref.apply(this, arguments); - }; - })(); - this.writeFileAsync = (file, contents) => (0, _util.writeFileAsync)((0, _path.join)(this.src, file), contents); - } - - set python(pythonPath) { - if (!pythonPath) { - return; - } - if (isWindows) { - this.env.PATH = this.env.PATH + ';"' + (0, _util.dequote)((0, _path.normalize)(pythonPath)) + '"'; - } else { - this.env.PYTHON = pythonPath; - } - } - - get _deliverableLocation() { - return isWindows ? (0, _path.join)(this.src, 'Release', 'node.exe') : (0, _path.join)(this.src, 'out', 'Release', 'node'); - } - - _runBuildCommandAsync(command, args) { - return new _bluebird.Promise((resolve, reject) => { - (0, _child_process.spawn)(command, args, { - cwd: this.src, - env: this.env, - stdio: 'ignore' - }).once('error', reject).once('close', resolve); - }); - } - - _configureAsync() { - return this._runBuildCommandAsync(this.env.PYTHON || 'python', [configure, ...this.configure]); - } - - buildAsync() { - var _this2 = this; - - return _asyncToGenerator(function* () { - yield _this2._configureAsync(); - return _this2._runBuildCommandAsync(make, _this2.make); - })(); - } - - getDeliverableAsync() { - return _bluebird.Promise.resolve((0, _fs.createReadStream)(this._deliverableLocation)); - } -} -exports.NexeCompiler = NexeCompiler; \ No newline at end of file diff --git a/lib/download.js b/lib/download.js deleted file mode 100644 index 45d556a..0000000 --- a/lib/download.js +++ /dev/null @@ -1,84 +0,0 @@ -'use strict'; - -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.default = download; - -var _zlib = require('zlib'); - -var _tar = require('tar'); - -var _request = require('request'); - -var _request2 = _interopRequireDefault(_request); - -var _bluebird = require('bluebird'); - -var _fs = require('fs'); - -var _rimraf = require('rimraf'); - -var _rimraf2 = _interopRequireDefault(_rimraf); - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } - -const statAsync = (0, _bluebird.promisify)(_fs.stat); -const rimrafAsync = (0, _bluebird.promisify)(_rimraf2.default); - -function progress(req, log, precision = 10) { - const logged = {}; - let length = 0; - let total = 1; - - return req.on('response', res => { - total = res.headers['content-length']; - }).on('data', chunk => { - length += chunk.length; - const percentComplete = +(length / total * 100).toFixed(); - if (percentComplete % precision === 0 && !logged[percentComplete]) { - logged[percentComplete] = true; - log(percentComplete); - } - }); -} - -function fetchNodeSource(path, url, log) { - log.info('Downloading Node: ' + url); - return new _bluebird.Promise((resolve, reject) => { - progress(_request2.default.get(url), pc => { - log.verbose(`Downloading Node: ${pc}%...`); - if (pc === 100) { - log.info('Extracting Node...'); - } - }).on('error', reject).pipe((0, _zlib.createGunzip)().on('error', reject)).pipe((0, _tar.Extract)({ path, strip: 1 })).on('error', reject).on('end', () => resolve(log.info('Extracted to: ' + path))); - }); -} - -function cleanSrc(clean, src, log) { - if (clean === true) { - log.info('Removing source: ' + src); - return rimrafAsync(src).then(() => { - log.info('Source deleted.' + src); - }); - } - return _bluebird.Promise.resolve(); -} - -/** - * Deletes (maybe) and downloads the node source to the configured temporary directory - * @param {*} compiler - * @param {*} next - */ -function download(compiler, next) { - const { src, log } = compiler; - const { version, sourceUrl, clean } = compiler.options; - const url = sourceUrl || `https://nodejs.org/dist/v${version}/node-v${version}.tar.gz`; - - return cleanSrc(clean, src, log).then(() => statAsync(src).then(x => !x.isDirectory() && fetchNodeSource(src, url, log), e => { - if (e.code !== 'ENOENT') { - throw e; - } - return fetchNodeSource(src, url, log); - })).then(next); -} \ No newline at end of file diff --git a/lib/logger.js b/lib/logger.js deleted file mode 100644 index 637cc61..0000000 --- a/lib/logger.js +++ /dev/null @@ -1,59 +0,0 @@ -'use strict'; - -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.verbose = exports.error = exports.info = exports.setLevel = undefined; - -var _os = require('os'); - -var _chalk = require('chalk'); - -var _chalk2 = _interopRequireDefault(_chalk); - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } - -function isFn(f) { - return typeof f === 'function'; -} - -function logNoop(x, cb) { - return isFn(cb) && process.nextTick(cb); -} - -function safeCb(f) { - return isFn(f) ? f : logNoop; -} - -const logLevels = [['verbose', 'green'], ['info', 'blue'], ['error', 'red']]; - -const logger = logLevels.reduce((logMethods, info) => { - const [level, color] = info; - logMethods[level] = function (output, cb) { - process.stderr.write(_chalk2.default[color](`${_os.EOL}[${level}]: ${output}`), safeCb(cb)); - }; - return logMethods; -}, { - setLevel(level) { - if (level === 'silent') { - logLevels.forEach(([x]) => { - logger[x] = logNoop; - }); - return; - } - process.on('beforeExit', () => { - process.stderr.write(_os.EOL); - }); - if (level === 'info') { - logger.verbose = logNoop; - } - return logger; - } -}); - -const { info, error, verbose, setLevel } = logger; - -exports.setLevel = setLevel; -exports.info = info; -exports.error = error; -exports.verbose = verbose; \ No newline at end of file diff --git a/lib/nexe.js b/lib/nexe.js deleted file mode 100644 index ec7f9e2..0000000 --- a/lib/nexe.js +++ /dev/null @@ -1,85 +0,0 @@ -'use strict'; - -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.compile = exports.isNexe = exports.argv = undefined; - -let compile = (() => { - var _ref = _asyncToGenerator(function* (compilerOptions, callback) { - const options = yield (0, _options.normalizeOptionsAsync)(compilerOptions); - const compiler = new _compiler.NexeCompiler(options); - - compiler.log.verbose('Compiler options:' + _os.EOL + JSON.stringify(compiler.options, null, 4)); - - const nexe = (0, _appBuilder.compose)(_bundle2.default, _cli2.default, _download2.default, (() => { - var _ref2 = _asyncToGenerator(function* (_, next) { - yield next(); - return compiler.buildAsync(); - }); - - return function (_x3, _x4) { - return _ref2.apply(this, arguments); - }; - })(), _artifacts2.default, _patches2.default, compiler.options.patches); - return nexe(compiler).asCallback(callback); - }); - - return function compile(_x, _x2) { - return _ref.apply(this, arguments); - }; -})(); - -var _appBuilder = require('app-builder'); - -var _bundle = require('./bundle'); - -var _bundle2 = _interopRequireDefault(_bundle); - -var _compiler = require('./compiler'); - -var _options = require('./options'); - -var _cli = require('./cli'); - -var _cli2 = _interopRequireDefault(_cli); - -var _download = require('./download'); - -var _download2 = _interopRequireDefault(_download); - -var _artifacts = require('./artifacts'); - -var _artifacts2 = _interopRequireDefault(_artifacts); - -var _patches = require('./patches'); - -var _patches2 = _interopRequireDefault(_patches); - -var _os = require('os'); - -var _bluebird = require('bluebird'); - -var _logger = require('./logger'); - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } - -function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new _bluebird.Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return _bluebird.Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; } - -_appBuilder.PromiseConfig.constructor = _bluebird.Promise; -(0, _bluebird.longStackTraces)(); - -function isNexe(callback) { - return _bluebird.Promise.resolve(Boolean(process.__nexe)).asCallback(callback); -} - -exports.argv = _options.argv; -exports.isNexe = isNexe; -exports.compile = compile; - - -if (require.main === module || process.__nexe) { - compile(_options.argv).catch(e => { - (0, _logger.error)(e.stack, () => process.exit(e.exitCode || 1)); - }); -} \ No newline at end of file diff --git a/lib/options.js b/lib/options.js deleted file mode 100644 index 5e5339f..0000000 --- a/lib/options.js +++ /dev/null @@ -1,152 +0,0 @@ -'use strict'; - -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.normalizeOptionsAsync = exports.argv = undefined; - -var _minimist = require('minimist'); - -var _minimist2 = _interopRequireDefault(_minimist); - -var _path = require('path'); - -var _bluebird = require('bluebird'); - -var _os = require('os'); - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } - -function padRight(str, l) { - return (str + ' '.repeat(l)).substr(0, l); -} -const defaults = { - temp: process.env.NEXE_TEMP || (0, _path.join)(process.cwd(), '.nexe'), - version: process.version.slice(1), - flags: [], - configure: [], - make: [], - vcBuild: ['nosign', 'release'], - quick: false, - bundle: true, - enableNodeCli: false, - verbose: false, - silent: false, - padding: 2, - patches: [] -}; -const alias = { - i: 'input', - o: 'output', - t: 'temp', - n: 'name', - v: 'version', - p: 'python', - f: 'flag', - c: 'configure', - m: 'make', - vc: 'vcBuild', - q: 'quick', - s: 'snapshot', - b: 'bundle', - cli: 'enableNodeCli', - h: 'help', - l: 'loglevel' -}; -const argv = (0, _minimist2.default)(process.argv, { alias, default: defaults }); -const help = ` -nexe --help CLI OPTIONS - - -i --input =./index.js -- application entry point - -o --output =./nexe.exe -- path to output file - -t --temp =./.nexe -- nexe temp directory (3Gb+) ~ NEXE_TEMP - -n --name =nexe.js -- file name for error reporting at run time - -v --version =${padRight(process.version.slice(1), 23)}-- node version - -p --python =/path/to/python2 -- python executable - -f --flag ="--expose-gc" -- *v8 flags to include during compilation - -c --configure ="--with-dtrace" -- *pass arguments to the configure command - -m --make ="--loglevel" -- *pass arguments to the make command - -vc --vcBuild =x64 -- *pass arguments to vcbuild.bat - -s --snapshot =/path/to/snapshot -- build with warmup snapshot - -b --bundle -- attempt bundling application - --ico -- file name for alternate icon file (windows) - --rc-* -- populate rc file options (windows) - --clean -- force download of sources - --enableNodeCli -- enable node cli enforcement (blocks app cli) - --sourceUrl -- pass an alternate source (node.tar.gz) url - --silent -- disable logging - --verbose -- set logging to verbose - - - -* variable key name * option can be used more than once - - TODO -q --quick =win32-x64-X.X.X -- use prebuilt binary (url, key or path) - TODO --resource-* =/path/to/resource -- *embed file bytes within the binary -`.trim(); - -function flattenFilter(...args) { - return [].concat(...args).filter(x => x); -} - -/** - * Extract keys such as { "rc-CompanyName": "Node.js" } to - * { CompanyName: "Node.js" } - * @param {*} match - * @param {*} options - */ -function extractCliMap(match, options) { - Object.keys(options).filter(x => match.test(x)).reduce((map, option) => { - const key = option.split('-')[1]; - map = map || {}; - map[key] = options[option]; - delete options[option]; - return map; - }, null); -} - -function tryResolveMainFileName() { - let filename = 'nexe'; - try { - const file = require.resolve(process.cwd()); - filename = (0, _path.basename)(file).replace((0, _path.extname)(file), ''); - } catch (_) {} - - return filename === 'index' ? 'nexe_' + Date.now() : filename; -} - -function extractLogLevel(options) { - if (options.loglevel) return options.loglevel; - if (options.silent) return 'silent'; - if (options.verbose) return 'verbose'; - if (options.info) return 'info'; -} - -function extractName(options) { - if (typeof options.input === 'string') { - return options.name || (0, _path.basename)(options.input).replace((0, _path.extname)(options.input), ''); - } - const mainName = tryResolveMainFileName(); - return options.name || mainName; -} - -function normalizeOptionsAsync(input) { - if (argv.help || Boolean(argv._.find(x => x === 'version'))) { - return (0, _bluebird.fromCallback)(cb => process.stderr.write(argv.help ? help : '2.0.0-beta.1' + _os.EOL, () => cb(null, process.exit(1)))); - } - - const options = Object.assign({}, defaults, input); - delete options._; - options.loglevel = extractLogLevel(options); - options.name = extractName(options); - options.flags = flattenFilter(options.flag, options.flags); - options.make = flattenFilter(options.make); - options.vcBuild = flattenFilter(options.vcBuild); - options.rc = options.rc || extractCliMap(/^rc-.*/, options); - options.resources = options.resources || extractCliMap(/^resource-.*/, options); - Object.keys(alias).filter(k => k !== 'rc').forEach(x => delete options[x]); - - return _bluebird.Promise.resolve(options); -} - -exports.argv = argv; -exports.normalizeOptionsAsync = normalizeOptionsAsync; \ No newline at end of file diff --git a/lib/patches/content.js b/lib/patches/content.js deleted file mode 100644 index 7903f31..0000000 --- a/lib/patches/content.js +++ /dev/null @@ -1,36 +0,0 @@ -'use strict'; - -Object.defineProperty(exports, "__esModule", { - value: true -}); - -var _buffer = require('buffer'); - -function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; } - -exports.default = (() => { - var _ref = _asyncToGenerator(function* (compiler, next) { - yield next(); - - const filename = 'lib/' + compiler.options.name + '.js'; - const file = yield compiler.readFileAsync(filename); - const header = '/' + '*'.repeat(19) + 'nexe_'; - const end = '_' + '*'.repeat(19) + '/'; - const padding = Array(compiler.options.padding * 1000000).fill('*').join(''); - - if (!padding) { - file.contents = compiler.input; - return; - } - - file.contents = [compiler.input, '/', padding, '/'].join(''); - - file.contents = header + _buffer.Buffer.byteLength(file.contents) + end + file.contents; - }); - - function content(_x, _x2) { - return _ref.apply(this, arguments); - } - - return content; -})(); \ No newline at end of file diff --git a/lib/patches/disable-node-cli.js b/lib/patches/disable-node-cli.js deleted file mode 100644 index 41ce40d..0000000 --- a/lib/patches/disable-node-cli.js +++ /dev/null @@ -1,29 +0,0 @@ -'use strict'; - -Object.defineProperty(exports, "__esModule", { - value: true -}); - -function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; } - -exports.default = (() => { - var _ref = _asyncToGenerator(function* (compiler, next) { - if (compiler.options.enableNodeCli) { - return next(); - } - - const nodecc = yield compiler.readFileAsync('src/node.cc'); - console.log(nodecc); - const nodeccMarker = "argv[index][0] == '-'"; - - nodecc.contents = nodecc.contents.replace(nodeccMarker, nodeccMarker.replace('-', ']')); - - return next(); - }); - - function disableNodeCli(_x, _x2) { - return _ref.apply(this, arguments); - } - - return disableNodeCli; -})(); \ No newline at end of file diff --git a/lib/patches/flags.js b/lib/patches/flags.js deleted file mode 100644 index 37fbe01..0000000 --- a/lib/patches/flags.js +++ /dev/null @@ -1,28 +0,0 @@ -'use strict'; - -Object.defineProperty(exports, "__esModule", { - value: true -}); - -function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; } - -exports.default = (() => { - var _ref = _asyncToGenerator(function* (compiler, next) { - const nodeflags = compiler.options.flags; - if (!nodeflags.length) { - return next(); - } - - const nodegyp = yield compiler.readFileAsync('node.gyp'); - - nodegyp.contents = nodegyp.contents.replace("'node_v8_options%': ''", `'node_v8_options%': '${nodeflags.join(' ')}'`); - - return next(); - }); - - function flags(_x, _x2) { - return _ref.apply(this, arguments); - } - - return flags; -})(); \ No newline at end of file diff --git a/lib/patches/gyp.js b/lib/patches/gyp.js deleted file mode 100644 index c4bc206..0000000 --- a/lib/patches/gyp.js +++ /dev/null @@ -1,31 +0,0 @@ -'use strict'; - -Object.defineProperty(exports, "__esModule", { - value: true -}); - -function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; } - -exports.default = (() => { - var _ref = _asyncToGenerator(function* ({ files, readFileAsync }, next) { - yield next(); - - const nodegyp = yield readFileAsync('node.gyp'); - const nodeGypMarker = "'lib/fs.js',"; - - nodegyp.contents = nodegyp.contents.replace(nodeGypMarker, ` - ${nodeGypMarker} - ${files.filter(function (x) { - return x.filename.startsWith('lib'); - }).map(function (x) { - return `'${x.filename}'`; - }).toString()}, - `.trim()); - }); - - function nodeGyp(_x, _x2) { - return _ref.apply(this, arguments); - } - - return nodeGyp; -})(); \ No newline at end of file diff --git a/lib/patches/ico.js b/lib/patches/ico.js deleted file mode 100644 index bd53c24..0000000 --- a/lib/patches/ico.js +++ /dev/null @@ -1,29 +0,0 @@ -'use strict'; - -Object.defineProperty(exports, "__esModule", { - value: true -}); - -var _path = require('path'); - -var _util = require('../util'); - -function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; } - -exports.default = (() => { - var _ref = _asyncToGenerator(function* (compiler, next) { - const iconFile = compiler.options.ico; - if (!iconFile) { - return next(); - } - const file = yield compiler.readFileAsync('src/res/node.ico'); - file.contents = yield (0, _util.readFileAsync)((0, _path.normalize)(iconFile)); - return next(); - }); - - function ico(_x, _x2) { - return _ref.apply(this, arguments); - } - - return ico; -})(); \ No newline at end of file diff --git a/lib/patches/index.js b/lib/patches/index.js deleted file mode 100644 index 97bf3ee..0000000 --- a/lib/patches/index.js +++ /dev/null @@ -1,39 +0,0 @@ -'use strict'; - -Object.defineProperty(exports, "__esModule", { - value: true -}); - -var _gyp = require('./gyp'); - -var _gyp2 = _interopRequireDefault(_gyp); - -var _content = require('./content'); - -var _content2 = _interopRequireDefault(_content); - -var _thirdPartyMain = require('./third-party-main'); - -var _thirdPartyMain2 = _interopRequireDefault(_thirdPartyMain); - -var _disableNodeCli = require('./disable-node-cli'); - -var _disableNodeCli2 = _interopRequireDefault(_disableNodeCli); - -var _flags = require('./flags'); - -var _flags2 = _interopRequireDefault(_flags); - -var _ico = require('./ico'); - -var _ico2 = _interopRequireDefault(_ico); - -var _nodeRc = require('./node-rc'); - -var _nodeRc2 = _interopRequireDefault(_nodeRc); - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } - -const patches = [_gyp2.default, _content2.default, _thirdPartyMain2.default, _disableNodeCli2.default, _flags2.default, _ico2.default, _nodeRc2.default]; - -exports.default = patches; \ No newline at end of file diff --git a/lib/patches/node-rc.js b/lib/patches/node-rc.js deleted file mode 100644 index 988da0f..0000000 --- a/lib/patches/node-rc.js +++ /dev/null @@ -1,34 +0,0 @@ -'use strict'; - -Object.defineProperty(exports, "__esModule", { - value: true -}); - -function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; } - -exports.default = (() => { - var _ref = _asyncToGenerator(function* (compiler, next) { - const options = compiler.options.rc; - if (!options) { - return next(); - } - - const file = yield compiler.readFileAsync('src/res/node.rc'); - - Object.keys(options).forEach(function (key) { - let value = options[key]; - const isVar = /^[A-Z_]+$/.test(value); - - value = isVar ? value : `"${value}"`; - file.contents.replace(new RegExp(`VALUE "${key}",*`), `VALUE "${key}", ${value}`); - }); - - return next(); - }); - - function nodeRc(_x, _x2) { - return _ref.apply(this, arguments); - } - - return nodeRc; -})(); \ No newline at end of file diff --git a/lib/patches/snapshot.js b/lib/patches/snapshot.js deleted file mode 100644 index bc0ca9b..0000000 --- a/lib/patches/snapshot.js +++ /dev/null @@ -1,27 +0,0 @@ -'use strict'; - -Object.defineProperty(exports, "__esModule", { - value: true -}); - -function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; } - -exports.default = (() => { - var _ref = _asyncToGenerator(function* (compiler, next) { - const snapshotFile = compiler.options.snapshot; - - if (!snapshotFile) { - return next(); - } - - const file = yield compiler.readFileAsync('configure'); - file.contents = file.contents.replace('def configure_v8(o):', `def configure_v8(o):\n o['variables']['embed_script'] = '${snapshotFile}'\n o['variables']['warmup_script'] = '${snapshotFile}'`); - return next(); - }); - - function snapshot(_x, _x2) { - return _ref.apply(this, arguments); - } - - return snapshot; -})(); \ No newline at end of file diff --git a/lib/patches/third-party-main.js b/lib/patches/third-party-main.js deleted file mode 100644 index 445b0a4..0000000 --- a/lib/patches/third-party-main.js +++ /dev/null @@ -1,37 +0,0 @@ -'use strict'; - -Object.defineProperty(exports, "__esModule", { - value: true -}); - -function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; } - -exports.default = (() => { - var _ref = _asyncToGenerator(function* (compiler, next) { - const mainFile = yield compiler.readFileAsync('lib/_third_party_main.js'); - mainFile.contents = ` - Object.defineProperty(process, '__nexe', { - value: true, - enumerable: false, - writable: false, - configurable: false - }); - require("${compiler.options.name}"); - `.trim(); - - if (compiler.options.empty === true) { - compiler.options.resources.length = 0; - //eslint-disable-next-line - compiler.input = 'console.log(`nexe-${process.platform}-${process.arch}-${process.version}`)'; - return next(); - } - - return next(); - }); - - function main(_x, _x2) { - return _ref.apply(this, arguments); - } - - return main; -})(); \ No newline at end of file diff --git a/lib/util.js b/lib/util.js deleted file mode 100644 index 8941b1d..0000000 --- a/lib/util.js +++ /dev/null @@ -1,28 +0,0 @@ -'use strict'; - -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.dequote = exports.writeFileAsync = exports.readFileAsync = undefined; - -var _fs = require('fs'); - -var _bluebird = require('bluebird'); - -function dequote(input) { - input = input.trim(); - - const singleQuote = input.startsWith('\'') && input.endsWith('\''); - const doubleQuote = input.startsWith('"') && input.endsWith('"'); - if (singleQuote || doubleQuote) { - return input.slice(1).slice(0, -1); - } - return input; -} - -const readFileAsync = (0, _bluebird.promisify)(_fs.readFile); -const writeFileAsync = (0, _bluebird.promisify)(_fs.writeFile); - -exports.readFileAsync = readFileAsync; -exports.writeFileAsync = writeFileAsync; -exports.dequote = dequote; \ No newline at end of file