Skip to content

Commit 66ca8ff

Browse files
committed
chore: upgrade update command
1 parent dc808ab commit 66ca8ff

File tree

1 file changed

+25
-26
lines changed

1 file changed

+25
-26
lines changed

src/plugins/commands/update/index.js

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ module.exports = function updateCommand(api, opts) {
1717
usage: 'micro-app update [options]',
1818
options: {
1919
'-': 'update all.',
20-
'-n <name>': 'only update <name>.',
20+
'--name <name>': 'only update <name>.',
2121
},
2222
details: `
2323
Examples:
@@ -27,7 +27,7 @@ Examples:
2727
micro-app update -n <name>
2828
`.trim(),
2929
}, args => {
30-
const name = args.n;
30+
const name = args.name;
3131
return updateMicro(api, name);
3232
});
3333
};
@@ -40,31 +40,32 @@ function updateMicro(api, name) {
4040
const currentNodeModulesPath = microAppConfig.nodeModulesPath;
4141
const currentPkgInfo = microAppConfig.package;
4242

43-
api.applyPluginHooks('beforeCommandUpdate', { name, logger, microsConfig });
43+
const options = {
44+
name, micros,
45+
};
46+
api.applyPluginHooks('beforeCommandUpdate', options);
47+
const _name = options.name;
48+
const _micros = options.micros;
4449

45-
if (micros.includes(name)) {
46-
const microConfig = microsConfig[name];
50+
if (_micros.includes(_name)) {
51+
const microConfig = microsConfig[_name];
4752
if (microConfig) {
4853
const root = microConfig.originalRoot || microConfig.root;
49-
if (!root.startsWith(currentNodeModulesPath)) {
50-
// 丢弃非 node_modules 中的地址
51-
return;
52-
}
53-
54-
const gitPath = (currentPkgInfo.devDependencies && currentPkgInfo.devDependencies[microConfig.packageName]) || (currentPkgInfo.dependencies && currentPkgInfo.dependencies[microConfig.packageName]) || false;
55-
if (gitPath) {
56-
logger.logo(`${chalk.yellow('Delete')}: ${root}`);
57-
shelljs.rm('-rf', root);
58-
shelljs.rm('-rf', path.join(microAppConfig.root, 'package-lock.json'));
59-
const spinner = logger.spinner(`Updating ${name} ...`);
60-
spinner.start();
61-
shelljs.exec(`npm install -D "${gitPath}"`);
62-
spinner.succeed(`${chalk.green('Update Finish!')}`);
63-
return;
54+
if (root.startsWith(currentNodeModulesPath)) { // 丢弃非 node_modules 中的地址
55+
const gitPath = (currentPkgInfo.devDependencies && currentPkgInfo.devDependencies[microConfig.packageName]) || (currentPkgInfo.dependencies && currentPkgInfo.dependencies[microConfig.packageName]) || false;
56+
if (gitPath) {
57+
logger.logo(`${chalk.yellow('Delete')}: ${root}`);
58+
shelljs.rm('-rf', root);
59+
shelljs.rm('-rf', path.join(microAppConfig.root, 'package-lock.json'));
60+
const spinner = logger.spinner(`Updating ${_name} ...`);
61+
spinner.start();
62+
shelljs.exec(`npm install -D "${gitPath}"`);
63+
spinner.succeed(`${chalk.green('Update Finish!')}`);
64+
}
6465
}
6566
}
66-
} else if (!name) { // all
67-
const gitPaths = micros.map(key => {
67+
} else if (!_name) { // all
68+
const gitPaths = _micros.map(key => {
6869
const microConfig = microsConfig[key];
6970
if (microConfig) {
7071
const root = microConfig.root;
@@ -96,15 +97,13 @@ function updateMicro(api, name) {
9697
}
9798

9899
logger.logo(`${chalk.green('Finish!')}`);
99-
return;
100100
} else {
101-
logger.error('[update]', `Not Found micros: "${name}"`);
101+
logger.error('[update]', `Not Found micros: "${_name}"`);
102102
}
103103

104-
api.applyPluginHooks('afterCommandUpdate', { name, logger, microsConfig });
104+
api.applyPluginHooks('afterCommandUpdate', options);
105105
}
106106

107-
108107
module.exports.configuration = {
109108
description: '强制更新 micros 依赖服务命令行',
110109
};

0 commit comments

Comments
 (0)