Comparing version 0.2.0 to 0.2.1
@@ -58,2 +58,6 @@ 'use strict'; | ||
describe: 'Package module to deb. disable to pack using --no-pack' | ||
}, | ||
collect: { | ||
alias: 'C', | ||
describe: 'Just collect packages built to dist.' | ||
} | ||
@@ -63,3 +67,3 @@ }; | ||
function build(options) { | ||
options = _.assign({}, process.env, options); | ||
options = _.defaults(options, process.env); | ||
@@ -99,26 +103,52 @@ debug('options', options); | ||
var cmd = 'npm install --silent --production --unsafe-perm --ignore-scripts'; | ||
log.info('build', 'Fetching modules:', cmd); | ||
var onlyCollect = !!options.collect; | ||
var result = sh.exec(cmd, {cwd: target}); | ||
if (result.code) { | ||
return Promise.reject(new Error('npm install failed')); | ||
} | ||
var promise = Promise.resolve(); | ||
return docker.verifyDockerImages().then(function () { | ||
return Promise.each(deps, function (dep) { | ||
ver = pkg.dependencies[dep]; | ||
console.log(chalk.green.bold('==>') + chalk.bold(' Building %s@%s'), dep, ver); | ||
var mod = path.join(target, 'node_modules', dep); | ||
if (!onlyCollect) { | ||
promise = promise.then(function () { | ||
var cmd = 'npm install --silent --production --unsafe-perm --ignore-scripts'; | ||
log.info('build', 'Fetching modules:', cmd); | ||
if (!fs.existsSync(mod)) { | ||
error = new Error(util.format('Module not found, %s', mod)); | ||
log.error('build', error.message); | ||
return Promise.reject(error); | ||
var result = sh.exec(cmd, {cwd: target}); | ||
if (result.code) { | ||
return Promise.reject(new Error('npm install failed')); | ||
} | ||
return _build(mod, options).then(function () { | ||
return collect(mod, options); | ||
return docker.verifyDockerImages().then(function () { | ||
return Promise.each(deps, function (dep, index, length) { | ||
ver = pkg.dependencies[dep]; | ||
console.log(chalk.bold(chalk.green('==>') + ' (' + (index + 1) + '/' + length + ') Building %s@%s'), dep, ver); | ||
var mod = path.join(target, 'node_modules', dep); | ||
if (!fs.existsSync(mod)) { | ||
error = new Error(util.format('Module not found, %s', mod)); | ||
log.error('build', error.message); | ||
return Promise.reject(error); | ||
} | ||
return _build(mod, options); | ||
}) | ||
}) | ||
}) | ||
} | ||
return promise.then(function () { | ||
var mods = _.map(deps, function (dep) { | ||
return path.join(target, 'node_modules', dep); | ||
}); | ||
options.output = path.resolve(options.output || 'dist'); | ||
if (fs.existsSync(options.output)) { | ||
log.info('build', 'The output directory "%s" exists, remove it now.', options.output); | ||
fs.removeSync(options.output); | ||
} | ||
console.log(chalk.bold(chalk.blue('==>') + ' Collecting all packages to ' + options.output)); | ||
return collect(mods, options); | ||
}).then(function () { | ||
console.log(chalk.bold('Build successful. All packages could be found in ' + options.output)); | ||
}); | ||
@@ -125,0 +155,0 @@ } |
@@ -7,14 +7,11 @@ 'use strict'; | ||
var util = require('util'); | ||
var Promise = require('bluebird'); | ||
var ndir = require('node-dir'); | ||
var paths = Promise.promisify(ndir.paths); | ||
var chalk = require('chalk'); | ||
var Promise = require('bluebird'); | ||
function collect(modspaths, options) { | ||
var output = options.output || 'dist'; | ||
var flat = options.flat; | ||
if (fs.existsSync(output)) { | ||
fs.removeSync(output); | ||
} | ||
if (typeof modspaths === 'string') { | ||
@@ -24,72 +21,43 @@ modspaths = [modspaths]; | ||
var promise = Promise.all(_.map(modspaths, function (modpath) { | ||
return move(modpath, output, flat); | ||
})); | ||
return promise | ||
.each(function (result) { | ||
_.forEach(result, function (mods, name) { | ||
name = name.replace(/^[_-]$/, ''); | ||
generateInstallScript(name, mods, output); | ||
}); | ||
}) | ||
.then(function () { | ||
console.log(chalk.green('Generated install script')); | ||
}); | ||
} | ||
function move(modpath, dest, flat) { | ||
var result = {}; | ||
return _move(modpath).then(function () { | ||
return result; | ||
}); | ||
function _move(modpath) { | ||
if (Array.isArray(modpath)) { | ||
return Promise.each(modpath, function (m) { | ||
return _move(m) | ||
}); | ||
} | ||
if (typeof modpath !== 'string') { | ||
return Promise.reject(new Error('modpath must be string')); | ||
} | ||
return Promise.map(modspaths, function (modpath) { | ||
var dir = path.resolve(modpath, 'dist'); | ||
if (!fs.existsSync(dir)) { | ||
console.log(chalk.yellow('WARN'), 'No dist folder found in', modpath); | ||
return Promise.resolve(); | ||
} | ||
return new Promise(function (resolve) { | ||
ndir.paths(dir, function (err, paths) { | ||
paths.files | ||
.filter(function (f) { | ||
return _.endsWith(f, '.deb'); | ||
}) | ||
.map(function (f) { | ||
var target, arch = ''; | ||
var p1 = f.lastIndexOf('_'); | ||
var p2 = f.lastIndexOf('.'); | ||
if (p2 > p1 && p1 > -1) { | ||
arch = f.substring(p1 + 1, p2); | ||
} | ||
target = path.join(dest, arch, flat ? '' : subdir); | ||
fs.ensureDirSync(target); | ||
target = path.join(target, path.basename(f)); | ||
console.log(chalk.green('Copying'), f, '->', target); | ||
fs.copySync(f, target); | ||
if (!arch) { | ||
arch = '-'; | ||
} | ||
result[arch] = result[arch] || []; | ||
result[arch].push(flat ? path.basename(f) : path.join(subdir, path.basename(f))); | ||
}); | ||
resolve(); | ||
return paths(dir).then(function (paths) { | ||
var files = _.filter(paths.files, function (p) { | ||
return _.endsWith(p, '.deb'); | ||
}); | ||
_.forEach(files, function (f) { | ||
var target, arch = ''; | ||
var p1 = f.lastIndexOf('_'); | ||
var p2 = f.lastIndexOf('.'); | ||
if (p2 > p1 && p1 > -1) { | ||
arch = f.substring(p1 + 1, p2); | ||
} | ||
target = path.join(output, arch); | ||
fs.ensureDirSync(target); | ||
target = path.join(target, path.basename(f)); | ||
console.log(chalk.green('Copying'), f, '->', target); | ||
fs.copySync(f, target); | ||
arch = arch || '-'; | ||
result[arch] = result[arch] || []; | ||
result[arch].push(path.basename(f)); | ||
}); | ||
}); | ||
} | ||
}).then(function () { | ||
_.forEach(result, function (mods, name) { | ||
name = name.replace(/^[_-]$/, ''); | ||
generateInstallScript(name, mods, output); | ||
}); | ||
console.log(chalk.bold('Generated install script')); | ||
}); | ||
} | ||
@@ -108,3 +76,2 @@ | ||
module.exports = collect; |
{ | ||
"name": "adm-build", | ||
"version": "0.2.0", | ||
"version": "0.2.1", | ||
"description": "Build nodejs application to arm or amd64 package", | ||
@@ -39,3 +39,2 @@ "homepage": "", | ||
"ignore": "^3.0.5", | ||
"json5": "^0.5.0", | ||
"lodash": "^4.6.1", | ||
@@ -50,4 +49,2 @@ "ncp": "^2.0.0", | ||
"devDependencies": { | ||
"eslint": "^2.3.0", | ||
"eslint-config-xo-space": "^0.11.0", | ||
"gulp": "^3.9.1", | ||
@@ -70,6 +67,5 @@ "gulp-eslint": "^2.0.0", | ||
"scripts": { | ||
"prepublish": "gulp prepublish", | ||
"test": "gulp" | ||
"test": "mocha" | ||
}, | ||
"license": "MIT" | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
34155
15
9
716
- Removedjson5@^0.5.0
- Removedjson5@0.5.1(transitive)