cmyr-template-cli 1.2.0 → 1.4.1
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/README.md +12 -0
- package/dist/plopfile.js +87 -14
- package/package.json +7 -3
package/README.md
CHANGED
package/dist/plopfile.js
CHANGED
|
@@ -5,7 +5,9 @@ var path = require('path');
|
|
|
5
5
|
var fs = require('fs-extra');
|
|
6
6
|
var ora = require('ora');
|
|
7
7
|
var download = require('download-git-repo');
|
|
8
|
+
var axios = require('axios');
|
|
8
9
|
var child_process = require('child_process');
|
|
10
|
+
var any = require('promise.any');
|
|
9
11
|
|
|
10
12
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
11
13
|
|
|
@@ -13,16 +15,27 @@ var path__default = /*#__PURE__*/_interopDefaultLegacy(path);
|
|
|
13
15
|
var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);
|
|
14
16
|
var ora__default = /*#__PURE__*/_interopDefaultLegacy(ora);
|
|
15
17
|
var download__default = /*#__PURE__*/_interopDefaultLegacy(download);
|
|
18
|
+
var axios__default = /*#__PURE__*/_interopDefaultLegacy(axios);
|
|
19
|
+
var any__default = /*#__PURE__*/_interopDefaultLegacy(any);
|
|
16
20
|
|
|
17
|
-
|
|
18
|
-
const __DEV__ = env.NODE_ENV === 'development';
|
|
21
|
+
process.env;
|
|
19
22
|
const PACKAGE_MANAGER = 'pnpm';
|
|
20
23
|
|
|
24
|
+
if (!Promise.any) {
|
|
25
|
+
Promise.any = any__default["default"];
|
|
26
|
+
}
|
|
27
|
+
const REMOTES = [
|
|
28
|
+
'https://github.com',
|
|
29
|
+
'https://hub.fastgit.org',
|
|
30
|
+
'https://gitclone.com',
|
|
31
|
+
'https://github.com.cnpmjs.org',
|
|
32
|
+
];
|
|
21
33
|
async function downloadGitRepo(repository, destination, options = {}) {
|
|
34
|
+
const fastRepo = await getFastGitRepo(repository);
|
|
22
35
|
const loading = ora__default["default"](`download - ${repository}`);
|
|
23
36
|
loading.start();
|
|
24
37
|
return new Promise((resolve, reject) => {
|
|
25
|
-
download__default["default"](
|
|
38
|
+
download__default["default"](fastRepo, destination, options, (err) => {
|
|
26
39
|
loading.stop();
|
|
27
40
|
if (err) {
|
|
28
41
|
return reject(err);
|
|
@@ -31,6 +44,28 @@ async function downloadGitRepo(repository, destination, options = {}) {
|
|
|
31
44
|
});
|
|
32
45
|
});
|
|
33
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
|
+
}
|
|
34
69
|
async function asyncExec(cmd, options) {
|
|
35
70
|
return new Promise((resolve, reject) => {
|
|
36
71
|
child_process.exec(cmd, options, (err, stdout, stderr) => {
|
|
@@ -44,8 +79,9 @@ async function asyncExec(cmd, options) {
|
|
|
44
79
|
});
|
|
45
80
|
});
|
|
46
81
|
}
|
|
47
|
-
async function init(projectPath,
|
|
82
|
+
async function init(projectPath, answers) {
|
|
48
83
|
const loading = ora__default["default"]('正在安装依赖……');
|
|
84
|
+
const { name, author, description, isOpenSource, isRemoveDependabot } = answers;
|
|
49
85
|
try {
|
|
50
86
|
await asyncExec('git --version', {
|
|
51
87
|
cwd: projectPath,
|
|
@@ -56,8 +92,24 @@ async function init(projectPath, pkgData) {
|
|
|
56
92
|
await asyncExec('git init', {
|
|
57
93
|
cwd: projectPath,
|
|
58
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
|
+
}
|
|
59
105
|
const pkgPath = path__default["default"].join(projectPath, 'package.json');
|
|
60
106
|
const pkg = await fs__default["default"].readJSON(pkgPath);
|
|
107
|
+
const pkgData = {
|
|
108
|
+
name,
|
|
109
|
+
author,
|
|
110
|
+
description,
|
|
111
|
+
private: !isOpenSource,
|
|
112
|
+
};
|
|
61
113
|
const newPkg = Object.assign({}, pkg, pkgData);
|
|
62
114
|
await fs__default["default"].writeFile(pkgPath, JSON.stringify(newPkg, null, 2));
|
|
63
115
|
await asyncExec('git add .', {
|
|
@@ -88,15 +140,10 @@ async function getGitUserName() {
|
|
|
88
140
|
|
|
89
141
|
module.exports = function (plop) {
|
|
90
142
|
plop.setActionType('initProject', async (answers) => {
|
|
91
|
-
const name = answers
|
|
92
|
-
const author = answers.author;
|
|
93
|
-
const template = answers.template;
|
|
143
|
+
const { name, template } = answers;
|
|
94
144
|
const projectPath = path__default["default"].join(process.cwd(), name);
|
|
95
|
-
await downloadGitRepo(`
|
|
96
|
-
await init(projectPath,
|
|
97
|
-
name,
|
|
98
|
-
author,
|
|
99
|
-
});
|
|
145
|
+
await downloadGitRepo(`CaoMeiYouRen/${template}`, projectPath);
|
|
146
|
+
await init(projectPath, answers);
|
|
100
147
|
return '- 下载项目模板成功!';
|
|
101
148
|
});
|
|
102
149
|
plop.setGenerator('create', {
|
|
@@ -110,7 +157,17 @@ module.exports = function (plop) {
|
|
|
110
157
|
validate(input) {
|
|
111
158
|
return input.trim().length !== 0;
|
|
112
159
|
},
|
|
113
|
-
default:
|
|
160
|
+
default: '',
|
|
161
|
+
filter: (e) => e.trim(),
|
|
162
|
+
},
|
|
163
|
+
{
|
|
164
|
+
type: 'input',
|
|
165
|
+
name: 'description',
|
|
166
|
+
message: '请输入项目简介',
|
|
167
|
+
transformer(input) {
|
|
168
|
+
return (input === null || input === void 0 ? void 0 : input.trim()) || '';
|
|
169
|
+
},
|
|
170
|
+
default: '',
|
|
114
171
|
filter: (e) => e.trim(),
|
|
115
172
|
},
|
|
116
173
|
{
|
|
@@ -120,7 +177,7 @@ module.exports = function (plop) {
|
|
|
120
177
|
validate(input) {
|
|
121
178
|
return input.trim().length !== 0;
|
|
122
179
|
},
|
|
123
|
-
default:
|
|
180
|
+
default: await getGitUserName(),
|
|
124
181
|
filter: (e) => e.trim(),
|
|
125
182
|
},
|
|
126
183
|
{
|
|
@@ -148,6 +205,22 @@ module.exports = function (plop) {
|
|
|
148
205
|
'github-action',
|
|
149
206
|
].map((e) => `${e}-template`);
|
|
150
207
|
},
|
|
208
|
+
default: '',
|
|
209
|
+
},
|
|
210
|
+
{
|
|
211
|
+
type: 'confirm',
|
|
212
|
+
name: 'isOpenSource',
|
|
213
|
+
message: '是否开源?',
|
|
214
|
+
default: false,
|
|
215
|
+
},
|
|
216
|
+
{
|
|
217
|
+
type: 'confirm',
|
|
218
|
+
name: 'isRemoveDependabot',
|
|
219
|
+
message: '是否移除 github-dependabot ?',
|
|
220
|
+
default: false,
|
|
221
|
+
when(answers) {
|
|
222
|
+
return answers.isOpenSource;
|
|
223
|
+
},
|
|
151
224
|
},
|
|
152
225
|
];
|
|
153
226
|
return inquirer.prompt(questions);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cmyr-template-cli",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.1",
|
|
4
4
|
"description": "草梅友仁自制的项目模板创建器",
|
|
5
5
|
"author": "CaoMeiYouRen",
|
|
6
6
|
"license": "MIT",
|
|
@@ -27,13 +27,14 @@
|
|
|
27
27
|
"release": "semantic-release",
|
|
28
28
|
"commit": "git add . && git cz",
|
|
29
29
|
"create": "ct create",
|
|
30
|
-
"build:dev": "
|
|
30
|
+
"build:dev": "rimraf dist && cross-env NODE_ENV=development rollup -c && rimraf temp && cross-env NODE_ENV=development ct create",
|
|
31
31
|
"build:prod": "npm run build && rimraf temp && cross-env NODE_ENV=production ct create"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"@rollup/plugin-commonjs": "^21.0.0",
|
|
35
35
|
"@rollup/plugin-json": "^4.1.0",
|
|
36
36
|
"@rollup/plugin-node-resolve": "^13.0.5",
|
|
37
|
+
"@rollup/plugin-replace": "^3.0.0",
|
|
37
38
|
"@rollup/plugin-typescript": "^8.0.0",
|
|
38
39
|
"@semantic-release/changelog": "^6.0.0",
|
|
39
40
|
"@semantic-release/git": "^10.0.0",
|
|
@@ -41,6 +42,7 @@
|
|
|
41
42
|
"@types/fs-extra": "^9.0.4",
|
|
42
43
|
"@types/lodash": "^4.14.165",
|
|
43
44
|
"@types/node": "^16.9.6",
|
|
45
|
+
"@types/promise.any": "^2.0.0",
|
|
44
46
|
"@typescript-eslint/eslint-plugin": "^4.9.0",
|
|
45
47
|
"@typescript-eslint/parser": "^4.9.0",
|
|
46
48
|
"commitizen": "^4.2.2",
|
|
@@ -64,6 +66,7 @@
|
|
|
64
66
|
"validate-commit-msg": "^2.14.0"
|
|
65
67
|
},
|
|
66
68
|
"dependencies": {
|
|
69
|
+
"axios": "^0.24.0",
|
|
67
70
|
"colors": "^1.4.0",
|
|
68
71
|
"commander": "^8.2.0",
|
|
69
72
|
"dayjs": "^1.9.6",
|
|
@@ -71,7 +74,8 @@
|
|
|
71
74
|
"fs-extra": "^10.0.0",
|
|
72
75
|
"minimist": "^1.2.5",
|
|
73
76
|
"ora": "^5.4.1",
|
|
74
|
-
"plop": "^2.7.6"
|
|
77
|
+
"plop": "^2.7.6",
|
|
78
|
+
"promise.any": "^2.0.2"
|
|
75
79
|
},
|
|
76
80
|
"config": {
|
|
77
81
|
"commitizen": {
|