Skip to content

Commit

Permalink
#21 安装组件时排除文件、目录
Browse files Browse the repository at this point in the history
  • Loading branch information
icefox0801 committed May 26, 2016
1 parent 8afc57d commit 3f9c947
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 17 deletions.
18 changes: 9 additions & 9 deletions lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@ cli.start = function (env) {
cli.run(env);
});

// bootstrap(env);
bootstrap(env);
// Test
bootstrap(env, {
username: 'icefox0801',
email: '[email protected]',
token: '4zWuy_my-jMuSnjLSkKv'
}, {
owner: 'icefox0801',
domain: 'https://gitlab.com'
});
//bootstrap(env, {
// username: 'icefox0801',
// email: '[email protected]',
// token: '4zWuy_my-jMuSnjLSkKv'
//}, {
// owner: 'icefox0801',
// domain: 'https://gitlab.com'
//});

};

Expand Down
45 changes: 43 additions & 2 deletions lib/component/Component.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ var path = require('path');
var _ = require('lodash');
var fs = require('graceful-fs');
var fse = require('fs-extra');
var glob = require('glob');
var minimatch = require('minimatch');
var semver = require('semver');
var jsonfile = require('jsonfile');
var AdmZip = require('adm-zip');
Expand Down Expand Up @@ -38,6 +40,7 @@ var Component = function (parsed, type, options) {

this.type = type;
this.tree = null;
this.exclude = [];
this.fullPath = path.join(fecom.componentRoot, parsed.name);
this.options = _.assign({}, Component.defaults, options);
this.initialize();
Expand Down Expand Up @@ -66,6 +69,7 @@ Component.prototype = {
var json = jsonfile.readFileSync(path.join(self.fullPath, 'component.json'));
self.version = json.version;
self.author = json.author;
self.exclude = json.exclude || [];
}

self.tree = new Tree(model);
Expand All @@ -90,7 +94,6 @@ Component.prototype = {
var parsed = tree.props;
return gitlabRepo.validate(parsed.owner, parsed.name, parsed.version)
.then(function (json) {

return gitlabRepo.getDependencies(parsed.owner, parsed.name, parsed.version, json)
.then(function (map) {
tree.props = fecom.parse(map.name);
Expand Down Expand Up @@ -167,8 +170,46 @@ Component.prototype = {
if (fs.existsSync(componentDir)) {
fse.removeSync(componentDir);
}
// Exclude files and directories
var componentJson = path.join(tmpDir, self.name, 'component.json');
var json = {};

if (fs.existsSync(componentJson)) {
json = jsonfile.readFileSync(componentJson);
}

self.exclude = json.exclude || [];

debugger;

var files = [];

if (self.exclude.length) {
self.exclude.forEach(function (pattern) {

if (!glob.hasMagic(pattern) && fs.lstatSync(path.join(tmpDir, self.name, pattern)).isDirectory()) {
files = files.concat(glob.sync(pattern, { cwd: path.join(tmpDir, self.name) }));
pattern += '/**/*';
}

files = files.concat(glob.sync(pattern, { cwd: path.join(tmpDir, self.name) }));
});
}

fse.copySync(path.join(tmpDir, self.name), componentDir);
files = files.map(function (file) {
return path.join(tmpDir, self.name, file);
});

fse.copySync(path.join(tmpDir, self.name), componentDir, {
filter: function (file) {
var isMatch;

if (files.indexOf(file) > -1) {
isMatch = true;
}
return !isMatch;
}
});

process.nextTick(function () {
fse.removeSync(tmpDir);
Expand Down
1 change: 0 additions & 1 deletion lib/component/mergeDependencies.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
var _ = require('lodash');

module.exports = function (newParsedList, oldParsedList) {
debugger;
var dependencies = _.unionWith(newParsedList, oldParsedList, function (newParsed, oldParsed) {
var isMatch = _.isMatch(newParsed, _.pick(oldParsed, ['name', 'owner']));

Expand Down
6 changes: 1 addition & 5 deletions lib/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ var analyze = require('./component/analyze');
var mergeDependencies = require('./component/mergeDependencies');

module.exports = function (semList, options) {
var installed, toInstall;

var parsedList = semList.map(function (str) {
return fecom.parse(str);
Expand All @@ -28,12 +27,9 @@ module.exports = function (semList, options) {
toInstall: getToInstall(parsedList)
})
.then(function (results) {
installed = results.installed;
toInstall = results.toInstall;
return analyze(results.toInstall, results.installed, 'ask');
})
.then(function (treeModel) {
debugger;
var toInstallAll = treeModel.getAllNodes().slice(1).filter(function (parsed) {
return !parsed.isInstalled;
}).map(function (parsed) {
Expand All @@ -51,7 +47,7 @@ module.exports = function (semList, options) {
return newInstalledList;
})
.catch(function (err) {
var _err = new Error(fecom.i18n('FAIL_TO_INSTALL_COMPONENTS', component.stringify()));
// var _err = new Error(fecom.i18n('FAIL_TO_INSTALL_COMPONENTS', component.stringify()));
fecom.errorHandler(err);
return newInstalledList;
});
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"commander": "^2.9.0",
"fs-extra": "^0.30.0",
"gitlab": "^1.6.0",
"glob": "^7.0.3",
"graceful-fs": "^4.1.4",
"ini": "^1.3.4",
"inquirer": "^1.0.2",
Expand All @@ -38,6 +39,7 @@
"liftoff": "^2.2.1",
"lodash": "^4.12.0",
"log4js": "^0.6.36",
"minimatch": "^3.0.0",
"os-locale": "^1.4.0",
"progress": "^1.1.8",
"semver": "^5.1.0",
Expand Down

0 comments on commit 3f9c947

Please sign in to comment.