Skip to content

Commit e4330fc

Browse files
committed
feat(init): 添加xta/none init选项
1 parent 748b4e3 commit e4330fc

File tree

2 files changed

+29
-17
lines changed

2 files changed

+29
-17
lines changed

lib/commands/init.js

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,13 @@ exports.run = function (options) {
3030
type: 'list',
3131
name: 'type',
3232
message: 'config type:',
33-
choices: ['qunar', 'hy']
33+
choices: ['qunar', 'hy', 'xta', 'none']
3434
}];
3535

3636
inquirer.prompt(questions).then(function (answers) {
3737
answers.name = answers.name || defaultName;
3838

3939
var initTmplPath = sysPath.resolve(__dirname, '../config/initTmpl/');
40-
var configFileName = 'ykit.' + answers.type + '.js';
4140
var writePackageJsonStream = void 0;
4241

4342
// 如果没有package.json,先添加package.json
@@ -46,22 +45,24 @@ exports.run = function (options) {
4645
}
4746

4847
if (!writePackageJsonStream) {
49-
createConfigFile();
48+
createConfigFile(answers.type);
5049
installDependencies();
5150
} else {
5251
writePackageJsonStream.on('finish', function () {
5352
log('Successfully created package.json file in ' + cwd);
5453

55-
createConfigFile();
56-
installDependencies();
54+
createConfigFile(answers.type);
55+
installDependencies(answers.type);
5756
});
5857
}
5958

6059
function createPakcageJson() {
6160
return fs.createReadStream(sysPath.resolve(initTmplPath, 'package.json')).pipe(replaceStream('#_name', answers.name)).pipe(fs.createWriteStream(sysPath.resolve(cwd, 'package.json')));
6261
}
6362

64-
function createConfigFile() {
63+
function createConfigFile(configType) {
64+
var configFileName = configType !== 'none' ? 'ykit.' + configType + '.js' : 'ykit.js';
65+
6566
if (!fileExists('./' + configFileName)) {
6667
var stream = fs.createReadStream(sysPath.resolve(initTmplPath, 'ykit.common.js')).pipe(replaceStream('#_name', answers.name)).pipe(fs.createWriteStream(sysPath.resolve(cwd, configFileName)));
6768

@@ -71,9 +72,13 @@ exports.run = function (options) {
7172
}
7273
}
7374

74-
function installDependencies() {
75-
var packageName = 'ykit-config-' + answers.type,
76-
installConfigPackageCmd = 'npm i --save git+ssh://git@gitlab.corp.qunar.com:mfe/ykit-config-' + answers.type + '.git';
75+
function installDependencies(configType) {
76+
if (configType === 'none') {
77+
return;
78+
}
79+
80+
var packageName = 'ykit-config-' + configType,
81+
installConfigPackageCmd = 'npm i --save git+ssh://git@gitlab.corp.qunar.com:mfe/ykit-config-' + configType + '.git';
7782

7883
log('Installing ' + packageName + '...');
7984
execSync(installConfigPackageCmd);

src/commands/init.js

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,15 @@ exports.run = function (options) {
3333
choices: [
3434
'qunar',
3535
'hy',
36+
'xta',
37+
'none',
3638
]
3739
}]
3840

3941
inquirer.prompt(questions).then((answers) => {
4042
answers.name = answers.name || defaultName;
4143

4244
const initTmplPath = sysPath.resolve(__dirname, '../config/initTmpl/');
43-
const configFileName = 'ykit.' + answers.type + '.js';
4445
let writePackageJsonStream;
4546

4647
// 如果没有package.json,先添加package.json
@@ -49,14 +50,14 @@ exports.run = function (options) {
4950
}
5051

5152
if(!writePackageJsonStream) {
52-
createConfigFile();
53+
createConfigFile(answers.type);
5354
installDependencies();
5455
} else {
5556
writePackageJsonStream.on('finish', () => {
5657
log('Successfully created package.json file in ' + cwd);
5758

58-
createConfigFile();
59-
installDependencies();
59+
createConfigFile(answers.type);
60+
installDependencies(answers.type);
6061
});
6162
}
6263

@@ -66,7 +67,9 @@ exports.run = function (options) {
6667
.pipe(fs.createWriteStream(sysPath.resolve(cwd, 'package.json')));
6768
}
6869

69-
function createConfigFile() {
70+
function createConfigFile(configType) {
71+
const configFileName = configType !== 'none' ? 'ykit.' + configType + '.js' : 'ykit.js';
72+
7073
if(!fileExists('./' + configFileName)) {
7174
const stream = fs.createReadStream(sysPath.resolve(initTmplPath, 'ykit.common.js'))
7275
.pipe(replaceStream('#_name', answers.name))
@@ -78,9 +81,13 @@ exports.run = function (options) {
7881
}
7982
}
8083

81-
function installDependencies() {
82-
const packageName = 'ykit-config-' + answers.type,
83-
installConfigPackageCmd = 'npm i --save git+ssh://git@gitlab.corp.qunar.com:mfe/ykit-config-' + answers.type + '.git';
84+
function installDependencies(configType) {
85+
if(configType === 'none') {
86+
return
87+
}
88+
89+
const packageName = 'ykit-config-' + configType,
90+
installConfigPackageCmd = 'npm i --save git+ssh://git@gitlab.corp.qunar.com:mfe/ykit-config-' + configType + '.git';
8491

8592
log('Installing ' + packageName + '...');
8693
execSync(installConfigPackageCmd);

0 commit comments

Comments
 (0)