@oinone/cli 7.2.5 → 7.2.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 +100 -71
- package/README_zh-CN.md +100 -71
- package/bin/cli.js +48 -473
- package/bin/commands/cache.js +70 -0
- package/bin/commands/create/enterprise.js +81 -0
- package/bin/commands/create/index.js +128 -0
- package/bin/commands/create/project.js +81 -0
- package/bin/commands/create/prompts.js +126 -0
- package/bin/commands/create/static-resources.js +159 -0
- package/bin/commands/create/template.js +38 -0
- package/bin/commands/create/update-check.js +44 -0
- package/bin/commands/create/version-source.js +32 -0
- package/bin/commands/create.js +1 -0
- package/bin/commands/doctor.js +51 -0
- package/bin/config.js +54 -0
- package/bin/i18n.js +51 -125
- package/bin/locales/en-US.json +81 -0
- package/bin/locales/zh-CN.json +81 -0
- package/bin/utils/oinone-version.js +60 -0
- package/package.json +2 -2
- package/template-6.4.0/packages/ss-boot/public/favicon.ico +0 -0
- package/{template-6.4.0-community → template-6.4.0}/packages/ss-boot/src/main.ts +1 -2
- package/{template-6.4.0-community → template-6.4.0}/packages/ss-boot/vue.config.js +1 -1
- package/{template-7.2.0-community → template-7.2.0}/npmrc +2 -0
- package/{template-7.2.0-community → template-7.2.0}/packages/ss-admin-widget/package.json +3 -2
- package/{template-7.2.0-community → template-7.2.0}/packages/ss-admin-widget/rollup.config.js +2 -0
- package/template-7.2.0/packages/ss-boot/public/favicon.ico +0 -0
- package/{template-7.2.0-community → template-7.2.0}/packages/ss-boot/src/main.ts +1 -2
- package/{template-7.2.0-community → template-7.2.0}/packages/ss-boot/vue.config.js +1 -1
- package/{template-7.2.0-enterprise → template-7.2.0}/packages/ss-oinone/package.json +3 -2
- package/{template-7.2.0-enterprise → template-7.2.0}/packages/ss-oinone/rollup.config.js +2 -0
- package/{template-7.2.0-community → template-7.2.0}/packages/ss-project/package.json +3 -2
- package/{template-7.2.0-enterprise → template-7.2.0}/packages/ss-project/rollup.config.js +2 -0
- package/template-6.4.0-community/packages/ss-boot/public/favicon.ico +0 -0
- package/template-6.4.0-enterprise/.eslintignore +0 -5
- package/template-6.4.0-enterprise/.eslintrc.json +0 -72
- package/template-6.4.0-enterprise/_package.json +0 -47
- package/template-6.4.0-enterprise/npmrc +0 -3
- package/template-6.4.0-enterprise/packages/ss-admin-widget/package.json +0 -25
- package/template-6.4.0-enterprise/packages/ss-admin-widget/rollup.config.js +0 -73
- package/template-6.4.0-enterprise/packages/ss-admin-widget/tsconfig.json +0 -45
- package/template-6.4.0-enterprise/packages/ss-boot/package.json +0 -66
- package/template-6.4.0-enterprise/packages/ss-boot/public/favicon.ico +0 -0
- package/template-6.4.0-enterprise/packages/ss-boot/src/main.ts +0 -69
- package/template-6.4.0-enterprise/packages/ss-boot/tsconfig.json +0 -44
- package/template-6.4.0-enterprise/packages/ss-boot/vue.config.js +0 -84
- package/template-6.4.0-enterprise/packages/ss-oinone/package.json +0 -29
- package/template-6.4.0-enterprise/packages/ss-oinone/rollup.config.js +0 -82
- package/template-6.4.0-enterprise/packages/ss-oinone/tsconfig.json +0 -42
- package/template-6.4.0-enterprise/packages/ss-project/package.json +0 -30
- package/template-6.4.0-enterprise/packages/ss-project/rollup.config.js +0 -83
- package/template-6.4.0-enterprise/packages/ss-project/tsconfig.json +0 -42
- package/template-6.4.0-enterprise/scripts/build/postbuild.js +0 -42
- package/template-6.4.0-enterprise/scripts/build/prebuild-only.js +0 -48
- package/template-7.2.0-community/.prettierrc.json +0 -8
- package/template-7.2.0-community/README.md +0 -59
- package/template-7.2.0-community/gitignore +0 -58
- package/template-7.2.0-community/lerna.json +0 -12
- package/template-7.2.0-community/packages/ss-admin-widget/index.ts +0 -1
- package/template-7.2.0-community/packages/ss-admin-widget/scripts/postpublish.js +0 -13
- package/template-7.2.0-community/packages/ss-admin-widget/scripts/prepublish-only.js +0 -24
- package/template-7.2.0-community/packages/ss-admin-widget/src/index.ts +0 -1
- package/template-7.2.0-community/packages/ss-admin-widget/src/shim-translate.d.ts +0 -10
- package/template-7.2.0-community/packages/ss-admin-widget/src/shim-vue.d.ts +0 -6
- package/template-7.2.0-community/packages/ss-boot/.env +0 -1
- package/template-7.2.0-community/packages/ss-boot/.env.example +0 -6
- 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 +0 -83
- package/template-7.2.0-community/packages/ss-boot/public/manifest.js +0 -5
- package/template-7.2.0-community/packages/ss-boot/src/shim-translate.d.ts +0 -10
- package/template-7.2.0-community/packages/ss-boot/src/shim-vue.d.ts +0 -6
- package/template-7.2.0-community/packages/ss-oinone/index.ts +0 -1
- package/template-7.2.0-community/packages/ss-oinone/package.json +0 -30
- package/template-7.2.0-community/packages/ss-oinone/rollup.config.js +0 -14
- package/template-7.2.0-community/packages/ss-oinone/scripts/postpublish.js +0 -13
- package/template-7.2.0-community/packages/ss-oinone/scripts/prepublish-only.js +0 -24
- package/template-7.2.0-community/packages/ss-oinone/src/index.ts +0 -1
- package/template-7.2.0-community/packages/ss-oinone/src/shim-translate.d.ts +0 -10
- package/template-7.2.0-community/packages/ss-oinone/src/shim-vue.d.ts +0 -6
- package/template-7.2.0-community/packages/ss-project/index.ts +0 -1
- package/template-7.2.0-community/packages/ss-project/rollup.config.js +0 -14
- package/template-7.2.0-community/packages/ss-project/scripts/postpublish.js +0 -13
- package/template-7.2.0-community/packages/ss-project/scripts/prepublish-only.js +0 -24
- package/template-7.2.0-community/packages/ss-project/src/index.ts +0 -1
- package/template-7.2.0-community/packages/ss-project/src/shim-translate.d.ts +0 -10
- package/template-7.2.0-community/packages/ss-project/src/shim-vue.d.ts +0 -6
- package/template-7.2.0-community/pnpm-workspace.yaml +0 -3
- package/template-7.2.0-community/scripts/build/inset-tsconfig.js +0 -68
- package/template-7.2.0-community/scripts/build/package-name.js +0 -25
- package/template-7.2.0-community/scripts/clean.mjs +0 -22
- package/template-7.2.0-enterprise/.prettierrc.json +0 -8
- package/template-7.2.0-enterprise/README.md +0 -59
- package/template-7.2.0-enterprise/_package.json +0 -57
- package/template-7.2.0-enterprise/eslint.config.ts +0 -23
- package/template-7.2.0-enterprise/gitignore +0 -58
- package/template-7.2.0-enterprise/lerna.json +0 -12
- package/template-7.2.0-enterprise/npmrc +0 -3
- package/template-7.2.0-enterprise/packages/ss-admin-widget/index.ts +0 -1
- package/template-7.2.0-enterprise/packages/ss-admin-widget/package.json +0 -27
- package/template-7.2.0-enterprise/packages/ss-admin-widget/rollup.config.js +0 -14
- package/template-7.2.0-enterprise/packages/ss-admin-widget/scripts/postpublish.js +0 -13
- package/template-7.2.0-enterprise/packages/ss-admin-widget/scripts/prepublish-only.js +0 -24
- package/template-7.2.0-enterprise/packages/ss-admin-widget/src/index.ts +0 -1
- package/template-7.2.0-enterprise/packages/ss-admin-widget/src/shim-translate.d.ts +0 -10
- package/template-7.2.0-enterprise/packages/ss-admin-widget/src/shim-vue.d.ts +0 -6
- package/template-7.2.0-enterprise/packages/ss-admin-widget/tsconfig.json +0 -14
- package/template-7.2.0-enterprise/packages/ss-boot/.env +0 -1
- package/template-7.2.0-enterprise/packages/ss-boot/.env.example +0 -6
- package/template-7.2.0-enterprise/packages/ss-boot/package.json +0 -64
- 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 +0 -83
- package/template-7.2.0-enterprise/packages/ss-boot/public/manifest.js +0 -5
- package/template-7.2.0-enterprise/packages/ss-boot/src/main.ts +0 -66
- package/template-7.2.0-enterprise/packages/ss-boot/src/shim-translate.d.ts +0 -10
- package/template-7.2.0-enterprise/packages/ss-boot/src/shim-vue.d.ts +0 -6
- package/template-7.2.0-enterprise/packages/ss-boot/tsconfig.json +0 -27
- package/template-7.2.0-enterprise/packages/ss-boot/vue.config.js +0 -87
- package/template-7.2.0-enterprise/packages/ss-oinone/index.ts +0 -1
- package/template-7.2.0-enterprise/packages/ss-oinone/scripts/postpublish.js +0 -13
- package/template-7.2.0-enterprise/packages/ss-oinone/scripts/prepublish-only.js +0 -24
- package/template-7.2.0-enterprise/packages/ss-oinone/src/index.ts +0 -1
- package/template-7.2.0-enterprise/packages/ss-oinone/src/shim-translate.d.ts +0 -10
- package/template-7.2.0-enterprise/packages/ss-oinone/src/shim-vue.d.ts +0 -6
- package/template-7.2.0-enterprise/packages/ss-oinone/tsconfig.json +0 -14
- package/template-7.2.0-enterprise/packages/ss-project/index.ts +0 -1
- package/template-7.2.0-enterprise/packages/ss-project/package.json +0 -30
- package/template-7.2.0-enterprise/packages/ss-project/scripts/postpublish.js +0 -13
- package/template-7.2.0-enterprise/packages/ss-project/scripts/prepublish-only.js +0 -24
- package/template-7.2.0-enterprise/packages/ss-project/src/index.ts +0 -1
- package/template-7.2.0-enterprise/packages/ss-project/src/shim-translate.d.ts +0 -10
- package/template-7.2.0-enterprise/packages/ss-project/src/shim-vue.d.ts +0 -6
- package/template-7.2.0-enterprise/packages/ss-project/tsconfig.json +0 -14
- package/template-7.2.0-enterprise/pnpm-workspace.yaml +0 -3
- package/template-7.2.0-enterprise/scripts/build/inset-tsconfig.js +0 -68
- package/template-7.2.0-enterprise/scripts/build/package-name.js +0 -25
- package/template-7.2.0-enterprise/scripts/clean.mjs +0 -22
- /package/{template-6.4.0-community → template-6.4.0}/.eslintignore +0 -0
- /package/{template-6.4.0-community → template-6.4.0}/.eslintrc.json +0 -0
- /package/{template-6.4.0-community → template-6.4.0}/.prettierrc.json +0 -0
- /package/{template-6.4.0-community → template-6.4.0}/README.md +0 -0
- /package/{template-6.4.0-community → template-6.4.0}/_package.json +0 -0
- /package/{template-6.4.0-community → template-6.4.0}/gitignore +0 -0
- /package/{template-6.4.0-community → template-6.4.0}/lerna.json +0 -0
- /package/{template-6.4.0-community → template-6.4.0}/npmrc +0 -0
- /package/{template-6.4.0-community → template-6.4.0}/packages/ss-admin-widget/index.ts +0 -0
- /package/{template-6.4.0-community → template-6.4.0}/packages/ss-admin-widget/package.json +0 -0
- /package/{template-6.4.0-community → template-6.4.0}/packages/ss-admin-widget/rollup.config.js +0 -0
- /package/{template-6.4.0-community → template-6.4.0}/packages/ss-admin-widget/scripts/postpublish.js +0 -0
- /package/{template-6.4.0-community → template-6.4.0}/packages/ss-admin-widget/scripts/prepublish-only.js +0 -0
- /package/{template-6.4.0-community → template-6.4.0}/packages/ss-admin-widget/src/index.ts +0 -0
- /package/{template-6.4.0-community → template-6.4.0}/packages/ss-admin-widget/src/shim-translate.d.ts +0 -0
- /package/{template-6.4.0-community → template-6.4.0}/packages/ss-admin-widget/src/shim-vue.d.ts +0 -0
- /package/{template-6.4.0-community → template-6.4.0}/packages/ss-admin-widget/tsconfig.json +0 -0
- /package/{template-6.4.0-community → template-6.4.0}/packages/ss-boot/.env +0 -0
- /package/{template-6.4.0-community → template-6.4.0}/packages/ss-boot/.env.example +0 -0
- /package/{template-6.4.0-community → template-6.4.0}/packages/ss-boot/package.json +0 -0
- /package/{template-6.4.0-community → template-6.4.0}/packages/ss-boot/public/index.html +0 -0
- /package/{template-6.4.0-community → template-6.4.0}/packages/ss-boot/public/manifest.js +0 -0
- /package/{template-6.4.0-community → template-6.4.0}/packages/ss-boot/src/shim-translate.d.ts +0 -0
- /package/{template-6.4.0-community → template-6.4.0}/packages/ss-boot/src/shim-vue.d.ts +0 -0
- /package/{template-6.4.0-community → template-6.4.0}/packages/ss-boot/tsconfig.json +0 -0
- /package/{template-6.4.0-community → template-6.4.0}/packages/ss-oinone/index.ts +0 -0
- /package/{template-6.4.0-community → template-6.4.0}/packages/ss-oinone/package.json +0 -0
- /package/{template-6.4.0-community → template-6.4.0}/packages/ss-oinone/rollup.config.js +0 -0
- /package/{template-6.4.0-community → template-6.4.0}/packages/ss-oinone/scripts/postpublish.js +0 -0
- /package/{template-6.4.0-community → template-6.4.0}/packages/ss-oinone/scripts/prepublish-only.js +0 -0
- /package/{template-6.4.0-community → template-6.4.0}/packages/ss-oinone/src/index.ts +0 -0
- /package/{template-6.4.0-community → template-6.4.0}/packages/ss-oinone/src/shim-translate.d.ts +0 -0
- /package/{template-6.4.0-community → template-6.4.0}/packages/ss-oinone/src/shim-vue.d.ts +0 -0
- /package/{template-6.4.0-community → template-6.4.0}/packages/ss-oinone/tsconfig.json +0 -0
- /package/{template-6.4.0-community → template-6.4.0}/packages/ss-project/index.ts +0 -0
- /package/{template-6.4.0-community → template-6.4.0}/packages/ss-project/package.json +0 -0
- /package/{template-6.4.0-community → template-6.4.0}/packages/ss-project/rollup.config.js +0 -0
- /package/{template-6.4.0-community → template-6.4.0}/packages/ss-project/scripts/postpublish.js +0 -0
- /package/{template-6.4.0-community → template-6.4.0}/packages/ss-project/scripts/prepublish-only.js +0 -0
- /package/{template-6.4.0-community → template-6.4.0}/packages/ss-project/src/index.ts +0 -0
- /package/{template-6.4.0-community → template-6.4.0}/packages/ss-project/src/shim-translate.d.ts +0 -0
- /package/{template-6.4.0-community → template-6.4.0}/packages/ss-project/src/shim-vue.d.ts +0 -0
- /package/{template-6.4.0-community → template-6.4.0}/packages/ss-project/tsconfig.json +0 -0
- /package/{template-6.4.0-community → template-6.4.0}/pnpm-workspace.yaml +0 -0
- /package/{template-6.4.0-community → template-6.4.0}/scripts/build/inset-tsconfig.js +0 -0
- /package/{template-6.4.0-community → template-6.4.0}/scripts/build/package-name.js +0 -0
- /package/{template-6.4.0-community → template-6.4.0}/scripts/build/postbuild.js +0 -0
- /package/{template-6.4.0-community → template-6.4.0}/scripts/build/prebuild-only.js +0 -0
- /package/{template-6.4.0-community → template-6.4.0}/scripts/clean.mjs +0 -0
- /package/{template-6.4.0-enterprise → template-7.2.0}/.prettierrc.json +0 -0
- /package/{template-6.4.0-enterprise → template-7.2.0}/README.md +0 -0
- /package/{template-7.2.0-community → template-7.2.0}/_package.json +0 -0
- /package/{template-7.2.0-community → template-7.2.0}/eslint.config.ts +0 -0
- /package/{template-6.4.0-enterprise → template-7.2.0}/gitignore +0 -0
- /package/{template-6.4.0-enterprise → template-7.2.0}/lerna.json +0 -0
- /package/{template-6.4.0-enterprise → template-7.2.0}/packages/ss-admin-widget/index.ts +0 -0
- /package/{template-6.4.0-enterprise → template-7.2.0}/packages/ss-admin-widget/scripts/postpublish.js +0 -0
- /package/{template-6.4.0-enterprise → template-7.2.0}/packages/ss-admin-widget/scripts/prepublish-only.js +0 -0
- /package/{template-6.4.0-enterprise → template-7.2.0}/packages/ss-admin-widget/src/index.ts +0 -0
- /package/{template-6.4.0-enterprise → template-7.2.0}/packages/ss-admin-widget/src/shim-translate.d.ts +0 -0
- /package/{template-6.4.0-enterprise → template-7.2.0}/packages/ss-admin-widget/src/shim-vue.d.ts +0 -0
- /package/{template-7.2.0-community → template-7.2.0}/packages/ss-admin-widget/tsconfig.json +0 -0
- /package/{template-6.4.0-enterprise → template-7.2.0}/packages/ss-boot/.env +0 -0
- /package/{template-6.4.0-enterprise → template-7.2.0}/packages/ss-boot/.env.example +0 -0
- /package/{template-7.2.0-community → template-7.2.0}/packages/ss-boot/package.json +0 -0
- /package/{template-6.4.0-enterprise → template-7.2.0}/packages/ss-boot/public/index.html +0 -0
- /package/{template-6.4.0-enterprise → template-7.2.0}/packages/ss-boot/public/manifest.js +0 -0
- /package/{template-6.4.0-enterprise → template-7.2.0}/packages/ss-boot/src/shim-translate.d.ts +0 -0
- /package/{template-6.4.0-enterprise → template-7.2.0}/packages/ss-boot/src/shim-vue.d.ts +0 -0
- /package/{template-7.2.0-community → template-7.2.0}/packages/ss-boot/tsconfig.json +0 -0
- /package/{template-6.4.0-enterprise → template-7.2.0}/packages/ss-oinone/index.ts +0 -0
- /package/{template-6.4.0-enterprise → template-7.2.0}/packages/ss-oinone/scripts/postpublish.js +0 -0
- /package/{template-6.4.0-enterprise → template-7.2.0}/packages/ss-oinone/scripts/prepublish-only.js +0 -0
- /package/{template-6.4.0-enterprise → template-7.2.0}/packages/ss-oinone/src/index.ts +0 -0
- /package/{template-6.4.0-enterprise → template-7.2.0}/packages/ss-oinone/src/shim-translate.d.ts +0 -0
- /package/{template-6.4.0-enterprise → template-7.2.0}/packages/ss-oinone/src/shim-vue.d.ts +0 -0
- /package/{template-7.2.0-community → template-7.2.0}/packages/ss-oinone/tsconfig.json +0 -0
- /package/{template-6.4.0-enterprise → template-7.2.0}/packages/ss-project/index.ts +0 -0
- /package/{template-6.4.0-enterprise → template-7.2.0}/packages/ss-project/scripts/postpublish.js +0 -0
- /package/{template-6.4.0-enterprise → template-7.2.0}/packages/ss-project/scripts/prepublish-only.js +0 -0
- /package/{template-6.4.0-enterprise → template-7.2.0}/packages/ss-project/src/index.ts +0 -0
- /package/{template-6.4.0-enterprise → template-7.2.0}/packages/ss-project/src/shim-translate.d.ts +0 -0
- /package/{template-6.4.0-enterprise → template-7.2.0}/packages/ss-project/src/shim-vue.d.ts +0 -0
- /package/{template-7.2.0-community → template-7.2.0}/packages/ss-project/tsconfig.json +0 -0
- /package/{template-6.4.0-enterprise → template-7.2.0}/pnpm-workspace.yaml +0 -0
- /package/{template-6.4.0-enterprise → template-7.2.0}/scripts/build/inset-tsconfig.js +0 -0
- /package/{template-6.4.0-enterprise → template-7.2.0}/scripts/build/package-name.js +0 -0
- /package/{template-6.4.0-enterprise → template-7.2.0}/scripts/clean.mjs +0 -0
package/bin/cli.js
CHANGED
|
@@ -1,492 +1,67 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
const { program } = require('commander');
|
|
4
|
-
const inquirer = require('inquirer');
|
|
5
|
-
const fs = require('fs-extra');
|
|
6
|
-
const path = require('path');
|
|
7
4
|
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
5
|
const packageJson = require('../package.json');
|
|
14
|
-
const { t } = require('./i18n');
|
|
6
|
+
const { setLang, t } = require('./i18n');
|
|
15
7
|
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
// 必须调用 resume() 消费响应数据,否则 Node 19+ 默认开启 keepAlive 会导致 socket 保持连接,进程卡住 60 秒
|
|
20
|
-
headRes.resume();
|
|
21
|
-
|
|
22
|
-
if (headRes.statusCode !== 200) {
|
|
23
|
-
reject(new Error(t('fetchFileInfoFailed', { status: headRes.statusCode })));
|
|
24
|
-
return;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
let etag = headRes.headers['etag'];
|
|
28
|
-
if (etag) {
|
|
29
|
-
etag = etag.replace(/"/g, ''); // Clean quotes
|
|
30
|
-
} else {
|
|
31
|
-
etag = headRes.headers['last-modified'] ? Buffer.from(headRes.headers['last-modified']).toString('hex') : 'default';
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
const cacheDir = path.join(os.tmpdir(), 'oinone-cli-cache');
|
|
35
|
-
fs.ensureDirSync(cacheDir);
|
|
36
|
-
|
|
37
|
-
const cachedZipPath = path.join(cacheDir, `static-resources-${etag}.zip`);
|
|
38
|
-
|
|
39
|
-
if (fs.existsSync(cachedZipPath)) {
|
|
40
|
-
console.log(chalk.cyan(t('usingCached')));
|
|
41
|
-
try {
|
|
42
|
-
const zip = new AdmZip(cachedZipPath);
|
|
43
|
-
zip.extractAllTo(targetDir, true);
|
|
44
|
-
resolve();
|
|
45
|
-
} catch (err) {
|
|
46
|
-
fs.unlinkSync(cachedZipPath);
|
|
47
|
-
reject(err);
|
|
48
|
-
}
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
const file = fs.createWriteStream(cachedZipPath);
|
|
53
|
-
|
|
54
|
-
https.get(url, (response) => {
|
|
55
|
-
if (response.statusCode !== 200) {
|
|
56
|
-
response.resume(); // 消费响应数据释放 socket
|
|
57
|
-
reject(new Error(t('downloadFailed', { status: response.statusCode })));
|
|
58
|
-
return;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
const totalBytes = parseInt(response.headers['content-length'], 10);
|
|
62
|
-
let isMB = false;
|
|
63
|
-
let totalDisplay = 0;
|
|
64
|
-
let unit = 'KB';
|
|
65
|
-
|
|
66
|
-
if (totalBytes > 10 * 1024 * 1024) {
|
|
67
|
-
isMB = true;
|
|
68
|
-
unit = 'MB';
|
|
69
|
-
totalDisplay = (totalBytes / (1024 * 1024)).toFixed(2);
|
|
70
|
-
} else {
|
|
71
|
-
totalDisplay = Math.round(totalBytes / 1024);
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
let downloadedBytes = 0;
|
|
75
|
-
let startTime = Date.now();
|
|
76
|
-
|
|
77
|
-
const progressBar = new cliProgress.SingleBar({
|
|
78
|
-
format: chalk.cyan(t('fetchingAwesomeness')) + `[{bar}] {percentage}% | ⏳ {eta}s ${t('progressLeft')} | 📦 {value}/{total} ${unit} | 💨 {speed} {speedUnit}/s`,
|
|
79
|
-
barCompleteChar: '\u2588',
|
|
80
|
-
barIncompleteChar: '\u2591',
|
|
81
|
-
hideCursor: true,
|
|
82
|
-
forceRedraw: true
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
progressBar.start(Number(totalDisplay), 0, { speed: '0.00', speedUnit: 'KB' });
|
|
86
|
-
|
|
87
|
-
response.on('data', (chunk) => {
|
|
88
|
-
downloadedBytes += chunk.length;
|
|
89
|
-
let downloadedDisplay = 0;
|
|
90
|
-
if (isMB) {
|
|
91
|
-
downloadedDisplay = Number((downloadedBytes / (1024 * 1024)).toFixed(2));
|
|
92
|
-
} else {
|
|
93
|
-
downloadedDisplay = Math.round(downloadedBytes / 1024);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
const currentTime = Date.now();
|
|
97
|
-
const elapsedSeconds = (currentTime - startTime) / 1000;
|
|
98
|
-
let speed = 0;
|
|
99
|
-
let speedUnit = 'KB';
|
|
100
|
-
|
|
101
|
-
if (elapsedSeconds > 0) {
|
|
102
|
-
const speedInBytes = downloadedBytes / elapsedSeconds;
|
|
103
|
-
if (speedInBytes > 1024 * 1024) {
|
|
104
|
-
speed = speedInBytes / (1024 * 1024);
|
|
105
|
-
speedUnit = 'MB';
|
|
106
|
-
} else {
|
|
107
|
-
speed = speedInBytes / 1024;
|
|
108
|
-
speedUnit = 'KB';
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
progressBar.update(downloadedDisplay, { speed: speed.toFixed(2), speedUnit });
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
response.pipe(file);
|
|
116
|
-
file.on('finish', () => {
|
|
117
|
-
progressBar.stop();
|
|
118
|
-
file.close();
|
|
119
|
-
try {
|
|
120
|
-
const zip = new AdmZip(cachedZipPath);
|
|
121
|
-
zip.extractAllTo(targetDir, true);
|
|
122
|
-
resolve();
|
|
123
|
-
} catch (err) {
|
|
124
|
-
if (fs.existsSync(cachedZipPath)) fs.unlinkSync(cachedZipPath);
|
|
125
|
-
reject(err);
|
|
126
|
-
}
|
|
127
|
-
});
|
|
128
|
-
}).on('error', (err) => {
|
|
129
|
-
if (fs.existsSync(cachedZipPath)) fs.unlink(cachedZipPath, () => {});
|
|
130
|
-
reject(err);
|
|
131
|
-
});
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
req.on('error', (err) => {
|
|
135
|
-
reject(err);
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
req.end();
|
|
139
|
-
});
|
|
140
|
-
};
|
|
8
|
+
const createAction = require('./commands/create');
|
|
9
|
+
const setupCacheCommand = require('./commands/cache');
|
|
10
|
+
const doctorAction = require('./commands/doctor');
|
|
141
11
|
|
|
142
12
|
program
|
|
143
|
-
.
|
|
144
|
-
.description(t('description'))
|
|
145
|
-
.
|
|
13
|
+
.name('oinone-frontend')
|
|
14
|
+
.description(t('cli.description'))
|
|
15
|
+
.version(packageJson.version, '-v, --version', t('cli.versionOption'))
|
|
16
|
+
.helpOption('-h, --help', t('cli.helpOption'));
|
|
146
17
|
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
.description(t('cacheCmdDesc'))
|
|
151
|
-
.action(() => {
|
|
152
|
-
// If just "cache" is typed without subcommands, show cache help
|
|
153
|
-
cacheCmd.help();
|
|
154
|
-
});
|
|
18
|
+
program
|
|
19
|
+
.option('-l, --lang <lang>', 'Specify language (zh-CN or en-US)')
|
|
20
|
+
;
|
|
155
21
|
|
|
156
|
-
|
|
157
|
-
.
|
|
158
|
-
.
|
|
159
|
-
|
|
160
|
-
const cacheDir = path.join(os.tmpdir(), 'oinone-cli-cache');
|
|
161
|
-
if (fs.existsSync(cacheDir)) {
|
|
162
|
-
fs.removeSync(cacheDir);
|
|
163
|
-
console.log(chalk.green(t('cacheCleaned', { dir: cacheDir })));
|
|
164
|
-
} else {
|
|
165
|
-
console.log(chalk.yellow(t('cacheAlreadyEmpty', { dir: cacheDir })));
|
|
166
|
-
}
|
|
167
|
-
});
|
|
22
|
+
program.hook('preAction', (thisCommand) => {
|
|
23
|
+
const opts = thisCommand.opts();
|
|
24
|
+
setLang(opts.lang);
|
|
25
|
+
});
|
|
168
26
|
|
|
169
|
-
|
|
170
|
-
.command('
|
|
171
|
-
.description(t('
|
|
172
|
-
.
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
totalSize += stat.size;
|
|
185
|
-
|
|
186
|
-
let displaySize = '';
|
|
187
|
-
if (stat.size > 1024 * 1024) {
|
|
188
|
-
displaySize = `${(stat.size / (1024 * 1024)).toFixed(2)} MB`;
|
|
189
|
-
} else {
|
|
190
|
-
displaySize = `${Math.round(stat.size / 1024)} KB`;
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
console.log(` - 📄 ${file} (${displaySize})`);
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
let totalDisplaySize = '';
|
|
197
|
-
if (totalSize > 1024 * 1024) {
|
|
198
|
-
totalDisplaySize = `${(totalSize / (1024 * 1024)).toFixed(2)} MB`;
|
|
199
|
-
} else {
|
|
200
|
-
totalDisplaySize = `${Math.round(totalSize / 1024)} KB`;
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
console.log(chalk.cyan(t('totalCacheSize')) + totalDisplaySize);
|
|
204
|
-
} else {
|
|
205
|
-
console.log(chalk.yellow(t('cacheEmpty')));
|
|
206
|
-
}
|
|
27
|
+
program
|
|
28
|
+
.command('create [projectName]')
|
|
29
|
+
.description(t('create.createCmdDesc'))
|
|
30
|
+
.option('--company-name <name>', 'Company/Organization name (silent mode)')
|
|
31
|
+
.option('--project-name <name>', 'Project name (silent mode)')
|
|
32
|
+
.option('--download-static-resource <boolean>', t('cli.downloadOpt'))
|
|
33
|
+
.option('-o, --oinone-version <version>', t('cli.versionOpt'))
|
|
34
|
+
.option('-e, --edition <edition>', t('cli.editionOpt'))
|
|
35
|
+
.option('--auth-token <token>', 'Oinone registry auth token (for enterprise edition)')
|
|
36
|
+
.option('--write-project-credential', 'Allow writing credentials to project directory')
|
|
37
|
+
.option('-f, --force', 'Overwrite target directory if it exists')
|
|
38
|
+
.option('-d, --dry-run', 'Skip writing files to disk')
|
|
39
|
+
.action((projectNameArg, options, command) => {
|
|
40
|
+
const mergedOptions = { ...program.opts(), ...options };
|
|
41
|
+
return createAction(projectNameArg, mergedOptions);
|
|
207
42
|
});
|
|
208
43
|
|
|
209
|
-
// Create Command (Default Behavior)
|
|
210
44
|
program
|
|
211
|
-
.
|
|
212
|
-
.
|
|
213
|
-
.option('--oinone-version <
|
|
214
|
-
.
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
// Trigger version check without blocking
|
|
222
|
-
let checkReq = null;
|
|
223
|
-
const versionCheckPromise = new Promise((resolve) => {
|
|
224
|
-
checkReq = https.get('https://registry.npmjs.org/-/package/@oinone/cli/dist-tags', { timeout: 3000 }, (res) => {
|
|
225
|
-
let data = '';
|
|
226
|
-
res.on('data', chunk => data += chunk);
|
|
227
|
-
res.on('end', () => {
|
|
228
|
-
try {
|
|
229
|
-
const parsed = JSON.parse(data);
|
|
230
|
-
resolve(parsed.latest);
|
|
231
|
-
} catch (e) {
|
|
232
|
-
resolve(null);
|
|
233
|
-
}
|
|
234
|
-
});
|
|
235
|
-
});
|
|
236
|
-
checkReq.on('timeout', () => {
|
|
237
|
-
checkReq.destroy();
|
|
238
|
-
resolve(null);
|
|
239
|
-
});
|
|
240
|
-
checkReq.on('error', () => {
|
|
241
|
-
resolve(null);
|
|
242
|
-
});
|
|
243
|
-
});
|
|
244
|
-
|
|
245
|
-
try {
|
|
246
|
-
let prefix;
|
|
247
|
-
let fullProjectName;
|
|
248
|
-
let oinoneVersion;
|
|
249
|
-
let edition;
|
|
250
|
-
let downloadStaticResources;
|
|
251
|
-
|
|
252
|
-
if (projectNameArg) {
|
|
253
|
-
// Remove '-frontend' suffix if it exists to form the prefix
|
|
254
|
-
prefix = projectNameArg.endsWith('-frontend')
|
|
255
|
-
? projectNameArg.slice(0, -9)
|
|
256
|
-
: projectNameArg;
|
|
257
|
-
fullProjectName = projectNameArg;
|
|
258
|
-
oinoneVersion = options.oinoneVersion;
|
|
259
|
-
// Ensure oinoneVersion has a tilde prefix
|
|
260
|
-
if (!oinoneVersion.startsWith('~')) {
|
|
261
|
-
oinoneVersion = `~${oinoneVersion}`;
|
|
262
|
-
}
|
|
263
|
-
edition = options.edition;
|
|
264
|
-
downloadStaticResources = options.downloadStaticResource !== 'false';
|
|
265
|
-
} else {
|
|
266
|
-
const answers = await inquirer.prompt([
|
|
267
|
-
{
|
|
268
|
-
type: 'input',
|
|
269
|
-
name: 'companyName',
|
|
270
|
-
message: t('promptCompany'),
|
|
271
|
-
default: 'ss',
|
|
272
|
-
validate: (input) => {
|
|
273
|
-
if (input.trim() === '') return t('errorCompanyEmpty');
|
|
274
|
-
return true;
|
|
275
|
-
},
|
|
276
|
-
},
|
|
277
|
-
{
|
|
278
|
-
type: 'input',
|
|
279
|
-
name: 'projectName',
|
|
280
|
-
message: t('promptProject'),
|
|
281
|
-
default: 'oms',
|
|
282
|
-
validate: (input) => {
|
|
283
|
-
if (input.trim() === '') return t('errorProjectEmpty');
|
|
284
|
-
return true;
|
|
285
|
-
},
|
|
286
|
-
},
|
|
287
|
-
{
|
|
288
|
-
type: 'list',
|
|
289
|
-
name: 'edition',
|
|
290
|
-
message: t('promptEdition'),
|
|
291
|
-
choices: [
|
|
292
|
-
{ name: t('editionCommunity'), value: 'community' },
|
|
293
|
-
{ name: t('editionEnterprise'), value: 'enterprise' }
|
|
294
|
-
],
|
|
295
|
-
default: 'community'
|
|
296
|
-
},
|
|
297
|
-
{
|
|
298
|
-
type: 'list',
|
|
299
|
-
name: 'oinoneVersion',
|
|
300
|
-
message: t('promptVersion'),
|
|
301
|
-
choices: [
|
|
302
|
-
{ name: t('version720'), value: '~7.2.0' },
|
|
303
|
-
{ name: t('version640'), value: '~6.4.0' }
|
|
304
|
-
],
|
|
305
|
-
default: '~7.2.0'
|
|
306
|
-
},
|
|
307
|
-
{
|
|
308
|
-
type: 'confirm',
|
|
309
|
-
name: 'downloadStaticResources',
|
|
310
|
-
message: t('promptDownload'),
|
|
311
|
-
default: true
|
|
312
|
-
}
|
|
313
|
-
]);
|
|
314
|
-
|
|
315
|
-
prefix = answers.companyName;
|
|
316
|
-
fullProjectName = `${answers.companyName}-${answers.projectName}-frontend`;
|
|
317
|
-
oinoneVersion = answers.oinoneVersion;
|
|
318
|
-
edition = answers.edition;
|
|
319
|
-
downloadStaticResources = answers.downloadStaticResources;
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
const targetPath = path.resolve(process.cwd(), fullProjectName);
|
|
323
|
-
|
|
324
|
-
if (fs.existsSync(targetPath)) {
|
|
325
|
-
console.log(chalk.red(t('errorDirExists', { name: fullProjectName })));
|
|
326
|
-
process.exit(1);
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
const spinner = ora(t('weavingMagic')).start();
|
|
330
|
-
|
|
331
|
-
const versionDir = oinoneVersion.replace(/[^0-9.]/g, ''); // Extract '7.2.0' or '6.4.0'
|
|
332
|
-
const templatePath = path.resolve(__dirname, `../template-${versionDir}-${edition}`);
|
|
333
|
-
|
|
334
|
-
if (!fs.existsSync(templatePath)) {
|
|
335
|
-
spinner.fail(chalk.red(t('errorTemplateMissing', { version: oinoneVersion, edition })));
|
|
336
|
-
process.exit(1);
|
|
337
|
-
}
|
|
338
|
-
|
|
339
|
-
// Helper function to process files recursively
|
|
340
|
-
const processDirectory = async (dirPath) => {
|
|
341
|
-
const files = await fs.readdir(dirPath);
|
|
342
|
-
for (const file of files) {
|
|
343
|
-
const currentPath = path.join(dirPath, file);
|
|
344
|
-
const stat = await fs.stat(currentPath);
|
|
345
|
-
|
|
346
|
-
// Rename directory if it starts with 'ss-'
|
|
347
|
-
let newPath = currentPath;
|
|
348
|
-
if (file.startsWith('ss-')) {
|
|
349
|
-
const newFile = file.replace(/^ss-/, `${prefix}-`);
|
|
350
|
-
newPath = path.join(dirPath, newFile);
|
|
351
|
-
await fs.rename(currentPath, newPath);
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
if (stat.isDirectory()) {
|
|
355
|
-
await processDirectory(newPath);
|
|
356
|
-
} else {
|
|
357
|
-
// Check if it's a text file
|
|
358
|
-
const ext = path.extname(newPath);
|
|
359
|
-
const isTextFile = !['.png', '.ico', '.jpg', '.jpeg', '.gif'].includes(ext);
|
|
360
|
-
|
|
361
|
-
if (isTextFile) {
|
|
362
|
-
let content = await fs.readFile(newPath, 'utf8');
|
|
363
|
-
let hasChanges = false;
|
|
364
|
-
|
|
365
|
-
// Replace 'ss-' with '${prefix}-' but avoid replacing within words
|
|
366
|
-
// We use a regex that matches 'ss-' either at the start of a string or preceded by non-word characters
|
|
367
|
-
// To prevent changing things like postcss -> postprefix
|
|
368
|
-
const regex = /(^|[^a-zA-Z])ss-/g;
|
|
369
|
-
if (regex.test(content)) {
|
|
370
|
-
content = content.replace(regex, `$1${prefix}-`);
|
|
371
|
-
hasChanges = true;
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
// Replace '@ss/oinone' with `@${prefix}/oinone`
|
|
375
|
-
if (content.includes('@ss/')) {
|
|
376
|
-
content = content.replace(/@ss\//g, `@${prefix}/`);
|
|
377
|
-
hasChanges = true;
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
if (hasChanges) {
|
|
381
|
-
await fs.writeFile(newPath, content, 'utf8');
|
|
382
|
-
}
|
|
383
|
-
}
|
|
384
|
-
}
|
|
385
|
-
}
|
|
386
|
-
};
|
|
387
|
-
|
|
388
|
-
// Copy template files
|
|
389
|
-
await fs.copy(templatePath, targetPath, {
|
|
390
|
-
filter: (src) => {
|
|
391
|
-
// Ignore node_modules just in case
|
|
392
|
-
const relativePath = path.relative(templatePath, src);
|
|
393
|
-
if (relativePath.split(path.sep).includes('node_modules')) return false;
|
|
394
|
-
return true;
|
|
395
|
-
}
|
|
396
|
-
});
|
|
397
|
-
|
|
398
|
-
// Process the copied files (rename and replace content)
|
|
399
|
-
await processDirectory(targetPath);
|
|
400
|
-
|
|
401
|
-
// Handle package.json
|
|
402
|
-
const pkgPath = path.join(targetPath, '_package.json');
|
|
403
|
-
const newPkgPath = path.join(targetPath, 'package.json');
|
|
404
|
-
if (fs.existsSync(pkgPath)) {
|
|
405
|
-
const pkgContent = await fs.readJson(pkgPath);
|
|
406
|
-
pkgContent.name = fullProjectName;
|
|
407
|
-
await fs.writeJson(newPkgPath, pkgContent, { spaces: 2 });
|
|
408
|
-
await fs.remove(pkgPath);
|
|
409
|
-
}
|
|
410
|
-
|
|
411
|
-
// Handle gitignore
|
|
412
|
-
const gitignorePath = path.join(targetPath, 'gitignore');
|
|
413
|
-
const newGitignorePath = path.join(targetPath, '.gitignore');
|
|
414
|
-
if (fs.existsSync(gitignorePath)) {
|
|
415
|
-
await fs.move(gitignorePath, newGitignorePath);
|
|
416
|
-
}
|
|
417
|
-
|
|
418
|
-
// Handle npmrc
|
|
419
|
-
const npmrcPath = path.join(targetPath, 'npmrc');
|
|
420
|
-
const newNpmrcPath = path.join(targetPath, '.npmrc');
|
|
421
|
-
if (fs.existsSync(npmrcPath)) {
|
|
422
|
-
await fs.move(npmrcPath, newNpmrcPath);
|
|
423
|
-
}
|
|
424
|
-
|
|
425
|
-
if (downloadStaticResources) {
|
|
426
|
-
spinner.succeed(chalk.green(t('structureReady')));
|
|
427
|
-
console.log(chalk.cyan(t('haulingStatic')));
|
|
428
|
-
try {
|
|
429
|
-
const ossDir = path.join(targetPath, 'packages', `${prefix}-boot`, 'public', 'oss');
|
|
430
|
-
await fs.ensureDir(ossDir);
|
|
431
|
-
await downloadAndExtractZip('https://pamirs.oss-cn-hangzhou.aliyuncs.com/oinone/installer/static-resources.zip', ossDir);
|
|
432
|
-
console.log(chalk.green(t('staticDownloaded')));
|
|
433
|
-
} catch (err) {
|
|
434
|
-
console.log(chalk.yellow(t('staticHiccup', { msg: err.message })));
|
|
435
|
-
}
|
|
436
|
-
} else {
|
|
437
|
-
spinner.succeed(chalk.green(t('projectCreated')));
|
|
438
|
-
const relativeOssDir = `packages/${prefix}-boot/public/oss`;
|
|
439
|
-
console.log(chalk.yellow(t('skipStaticWarning')));
|
|
440
|
-
console.log(chalk.yellow(t('manualStaticInstructions')));
|
|
441
|
-
console.log(chalk.cyan(` mkdir -p ${fullProjectName}/${relativeOssDir}`));
|
|
442
|
-
console.log(chalk.cyan(` curl -L https://pamirs.oss-cn-hangzhou.aliyuncs.com/oinone/installer/static-resources.zip -o static-resources.zip`));
|
|
443
|
-
console.log(chalk.cyan(` unzip static-resources.zip -d ${fullProjectName}/${relativeOssDir}`));
|
|
444
|
-
console.log(chalk.cyan(` rm static-resources.zip`));
|
|
445
|
-
}
|
|
446
|
-
|
|
447
|
-
console.log(t('partyStarted'));
|
|
448
|
-
console.log(chalk.cyan(` cd ${fullProjectName}`));
|
|
449
|
-
console.log(chalk.cyan(` pnpm install`));
|
|
450
|
-
console.log(chalk.cyan(` pnpm run dev\n`));
|
|
451
|
-
console.log(chalk.magenta(t('happyCoding')));
|
|
45
|
+
.command('doctor')
|
|
46
|
+
.description(t('doctor.doctorCmdDesc'))
|
|
47
|
+
.option('-o, --oinone-version <version>', t('cli.versionOpt'))
|
|
48
|
+
.action((...args) => {
|
|
49
|
+
const cmd = args[args.length - 1];
|
|
50
|
+
const mergedOptions = { ...program.opts(), ...(cmd && typeof cmd.opts === 'function' ? cmd.opts() : {}) };
|
|
51
|
+
return doctorAction(mergedOptions);
|
|
52
|
+
});
|
|
452
53
|
|
|
453
|
-
|
|
454
|
-
const latestVersion = await Promise.race([
|
|
455
|
-
versionCheckPromise,
|
|
456
|
-
new Promise(resolve => setTimeout(() => {
|
|
457
|
-
if (checkReq) checkReq.destroy();
|
|
458
|
-
resolve(null);
|
|
459
|
-
}, 1000))
|
|
460
|
-
]);
|
|
54
|
+
setupCacheCommand();
|
|
461
55
|
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
const numC = c[i] || 0;
|
|
468
|
-
const numL = l[i] || 0;
|
|
469
|
-
if (numL > numC) return true;
|
|
470
|
-
if (numL < numC) return false;
|
|
471
|
-
}
|
|
472
|
-
return false;
|
|
473
|
-
};
|
|
474
|
-
|
|
475
|
-
if (isNewerVersion(packageJson.version, latestVersion)) {
|
|
476
|
-
console.log(chalk.yellow(`====================================================`));
|
|
477
|
-
console.log(chalk.yellow(t('updateAvailable', { current: chalk.red(packageJson.version), latest: chalk.green(latestVersion) })));
|
|
478
|
-
console.log(chalk.yellow(t('runUpdate', { cmd: chalk.cyan('npm install -g @oinone/cli') })));
|
|
479
|
-
console.log(chalk.yellow(`====================================================\n`));
|
|
480
|
-
}
|
|
481
|
-
}
|
|
482
|
-
} catch (e) {
|
|
483
|
-
// ignore errors
|
|
484
|
-
}
|
|
56
|
+
program.on('command:*', (operands) => {
|
|
57
|
+
const first = Array.isArray(operands) && operands.length > 0 ? operands[0] : '';
|
|
58
|
+
console.log(chalk.red(t('cli.requireCreateSubcommand', { cmd: first })));
|
|
59
|
+
process.exit(1);
|
|
60
|
+
});
|
|
485
61
|
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
});
|
|
62
|
+
if (process.argv.length <= 2) {
|
|
63
|
+
program.outputHelp();
|
|
64
|
+
process.exit(0);
|
|
65
|
+
}
|
|
491
66
|
|
|
492
67
|
program.parse(process.argv);
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
const { program } = require('commander');
|
|
2
|
+
const fs = require('fs-extra');
|
|
3
|
+
const path = require('path');
|
|
4
|
+
const os = require('os');
|
|
5
|
+
const chalk = require('chalk');
|
|
6
|
+
const { t } = require('../i18n');
|
|
7
|
+
|
|
8
|
+
function setupCacheCommand() {
|
|
9
|
+
const cacheCmd = program
|
|
10
|
+
.command('cache')
|
|
11
|
+
.description(t('cache.cacheCmdDesc'))
|
|
12
|
+
.action(() => {
|
|
13
|
+
cacheCmd.help();
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
cacheCmd
|
|
17
|
+
.command('clean')
|
|
18
|
+
.description(t('cache.cacheCleanDesc'))
|
|
19
|
+
.action(() => {
|
|
20
|
+
const cacheDir = path.join(os.tmpdir(), 'oinone-cli-cache');
|
|
21
|
+
if (fs.existsSync(cacheDir)) {
|
|
22
|
+
fs.removeSync(cacheDir);
|
|
23
|
+
console.log(chalk.green(t('cache.cacheCleaned', { dir: cacheDir })));
|
|
24
|
+
} else {
|
|
25
|
+
console.log(chalk.yellow(t('cache.cacheAlreadyEmpty', { dir: cacheDir })));
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
cacheCmd
|
|
30
|
+
.command('info')
|
|
31
|
+
.description(t('cache.cacheInfoDesc'))
|
|
32
|
+
.action(async () => {
|
|
33
|
+
const cacheDir = path.join(os.tmpdir(), 'oinone-cli-cache');
|
|
34
|
+
console.log(chalk.cyan(t('cache.cacheDir')) + cacheDir);
|
|
35
|
+
|
|
36
|
+
if (fs.existsSync(cacheDir)) {
|
|
37
|
+
const files = await fs.readdir(cacheDir);
|
|
38
|
+
let totalSize = 0;
|
|
39
|
+
|
|
40
|
+
console.log(chalk.cyan(t('cache.cachedFiles')));
|
|
41
|
+
for (const file of files) {
|
|
42
|
+
const filePath = path.join(cacheDir, file);
|
|
43
|
+
const stat = await fs.stat(filePath);
|
|
44
|
+
totalSize += stat.size;
|
|
45
|
+
|
|
46
|
+
let displaySize = '';
|
|
47
|
+
if (stat.size > 1024 * 1024) {
|
|
48
|
+
displaySize = `${(stat.size / (1024 * 1024)).toFixed(2)} MB`;
|
|
49
|
+
} else {
|
|
50
|
+
displaySize = `${Math.round(stat.size / 1024)} KB`;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
console.log(` - 📄 ${file} (${displaySize})`);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
let totalDisplaySize = '';
|
|
57
|
+
if (totalSize > 1024 * 1024) {
|
|
58
|
+
totalDisplaySize = `${(totalSize / (1024 * 1024)).toFixed(2)} MB`;
|
|
59
|
+
} else {
|
|
60
|
+
totalDisplaySize = `${Math.round(totalSize / 1024)} KB`;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
console.log(chalk.cyan(t('cache.totalCacheSize')) + totalDisplaySize);
|
|
64
|
+
} else {
|
|
65
|
+
console.log(chalk.yellow(t('cache.cacheEmpty')));
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
module.exports = setupCacheCommand;
|