Skip to content

Commit

Permalink
support subproject inside another subproject
Browse files Browse the repository at this point in the history
  • Loading branch information
lcxfs1991 committed Jun 24, 2016
1 parent 7016b6d commit 9bb2b9f
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 10 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ var steamerConfig = {
},
repos: { // 自己想加入steamer管理的boilerplate
"react-cdk": {
git: "react-cdk", // 默认源文位位置,可以通过npm --install --name [localName]的localName更改
git: "react-cdk",
config: {
src: "./react-cdk/",
src: "./react-cdk/", // 默认源文位位置,可以通过npm --install --name [localName]的localName更改
cmds: {
dev: "npm run dev",
pub: "npm run pub",
Expand Down
4 changes: 1 addition & 3 deletions libs/SteamerGet.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function updateConfig(repo, localName) {
repoConfig = repos[repo].config;

repoConfig.src = path.resolve(localName);
config.projects[localName] = repoConfig;
config.projects[path.basename(localName)] = repoConfig;

let configStr = 'var steamerConfig = ' + JSON.stringify(config, null, 4)
+ '\n ' + 'module.exports = steamerConfig;';
Expand All @@ -36,8 +36,6 @@ module.exports = function(steamerConfig) {
localName = argv.name || argv.get;
localName = localName.replace('\\', '').replace('./', '').replace('.', '');

console.log(steamerConfig.hasOwnProperty('repos'));

if (steamerConfig.hasOwnProperty('repos')) {
repos = _.merge(repos, steamerConfig.repos);
}
Expand Down
25 changes: 21 additions & 4 deletions libs/SteamerInstall.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,23 @@ function installPkg(paths, projects) {
runNpn(paths[0], 0);
}

/**
* Search Main Project Path
* @return {[type]} [description]
*/
function getMainProjectPath() {
let basePath = path.resolve(),
key = '';

while (1) {
key = path.basename(basePath);
if (!projectConfig.hasOwnProperty(key)) {
return basePath;
}
basePath = path.dirname(basePath);
}
};

/**
* execute installation command
* @return {[type]} [description]
Expand All @@ -86,8 +103,8 @@ function execIntall() {
// projectNodeVers.push(project.node || defaultNodeVer);
});

let packageJson = {},
mainPackageJson = {};
let packageJson = {}, // subproject package.json
mainPackageJson = {}; // main project package.json

projectSrc.map((item, key) => {
let packageJsonPath = path.join(item, 'package.json');
Expand All @@ -99,8 +116,8 @@ function execIntall() {
packageJson[key] = require(packageJsonPath);
});

mainPackageJson = require(path.resolve("package.json"));

mainPackageJson = require(path.join(getMainProjectPath(), "package.json"));
// main project gets value of dependencies and devDependencies from subprojects
projectSrc.map((item, key) => {
let diffDependencies = _.difference(_.keys(packageJson[key].dependencies), _.keys(mainPackageJson.dependencies)),
Expand Down
11 changes: 10 additions & 1 deletion libs/SteamerRemove.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,21 @@ function RemoveProject(project) {
throw new Warning.FolderNotExistErr(folderPath);
}

fs.remove(folderPath);
Logger.log(project + " is being deleted");

fs.removeSync(folderPath);

let config = require(path.resolve('steamer.config.js'));

if (config.projects.hasOwnProperty(project)) {
delete config.projects[project];

Object.keys(config.projects).map((item, index) => {
if (!fs.existsSync(config.projects[item].src)) {
delete config.projects[item];
}
});

let configStr = 'var steamerConfig = ' + JSON.stringify(config, null, 4)
+ '\n ' + 'module.exports = steamerConfig;';

Expand Down

0 comments on commit 9bb2b9f

Please sign in to comment.