cmyr-template-cli 1.3.1 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/plopfile.js +56 -30
- package/package.json +1 -1
package/dist/plopfile.js
CHANGED
|
@@ -44,6 +44,28 @@ async function downloadGitRepo(repository, destination, options = {}) {
|
|
|
44
44
|
});
|
|
45
45
|
});
|
|
46
46
|
}
|
|
47
|
+
async function getFastGitRepo(repository) {
|
|
48
|
+
const loading = ora__default["default"](`正在选择镜像源 - ${repository}`);
|
|
49
|
+
loading.start();
|
|
50
|
+
try {
|
|
51
|
+
const fast = await Promise.any(REMOTES.map((remote) => {
|
|
52
|
+
const url = `${remote}/${repository}/archive/refs/heads/master.zip`;
|
|
53
|
+
return axios__default["default"]({
|
|
54
|
+
url,
|
|
55
|
+
method: 'HEAD',
|
|
56
|
+
timeout: 15 * 1000,
|
|
57
|
+
});
|
|
58
|
+
}));
|
|
59
|
+
return `direct:${fast.config.url}`;
|
|
60
|
+
}
|
|
61
|
+
catch (error) {
|
|
62
|
+
console.error(error);
|
|
63
|
+
process.exit(1);
|
|
64
|
+
}
|
|
65
|
+
finally {
|
|
66
|
+
loading.stop();
|
|
67
|
+
}
|
|
68
|
+
}
|
|
47
69
|
async function asyncExec(cmd, options) {
|
|
48
70
|
return new Promise((resolve, reject) => {
|
|
49
71
|
child_process.exec(cmd, options, (err, stdout, stderr) => {
|
|
@@ -57,8 +79,9 @@ async function asyncExec(cmd, options) {
|
|
|
57
79
|
});
|
|
58
80
|
});
|
|
59
81
|
}
|
|
60
|
-
async function init(projectPath,
|
|
82
|
+
async function init(projectPath, answers) {
|
|
61
83
|
const loading = ora__default["default"]('正在安装依赖……');
|
|
84
|
+
const { name, author, isOpenSource, isRemoveDependabot } = answers;
|
|
62
85
|
try {
|
|
63
86
|
await asyncExec('git --version', {
|
|
64
87
|
cwd: projectPath,
|
|
@@ -69,8 +92,23 @@ async function init(projectPath, pkgData) {
|
|
|
69
92
|
await asyncExec('git init', {
|
|
70
93
|
cwd: projectPath,
|
|
71
94
|
});
|
|
95
|
+
const dependabotPath = path__default["default"].join(projectPath, '.github/dependabot.yml');
|
|
96
|
+
const mergifyPath = path__default["default"].join(projectPath, '.github/mergify.yml');
|
|
97
|
+
if (!isOpenSource || isRemoveDependabot) {
|
|
98
|
+
if (await fs__default["default"].pathExists(dependabotPath)) {
|
|
99
|
+
await fs__default["default"].remove(dependabotPath);
|
|
100
|
+
}
|
|
101
|
+
if (await fs__default["default"].pathExists(mergifyPath)) {
|
|
102
|
+
await fs__default["default"].remove(mergifyPath);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
72
105
|
const pkgPath = path__default["default"].join(projectPath, 'package.json');
|
|
73
106
|
const pkg = await fs__default["default"].readJSON(pkgPath);
|
|
107
|
+
const pkgData = {
|
|
108
|
+
name,
|
|
109
|
+
author,
|
|
110
|
+
private: !isOpenSource,
|
|
111
|
+
};
|
|
74
112
|
const newPkg = Object.assign({}, pkg, pkgData);
|
|
75
113
|
await fs__default["default"].writeFile(pkgPath, JSON.stringify(newPkg, null, 2));
|
|
76
114
|
await asyncExec('git add .', {
|
|
@@ -98,40 +136,13 @@ async function getGitUserName() {
|
|
|
98
136
|
const username = (await asyncExec('git config user.name'));
|
|
99
137
|
return username.trim();
|
|
100
138
|
}
|
|
101
|
-
async function getFastGitRepo(repository) {
|
|
102
|
-
const loading = ora__default["default"](`正在选择镜像源 - ${repository}`);
|
|
103
|
-
loading.start();
|
|
104
|
-
try {
|
|
105
|
-
const fast = await Promise.any(REMOTES.map((remote) => {
|
|
106
|
-
const url = `${remote}/${repository}/archive/refs/heads/master.zip`;
|
|
107
|
-
return axios__default["default"]({
|
|
108
|
-
url,
|
|
109
|
-
method: 'HEAD',
|
|
110
|
-
timeout: 15 * 1000,
|
|
111
|
-
});
|
|
112
|
-
}));
|
|
113
|
-
return `direct:${fast.config.url}`;
|
|
114
|
-
}
|
|
115
|
-
catch (error) {
|
|
116
|
-
console.error(error);
|
|
117
|
-
process.exit(1);
|
|
118
|
-
}
|
|
119
|
-
finally {
|
|
120
|
-
loading.stop();
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
139
|
|
|
124
140
|
module.exports = function (plop) {
|
|
125
141
|
plop.setActionType('initProject', async (answers) => {
|
|
126
|
-
const name = answers
|
|
127
|
-
const author = answers.author;
|
|
128
|
-
const template = answers.template;
|
|
142
|
+
const { name, template } = answers;
|
|
129
143
|
const projectPath = path__default["default"].join(process.cwd(), name);
|
|
130
144
|
await downloadGitRepo(`CaoMeiYouRen/${template}`, projectPath);
|
|
131
|
-
await init(projectPath,
|
|
132
|
-
name,
|
|
133
|
-
author,
|
|
134
|
-
});
|
|
145
|
+
await init(projectPath, answers);
|
|
135
146
|
return '- 下载项目模板成功!';
|
|
136
147
|
});
|
|
137
148
|
plop.setGenerator('create', {
|
|
@@ -185,6 +196,21 @@ module.exports = function (plop) {
|
|
|
185
196
|
},
|
|
186
197
|
default: '',
|
|
187
198
|
},
|
|
199
|
+
{
|
|
200
|
+
type: 'confirm',
|
|
201
|
+
name: 'isOpenSource',
|
|
202
|
+
message: '是否开源?',
|
|
203
|
+
default: false,
|
|
204
|
+
},
|
|
205
|
+
{
|
|
206
|
+
type: 'confirm',
|
|
207
|
+
name: 'isRemoveDependabot',
|
|
208
|
+
message: '是否移除 github-dependabot ?',
|
|
209
|
+
default: false,
|
|
210
|
+
when(answers) {
|
|
211
|
+
return answers.isOpenSource;
|
|
212
|
+
},
|
|
213
|
+
},
|
|
188
214
|
];
|
|
189
215
|
return inquirer.prompt(questions);
|
|
190
216
|
},
|