@tomjs/create-app 1.7.0 → 2.0.0

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.
Files changed (263) hide show
  1. package/README.md +1 -1
  2. package/README.zh_CN.md +1 -1
  3. package/dist/index.js +10 -22
  4. package/package.json +48 -51
  5. package/templates/{base/core → config/base}/.editorconfig +0 -4
  6. package/templates/config/base/.vscode/settings.json +50 -0
  7. package/templates/{base/core/_gitignore → config/base/_.gitignore} +1 -3
  8. package/templates/config/base/_commitlint.config.mjs +3 -0
  9. package/templates/config/base/_eslint.config.mjs +8 -0
  10. package/templates/config/base/lint-staged.config.mjs +3 -0
  11. package/templates/config/base/package.json +24 -0
  12. package/templates/config/base/pnpm-workspace.yaml +3 -0
  13. package/templates/config/base/simple-git-hooks.mjs +4 -0
  14. package/templates/{vscode → config/public}/LICENSE +1 -1
  15. package/templates/config/public/README.md +20 -0
  16. package/templates/config/public/README.zh_CN.md +20 -0
  17. package/templates/config/public/package.json +10 -0
  18. package/templates/config/style/lint-staged.config.mjs +7 -0
  19. package/templates/config/style/package.json +12 -0
  20. package/templates/config/style/stylelint.config.mjs +3 -0
  21. package/templates/{base/electron → electron-react}/.vscode/launch.json +23 -3
  22. package/templates/electron-react/.vscode/tasks.json +67 -0
  23. package/templates/electron-react/README.md +1 -1
  24. package/templates/electron-react/_eslint.config.mjs +8 -0
  25. package/templates/electron-react/electron/main/index.ts +71 -40
  26. package/templates/electron-react/electron/preload/index.ts +4 -0
  27. package/templates/electron-react/index.html +1 -2
  28. package/templates/electron-react/package.json +35 -1
  29. package/templates/electron-react/pnpm-workspace.yaml +6 -0
  30. package/templates/electron-react/src/App.css +6 -2
  31. package/templates/electron-react/src/App.tsx +12 -5
  32. package/templates/electron-react/src/index.css +14 -9
  33. package/templates/electron-react/tsconfig.json +9 -0
  34. package/templates/{base/electron → electron-react}/tsconfig.node.json +1 -1
  35. package/templates/electron-react/vite.config.ts +9 -22
  36. package/templates/electron-vue/.vscode/launch.json +48 -0
  37. package/templates/electron-vue/.vscode/tasks.json +67 -0
  38. package/templates/electron-vue/README.md +1 -1
  39. package/templates/electron-vue/_eslint.config.mjs +8 -0
  40. package/templates/electron-vue/electron/env.d.ts +1 -0
  41. package/templates/electron-vue/electron/main/index.ts +46 -30
  42. package/templates/electron-vue/electron/preload/index.ts +4 -0
  43. package/templates/electron-vue/index.html +1 -2
  44. package/templates/electron-vue/package.json +31 -2
  45. package/templates/electron-vue/pnpm-workspace.yaml +5 -0
  46. package/templates/electron-vue/src/App.vue +1 -1
  47. package/templates/electron-vue/src/style.css +15 -10
  48. package/templates/electron-vue/tsconfig.json +5 -0
  49. package/templates/electron-vue/tsconfig.node.json +7 -0
  50. package/templates/electron-vue/vite.config.ts +3 -21
  51. package/templates/{node-cli-legacy → node-base}/.vscode/launch.json +3 -6
  52. package/templates/node-base/package.json +15 -0
  53. package/templates/node-base/src/index.ts +5 -0
  54. package/templates/{node-cli-legacy → node-base}/tsconfig.json +1 -1
  55. package/templates/node-cli/.vscode/i18n-ally-custom-framework.yml +35 -0
  56. package/templates/node-cli/.vscode/launch.json +3 -6
  57. package/templates/node-cli/.vscode/settings.json +56 -0
  58. package/templates/node-cli/_.gitignore +59 -0
  59. package/templates/node-cli/locales/en-US.json +11 -0
  60. package/templates/node-cli/locales/zh-Hans.json +11 -0
  61. package/templates/node-cli/locales/zh-Hant.json +11 -0
  62. package/templates/node-cli/package.json +20 -20
  63. package/templates/node-cli/src/app.ts +19 -0
  64. package/templates/node-cli/src/config.ts +2 -2
  65. package/templates/node-cli/src/index.ts +77 -1
  66. package/templates/node-cli/src/types.ts +5 -1
  67. package/templates/node-cli/src/utils/exec.ts +68 -0
  68. package/templates/node-cli/src/utils/index.ts +3 -0
  69. package/templates/node-cli/src/utils/lang.ts +104 -0
  70. package/templates/node-cli/src/utils/util.ts +20 -0
  71. package/templates/node-cli/tsconfig.json +2 -2
  72. package/templates/node-cli/{tsup.config.ts → tsdown.config.ts} +3 -4
  73. package/templates/node-vite/examples/react/README.md +1 -0
  74. package/templates/node-vite/examples/react/_eslint.config.mjs +6 -0
  75. package/templates/{react → node-vite/examples/react}/index.html +1 -2
  76. package/templates/node-vite/examples/react/package.json +27 -0
  77. package/templates/{react → node-vite/examples/react}/src/App.css +5 -2
  78. package/templates/{react → node-vite/examples/react}/src/App.tsx +8 -9
  79. package/templates/{react → node-vite/examples/react}/src/index.css +15 -11
  80. package/templates/node-vite/examples/react/src/main.tsx +10 -0
  81. package/templates/node-vite/examples/react/tsconfig.json +5 -0
  82. package/templates/node-vite/examples/react/vite.config.ts +14 -0
  83. package/templates/node-vite/examples/vue/README.md +1 -0
  84. package/templates/node-vite/examples/vue/_eslint.config.mjs +6 -0
  85. package/templates/{vue → node-vite/examples/vue}/index.html +1 -2
  86. package/templates/node-vite/examples/vue/package.json +22 -0
  87. package/templates/{vue → node-vite/examples/vue}/src/App.vue +3 -3
  88. package/templates/node-vite/examples/vue/src/components/HelloWorld.vue +19 -0
  89. package/templates/{vue → node-vite/examples/vue}/src/main.ts +0 -1
  90. package/templates/{vue → node-vite/examples/vue}/src/style.css +16 -12
  91. package/templates/{base → node-vite/examples}/vue/tsconfig.json +2 -2
  92. package/templates/{vue → node-vite/examples/vue}/vite.config.ts +1 -1
  93. package/templates/node-vite/package.json +16 -0
  94. package/templates/node-vite/pnpm-lock.yaml +2293 -0
  95. package/templates/node-vite/pnpm-workspace.yaml +6 -0
  96. package/templates/{node → node-vite}/tsconfig.json +1 -1
  97. package/templates/{node-cli-legacy/tsup.config.ts → node-vite/tsdown.config.ts} +4 -5
  98. package/templates/vscode-base/.vscode/settings.json +59 -0
  99. package/templates/{vscode → vscode-base}/.vscode/tasks.json +2 -2
  100. package/templates/{base/node → vscode-base}/LICENSE +1 -1
  101. package/templates/{vscode/_gitignore → vscode-base/_.gitignore} +1 -0
  102. package/templates/vscode-base/locales/zh-CN.json +6 -0
  103. package/templates/{vscode → vscode-base}/package.json +12 -19
  104. package/templates/vscode-base/resources/logo.png +0 -0
  105. package/templates/vscode-base/resources/logo.svg +1 -0
  106. package/templates/{vscode/tsup.config.ts → vscode-base/tsdown.config.ts} +3 -3
  107. package/templates/{base/vscode → vscode-react}/.vscode/launch.json +14 -1
  108. package/templates/vscode-react/.vscode/settings.json +59 -0
  109. package/templates/{base/vscode → vscode-react}/.vscode/tasks.json +10 -1
  110. package/templates/{base/vscode → vscode-react}/LICENSE +1 -1
  111. package/templates/vscode-react/README.md +2 -2
  112. package/templates/{base/vscode/_gitignore → vscode-react/_.gitignore} +2 -1
  113. package/templates/{base/vscode → vscode-react}/extension/views/helper.ts +5 -4
  114. package/templates/{base/vscode → vscode-react}/extension/views/panel.ts +2 -1
  115. package/templates/vscode-react/package.json +65 -1
  116. package/templates/vscode-react/pnpm-workspace.yaml +5 -0
  117. package/templates/vscode-react/src/App.css +1 -1
  118. package/templates/vscode-react/src/App.tsx +16 -10
  119. package/templates/vscode-react/src/utils/vscode.ts +2 -81
  120. package/templates/vscode-react/src/vite-env.d.ts +1 -0
  121. package/templates/vscode-react/tsconfig.json +5 -0
  122. package/templates/vscode-react/vite.config.ts +4 -5
  123. package/templates/vscode-vue/.vscode/extensions.json +5 -0
  124. package/templates/vscode-vue/.vscode/launch.json +34 -0
  125. package/templates/vscode-vue/.vscode/settings.json +59 -0
  126. package/templates/{base/electron → vscode-vue}/.vscode/tasks.json +14 -6
  127. package/templates/vscode-vue/.vscodeignore +73 -0
  128. package/templates/vscode-vue/LICENSE +21 -0
  129. package/templates/vscode-vue/README.md +2 -2
  130. package/templates/vscode-vue/_.gitignore +65 -0
  131. package/templates/vscode-vue/extension/env.d.ts +1 -0
  132. package/templates/vscode-vue/extension/index.ts +21 -0
  133. package/templates/vscode-vue/extension/views/helper.ts +28 -0
  134. package/templates/vscode-vue/extension/views/panel.ts +49 -0
  135. package/templates/vscode-vue/locales/en.json +6 -0
  136. package/templates/vscode-vue/package.json +56 -2
  137. package/templates/vscode-vue/pnpm-workspace.yaml +4 -0
  138. package/templates/vscode-vue/src/App.vue +17 -11
  139. package/templates/vscode-vue/src/utils/vscode.ts +2 -81
  140. package/templates/vscode-vue/src/vite-env.d.ts +1 -0
  141. package/templates/vscode-vue/tsconfig.json +5 -0
  142. package/templates/vscode-vue/tsconfig.node.json +7 -0
  143. package/templates/vscode-vue/vite.config.ts +0 -4
  144. package/templates/web-react/README.md +1 -0
  145. package/templates/web-react/_eslint.config.mjs +6 -0
  146. package/templates/web-react/index.html +13 -0
  147. package/templates/web-react/package.json +27 -0
  148. package/templates/web-react/public/vite.svg +1 -0
  149. package/templates/web-react/src/App.css +45 -0
  150. package/templates/web-react/src/App.tsx +31 -0
  151. package/templates/web-react/src/assets/react.svg +1 -0
  152. package/templates/web-react/src/index.css +73 -0
  153. package/templates/web-react/src/main.tsx +10 -0
  154. package/templates/web-react/tsconfig.app.json +28 -0
  155. package/templates/web-react/tsconfig.json +7 -0
  156. package/templates/web-react/tsconfig.node.json +26 -0
  157. package/templates/web-react/vite.config.ts +14 -0
  158. package/templates/web-vue/README.md +1 -0
  159. package/templates/web-vue/_eslint.config.mjs +6 -0
  160. package/templates/web-vue/index.html +13 -0
  161. package/templates/web-vue/package.json +22 -0
  162. package/templates/web-vue/public/vite.svg +1 -0
  163. package/templates/web-vue/src/App.vue +32 -0
  164. package/templates/web-vue/src/assets/vue.svg +1 -0
  165. package/templates/web-vue/src/components/HelloWorld.vue +19 -0
  166. package/templates/web-vue/src/main.ts +5 -0
  167. package/templates/web-vue/src/style.css +84 -0
  168. package/templates/web-vue/tsconfig.app.json +4 -0
  169. package/templates/web-vue/tsconfig.json +7 -0
  170. package/templates/web-vue/tsconfig.node.json +7 -0
  171. package/templates/web-vue/vite.config.ts +7 -0
  172. package/templates/base/core/.commitlintrc.cjs +0 -3
  173. package/templates/base/core/.eslintignore +0 -14
  174. package/templates/base/core/.husky/commit-msg +0 -1
  175. package/templates/base/core/.husky/pre-commit +0 -1
  176. package/templates/base/core/.prettierignore +0 -17
  177. package/templates/base/core/.prettierrc.cjs +0 -1
  178. package/templates/base/core/_eslintrc.cjs +0 -7
  179. package/templates/base/core/_lintstagedrc.cjs +0 -4
  180. package/templates/base/core/package.json +0 -31
  181. package/templates/base/electron/electron/main/index.ts +0 -111
  182. package/templates/base/electron/electron/polyfills.ts +0 -4
  183. package/templates/base/electron/electron/preload/index.ts +0 -1
  184. package/templates/base/electron/package.json +0 -25
  185. package/templates/base/node/README.md +0 -13
  186. package/templates/base/node/README.zh_CN.md +0 -13
  187. package/templates/base/node/package.json +0 -48
  188. package/templates/base/node/test/index.test.ts +0 -7
  189. package/templates/base/package/package.json +0 -8
  190. package/templates/base/react/_eslintrc.cjs +0 -7
  191. package/templates/base/react/_lintstagedrc.cjs +0 -6
  192. package/templates/base/react/package.json +0 -19
  193. package/templates/base/react/tsconfig.json +0 -5
  194. package/templates/base/style/.stylelintignore +0 -16
  195. package/templates/base/style/.stylelintrc.cjs +0 -3
  196. package/templates/base/style/_lintstagedrc.cjs +0 -5
  197. package/templates/base/style/package.json +0 -10
  198. package/templates/base/vscode/.vscode/settings.json +0 -10
  199. package/templates/base/vscode/package.json +0 -67
  200. package/templates/base/vue/_eslintrc.cjs +0 -7
  201. package/templates/base/vue/_lintstagedrc.cjs +0 -6
  202. package/templates/base/vue/package.json +0 -17
  203. package/templates/config.json +0 -108
  204. package/templates/electron-react/public/img/icon.png +0 -0
  205. package/templates/electron-vue/public/img/icon.png +0 -0
  206. package/templates/node/package.json +0 -10
  207. package/templates/node/src/index.ts +0 -3
  208. package/templates/node/tsup.config.ts +0 -19
  209. package/templates/node-cli/index.d.ts +0 -5
  210. package/templates/node-cli/src/cli.ts +0 -68
  211. package/templates/node-cli/xxx.config.cjs +0 -0
  212. package/templates/node-cli-legacy/index.d.ts +0 -5
  213. package/templates/node-cli-legacy/package.json +0 -30
  214. package/templates/node-cli-legacy/src/cli.ts +0 -45
  215. package/templates/node-cli-legacy/src/config.ts +0 -28
  216. package/templates/node-cli-legacy/src/index.ts +0 -3
  217. package/templates/node-cli-legacy/src/types.ts +0 -1
  218. package/templates/node-cli-legacy/src/utils.ts +0 -5
  219. package/templates/node-vite-plugin/package.json +0 -18
  220. package/templates/node-vite-plugin/test/index.test.ts +0 -7
  221. package/templates/node-vite-plugin/tsconfig.json +0 -4
  222. package/templates/node-vite-plugin/tsup.config.ts +0 -18
  223. package/templates/node-workspaces/package.json +0 -8
  224. package/templates/react/package.json +0 -12
  225. package/templates/react/src/main.tsx +0 -11
  226. package/templates/react/src/vite-env.d.ts +0 -1
  227. package/templates/react/vite.config.ts +0 -7
  228. package/templates/schema.json +0 -110
  229. package/templates/vscode/.vscode/settings.json +0 -10
  230. package/templates/vscode/README.md +0 -3
  231. package/templates/vue/package.json +0 -12
  232. package/templates/vue/src/components/HelloWorld.vue +0 -37
  233. package/templates/vue/src/vite-env.d.ts +0 -1
  234. package/templates/{base/core → config/base}/.gitattributes +0 -0
  235. package/templates/{node-cli-legacy/xxx.config.cjs → config/base/README.md} +0 -0
  236. package/templates/{base/electron → electron-react}/electron/env.d.ts +0 -0
  237. package/templates/{react → node-vite/examples/react}/public/vite.svg +0 -0
  238. package/templates/{react → node-vite/examples/react}/src/assets/react.svg +0 -0
  239. package/templates/{base → node-vite/examples}/react/tsconfig.node.json +0 -0
  240. package/templates/{vue → node-vite/examples/vue}/public/vite.svg +0 -0
  241. package/templates/{vue → node-vite/examples/vue}/src/assets/vue.svg +0 -0
  242. package/templates/{base → node-vite/examples}/vue/tsconfig.node.json +0 -0
  243. package/templates/{node-vite-plugin → node-vite}/src/index.ts +0 -0
  244. package/templates/{node-vite-plugin → node-vite}/src/types.ts +0 -0
  245. package/templates/{base/vscode → vscode-base}/.vscode/extensions.json +0 -0
  246. package/templates/{vscode → vscode-base}/.vscode/launch.json +0 -0
  247. package/templates/{vscode → vscode-base}/.vscodeignore +0 -0
  248. package/templates/{base/vscode → vscode-base}/README.md +0 -0
  249. package/templates/{vscode → vscode-base}/locales/en.json +0 -0
  250. package/templates/{vscode → vscode-base}/src/index.ts +1 -1
  251. package/templates/{vscode → vscode-base}/tsconfig.json +0 -0
  252. package/templates/{vscode → vscode-react}/.vscode/extensions.json +0 -0
  253. package/templates/{base/vscode → vscode-react}/.vscodeignore +0 -0
  254. package/templates/{base/vscode → vscode-react}/extension/env.d.ts +0 -0
  255. package/templates/{base/vscode → vscode-react}/extension/index.ts +1 -1
  256. /package/templates/{base/vscode → vscode-react}/locales/en.json +0 -0
  257. /package/templates/{base/vscode → vscode-react}/locales/zh-CN.json +0 -0
  258. /package/templates/{base/vscode → vscode-react}/resources/logo.png +0 -0
  259. /package/templates/{base/vscode → vscode-react}/resources/logo.svg +0 -0
  260. /package/templates/{base/vscode → vscode-react}/tsconfig.node.json +0 -0
  261. /package/templates/{vscode → vscode-vue}/locales/zh-CN.json +0 -0
  262. /package/templates/{vscode → vscode-vue}/resources/logo.png +0 -0
  263. /package/templates/{vscode → vscode-vue}/resources/logo.svg +0 -0
