@oinone/cli 7.2.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 +115 -0
- package/README_zh-CN.md +115 -0
- package/bin/cli.js +429 -0
- package/package.json +25 -0
- package/template-6.4.0-community/.eslintignore +5 -0
- package/template-6.4.0-community/.eslintrc.json +72 -0
- package/template-6.4.0-community/.prettierrc.json +8 -0
- package/template-6.4.0-community/README.md +59 -0
- package/template-6.4.0-community/_package.json +47 -0
- package/template-6.4.0-community/gitignore +58 -0
- package/template-6.4.0-community/lerna.json +12 -0
- package/template-6.4.0-community/npmrc +3 -0
- package/template-6.4.0-community/packages/ss-admin-widget/index.ts +1 -0
- package/template-6.4.0-community/packages/ss-admin-widget/package.json +25 -0
- package/template-6.4.0-community/packages/ss-admin-widget/rollup.config.js +73 -0
- package/template-6.4.0-community/packages/ss-admin-widget/scripts/postpublish.js +13 -0
- package/template-6.4.0-community/packages/ss-admin-widget/scripts/prepublish-only.js +24 -0
- package/template-6.4.0-community/packages/ss-admin-widget/src/index.ts +1 -0
- package/template-6.4.0-community/packages/ss-admin-widget/src/shim-translate.d.ts +10 -0
- package/template-6.4.0-community/packages/ss-admin-widget/src/shim-vue.d.ts +6 -0
- package/template-6.4.0-community/packages/ss-admin-widget/tsconfig.json +45 -0
- package/template-6.4.0-community/packages/ss-boot/.env +1 -0
- package/template-6.4.0-community/packages/ss-boot/.env.example +6 -0
- package/template-6.4.0-community/packages/ss-boot/package.json +53 -0
- package/template-6.4.0-community/packages/ss-boot/public/favicon.ico +0 -0
- package/template-6.4.0-community/packages/ss-boot/public/index.html +83 -0
- package/template-6.4.0-community/packages/ss-boot/public/manifest.js +5 -0
- package/template-6.4.0-community/packages/ss-boot/src/main.ts +50 -0
- package/template-6.4.0-community/packages/ss-boot/src/shim-translate.d.ts +10 -0
- package/template-6.4.0-community/packages/ss-boot/src/shim-vue.d.ts +6 -0
- package/template-6.4.0-community/packages/ss-boot/tsconfig.json +44 -0
- package/template-6.4.0-community/packages/ss-boot/vue.config.js +84 -0
- package/template-6.4.0-community/packages/ss-oinone/index.ts +1 -0
- package/template-6.4.0-community/packages/ss-oinone/package.json +29 -0
- package/template-6.4.0-community/packages/ss-oinone/rollup.config.js +82 -0
- package/template-6.4.0-community/packages/ss-oinone/scripts/postpublish.js +13 -0
- package/template-6.4.0-community/packages/ss-oinone/scripts/prepublish-only.js +24 -0
- package/template-6.4.0-community/packages/ss-oinone/src/index.ts +1 -0
- package/template-6.4.0-community/packages/ss-oinone/src/shim-translate.d.ts +10 -0
- package/template-6.4.0-community/packages/ss-oinone/src/shim-vue.d.ts +6 -0
- package/template-6.4.0-community/packages/ss-oinone/tsconfig.json +42 -0
- package/template-6.4.0-community/packages/ss-project/index.ts +1 -0
- package/template-6.4.0-community/packages/ss-project/package.json +30 -0
- package/template-6.4.0-community/packages/ss-project/rollup.config.js +83 -0
- package/template-6.4.0-community/packages/ss-project/scripts/postpublish.js +13 -0
- package/template-6.4.0-community/packages/ss-project/scripts/prepublish-only.js +24 -0
- package/template-6.4.0-community/packages/ss-project/src/index.ts +1 -0
- package/template-6.4.0-community/packages/ss-project/src/shim-translate.d.ts +10 -0
- package/template-6.4.0-community/packages/ss-project/src/shim-vue.d.ts +6 -0
- package/template-6.4.0-community/packages/ss-project/tsconfig.json +42 -0
- package/template-6.4.0-community/pnpm-workspace.yaml +3 -0
- package/template-6.4.0-community/scripts/build/inset-tsconfig.js +68 -0
- package/template-6.4.0-community/scripts/build/package-name.js +25 -0
- package/template-6.4.0-community/scripts/build/postbuild.js +42 -0
- package/template-6.4.0-community/scripts/build/prebuild-only.js +48 -0
- package/template-6.4.0-community/scripts/clean.mjs +22 -0
- package/template-6.4.0-enterprise/.eslintignore +5 -0
- package/template-6.4.0-enterprise/.eslintrc.json +72 -0
- package/template-6.4.0-enterprise/.prettierrc.json +8 -0
- package/template-6.4.0-enterprise/README.md +59 -0
- package/template-6.4.0-enterprise/_package.json +47 -0
- package/template-6.4.0-enterprise/gitignore +58 -0
- package/template-6.4.0-enterprise/lerna.json +12 -0
- package/template-6.4.0-enterprise/npmrc +3 -0
- package/template-6.4.0-enterprise/packages/ss-admin-widget/index.ts +1 -0
- package/template-6.4.0-enterprise/packages/ss-admin-widget/package.json +25 -0
- package/template-6.4.0-enterprise/packages/ss-admin-widget/rollup.config.js +73 -0
- package/template-6.4.0-enterprise/packages/ss-admin-widget/scripts/postpublish.js +13 -0
- package/template-6.4.0-enterprise/packages/ss-admin-widget/scripts/prepublish-only.js +24 -0
- package/template-6.4.0-enterprise/packages/ss-admin-widget/src/index.ts +1 -0
- package/template-6.4.0-enterprise/packages/ss-admin-widget/src/shim-translate.d.ts +10 -0
- package/template-6.4.0-enterprise/packages/ss-admin-widget/src/shim-vue.d.ts +6 -0
- package/template-6.4.0-enterprise/packages/ss-admin-widget/tsconfig.json +45 -0
- package/template-6.4.0-enterprise/packages/ss-boot/.env +1 -0
- package/template-6.4.0-enterprise/packages/ss-boot/.env.example +6 -0
- package/template-6.4.0-enterprise/packages/ss-boot/package.json +66 -0
- package/template-6.4.0-enterprise/packages/ss-boot/public/favicon.ico +0 -0
- package/template-6.4.0-enterprise/packages/ss-boot/public/index.html +83 -0
- package/template-6.4.0-enterprise/packages/ss-boot/public/manifest.js +5 -0
- package/template-6.4.0-enterprise/packages/ss-boot/src/main.ts +69 -0
- package/template-6.4.0-enterprise/packages/ss-boot/src/shim-translate.d.ts +10 -0
- package/template-6.4.0-enterprise/packages/ss-boot/src/shim-vue.d.ts +6 -0
- package/template-6.4.0-enterprise/packages/ss-boot/tsconfig.json +44 -0
- package/template-6.4.0-enterprise/packages/ss-boot/vue.config.js +84 -0
- package/template-6.4.0-enterprise/packages/ss-oinone/index.ts +1 -0
- package/template-6.4.0-enterprise/packages/ss-oinone/package.json +29 -0
- package/template-6.4.0-enterprise/packages/ss-oinone/rollup.config.js +82 -0
- package/template-6.4.0-enterprise/packages/ss-oinone/scripts/postpublish.js +13 -0
- package/template-6.4.0-enterprise/packages/ss-oinone/scripts/prepublish-only.js +24 -0
- package/template-6.4.0-enterprise/packages/ss-oinone/src/index.ts +1 -0
- package/template-6.4.0-enterprise/packages/ss-oinone/src/shim-translate.d.ts +10 -0
- package/template-6.4.0-enterprise/packages/ss-oinone/src/shim-vue.d.ts +6 -0
- package/template-6.4.0-enterprise/packages/ss-oinone/tsconfig.json +42 -0
- package/template-6.4.0-enterprise/packages/ss-project/index.ts +1 -0
- package/template-6.4.0-enterprise/packages/ss-project/package.json +30 -0
- package/template-6.4.0-enterprise/packages/ss-project/rollup.config.js +83 -0
- package/template-6.4.0-enterprise/packages/ss-project/scripts/postpublish.js +13 -0
- package/template-6.4.0-enterprise/packages/ss-project/scripts/prepublish-only.js +24 -0
- package/template-6.4.0-enterprise/packages/ss-project/src/index.ts +1 -0
- package/template-6.4.0-enterprise/packages/ss-project/src/shim-translate.d.ts +10 -0
- package/template-6.4.0-enterprise/packages/ss-project/src/shim-vue.d.ts +6 -0
- package/template-6.4.0-enterprise/packages/ss-project/tsconfig.json +42 -0
- package/template-6.4.0-enterprise/pnpm-workspace.yaml +3 -0
- package/template-6.4.0-enterprise/scripts/build/inset-tsconfig.js +68 -0
- package/template-6.4.0-enterprise/scripts/build/package-name.js +25 -0
- package/template-6.4.0-enterprise/scripts/build/postbuild.js +42 -0
- package/template-6.4.0-enterprise/scripts/build/prebuild-only.js +48 -0
- package/template-6.4.0-enterprise/scripts/clean.mjs +22 -0
- package/template-7.2.0-community/.prettierrc.json +8 -0
- package/template-7.2.0-community/README.md +59 -0
- package/template-7.2.0-community/_package.json +57 -0
- package/template-7.2.0-community/eslint.config.ts +23 -0
- package/template-7.2.0-community/gitignore +58 -0
- package/template-7.2.0-community/lerna.json +12 -0
- package/template-7.2.0-community/npmrc +3 -0
- package/template-7.2.0-community/packages/ss-admin-widget/index.ts +1 -0
- package/template-7.2.0-community/packages/ss-admin-widget/package.json +27 -0
- package/template-7.2.0-community/packages/ss-admin-widget/rollup.config.js +12 -0
- package/template-7.2.0-community/packages/ss-admin-widget/scripts/postpublish.js +13 -0
- package/template-7.2.0-community/packages/ss-admin-widget/scripts/prepublish-only.js +24 -0
- package/template-7.2.0-community/packages/ss-admin-widget/src/index.ts +1 -0
- package/template-7.2.0-community/packages/ss-admin-widget/src/shim-translate.d.ts +10 -0
- package/template-7.2.0-community/packages/ss-admin-widget/src/shim-vue.d.ts +6 -0
- package/template-7.2.0-community/packages/ss-admin-widget/tsconfig.json +14 -0
- package/template-7.2.0-community/packages/ss-boot/.env +1 -0
- package/template-7.2.0-community/packages/ss-boot/.env.example +6 -0
- package/template-7.2.0-community/packages/ss-boot/package.json +51 -0
- package/template-7.2.0-community/packages/ss-boot/public/favicon.ico +0 -0
- package/template-7.2.0-community/packages/ss-boot/public/index.html +83 -0
- package/template-7.2.0-community/packages/ss-boot/public/manifest.js +5 -0
- package/template-7.2.0-community/packages/ss-boot/src/main.ts +46 -0
- package/template-7.2.0-community/packages/ss-boot/src/shim-translate.d.ts +10 -0
- package/template-7.2.0-community/packages/ss-boot/src/shim-vue.d.ts +6 -0
- package/template-7.2.0-community/packages/ss-boot/tsconfig.json +27 -0
- package/template-7.2.0-community/packages/ss-boot/vue.config.js +87 -0
- package/template-7.2.0-community/packages/ss-oinone/index.ts +1 -0
- package/template-7.2.0-community/packages/ss-oinone/package.json +30 -0
- package/template-7.2.0-community/packages/ss-oinone/rollup.config.js +12 -0
- package/template-7.2.0-community/packages/ss-oinone/scripts/postpublish.js +13 -0
- package/template-7.2.0-community/packages/ss-oinone/scripts/prepublish-only.js +24 -0
- package/template-7.2.0-community/packages/ss-oinone/src/index.ts +1 -0
- package/template-7.2.0-community/packages/ss-oinone/src/shim-translate.d.ts +10 -0
- package/template-7.2.0-community/packages/ss-oinone/src/shim-vue.d.ts +6 -0
- package/template-7.2.0-community/packages/ss-oinone/tsconfig.json +14 -0
- package/template-7.2.0-community/packages/ss-project/index.ts +1 -0
- package/template-7.2.0-community/packages/ss-project/package.json +30 -0
- package/template-7.2.0-community/packages/ss-project/rollup.config.js +12 -0
- package/template-7.2.0-community/packages/ss-project/scripts/postpublish.js +13 -0
- package/template-7.2.0-community/packages/ss-project/scripts/prepublish-only.js +24 -0
- package/template-7.2.0-community/packages/ss-project/src/index.ts +1 -0
- package/template-7.2.0-community/packages/ss-project/src/shim-translate.d.ts +10 -0
- package/template-7.2.0-community/packages/ss-project/src/shim-vue.d.ts +6 -0
- package/template-7.2.0-community/packages/ss-project/tsconfig.json +14 -0
- package/template-7.2.0-community/pnpm-workspace.yaml +3 -0
- package/template-7.2.0-community/scripts/build/inset-tsconfig.js +68 -0
- package/template-7.2.0-community/scripts/build/package-name.js +25 -0
- package/template-7.2.0-community/scripts/clean.mjs +22 -0
- package/template-7.2.0-enterprise/.prettierrc.json +8 -0
- package/template-7.2.0-enterprise/README.md +59 -0
- package/template-7.2.0-enterprise/_package.json +57 -0
- package/template-7.2.0-enterprise/eslint.config.ts +23 -0
- package/template-7.2.0-enterprise/gitignore +58 -0
- package/template-7.2.0-enterprise/lerna.json +12 -0
- package/template-7.2.0-enterprise/npmrc +3 -0
- package/template-7.2.0-enterprise/packages/ss-admin-widget/index.ts +1 -0
- package/template-7.2.0-enterprise/packages/ss-admin-widget/package.json +27 -0
- package/template-7.2.0-enterprise/packages/ss-admin-widget/rollup.config.js +12 -0
- package/template-7.2.0-enterprise/packages/ss-admin-widget/scripts/postpublish.js +13 -0
- package/template-7.2.0-enterprise/packages/ss-admin-widget/scripts/prepublish-only.js +24 -0
- package/template-7.2.0-enterprise/packages/ss-admin-widget/src/index.ts +1 -0
- package/template-7.2.0-enterprise/packages/ss-admin-widget/src/shim-translate.d.ts +10 -0
- package/template-7.2.0-enterprise/packages/ss-admin-widget/src/shim-vue.d.ts +6 -0
- package/template-7.2.0-enterprise/packages/ss-admin-widget/tsconfig.json +14 -0
- package/template-7.2.0-enterprise/packages/ss-boot/.env +1 -0
- package/template-7.2.0-enterprise/packages/ss-boot/.env.example +6 -0
- package/template-7.2.0-enterprise/packages/ss-boot/package.json +64 -0
- package/template-7.2.0-enterprise/packages/ss-boot/public/favicon.ico +0 -0
- package/template-7.2.0-enterprise/packages/ss-boot/public/index.html +83 -0
- package/template-7.2.0-enterprise/packages/ss-boot/public/manifest.js +5 -0
- package/template-7.2.0-enterprise/packages/ss-boot/src/main.ts +66 -0
- package/template-7.2.0-enterprise/packages/ss-boot/src/shim-translate.d.ts +10 -0
- package/template-7.2.0-enterprise/packages/ss-boot/src/shim-vue.d.ts +6 -0
- package/template-7.2.0-enterprise/packages/ss-boot/tsconfig.json +27 -0
- package/template-7.2.0-enterprise/packages/ss-boot/vue.config.js +87 -0
- package/template-7.2.0-enterprise/packages/ss-oinone/index.ts +1 -0
- package/template-7.2.0-enterprise/packages/ss-oinone/package.json +30 -0
- package/template-7.2.0-enterprise/packages/ss-oinone/rollup.config.js +12 -0
- package/template-7.2.0-enterprise/packages/ss-oinone/scripts/postpublish.js +13 -0
- package/template-7.2.0-enterprise/packages/ss-oinone/scripts/prepublish-only.js +24 -0
- package/template-7.2.0-enterprise/packages/ss-oinone/src/index.ts +1 -0
- package/template-7.2.0-enterprise/packages/ss-oinone/src/shim-translate.d.ts +10 -0
- package/template-7.2.0-enterprise/packages/ss-oinone/src/shim-vue.d.ts +6 -0
- package/template-7.2.0-enterprise/packages/ss-oinone/tsconfig.json +14 -0
- package/template-7.2.0-enterprise/packages/ss-project/index.ts +1 -0
- package/template-7.2.0-enterprise/packages/ss-project/package.json +30 -0
- package/template-7.2.0-enterprise/packages/ss-project/rollup.config.js +12 -0
- package/template-7.2.0-enterprise/packages/ss-project/scripts/postpublish.js +13 -0
- package/template-7.2.0-enterprise/packages/ss-project/scripts/prepublish-only.js +24 -0
- package/template-7.2.0-enterprise/packages/ss-project/src/index.ts +1 -0
- package/template-7.2.0-enterprise/packages/ss-project/src/shim-translate.d.ts +10 -0
- package/template-7.2.0-enterprise/packages/ss-project/src/shim-vue.d.ts +6 -0
- package/template-7.2.0-enterprise/packages/ss-project/tsconfig.json +14 -0
- package/template-7.2.0-enterprise/pnpm-workspace.yaml +3 -0
- package/template-7.2.0-enterprise/scripts/build/inset-tsconfig.js +68 -0
- package/template-7.2.0-enterprise/scripts/build/package-name.js +25 -0
- package/template-7.2.0-enterprise/scripts/clean.mjs +22 -0
package/README.md
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
# Quick Start
|
|
2
|
+
|
|
3
|
+
Read this in [中文](README_zh-CN.md).
|
|
4
|
+
|
|
5
|
+
## Global Installation of `@oinone/cli`
|
|
6
|
+
|
|
7
|
+
```shell
|
|
8
|
+
npm install -g @oinone/cli
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Create Frontend Project
|
|
12
|
+
|
|
13
|
+
Create a frontend project in any directory. We provide two modes: interactive creation and silent creation.
|
|
14
|
+
|
|
15
|
+
### 1. **Interactive Creation**
|
|
16
|
+
|
|
17
|
+
Follow the prompts to enter the company abbreviation, project name, select the Oinone edition, version, and whether to download the latest static resources.
|
|
18
|
+
|
|
19
|
+
```shell
|
|
20
|
+
oinone-frontend
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
**Example:**
|
|
24
|
+
|
|
25
|
+
```shell
|
|
26
|
+
Please enter the company name (e.g. ss): ss
|
|
27
|
+
Please enter the project name (e.g. oms): oms
|
|
28
|
+
Please select the Oinone edition: Community Edition (Default)
|
|
29
|
+
Please select the Oinone version: 7.2.0 (Default)
|
|
30
|
+
Do you want to download the latest static resources? (Y/n): Y
|
|
31
|
+
|
|
32
|
+
✔ Project created successfully!
|
|
33
|
+
|
|
34
|
+
To get started:
|
|
35
|
+
|
|
36
|
+
cd ss-oms-frontend
|
|
37
|
+
pnpm install
|
|
38
|
+
pnpm run dev
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
### 2. Silent Creation
|
|
42
|
+
|
|
43
|
+
If you want to skip the interactive steps to quickly create a project, you can directly append the project name after the command. In silent creation mode, the sub-packages and file prefixes in the project will default to this project name, the Oinone version will default to `7.2.0`, and the edition will default to `community`.
|
|
44
|
+
|
|
45
|
+
```shell
|
|
46
|
+
oinone-frontend <project-name>
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
**Parameters:**
|
|
50
|
+
- `<project-name>`: The name of the project you want to create (will be used as the project folder name and module prefix).
|
|
51
|
+
- `--download-static-resource`: Controls whether to automatically download static resources. Optional values are `true` (default) or `false`.
|
|
52
|
+
- `--oinone-version`: Specifies the Oinone version number (e.g., `7.2.0` or `6.4.0`). The default value is `7.2.0`.
|
|
53
|
+
- `--edition`: Specifies the Oinone edition to use. Optional values are `community` (default) or `enterprise`.
|
|
54
|
+
|
|
55
|
+
**Example (Create, skip resource download, and specify version number and edition):**
|
|
56
|
+
|
|
57
|
+
```shell
|
|
58
|
+
oinone-frontend my-project --download-static-resource=true --oinone-version="7.2.0" --edition="enterprise"
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
When you disable the automatic download of the resource package, the CLI will output the script commands required for manual download after the project creation is completed.
|
|
62
|
+
|
|
63
|
+
### 3. Cache Management
|
|
64
|
+
|
|
65
|
+
The CLI caches downloaded static resources in the system's temporary directory to speed up subsequent project creations. You can manage this cache using the `cache` command.
|
|
66
|
+
|
|
67
|
+
**View Cache Information:**
|
|
68
|
+
```shell
|
|
69
|
+
oinone-frontend cache info
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
**Clean Cache:**
|
|
73
|
+
```shell
|
|
74
|
+
oinone-frontend cache clean
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
**Cache Help Command:**
|
|
78
|
+
You can use the `-h` or `--help` option with the `cache` command to view its specific help documentation.
|
|
79
|
+
```shell
|
|
80
|
+
oinone-frontend cache -h
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### 4. Help Command
|
|
84
|
+
|
|
85
|
+
You can use the `-h` or `--help` option to view the CLI's standard help documentation.
|
|
86
|
+
|
|
87
|
+
```shell
|
|
88
|
+
oinone-frontend -h
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
**Output:**
|
|
92
|
+
|
|
93
|
+
```shell
|
|
94
|
+
Usage: cli [options] [command]
|
|
95
|
+
|
|
96
|
+
Oinone Frontend Template CLI
|
|
97
|
+
|
|
98
|
+
Options:
|
|
99
|
+
-V, --version output the version number
|
|
100
|
+
-h, --help display help for command
|
|
101
|
+
|
|
102
|
+
Commands:
|
|
103
|
+
cache Manage the local static resources cache
|
|
104
|
+
help [command] display help for command
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
## Uninstall `@oinone/cli`
|
|
108
|
+
|
|
109
|
+
If you need to uninstall the CLI tool, you can run the following command:
|
|
110
|
+
|
|
111
|
+
```shell
|
|
112
|
+
npm uninstall -g @oinone/cli
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
> **Note:** Uninstalling the CLI will **not** automatically clean up the cached static resources in your temporary directory. If you want to completely remove the cache, please run `oinone-frontend cache clean` before uninstalling, or manually delete the `oinone-cli-cache` folder in your system's temporary directory.
|
package/README_zh-CN.md
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
# 快速开始
|
|
2
|
+
|
|
3
|
+
Read this in [English](README.MD).
|
|
4
|
+
|
|
5
|
+
## 全局安装 `@oinone/cli`
|
|
6
|
+
|
|
7
|
+
``` shell
|
|
8
|
+
npm install -g @oinone/cli
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## 创建前端工程
|
|
12
|
+
|
|
13
|
+
在任意目录下创建前端工程。我们提供了交互式创建和静默创建两种模式。
|
|
14
|
+
|
|
15
|
+
### 1. 交互式创建
|
|
16
|
+
|
|
17
|
+
根据提示输入公司简称, 项目名称、选择 Oinone 版本(社区/企业)、版本号以及是否下载最新静态资源包即可。
|
|
18
|
+
|
|
19
|
+
``` shell
|
|
20
|
+
oinone-frontend
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
**示例:**
|
|
24
|
+
|
|
25
|
+
``` shell
|
|
26
|
+
Please enter the company name (e.g. ss): ss
|
|
27
|
+
Please enter the project name (e.g. oms): oms
|
|
28
|
+
Please select the Oinone edition: Community Edition (Default)
|
|
29
|
+
Please select the Oinone version: 7.2.0 (Default)
|
|
30
|
+
Do you want to download the latest static resources? (Y/n): Y
|
|
31
|
+
|
|
32
|
+
✔ Project created successfully!
|
|
33
|
+
|
|
34
|
+
To get started:
|
|
35
|
+
|
|
36
|
+
cd ss-oms-frontend
|
|
37
|
+
pnpm install
|
|
38
|
+
pnpm run dev
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
### 2. 静默创建
|
|
42
|
+
|
|
43
|
+
如果您希望跳过交互步骤快速创建工程,可以直接在命令后追加项目名称。静默创建时,项目中的子包及文件前缀将默认使用该项目名称,Oinone 版本号默认为 `7.2.0`,版本默认为 `community`(社区版)。
|
|
44
|
+
|
|
45
|
+
``` shell
|
|
46
|
+
oinone-frontend <project-name>
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
**参数说明:**
|
|
50
|
+
- `<project-name>`: 您要创建的项目名称(将作为项目文件夹名称和各模块前缀)。
|
|
51
|
+
- `--download-static-resource`: 控制是否自动下载静态资源包。可选值为 `true` (默认) 或 `false`。
|
|
52
|
+
- `--oinone-version`: 指定 Oinone 的版本号(如 `7.2.0` 或 `6.4.0`)。默认值为 `7.2.0`。
|
|
53
|
+
- `--edition`: 指定要使用的 Oinone 版本(社区版/企业版)。可选值为 `community` (默认) 或 `enterprise`。
|
|
54
|
+
|
|
55
|
+
**示例(创建并跳过资源下载,指定版本号及企业版):**
|
|
56
|
+
|
|
57
|
+
```shell
|
|
58
|
+
oinone-frontend my-project --download-static-resource=true --oinone-version="7.2.0" --edition="enterprise"
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
当您禁用自动下载资源包时,CLI 在项目创建完成后会输出手动下载所需执行的脚本命令。
|
|
62
|
+
|
|
63
|
+
### 3. 缓存管理
|
|
64
|
+
|
|
65
|
+
CLI 会在系统临时目录中缓存下载过的静态资源,以加快后续项目的创建速度。您可以通过 `cache` 命令来管理这些缓存文件。
|
|
66
|
+
|
|
67
|
+
**查看缓存信息:**
|
|
68
|
+
```shell
|
|
69
|
+
oinone-frontend cache info
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
**清理缓存:**
|
|
73
|
+
```shell
|
|
74
|
+
oinone-frontend cache clean
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
**缓存帮助文档:**
|
|
78
|
+
您可以使用 `-h` 或 `--help` 选项来查看 `cache` 命令的专属帮助文档。
|
|
79
|
+
```shell
|
|
80
|
+
oinone-frontend cache -h
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### 4. 查看帮助文档
|
|
84
|
+
|
|
85
|
+
您可以使用 `-h` 或 `--help` 选项来查看 CLI 的标准帮助文档。
|
|
86
|
+
|
|
87
|
+
```shell
|
|
88
|
+
oinone-frontend -h
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
**输出:**
|
|
92
|
+
|
|
93
|
+
```shell
|
|
94
|
+
Usage: cli [options] [command]
|
|
95
|
+
|
|
96
|
+
Oinone Frontend Template CLI
|
|
97
|
+
|
|
98
|
+
Options:
|
|
99
|
+
-V, --version output the version number
|
|
100
|
+
-h, --help display help for command
|
|
101
|
+
|
|
102
|
+
Commands:
|
|
103
|
+
cache Manage the local static resources cache
|
|
104
|
+
help [command] display help for command
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
## 卸载 `@oinone/cli`
|
|
108
|
+
|
|
109
|
+
如果您需要卸载该 CLI 工具,可以运行以下命令:
|
|
110
|
+
|
|
111
|
+
```shell
|
|
112
|
+
npm uninstall -g @oinone/cli
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
> **注意:** 卸载 CLI **不会**自动清理存储在系统临时目录中的静态资源缓存文件。如果您希望完全移除缓存,请在卸载前执行 `oinone-frontend cache clean`,或者手动删除系统临时目录下的 `oinone-cli-cache` 文件夹。
|
package/bin/cli.js
ADDED
|
@@ -0,0 +1,429 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const { program } = require('commander');
|
|
4
|
+
const inquirer = require('inquirer');
|
|
5
|
+
const fs = require('fs-extra');
|
|
6
|
+
const path = require('path');
|
|
7
|
+
const chalk = require('chalk');
|
|
8
|
+
const ora = require('ora');
|
|
9
|
+
const https = require('https');
|
|
10
|
+
const os = require('os');
|
|
11
|
+
const AdmZip = require('adm-zip');
|
|
12
|
+
const cliProgress = require('cli-progress');
|
|
13
|
+
const packageJson = require('../package.json');
|
|
14
|
+
|
|
15
|
+
const downloadAndExtractZip = (url, targetDir) => {
|
|
16
|
+
return new Promise((resolve, reject) => {
|
|
17
|
+
const req = https.request(url, { method: 'HEAD' }, (headRes) => {
|
|
18
|
+
if (headRes.statusCode !== 200) {
|
|
19
|
+
reject(new Error(`Failed to fetch file info: ${headRes.statusCode}`));
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
let etag = headRes.headers['etag'];
|
|
24
|
+
if (etag) {
|
|
25
|
+
etag = etag.replace(/"/g, ''); // Clean quotes
|
|
26
|
+
} else {
|
|
27
|
+
etag = headRes.headers['last-modified'] ? Buffer.from(headRes.headers['last-modified']).toString('hex') : 'default';
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const cacheDir = path.join(os.tmpdir(), 'oinone-cli-cache');
|
|
31
|
+
fs.ensureDirSync(cacheDir);
|
|
32
|
+
|
|
33
|
+
const cachedZipPath = path.join(cacheDir, `static-resources-${etag}.zip`);
|
|
34
|
+
|
|
35
|
+
if (fs.existsSync(cachedZipPath)) {
|
|
36
|
+
console.log(chalk.cyan('Using cached static resources...'));
|
|
37
|
+
try {
|
|
38
|
+
const zip = new AdmZip(cachedZipPath);
|
|
39
|
+
zip.extractAllTo(targetDir, true);
|
|
40
|
+
resolve();
|
|
41
|
+
} catch (err) {
|
|
42
|
+
fs.unlinkSync(cachedZipPath);
|
|
43
|
+
reject(err);
|
|
44
|
+
}
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const file = fs.createWriteStream(cachedZipPath);
|
|
49
|
+
|
|
50
|
+
https.get(url, (response) => {
|
|
51
|
+
if (response.statusCode !== 200) {
|
|
52
|
+
reject(new Error(`Failed to download: ${response.statusCode}`));
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const totalBytes = parseInt(response.headers['content-length'], 10);
|
|
57
|
+
let isMB = false;
|
|
58
|
+
let totalDisplay = 0;
|
|
59
|
+
let unit = 'KB';
|
|
60
|
+
|
|
61
|
+
if (totalBytes > 10 * 1024 * 1024) {
|
|
62
|
+
isMB = true;
|
|
63
|
+
unit = 'MB';
|
|
64
|
+
totalDisplay = (totalBytes / (1024 * 1024)).toFixed(2);
|
|
65
|
+
} else {
|
|
66
|
+
totalDisplay = Math.round(totalBytes / 1024);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
let downloadedBytes = 0;
|
|
70
|
+
let startTime = Date.now();
|
|
71
|
+
|
|
72
|
+
const progressBar = new cliProgress.SingleBar({
|
|
73
|
+
format: chalk.cyan('Downloading ') + `[{bar}] {percentage}% | ETA: {eta}s | {value}/{total} ${unit} | Speed: {speed} {speedUnit}/s`,
|
|
74
|
+
barCompleteChar: '\u2588',
|
|
75
|
+
barIncompleteChar: '\u2591',
|
|
76
|
+
hideCursor: true,
|
|
77
|
+
forceRedraw: true
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
progressBar.start(Number(totalDisplay), 0, { speed: '0.00', speedUnit: 'KB' });
|
|
81
|
+
|
|
82
|
+
response.on('data', (chunk) => {
|
|
83
|
+
downloadedBytes += chunk.length;
|
|
84
|
+
let downloadedDisplay = 0;
|
|
85
|
+
if (isMB) {
|
|
86
|
+
downloadedDisplay = Number((downloadedBytes / (1024 * 1024)).toFixed(2));
|
|
87
|
+
} else {
|
|
88
|
+
downloadedDisplay = Math.round(downloadedBytes / 1024);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const currentTime = Date.now();
|
|
92
|
+
const elapsedSeconds = (currentTime - startTime) / 1000;
|
|
93
|
+
let speed = 0;
|
|
94
|
+
let speedUnit = 'KB';
|
|
95
|
+
|
|
96
|
+
if (elapsedSeconds > 0) {
|
|
97
|
+
const speedInBytes = downloadedBytes / elapsedSeconds;
|
|
98
|
+
if (speedInBytes > 1024 * 1024) {
|
|
99
|
+
speed = speedInBytes / (1024 * 1024);
|
|
100
|
+
speedUnit = 'MB';
|
|
101
|
+
} else {
|
|
102
|
+
speed = speedInBytes / 1024;
|
|
103
|
+
speedUnit = 'KB';
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
progressBar.update(downloadedDisplay, { speed: speed.toFixed(2), speedUnit });
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
response.pipe(file);
|
|
111
|
+
file.on('finish', () => {
|
|
112
|
+
progressBar.stop();
|
|
113
|
+
file.close();
|
|
114
|
+
try {
|
|
115
|
+
const zip = new AdmZip(cachedZipPath);
|
|
116
|
+
zip.extractAllTo(targetDir, true);
|
|
117
|
+
resolve();
|
|
118
|
+
} catch (err) {
|
|
119
|
+
if (fs.existsSync(cachedZipPath)) fs.unlinkSync(cachedZipPath);
|
|
120
|
+
reject(err);
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
}).on('error', (err) => {
|
|
124
|
+
if (fs.existsSync(cachedZipPath)) fs.unlink(cachedZipPath, () => {});
|
|
125
|
+
reject(err);
|
|
126
|
+
});
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
req.on('error', (err) => {
|
|
130
|
+
reject(err);
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
req.end();
|
|
134
|
+
});
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
program
|
|
138
|
+
.version(packageJson.version)
|
|
139
|
+
.description('Oinone Frontend Template CLI')
|
|
140
|
+
.helpOption('-h, --help', 'display help for command');
|
|
141
|
+
|
|
142
|
+
// Cache Command
|
|
143
|
+
const cacheCmd = program
|
|
144
|
+
.command('cache')
|
|
145
|
+
.description('Manage the local static resources cache')
|
|
146
|
+
.action(() => {
|
|
147
|
+
// If just "cache" is typed without subcommands, show cache help
|
|
148
|
+
cacheCmd.help();
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
cacheCmd
|
|
152
|
+
.command('clean')
|
|
153
|
+
.description('Clean the local static resources cache')
|
|
154
|
+
.action(() => {
|
|
155
|
+
const cacheDir = path.join(os.tmpdir(), 'oinone-cli-cache');
|
|
156
|
+
if (fs.existsSync(cacheDir)) {
|
|
157
|
+
fs.removeSync(cacheDir);
|
|
158
|
+
console.log(chalk.green(`✔ Cache cleaned successfully at ${cacheDir}`));
|
|
159
|
+
} else {
|
|
160
|
+
console.log(chalk.yellow(`Cache directory does not exist: ${cacheDir}`));
|
|
161
|
+
}
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
cacheCmd
|
|
165
|
+
.command('info')
|
|
166
|
+
.description('Print cache directory information')
|
|
167
|
+
.action(async () => {
|
|
168
|
+
const cacheDir = path.join(os.tmpdir(), 'oinone-cli-cache');
|
|
169
|
+
console.log(chalk.cyan('Cache Directory: ') + cacheDir);
|
|
170
|
+
|
|
171
|
+
if (fs.existsSync(cacheDir)) {
|
|
172
|
+
const files = await fs.readdir(cacheDir);
|
|
173
|
+
let totalSize = 0;
|
|
174
|
+
|
|
175
|
+
console.log(chalk.cyan('Cached Files:'));
|
|
176
|
+
for (const file of files) {
|
|
177
|
+
const filePath = path.join(cacheDir, file);
|
|
178
|
+
const stat = await fs.stat(filePath);
|
|
179
|
+
totalSize += stat.size;
|
|
180
|
+
|
|
181
|
+
let displaySize = '';
|
|
182
|
+
if (stat.size > 1024 * 1024) {
|
|
183
|
+
displaySize = `${(stat.size / (1024 * 1024)).toFixed(2)} MB`;
|
|
184
|
+
} else {
|
|
185
|
+
displaySize = `${Math.round(stat.size / 1024)} KB`;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
console.log(` - ${file} (${displaySize})`);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
let totalDisplaySize = '';
|
|
192
|
+
if (totalSize > 1024 * 1024) {
|
|
193
|
+
totalDisplaySize = `${(totalSize / (1024 * 1024)).toFixed(2)} MB`;
|
|
194
|
+
} else {
|
|
195
|
+
totalDisplaySize = `${Math.round(totalSize / 1024)} KB`;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
console.log(chalk.cyan(`Total Cache Size: `) + totalDisplaySize);
|
|
199
|
+
} else {
|
|
200
|
+
console.log(chalk.yellow('Cache is currently empty.'));
|
|
201
|
+
}
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
// Create Command (Default Behavior)
|
|
205
|
+
program
|
|
206
|
+
.argument('[project-name]', 'Name of the project to create silently')
|
|
207
|
+
.option('--download-static-resource <value>', 'Download static resources (true/false)', 'true')
|
|
208
|
+
.option('--oinone-version <value>', 'Oinone version to use (e.g. 7.2.0, 6.4.0)', '7.2.0')
|
|
209
|
+
.option('--edition <value>', 'Oinone edition to use (community/enterprise)', 'community')
|
|
210
|
+
.action(async (projectNameArg, options) => {
|
|
211
|
+
// If command is 'cache', skip create logic
|
|
212
|
+
if (projectNameArg === 'cache') {
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
try {
|
|
217
|
+
let prefix;
|
|
218
|
+
let fullProjectName;
|
|
219
|
+
let oinoneVersion;
|
|
220
|
+
let edition;
|
|
221
|
+
let downloadStaticResources;
|
|
222
|
+
|
|
223
|
+
if (projectNameArg) {
|
|
224
|
+
// Remove '-frontend' suffix if it exists to form the prefix
|
|
225
|
+
prefix = projectNameArg.endsWith('-frontend')
|
|
226
|
+
? projectNameArg.slice(0, -9)
|
|
227
|
+
: projectNameArg;
|
|
228
|
+
fullProjectName = projectNameArg;
|
|
229
|
+
oinoneVersion = options.oinoneVersion;
|
|
230
|
+
// Ensure oinoneVersion has a tilde prefix
|
|
231
|
+
if (!oinoneVersion.startsWith('~')) {
|
|
232
|
+
oinoneVersion = `~${oinoneVersion}`;
|
|
233
|
+
}
|
|
234
|
+
edition = options.edition;
|
|
235
|
+
downloadStaticResources = options.downloadStaticResource !== 'false';
|
|
236
|
+
} else {
|
|
237
|
+
const answers = await inquirer.prompt([
|
|
238
|
+
{
|
|
239
|
+
type: 'input',
|
|
240
|
+
name: 'companyName',
|
|
241
|
+
message: 'Please enter the company name (e.g. ss):',
|
|
242
|
+
default: 'ss',
|
|
243
|
+
validate: (input) => {
|
|
244
|
+
if (input.trim() === '') return 'Company name cannot be empty.';
|
|
245
|
+
return true;
|
|
246
|
+
},
|
|
247
|
+
},
|
|
248
|
+
{
|
|
249
|
+
type: 'input',
|
|
250
|
+
name: 'projectName',
|
|
251
|
+
message: 'Please enter the project name (e.g. oms):',
|
|
252
|
+
default: 'oms',
|
|
253
|
+
validate: (input) => {
|
|
254
|
+
if (input.trim() === '') return 'Project name cannot be empty.';
|
|
255
|
+
return true;
|
|
256
|
+
},
|
|
257
|
+
},
|
|
258
|
+
{
|
|
259
|
+
type: 'list',
|
|
260
|
+
name: 'edition',
|
|
261
|
+
message: 'Please select the Oinone edition:',
|
|
262
|
+
choices: [
|
|
263
|
+
{ name: 'Community Edition (Default)', value: 'community' },
|
|
264
|
+
{ name: 'Enterprise Edition', value: 'enterprise' }
|
|
265
|
+
],
|
|
266
|
+
default: 'community'
|
|
267
|
+
},
|
|
268
|
+
{
|
|
269
|
+
type: 'list',
|
|
270
|
+
name: 'oinoneVersion',
|
|
271
|
+
message: 'Please select the Oinone version:',
|
|
272
|
+
choices: [
|
|
273
|
+
{ name: '7.2.0 (Default)', value: '~7.2.0' },
|
|
274
|
+
{ name: '6.4.0', value: '~6.4.0' }
|
|
275
|
+
],
|
|
276
|
+
default: '~7.2.0'
|
|
277
|
+
},
|
|
278
|
+
{
|
|
279
|
+
type: 'confirm',
|
|
280
|
+
name: 'downloadStaticResources',
|
|
281
|
+
message: 'Do you want to download the latest static resources?',
|
|
282
|
+
default: true
|
|
283
|
+
}
|
|
284
|
+
]);
|
|
285
|
+
|
|
286
|
+
prefix = answers.companyName;
|
|
287
|
+
fullProjectName = `${answers.companyName}-${answers.projectName}-frontend`;
|
|
288
|
+
oinoneVersion = answers.oinoneVersion;
|
|
289
|
+
edition = answers.edition;
|
|
290
|
+
downloadStaticResources = answers.downloadStaticResources;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
const targetPath = path.resolve(process.cwd(), fullProjectName);
|
|
294
|
+
|
|
295
|
+
if (fs.existsSync(targetPath)) {
|
|
296
|
+
console.log(chalk.red(`\nError: Directory ${fullProjectName} already exists.\n`));
|
|
297
|
+
process.exit(1);
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
const spinner = ora('Creating project...').start();
|
|
301
|
+
|
|
302
|
+
const versionDir = oinoneVersion.replace(/[^0-9.]/g, ''); // Extract '7.2.0' or '6.4.0'
|
|
303
|
+
const templatePath = path.resolve(__dirname, `../template-${versionDir}-${edition}`);
|
|
304
|
+
|
|
305
|
+
if (!fs.existsSync(templatePath)) {
|
|
306
|
+
spinner.fail(chalk.red(`Template for version ${oinoneVersion} (${edition} edition) not found.`));
|
|
307
|
+
process.exit(1);
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
// Helper function to process files recursively
|
|
311
|
+
const processDirectory = async (dirPath) => {
|
|
312
|
+
const files = await fs.readdir(dirPath);
|
|
313
|
+
for (const file of files) {
|
|
314
|
+
const currentPath = path.join(dirPath, file);
|
|
315
|
+
const stat = await fs.stat(currentPath);
|
|
316
|
+
|
|
317
|
+
// Rename directory if it starts with 'ss-'
|
|
318
|
+
let newPath = currentPath;
|
|
319
|
+
if (file.startsWith('ss-')) {
|
|
320
|
+
const newFile = file.replace(/^ss-/, `${prefix}-`);
|
|
321
|
+
newPath = path.join(dirPath, newFile);
|
|
322
|
+
await fs.rename(currentPath, newPath);
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
if (stat.isDirectory()) {
|
|
326
|
+
await processDirectory(newPath);
|
|
327
|
+
} else {
|
|
328
|
+
// Check if it's a text file
|
|
329
|
+
const ext = path.extname(newPath);
|
|
330
|
+
const isTextFile = !['.png', '.ico', '.jpg', '.jpeg', '.gif'].includes(ext);
|
|
331
|
+
|
|
332
|
+
if (isTextFile) {
|
|
333
|
+
let content = await fs.readFile(newPath, 'utf8');
|
|
334
|
+
let hasChanges = false;
|
|
335
|
+
|
|
336
|
+
// Replace 'ss-' with '${prefix}-' but avoid replacing within words
|
|
337
|
+
// We use a regex that matches 'ss-' either at the start of a string or preceded by non-word characters
|
|
338
|
+
// To prevent changing things like postcss -> postprefix
|
|
339
|
+
const regex = /(^|[^a-zA-Z])ss-/g;
|
|
340
|
+
if (regex.test(content)) {
|
|
341
|
+
content = content.replace(regex, `$1${prefix}-`);
|
|
342
|
+
hasChanges = true;
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
// Replace '@ss/oinone' with `@${prefix}/oinone`
|
|
346
|
+
if (content.includes('@ss/')) {
|
|
347
|
+
content = content.replace(/@ss\//g, `@${prefix}/`);
|
|
348
|
+
hasChanges = true;
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
if (hasChanges) {
|
|
352
|
+
await fs.writeFile(newPath, content, 'utf8');
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
};
|
|
358
|
+
|
|
359
|
+
// Copy template files
|
|
360
|
+
await fs.copy(templatePath, targetPath, {
|
|
361
|
+
filter: (src) => {
|
|
362
|
+
// Ignore node_modules just in case
|
|
363
|
+
const relativePath = path.relative(templatePath, src);
|
|
364
|
+
if (relativePath.split(path.sep).includes('node_modules')) return false;
|
|
365
|
+
return true;
|
|
366
|
+
}
|
|
367
|
+
});
|
|
368
|
+
|
|
369
|
+
// Process the copied files (rename and replace content)
|
|
370
|
+
await processDirectory(targetPath);
|
|
371
|
+
|
|
372
|
+
// Handle package.json
|
|
373
|
+
const pkgPath = path.join(targetPath, '_package.json');
|
|
374
|
+
const newPkgPath = path.join(targetPath, 'package.json');
|
|
375
|
+
if (fs.existsSync(pkgPath)) {
|
|
376
|
+
const pkgContent = await fs.readJson(pkgPath);
|
|
377
|
+
pkgContent.name = fullProjectName;
|
|
378
|
+
await fs.writeJson(newPkgPath, pkgContent, { spaces: 2 });
|
|
379
|
+
await fs.remove(pkgPath);
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
// Handle gitignore
|
|
383
|
+
const gitignorePath = path.join(targetPath, 'gitignore');
|
|
384
|
+
const newGitignorePath = path.join(targetPath, '.gitignore');
|
|
385
|
+
if (fs.existsSync(gitignorePath)) {
|
|
386
|
+
await fs.move(gitignorePath, newGitignorePath);
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
// Handle npmrc
|
|
390
|
+
const npmrcPath = path.join(targetPath, 'npmrc');
|
|
391
|
+
const newNpmrcPath = path.join(targetPath, '.npmrc');
|
|
392
|
+
if (fs.existsSync(npmrcPath)) {
|
|
393
|
+
await fs.move(npmrcPath, newNpmrcPath);
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
if (downloadStaticResources) {
|
|
397
|
+
spinner.succeed(chalk.green('Project structure created successfully!'));
|
|
398
|
+
console.log(chalk.cyan('Downloading static resources...'));
|
|
399
|
+
try {
|
|
400
|
+
const ossDir = path.join(targetPath, 'packages', `${prefix}-boot`, 'public', 'oss');
|
|
401
|
+
await fs.ensureDir(ossDir);
|
|
402
|
+
await downloadAndExtractZip('https://pamirs.oss-cn-hangzhou.aliyuncs.com/oinone/installer/static-resources.zip', ossDir);
|
|
403
|
+
console.log(chalk.green('✔ Static resources downloaded successfully!'));
|
|
404
|
+
} catch (err) {
|
|
405
|
+
console.log(chalk.yellow(`⚠️ Project created, but failed to download static resources: ${err.message}`));
|
|
406
|
+
}
|
|
407
|
+
} else {
|
|
408
|
+
spinner.succeed(chalk.green('Project created successfully!'));
|
|
409
|
+
const relativeOssDir = `packages/${prefix}-boot/public/oss`;
|
|
410
|
+
console.log(chalk.yellow(`\n⚠️ You chose not to download static resources automatically.`));
|
|
411
|
+
console.log(chalk.yellow(`Please download and extract them manually before running the project:`));
|
|
412
|
+
console.log(chalk.cyan(` mkdir -p ${fullProjectName}/${relativeOssDir}`));
|
|
413
|
+
console.log(chalk.cyan(` curl -L https://pamirs.oss-cn-hangzhou.aliyuncs.com/oinone/installer/static-resources.zip -o static-resources.zip`));
|
|
414
|
+
console.log(chalk.cyan(` unzip static-resources.zip -d ${fullProjectName}/${relativeOssDir}`));
|
|
415
|
+
console.log(chalk.cyan(` rm static-resources.zip`));
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
console.log(`\nTo get started:\n`);
|
|
419
|
+
console.log(chalk.cyan(` cd ${fullProjectName}`));
|
|
420
|
+
console.log(chalk.cyan(` pnpm install`));
|
|
421
|
+
console.log(chalk.cyan(` pnpm run dev\n`));
|
|
422
|
+
|
|
423
|
+
} catch (error) {
|
|
424
|
+
console.error(chalk.red(`\nAn error occurred: ${error.message}\n`));
|
|
425
|
+
process.exit(1);
|
|
426
|
+
}
|
|
427
|
+
});
|
|
428
|
+
|
|
429
|
+
program.parse(process.argv);
|
package/package.json
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@oinone/cli",
|
|
3
|
+
"version": "7.2.1",
|
|
4
|
+
"description": "CLI tool to generate Oinone Frontend Template",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"bin": {
|
|
7
|
+
"oinone-frontend": "./bin/cli.js"
|
|
8
|
+
},
|
|
9
|
+
"scripts": {
|
|
10
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
11
|
+
},
|
|
12
|
+
"keywords": [],
|
|
13
|
+
"author": "",
|
|
14
|
+
"license": "ISC",
|
|
15
|
+
"dependencies": {
|
|
16
|
+
"adm-zip": "^0.5.17",
|
|
17
|
+
"chalk": "^4.1.2",
|
|
18
|
+
"cli-progress": "^3.12.0",
|
|
19
|
+
"commander": "^14.0.3",
|
|
20
|
+
"ejs": "^5.0.2",
|
|
21
|
+
"fs-extra": "^11.3.4",
|
|
22
|
+
"inquirer": "^8.2.6",
|
|
23
|
+
"ora": "^5.4.1"
|
|
24
|
+
}
|
|
25
|
+
}
|