@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 CHANGED
@@ -1,126 +1,164 @@
1
+ [English](README.md) | [中文](README-CN.md)
2
+
1
3
  # @yaoxfly/cli
2
- 干净极简的项目脚手架集成了`vue3`项目模板,`vitepress`项目模板等,开箱即用。
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
- # 使用 npx
10
+ # Use npx
6
11
 
7
- 无感知下载模板,无需安装`@yaoxfly/cli`。
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
- > 国内`npx`使用`npm`镜像下载可能会比慢,请切换其他镜像比如`taobao`镜像,可使用`nrm`管理,或其他方式,[镜像切换](#镜像切换)。
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 或者 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.默认是 `master` 分枝, 但你可以指定分枝和`tag` ,如 `owner/name#my-branch`。
47
- > 2.你还可以指定自定义来源,如`gitlab:custom.com:owner/name`. 自定义来源默认为 `https` 或 `git@` , 可自定义协议。
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
- 这种方式会跳过上面简写的方式,直接传递完整的 `url`。
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
- ## 使用nrm
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
- >`node`版本较低,高版本`nrm`可能无法使用。
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
- ## 使用npm
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
- 查看npm当前配置
119
+ View the current configuration of npm
109
120
  ```
110
121
  npm config list
111
122
  ```
112
123
 
113
- 设置npm镜像
124
+ Set up an npm image
114
125
  ```
115
126
  npm config set registry https://registry.npmjs.org/
116
127
  ```
117
128
 
118
- ## 使用.npmrc
119
- 根目录下,创建`.npmrc`写入下面内容
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: 'pnpm',
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
- const file = (0, fs_1.readFileSync)(filePath);
13
- return JSON.parse(file.toString());
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.5",
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
- }
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.2]、typeScript 、vite3、 pinia、 eslint、axios、mock、多环境"
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
@@ -1,3 +1,3 @@
1
1
  {
2
- "version": "1.0.5"
2
+ "version": "1.0.7"
3
3
  }