@tomjs/create-app 1.7.0 → 2.0.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 +14 -21
- package/README.zh_CN.md +14 -21
- package/dist/index.js +9 -22
- package/package.json +49 -52
- package/templates/{base/core → config/base}/.editorconfig +0 -4
- package/templates/config/base/.vscode/settings.json +50 -0
- package/templates/{base/core/_gitignore → config/base/_.gitignore} +1 -3
- package/templates/config/base/_commitlint.config.mjs +3 -0
- package/templates/config/base/_eslint.config.mjs +8 -0
- package/templates/config/base/lint-staged.config.mjs +3 -0
- package/templates/config/base/package.json +24 -0
- package/templates/config/base/pnpm-workspace.yaml +3 -0
- package/templates/config/base/simple-git-hooks.mjs +4 -0
- package/templates/{vscode → config/public}/LICENSE +1 -1
- package/templates/config/public/README.md +20 -0
- package/templates/config/public/README.zh_CN.md +20 -0
- package/templates/config/public/package.json +10 -0
- package/templates/config/style/lint-staged.config.mjs +7 -0
- package/templates/config/style/package.json +12 -0
- package/templates/config/style/stylelint.config.mjs +3 -0
- package/templates/{base/electron → electron-react}/.vscode/launch.json +23 -3
- package/templates/electron-react/.vscode/tasks.json +67 -0
- package/templates/electron-react/README.md +1 -1
- package/templates/electron-react/_eslint.config.mjs +8 -0
- package/templates/electron-react/electron/main/index.ts +71 -40
- package/templates/electron-react/electron/preload/index.ts +4 -0
- package/templates/electron-react/index.html +1 -2
- package/templates/electron-react/package.json +35 -1
- package/templates/electron-react/pnpm-workspace.yaml +6 -0
- package/templates/electron-react/src/App.css +6 -2
- package/templates/electron-react/src/App.tsx +12 -5
- package/templates/electron-react/src/index.css +14 -9
- package/templates/electron-react/tsconfig.json +9 -0
- package/templates/{base/electron → electron-react}/tsconfig.node.json +1 -1
- package/templates/electron-react/vite.config.ts +9 -22
- package/templates/electron-vue/.vscode/launch.json +48 -0
- package/templates/electron-vue/.vscode/tasks.json +67 -0
- package/templates/electron-vue/README.md +1 -1
- package/templates/electron-vue/_eslint.config.mjs +8 -0
- package/templates/electron-vue/electron/env.d.ts +1 -0
- package/templates/electron-vue/electron/main/index.ts +46 -30
- package/templates/electron-vue/electron/preload/index.ts +4 -0
- package/templates/electron-vue/index.html +1 -2
- package/templates/electron-vue/package.json +31 -2
- package/templates/electron-vue/pnpm-workspace.yaml +5 -0
- package/templates/electron-vue/src/App.vue +1 -1
- package/templates/electron-vue/src/style.css +15 -10
- package/templates/electron-vue/tsconfig.json +5 -0
- package/templates/electron-vue/tsconfig.node.json +7 -0
- package/templates/electron-vue/vite.config.ts +3 -21
- package/templates/{node-cli-legacy → node-base}/.vscode/launch.json +3 -6
- package/templates/node-base/package.json +15 -0
- package/templates/node-base/src/index.ts +5 -0
- package/templates/{node-cli-legacy → node-base}/tsconfig.json +1 -1
- package/templates/node-cli/.vscode/i18n-ally-custom-framework.yml +35 -0
- package/templates/node-cli/.vscode/launch.json +3 -6
- package/templates/node-cli/.vscode/settings.json +56 -0
- package/templates/node-cli/_.gitignore +59 -0
- package/templates/node-cli/locales/en-US.json +12 -0
- package/templates/node-cli/locales/zh-CN.json +12 -0
- package/templates/node-cli/package.json +20 -20
- package/templates/node-cli/src/app.ts +19 -0
- package/templates/node-cli/src/config.ts +2 -2
- package/templates/node-cli/src/index.ts +78 -1
- package/templates/node-cli/src/types.ts +5 -1
- package/templates/node-cli/src/utils/exec.ts +68 -0
- package/templates/node-cli/src/utils/index.ts +3 -0
- package/templates/node-cli/src/utils/lang.ts +104 -0
- package/templates/node-cli/src/utils/util.ts +20 -0
- package/templates/node-cli/tsconfig.json +2 -2
- package/templates/node-cli/{tsup.config.ts → tsdown.config.ts} +3 -4
- package/templates/node-vite/examples/react/README.md +1 -0
- package/templates/node-vite/examples/react/_eslint.config.mjs +6 -0
- package/templates/{react → node-vite/examples/react}/index.html +1 -2
- package/templates/node-vite/examples/react/package.json +27 -0
- package/templates/{react → node-vite/examples/react}/src/App.css +5 -2
- package/templates/{react → node-vite/examples/react}/src/App.tsx +8 -9
- package/templates/{react → node-vite/examples/react}/src/index.css +15 -11
- package/templates/node-vite/examples/react/src/main.tsx +10 -0
- package/templates/node-vite/examples/react/tsconfig.json +5 -0
- package/templates/node-vite/examples/react/vite.config.ts +14 -0
- package/templates/node-vite/examples/vue/README.md +1 -0
- package/templates/node-vite/examples/vue/_eslint.config.mjs +6 -0
- package/templates/{vue → node-vite/examples/vue}/index.html +1 -2
- package/templates/node-vite/examples/vue/package.json +22 -0
- package/templates/{vue → node-vite/examples/vue}/src/App.vue +3 -3
- package/templates/node-vite/examples/vue/src/components/HelloWorld.vue +19 -0
- package/templates/{vue → node-vite/examples/vue}/src/main.ts +0 -1
- package/templates/{vue → node-vite/examples/vue}/src/style.css +16 -12
- package/templates/{base → node-vite/examples}/vue/tsconfig.json +2 -2
- package/templates/{vue → node-vite/examples/vue}/vite.config.ts +1 -1
- package/templates/node-vite/package.json +16 -0
- package/templates/node-vite/pnpm-lock.yaml +2293 -0
- package/templates/node-vite/pnpm-workspace.yaml +6 -0
- package/templates/{node → node-vite}/tsconfig.json +1 -1
- package/templates/{node-cli-legacy/tsup.config.ts → node-vite/tsdown.config.ts} +4 -5
- package/templates/vscode-base/.vscode/settings.json +59 -0
- package/templates/{vscode → vscode-base}/.vscode/tasks.json +2 -2
- package/templates/{base/node → vscode-base}/LICENSE +1 -1
- package/templates/{vscode/_gitignore → vscode-base/_.gitignore} +1 -0
- package/templates/vscode-base/locales/zh-CN.json +6 -0
- package/templates/{vscode → vscode-base}/package.json +12 -19
- package/templates/vscode-base/resources/logo.png +0 -0
- package/templates/vscode-base/resources/logo.svg +1 -0
- package/templates/{vscode/tsup.config.ts → vscode-base/tsdown.config.ts} +3 -3
- package/templates/{base/vscode → vscode-react}/.vscode/launch.json +14 -1
- package/templates/vscode-react/.vscode/settings.json +59 -0
- package/templates/{base/vscode → vscode-react}/.vscode/tasks.json +10 -1
- package/templates/{base/vscode → vscode-react}/LICENSE +1 -1
- package/templates/vscode-react/README.md +2 -2
- package/templates/{base/vscode/_gitignore → vscode-react/_.gitignore} +2 -1
- package/templates/{base/vscode → vscode-react}/extension/views/helper.ts +5 -4
- package/templates/{base/vscode → vscode-react}/extension/views/panel.ts +2 -1
- package/templates/vscode-react/package.json +65 -1
- package/templates/vscode-react/pnpm-workspace.yaml +5 -0
- package/templates/vscode-react/src/App.css +1 -1
- package/templates/vscode-react/src/App.tsx +16 -10
- package/templates/vscode-react/src/utils/vscode.ts +2 -81
- package/templates/vscode-react/src/vite-env.d.ts +1 -0
- package/templates/vscode-react/tsconfig.json +5 -0
- package/templates/vscode-react/vite.config.ts +4 -5
- package/templates/vscode-vue/.vscode/extensions.json +5 -0
- package/templates/vscode-vue/.vscode/launch.json +34 -0
- package/templates/vscode-vue/.vscode/settings.json +59 -0
- package/templates/{base/electron → vscode-vue}/.vscode/tasks.json +14 -6
- package/templates/vscode-vue/.vscodeignore +73 -0
- package/templates/vscode-vue/LICENSE +21 -0
- package/templates/vscode-vue/README.md +2 -2
- package/templates/vscode-vue/_.gitignore +65 -0
- package/templates/vscode-vue/extension/env.d.ts +1 -0
- package/templates/vscode-vue/extension/index.ts +21 -0
- package/templates/vscode-vue/extension/views/helper.ts +28 -0
- package/templates/vscode-vue/extension/views/panel.ts +49 -0
- package/templates/vscode-vue/locales/en.json +6 -0
- package/templates/vscode-vue/package.json +56 -2
- package/templates/vscode-vue/pnpm-workspace.yaml +4 -0
- package/templates/vscode-vue/src/App.vue +17 -11
- package/templates/vscode-vue/src/utils/vscode.ts +2 -81
- package/templates/vscode-vue/src/vite-env.d.ts +1 -0
- package/templates/vscode-vue/tsconfig.json +5 -0
- package/templates/vscode-vue/tsconfig.node.json +7 -0
- package/templates/vscode-vue/vite.config.ts +0 -4
- package/templates/web-react/README.md +1 -0
- package/templates/web-react/_eslint.config.mjs +6 -0
- package/templates/web-react/index.html +13 -0
- package/templates/web-react/package.json +27 -0
- package/templates/web-react/public/vite.svg +1 -0
- package/templates/web-react/src/App.css +45 -0
- package/templates/web-react/src/App.tsx +31 -0
- package/templates/web-react/src/assets/react.svg +1 -0
- package/templates/web-react/src/index.css +73 -0
- package/templates/web-react/src/main.tsx +10 -0
- package/templates/web-react/tsconfig.app.json +28 -0
- package/templates/web-react/tsconfig.json +7 -0
- package/templates/web-react/tsconfig.node.json +26 -0
- package/templates/web-react/vite.config.ts +14 -0
- package/templates/web-vue/README.md +1 -0
- package/templates/web-vue/_eslint.config.mjs +6 -0
- package/templates/web-vue/index.html +13 -0
- package/templates/web-vue/package.json +22 -0
- package/templates/web-vue/public/vite.svg +1 -0
- package/templates/web-vue/src/App.vue +32 -0
- package/templates/web-vue/src/assets/vue.svg +1 -0
- package/templates/web-vue/src/components/HelloWorld.vue +19 -0
- package/templates/web-vue/src/main.ts +5 -0
- package/templates/web-vue/src/style.css +84 -0
- package/templates/web-vue/tsconfig.app.json +4 -0
- package/templates/web-vue/tsconfig.json +7 -0
- package/templates/web-vue/tsconfig.node.json +7 -0
- package/templates/web-vue/vite.config.ts +7 -0
- package/templates/base/core/.commitlintrc.cjs +0 -3
- package/templates/base/core/.eslintignore +0 -14
- package/templates/base/core/.husky/commit-msg +0 -1
- package/templates/base/core/.husky/pre-commit +0 -1
- package/templates/base/core/.prettierignore +0 -17
- package/templates/base/core/.prettierrc.cjs +0 -1
- package/templates/base/core/_eslintrc.cjs +0 -7
- package/templates/base/core/_lintstagedrc.cjs +0 -4
- package/templates/base/core/package.json +0 -31
- package/templates/base/electron/electron/main/index.ts +0 -111
- package/templates/base/electron/electron/polyfills.ts +0 -4
- package/templates/base/electron/electron/preload/index.ts +0 -1
- package/templates/base/electron/package.json +0 -25
- package/templates/base/node/README.md +0 -13
- package/templates/base/node/README.zh_CN.md +0 -13
- package/templates/base/node/package.json +0 -48
- package/templates/base/node/test/index.test.ts +0 -7
- package/templates/base/package/package.json +0 -8
- package/templates/base/react/_eslintrc.cjs +0 -7
- package/templates/base/react/_lintstagedrc.cjs +0 -6
- package/templates/base/react/package.json +0 -19
- package/templates/base/react/tsconfig.json +0 -5
- package/templates/base/style/.stylelintignore +0 -16
- package/templates/base/style/.stylelintrc.cjs +0 -3
- package/templates/base/style/_lintstagedrc.cjs +0 -5
- package/templates/base/style/package.json +0 -10
- package/templates/base/vscode/.vscode/settings.json +0 -10
- package/templates/base/vscode/package.json +0 -67
- package/templates/base/vue/_eslintrc.cjs +0 -7
- package/templates/base/vue/_lintstagedrc.cjs +0 -6
- package/templates/base/vue/package.json +0 -17
- package/templates/config.json +0 -108
- package/templates/electron-react/public/img/icon.png +0 -0
- package/templates/electron-vue/public/img/icon.png +0 -0
- package/templates/node/package.json +0 -10
- package/templates/node/src/index.ts +0 -3
- package/templates/node/tsup.config.ts +0 -19
- package/templates/node-cli/index.d.ts +0 -5
- package/templates/node-cli/src/cli.ts +0 -68
- package/templates/node-cli/xxx.config.cjs +0 -0
- package/templates/node-cli-legacy/index.d.ts +0 -5
- package/templates/node-cli-legacy/package.json +0 -30
- package/templates/node-cli-legacy/src/cli.ts +0 -45
- package/templates/node-cli-legacy/src/config.ts +0 -28
- package/templates/node-cli-legacy/src/index.ts +0 -3
- package/templates/node-cli-legacy/src/types.ts +0 -1
- package/templates/node-cli-legacy/src/utils.ts +0 -5
- package/templates/node-vite-plugin/package.json +0 -18
- package/templates/node-vite-plugin/test/index.test.ts +0 -7
- package/templates/node-vite-plugin/tsconfig.json +0 -4
- package/templates/node-vite-plugin/tsup.config.ts +0 -18
- package/templates/node-workspaces/package.json +0 -8
- package/templates/react/package.json +0 -12
- package/templates/react/src/main.tsx +0 -11
- package/templates/react/src/vite-env.d.ts +0 -1
- package/templates/react/vite.config.ts +0 -7
- package/templates/schema.json +0 -110
- package/templates/vscode/.vscode/settings.json +0 -10
- package/templates/vscode/README.md +0 -3
- package/templates/vue/package.json +0 -12
- package/templates/vue/src/components/HelloWorld.vue +0 -37
- package/templates/vue/src/vite-env.d.ts +0 -1
- package/templates/{base/core → config/base}/.gitattributes +0 -0
- package/templates/{node-cli-legacy/xxx.config.cjs → config/base/README.md} +0 -0
- package/templates/{base/electron → electron-react}/electron/env.d.ts +0 -0
- package/templates/{react → node-vite/examples/react}/public/vite.svg +0 -0
- package/templates/{react → node-vite/examples/react}/src/assets/react.svg +0 -0
- package/templates/{base → node-vite/examples}/react/tsconfig.node.json +0 -0
- package/templates/{vue → node-vite/examples/vue}/public/vite.svg +0 -0
- package/templates/{vue → node-vite/examples/vue}/src/assets/vue.svg +0 -0
- package/templates/{base → node-vite/examples}/vue/tsconfig.node.json +0 -0
- package/templates/{node-vite-plugin → node-vite}/src/index.ts +0 -0
- package/templates/{node-vite-plugin → node-vite}/src/types.ts +0 -0
- package/templates/{base/vscode → vscode-base}/.vscode/extensions.json +0 -0
- package/templates/{vscode → vscode-base}/.vscode/launch.json +0 -0
- package/templates/{vscode → vscode-base}/.vscodeignore +0 -0
- package/templates/{base/vscode → vscode-base}/README.md +0 -0
- package/templates/{vscode → vscode-base}/locales/en.json +0 -0
- package/templates/{vscode → vscode-base}/src/index.ts +1 -1
- package/templates/{vscode → vscode-base}/tsconfig.json +0 -0
- package/templates/{vscode → vscode-react}/.vscode/extensions.json +0 -0
- package/templates/{base/vscode → vscode-react}/.vscodeignore +0 -0
- package/templates/{base/vscode → vscode-react}/extension/env.d.ts +0 -0
- package/templates/{base/vscode → vscode-react}/extension/index.ts +1 -1
- /package/templates/{base/vscode → vscode-react}/locales/en.json +0 -0
- /package/templates/{base/vscode → vscode-react}/locales/zh-CN.json +0 -0
- /package/templates/{base/vscode → vscode-react}/resources/logo.png +0 -0
- /package/templates/{base/vscode → vscode-react}/resources/logo.svg +0 -0
- /package/templates/{base/vscode → vscode-react}/tsconfig.node.json +0 -0
- /package/templates/{vscode → vscode-vue}/locales/zh-CN.json +0 -0
- /package/templates/{vscode → vscode-vue}/resources/logo.png +0 -0
- /package/templates/{vscode → vscode-vue}/resources/logo.svg +0 -0
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"app.description": "Create a project",
|
|
3
|
+
"options.config": "Configuration file path (e.g., \"./xxx.config.json\")",
|
|
4
|
+
"options.dir": "Current working directory (default: \".\")",
|
|
5
|
+
"options.help": "Display help information",
|
|
6
|
+
"options.verbose": "Display detailed logs",
|
|
7
|
+
"options.version": "Display version information",
|
|
8
|
+
"prompt.cancel": "Operation canceled",
|
|
9
|
+
"prompt.confirm.no": "No",
|
|
10
|
+
"prompt.confirm.yes": "Yes",
|
|
11
|
+
"prompt.public.message": "Is it public?"
|
|
12
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"app.description": "创建一个项目",
|
|
3
|
+
"options.config": "配置文件路径 (如: \"./xxx.config.json\")",
|
|
4
|
+
"options.dir": "当前工作目录 (默认: \".\")",
|
|
5
|
+
"options.help": "显示帮助信息",
|
|
6
|
+
"options.verbose": "显示详细日志",
|
|
7
|
+
"options.version": "显示版本信息",
|
|
8
|
+
"prompt.cancel": "操作取消",
|
|
9
|
+
"prompt.confirm.no": "否",
|
|
10
|
+
"prompt.confirm.yes": "是",
|
|
11
|
+
"prompt.public.message": "是否为公开?"
|
|
12
|
+
}
|
|
@@ -1,31 +1,31 @@
|
|
|
1
1
|
{
|
|
2
|
-
"
|
|
3
|
-
"description": "node
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
],
|
|
7
|
-
"engines": {
|
|
8
|
-
"node": ">=18"
|
|
2
|
+
"name": "cli",
|
|
3
|
+
"description": "cli node project",
|
|
4
|
+
"bin": {
|
|
5
|
+
"xxx": "./dist/index.mjs"
|
|
9
6
|
},
|
|
10
7
|
"files": [
|
|
11
|
-
"dist"
|
|
12
|
-
"index.d.ts"
|
|
8
|
+
"dist"
|
|
13
9
|
],
|
|
14
|
-
"
|
|
15
|
-
"
|
|
16
|
-
"xxx-cli": "./dist/index.js"
|
|
10
|
+
"engines": {
|
|
11
|
+
"node": ">=18"
|
|
17
12
|
},
|
|
18
13
|
"scripts": {
|
|
19
|
-
"dev": "
|
|
20
|
-
"
|
|
21
|
-
"build": "tsup"
|
|
14
|
+
"dev": "tsdown --watch",
|
|
15
|
+
"build": "tsdown"
|
|
22
16
|
},
|
|
23
17
|
"dependencies": {
|
|
24
|
-
"
|
|
18
|
+
"@clack/prompts": "^0.11.0",
|
|
19
|
+
"@tomjs/logger": "^1.4.0",
|
|
20
|
+
"@tomjs/node": "^2.2.3",
|
|
21
|
+
"chalk": "^5.6.2",
|
|
25
22
|
"cosmiconfig": "^9.0.0",
|
|
26
|
-
"execa": "^9.
|
|
27
|
-
"meow": "^
|
|
28
|
-
"ora": "^
|
|
23
|
+
"execa": "^9.6.0",
|
|
24
|
+
"meow": "^14.0.0",
|
|
25
|
+
"ora": "^9.0.0"
|
|
29
26
|
},
|
|
30
|
-
"devDependencies": {
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"publint": "0.3.15",
|
|
29
|
+
"tsdown": "^0.16.7"
|
|
30
|
+
}
|
|
31
31
|
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { XxxCLIOptions } from './types';
|
|
2
|
+
import * as prompts from '@clack/prompts';
|
|
3
|
+
import { logger, t } from './utils';
|
|
4
|
+
|
|
5
|
+
const cancel = () => prompts.cancel(t('prompt.cancel'));
|
|
6
|
+
|
|
7
|
+
export async function runApp(opts: XxxCLIOptions) {
|
|
8
|
+
logger.debug('opts', opts);
|
|
9
|
+
logger.info('Starting App...');
|
|
10
|
+
|
|
11
|
+
const isPublic = await prompts.confirm({
|
|
12
|
+
message: t('prompt.public.message'),
|
|
13
|
+
active: t('prompt.confirm.yes'),
|
|
14
|
+
inactive: t('prompt.confirm.no'),
|
|
15
|
+
});
|
|
16
|
+
if (prompts.isCancel(isPublic)) {
|
|
17
|
+
return cancel();
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
+
import type { XxxCLIOptions } from './types';
|
|
1
2
|
import fs from 'node:fs';
|
|
2
3
|
import { cosmiconfig } from 'cosmiconfig';
|
|
3
|
-
import type { XxxCLIOptions } from './types.js';
|
|
4
4
|
|
|
5
5
|
export async function getReleaseConfig(opts: XxxCLIOptions) {
|
|
6
6
|
const explorer = cosmiconfig('xxx', {
|
|
7
|
-
stopDir: opts.
|
|
7
|
+
stopDir: opts.dir,
|
|
8
8
|
searchPlaces: [
|
|
9
9
|
'package.json',
|
|
10
10
|
'xxx.config.json',
|
|
@@ -1,3 +1,80 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
import type { XxxCLIOptions } from './types';
|
|
3
|
+
import meow from 'meow';
|
|
4
|
+
import { runApp } from './app';
|
|
5
|
+
import { getReleaseConfig } from './config';
|
|
6
|
+
import { isDev } from './constants';
|
|
7
|
+
import { logger, t } from './utils';
|
|
2
8
|
|
|
3
|
-
|
|
9
|
+
const cli = meow(
|
|
10
|
+
`
|
|
11
|
+
Usage
|
|
12
|
+
$ xxx [input] [options]
|
|
13
|
+
|
|
14
|
+
Options
|
|
15
|
+
-d, --dir ${t('options.dir')}
|
|
16
|
+
-c, --config ${t('options.config')}
|
|
17
|
+
--verbose ${t('options.verbose')}
|
|
18
|
+
-h, --help ${t('options.help')}
|
|
19
|
+
-v, --version ${t('options.version')}
|
|
20
|
+
`,
|
|
21
|
+
{
|
|
22
|
+
importMeta: import.meta,
|
|
23
|
+
booleanDefault: undefined,
|
|
24
|
+
helpIndent: 0,
|
|
25
|
+
description: t('app.description'),
|
|
26
|
+
flags: {
|
|
27
|
+
dir: {
|
|
28
|
+
type: 'string',
|
|
29
|
+
shortFlag: 'd',
|
|
30
|
+
},
|
|
31
|
+
config: {
|
|
32
|
+
type: 'string',
|
|
33
|
+
shortFlag: 'c',
|
|
34
|
+
},
|
|
35
|
+
verbose: {
|
|
36
|
+
type: 'boolean',
|
|
37
|
+
default: process.env.NODE_ENV === 'development',
|
|
38
|
+
},
|
|
39
|
+
help: {
|
|
40
|
+
type: 'boolean',
|
|
41
|
+
shortFlag: 'h',
|
|
42
|
+
default: false,
|
|
43
|
+
},
|
|
44
|
+
version: {
|
|
45
|
+
type: 'boolean',
|
|
46
|
+
shortFlag: 'v',
|
|
47
|
+
default: false,
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
const { input, flags } = cli;
|
|
54
|
+
if (flags.help) {
|
|
55
|
+
cli.showHelp(0);
|
|
56
|
+
}
|
|
57
|
+
else if (flags.version) {
|
|
58
|
+
cli.showVersion();
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
logger.enableDebug(flags.verbose);
|
|
62
|
+
logger.debug('input:', input);
|
|
63
|
+
logger.debug('cli options:', flags);
|
|
64
|
+
|
|
65
|
+
const config = await getReleaseConfig(flags);
|
|
66
|
+
logger.debug('config file:', config);
|
|
67
|
+
|
|
68
|
+
const mergedOpts = Object.assign(
|
|
69
|
+
{
|
|
70
|
+
verbose: isDev,
|
|
71
|
+
} as XxxCLIOptions,
|
|
72
|
+
config,
|
|
73
|
+
flags,
|
|
74
|
+
) as XxxCLIOptions;
|
|
75
|
+
|
|
76
|
+
mergedOpts.dir ||= process.cwd();
|
|
77
|
+
logger.debug('merged options:', mergedOpts);
|
|
78
|
+
|
|
79
|
+
await runApp(mergedOpts);
|
|
80
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type { Options as ExecaOptions } from 'execa';
|
|
2
|
+
import { $ } from 'execa';
|
|
3
|
+
import { getOptions, logger } from './util';
|
|
4
|
+
|
|
5
|
+
interface RunExecaOptions extends ExecaOptions {
|
|
6
|
+
/**
|
|
7
|
+
* Whether to clear the command output, replace \r and \n to ""
|
|
8
|
+
* @default false
|
|
9
|
+
*/
|
|
10
|
+
trim?: boolean;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* run a command
|
|
15
|
+
* @param cmd command
|
|
16
|
+
* @param options custom and execa options
|
|
17
|
+
*/
|
|
18
|
+
export async function run(cmd: string, options?: RunExecaOptions): Promise<string>;
|
|
19
|
+
/**
|
|
20
|
+
* run a command
|
|
21
|
+
* @param cmd a command array, will be joined by space
|
|
22
|
+
* @param options custom and execa options
|
|
23
|
+
*/
|
|
24
|
+
export async function run(cmd: string[], options?: RunExecaOptions): Promise<string>;
|
|
25
|
+
|
|
26
|
+
export async function run(cmd: string | string[], options?: RunExecaOptions): Promise<string> {
|
|
27
|
+
const { trim, ...execOpts } = Object.assign(
|
|
28
|
+
{
|
|
29
|
+
stdio: 'pipe',
|
|
30
|
+
shell: true,
|
|
31
|
+
} as RunExecaOptions,
|
|
32
|
+
options,
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
if (Array.isArray(cmd)) {
|
|
36
|
+
cmd = cmd.join(' ');
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const log = (str: string) => {
|
|
40
|
+
if (getOptions().verbose) {
|
|
41
|
+
logger.debug(str);
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
logger.write(str);
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
log(`$ ${cmd}`);
|
|
49
|
+
|
|
50
|
+
try {
|
|
51
|
+
const result = await $(execOpts)`${cmd}`;
|
|
52
|
+
const stdout = result.stdout as string;
|
|
53
|
+
|
|
54
|
+
log(stdout);
|
|
55
|
+
|
|
56
|
+
if (trim) {
|
|
57
|
+
return stdout.trim().replace(/\n|\r/g, '');
|
|
58
|
+
}
|
|
59
|
+
return stdout.trim();
|
|
60
|
+
}
|
|
61
|
+
catch (e: any) {
|
|
62
|
+
const msg = e.stderr || e.message;
|
|
63
|
+
|
|
64
|
+
log(msg);
|
|
65
|
+
|
|
66
|
+
throw new Error(msg);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
// copy from https://github.com/vuejs/create-vue/blob/b1494b6ed5b493c289cac020359dbb49bdfff47d/utils/getLanguage.ts#L1-L133
|
|
2
|
+
import * as fs from 'node:fs';
|
|
3
|
+
import * as path from 'node:path';
|
|
4
|
+
import { fileURLToPath } from 'node:url';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
*
|
|
8
|
+
* This function is used to link obtained locale with correct locale file in order to make locales reusable
|
|
9
|
+
*
|
|
10
|
+
* @param locale the obtained locale
|
|
11
|
+
* @returns locale that linked with correct name
|
|
12
|
+
*/
|
|
13
|
+
function linkLocale(locale: string) {
|
|
14
|
+
// The C locale is the default system locale for POSIX systems.
|
|
15
|
+
// https://docs.oracle.com/cd/E36784_01/html/E36823/glmar.html
|
|
16
|
+
// https://sourceware.org/glibc/wiki/Proposals/C.UTF-8
|
|
17
|
+
// It is common among containerized environments or minimal virtual environments
|
|
18
|
+
// though most user-facing systems would have a more specific locale set.
|
|
19
|
+
// The problem here is that the C locale is not a valid language tag for the Intl API.
|
|
20
|
+
// But it is not desirable to throw an error in this case.
|
|
21
|
+
// So we map it to 'en-US'.
|
|
22
|
+
if (locale === 'C') {
|
|
23
|
+
return 'en-US';
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
let linkedLocale: string = '';
|
|
27
|
+
try {
|
|
28
|
+
linkedLocale = Intl.getCanonicalLocales(locale)[0];
|
|
29
|
+
}
|
|
30
|
+
catch (error) {
|
|
31
|
+
console.log(`${error.toString()}, invalid language tag: "${locale}"\n`);
|
|
32
|
+
}
|
|
33
|
+
switch (linkedLocale) {
|
|
34
|
+
case 'zh-TW':
|
|
35
|
+
case 'zh-HK':
|
|
36
|
+
case 'zh-MO':
|
|
37
|
+
linkedLocale = 'zh-Hant';
|
|
38
|
+
break;
|
|
39
|
+
case 'zh-CN':
|
|
40
|
+
case 'zh-SG':
|
|
41
|
+
linkedLocale = 'zh-Hans';
|
|
42
|
+
break;
|
|
43
|
+
default:
|
|
44
|
+
linkedLocale = locale;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return linkedLocale;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function getLocale() {
|
|
51
|
+
const shellLocale
|
|
52
|
+
= process.env.LC_ALL // POSIX locale environment variables
|
|
53
|
+
|| process.env.LC_MESSAGES
|
|
54
|
+
|| process.env.LANG
|
|
55
|
+
|| Intl.DateTimeFormat().resolvedOptions().locale // Built-in ECMA-402 support
|
|
56
|
+
|| 'en-US'; // Default fallback
|
|
57
|
+
|
|
58
|
+
return linkLocale(shellLocale.split('.')[0].replace('_', '-'));
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
async function loadLanguageFile(filePath: string): Promise<Record<string, string>> {
|
|
62
|
+
return await fs.promises.readFile(filePath, 'utf-8').then((data) => {
|
|
63
|
+
const parsedData = JSON.parse(data);
|
|
64
|
+
if (parsedData) {
|
|
65
|
+
return parsedData;
|
|
66
|
+
}
|
|
67
|
+
return {};
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export async function getLanguage(localesRoot: string) {
|
|
72
|
+
const locale = getLocale();
|
|
73
|
+
|
|
74
|
+
const languageFilePath = path.resolve(localesRoot, `${locale}.json`);
|
|
75
|
+
const fallbackPath = path.resolve(localesRoot, 'en-US.json');
|
|
76
|
+
|
|
77
|
+
const doesLanguageExist = fs.existsSync(languageFilePath);
|
|
78
|
+
return doesLanguageExist
|
|
79
|
+
? await loadLanguageFile(languageFilePath)
|
|
80
|
+
: await loadLanguageFile(fallbackPath);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// export const t = await getLanguage(fileURLToPath(new URL('../locales', import.meta.url)));
|
|
84
|
+
|
|
85
|
+
const messages = await getLanguage(fileURLToPath(new URL('../locales', import.meta.url))); ;
|
|
86
|
+
|
|
87
|
+
export function t(
|
|
88
|
+
...params:
|
|
89
|
+
| [message: string, ...args: Array<string | number | boolean>]
|
|
90
|
+
| [message: string, args: Record<string, any>]
|
|
91
|
+
) {
|
|
92
|
+
if (params.length === 0 || !messages) {
|
|
93
|
+
return '';
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const [key, ...args] = params;
|
|
97
|
+
const text = messages[key] ?? '';
|
|
98
|
+
if (args[0] === null || args[0] === undefined || args[0] === '') {
|
|
99
|
+
return text;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const values: any = typeof args[0] === 'object' ? args[0] : args;
|
|
103
|
+
return text.replace(/\{([^}]+)\}/g, (match, group) => (values[group] ?? match) as string);
|
|
104
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { XxxCLIOptions } from '../types';
|
|
2
|
+
import Logger from '@tomjs/logger';
|
|
3
|
+
|
|
4
|
+
export const logger = new Logger({
|
|
5
|
+
directory: 'xxx/logs',
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
export const isWindows = process.platform === 'win32';
|
|
9
|
+
|
|
10
|
+
let _opts: XxxCLIOptions = {
|
|
11
|
+
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export function setOptions(opts: XxxCLIOptions) {
|
|
15
|
+
_opts = opts;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function getOptions() {
|
|
19
|
+
return _opts;
|
|
20
|
+
}
|
|
@@ -1,16 +1,15 @@
|
|
|
1
|
-
import { defineConfig } from '
|
|
1
|
+
import { defineConfig } from 'tsdown';
|
|
2
2
|
|
|
3
|
-
export default defineConfig(options => {
|
|
3
|
+
export default defineConfig((options) => {
|
|
4
4
|
const isDev = !!options.watch;
|
|
5
5
|
|
|
6
6
|
return {
|
|
7
7
|
entry: ['src/index.ts'],
|
|
8
|
-
format:
|
|
8
|
+
format: 'esm',
|
|
9
9
|
target: 'node18',
|
|
10
10
|
shims: false,
|
|
11
11
|
clean: true,
|
|
12
12
|
sourcemap: isDev,
|
|
13
|
-
splitting: false,
|
|
14
13
|
env: {
|
|
15
14
|
NODE_ENV: isDev ? 'development' : 'production',
|
|
16
15
|
},
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# react example
|
|
@@ -4,9 +4,8 @@
|
|
|
4
4
|
<meta charset="UTF-8" />
|
|
5
5
|
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
|
6
6
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
7
|
-
<title>
|
|
7
|
+
<title>vite+react</title>
|
|
8
8
|
</head>
|
|
9
|
-
|
|
10
9
|
<body>
|
|
11
10
|
<div id="root"></div>
|
|
12
11
|
<script type="module" src="/src/main.tsx"></script>
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "react-project",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "0.0.0",
|
|
5
|
+
"private": true,
|
|
6
|
+
"scripts": {
|
|
7
|
+
"dev": "vite",
|
|
8
|
+
"build": "tsc -b && vite build",
|
|
9
|
+
"lint": "eslint .",
|
|
10
|
+
"preview": "vite preview"
|
|
11
|
+
},
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"react": "^19.2.0",
|
|
14
|
+
"react-dom": "^19.2.0"
|
|
15
|
+
},
|
|
16
|
+
"devDependencies": {
|
|
17
|
+
"@eslint-react/eslint-plugin": "^2.3.9",
|
|
18
|
+
"@types/node": "^24.10.1",
|
|
19
|
+
"@types/react": "^19.2.5",
|
|
20
|
+
"@types/react-dom": "^19.2.3",
|
|
21
|
+
"@vitejs/plugin-react-swc": "^4.2.2",
|
|
22
|
+
"eslint-plugin-react-hooks": "^7.0.1",
|
|
23
|
+
"eslint-plugin-react-refresh": "^0.4.24",
|
|
24
|
+
"typescript": "~5.9.3",
|
|
25
|
+
"vite": "^7.2.4"
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -1,19 +1,21 @@
|
|
|
1
1
|
#root {
|
|
2
2
|
max-width: 1280px;
|
|
3
|
-
margin: 0 auto;
|
|
4
3
|
padding: 2rem;
|
|
4
|
+
margin: 0 auto;
|
|
5
5
|
text-align: center;
|
|
6
6
|
}
|
|
7
7
|
|
|
8
8
|
.logo {
|
|
9
9
|
height: 6em;
|
|
10
10
|
padding: 1.5em;
|
|
11
|
-
will-change: filter;
|
|
12
11
|
transition: filter 300ms;
|
|
12
|
+
will-change: filter;
|
|
13
13
|
}
|
|
14
|
+
|
|
14
15
|
.logo:hover {
|
|
15
16
|
filter: drop-shadow(0 0 2em #646cffaa);
|
|
16
17
|
}
|
|
18
|
+
|
|
17
19
|
.logo.react:hover {
|
|
18
20
|
filter: drop-shadow(0 0 2em #61dafbaa);
|
|
19
21
|
}
|
|
@@ -22,6 +24,7 @@
|
|
|
22
24
|
from {
|
|
23
25
|
transform: rotate(0deg);
|
|
24
26
|
}
|
|
27
|
+
|
|
25
28
|
to {
|
|
26
29
|
transform: rotate(360deg);
|
|
27
30
|
}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { useState } from 'react';
|
|
2
|
-
import viteLogo from '/vite.svg';
|
|
3
2
|
import reactLogo from './assets/react.svg';
|
|
4
|
-
|
|
5
3
|
import './App.css';
|
|
4
|
+
import viteLogo from '/vite.svg';
|
|
6
5
|
|
|
7
6
|
function App() {
|
|
8
7
|
const [count, setCount] = useState(0);
|
|
@@ -10,21 +9,21 @@ function App() {
|
|
|
10
9
|
return (
|
|
11
10
|
<>
|
|
12
11
|
<div>
|
|
13
|
-
<a href="https://
|
|
12
|
+
<a href="https://vite.dev" target="_blank">
|
|
14
13
|
<img src={viteLogo} className="logo" alt="Vite logo" />
|
|
15
14
|
</a>
|
|
16
|
-
<a href="https://react.dev" target="_blank"
|
|
15
|
+
<a href="https://react.dev" target="_blank">
|
|
17
16
|
<img src={reactLogo} className="logo react" alt="React logo" />
|
|
18
17
|
</a>
|
|
19
18
|
</div>
|
|
20
19
|
<h1>Vite + React</h1>
|
|
21
20
|
<div className="card">
|
|
22
|
-
<button onClick={() => setCount(count => count + 1)}>
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
21
|
+
<button onClick={() => setCount(count => count + 1)}>
|
|
22
|
+
count is
|
|
23
|
+
{' '}
|
|
24
|
+
{count}
|
|
25
|
+
</button>
|
|
26
26
|
</div>
|
|
27
|
-
<p className="read-the-docs">Click on the Vite and React logos to learn more</p>
|
|
28
27
|
</>
|
|
29
28
|
);
|
|
30
29
|
}
|
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
:root {
|
|
2
|
-
font-family:
|
|
3
|
-
line-height: 1.5;
|
|
2
|
+
font-family: system-ui, Avenir, Helvetica, Arial, sans-serif;
|
|
4
3
|
font-weight: 400;
|
|
5
4
|
|
|
6
|
-
|
|
5
|
+
font-synthesis: none;
|
|
6
|
+
line-height: 1.5;
|
|
7
7
|
color: rgba(255, 255, 255, 0.87);
|
|
8
|
-
background-color: #242424;
|
|
9
8
|
|
|
10
|
-
|
|
9
|
+
color-scheme: light dark;
|
|
10
|
+
background-color: #242424;
|
|
11
11
|
text-rendering: optimizeLegibility;
|
|
12
12
|
-webkit-font-smoothing: antialiased;
|
|
13
13
|
-moz-osx-font-smoothing: grayscale;
|
|
14
|
-
-webkit-text-size-adjust: 100%;
|
|
15
14
|
}
|
|
16
15
|
|
|
17
16
|
a {
|
|
@@ -19,16 +18,17 @@ a {
|
|
|
19
18
|
color: #646cff;
|
|
20
19
|
text-decoration: inherit;
|
|
21
20
|
}
|
|
21
|
+
|
|
22
22
|
a:hover {
|
|
23
23
|
color: #535bf2;
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
body {
|
|
27
|
-
margin: 0;
|
|
28
27
|
display: flex;
|
|
29
28
|
place-items: center;
|
|
30
29
|
min-width: 320px;
|
|
31
30
|
min-height: 100vh;
|
|
31
|
+
margin: 0;
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
h1 {
|
|
@@ -37,19 +37,21 @@ h1 {
|
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
button {
|
|
40
|
-
border-radius: 8px;
|
|
41
|
-
border: 1px solid transparent;
|
|
42
40
|
padding: 0.6em 1.2em;
|
|
41
|
+
font-family: inherit;
|
|
43
42
|
font-size: 1em;
|
|
44
43
|
font-weight: 500;
|
|
45
|
-
font-family: inherit;
|
|
46
|
-
background-color: #1a1a1a;
|
|
47
44
|
cursor: pointer;
|
|
45
|
+
background-color: #1a1a1a;
|
|
46
|
+
border: 1px solid transparent;
|
|
47
|
+
border-radius: 8px;
|
|
48
48
|
transition: border-color 0.25s;
|
|
49
49
|
}
|
|
50
|
+
|
|
50
51
|
button:hover {
|
|
51
52
|
border-color: #646cff;
|
|
52
53
|
}
|
|
54
|
+
|
|
53
55
|
button:focus,
|
|
54
56
|
button:focus-visible {
|
|
55
57
|
outline: 4px auto -webkit-focus-ring-color;
|
|
@@ -60,9 +62,11 @@ button:focus-visible {
|
|
|
60
62
|
color: #213547;
|
|
61
63
|
background-color: #ffffff;
|
|
62
64
|
}
|
|
65
|
+
|
|
63
66
|
a:hover {
|
|
64
67
|
color: #747bff;
|
|
65
68
|
}
|
|
69
|
+
|
|
66
70
|
button {
|
|
67
71
|
background-color: #f9f9f9;
|
|
68
72
|
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import react from '@vitejs/plugin-react-swc';
|
|
3
|
+
import { defineConfig } from 'vite';
|
|
4
|
+
|
|
5
|
+
// https://vite.dev/config/
|
|
6
|
+
export default defineConfig({
|
|
7
|
+
resolve: {
|
|
8
|
+
alias: {
|
|
9
|
+
// https://github.com/facebook/react/issues/24928#issuecomment-2267624188
|
|
10
|
+
react: path.resolve(process.cwd(), 'node_modules/react'),
|
|
11
|
+
},
|
|
12
|
+
},
|
|
13
|
+
plugins: [react()],
|
|
14
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# vue example
|