@@ -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.cwd,
7
+ stopDir: opts.dir,
8
8
  searchPlaces: [
9
9
  'package.json',
10
10
  'xxx.config.json',
@@ -1,3 +1,79 @@
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
- console.log('Hello World!');
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
+ flags: {
26
+ dir: {
27
+ type: 'string',
28
+ shortFlag: 'd',
29
+ },
30
+ config: {
31
+ type: 'string',
32
+ shortFlag: 'c',
33
+ },
34
+ verbose: {
35
+ type: 'boolean',
36
+ default: process.env.NODE_ENV === 'development',
37
+ },
38
+ help: {
39
+ type: 'boolean',
40
+ shortFlag: 'h',
41
+ default: false,
42
+ },
43
+ version: {
44
+ type: 'boolean',
45
+ shortFlag: 'v',
46
+ default: false,
47
+ },
48
+ },
49
+ },
50
+ );
51
+
52
+ const { input, flags } = cli;
53
+ if (flags.help) {
54
+ cli.showHelp(0);
55
+ }
56
+ else if (flags.version) {
57
+ cli.showVersion();
58
+ }
59
+ else {
60
+ logger.enableDebug(flags.verbose);
61
+ logger.debug('input:', input);
62
+ logger.debug('cli options:', flags);
63
+
64
+ const config = await getReleaseConfig(flags);
65
+ logger.debug('config file:', config);
66
+
67
+ const mergedOpts = Object.assign(
68
+ {
69
+ verbose: isDev,
70
+ } as XxxCLIOptions,
71
+ config,
72
+ flags,
73
+ ) as XxxCLIOptions;
74
+
75
+ mergedOpts.dir ||= process.cwd();
76
+ logger.debug('merged options:', mergedOpts);
77
+
78
+ await runApp(mergedOpts);
79
+ }
@@ -1 +1,5 @@
1
- export { XxxCLIOptions } from '../index';
1
+ export interface XxxCLIOptions {
2
+ dir?: string;
3
+ config?: string;
4
+ verbose?: boolean;
5
+ }
@@ -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,3 @@
1
+ export * from './exec';
2
+ export * from './lang';
3
+ export * from './util';
@@ -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,4 +1,4 @@
1
1
  {
2
- "extends": "@tomjs/tsconfig/node16.json",
3
- "include": ["src", "test", "*.ts"]
2
+ "extends": "@tomjs/tsconfig/node.json",
3
+ "include": ["src", "*.ts"]
4
4
  }
