fis-command-install
Advanced tools
Comparing version 0.0.7 to 0.1.0-beta
265
install.js
@@ -9,32 +9,245 @@ /* | ||
exports.name = 'install'; | ||
exports.usage = '<names> [path] [options]'; | ||
exports.desc = 'install components and demos'; | ||
exports.register = function(commander){ | ||
exports.usage = '[options] <components...>'; | ||
exports.desc = 'install components'; | ||
var logger = require('./lib/logger'); | ||
exports.register = function(commander) { | ||
commander | ||
.option('--repos <url>', 'repository', String) | ||
.action(function(){ | ||
var args = Array.prototype.slice.call(arguments); | ||
.option('--save', 'save component(s) dependencies into `components.json` file.') | ||
.option('-r, --root <path>', 'set project root') | ||
.action(function() { | ||
var args = [].slice.call(arguments); | ||
var options = args.pop(); | ||
var names = args.shift(); | ||
var path = args.shift(); | ||
var remote = options.repos || fis.config.get( | ||
'system.repos', | ||
fis.project.DEFAULT_REMOTE_REPOS | ||
).replace(/^\/$/, '') + '/component'; | ||
var dest = process.cwd(); | ||
if(path){ | ||
if(!fis.util.isAbsolute(path)){ | ||
dest = fis.util(dest, path); | ||
} | ||
} | ||
var opt = { | ||
extract : dest, | ||
remote : remote | ||
var Promise = require('bluebird'); | ||
var settings = { | ||
save: !!options.save, | ||
root: options.root || '', | ||
components: args.concat() | ||
}; | ||
names.split(/,/).forEach(function(name){ | ||
name = name.split('@'); | ||
fis.util.install(name[0], name[1], opt); | ||
}); | ||
Promise | ||
// resolve project root. | ||
// 根据 fis-conf.js 所在目录来决定 root 是哪个目录。 | ||
.try(function() { | ||
if (!settings.root) { | ||
var findup = require('findup'); | ||
return new Promise(function(resolve, reject) { | ||
var fup = findup(process.cwd(), 'fis-conf.js'); | ||
var dir = null; | ||
fup.on('found', function(found) { | ||
dir = found; | ||
fup.stop(); | ||
}); | ||
fup.on('error', reject); | ||
fup.on('end', function() { | ||
resolve(dir); | ||
}); | ||
}) | ||
.then(function(dir) { | ||
settings.root = dir || process.cwd(); | ||
}); | ||
} | ||
}) | ||
// load fis-conf.js if exists. | ||
// 读取用户配置信息。 | ||
.then(function() { | ||
var path = require('path'); | ||
var exists = require('fs').existsSync; | ||
var filepath = path.join(settings.root, 'fis-conf.js'); | ||
if (exists(filepath)) { | ||
require(filepath); | ||
// 应用 fis-conf.js | ||
settings.componentsDir = path.join(settings.root, | ||
fis.config.get('component.dir') || '/components'); | ||
settings.protocol = fis.config.get('component.protocol', 'github'); | ||
settings.github = fis.config.get('component.github', {}); | ||
settings.gitlab = fis.config.get('component.gitlab', {}); | ||
settings.lights = fis.config.get('component.lights', {}); | ||
} | ||
}) | ||
// 读取 components.json 如果存在 | ||
.then(function() { | ||
var components = settings.components; | ||
var path = require('path'); | ||
var exists = require('fs').existsSync; | ||
var componentJson = path.join(settings.root, 'component.json'); | ||
if (!components.length && !exists(componentJson)) { | ||
throw new Error('missing `component.json`'); | ||
} | ||
if (exists(componentJson)) { | ||
var config = Promise.promisify(require('./lib/config')); | ||
return config(componentJson) | ||
.then(function(ret) { | ||
var _ = require('./lib/util.js'); | ||
settings.config = ret; | ||
[] | ||
.join | ||
.apply(settings.components, ret.dependencies || []); | ||
ret.protocol && (settings.protocol = ret.protocol); | ||
ret.github && _.mixin(settings.github, ret.github); | ||
ret.gitlab && _.mixin(settings.gitlab, ret.gitlab); | ||
ret.lights && _.mixin(settings.lights, ret.lights); | ||
}); | ||
} | ||
}) | ||
.then(function() { | ||
var components = settings.components || []; | ||
var factory = require('./lib/remotes/factory.js'); | ||
factory.setSettings(settings); | ||
// validate and filter invalid dependencies. | ||
// 过滤掉不能识别的依赖。 | ||
return components | ||
.map(function(component) { | ||
var type = factory.detect(component); | ||
if (!type) { | ||
logger.warn('`%s` is not a valid repository.', component); | ||
return null; | ||
} | ||
return factory(component); | ||
}) | ||
.filter(function(item) { | ||
return item != null; | ||
}); | ||
}) | ||
// finally get components list. | ||
.then(function(components) { | ||
if (!components.length) { | ||
logger.warn('Installed nothing!'); | ||
return; | ||
} | ||
var collector = require('./lib/collector.js'); | ||
return collector(components) | ||
.then(function(components) { | ||
var _ = require('./lib/util.js'); | ||
// 过滤掉本地的仓库。已经同名的包。 | ||
components = components | ||
.filter(function(item) { | ||
return item.location !== 'local'; | ||
}) | ||
// 先不 sort 了,通过先后顺序来准定用哪个版本吧。 | ||
// 而不是总是用最新版本。 | ||
// .sort(function(a, b) { | ||
// return _.compareVersion(a.version, b.version); | ||
// }) | ||
// 过滤同名的组件名。 | ||
.filter(function(item, index, list) { | ||
return _.indexOfArray('name', item.name, list) === index; | ||
}); | ||
if (!components.length) { | ||
console.log('Aready installed'); | ||
return; | ||
} | ||
var ProgressBar = require('progress'); | ||
var percentages = {}; | ||
// 优化进度提示。 | ||
components.forEach(function(item) { | ||
percentages[item.name] = { | ||
loaded: 0, | ||
total: 1024 * 1024 // 假的,后面会动态调整。 | ||
}; | ||
}); | ||
var bar; | ||
var ticked = 0; | ||
var update = function(name, loaded, total) { | ||
// percentages[name] = percentages[name] || {}; | ||
percentages[name].loaded = loaded; | ||
percentages[name].total = total; | ||
updateAll(); | ||
}; | ||
var updateAll = function() { | ||
bar = bar || new ProgressBar(' downloading [:bar] :percent :etas', { | ||
incomplete: ' ', | ||
total: 100, | ||
clear: true | ||
}); | ||
var total = 0; | ||
var loaded = 0; | ||
Object.keys(percentages).forEach(function(key) { | ||
var item = percentages[key]; | ||
total += item.total; | ||
loaded += item.loaded; | ||
}); | ||
var percentage = Math.round(loaded * 100 / total); | ||
var step = Math.max(percentage - ticked, 0); | ||
ticked += step; | ||
bar.tick(step); | ||
} | ||
return Promise | ||
.all(components.map(function(component) { | ||
return component.install(function(percent, loaded, total) { | ||
update(component.name, loaded, total); | ||
}); | ||
})) | ||
.then(function(components) { | ||
// 如果没有 tick 完,则收下尾 | ||
(100 - ticked) && bar && bar.tick(100 - ticked); | ||
var last = components.length - 1; | ||
var arrs = components.map(function(item, index) { | ||
return (index === last ? '└── ' : '├── ') + item.type + ':' + item.address + '@' + item.version; | ||
}); | ||
console.log('Installed\n%s', arrs.join('\n')); | ||
}); | ||
}); | ||
}) | ||
// 保存 components.json | ||
.then(function() { | ||
// todo | ||
// 如果指定了 --save, 则需要把数据写入到 components.josn 文件里面。 | ||
}) | ||
// error handle | ||
.catch(function(e) { | ||
if (/Not\s+Found/i.test(e.message)) { | ||
logger.warn('`fis install` now is for installing commponents, you may use `\x1b[31mlights install\x1b[0m` instead.'); | ||
} | ||
logger.error('\x1b[31m%s\x1b[0m', e.message); | ||
}); | ||
}); | ||
}; |
@@ -0,0 +0,0 @@ Copyright (C) 2013 baidu.com |
{ | ||
"name" : "fis-command-install", | ||
"description" : "fis install command.", | ||
"version" : "0.0.7", | ||
"author" : "FIS Team <fis@baidu.com>", | ||
"homepage" : "http://fis.baidu.com/", | ||
"keywords": [ "fis" ], | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/fis-dev/fis-command-install.git" | ||
}, | ||
"engines" : { | ||
"node" : ">= 0.8.0" | ||
}, | ||
"main" : "install.js", | ||
"scripts" : { | ||
"test" : "mocha test/ut --recursive" | ||
}, | ||
"dependencies" : {}, | ||
"devDependencies": {} | ||
} | ||
"name": "fis-command-install", | ||
"description": "fis install command.", | ||
"version": "0.1.0-beta", | ||
"author": "FIS Team <fis@baidu.com>", | ||
"homepage": "http://fis.baidu.com/", | ||
"keywords": [ | ||
"fis" | ||
], | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/fis-dev/fis-command-install.git" | ||
}, | ||
"engines": { | ||
"node": ">= 0.8.0" | ||
}, | ||
"main": "install.js", | ||
"scripts": { | ||
"test": "mocha test/ut --recursive" | ||
}, | ||
"dependencies": { | ||
"bluebird": "^2.3.11", | ||
"findup": "^0.1.5", | ||
"fis-scaffold-kernel": "~0.0.6", | ||
"progress": "^1.1.8", | ||
"progress-bar": "^0.1.1", | ||
"request": "^2.48.0", | ||
"semver": "^4.1.0" | ||
}, | ||
"devDependencies": {} | ||
} |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
38904
15
874
7
7
2
+ Addedbluebird@^2.3.11
+ Addedfindup@^0.1.5
+ Addedfis-scaffold-kernel@~0.0.6
+ Addedprogress@^1.1.8
+ Addedprogress-bar@^0.1.1
+ Addedrequest@^2.48.0
+ Addedsemver@^4.1.0
+ Addedadm-zip@0.4.30.4.4(transitive)
+ Addedajv@6.12.6(transitive)
+ Addedarchiver@0.4.9(transitive)
+ Addedarray-buffer-byte-length@1.0.2(transitive)
+ Addedasn1@0.1.110.2.6(transitive)
+ Addedassert-plus@0.1.51.0.0(transitive)
+ Addedasync@0.2.90.9.2(transitive)
+ Addedasynckit@0.4.0(transitive)
+ Addedavailable-typed-arrays@1.0.7(transitive)
+ Addedaws-sign@0.3.0(transitive)
+ Addedaws-sign2@0.7.0(transitive)
+ Addedaws4@1.13.2(transitive)
+ Addedbalanced-match@1.0.2(transitive)
+ Addedbcrypt-pbkdf@1.0.2(transitive)
+ Addedblock-stream@0.0.9(transitive)
+ Addedbluebird@2.11.0(transitive)
+ Addedboom@0.4.2(transitive)
+ Addedbrace-expansion@1.1.11(transitive)
+ Addedcall-bind@1.0.8(transitive)
+ Addedcall-bind-apply-helpers@1.0.1(transitive)
+ Addedcall-bound@1.0.3(transitive)
+ Addedcaseless@0.12.0(transitive)
+ Addedcolors@0.6.2(transitive)
+ Addedcombined-stream@0.0.71.0.8(transitive)
+ Addedcommander@2.1.0(transitive)
+ Addedconcat-map@0.0.1(transitive)
+ Addedcookie-jar@0.3.0(transitive)
+ Addedcore-util-is@1.0.21.0.3(transitive)
+ Addedcryptiles@0.2.2(transitive)
+ Addedctype@0.5.3(transitive)
+ Addedcycle@1.0.3(transitive)
+ Addeddashdash@1.14.1(transitive)
+ Addeddebug@0.8.02.1.0(transitive)
+ Addeddeep-equal@2.2.3(transitive)
+ Addeddefine-data-property@1.1.4(transitive)
+ Addeddefine-properties@1.2.1(transitive)
+ Addeddelayed-stream@0.0.51.0.0(transitive)
+ Addeddunder-proto@1.0.1(transitive)
+ Addedecc-jsbn@0.1.2(transitive)
+ Addedes-define-property@1.0.1(transitive)
+ Addedes-errors@1.3.0(transitive)
+ Addedes-get-iterator@1.1.3(transitive)
+ Addedes-object-atoms@1.1.1(transitive)
+ Addedextend@3.0.2(transitive)
+ Addedextsprintf@1.3.0(transitive)
+ Addedeyes@0.1.8(transitive)
+ Addedfast-deep-equal@3.1.3(transitive)
+ Addedfast-json-stable-stringify@2.1.0(transitive)
+ Addedfindup@0.1.5(transitive)
+ Addedfis-repo-client@0.1.14(transitive)
+ Addedfis-scaffold-kernel@0.0.22(transitive)
+ Addedfor-each@0.3.4(transitive)
+ Addedforever-agent@0.5.20.6.1(transitive)
+ Addedform-data@0.1.42.3.3(transitive)
+ Addedfs.realpath@1.0.0(transitive)
+ Addedfstream@1.0.12(transitive)
+ Addedfunction-bind@1.1.2(transitive)
+ Addedfunctions-have-names@1.2.3(transitive)
+ Addedget-intrinsic@1.2.7(transitive)
+ Addedget-proto@1.0.1(transitive)
+ Addedgetpass@0.1.7(transitive)
+ Addedglob@7.2.3(transitive)
+ Addedglob.js@0.1.0(transitive)
+ Addedgopd@1.2.0(transitive)
+ Addedgraceful-fs@4.2.11(transitive)
+ Addedhar-schema@2.0.0(transitive)
+ Addedhar-validator@5.1.5(transitive)
+ Addedhas-bigints@1.1.0(transitive)
+ Addedhas-property-descriptors@1.0.2(transitive)
+ Addedhas-symbols@1.1.0(transitive)
+ Addedhas-tostringtag@1.0.2(transitive)
+ Addedhasown@2.0.2(transitive)
+ Addedhawk@1.0.0(transitive)
+ Addedhoek@0.9.1(transitive)
+ Addedhttp-signature@0.10.11.2.0(transitive)
+ Addedi@0.3.7(transitive)
+ Addediconv-lite@0.2.110.4.4(transitive)
+ Addedignore@2.2.7(transitive)
+ Addedinflight@1.0.6(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedini@1.0.0(transitive)
+ Addedinternal-slot@1.1.0(transitive)
+ Addedis-arguments@1.2.0(transitive)
+ Addedis-array-buffer@3.0.5(transitive)
+ Addedis-bigint@1.1.0(transitive)
+ Addedis-boolean-object@1.2.1(transitive)
+ Addedis-callable@1.2.7(transitive)
+ Addedis-date-object@1.1.0(transitive)
+ Addedis-map@2.0.3(transitive)
+ Addedis-number-object@1.1.1(transitive)
+ Addedis-regex@1.2.1(transitive)
+ Addedis-set@2.0.3(transitive)
+ Addedis-shared-array-buffer@1.0.4(transitive)
+ Addedis-string@1.1.1(transitive)
+ Addedis-symbol@1.1.1(transitive)
+ Addedis-typedarray@1.0.0(transitive)
+ Addedis-utf8@0.2.0(transitive)
+ Addedis-weakmap@2.0.2(transitive)
+ Addedis-weakset@2.0.4(transitive)
+ Addedisarray@0.0.12.0.5(transitive)
+ Addedisstream@0.1.2(transitive)
+ Addedjs-base64@2.1.2(transitive)
+ Addedjsbn@0.1.1(transitive)
+ Addedjson-schema@0.4.0(transitive)
+ Addedjson-schema-traverse@0.4.1(transitive)
+ Addedjson-stringify-safe@5.0.1(transitive)
+ Addedjsprim@1.4.2(transitive)
+ Addedlodash@2.4.1(transitive)
+ Addedmath-intrinsics@1.1.0(transitive)
+ Addedmime@1.2.11(transitive)
+ Addedmime-db@1.52.0(transitive)
+ Addedmime-types@2.1.35(transitive)
+ Addedminimatch@3.1.2(transitive)
+ Addedminimist@1.2.8(transitive)
+ Addedmkdirp@0.5.6(transitive)
+ Addedms@0.6.2(transitive)
+ Addedmute-stream@0.0.8(transitive)
+ Addedncp@0.4.2(transitive)
+ Addednode-uuid@1.4.8(transitive)
+ Addedoauth-sign@0.3.00.9.0(transitive)
+ Addedobject-inspect@1.13.3(transitive)
+ Addedobject-is@1.1.6(transitive)
+ Addedobject-keys@1.1.1(transitive)
+ Addedobject.assign@4.1.7(transitive)
+ Addedonce@1.4.0(transitive)
+ Addedpath-is-absolute@1.0.1(transitive)
+ Addedperformance-now@2.1.0(transitive)
+ Addedpkginfo@0.3.10.4.1(transitive)
+ Addedpossible-typed-array-names@1.0.0(transitive)
+ Addedprogress@1.1.8(transitive)
+ Addedprogress-bar@0.1.1(transitive)
+ Addedprompt@0.2.14(transitive)
+ Addedpsl@1.15.0(transitive)
+ Addedpunycode@2.3.1(transitive)
+ Addedq@1.0.1(transitive)
+ Addedqs@0.6.66.5.3(transitive)
+ Addedread@1.0.7(transitive)
+ Addedreadable-stream@1.0.34(transitive)
+ Addedregexp.prototype.flags@1.5.4(transitive)
+ Addedrequest@2.27.02.88.2(transitive)
+ Addedrevalidator@0.1.8(transitive)
+ Addedrimraf@2.7.1(transitive)
+ Addedsafe-buffer@5.2.1(transitive)
+ Addedsafe-regex-test@1.1.0(transitive)
+ Addedsafer-buffer@2.1.2(transitive)
+ Addedsemver@4.3.6(transitive)
+ Addedset-function-length@1.2.2(transitive)
+ Addedset-function-name@2.0.2(transitive)
+ Addedside-channel@1.1.0(transitive)
+ Addedside-channel-list@1.0.0(transitive)
+ Addedside-channel-map@1.0.1(transitive)
+ Addedside-channel-weakmap@1.0.2(transitive)
+ Addedsntp@0.2.4(transitive)
+ Addedsshpk@1.18.0(transitive)
+ Addedstack-trace@0.0.10(transitive)
+ Addedstop-iteration-iterator@1.1.0(transitive)
+ Addedstring_decoder@0.10.31(transitive)
+ Addedtar@1.0.3(transitive)
+ Addedtough-cookie@2.5.0(transitive)
+ Addedtunnel-agent@0.3.00.6.0(transitive)
+ Addedtweetnacl@0.14.5(transitive)
+ Addeduri-js@4.4.1(transitive)
+ Addedutile@0.2.1(transitive)
+ Addeduuid@3.4.0(transitive)
+ Addedverror@1.10.0(transitive)
+ Addedwhich-boxed-primitive@1.1.1(transitive)
+ Addedwhich-collection@1.0.2(transitive)
+ Addedwhich-typed-array@1.1.18(transitive)
+ Addedwinston@0.8.3(transitive)
+ Addedwrappy@1.0.2(transitive)