@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
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
const fs = require('fs-extra');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const chalk = require('chalk');
|
|
4
|
+
const { t } = require('../../i18n');
|
|
5
|
+
const config = require('../../config');
|
|
6
|
+
|
|
7
|
+
async function applyEnterpriseConfig({ targetPath, prefix, oinoneVersion, authToken, writeProjectCredential, newNpmrcPath, newGitignorePath }) {
|
|
8
|
+
const entConfig = config.getEnterpriseConfig(oinoneVersion);
|
|
9
|
+
|
|
10
|
+
if (entConfig.npmrc && entConfig.npmrc.uncommentRegistry && await fs.pathExists(newNpmrcPath)) {
|
|
11
|
+
let npmrcContent = await fs.readFile(newNpmrcPath, 'utf8');
|
|
12
|
+
npmrcContent = npmrcContent.replace(/#\s*(@oinone:registry=.*)/, '$1');
|
|
13
|
+
await fs.writeFile(newNpmrcPath, npmrcContent, 'utf8');
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const bootPkgPath = path.join(targetPath, 'packages', `${prefix}-boot`, 'package.json');
|
|
17
|
+
if (await fs.pathExists(bootPkgPath)) {
|
|
18
|
+
const bootPkg = await fs.readJson(bootPkgPath);
|
|
19
|
+
if (!bootPkg.dependencies) bootPkg.dependencies = {};
|
|
20
|
+
Object.assign(bootPkg.dependencies, entConfig.packageJson.dependencies);
|
|
21
|
+
|
|
22
|
+
const sortedDeps = {};
|
|
23
|
+
Object.keys(bootPkg.dependencies).sort().forEach(key => {
|
|
24
|
+
sortedDeps[key] = bootPkg.dependencies[key];
|
|
25
|
+
});
|
|
26
|
+
bootPkg.dependencies = sortedDeps;
|
|
27
|
+
|
|
28
|
+
await fs.writeJson(bootPkgPath, bootPkg, { spaces: 2 });
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const mainTsPath = path.join(targetPath, 'packages', `${prefix}-boot`, 'src', 'main.ts');
|
|
32
|
+
if (await fs.pathExists(mainTsPath)) {
|
|
33
|
+
let mainTsContent = await fs.readFile(mainTsPath, 'utf8');
|
|
34
|
+
|
|
35
|
+
if (entConfig.mainTs.cssImports && entConfig.mainTs.cssImports.length > 0) {
|
|
36
|
+
mainTsContent = mainTsContent.replace(
|
|
37
|
+
"import '@oinone/kunlun-vue-ui-el/dist/oinone-kunlun-vue-ui-el.css';",
|
|
38
|
+
"import '@oinone/kunlun-vue-ui-el/dist/oinone-kunlun-vue-ui-el.css';\n" + entConfig.mainTs.cssImports.join('\n') + "\n"
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (entConfig.mainTs.scriptImports && entConfig.mainTs.scriptImports.length > 0) {
|
|
43
|
+
mainTsContent = mainTsContent.replace(
|
|
44
|
+
"// 标准能力",
|
|
45
|
+
entConfig.mainTs.scriptImports.join('\n') + "\n// 标准能力"
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (entConfig.mainTs.components && entConfig.mainTs.components.length > 0) {
|
|
50
|
+
mainTsContent = mainTsContent.replace(
|
|
51
|
+
"kunlunVueUiEl: import('@oinone/kunlun-vue-ui-el'),",
|
|
52
|
+
"kunlunVueUiEl: import('@oinone/kunlun-vue-ui-el'),\n " + entConfig.mainTs.components.join('\n ')
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
await fs.writeFile(mainTsPath, mainTsContent, 'utf8');
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
if (authToken && writeProjectCredential) {
|
|
60
|
+
let npmrcContent = '';
|
|
61
|
+
if (await fs.pathExists(newNpmrcPath)) {
|
|
62
|
+
npmrcContent = await fs.readFile(newNpmrcPath, 'utf8');
|
|
63
|
+
}
|
|
64
|
+
npmrcContent += `\n//nexus.shushi.pro/repository/pamirs-releases/:_authToken=${authToken}`;
|
|
65
|
+
await fs.writeFile(newNpmrcPath, npmrcContent, 'utf8');
|
|
66
|
+
|
|
67
|
+
let gitignoreContent = '';
|
|
68
|
+
if (await fs.pathExists(newGitignorePath)) {
|
|
69
|
+
gitignoreContent = await fs.readFile(newGitignorePath, 'utf8');
|
|
70
|
+
}
|
|
71
|
+
if (!gitignoreContent.includes('\n.npmrc') && !gitignoreContent.includes('\n/.npmrc')) {
|
|
72
|
+
const suffix = gitignoreContent.endsWith('\n') || gitignoreContent === '' ? '' : '\n';
|
|
73
|
+
gitignoreContent += `${suffix}.npmrc\n`;
|
|
74
|
+
await fs.writeFile(newGitignorePath, gitignoreContent, 'utf8');
|
|
75
|
+
}
|
|
76
|
+
} else if (authToken && !writeProjectCredential) {
|
|
77
|
+
console.log(chalk.yellow(t('create.skipProjectCredential')));
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
module.exports = { applyEnterpriseConfig };
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
const inquirer = require('inquirer');
|
|
2
|
+
const fs = require('fs-extra');
|
|
3
|
+
const path = require('path');
|
|
4
|
+
const chalk = require('chalk');
|
|
5
|
+
const ora = require('ora');
|
|
6
|
+
const packageJson = require('../../../package.json');
|
|
7
|
+
const { t } = require('../../i18n');
|
|
8
|
+
const { resolveCreateInputs } = require('./prompts');
|
|
9
|
+
const { resolveTemplate } = require('./template');
|
|
10
|
+
const { createProjectFromTemplate } = require('./project');
|
|
11
|
+
const { applyEnterpriseConfig } = require('./enterprise');
|
|
12
|
+
const { handleStaticResources } = require('./static-resources');
|
|
13
|
+
const { fetchKunlunMinorVersionsFromMirror } = require('./version-source');
|
|
14
|
+
const { startNpmDistTagLatestCheck, isNewerVersion } = require('./update-check');
|
|
15
|
+
const { compareSemver, isAtLeast73 } = require('../../utils/oinone-version');
|
|
16
|
+
|
|
17
|
+
async function createAction(projectNameArg, options) {
|
|
18
|
+
if (projectNameArg === 'cache') {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const updateCheck = startNpmDistTagLatestCheck('@oinone/cli', 3000);
|
|
23
|
+
|
|
24
|
+
try {
|
|
25
|
+
const {
|
|
26
|
+
prefix,
|
|
27
|
+
fullProjectName,
|
|
28
|
+
oinoneVersion,
|
|
29
|
+
edition,
|
|
30
|
+
downloadStaticResources,
|
|
31
|
+
authToken,
|
|
32
|
+
isSilent
|
|
33
|
+
} = await resolveCreateInputs(projectNameArg, options);
|
|
34
|
+
|
|
35
|
+
const targetPath = path.resolve(process.cwd(), fullProjectName);
|
|
36
|
+
|
|
37
|
+
if (await fs.pathExists(targetPath)) {
|
|
38
|
+
if (options.force) {
|
|
39
|
+
console.log(chalk.yellow(`\n⚠️ ${t('create.overwritePrompt', { name: fullProjectName })}`));
|
|
40
|
+
} else {
|
|
41
|
+
const { overwrite } = await inquirer.prompt([{
|
|
42
|
+
type: 'confirm',
|
|
43
|
+
name: 'overwrite',
|
|
44
|
+
message: t('create.overwritePrompt', { name: fullProjectName }),
|
|
45
|
+
default: false
|
|
46
|
+
}]);
|
|
47
|
+
if (!overwrite) {
|
|
48
|
+
console.log(chalk.red(t('common.canceled')));
|
|
49
|
+
process.exit(1);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const { templatePath, selectedMinorVersion } = resolveTemplate(oinoneVersion, edition);
|
|
55
|
+
|
|
56
|
+
if (options.dryRun) {
|
|
57
|
+
console.log(chalk.yellow(t('common.dryRun')));
|
|
58
|
+
process.exit(0);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const spinner = ora(t('create.weavingMagic')).start();
|
|
62
|
+
|
|
63
|
+
const { newGitignorePath, newNpmrcPath } = await createProjectFromTemplate({
|
|
64
|
+
templatePath,
|
|
65
|
+
targetPath,
|
|
66
|
+
prefix,
|
|
67
|
+
fullProjectName
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
if (edition === 'enterprise') {
|
|
71
|
+
await applyEnterpriseConfig({
|
|
72
|
+
targetPath,
|
|
73
|
+
prefix,
|
|
74
|
+
oinoneVersion,
|
|
75
|
+
authToken,
|
|
76
|
+
writeProjectCredential: options.writeProjectCredential,
|
|
77
|
+
newNpmrcPath,
|
|
78
|
+
newGitignorePath
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
await handleStaticResources({ downloadStaticResources, spinner, prefix, targetPath, fullProjectName });
|
|
83
|
+
|
|
84
|
+
console.log(t('create.partyStarted'));
|
|
85
|
+
console.log(chalk.cyan(` cd ${fullProjectName}`));
|
|
86
|
+
console.log(chalk.cyan(` pnpm install`));
|
|
87
|
+
console.log(chalk.cyan(` pnpm run dev\n`));
|
|
88
|
+
console.log(chalk.magenta(t('create.happyCoding')));
|
|
89
|
+
|
|
90
|
+
if (isSilent && selectedMinorVersion && compareSemver(selectedMinorVersion, '7.3.0') < 0) {
|
|
91
|
+
try {
|
|
92
|
+
const remoteMinorVersions = await fetchKunlunMinorVersionsFromMirror(200);
|
|
93
|
+
if (remoteMinorVersions && remoteMinorVersions.length) {
|
|
94
|
+
const latestNewMinor = remoteMinorVersions.find(v => isAtLeast73(v));
|
|
95
|
+
if (latestNewMinor && compareSemver(latestNewMinor, selectedMinorVersion) > 0) {
|
|
96
|
+
console.log(chalk.yellow(`====================================================`));
|
|
97
|
+
console.log(chalk.yellow(t('common.newMinorAvailable', { latest: chalk.green(latestNewMinor) })));
|
|
98
|
+
console.log(chalk.yellow(`====================================================\n`));
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
} catch (e) {
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
try {
|
|
106
|
+
const latestVersion = await Promise.race([
|
|
107
|
+
updateCheck.promise,
|
|
108
|
+
new Promise(resolve => setTimeout(() => {
|
|
109
|
+
updateCheck.cancel();
|
|
110
|
+
resolve(null);
|
|
111
|
+
}, 1000))
|
|
112
|
+
]);
|
|
113
|
+
|
|
114
|
+
if (latestVersion && isNewerVersion(packageJson.version, latestVersion)) {
|
|
115
|
+
console.log(chalk.yellow(`====================================================`));
|
|
116
|
+
console.log(chalk.yellow(t('common.updateAvailable', { current: chalk.red(packageJson.version), latest: chalk.green(latestVersion) })));
|
|
117
|
+
console.log(chalk.yellow(t('common.runUpdate', { cmd: chalk.cyan('npm install -g @oinone/cli') })));
|
|
118
|
+
console.log(chalk.yellow(`====================================================\n`));
|
|
119
|
+
}
|
|
120
|
+
} catch (e) {
|
|
121
|
+
}
|
|
122
|
+
} catch (error) {
|
|
123
|
+
console.error(chalk.red(t('common.somethingBroke', { msg: error.message })));
|
|
124
|
+
process.exit(1);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
module.exports = createAction;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
const fs = require('fs-extra');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
|
|
4
|
+
async function processDirectory(dirPath, prefix) {
|
|
5
|
+
const files = await fs.readdir(dirPath);
|
|
6
|
+
for (const file of files) {
|
|
7
|
+
const currentPath = path.join(dirPath, file);
|
|
8
|
+
const stat = await fs.stat(currentPath);
|
|
9
|
+
|
|
10
|
+
let newPath = currentPath;
|
|
11
|
+
if (file.startsWith('ss-')) {
|
|
12
|
+
const newFile = file.replace(/^ss-/, `${prefix}-`);
|
|
13
|
+
newPath = path.join(dirPath, newFile);
|
|
14
|
+
await fs.rename(currentPath, newPath);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
if (stat.isDirectory()) {
|
|
18
|
+
await processDirectory(newPath, prefix);
|
|
19
|
+
} else {
|
|
20
|
+
const ext = path.extname(newPath);
|
|
21
|
+
const isTextFile = !['.png', '.ico', '.jpg', '.jpeg', '.gif'].includes(ext);
|
|
22
|
+
|
|
23
|
+
if (isTextFile) {
|
|
24
|
+
let content = await fs.readFile(newPath, 'utf8');
|
|
25
|
+
let hasChanges = false;
|
|
26
|
+
|
|
27
|
+
const regex = /(^|[^a-zA-Z])ss-/g;
|
|
28
|
+
if (regex.test(content)) {
|
|
29
|
+
content = content.replace(regex, `$1${prefix}-`);
|
|
30
|
+
hasChanges = true;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (content.includes('@ss/')) {
|
|
34
|
+
content = content.replace(/@ss\//g, `@${prefix}/`);
|
|
35
|
+
hasChanges = true;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (hasChanges) {
|
|
39
|
+
await fs.writeFile(newPath, content, 'utf8');
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
async function createProjectFromTemplate({ templatePath, targetPath, prefix, fullProjectName }) {
|
|
47
|
+
await fs.copy(templatePath, targetPath, {
|
|
48
|
+
filter: (src) => {
|
|
49
|
+
const relativePath = path.relative(templatePath, src);
|
|
50
|
+
if (relativePath.split(path.sep).includes('node_modules')) return false;
|
|
51
|
+
return true;
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
await processDirectory(targetPath, prefix);
|
|
56
|
+
|
|
57
|
+
const pkgPath = path.join(targetPath, '_package.json');
|
|
58
|
+
const newPkgPath = path.join(targetPath, 'package.json');
|
|
59
|
+
if (await fs.pathExists(pkgPath)) {
|
|
60
|
+
const pkgContent = await fs.readJson(pkgPath);
|
|
61
|
+
pkgContent.name = fullProjectName;
|
|
62
|
+
await fs.writeJson(newPkgPath, pkgContent, { spaces: 2 });
|
|
63
|
+
await fs.remove(pkgPath);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const gitignorePath = path.join(targetPath, 'gitignore');
|
|
67
|
+
const newGitignorePath = path.join(targetPath, '.gitignore');
|
|
68
|
+
if (await fs.pathExists(gitignorePath)) {
|
|
69
|
+
await fs.move(gitignorePath, newGitignorePath);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const npmrcPath = path.join(targetPath, 'npmrc');
|
|
73
|
+
const newNpmrcPath = path.join(targetPath, '.npmrc');
|
|
74
|
+
if (await fs.pathExists(npmrcPath)) {
|
|
75
|
+
await fs.move(npmrcPath, newNpmrcPath);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return { newGitignorePath, newNpmrcPath };
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
module.exports = { createProjectFromTemplate };
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
const inquirer = require('inquirer');
|
|
2
|
+
const { t } = require('../../i18n');
|
|
3
|
+
const { fetchKunlunMinorVersionsFromMirror } = require('./version-source');
|
|
4
|
+
const { compareSemver, normalizeToMinorVersion, isSupportedMinorVersion } = require('../../utils/oinone-version');
|
|
5
|
+
|
|
6
|
+
async function resolveCreateInputs(projectNameArg, options) {
|
|
7
|
+
let prefix;
|
|
8
|
+
let fullProjectName;
|
|
9
|
+
let oinoneVersion;
|
|
10
|
+
let edition;
|
|
11
|
+
let downloadStaticResources;
|
|
12
|
+
|
|
13
|
+
const isSilent = !!(projectNameArg || (options.companyName && options.projectName));
|
|
14
|
+
|
|
15
|
+
if (isSilent) {
|
|
16
|
+
if (projectNameArg) {
|
|
17
|
+
prefix = projectNameArg.endsWith('-frontend')
|
|
18
|
+
? projectNameArg.slice(0, -9)
|
|
19
|
+
: projectNameArg;
|
|
20
|
+
fullProjectName = projectNameArg;
|
|
21
|
+
} else {
|
|
22
|
+
prefix = options.companyName;
|
|
23
|
+
fullProjectName = `${options.companyName}-${options.projectName}-frontend`;
|
|
24
|
+
}
|
|
25
|
+
oinoneVersion = options.oinoneVersion;
|
|
26
|
+
const normalizedMinor = normalizeToMinorVersion(oinoneVersion);
|
|
27
|
+
if (normalizedMinor) {
|
|
28
|
+
oinoneVersion = `~${normalizedMinor}`;
|
|
29
|
+
} else if (oinoneVersion && !oinoneVersion.startsWith('~')) {
|
|
30
|
+
oinoneVersion = `~${oinoneVersion}`;
|
|
31
|
+
}
|
|
32
|
+
edition = options.edition;
|
|
33
|
+
downloadStaticResources = options.downloadStaticResource !== 'false';
|
|
34
|
+
} else {
|
|
35
|
+
const remoteMinorVersions = await fetchKunlunMinorVersionsFromMirror(900);
|
|
36
|
+
const versionChoices = [
|
|
37
|
+
{ name: t('create.version720', { version: '7.2.0' }), value: '~7.2.0' },
|
|
38
|
+
{ name: t('create.version640', { version: '6.4.0' }), value: '~6.4.0' }
|
|
39
|
+
];
|
|
40
|
+
if (remoteMinorVersions && remoteMinorVersions.length) {
|
|
41
|
+
for (const v of remoteMinorVersions) {
|
|
42
|
+
if (v === '7.2.0' || v === '6.4.0') continue;
|
|
43
|
+
if (!isSupportedMinorVersion(v)) continue;
|
|
44
|
+
if (compareSemver(v, '7.2.0') < 0 && v !== '6.4.0') continue;
|
|
45
|
+
versionChoices.push({ name: t('create.versionOther', { version: v }), value: `~${v}` });
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
const answers = await inquirer.prompt([
|
|
49
|
+
{
|
|
50
|
+
type: 'input',
|
|
51
|
+
name: 'companyName',
|
|
52
|
+
message: t('create.promptCompany'),
|
|
53
|
+
default: 'ss',
|
|
54
|
+
validate: (input) => {
|
|
55
|
+
if (input.trim() === '') return t('create.errorCompanyEmpty');
|
|
56
|
+
return true;
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
type: 'input',
|
|
61
|
+
name: 'projectName',
|
|
62
|
+
message: t('create.promptProject'),
|
|
63
|
+
default: 'oms',
|
|
64
|
+
validate: (input) => {
|
|
65
|
+
if (input.trim() === '') return t('create.errorProjectEmpty');
|
|
66
|
+
return true;
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
type: 'list',
|
|
71
|
+
name: 'edition',
|
|
72
|
+
message: t('create.promptEdition'),
|
|
73
|
+
choices: [
|
|
74
|
+
{ name: t('create.editionCommunity'), value: 'community' },
|
|
75
|
+
{ name: t('create.editionEnterprise'), value: 'enterprise' }
|
|
76
|
+
],
|
|
77
|
+
default: 'community'
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
type: 'list',
|
|
81
|
+
name: 'oinoneVersion',
|
|
82
|
+
message: t('create.promptVersion'),
|
|
83
|
+
choices: versionChoices,
|
|
84
|
+
default: '~7.2.0'
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
type: 'confirm',
|
|
88
|
+
name: 'downloadStaticResources',
|
|
89
|
+
message: t('create.promptDownload'),
|
|
90
|
+
default: true
|
|
91
|
+
}
|
|
92
|
+
]);
|
|
93
|
+
|
|
94
|
+
prefix = answers.companyName;
|
|
95
|
+
fullProjectName = `${answers.companyName}-${answers.projectName}-frontend`;
|
|
96
|
+
oinoneVersion = answers.oinoneVersion;
|
|
97
|
+
const normalizedMinor = normalizeToMinorVersion(oinoneVersion);
|
|
98
|
+
if (normalizedMinor) {
|
|
99
|
+
oinoneVersion = `~${normalizedMinor}`;
|
|
100
|
+
}
|
|
101
|
+
edition = answers.edition;
|
|
102
|
+
downloadStaticResources = answers.downloadStaticResources;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
let authToken = options.authToken;
|
|
106
|
+
if (edition === 'enterprise' && !isSilent) {
|
|
107
|
+
if (authToken === undefined) {
|
|
108
|
+
const { wantRepo } = await inquirer.prompt([{
|
|
109
|
+
type: 'confirm',
|
|
110
|
+
name: 'wantRepo',
|
|
111
|
+
message: t('create.promptWantRepo'),
|
|
112
|
+
default: true
|
|
113
|
+
}]);
|
|
114
|
+
if (wantRepo) {
|
|
115
|
+
const creds = await inquirer.prompt([
|
|
116
|
+
{ type: 'password', name: 'authToken', message: t('create.promptAuthToken') }
|
|
117
|
+
]);
|
|
118
|
+
authToken = creds.authToken;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
return { prefix, fullProjectName, oinoneVersion, edition, downloadStaticResources, authToken, isSilent };
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
module.exports = { resolveCreateInputs };
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
const fs = require('fs-extra');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const chalk = require('chalk');
|
|
4
|
+
const https = require('https');
|
|
5
|
+
const os = require('os');
|
|
6
|
+
const AdmZip = require('adm-zip');
|
|
7
|
+
const cliProgress = require('cli-progress');
|
|
8
|
+
const { t } = require('../../i18n');
|
|
9
|
+
|
|
10
|
+
function downloadAndExtractZip(url, targetDir) {
|
|
11
|
+
return new Promise((resolve, reject) => {
|
|
12
|
+
const req = https.request(url, { method: 'HEAD' }, (headRes) => {
|
|
13
|
+
headRes.resume();
|
|
14
|
+
|
|
15
|
+
if (headRes.statusCode !== 200) {
|
|
16
|
+
reject(new Error(t('create.fetchFileInfoFailed', { status: headRes.statusCode })));
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
let etag = headRes.headers['etag'];
|
|
21
|
+
if (etag) {
|
|
22
|
+
etag = etag.replace(/"/g, '');
|
|
23
|
+
} else {
|
|
24
|
+
etag = headRes.headers['last-modified'] ? Buffer.from(headRes.headers['last-modified']).toString('hex') : 'default';
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const cacheDir = path.join(os.tmpdir(), 'oinone-cli-cache');
|
|
28
|
+
fs.ensureDirSync(cacheDir);
|
|
29
|
+
|
|
30
|
+
const cachedZipPath = path.join(cacheDir, `static-resources-${etag}.zip`);
|
|
31
|
+
|
|
32
|
+
if (fs.existsSync(cachedZipPath)) {
|
|
33
|
+
console.log(chalk.cyan(t('cache.usingCached')));
|
|
34
|
+
try {
|
|
35
|
+
const zip = new AdmZip(cachedZipPath);
|
|
36
|
+
zip.extractAllTo(targetDir, true);
|
|
37
|
+
resolve();
|
|
38
|
+
} catch (err) {
|
|
39
|
+
fs.unlinkSync(cachedZipPath);
|
|
40
|
+
reject(err);
|
|
41
|
+
}
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const file = fs.createWriteStream(cachedZipPath);
|
|
46
|
+
|
|
47
|
+
https.get(url, (response) => {
|
|
48
|
+
if (response.statusCode !== 200) {
|
|
49
|
+
response.resume();
|
|
50
|
+
reject(new Error(t('create.downloadFailed', { status: response.statusCode })));
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const totalBytes = parseInt(response.headers['content-length'], 10);
|
|
55
|
+
let isMB = false;
|
|
56
|
+
let totalDisplay = 0;
|
|
57
|
+
let unit = 'KB';
|
|
58
|
+
|
|
59
|
+
if (totalBytes > 10 * 1024 * 1024) {
|
|
60
|
+
isMB = true;
|
|
61
|
+
unit = 'MB';
|
|
62
|
+
totalDisplay = (totalBytes / (1024 * 1024)).toFixed(2);
|
|
63
|
+
} else {
|
|
64
|
+
totalDisplay = Math.round(totalBytes / 1024);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
let downloadedBytes = 0;
|
|
68
|
+
let startTime = Date.now();
|
|
69
|
+
|
|
70
|
+
const progressBar = new cliProgress.SingleBar({
|
|
71
|
+
format: chalk.cyan(t('create.fetchingAwesomeness')) + `[{bar}] {percentage}% | ⏳ {eta}s ${t('create.progressLeft')} | 📦 {value}/{total} ${unit} | 💨 {speed} {speedUnit}/s`,
|
|
72
|
+
barCompleteChar: '\u2588',
|
|
73
|
+
barIncompleteChar: '\u2591',
|
|
74
|
+
hideCursor: true,
|
|
75
|
+
forceRedraw: true
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
progressBar.start(Number(totalDisplay), 0, { speed: '0.00', speedUnit: 'KB' });
|
|
79
|
+
|
|
80
|
+
response.on('data', (chunk) => {
|
|
81
|
+
downloadedBytes += chunk.length;
|
|
82
|
+
let downloadedDisplay = 0;
|
|
83
|
+
if (isMB) {
|
|
84
|
+
downloadedDisplay = Number((downloadedBytes / (1024 * 1024)).toFixed(2));
|
|
85
|
+
} else {
|
|
86
|
+
downloadedDisplay = Math.round(downloadedBytes / 1024);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const currentTime = Date.now();
|
|
90
|
+
const elapsedSeconds = (currentTime - startTime) / 1000;
|
|
91
|
+
let speed = 0;
|
|
92
|
+
let speedUnit = 'KB';
|
|
93
|
+
|
|
94
|
+
if (elapsedSeconds > 0) {
|
|
95
|
+
const speedInBytes = downloadedBytes / elapsedSeconds;
|
|
96
|
+
if (speedInBytes > 1024 * 1024) {
|
|
97
|
+
speed = speedInBytes / (1024 * 1024);
|
|
98
|
+
speedUnit = 'MB';
|
|
99
|
+
} else {
|
|
100
|
+
speed = speedInBytes / 1024;
|
|
101
|
+
speedUnit = 'KB';
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
progressBar.update(downloadedDisplay, { speed: speed.toFixed(2), speedUnit });
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
response.pipe(file);
|
|
109
|
+
file.on('finish', () => {
|
|
110
|
+
progressBar.stop();
|
|
111
|
+
file.close();
|
|
112
|
+
try {
|
|
113
|
+
const zip = new AdmZip(cachedZipPath);
|
|
114
|
+
zip.extractAllTo(targetDir, true);
|
|
115
|
+
resolve();
|
|
116
|
+
} catch (err) {
|
|
117
|
+
if (fs.existsSync(cachedZipPath)) fs.unlinkSync(cachedZipPath);
|
|
118
|
+
reject(err);
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
}).on('error', (err) => {
|
|
122
|
+
if (fs.existsSync(cachedZipPath)) fs.unlink(cachedZipPath, () => {});
|
|
123
|
+
reject(err);
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
req.on('error', (err) => {
|
|
128
|
+
reject(err);
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
req.end();
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
async function handleStaticResources({ downloadStaticResources, spinner, prefix, targetPath, fullProjectName }) {
|
|
136
|
+
if (downloadStaticResources) {
|
|
137
|
+
spinner.succeed(chalk.green(t('create.structureReady')));
|
|
138
|
+
console.log(chalk.cyan(t('create.haulingStatic')));
|
|
139
|
+
try {
|
|
140
|
+
const ossDir = path.join(targetPath, 'packages', `${prefix}-boot`, 'public', 'oss');
|
|
141
|
+
await fs.ensureDir(ossDir);
|
|
142
|
+
await downloadAndExtractZip('https://pamirs.oss-cn-hangzhou.aliyuncs.com/oinone/installer/static-resources.zip', ossDir);
|
|
143
|
+
console.log(chalk.green(t('create.staticDownloaded')));
|
|
144
|
+
} catch (err) {
|
|
145
|
+
console.log(chalk.yellow(t('create.staticHiccup', { msg: err.message })));
|
|
146
|
+
}
|
|
147
|
+
} else {
|
|
148
|
+
spinner.succeed(chalk.green(t('create.projectCreated')));
|
|
149
|
+
const relativeOssDir = `packages/${prefix}-boot/public/oss`;
|
|
150
|
+
console.log(chalk.yellow(t('create.skipStaticWarning')));
|
|
151
|
+
console.log(chalk.yellow(t('create.manualStaticInstructions')));
|
|
152
|
+
console.log(chalk.cyan(` mkdir -p ${fullProjectName}/${relativeOssDir}`));
|
|
153
|
+
console.log(chalk.cyan(` curl -L https://pamirs.oss-cn-hangzhou.aliyuncs.com/oinone/installer/static-resources.zip -o static-resources.zip`));
|
|
154
|
+
console.log(chalk.cyan(` unzip static-resources.zip -d ${fullProjectName}/${relativeOssDir}`));
|
|
155
|
+
console.log(chalk.cyan(` rm static-resources.zip`));
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
module.exports = { handleStaticResources };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
const fs = require('fs-extra');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const chalk = require('chalk');
|
|
4
|
+
const { t } = require('../../i18n');
|
|
5
|
+
|
|
6
|
+
function resolveTemplate(oinoneVersion, edition) {
|
|
7
|
+
const versionStr = String(oinoneVersion || '').trim();
|
|
8
|
+
const normalizedVersionStr = versionStr.replace(/[^0-9.]/g, '');
|
|
9
|
+
const versionMatch = normalizedVersionStr.match(/^(\d+)\.(\d+)(?:\.(\d+))?/);
|
|
10
|
+
if (!versionMatch) {
|
|
11
|
+
console.log(chalk.red(t('create.unsupportedVersion', { version: versionStr })));
|
|
12
|
+
process.exit(1);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const major = Number(versionMatch[1]);
|
|
16
|
+
const minor = Number(versionMatch[2]);
|
|
17
|
+
const selectedMinorVersion = `${major}.${minor}.0`;
|
|
18
|
+
|
|
19
|
+
let templateName;
|
|
20
|
+
if (major > 7 || (major === 7 && minor >= 2)) {
|
|
21
|
+
templateName = 'template-7.2.0';
|
|
22
|
+
} else if (major === 6 && minor === 4) {
|
|
23
|
+
templateName = 'template-6.4.0';
|
|
24
|
+
} else {
|
|
25
|
+
console.log(chalk.red(t('create.unsupportedVersion', { version: versionStr })));
|
|
26
|
+
process.exit(1);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const templatePath = path.resolve(__dirname, '..', '..', '..', templateName);
|
|
30
|
+
if (!fs.existsSync(templatePath)) {
|
|
31
|
+
console.log(chalk.red(t('create.errorTemplateMissing', { version: normalizedVersionStr || versionStr, edition })));
|
|
32
|
+
process.exit(1);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return { templateName, templatePath, selectedMinorVersion, normalizedVersionStr, versionStr };
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
module.exports = { resolveTemplate };
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
const https = require('https');
|
|
2
|
+
|
|
3
|
+
function isNewerVersion(current, latest) {
|
|
4
|
+
const c = String(current || '').replace(/[^0-9.]/g, '').split('.').map(Number);
|
|
5
|
+
const l = String(latest || '').replace(/[^0-9.]/g, '').split('.').map(Number);
|
|
6
|
+
for (let i = 0; i < Math.max(c.length, l.length); i++) {
|
|
7
|
+
const numC = c[i] || 0;
|
|
8
|
+
const numL = l[i] || 0;
|
|
9
|
+
if (numL > numC) return true;
|
|
10
|
+
if (numL < numC) return false;
|
|
11
|
+
}
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function startNpmDistTagLatestCheck(packageName, timeoutMs = 3000) {
|
|
16
|
+
let req = null;
|
|
17
|
+
const promise = new Promise((resolve) => {
|
|
18
|
+
req = https.get(`https://registry.npmjs.org/-/package/${packageName}/dist-tags`, { timeout: timeoutMs }, (res) => {
|
|
19
|
+
let data = '';
|
|
20
|
+
res.on('data', chunk => data += chunk);
|
|
21
|
+
res.on('end', () => {
|
|
22
|
+
try {
|
|
23
|
+
const parsed = JSON.parse(data);
|
|
24
|
+
resolve(parsed.latest);
|
|
25
|
+
} catch (e) {
|
|
26
|
+
resolve(null);
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
req.on('timeout', () => {
|
|
31
|
+
req.destroy();
|
|
32
|
+
resolve(null);
|
|
33
|
+
});
|
|
34
|
+
req.on('error', () => resolve(null));
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
const cancel = () => {
|
|
38
|
+
if (req) req.destroy();
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
return { promise, cancel };
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
module.exports = { startNpmDistTagLatestCheck, isNewerVersion };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
const https = require('https');
|
|
2
|
+
const { toMinorVersions, isSupportedMinorVersion } = require('../../utils/oinone-version');
|
|
3
|
+
|
|
4
|
+
function fetchKunlunMinorVersionsFromMirror(timeoutMs) {
|
|
5
|
+
return new Promise((resolve) => {
|
|
6
|
+
const req = https.get('https://registry.npmmirror.com/@oinone/kunlun-dependencies', { timeout: timeoutMs }, (res) => {
|
|
7
|
+
let data = '';
|
|
8
|
+
res.on('data', (chunk) => data += chunk);
|
|
9
|
+
res.on('end', () => {
|
|
10
|
+
if (res.statusCode !== 200) {
|
|
11
|
+
resolve(null);
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
try {
|
|
15
|
+
const parsed = JSON.parse(data);
|
|
16
|
+
const versions = parsed && parsed.versions ? Object.keys(parsed.versions) : [];
|
|
17
|
+
const minorVersions = toMinorVersions(versions).filter(isSupportedMinorVersion);
|
|
18
|
+
resolve(minorVersions.length ? minorVersions : null);
|
|
19
|
+
} catch (e) {
|
|
20
|
+
resolve(null);
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
req.on('timeout', () => {
|
|
25
|
+
req.destroy();
|
|
26
|
+
resolve(null);
|
|
27
|
+
});
|
|
28
|
+
req.on('error', () => resolve(null));
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
module.exports = { fetchKunlunMinorVersionsFromMirror };
|