@varlet/cli 2.1.0 → 2.2.0-alpha.1667670228109

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 (81) hide show
  1. package/README.en-US.md +7 -5
  2. package/README.md +7 -5
  3. package/lib/client/appType.d.ts +4 -4
  4. package/lib/client/appType.js +7 -7
  5. package/lib/client/index.d.ts +17 -17
  6. package/lib/client/index.js +106 -106
  7. package/lib/node/bin.d.ts +2 -2
  8. package/lib/node/bin.js +122 -122
  9. package/lib/node/commands/build.d.ts +1 -1
  10. package/lib/node/commands/build.js +15 -15
  11. package/lib/node/commands/changelog.d.ts +6 -6
  12. package/lib/node/commands/changelog.js +20 -20
  13. package/lib/node/commands/commitLint.d.ts +1 -1
  14. package/lib/node/commands/commitLint.js +16 -16
  15. package/lib/node/commands/compile.d.ts +7 -7
  16. package/lib/node/commands/compile.js +35 -35
  17. package/lib/node/commands/create.d.ts +8 -8
  18. package/lib/node/commands/create.js +91 -91
  19. package/lib/node/commands/dev.d.ts +5 -5
  20. package/lib/node/commands/dev.js +38 -38
  21. package/lib/node/commands/gen.d.ts +8 -8
  22. package/lib/node/commands/gen.js +68 -68
  23. package/lib/node/commands/jest.d.ts +8 -8
  24. package/lib/node/commands/jest.js +27 -27
  25. package/lib/node/commands/lint.d.ts +1 -1
  26. package/lib/node/commands/lint.js +42 -42
  27. package/lib/node/commands/preview.d.ts +1 -1
  28. package/lib/node/commands/preview.js +18 -18
  29. package/lib/node/commands/release.d.ts +5 -5
  30. package/lib/node/commands/release.js +146 -146
  31. package/lib/node/commands/vite.d.ts +3 -3
  32. package/lib/node/commands/vite.js +13 -13
  33. package/lib/node/compiler/compileModule.d.ts +5 -5
  34. package/lib/node/compiler/compileModule.js +74 -74
  35. package/lib/node/compiler/compileSFC.d.ts +2 -2
  36. package/lib/node/compiler/compileSFC.js +74 -74
  37. package/lib/node/compiler/compileScript.d.ts +17 -17
  38. package/lib/node/compiler/compileScript.js +95 -95
  39. package/lib/node/compiler/compileSiteEntry.d.ts +13 -13
  40. package/lib/node/compiler/compileSiteEntry.js +95 -95
  41. package/lib/node/compiler/compileStyle.d.ts +11 -11
  42. package/lib/node/compiler/compileStyle.js +39 -39
  43. package/lib/node/compiler/compileTemplateHighlight.d.ts +10 -10
  44. package/lib/node/compiler/compileTemplateHighlight.js +133 -133
  45. package/lib/node/compiler/compileTypes.d.ts +2 -2
  46. package/lib/node/compiler/compileTypes.js +30 -30
  47. package/lib/node/config/varlet.config.d.ts +45 -45
  48. package/lib/node/config/varlet.config.js +27 -27
  49. package/lib/node/config/varlet.default.config.d.ts +2 -2
  50. package/lib/node/config/varlet.default.config.js +264 -264
  51. package/lib/node/config/vite.config.d.ts +6 -6
  52. package/lib/node/config/vite.config.js +142 -142
  53. package/lib/node/index.d.ts +1 -1
  54. package/lib/node/index.js +1 -1
  55. package/lib/node/shared/constant.d.ts +42 -42
  56. package/lib/node/shared/constant.js +47 -47
  57. package/lib/node/shared/fsUtils.d.ts +13 -13
  58. package/lib/node/shared/fsUtils.js +48 -48
  59. package/lib/node/shared/logger.d.ts +8 -8
  60. package/lib/node/shared/logger.js +18 -18
  61. package/package.json +7 -7
  62. package/site/components/button/index.ts +10 -10
  63. package/site/components/cell/index.ts +10 -10
  64. package/site/components/code-example/codeExample.less +41 -41
  65. package/site/components/code-example/index.ts +10 -10
  66. package/site/components/context/zIndex.ts +20 -20
  67. package/site/components/icon/icon.less +26 -26
  68. package/site/components/icon/index.ts +10 -10
  69. package/site/components/icon/props.ts +24 -24
  70. package/site/components/loading/index.ts +10 -10
  71. package/site/components/progress/index.ts +10 -10
  72. package/site/components/snackbar/snackbar.less +135 -135
  73. package/site/components/styles/common.less +64 -64
  74. package/site/components/styles/elevation.less +126 -126
  75. package/site/components/styles/var.less +27 -27
  76. package/site/index.html +49 -49
  77. package/site/mobile/components/app-bar/index.ts +10 -10
  78. package/site/mobile/components/app-bar/props.ts +25 -25
  79. package/site/mobile.html +41 -41
  80. package/site/module.d.ts +5 -5
  81. package/site/tsconfig.json +11 -11
