From 9bb2b9f55348dd464b6c2e3fd1a47b1cf0d845d8 Mon Sep 17 00:00:00 2001 From: lcxfs1991 Date: Fri, 24 Jun 2016 11:08:24 +0800 Subject: [PATCH] support subproject inside another subproject --- README.md | 4 ++-- libs/SteamerGet.js | 4 +--- libs/SteamerInstall.js | 25 +++++++++++++++++++++---- libs/SteamerRemove.js | 11 ++++++++++- 4 files changed, 34 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 3745a2e..9e2b21f 100755 --- a/README.md +++ b/README.md @@ -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", diff --git a/libs/SteamerGet.js b/libs/SteamerGet.js index 29f2e48..21f53ed 100644 --- a/libs/SteamerGet.js +++ b/libs/SteamerGet.js @@ -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;'; @@ -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); } diff --git a/libs/SteamerInstall.js b/libs/SteamerInstall.js index e01c8d7..f7adcec 100644 --- a/libs/SteamerInstall.js +++ b/libs/SteamerInstall.js @@ -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] @@ -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'); @@ -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)), diff --git a/libs/SteamerRemove.js b/libs/SteamerRemove.js index 7e412a4..0fc4fda 100644 --- a/libs/SteamerRemove.js +++ b/libs/SteamerRemove.js @@ -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;';