@yugu-ui/shared 0.0.0-stage → 0.1.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.
Files changed (71) hide show
  1. package/bin.ts +4 -0
  2. package/dist/bin.d.ts +0 -0
  3. package/dist/constants/index.d.ts +1 -0
  4. package/dist/constants/reg.d.ts +12 -0
  5. package/dist/constants.d.ts +2 -0
  6. package/dist/constants.js +15 -0
  7. package/dist/hooks/index.d.ts +8 -0
  8. package/dist/hooks/use-boolean.d.ts +12 -0
  9. package/dist/hooks/use-context.d.ts +15 -0
  10. package/dist/hooks/use-count-down.d.ts +12 -0
  11. package/dist/hooks/use-loading.d.ts +10 -0
  12. package/dist/hooks/use-request.d.ts +23 -0
  13. package/dist/hooks/use-svg-icon-render.d.ts +19 -0
  14. package/dist/hooks/use-table.d.ts +63 -0
  15. package/dist/hooks.d.ts +2 -0
  16. package/dist/hooks.js +205 -0
  17. package/dist/index.d.ts +2 -0
  18. package/dist/index.js +3146 -0
  19. package/dist/nanoid-CQE6QAZJ.js +2 -0
  20. package/dist/request/constant.d.ts +6 -0
  21. package/dist/request/index.d.ts +22 -0
  22. package/dist/request/options.d.ts +6 -0
  23. package/dist/request/shared.d.ts +17 -0
  24. package/dist/request/type.d.ts +94 -0
  25. package/dist/request.d.ts +2 -0
  26. package/dist/request.js +182 -0
  27. package/dist/scripts/src/commands/changelog.d.ts +2 -0
  28. package/dist/scripts/src/commands/cleanup.d.ts +1 -0
  29. package/dist/scripts/src/commands/git-commit.d.ts +9 -0
  30. package/dist/scripts/src/commands/index.d.ts +6 -0
  31. package/dist/scripts/src/commands/release.d.ts +1 -0
  32. package/dist/scripts/src/commands/router.d.ts +2 -0
  33. package/dist/scripts/src/commands/update-pkg.d.ts +1 -0
  34. package/dist/scripts/src/config/index.d.ts +2 -0
  35. package/dist/scripts/src/index.d.ts +1 -0
  36. package/dist/scripts/src/locales/index.d.ts +25 -0
  37. package/dist/scripts/src/shared/index.d.ts +2 -0
  38. package/dist/scripts/src/types/index.d.ts +30 -0
  39. package/dist/uno-preset/index.d.ts +4 -0
  40. package/dist/uno-preset.d.ts +6 -0
  41. package/dist/uno-preset.js +49 -0
  42. package/dist/utils/color/constant/index.d.ts +2 -0
  43. package/dist/utils/color/constant/name.d.ts +8 -0
  44. package/dist/utils/color/constant/palette.d.ts +2 -0
  45. package/dist/utils/color/index.d.ts +5 -0
  46. package/dist/utils/color/palette/antd.d.ts +18 -0
  47. package/dist/utils/color/palette/index.d.ts +17 -0
  48. package/dist/utils/color/palette/recommend.d.ts +20 -0
  49. package/dist/utils/color/shared/colord.d.ts +38 -0
  50. package/dist/utils/color/shared/index.d.ts +2 -0
  51. package/dist/utils/color/shared/name.d.ts +6 -0
  52. package/dist/utils/color/types/index.d.ts +52 -0
  53. package/dist/utils/common.d.ts +2 -0
  54. package/dist/utils/index.d.ts +5 -0
  55. package/dist/utils/klona.d.ts +2 -0
  56. package/dist/utils/nanoid.d.ts +1 -0
  57. package/dist/utils/storage.d.ts +28 -0
  58. package/package.json +89 -4
  59. package/scripts/src/commands/changelog.ts +10 -0
  60. package/scripts/src/commands/cleanup.ts +5 -0
  61. package/scripts/src/commands/git-commit.ts +107 -0
  62. package/scripts/src/commands/index.ts +6 -0
  63. package/scripts/src/commands/release.ts +12 -0
  64. package/scripts/src/commands/router.ts +90 -0
  65. package/scripts/src/commands/update-pkg.ts +5 -0
  66. package/scripts/src/config/index.ts +39 -0
  67. package/scripts/src/index.ts +110 -0
  68. package/scripts/src/locales/index.ts +84 -0
  69. package/scripts/src/shared/index.ts +7 -0
  70. package/scripts/src/types/index.ts +31 -0
  71. package/README.md +0 -3