package/README.en-US.md CHANGED
@@ -34,8 +34,8 @@ you can start the development of the component library
34
34
 
35
35
  ### Configuration file
36
36
 
37
- The `varlet.config.js` in the project root directory is used to manage the specific details of the entire component library project.
38
- The default configuration can be viewed [varlet.default.config.ts](https://github.com/varletjs/varlet/blob/dev/packages/varlet-cli/src/config/varlet.default.config.ts)。
37
+ The `varlet.config.mjs` in the project root directory is used to manage the specific details of the entire component library project.
38
+ The default configuration can be viewed [varlet.default.config.ts](https://github.com/varletjs/varlet/blob/dev/packages/varlet-cli/src/node/config/varlet.default.config.ts)。
39
39
  Also refer to `@varlet/ui` [varlet.config.mjs](https://github.com/varletjs/varlet/blob/dev/packages/varlet-ui/varlet.config.mjs)
40
40
 
41
41
  | Parameter | Description | Type | Default |
@@ -215,10 +215,12 @@ import * as dayjs from 'dayjs'
215
215
  In the project, we embrace the first way of writing the `esmodule` module, and make the following configuration for adaptation
216
216
 
217
217
  ```js
218
- // varlet.config.js
219
- module.exports = {
218
+ // varlet.config.mjs
219
+ import { defineConfig } from '@varlet/cli'
220
+
221
+ export default defineConfig({
220
222
  moduleCompatible: {
221
223
  "import dayjs from 'dayjs/esm'\n": "import * as dayjs from 'dayjs'\n"
222
224
  }
223
- }
225
+ })
224
226
  ```
package/README.md CHANGED
@@ -32,8 +32,8 @@ varlet-cli gen
32
32
 
33
33
  ### 配置文件
34
34
 
35
- 项目根目录下的 `varlet.config.js` 用来管理整个组件库项目的具体细节。
36
- 默认配置可查阅 [varlet.default.config.ts](https://github.com/varletjs/varlet/blob/dev/packages/varlet-cli/src/config/varlet.default.config.ts)。
35
+ 项目根目录下的 `varlet.config.mjs` 用来管理整个组件库项目的具体细节。
36
+ 默认配置可查阅 [varlet.default.config.ts](https://github.com/varletjs/varlet/blob/dev/packages/varlet-cli/src/node/config/varlet.default.config.ts)。
37
37
  也可以参考 `@varlet/ui` 的 [varlet.config.mjs](https://github.com/varletjs/varlet/blob/dev/packages/varlet-ui/varlet.config.mjs)
38
38
 
39
39
  | 参数 | 说明 | 类型 | 默认值 |
@@ -213,10 +213,12 @@ import * as dayjs from 'dayjs'
213
213
  在项目中我们拥抱 `esmodule` 模块使用第一种写法,并做如下配置进行适配
214
214
 
215
215
  ```js
216
- // varlet.config.js
217
- module.exports = {
216
+ // varlet.config.mjs
217
+ import { defineConfig } from '@varlet/cli'
218
+
219
+ export default defineConfig({
218
220
  moduleCompatible: {
219
221
  "import dayjs from 'dayjs/esm'\n": "import * as dayjs from 'dayjs'\n"
220
222
  }
221
- }
223
+ })
222
224
  ```
@@ -1,4 +1,4 @@
1
- declare const _default: import("vue").DefineComponent<{}, () => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
2
- [key: string]: any;
3
- }>, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, import("vue").EmitsOptions, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<{} & {} & {}>, {}>;
4
- export default _default;
1
+ declare const _default: import("vue").DefineComponent<{}, () => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
2
+ [key: string]: any;
3
+ }>, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, import("vue").EmitsOptions, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<{} & {} & {}>, {}>;
4
+ export default _default;
@@ -1,7 +1,7 @@
1
- import { defineComponent, h } from 'vue';
2
- export default defineComponent({
3
- name: 'AppType',
4
- setup(props, { slots }) {
5
- return () => { var _a; return h('div', { class: 'app-type' }, [(_a = slots.default) === null || _a === void 0 ? void 0 : _a.call(slots)]); };
6
- },
7
- });
1
+ import { defineComponent, h } from 'vue';
2
+ export default defineComponent({
3
+ name: 'AppType',
4
+ setup(props, { slots }) {
5
+ return () => { var _a; return h('div', { class: 'app-type' }, [(_a = slots.default) === null || _a === void 0 ? void 0 : _a.call(slots)]); };
6
+ },
7
+ });
@@ -1,17 +1,17 @@
1
- import AppType from './appType';
2
- interface PCLocationInfo {
3
- language: string;
4
- menuName: string;
5
- }
6
- export declare type Theme = 'lightTheme' | 'darkTheme';
7
- export declare type StyleVars = Record<string, string>;
8
- export declare function StyleProvider(styleVars?: StyleVars | null): void;
9
- export declare function getPCLocationInfo(): PCLocationInfo;
10
- export declare function getBrowserTheme(): Theme;
11
- export declare function watchLang(cb: (lang: string) => void, platform?: 'pc' | 'mobile'): void;
12
- export declare function withSiteConfigNamespace(styleVars: Record<string, any>): StyleVars;
13
- export declare function watchPlatform(cb: (platform: string) => void): void;
14
- export declare function useRouteListener(cb: () => void): void;
15
- export declare function watchDarkMode(dark: StyleVars, cb?: (theme: Theme) => void): void;
16
- export declare function watchTheme(cb: (theme: Theme, from: 'pc' | 'mobile' | 'default' | 'playground') => void, shouldUnmount?: boolean): void;
17
- export { AppType };
1
+ import AppType from './appType';
2
+ interface PCLocationInfo {
3
+ language: string;
4
+ menuName: string;
5
+ }
6
+ export declare type Theme = 'lightTheme' | 'darkTheme';
7
+ export declare type StyleVars = Record<string, string>;
8
+ export declare function StyleProvider(styleVars?: StyleVars | null): void;
9
+ export declare function getPCLocationInfo(): PCLocationInfo;
10
+ export declare function getBrowserTheme(): Theme;
11
+ export declare function watchLang(cb: (lang: string) => void, platform?: 'pc' | 'mobile'): void;
12
+ export declare function withSiteConfigNamespace(styleVars: Record<string, any>): StyleVars;
13
+ export declare function watchPlatform(cb: (platform: string) => void): void;
14
+ export declare function useRouteListener(cb: () => void): void;
15
+ export declare function watchDarkMode(dark: StyleVars, cb?: (theme: Theme) => void): void;
16
+ export declare function watchTheme(cb: (theme: Theme, from: 'pc' | 'mobile' | 'default' | 'playground') => void, shouldUnmount?: boolean): void;
17
+ export { AppType };
@@ -1,106 +1,106 @@
1
- import config from '@config';
2
- import AppType from './appType';
3
- import { onMounted, onUnmounted } from 'vue';
4
- import { kebabCase } from '@varlet/shared';
5
- import { get } from 'lodash-es';
6
- const mountedVarKeys = [];
7
- function formatStyleVars(styleVars) {
8
- return Object.entries(styleVars !== null && styleVars !== void 0 ? styleVars : {}).reduce((styles, [key, value]) => {
9
- const cssVar = key.startsWith('--') ? key : `--${kebabCase(key)}`;
10
- styles[cssVar] = value;
11
- return styles;
12
- }, {});
13
- }
14
- export function StyleProvider(styleVars = {}) {
15
- mountedVarKeys.forEach((key) => document.documentElement.style.removeProperty(key));
16
- mountedVarKeys.length = 0;
17
- const styles = formatStyleVars(styleVars);
18
- Object.entries(styles).forEach(([key, value]) => {
19
- document.documentElement.style.setProperty(key, value);
20
- mountedVarKeys.push(key);
21
- });
22
- }
23
- export function getPCLocationInfo() {
24
- const [, language, menuName] = window.location.hash.split('/');
25
- return {
26
- language,
27
- menuName,
28
- };
29
- }
30
- function getHashSearch() {
31
- const { href } = window.location;
32
- const hashSearch = href.slice(href.indexOf('?'));
33
- return new URLSearchParams(hashSearch);
34
- }
35
- export function getBrowserTheme() {
36
- var _a;
37
- const themeKey = get(config, 'themeKey');
38
- const darkThemeConfig = get(config, 'darkTheme');
39
- if (!darkThemeConfig) {
40
- return 'lightTheme';
41
- }
42
- const storageTheme = window.localStorage.getItem(themeKey);
43
- if (!storageTheme) {
44
- const preferTheme = ((_a = window.matchMedia) === null || _a === void 0 ? void 0 : _a.call(window, '(prefers-color-scheme: dark)').matches) ? 'darkTheme' : 'lightTheme';
45
- window.localStorage.setItem(themeKey, preferTheme);
46
- return preferTheme;
47
- }
48
- return storageTheme;
49
- }
50
- export function watchLang(cb, platform = 'mobile') {
51
- const handleHashchange = () => {
52
- var _a;
53
- const language = platform === 'mobile' ? (_a = getHashSearch().get('language')) !== null && _a !== void 0 ? _a : 'zh-CN' : getPCLocationInfo().language;
54
- cb(language);
55
- };
56
- useRouteListener(handleHashchange);
57
- handleHashchange();
58
- }
59
- export function withSiteConfigNamespace(styleVars) {
60
- return Object.entries(styleVars).reduce((styleVars, [key, value]) => {
61
- styleVars[`--site-config-${key}`] = value;
62
- return styleVars;
63
- }, {});
64
- }
65
- export function watchPlatform(cb) {
66
- const handleHashchange = () => {
67
- var _a;
68
- const platform = (_a = getHashSearch().get('platform')) !== null && _a !== void 0 ? _a : 'mobile';
69
- cb(platform);
70
- };
71
- useRouteListener(handleHashchange);
72
- handleHashchange();
73
- }
74
- export function useRouteListener(cb) {
75
- onMounted(() => {
76
- window.addEventListener('hashchange', cb);
77
- window.addEventListener('popstate', cb);
78
- });
79
- onUnmounted(() => {
80
- window.removeEventListener('hashchange', cb);
81
- window.removeEventListener('popstate', cb);
82
- });
83
- }
84
- export function watchDarkMode(dark, cb) {
85
- watchTheme((theme) => {
86
- const siteStyleVars = withSiteConfigNamespace(get(config, theme, {}));
87
- StyleProvider(theme === 'darkTheme' ? Object.assign(Object.assign({}, siteStyleVars), dark) : siteStyleVars);
88
- cb === null || cb === void 0 ? void 0 : cb(theme);
89
- });
90
- }
91
- export function watchTheme(cb, shouldUnmount = true) {
92
- const handleThemeChange = (event) => {
93
- const { data } = event;
94
- if (data.action === 'theme-change') {
95
- cb(data.data, data.from);
96
- }
97
- };
98
- window.addEventListener('message', handleThemeChange);
99
- if (shouldUnmount) {
100
- onUnmounted(() => {
101
- window.removeEventListener('message', handleThemeChange);
102
- });
103
- }
104
- cb(getBrowserTheme(), 'default');
105
- }
106
- export { AppType };
1
+ import config from '@config';
2
+ import AppType from './appType';
3
+ import { onMounted, onUnmounted } from 'vue';
4
+ import { kebabCase } from '@varlet/shared';
5
+ import { get } from 'lodash-es';
6
+ const mountedVarKeys = [];
7
+ function formatStyleVars(styleVars) {
8
+ return Object.entries(styleVars !== null && styleVars !== void 0 ? styleVars : {}).reduce((styles, [key, value]) => {
9
+ const cssVar = key.startsWith('--') ? key : `--${kebabCase(key)}`;
10
+ styles[cssVar] = value;
11
+ return styles;
12
+ }, {});
13
+ }
14
+ export function StyleProvider(styleVars = {}) {
15
+ mountedVarKeys.forEach((key) => document.documentElement.style.removeProperty(key));
16
+ mountedVarKeys.length = 0;
17
+ const styles = formatStyleVars(styleVars);
18
+ Object.entries(styles).forEach(([key, value]) => {
19
+ document.documentElement.style.setProperty(key, value);
20
+ mountedVarKeys.push(key);
21
+ });
22
+ }
23
+ export function getPCLocationInfo() {
24
+ const [, language, menuName] = window.location.hash.split('/');
25
+ return {
26
+ language,
27
+ menuName,
28
+ };
29
+ }
30
+ function getHashSearch() {
31
+ const { href } = window.location;
32
+ const hashSearch = href.slice(href.indexOf('?'));
33
+ return new URLSearchParams(hashSearch);
34
+ }
35
+ export function getBrowserTheme() {
36
+ var _a;
37
+ const themeKey = get(config, 'themeKey');
38
+ const darkThemeConfig = get(config, 'darkTheme');
39
+ if (!darkThemeConfig) {
40
+ return 'lightTheme';
41
+ }
42
+ const storageTheme = window.localStorage.getItem(themeKey);
43
+ if (!storageTheme) {
44
+ const preferTheme = ((_a = window.matchMedia) === null || _a === void 0 ? void 0 : _a.call(window, '(prefers-color-scheme: dark)').matches) ? 'darkTheme' : 'lightTheme';
45
+ window.localStorage.setItem(themeKey, preferTheme);
46
+ return preferTheme;
47
+ }
48
+ return storageTheme;
49
+ }
50
+ export function watchLang(cb, platform = 'mobile') {
51
+ const handleHashchange = () => {
52
+ var _a;
53
+ const language = platform === 'mobile' ? (_a = getHashSearch().get('language')) !== null && _a !== void 0 ? _a : 'zh-CN' : getPCLocationInfo().language;
54
+ cb(language);
55
+ };
56
+ useRouteListener(handleHashchange);
57
+ handleHashchange();
58
+ }
59
+ export function withSiteConfigNamespace(styleVars) {
60
+ return Object.entries(styleVars).reduce((styleVars, [key, value]) => {
61
+ styleVars[`--site-config-${key}`] = value;
62
+ return styleVars;
63
+ }, {});
64
+ }
65
+ export function watchPlatform(cb) {
66
+ const handleHashchange = () => {
67
+ var _a;
68
+ const platform = (_a = getHashSearch().get('platform')) !== null && _a !== void 0 ? _a : 'mobile';
69
+ cb(platform);
70
+ };
71
+ useRouteListener(handleHashchange);
72
+ handleHashchange();
73
+ }
74
+ export function useRouteListener(cb) {
75
+ onMounted(() => {
76
+ window.addEventListener('hashchange', cb);
77
+ window.addEventListener('popstate', cb);
78
+ });
79
+ onUnmounted(() => {
80
+ window.removeEventListener('hashchange', cb);
81
+ window.removeEventListener('popstate', cb);
82
+ });
83
+ }
84
+ export function watchDarkMode(dark, cb) {
85
+ watchTheme((theme) => {
86
+ const siteStyleVars = withSiteConfigNamespace(get(config, theme, {}));
87
+ StyleProvider(theme === 'darkTheme' ? Object.assign(Object.assign({}, siteStyleVars), dark) : siteStyleVars);
88
+ cb === null || cb === void 0 ? void 0 : cb(theme);
89
+ });
90
+ }
91
+ export function watchTheme(cb, shouldUnmount = true) {
92
+ const handleThemeChange = (event) => {
93
+ const { data } = event;
94
+ if (data.action === 'theme-change') {
95
+ cb(data.data, data.from);
96
+ }
97
+ };
98
+ window.addEventListener('message', handleThemeChange);
99
+ if (shouldUnmount) {
100
+ onUnmounted(() => {
101
+ window.removeEventListener('message', handleThemeChange);
102
+ });
103
+ }
104
+ cb(getBrowserTheme(), 'default');
105
+ }
106
+ export { AppType };
package/lib/node/bin.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- #!/usr/bin/env node
2
- export {};
1
+ #!/usr/bin/env node
2
+ export {};
package/lib/node/bin.js CHANGED
@@ -1,122 +1,122 @@
1
- #!/usr/bin/env node
2
- import fse from 'fs-extra';
3
- import { Command } from 'commander';
4
- import { CLI_PACKAGE_JSON } from './shared/constant.js';
5
- const { readJSONSync } = fse;
6
- const program = new Command();
7
- program.version(`varlet-cli ${readJSONSync(CLI_PACKAGE_JSON).version}`).usage('<command> [options]');
8
- program
9
- .command('dev')
10
- .option('-f --force', 'Force dep pre-optimization regardless of whether deps have changed')
11
- .description('Run varlet development environment')
12
- .action(async (options) => {
13
- const { dev } = await import('./commands/dev.js');
14
- return dev(options);
15
- });
16
- program
17
- .command('build')
18
- .description('Build varlet site for production')
19
- .action(async () => {
20
- const { build } = await import('./commands/build.js');
21
- return build();
22
- });
23
- program
24
- .command('build:vite')
25
- .description('Use vite build app for production')
26
- .action(async () => {
27
- const { vite } = await import('./commands/vite.js');
28
- return vite('build');
29
- });
30
- program
31
- .command('dev:vite')
32
- .description('Use vite start server for development')
33
- .action(async () => {
34
- const { vite } = await import('./commands/vite.js');
35
- return vite('dev');
36
- });
37
- program
38
- .command('preview')
39
- .description('Preview varlet site for production')
40
- .action(async () => {
41
- const { preview } = await import('./commands/preview.js');
42
- return preview();
43
- });
44
- program
45
- .command('compile')
46
- .description('Compile varlet components library code')
47
- .option('-nu, --noUmd', 'Do not compile umd target code')
48
- .action(async (options) => {
49
- const { compile } = await import('./commands/compile.js');
50
- return compile(options);
51
- });
52
- program
53
- .command('lint')
54
- .description('Lint code')
55
- .action(async () => {
56
- const { lint } = await import('./commands/lint.js');
57
- return lint();
58
- });
59
- program
60
- .command('create')
61
- .description('Create a component directory')
62
- .option('-n, --name <componentName>', 'Component name')
63
- .option('-s, --sfc', 'Generate files in sfc format')
64
- .option('-t, --tsx', 'Generate files in tsx format')
65
- .option('-l, --locale', 'Generator internationalized files')
66
- .action(async (options) => {
67
- const { create } = await import('./commands/create.js');
68
- return create(options);
69
- });
70
- program
71
- .command('jest')
72
- .description('Run Jest in work directory')
73
- .option('-w, --watch', 'Watch files for changes and rerun tests related to changed files')
74
- .option('-wa, --watchAll', 'Watch files for changes and rerun all tests when something changes')
75
- .option('-c, --component <componentName>', 'Test a specific component')
76
- .option('-cc --clearCache', 'Clear test cache')
77
- .action(async (option) => {
78
- const { jest } = await import('./commands/jest.js');
79
- return jest(option);
80
- });
81
- program
82
- .command('gen')
83
- .description('Generate cli application')
84
- .option('-n, --name <applicationName>', 'Application name')
85
- .option('-s, --sfc', 'Generate files in sfc format')
86
- .option('-t, --tsx', 'Generate files in tsx format')
87
- .option('-l, --locale', 'Generator internationalized files')
88
- .action(async (option) => {
89
- const { gen } = await import('./commands/gen.js');
90
- return gen(option);
91
- });
92
- program
93
- .command('changelog')
94
- .option('-rc --releaseCount <releaseCount>', 'Release count')
95
- .option('-f --file <file>', 'Changelog filename')
96
- .description('Generate changelog')
97
- .action(async (option) => {
98
- const { changelog } = await import('./commands/changelog.js');
99
- return changelog(option);
100
- });
101
- program
102
- .command('release')
103
- .option('-r --remote <remote>', 'Remote name')
104
- .description('Release all packages and generate changelogs')
105
- .action(async (option) => {
106
- const { release } = await import('./commands/release.js');
107
- return release(option);
108
- });
109
- program
110
- .command('commit-lint <gitParams>')
111
- .description('Lint commit message')
112
- .action(async (option) => {
113
- const { commitLint } = await import('./commands/commitLint.js');
114
- return commitLint(option);
115
- });
116
- program.on('command:*', async ([cmd]) => {
117
- const { default: logger } = await import('./shared/logger.js');
118
- program.outputHelp();
119
- logger.error(`\nUnknown command ${cmd}.\n`);
120
- process.exitCode = 1;
121
- });
122
- program.parse();
1
+ #!/usr/bin/env node
2
+ import fse from 'fs-extra';
3
+ import { Command } from 'commander';
4
+ import { CLI_PACKAGE_JSON } from './shared/constant.js';
5
+ const { readJSONSync } = fse;
6
+ const program = new Command();
7
+ program.version(`varlet-cli ${readJSONSync(CLI_PACKAGE_JSON).version}`).usage('<command> [options]');
8
+ program
9
+ .command('dev')
10
+ .option('-f --force', 'Force dep pre-optimization regardless of whether deps have changed')
11
+ .description('Run varlet development environment')
12
+ .action(async (options) => {
13
+ const { dev } = await import('./commands/dev.js');
14
+ return dev(options);
15
+ });
16
+ program
17
+ .command('build')
18
+ .description('Build varlet site for production')
19
+ .action(async () => {
20
+ const { build } = await import('./commands/build.js');
21
+ return build();
22
+ });
23
+ program
24
+ .command('build:vite')
25
+ .description('Use vite build app for production')
26
+ .action(async () => {
27
+ const { vite } = await import('./commands/vite.js');
28
+ return vite('build');
29
+ });
30
+ program
31
+ .command('dev:vite')
32
+ .description('Use vite start server for development')
33
+ .action(async () => {
34
+ const { vite } = await import('./commands/vite.js');
35
+ return vite('dev');
36
+ });
37
+ program
38
+ .command('preview')
39
+ .description('Preview varlet site for production')
40
+ .action(async () => {
41
+ const { preview } = await import('./commands/preview.js');
42
+ return preview();
43
+ });
44
+ program
45
+ .command('compile')
46
+ .description('Compile varlet components library code')
47
+ .option('-nu, --noUmd', 'Do not compile umd target code')
48
+ .action(async (options) => {
49
+ const { compile } = await import('./commands/compile.js');
50
+ return compile(options);
51
+ });
52
+ program
53
+ .command('lint')
54
+ .description('Lint code')
55
+ .action(async () => {
56
+ const { lint } = await import('./commands/lint.js');
57
+ return lint();
58
+ });
59
+ program
60
+ .command('create')
61
+ .description('Create a component directory')
62
+ .option('-n, --name <componentName>', 'Component name')
63
+ .option('-s, --sfc', 'Generate files in sfc format')
64
+ .option('-t, --tsx', 'Generate files in tsx format')
65
+ .option('-l, --locale', 'Generator internationalized files')
66
+ .action(async (options) => {
67
+ const { create } = await import('./commands/create.js');
68
+ return create(options);
69
+ });
70
+ program
71
+ .command('jest')
72
+ .description('Run Jest in work directory')
73
+ .option('-w, --watch', 'Watch files for changes and rerun tests related to changed files')
74
+ .option('-wa, --watchAll', 'Watch files for changes and rerun all tests when something changes')
75
+ .option('-c, --component <componentName>', 'Test a specific component')
76
+ .option('-cc --clearCache', 'Clear test cache')
77
+ .action(async (option) => {
78
+ const { jest } = await import('./commands/jest.js');
79
+ return jest(option);
80
+ });
81
+ program
82
+ .command('gen')
83
+ .description('Generate cli application')
84
+ .option('-n, --name <applicationName>', 'Application name')
85
+ .option('-s, --sfc', 'Generate files in sfc format')
86
+ .option('-t, --tsx', 'Generate files in tsx format')
87
+ .option('-l, --locale', 'Generator internationalized files')
88
+ .action(async (option) => {
89
+ const { gen } = await import('./commands/gen.js');
90
+ return gen(option);
91
+ });
92
+ program
93
+ .command('changelog')
94
+ .option('-rc --releaseCount <releaseCount>', 'Release count')
95
+ .option('-f --file <file>', 'Changelog filename')
96
+ .description('Generate changelog')
97
+ .action(async (option) => {
98
+ const { changelog } = await import('./commands/changelog.js');
99
+ return changelog(option);
100
+ });
101
+ program
102
+ .command('release')
103
+ .option('-r --remote <remote>', 'Remote name')
104
+ .description('Release all packages and generate changelogs')
105
+ .action(async (option) => {
106
+ const { release } = await import('./commands/release.js');
107
+ return release(option);
108
+ });
109
+ program
110
+ .command('commit-lint <gitParams>')
111
+ .description('Lint commit message')
112
+ .action(async (option) => {
113
+ const { commitLint } = await import('./commands/commitLint.js');
114
+ return commitLint(option);
115
+ });
116
+ program.on('command:*', async ([cmd]) => {
117
+ const { default: logger } = await import('./shared/logger.js');
118
+ program.outputHelp();
119
+ logger.error(`\nUnknown command ${cmd}.\n`);
120
+ process.exitCode = 1;
121
+ });
122
+ program.parse();
@@ -1 +1 @@
1
- export declare function build(): Promise<void>;
1
+ export declare function build(): Promise<void>;
@@ -1,15 +1,15 @@
1
- import fse from 'fs-extra';
2
- import { SRC_DIR } from '../shared/constant.js';
3
- import { build as buildVite } from 'vite';
4
- import { getBuildConfig } from '../config/vite.config.js';
5
- import { getVarletConfig } from '../config/varlet.config.js';
6
- import { buildSiteEntry } from '../compiler/compileSiteEntry.js';
7
- const { ensureDirSync } = fse;
8
- export async function build() {
9
- process.env.NODE_ENV = 'production';
10
- ensureDirSync(SRC_DIR);
11
- await buildSiteEntry();
12
- const varletConfig = await getVarletConfig();
13
- const buildConfig = getBuildConfig(varletConfig);
14
- await buildVite(buildConfig);
15
- }
1
+ import fse from 'fs-extra';
2
+ import { SRC_DIR } from '../shared/constant.js';
3
+ import { build as buildVite } from 'vite';
4
+ import { getBuildConfig } from '../config/vite.config.js';
5
+ import { getVarletConfig } from '../config/varlet.config.js';
6
+ import { buildSiteEntry } from '../compiler/compileSiteEntry.js';
7
+ const { ensureDirSync } = fse;
8
+ export async function build() {
9
+ process.env.NODE_ENV = 'production';
10
+ ensureDirSync(SRC_DIR);
11
+ await buildSiteEntry();
12
+ const varletConfig = await getVarletConfig();
13
+ const buildConfig = getBuildConfig(varletConfig);
14
+ await buildVite(buildConfig);
15
+ }
@@ -1,6 +1,6 @@
1
- interface ChangelogCommandOptions {
2
- file?: string;
3
- releaseCount?: number;
4
- }
5
- export declare function changelog({ releaseCount, file }?: ChangelogCommandOptions): Promise<void>;
6
- export {};
1
+ interface ChangelogCommandOptions {
2
+ file?: string;
3
+ releaseCount?: number;
4
+ }
5
+ export declare function changelog({ releaseCount, file }?: ChangelogCommandOptions): Promise<void>;
6
+ export {};