@yaoxfly/cli 1.0.5 → 1.0.7
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 +74 -36
- package/bin/create.js +45 -4
- package/bin/utils.js +25 -3
- package/package.json +54 -54
- package/template.json +15 -10
- package/version.json +1 -1
package/README.md
CHANGED
|
@@ -1,126 +1,164 @@
|
|
|
1
|
+
[English](README.md) | [中文](README-CN.md)
|
|
2
|
+
|
|
1
3
|
# @yaoxfly/cli
|
|
2
|
-
|
|
4
|
+
|
|
5
|
+
Clean and minimalist project scaffolding integrates`vue3` project templates,`vitepress ` project templates, etc., right out of the box.
|
|
6
|
+
|
|
7
|
+
> Compatibility note: The scaffolding uses `Vite` internally by default,`Vite` requires `Node.js` version ` 14.18+ `, `16+`. However, some templates rely on a higher version of `Node` to function properly, so be careful to upgrade your version of 'Node' when your package manager warns you. [node version switch](#node-version-switch)
|
|
3
8
|
|
|
4
9
|
|
|
5
|
-
#
|
|
10
|
+
# Use npx
|
|
6
11
|
|
|
7
|
-
|
|
12
|
+
No sense download template, no need to install `@yaoxfly/cli`.
|
|
8
13
|
|
|
9
14
|
```
|
|
10
|
-
npx @yaoxfly/cli@latest create [
|
|
15
|
+
npx @yaoxfly/cli@latest create [Project name]
|
|
11
16
|
|
|
12
17
|
```
|
|
13
18
|
|
|
14
|
-
>
|
|
19
|
+
> If the `npm` image downloads slowly, please switch other image such as `taobao` image, you can use `nrm` management, or other ways, [image switch](#image-switch).
|
|
15
20
|
|
|
16
|
-
# 创建工程
|
|
17
21
|
|
|
18
|
-
|
|
22
|
+
# Creation project
|
|
23
|
+
|
|
24
|
+
You can also download and then use, the current way can provide more comprehensive features, global download.
|
|
19
25
|
|
|
20
26
|
```
|
|
21
27
|
npm i @yaoxfly/cli -g
|
|
22
28
|
```
|
|
23
29
|
|
|
24
|
-
|
|
30
|
+
use
|
|
31
|
+
|
|
25
32
|
```
|
|
26
|
-
yx-cli create [
|
|
33
|
+
yx-cli create [Project name]
|
|
27
34
|
```
|
|
28
|
-
<a id='mirrorSwitching'></a>
|
|
29
35
|
|
|
36
|
+
# Add template
|
|
37
|
+
|
|
38
|
+
Add custom templates, such as your own `GitHub` or `Gitee` (code cloud) project address
|
|
30
39
|
|
|
31
|
-
# 添加模板
|
|
32
|
-
添加自定义的模板,比如自己`GitHub`或者`Gitee`(码云)上的项目地址
|
|
33
40
|
```
|
|
34
41
|
yx-cli add
|
|
35
42
|
```
|
|
36
43
|
|
|
37
|
-
####
|
|
44
|
+
#### Format of the template address
|
|
38
45
|
|
|
39
|
-
|
|
46
|
+
You can use the following shorthand
|
|
40
47
|
|
|
41
48
|
```
|
|
42
|
-
GitHub - github:owner/name
|
|
49
|
+
GitHub - github:owner/name or owner/name
|
|
43
50
|
GitLab - gitlab:owner/name
|
|
44
51
|
Bitbucket - bitbucket:owner/name
|
|
45
52
|
```
|
|
46
|
-
> 1
|
|
47
|
-
> 2
|
|
53
|
+
> 1.The default is `master` branching, but you can specify branching and `tag`, such as `owner/name#my-branch`.
|
|
54
|
+
> 2.You can also specify a custom source, such as ` gitlab:custom.com: owner/name `. Custom source default is `https` or `git@`, you can customize the protocol.
|
|
48
55
|
|
|
49
56
|
|
|
50
|
-
#### Direct - direct:url
|
|
57
|
+
#### Direct - direct:url
|
|
51
58
|
|
|
52
|
-
|
|
59
|
+
This method skips the above shorthand and passes the full `url`.
|
|
53
60
|
|
|
54
61
|
```
|
|
55
62
|
direct:https://gitlab.com/flippidippi/download-git-repo-fixture.git
|
|
56
63
|
```
|
|
57
64
|
|
|
58
|
-
> Gitee(
|
|
65
|
+
> Gitee(code cloud), private library address can be used in this way.
|
|
59
66
|
|
|
60
|
-
#
|
|
67
|
+
# Deleting a template
|
|
61
68
|
|
|
62
69
|
```
|
|
63
70
|
yx-cli delete
|
|
64
71
|
```
|
|
65
72
|
|
|
66
|
-
|
|
67
|
-
# 查看模板列表
|
|
73
|
+
# Viewing the Template list
|
|
68
74
|
|
|
69
75
|
```
|
|
70
76
|
yx-cli list
|
|
71
77
|
```
|
|
72
78
|
|
|
73
|
-
#
|
|
79
|
+
# image switch
|
|
74
80
|
|
|
75
|
-
##
|
|
81
|
+
## Use nrm
|
|
76
82
|
|
|
77
|
-
|
|
83
|
+
Global download
|
|
78
84
|
|
|
79
85
|
```
|
|
80
86
|
npm i nrm@1.0.0 -g
|
|
81
87
|
```
|
|
82
|
-
|
|
88
|
+
>A lower version of `node` and a higher version of `nrm` may not be available.
|
|
83
89
|
|
|
84
|
-
|
|
90
|
+
Viewing the image list
|
|
85
91
|
|
|
86
92
|
```
|
|
87
93
|
nrm ls
|
|
88
94
|
```
|
|
89
95
|
|
|
90
|
-
|
|
96
|
+
Using Taobao image
|
|
97
|
+
|
|
91
98
|
```
|
|
92
99
|
nrm use taobao
|
|
93
100
|
```
|
|
94
101
|
|
|
95
|
-
##
|
|
102
|
+
## Use npm
|
|
96
103
|
|
|
97
|
-
|
|
104
|
+
Set Taobao image
|
|
98
105
|
|
|
99
106
|
```
|
|
100
107
|
npm config set registry https://registry.npmmirror.com/
|
|
101
108
|
```
|
|
102
109
|
|
|
103
|
-
|
|
110
|
+
> `registry.npm.taobao.org`, which was abandoned on May 31, 2022, needs to be replaced with a new `registry.npmmirror.com` source.
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
Check whether the configuration is successful
|
|
114
|
+
|
|
104
115
|
```
|
|
105
116
|
npm config get registry
|
|
106
117
|
```
|
|
107
118
|
|
|
108
|
-
|
|
119
|
+
View the current configuration of npm
|
|
109
120
|
```
|
|
110
121
|
npm config list
|
|
111
122
|
```
|
|
112
123
|
|
|
113
|
-
|
|
124
|
+
Set up an npm image
|
|
114
125
|
```
|
|
115
126
|
npm config set registry https://registry.npmjs.org/
|
|
116
127
|
```
|
|
117
128
|
|
|
118
|
-
##
|
|
119
|
-
|
|
129
|
+
## Use .npmrc
|
|
130
|
+
In the root directory, create `.npmrc` and write the following
|
|
120
131
|
|
|
121
132
|
```
|
|
122
133
|
registry= https://registry.npmmirror.com/
|
|
123
134
|
```
|
|
124
135
|
|
|
125
136
|
|
|
137
|
+
# node version switch
|
|
138
|
+
|
|
139
|
+
#### Use `nvm` to manage your `node` version
|
|
126
140
|
|
|
141
|
+
[nvm download address](https://github.com/coreybutler/nvm-windows/releases)
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
Download the `vmm-setup. zip` version and install it as prompted.
|
|
145
|
+
|
|
146
|
+
#### To download node
|
|
147
|
+
|
|
148
|
+
This describes only windows systems.
|
|
149
|
+
|
|
150
|
+
When node is installed using the `nvm` command line, `nvm` will not install `npm` when the `node` version is` 8`or higher.
|
|
151
|
+
|
|
152
|
+
Download the corresponding version `zip` file from the [nodejs download website](https://registry.npmmirror.com/binary.html?path=node) and decompress it to the root directory of the `nvm` installation directory. Change the name of the decompressed folder to `v version number`
|
|
153
|
+
For example, the folder name after decompression is changed from `node-v16.13.1-win-x64` to `v16.13.1`.
|
|
154
|
+
|
|
155
|
+
View the downloaded version of `node`
|
|
156
|
+
|
|
157
|
+
```
|
|
158
|
+
nvm list
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
Use the corresponding version
|
|
162
|
+
```
|
|
163
|
+
nvm use [Version number]
|
|
164
|
+
```
|
package/bin/create.js
CHANGED
|
@@ -45,6 +45,7 @@ const download_git_repo_1 = __importDefault(require("download-git-repo"));
|
|
|
45
45
|
const log_symbols_1 = __importDefault(require("log-symbols"));
|
|
46
46
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
47
47
|
const utils_1 = require("./utils");
|
|
48
|
+
const child_process_1 = require("child_process");
|
|
48
49
|
const tips = (param) => {
|
|
49
50
|
const { install, installMode = 'pnpm', projectName } = param || {};
|
|
50
51
|
console.log(log_symbols_1.default.success, chalk_1.default.green('The project is initialized'));
|
|
@@ -53,7 +54,28 @@ const tips = (param) => {
|
|
|
53
54
|
!install && console.log(`\n ${installMode} install`);
|
|
54
55
|
console.log(`\n ${installMode === 'yarn' ? 'yarn dev' : `${installMode} run dev`} `);
|
|
55
56
|
};
|
|
57
|
+
const has = (0, utils_1.hasPackage)();
|
|
58
|
+
const iMode = () => {
|
|
59
|
+
if (has('pnpm'))
|
|
60
|
+
return 'pnpm';
|
|
61
|
+
if (has('yarn'))
|
|
62
|
+
return 'yarn';
|
|
63
|
+
return 'npm';
|
|
64
|
+
};
|
|
56
65
|
const create = (projectName, options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
66
|
+
if (!has('git')) {
|
|
67
|
+
console.log(chalk_1.default.red("Error, Git is not exsits ,please install git!"));
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
if (has('node')) {
|
|
71
|
+
let nodeVersion = (0, child_process_1.execSync)(`node --version`).toString();
|
|
72
|
+
nodeVersion = nodeVersion.substring(1, nodeVersion.length);
|
|
73
|
+
nodeVersion = parseInt(nodeVersion.split('.').join('').substring(0, 4));
|
|
74
|
+
if (nodeVersion < 1418) {
|
|
75
|
+
console.log(chalk_1.default.red("Error, node version must be at least v14.18.0!"));
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
57
79
|
const { force } = options || {};
|
|
58
80
|
if (!force && fs_1.default.existsSync(projectName)) {
|
|
59
81
|
console.log(chalk_1.default.red("Error, In this directory, the project name already exsits !"));
|
|
@@ -93,11 +115,11 @@ const create = (projectName, options) => __awaiter(void 0, void 0, void 0, funct
|
|
|
93
115
|
type: 'list',
|
|
94
116
|
message: '请选择一个安装方式',
|
|
95
117
|
name: 'installMode',
|
|
96
|
-
default:
|
|
118
|
+
default: iMode(),
|
|
97
119
|
choices: ['pnpm', 'npm', 'yarn'],
|
|
98
120
|
when: (answers) => {
|
|
99
|
-
const { install } = answers;
|
|
100
|
-
return install;
|
|
121
|
+
const { install, templateName } = answers;
|
|
122
|
+
return install && templateName !== 'monorope-component';
|
|
101
123
|
}
|
|
102
124
|
},
|
|
103
125
|
];
|
|
@@ -109,7 +131,7 @@ const create = (projectName, options) => __awaiter(void 0, void 0, void 0, funct
|
|
|
109
131
|
yield fs_extra_1.default.remove(projectName);
|
|
110
132
|
spinner.succeed();
|
|
111
133
|
}
|
|
112
|
-
const { templateName, description, author, install, installMode } = answers || {};
|
|
134
|
+
const { templateName, description, author, install, installMode = 'pnpm' } = answers || {};
|
|
113
135
|
const url = templateObj[templateName].url;
|
|
114
136
|
const direct = url.split(':')[0] === 'direct';
|
|
115
137
|
console.log(chalk_1.default.white('\n Start generating... \n'));
|
|
@@ -131,6 +153,25 @@ const create = (projectName, options) => __awaiter(void 0, void 0, void 0, funct
|
|
|
131
153
|
Object.assign(packageJsonData, meta);
|
|
132
154
|
fs_1.default.writeFileSync(filePath, JSON.stringify(packageJsonData, null, 2));
|
|
133
155
|
spinner.succeed();
|
|
156
|
+
const gitignorePath = `${projectName}/.gitignore`;
|
|
157
|
+
const fileContent = (0, utils_1.readFile)(`${projectName}/.gitignore`);
|
|
158
|
+
const newContent = fileContent
|
|
159
|
+
.split('\n')
|
|
160
|
+
.filter(line => !line.includes('pnpm-lock.yaml'))
|
|
161
|
+
.join('\n');
|
|
162
|
+
fs_1.default.writeFileSync(gitignorePath, newContent, 'utf-8');
|
|
163
|
+
try {
|
|
164
|
+
console.log(chalk_1.default.white('\n Start update... \n'));
|
|
165
|
+
const output = yield (0, child_process_1.execSync)(`npx npm-check-updates@16.14.20 -u --target semver --packageManager ${installMode}`, {
|
|
166
|
+
cwd: projectName,
|
|
167
|
+
encoding: 'utf-8',
|
|
168
|
+
stdio: 'inherit'
|
|
169
|
+
});
|
|
170
|
+
output && console.log('Command output:\n', output);
|
|
171
|
+
}
|
|
172
|
+
catch (error) {
|
|
173
|
+
console.error('Error executing command:\n', error.message);
|
|
174
|
+
}
|
|
134
175
|
if (install) {
|
|
135
176
|
const stdout = yield (0, utils_1.shellExec)({
|
|
136
177
|
directive: `${installMode} install --force`,
|
package/bin/utils.js
CHANGED
|
@@ -3,14 +3,22 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.resolve = exports.shellExec = exports.readFile = void 0;
|
|
6
|
+
exports.hasPackage = exports.resolve = exports.shellExec = exports.readFile = void 0;
|
|
7
7
|
const fs_1 = require("fs");
|
|
8
8
|
const ora_1 = __importDefault(require("ora"));
|
|
9
9
|
const child_process_1 = require("child_process");
|
|
10
10
|
const path_1 = __importDefault(require("path"));
|
|
11
11
|
const readFile = (filePath) => {
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
let file = null;
|
|
13
|
+
try {
|
|
14
|
+
file = (0, fs_1.readFileSync)(filePath);
|
|
15
|
+
file = JSON.parse(file.toString());
|
|
16
|
+
}
|
|
17
|
+
catch (error) {
|
|
18
|
+
file = (0, fs_1.readFileSync)(filePath);
|
|
19
|
+
file = file.toString('utf-8');
|
|
20
|
+
}
|
|
21
|
+
return file;
|
|
14
22
|
};
|
|
15
23
|
exports.readFile = readFile;
|
|
16
24
|
const shellExec = (config) => {
|
|
@@ -22,6 +30,7 @@ const shellExec = (config) => {
|
|
|
22
30
|
(0, child_process_1.exec)(directive, { cwd }, (error, stdout) => {
|
|
23
31
|
if (error) {
|
|
24
32
|
loading && spinner.fail();
|
|
33
|
+
console.log(stdout);
|
|
25
34
|
reject(error);
|
|
26
35
|
return;
|
|
27
36
|
}
|
|
@@ -33,3 +42,16 @@ const shellExec = (config) => {
|
|
|
33
42
|
exports.shellExec = shellExec;
|
|
34
43
|
const resolve = (...file) => path_1.default.resolve(__dirname, ...file);
|
|
35
44
|
exports.resolve = resolve;
|
|
45
|
+
const hasPackage = () => {
|
|
46
|
+
const fn = (tool) => {
|
|
47
|
+
try {
|
|
48
|
+
(0, child_process_1.execSync)(`${tool} --version`, { stdio: 'ignore' });
|
|
49
|
+
return true;
|
|
50
|
+
}
|
|
51
|
+
catch (e) {
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
return fn;
|
|
56
|
+
};
|
|
57
|
+
exports.hasPackage = hasPackage;
|
package/package.json
CHANGED
|
@@ -1,54 +1,54 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@yaoxfly/cli",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "脚手架工具,开箱即用",
|
|
5
|
-
"main": "bin",
|
|
6
|
-
"private": false,
|
|
7
|
-
"author": "yaoxfly",
|
|
8
|
-
"license": "MIT",
|
|
9
|
-
"scripts": {
|
|
10
|
-
"dev": "tsc -w",
|
|
11
|
-
"test": "echo \"Error: no test specified\" && exit 1",
|
|
12
|
-
"lint": "eslint . --ext .js,.ts, --fix",
|
|
13
|
-
"prepublishOnly": "node ./bin/version.js",
|
|
14
|
-
"publish": "npm version patch -f"
|
|
15
|
-
},
|
|
16
|
-
"bin": {
|
|
17
|
-
"yx-cli": "./bin/index.js"
|
|
18
|
-
},
|
|
19
|
-
"files": [
|
|
20
|
-
"bin",
|
|
21
|
-
"template.json",
|
|
22
|
-
"version.json"
|
|
23
|
-
],
|
|
24
|
-
"publishConfig": {
|
|
25
|
-
"access": "public"
|
|
26
|
-
},
|
|
27
|
-
"keywords": [
|
|
28
|
-
"cli",
|
|
29
|
-
"yaoxfly",
|
|
30
|
-
"vue",
|
|
31
|
-
"vitepress",
|
|
32
|
-
"vite"
|
|
33
|
-
],
|
|
34
|
-
"repository": {
|
|
35
|
-
"type": "git",
|
|
36
|
-
"url": "https://github.com/yaoxfly/yaoxfly-cli.git"
|
|
37
|
-
},
|
|
38
|
-
"devDependencies": {
|
|
39
|
-
"@types/node": "^18.8.5",
|
|
40
|
-
"@typescript-eslint/eslint-plugin": "^5.40.0",
|
|
41
|
-
"@typescript-eslint/parser": "^5.40.0",
|
|
42
|
-
"eslint": "^8.25.0",
|
|
43
|
-
"typescript": "
|
|
44
|
-
},
|
|
45
|
-
"dependencies": {
|
|
46
|
-
"chalk": "4.1.2",
|
|
47
|
-
"commander": "9.4.1",
|
|
48
|
-
"download-git-repo": "3.0.2",
|
|
49
|
-
"fs-extra": "10.1.0",
|
|
50
|
-
"inquirer": "8.0.0",
|
|
51
|
-
"log-symbols": "4.0.0",
|
|
52
|
-
"ora": "5.2.0"
|
|
53
|
-
}
|
|
54
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@yaoxfly/cli",
|
|
3
|
+
"version": "1.0.7",
|
|
4
|
+
"description": "脚手架工具,开箱即用",
|
|
5
|
+
"main": "bin",
|
|
6
|
+
"private": false,
|
|
7
|
+
"author": "yaoxfly",
|
|
8
|
+
"license": "MIT",
|
|
9
|
+
"scripts": {
|
|
10
|
+
"dev": "tsc -w",
|
|
11
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
|
12
|
+
"lint": "eslint . --ext .js,.ts, --fix",
|
|
13
|
+
"prepublishOnly": "node ./bin/version.js",
|
|
14
|
+
"publish": "npm version patch -f"
|
|
15
|
+
},
|
|
16
|
+
"bin": {
|
|
17
|
+
"yx-cli": "./bin/index.js"
|
|
18
|
+
},
|
|
19
|
+
"files": [
|
|
20
|
+
"bin",
|
|
21
|
+
"template.json",
|
|
22
|
+
"version.json"
|
|
23
|
+
],
|
|
24
|
+
"publishConfig": {
|
|
25
|
+
"access": "public"
|
|
26
|
+
},
|
|
27
|
+
"keywords": [
|
|
28
|
+
"cli",
|
|
29
|
+
"yaoxfly",
|
|
30
|
+
"vue",
|
|
31
|
+
"vitepress",
|
|
32
|
+
"vite"
|
|
33
|
+
],
|
|
34
|
+
"repository": {
|
|
35
|
+
"type": "git",
|
|
36
|
+
"url": "https://github.com/yaoxfly/yaoxfly-cli.git"
|
|
37
|
+
},
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"@types/node": "^18.8.5",
|
|
40
|
+
"@typescript-eslint/eslint-plugin": "^5.40.0",
|
|
41
|
+
"@typescript-eslint/parser": "^5.40.0",
|
|
42
|
+
"eslint": "^8.25.0",
|
|
43
|
+
"typescript": "4.8.4"
|
|
44
|
+
},
|
|
45
|
+
"dependencies": {
|
|
46
|
+
"chalk": "4.1.2",
|
|
47
|
+
"commander": "9.4.1",
|
|
48
|
+
"download-git-repo": "3.0.2",
|
|
49
|
+
"fs-extra": "10.1.0",
|
|
50
|
+
"inquirer": "8.0.0",
|
|
51
|
+
"log-symbols": "4.0.0",
|
|
52
|
+
"ora": "5.2.0"
|
|
53
|
+
}
|
|
54
|
+
}
|
package/template.json
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
|
-
{
|
|
2
|
-
"vue3-simple-frame": {
|
|
3
|
-
"url": "yaoxfly/vue3-simple-frame",
|
|
4
|
-
"description": "[vue3.
|
|
5
|
-
},
|
|
6
|
-
"vitepress-template": {
|
|
7
|
-
"url": "yaoxfly/vitepress-template",
|
|
8
|
-
"description": "[vitepress]、typeScript、vue3
|
|
9
|
-
}
|
|
10
|
-
|
|
1
|
+
{
|
|
2
|
+
"vue3-simple-frame": {
|
|
3
|
+
"url": "yaoxfly/vue3-simple-frame",
|
|
4
|
+
"description": "[vue3.x]、typeScript 、vite3、pinia、eslint、axios、mock、multiple environments"
|
|
5
|
+
},
|
|
6
|
+
"vitepress-template": {
|
|
7
|
+
"url": "yaoxfly/vitepress-template",
|
|
8
|
+
"description": "[vitepress]、typeScript、vue3、Custom Theme"
|
|
9
|
+
},
|
|
10
|
+
|
|
11
|
+
"monorope-component": {
|
|
12
|
+
"url": "yaoxfly/monorope-component",
|
|
13
|
+
"description": "[monorope]、typeScript、vue3、vite、pnpm"
|
|
14
|
+
}
|
|
15
|
+
}
|
package/version.json
CHANGED