@@ -1,16 +1,15 @@
1
- import { defineConfig } from 'tsup';
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: ['esm'],
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
@@ -0,0 +1,6 @@
1
+ import defineConfig from '@tomjs/eslint';
2
+
3
+ export default defineConfig({
4
+ react: true,
5
+ typescript: true,
6
+ });
@@ -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>Vite + React</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://vitejs.dev" target="_blank" rel="noreferrer">
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" rel="noreferrer">
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)}>count is {count}</button>
23
- <p>
24
- Edit <code>src/App.tsx</code> and save to test HMR
25
- </p>
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: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif;
3
- line-height: 1.5;
2
+ font-family: system-ui, Avenir, Helvetica, Arial, sans-serif;
4
3
  font-weight: 400;
5
4
 
6
- color-scheme: light dark;
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
- font-synthesis: none;
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,10 @@
1
+ import { StrictMode } from 'react';
2
+ import { createRoot } from 'react-dom/client';
3
+ import App from './App.tsx';
4
+ import './index.css';
5
+
6
+ createRoot(document.getElementById('root')!).render(
7
+ <StrictMode>
8
+ <App />
9
+ </StrictMode>,
10
+ );
@@ -0,0 +1,5 @@
1
+ {
2
+ "extends": "@tomjs/tsconfig/react.json",
3
+ "references": [{ "path": "./tsconfig.node.json" }],
4
+ "include": ["src"]
5
+ }
@@ -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
@@ -0,0 +1,6 @@
1
+ import defineConfig from '@tomjs/eslint';
2
+
3
+ export default defineConfig({
4
+ vue: true,
5
+ typescript: true,
6
+ });
@@ -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>Vite + Vue</title>
7
+ <title>vite+vue</title>
8
8
  </head>
