cmyr-template-cli 1.1.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/README.md +12 -0
- package/dist/plopfile.js +80 -18
- 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
|
-
|
|
19
|
-
const __DEV__ = env.NODE_ENV === 'development';
|
|
21
|
+
process.env;
|
|
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,21 +79,36 @@ 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"]('正在安装依赖……');
|
|
49
|
-
|
|
84
|
+
const { name, author, isOpenSource, isRemoveDependabot } = answers;
|
|
50
85
|
try {
|
|
51
86
|
await asyncExec('git --version', {
|
|
52
87
|
cwd: projectPath,
|
|
53
88
|
});
|
|
54
|
-
await asyncExec(
|
|
89
|
+
await asyncExec(`${PACKAGE_MANAGER} -v`, {
|
|
55
90
|
cwd: projectPath,
|
|
56
91
|
});
|
|
57
92
|
await asyncExec('git init', {
|
|
58
93
|
cwd: projectPath,
|
|
59
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
|
+
}
|
|
60
105
|
const pkgPath = path__default["default"].join(projectPath, 'package.json');
|
|
61
106
|
const pkg = await fs__default["default"].readJSON(pkgPath);
|
|
107
|
+
const pkgData = {
|
|
108
|
+
name,
|
|
109
|
+
author,
|
|
110
|
+
private: !isOpenSource,
|
|
111
|
+
};
|
|
62
112
|
const newPkg = Object.assign({}, pkg, pkgData);
|
|
63
113
|
await fs__default["default"].writeFile(pkgPath, JSON.stringify(newPkg, null, 2));
|
|
64
114
|
await asyncExec('git add .', {
|
|
@@ -67,7 +117,8 @@ async function init(projectPath, pkgData) {
|
|
|
67
117
|
await asyncExec('git commit -m "chore: init"', {
|
|
68
118
|
cwd: projectPath,
|
|
69
119
|
});
|
|
70
|
-
|
|
120
|
+
loading.start();
|
|
121
|
+
await asyncExec(`${PACKAGE_MANAGER} i`, {
|
|
71
122
|
cwd: projectPath,
|
|
72
123
|
});
|
|
73
124
|
await asyncExec('git add .', {
|
|
@@ -88,15 +139,10 @@ async function getGitUserName() {
|
|
|
88
139
|
|
|
89
140
|
module.exports = function (plop) {
|
|
90
141
|
plop.setActionType('initProject', async (answers) => {
|
|
91
|
-
const name = answers
|
|
92
|
-
const author = answers.author;
|
|
93
|
-
const template = answers.template;
|
|
142
|
+
const { name, template } = answers;
|
|
94
143
|
const projectPath = path__default["default"].join(process.cwd(), name);
|
|
95
|
-
await downloadGitRepo(`
|
|
96
|
-
await init(projectPath,
|
|
97
|
-
name,
|
|
98
|
-
author,
|
|
99
|
-
});
|
|
144
|
+
await downloadGitRepo(`CaoMeiYouRen/${template}`, projectPath);
|
|
145
|
+
await init(projectPath, answers);
|
|
100
146
|
return '- 下载项目模板成功!';
|
|
101
147
|
});
|
|
102
148
|
plop.setGenerator('create', {
|
|
@@ -110,7 +156,7 @@ module.exports = function (plop) {
|
|
|
110
156
|
validate(input) {
|
|
111
157
|
return input.trim().length !== 0;
|
|
112
158
|
},
|
|
113
|
-
default:
|
|
159
|
+
default: '',
|
|
114
160
|
filter: (e) => e.trim(),
|
|
115
161
|
},
|
|
116
162
|
{
|
|
@@ -120,7 +166,7 @@ module.exports = function (plop) {
|
|
|
120
166
|
validate(input) {
|
|
121
167
|
return input.trim().length !== 0;
|
|
122
168
|
},
|
|
123
|
-
default:
|
|
169
|
+
default: await getGitUserName(),
|
|
124
170
|
filter: (e) => e.trim(),
|
|
125
171
|
},
|
|
126
172
|
{
|
|
@@ -148,6 +194,22 @@ module.exports = function (plop) {
|
|
|
148
194
|
'github-action',
|
|
149
195
|
].map((e) => `${e}-template`);
|
|
150
196
|
},
|
|
197
|
+
default: '',
|
|
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
|
+
},
|
|
151
213
|
},
|
|
152
214
|
];
|
|
153
215
|
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.0",
|
|
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": {
|