@@ -0,0 +1,52 @@
1
+ /**
2
+ * the color palette number
3
+ *
4
+ * the main color number is 500
5
+ */
6
+ export type ColorPaletteNumber = 50 | 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900 | 950;
7
+ /** the color palette */
8
+ export type ColorPalette = {
9
+ /** the color hex value */
10
+ hex: string;
11
+ /**
12
+ * the color number
13
+ *
14
+ * - 50 | 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900 | 950
15
+ */
16
+ number: ColorPaletteNumber;
17
+ };
18
+ /** the color palette family */
19
+ export type ColorPaletteFamily = {
20
+ /** the color palette family name */
21
+ name: string;
22
+ /** the color palettes */
23
+ palettes: ColorPalette[];
24
+ };
25
+ /** the color palette with delta */
26
+ export type ColorPaletteWithDelta = ColorPalette & {
27
+ delta: number;
28
+ };
29
+ /** the color palette family with nearest palette */
30
+ export type ColorPaletteFamilyWithNearestPalette = ColorPaletteFamily & {
31
+ nearestPalette: ColorPaletteWithDelta;
32
+ nearestLightnessPalette: ColorPaletteWithDelta;
33
+ };
34
+ /** the color palette match */
35
+ export type ColorPaletteMatch = ColorPaletteFamily & {
36
+ /** the color map of the palette */
37
+ colorMap: Map<ColorPaletteNumber, ColorPalette>;
38
+ /**
39
+ * the main color of the palette
40
+ *
41
+ * which number is 500
42
+ */
43
+ main: ColorPalette;
44
+ /** the match color of the palette */
45
+ match: ColorPalette;
46
+ };
47
+ /**
48
+ * The color index of color palette
49
+ *
50
+ * From left to right, the color is from light to dark, 6 is main color
51
+ */
52
+ export type ColorIndex = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11;
@@ -0,0 +1,2 @@
1
+ export declare function isTimeColumn(key: string): boolean;
2
+ export declare function formatTime(value: any, format?: string): string;
@@ -0,0 +1,5 @@
1
+ export * from './storage';
2
+ export * from './nanoid';
3
+ export * from './klona';
4
+ export * from './color';
5
+ export * from './common';
@@ -0,0 +1,2 @@
1
+ import { klona as jsonClone } from 'klona/json';
2
+ export { jsonClone };
@@ -0,0 +1 @@
1
+ export { nanoid } from 'nanoid';
@@ -0,0 +1,28 @@
1
+ import { default as localforage } from 'localforage';
2
+ /** The storage type */
3
+ export type StorageType = 'local' | 'session';
4
+ export declare function createStorage<T extends object>(type: StorageType, storagePrefix: string): {
5
+ /**
6
+ * Set session
7
+ *
8
+ * @param key Session key
9
+ * @param value Session value
10
+ */
11
+ set<K extends keyof T>(key: K, value: T[K]): void;
12
+ /**
13
+ * Get session
14
+ *
15
+ * @param key Session key
16
+ */
17
+ get<K extends keyof T>(key: K): T[K] | null;
18
+ remove(key: keyof T): void;
19
+ clear(): void;
20
+ };
21
+ type LocalForage<T extends object> = Omit<typeof localforage, 'getItem' | 'setItem' | 'removeItem'> & {
22
+ getItem<K extends keyof T>(key: K, callback?: (err: any, value: T[K] | null) => void): Promise<T[K] | null>;
23
+ setItem<K extends keyof T>(key: K, value: T[K], callback?: (err: any, value: T[K]) => void): Promise<T[K]>;
24
+ removeItem(key: keyof T, callback?: (err: any) => void): Promise<void>;
25
+ };
26
+ type LocalforageDriver = 'local' | 'indexedDB' | 'webSQL';
27
+ export declare function createLocalforage<T extends object>(driver: LocalforageDriver): LocalForage<T>;
28
+ export {};
package/package.json CHANGED
@@ -1,6 +1,91 @@
1
1
  {
2
2
  "name": "@yugu-ui/shared",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.1",
4
+ "description": "堉古共享公共包:utils / request / hooks / uno-preset / scripts 五模块合一,后续公共代码统一进本包(阶段 1 收编 @sa/*)",
5
+ "type": "module",
6
+ "license": "UNLICENSED",
7
+ "sideEffects": false,
8
+ "files": [
9
+ "dist",
10
+ "bin.ts",
11
+ "scripts"
12
+ ],
13
+ "bin": {
14
+ "sa": "./bin.ts"
15
+ },
16
+ "main": "./dist/index.js",
17
+ "module": "./dist/index.js",
18
+ "types": "./dist/index.d.ts",
19
+ "exports": {
20
+ ".": {
21
+ "types": "./dist/index.d.ts",
22
+ "import": "./dist/index.js"
23
+ },
24
+ "./utils": {
25
+ "types": "./dist/index.d.ts",
26
+ "import": "./dist/index.js"
27
+ },
28
+ "./request": {
29
+ "types": "./dist/request.d.ts",
30
+ "import": "./dist/request.js"
31
+ },
32
+ "./hooks": {
33
+ "types": "./dist/hooks.d.ts",
34
+ "import": "./dist/hooks.js"
35
+ },
36
+ "./uno-preset": {
37
+ "types": "./dist/uno-preset.d.ts",
38
+ "import": "./dist/uno-preset.js"
39
+ },
40
+ "./constants": {
41
+ "types": "./dist/constants.d.ts",
42
+ "import": "./dist/constants.js"
43
+ },
44
+ "./scripts": "./scripts/src/index.ts"
45
+ },
46
+ "scripts": {
47
+ "build": "vite build --config vite.lib.config.ts",
48
+ "typecheck": "tsc --noEmit --skipLibCheck"
49
+ },
50
+ "peerDependencies": {
51
+ "vue": ">=3.3.0"
52
+ },
53
+ "dependencies": {
54
+ "@soybeanjs/changelog": "0.4.7",
55
+ "@vueuse/core": "14.3.0",
56
+ "axios": "1.16.0",
57
+ "axios-retry": "4.5.0",
58
+ "bumpp": "11.1.0",
59
+ "c12": "3.3.4",
60
+ "cac": "7.0.0",
61
+ "colord": "2.9.3",
62
+ "consola": "3.4.2",
63
+ "dayjs": "1.11.20",
64
+ "enquirer": "2.4.1",
65
+ "execa": "9.6.1",
66
+ "klona": "2.0.6",
67
+ "kolorist": "1.8.0",
68
+ "localforage": "1.10.0",
69
+ "nanoid": "5.1.11",
70
+ "npm-check-updates": "22.2.0",
71
+ "picomatch": "4.0.4",
72
+ "qs": "6.15.1",
73
+ "rimraf": "6.1.3"
74
+ },
75
+ "devDependencies": {
76
+ "@types/node": "^22.10.5",
77
+ "@types/qs": "6.15.1",
78
+ "typescript": "6.0.3",
79
+ "unocss": "66.7.5",
80
+ "unplugin-dts": "^1.1.2",
81
+ "vite": "8.0.12",
82
+ "vue": "3.5.34"
83
+ },
84
+ "engines": {
85
+ "node": ">=20.19.0"
86
+ },
87
+ "publishConfig": {
88
+ "access": "public",
89
+ "registry": "https://registry.npmjs.org/"
90
+ }
91
+ }
@@ -0,0 +1,10 @@
1
+ import { generateChangelog, generateTotalChangelog } from '@soybeanjs/changelog';
2
+ import type { ChangelogOption } from '@soybeanjs/changelog';
3
+
4
+ export async function genChangelog(options?: Partial<ChangelogOption>, total = false) {
5
+ if (total) {
6
+ await generateTotalChangelog(options);
7
+ } else {
8
+ await generateChangelog(options);
9
+ }
10
+ }
@@ -0,0 +1,5 @@
1
+ import { rimraf } from 'rimraf';
2
+
3
+ export async function cleanup(paths: string[]) {
4
+ await rimraf(paths, { glob: true });
5
+ }
@@ -0,0 +1,107 @@
1
+ import path from 'node:path';
2
+ import { readFileSync } from 'node:fs';
3
+ import { prompt } from 'enquirer';
4
+ import { execCommand } from '../shared';
5
+ import { locales } from '../locales';
6
+ import type { Lang } from '../locales';
7
+
8
+ interface PromptObject {
9
+ types: string;
10
+ scopes: string;
11
+ description: string;
12
+ }
13
+
14
+ /**
15
+ * Git commit with Conventional Commits standard
16
+ *
17
+ * @param lang
18
+ */
19
+ export async function gitCommit(lang: Lang = 'en-us') {
20
+ const { gitCommitMessages, gitCommitNoStaged, gitCommitTypes, gitCommitScopes } = locales[lang];
21
+
22
+ const stagedFiles = await execCommand('git', ['diff', '--cached', '--name-only']);
23
+
24
+ if (!stagedFiles) {
25
+ console.error(gitCommitNoStaged);
26
+ process.exit(1);
27
+ }
28
+
29
+ const typesChoices = gitCommitTypes.map(([value, msg]) => {
30
+ const nameWithSuffix = `${value}:`;
31
+
32
+ const message = `${nameWithSuffix.padEnd(12)}${msg}`;
33
+
34
+ return {
35
+ name: value,
36
+ message
37
+ };
38
+ });
39
+
40
+ const scopesChoices = gitCommitScopes.map(([value, msg]) => ({
41
+ name: value,
42
+ message: `${value.padEnd(30)} (${msg})`
43
+ }));
44
+
45
+ // Suppress ERR_USE_AFTER_CLOSE thrown by enquirer's readline cleanup on Ctrl+C (Node.js v24+)
46
+ const errorHandler = (error: NodeJS.ErrnoException) => {
47
+ if (error.code === 'ERR_USE_AFTER_CLOSE') {
48
+ process.exit(0);
49
+ }
50
+ };
51
+ process.on('uncaughtException', errorHandler);
52
+
53
+ let result: PromptObject;
54
+
55
+ try {
56
+ result = await prompt<PromptObject>([
57
+ {
58
+ name: 'types',
59
+ type: 'select',
60
+ message: gitCommitMessages.types,
61
+ choices: typesChoices
62
+ },
63
+ {
64
+ name: 'scopes',
65
+ type: 'select',
66
+ message: gitCommitMessages.scopes,
67
+ choices: scopesChoices
68
+ },
69
+ {
70
+ name: 'description',
71
+ type: 'text',
72
+ message: gitCommitMessages.description
73
+ }
74
+ ]);
75
+ } catch {
76
+ process.exit(0);
77
+ } finally {
78
+ process.off('uncaughtException', errorHandler);
79
+ }
80
+
81
+ const breaking = result.description.startsWith('!') ? '!' : '';
82
+
83
+ const description = result.description.replace(/^!/, '').trim();
84
+
85
+ const commitMsg = `${result.types}(${result.scopes})${breaking}: ${description}`;
86
+
87
+ await execCommand('git', ['commit', '-m', commitMsg], { stdio: 'inherit' });
88
+ }
89
+
90
+ /** Git commit message verify */
91
+ export async function gitCommitVerify(lang: Lang = 'en-us', ignores: RegExp[] = []) {
92
+ const gitPath = await execCommand('git', ['rev-parse', '--show-toplevel']);
93
+
94
+ const gitMsgPath = path.join(gitPath, '.git', 'COMMIT_EDITMSG');
95
+
96
+ const commitMsg = readFileSync(gitMsgPath, 'utf8').trim();
97
+
98
+ if (ignores.some(regExp => regExp.test(commitMsg))) return;
99
+
100
+ const REG_EXP = /(?<type>[a-z]+)(?:\((?<scope>.+)\))?(?<breaking>!)?: (?<description>.+)/i;
101
+
102
+ if (!REG_EXP.test(commitMsg)) {
103
+ const errorMsg = locales[lang].gitCommitVerify;
104
+
105
+ throw new Error(errorMsg);
106
+ }
107
+ }
@@ -0,0 +1,6 @@
1
+ export * from './git-commit';
2
+ export * from './cleanup';
3
+ export * from './update-pkg';
4
+ export * from './changelog';
5
+ export * from './release';
6
+ export * from './router';
@@ -0,0 +1,12 @@
1
+ import { versionBump } from 'bumpp';
2
+
3
+ export async function release(execute = 'pnpm sa changelog', push = true) {
4
+ await versionBump({
5
+ files: ['**/package.json', '!**/node_modules'],
6
+ execute,
7
+ all: true,
8
+ tag: true,
9
+ commit: 'chore(projects): release v%s',
10
+ push
11
+ });
12
+ }
@@ -0,0 +1,90 @@
1
+ import process from 'node:process';
2
+ import path from 'node:path';
3
+ import { writeFile } from 'node:fs/promises';
4
+ import { existsSync, mkdirSync } from 'node:fs';
5
+ import { prompt } from 'enquirer';
6
+ import { green, red } from 'kolorist';
7
+
8
+ interface PromptObject {
9
+ routeName: string;
10
+ addRouteParams: boolean;
11
+ routeParams: string;
12
+ }
13
+
14
+ /** generate route */
15
+ export async function generateRoute() {
16
+ const result = await prompt<PromptObject>([
17
+ {
18
+ name: 'routeName',
19
+ type: 'text',
20
+ message: 'please enter route name',
21
+ initial: 'demo-route_child'
22
+ },
23
+ {
24
+ name: 'addRouteParams',
25
+ type: 'confirm',
26
+ message: 'add route params?',
27
+ initial: false
28
+ }
29
+ ]);
30
+
31
+ if (result.addRouteParams) {
32
+ const answers = await prompt<PromptObject>({
33
+ name: 'routeParams',
34
+ type: 'text',
35
+ message: 'please enter route params',
36
+ initial: 'id'
37
+ });
38
+
39
+ Object.assign(result, answers);
40
+ }
41
+
42
+ const PAGE_DIR_NAME_PATTERN = /^[\w-]+[0-9a-zA-Z]+$/;
43
+
44
+ if (!PAGE_DIR_NAME_PATTERN.test(result.routeName)) {
45
+ throw new Error(`${red('route name is invalid, it only allow letters, numbers, "-" or "_"')}.
46
+ For example:
47
+ (1) one level route: ${green('demo-route')}
48
+ (2) two level route: ${green('demo-route_child')}
49
+ (3) multi level route: ${green('demo-route_child_child')}
50
+ (4) group route: ${green('_ignore_demo-route')}'
51
+ `);
52
+ }
53
+
54
+ const PARAM_REG = /^\w+$/g;
55
+
56
+ if (result.routeParams && !PARAM_REG.test(result.routeParams)) {
57
+ throw new Error(red('route params is invalid, it only allow letters, numbers or "_".'));
58
+ }
59
+
60
+ const cwd = process.cwd();
61
+
62
+ const [dir, ...rest] = result.routeName.split('_') as string[];
63
+
64
+ let routeDir = path.join(cwd, 'src', 'views', dir);
65
+
66
+ if (rest.length) {
67
+ routeDir = path.join(routeDir, rest.join('_'));
68
+ }
69
+
70
+ if (!existsSync(routeDir)) {
71
+ mkdirSync(routeDir, { recursive: true });
72
+ } else {
73
+ throw new Error(red('route already exists'));
74
+ }
75
+
76
+ const fileName = result.routeParams ? `[${result.routeParams}].vue` : 'index.vue';
77
+
78
+ const vueTemplate = `<script setup lang="ts"></script>
79
+
80
+ <template>
81
+ <div>${result.routeName}</div>
82
+ </template>
83
+
84
+ <style scoped></style>
85
+ `;
86
+
87
+ const filePath = path.join(routeDir, fileName);
88
+
89
+ await writeFile(filePath, vueTemplate);
90
+ }
@@ -0,0 +1,5 @@
1
+ import { execCommand } from '../shared';
2
+
3
+ export async function updatePkg(args: string[] = ['--deep', '-u']) {
4
+ execCommand('npx', ['npm-check-updates', ...args], { stdio: 'inherit' });
5
+ }
@@ -0,0 +1,39 @@
1
+ import process from 'node:process';
2
+ import { loadConfig } from 'c12';
3
+ import type { CliOption } from '../types';
4
+
5
+ const defaultOptions: CliOption = {
6
+ cwd: process.cwd(),
7
+ cleanupDirs: [
8
+ 'dist',
9
+ '**/package-lock.json',
10
+ '**/yarn.lock',
11
+ '**/pnpm-lock.yaml',
12
+ '**/node_modules',
13
+ '!node_modules/**'
14
+ ],
15
+ ncuCommandArgs: ['--deep', '-u'],
16
+ changelogOptions: {},
17
+ gitCommitVerifyIgnores: [
18
+ /^((Merge pull request)|(Merge (.*?) into (.*?)|(Merge branch (.*?)))(?:\r?\n)*$)/m,
19
+ /^(Merge tag (.*?))(?:\r?\n)*$/m,
20
+ /^(R|r)evert (.*)/,
21
+ /^(amend|fixup|squash)!/,
22
+ /^(Merged (.*?)(in|into) (.*)|Merged PR (.*): (.*))/,
23
+ /^Merge remote-tracking branch(\s*)(.*)/,
24
+ /^Automatic merge(.*)/,
25
+ /^Auto-merged (.*?) into (.*)/
26
+ ]
27
+ };
28
+
29
+ export async function loadCliOptions(overrides?: Partial<CliOption>, cwd = process.cwd()) {
30
+ const { config } = await loadConfig<Partial<CliOption>>({
31
+ name: 'soybean',
32
+ defaults: defaultOptions,
33
+ overrides,
34
+ cwd,
35
+ packageJson: true
36
+ });
37
+
38
+ return config as CliOption;
39
+ }
@@ -0,0 +1,110 @@
1
+ import { cac } from 'cac';
2
+ import { blue, lightGreen } from 'kolorist';
3
+ // Developed collaboratively with vscode - 改动代码行数: 1行(阶段 1 五包合一:并入 @yugu-ui/shared 后 package.json 上移一级,修正版本号导入路径)
4
+ import { version } from '../../package.json';
5
+ import { cleanup, genChangelog, generateRoute, gitCommit, gitCommitVerify, release, updatePkg } from './commands';
6
+ import { loadCliOptions } from './config';
7
+ import type { Lang } from './locales';
8
+
9
+ type Command = 'cleanup' | 'update-pkg' | 'git-commit' | 'git-commit-verify' | 'changelog' | 'release' | 'gen-route';
10
+
11
+ type CommandAction<A extends object> = (args?: A) => Promise<void> | void;
12
+
13
+ type CommandWithAction<A extends object = object> = Record<Command, { desc: string; action: CommandAction<A> }>;
14
+
15
+ interface CommandArg {
16
+ /** Execute additional command after bumping and before git commit. Defaults to 'pnpm sa changelog' */
17
+ execute?: string;
18
+ /** Indicates whether to push the git commit and tag. Defaults to true */
19
+ push?: boolean;
20
+ /** Generate changelog by total tags */
21
+ total?: boolean;
22
+ /**
23
+ * The glob pattern of dirs to clean up
24
+ *
25
+ * If not set, it will use the default value
26
+ *
27
+ * Multiple values use "," to separate them
28
+ */
29
+ cleanupDir?: string;
30
+ /**
31
+ * display lang of cli
32
+ *
33
+ * @default 'en-us'
34
+ */
35
+ lang?: Lang;
36
+ }
37
+
38
+ export async function setupCli() {
39
+ const cliOptions = await loadCliOptions();
40
+
41
+ const cli = cac(blue('soybean-admin'));
42
+
43
+ cli
44
+ .version(lightGreen(version))
45
+ .option(
46
+ '-e, --execute [command]',
47
+ "Execute additional command after bumping and before git commit. Defaults to 'npx soy changelog'"
48
+ )
49
+ .option('-p, --push', 'Indicates whether to push the git commit and tag')
50
+ .option('-t, --total', 'Generate changelog by total tags')
51
+ .option(
52
+ '-c, --cleanupDir <dir>',
53
+ 'The glob pattern of dirs to cleanup, If not set, it will use the default value, Multiple values use "," to separate them'
54
+ )
55
+ .option('-l, --lang <lang>', 'display lang of cli', { default: 'en-us', type: [String] })
56
+ .help();
57
+
58
+ const commands: CommandWithAction<CommandArg> = {
59
+ cleanup: {
60
+ desc: 'delete dirs: node_modules, dist, etc.',
61
+ action: async () => {
62
+ await cleanup(cliOptions.cleanupDirs);
63
+ }
64
+ },
65
+ 'update-pkg': {
66
+ desc: 'update package.json dependencies versions',
67
+ action: async () => {
68
+ await updatePkg(cliOptions.ncuCommandArgs);
69
+ }
70
+ },
71
+ 'git-commit': {
72
+ desc: 'git commit, generate commit message which match Conventional Commits standard',
73
+ action: async args => {
74
+ await gitCommit(args?.lang);
75
+ }
76
+ },
77
+ 'git-commit-verify': {
78
+ desc: 'verify git commit message, make sure it match Conventional Commits standard',
79
+ action: async args => {
80
+ await gitCommitVerify(args?.lang, cliOptions.gitCommitVerifyIgnores);
81
+ }
82
+ },
83
+ changelog: {
84
+ desc: 'generate changelog',
85
+ action: async args => {
86
+ await genChangelog(cliOptions.changelogOptions, args?.total);
87
+ }
88
+ },
89
+ release: {
90
+ desc: 'release: update version, generate changelog, commit code',
91
+ action: async args => {
92
+ await release(args?.execute, args?.push);
93
+ }
94
+ },
95
+ 'gen-route': {
96
+ desc: 'generate route',
97
+ action: async () => {
98
+ await generateRoute();
99
+ }
100
+ }
101
+ };
102
+
103
+ for (const [command, { desc, action }] of Object.entries(commands)) {
104
+ cli.command(command, lightGreen(desc)).action(action);
105
+ }
106
+
107
+ cli.parse();
108
+ }
109
+
110
+ setupCli();
@@ -0,0 +1,84 @@
1
+ import { bgRed, green, red, yellow } from 'kolorist';
2
+
3
+ export type Lang = 'zh-cn' | 'en-us';
4
+
5
+ export const locales = {
6
+ 'zh-cn': {
7
+ gitCommitMessages: {
8
+ types: '请选择提交类型',
9
+ scopes: '请选择提交范围',
10
+ description: `请输入描述信息(${yellow('!')}开头表示破坏性改动`
11
+ },
12
+ gitCommitTypes: [
13
+ ['feat', '新功能'],
14
+ ['feat-wip', '开发中的功能,比如某功能的部分代码'],
15
+ ['fix', '修复Bug'],
16
+ ['docs', '只涉及文档更新'],
17
+ ['typo', '代码或文档勘误,比如错误拼写'],
18
+ ['style', '修改代码风格,不影响代码含义的变更'],
19
+ ['refactor', '代码重构,既不修复 bug 也不添加功能的代码变更'],
20
+ ['perf', '可提高性能的代码更改'],
21
+ ['optimize', '优化代码质量的代码更改'],
22
+ ['test', '添加缺失的测试或更正现有测试'],
23
+ ['build', '影响构建系统或外部依赖项的更改'],
24
+ ['ci', '对 CI 配置文件和脚本的更改'],
25
+ ['chore', '没有修改src或测试文件的其他变更'],
26
+ ['revert', '还原先前的提交']
27
+ ] as [string, string][],
28
+ gitCommitScopes: [
29
+ ['projects', '项目'],
30
+ ['packages', '包'],
31
+ ['components', '组件'],
32
+ ['hooks', '钩子函数'],
33
+ ['utils', '工具函数'],
34
+ ['types', 'TS类型声明'],
35
+ ['styles', '代码风格'],
36
+ ['deps', '项目依赖'],
37
+ ['release', '发布项目新版本'],
38
+ ['other', '其他的变更']
39
+ ] as [string, string][],
40
+ gitCommitNoStaged: `${bgRed(' 错误 ')} ${red('暂存区没有文件,请先使用 git add 添加文件后再提交!')}`,
41
+ gitCommitVerify: `${bgRed(' 错误 ')} ${red('git 提交信息必须符合 Conventional Commits 标准!')}\n\n${green(
42
+ '推荐使用命令 `pnpm commit` 生成符合 Conventional Commits 标准的提交信息。\n获取有关 Conventional Commits 的更多信息,请访问此链接: https://conventionalcommits.org'
43
+ )}`
44
+ },
45
+ 'en-us': {
46
+ gitCommitMessages: {
47
+ types: 'Please select a type',
48
+ scopes: 'Please select a scope',
49
+ description: `Please enter a description (add prefix ${yellow('!')} to indicate breaking change)`
50
+ },
51
+ gitCommitTypes: [
52
+ ['feat', 'A new feature'],
53
+ ['feat-wip', 'Features in development, such as partial code for a certain feature'],
54
+ ['fix', 'A bug fix'],
55
+ ['docs', 'Documentation only changes'],
56
+ ['typo', 'Code or document corrections, such as spelling errors'],
57
+ ['style', 'Changes that do not affect the meaning of the code'],
58
+ ['refactor', 'A code change that neither fixes a bug nor adds a feature'],
59
+ ['perf', 'A code change that improves performance'],
60
+ ['optimize', 'A code change that optimizes code quality'],
61
+ ['test', 'Adding missing tests or correcting existing tests'],
62
+ ['build', 'Changes that affect the build system or external dependencies'],
63
+ ['ci', 'Changes to our CI configuration files and scripts'],
64
+ ['chore', "Other changes that don't modify src or test files"],
65
+ ['revert', 'Reverts a previous commit']
66
+ ] as [string, string][],
67
+ gitCommitScopes: [
68
+ ['projects', 'project'],
69
+ ['packages', 'packages'],
70
+ ['components', 'components'],
71
+ ['hooks', 'hook functions'],
72
+ ['utils', 'utils functions'],
73
+ ['types', 'TS declaration'],
74
+ ['styles', 'style'],
75
+ ['deps', 'project dependencies'],
76
+ ['release', 'release project'],
77
+ ['other', 'other changes']
78
+ ] as [string, string][],
79
+ gitCommitNoStaged: `${bgRed(' ERROR ')} ${red('No files in staging area, please use git add to stage files first!')}`,
80
+ gitCommitVerify: `${bgRed(' ERROR ')} ${red('git commit message must match the Conventional Commits standard!')}\n\n${green(
81
+ 'Recommended to use the command `pnpm commit` to generate Conventional Commits compliant commit information.\nGet more info about Conventional Commits, follow this link: https://conventionalcommits.org'
82
+ )}`
83
+ }
84
+ } satisfies Record<Lang, Record<string, unknown>>;