9
-
10
9
  <body>
11
10
  <div id="app"></div>
12
11
  <script type="module" src="/src/main.ts"></script>
@@ -0,0 +1,22 @@
1
+ {
2
+ "name": "vite-vue",
3
+ "type": "module",
4
+ "version": "0.0.0",
5
+ "private": true,
6
+ "scripts": {
7
+ "dev": "vite",
8
+ "build": "vue-tsc -b && vite build",
9
+ "preview": "vite preview"
10
+ },
11
+ "dependencies": {
12
+ "vue": "^3.5.24"
13
+ },
14
+ "devDependencies": {
15
+ "@types/node": "^24.10.1",
16
+ "@vitejs/plugin-vue": "^6.0.1",
17
+ "@vue/tsconfig": "^0.8.1",
18
+ "typescript": "~5.9.3",
19
+ "vite": "^7.2.4",
20
+ "vue-tsc": "^3.1.4"
21
+ }
22
+ }
@@ -1,10 +1,10 @@
1
1
  <script setup lang="ts">
2
- import HelloWorld from './components/HelloWorld.vue';
2
+ import HelloWorld from './components/HelloWorld.vue'
3
3
  </script>
4
4
 
5
5
  <template>
6
6
  <div>
7
- <a href="https://vitejs.dev" target="_blank">
7
+ <a href="https://vite.dev" target="_blank">
8
8
  <img src="/vite.svg" class="logo" alt="Vite logo" />
9
9
  </a>
10
10
  <a href="https://vuejs.org/" target="_blank">
@@ -18,8 +18,8 @@ import HelloWorld from './components/HelloWorld.vue';
18
18
  .logo {
19
19
  height: 6em;
20
20
  padding: 1.5em;
21
- will-change: filter;
22
21
  transition: filter 300ms;
22
+ will-change: filter;
23
23
  }
24
24
 
25
25
  .logo:hover {
@@ -0,0 +1,19 @@
1
+ <script setup lang="ts">
2
+ import { ref } from 'vue'
3
+
4
+ defineProps<{ msg: string }>()
5
+
6
+ const count = ref(0)
7
+ </script>
8
+
9
+ <template>
10
+ <h1>{{ msg }}</h1>
11
+
12
+ <div class="card">
13
+ <button type="button" @click="count++">count is {{ count }}</button>
14
+ </div>
15
+ </template>
16
+
17
+ <style scoped>
18
+
19
+ </style>