@varlet/cli 2.0.6 → 2.1.0-alpha.1666877950844

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 (143) hide show
  1. package/README.en-US.md +2 -2
  2. package/README.md +2 -2
  3. package/cjs/babel.config.cjs +29 -0
  4. package/cjs/babel.sfc.transform.cjs +18 -0
  5. package/cjs/jest.config.cjs +33 -0
  6. package/cjs/jest.media.mock.cjs +1 -0
  7. package/cjs/jest.style.mock.cjs +1 -0
  8. package/client.d.ts +1 -0
  9. package/client.js +1 -0
  10. package/lib/client/appType.d.ts +4 -0
  11. package/lib/client/appType.js +7 -0
  12. package/lib/client/index.d.ts +17 -0
  13. package/lib/client/index.js +106 -0
  14. package/lib/{bin.d.ts → node/bin.d.ts} +2 -2
  15. package/lib/node/bin.js +122 -0
  16. package/lib/{commands → node/commands}/build.d.ts +1 -1
  17. package/lib/node/commands/build.js +15 -0
  18. package/lib/{commands → node/commands}/changelog.d.ts +6 -6
  19. package/lib/node/commands/changelog.js +20 -0
  20. package/lib/{commands → node/commands}/commitLint.d.ts +1 -1
  21. package/lib/node/commands/commitLint.js +45 -0
  22. package/lib/{commands → node/commands}/compile.d.ts +7 -7
  23. package/lib/node/commands/compile.js +35 -0
  24. package/lib/{commands → node/commands}/create.d.ts +8 -8
  25. package/lib/node/commands/create.js +91 -0
  26. package/lib/{commands → node/commands}/dev.d.ts +5 -5
  27. package/lib/node/commands/dev.js +38 -0
  28. package/lib/{commands → node/commands}/gen.d.ts +8 -8
  29. package/lib/node/commands/gen.js +75 -0
  30. package/lib/{commands → node/commands}/jest.d.ts +8 -8
  31. package/lib/node/commands/jest.js +27 -0
  32. package/lib/{commands → node/commands}/lint.d.ts +1 -1
  33. package/lib/node/commands/lint.js +41 -0
  34. package/lib/{commands → node/commands}/preview.d.ts +1 -1
  35. package/lib/node/commands/preview.js +18 -0
  36. package/lib/{commands → node/commands}/release.d.ts +5 -5
  37. package/lib/node/commands/release.js +146 -0
  38. package/lib/{commands → node/commands}/vite.d.ts +3 -3
  39. package/lib/node/commands/vite.js +13 -0
  40. package/lib/{compiler → node/compiler}/compileModule.d.ts +5 -5
  41. package/lib/node/compiler/compileModule.js +74 -0
  42. package/lib/{compiler → node/compiler}/compileSFC.d.ts +2 -2
  43. package/lib/node/compiler/compileSFC.js +79 -0
  44. package/lib/{compiler → node/compiler}/compileScript.d.ts +17 -17
  45. package/lib/node/compiler/compileScript.js +141 -0
  46. package/lib/{compiler → node/compiler}/compileSiteEntry.d.ts +13 -13
  47. package/lib/node/compiler/compileSiteEntry.js +128 -0
  48. package/lib/{compiler → node/compiler}/compileStyle.d.ts +11 -11
  49. package/lib/node/compiler/compileStyle.js +39 -0
  50. package/lib/{compiler → node/compiler}/compileTemplateHighlight.d.ts +10 -10
  51. package/lib/node/compiler/compileTemplateHighlight.js +133 -0
  52. package/lib/{compiler → node/compiler}/compileTypes.d.ts +2 -2
  53. package/lib/node/compiler/compileTypes.js +45 -0
  54. package/lib/{config → node/config}/varlet.config.d.ts +45 -44
  55. package/lib/node/config/varlet.config.js +27 -0
  56. package/lib/node/config/varlet.default.config.d.ts +2 -0
  57. package/lib/node/config/varlet.default.config.js +264 -0
  58. package/lib/node/config/vite.config.d.ts +6 -0
  59. package/lib/node/config/vite.config.js +144 -0
  60. package/lib/node/index.d.ts +1 -0
  61. package/lib/node/index.js +1 -0
  62. package/lib/{shared → node/shared}/constant.d.ts +42 -43
  63. package/lib/node/shared/constant.js +47 -0
  64. package/lib/{shared → node/shared}/fsUtils.d.ts +13 -12
  65. package/lib/node/shared/fsUtils.js +48 -0
  66. package/lib/{shared → node/shared}/logger.d.ts +8 -8
  67. package/lib/node/shared/logger.js +18 -0
  68. package/package.json +22 -19
  69. package/{preset.js → preset.cjs} +1 -1
  70. package/site/components/button/index.ts +10 -10
  71. package/site/components/cell/index.ts +10 -10
  72. package/site/components/code-example/CodeExample.vue +2 -1
  73. package/site/components/code-example/codeExample.less +41 -41
  74. package/site/components/code-example/index.ts +10 -10
  75. package/site/components/context/zIndex.ts +20 -20
  76. package/site/components/icon/icon.less +26 -26
  77. package/site/components/icon/index.ts +10 -10
  78. package/site/components/icon/props.ts +24 -24
  79. package/site/components/loading/index.ts +10 -10
  80. package/site/components/progress/index.ts +10 -10
  81. package/site/components/snackbar/snackbar.less +135 -135
  82. package/site/components/styles/common.less +64 -64
  83. package/site/components/styles/elevation.less +126 -126
  84. package/site/components/styles/var.less +27 -27
  85. package/site/components/utils/components.ts +1 -4
  86. package/site/components/utils/elements.ts +1 -1
  87. package/site/index.html +49 -49
  88. package/site/mobile/App.vue +27 -26
  89. package/site/mobile/components/AppHome.vue +2 -1
  90. package/site/mobile/components/app-bar/index.ts +10 -10
  91. package/site/mobile/components/app-bar/props.ts +25 -25
  92. package/site/mobile.html +41 -41
  93. package/site/module.d.ts +5 -5
  94. package/site/pc/App.vue +2 -1
  95. package/site/pc/Layout.vue +2 -1
  96. package/site/pc/components/AppHeader.vue +4 -2
  97. package/site/pc/pages/index/index.vue +8 -4
  98. package/site/tsconfig.json +11 -11
  99. package/site/useProgress.ts +2 -1
  100. package/site/utils.ts +6 -137
  101. package/template/generators/config/default/base/{varlet.config.js → varlet.config.mjs} +2 -2
  102. package/template/generators/config/i18n/base/{varlet.config.js → varlet.config.mjs} +2 -2
  103. package/tsconfig.json +2 -9
  104. package/lib/bin.js +0 -102
  105. package/lib/commands/build.js +0 -67
  106. package/lib/commands/changelog.js +0 -27
  107. package/lib/commands/commitLint.js +0 -21
  108. package/lib/commands/compile.js +0 -119
  109. package/lib/commands/create.js +0 -166
  110. package/lib/commands/dev.js +0 -123
  111. package/lib/commands/gen.js +0 -138
  112. package/lib/commands/jest.js +0 -85
  113. package/lib/commands/lint.js +0 -123
  114. package/lib/commands/preview.js +0 -74
  115. package/lib/commands/release.js +0 -305
  116. package/lib/commands/vite.js +0 -69
  117. package/lib/compiler/compileModule.js +0 -190
  118. package/lib/compiler/compileSFC.js +0 -135
  119. package/lib/compiler/compileScript.js +0 -194
  120. package/lib/compiler/compileSiteEntry.js +0 -237
  121. package/lib/compiler/compileStyle.js +0 -91
  122. package/lib/compiler/compileTemplateHighlight.js +0 -193
  123. package/lib/compiler/compileTypes.js +0 -85
  124. package/lib/config/babel.config.d.ts +0 -2
  125. package/lib/config/babel.config.js +0 -31
  126. package/lib/config/babel.sfc.transform.d.ts +0 -1
  127. package/lib/config/babel.sfc.transform.js +0 -18
  128. package/lib/config/jest.config.d.ts +0 -1
  129. package/lib/config/jest.config.js +0 -37
  130. package/lib/config/jest.media.mock.d.ts +0 -0
  131. package/lib/config/jest.media.mock.js +0 -2
  132. package/lib/config/jest.style.mock.d.ts +0 -0
  133. package/lib/config/jest.style.mock.js +0 -2
  134. package/lib/config/varlet.config.js +0 -35
  135. package/lib/config/vite.config.d.ts +0 -5
  136. package/lib/config/vite.config.js +0 -162
  137. package/lib/index.d.ts +0 -1
  138. package/lib/index.js +0 -5
  139. package/lib/shared/constant.js +0 -50
  140. package/lib/shared/fsUtils.js +0 -108
  141. package/lib/shared/logger.js +0 -23
  142. package/site/mobile/components/AppType.vue +0 -22
  143. package/varlet.default.config.js +0 -267
package/README.en-US.md CHANGED
@@ -35,8 +35,8 @@ you can start the development of the component library
35
35
  ### Configuration file
36
36
 
37
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.js](https://github.com/varletjs/varlet/blob/dev/packages/varlet-cli/varlet.default.config.js)。
39
- Also refer to `@varlet/ui` [varlet.config.js](https://github.com/varletjs/varlet/blob/dev/packages/varlet-ui/varlet.config.js)
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)。
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 |
42
42
  | -- | -------------- | -------- | ---------- |
package/README.md CHANGED
@@ -33,8 +33,8 @@ varlet-cli gen
33
33
  ### 配置文件
34
34
 
35
35
  项目根目录下的 `varlet.config.js` 用来管理整个组件库项目的具体细节。
36
- 默认配置可查阅 [varlet.default.config.js](https://github.com/varletjs/varlet/blob/dev/packages/varlet-cli/varlet.default.config.js)。
37
- 也可以参考 `@varlet/ui` 的 [varlet.config.js](https://github.com/varletjs/varlet/blob/dev/packages/varlet-ui/varlet.config.js)
36
+ 默认配置可查阅 [varlet.default.config.ts](https://github.com/varletjs/varlet/blob/dev/packages/varlet-cli/src/config/varlet.default.config.ts)。
37
+ 也可以参考 `@varlet/ui` 的 [varlet.config.mjs](https://github.com/varletjs/varlet/blob/dev/packages/varlet-ui/varlet.config.mjs)
38
38
 
39
39
  | 参数 | 说明 | 类型 | 默认值 |
40
40
  | ----- | -------------- | -------- | ---------- |
@@ -0,0 +1,29 @@
1
+ module.exports = (api, options) => {
2
+ if (api) {
3
+ api.cache.never()
4
+ }
5
+
6
+ const isCommonJS = process.env.NODE_ENV === 'test' || process.env.BABEL_MODULE === 'commonjs'
7
+
8
+ return {
9
+ presets: [
10
+ [
11
+ require.resolve('@babel/preset-env'),
12
+ {
13
+ modules: isCommonJS ? 'commonjs' : false,
14
+ loose: options.loose,
15
+ },
16
+ ],
17
+ require.resolve('@babel/preset-typescript'),
18
+ require('./babel.sfc.transform.cjs'),
19
+ ],
20
+ plugins: [
21
+ [
22
+ require.resolve('@vue/babel-plugin-jsx'),
23
+ {
24
+ enableObjectSlots: options.enableObjectSlots,
25
+ },
26
+ ],
27
+ ],
28
+ }
29
+ }
@@ -0,0 +1,18 @@
1
+ const { readFileSync } = require('fs')
2
+ const { declare } = require('@babel/helper-plugin-utils')
3
+
4
+ module.exports = declare(() => ({
5
+ overrides: [
6
+ {
7
+ test: (file) => {
8
+ if (/\.vue$/.test(file)) {
9
+ const code = readFileSync(file, 'utf8')
10
+ return code.includes('lang="ts"') || code.includes("lang='ts'")
11
+ }
12
+
13
+ return false
14
+ },
15
+ plugins: ['@babel/plugin-transform-typescript'],
16
+ },
17
+ ],
18
+ }))
@@ -0,0 +1,33 @@
1
+ const { resolve } = require('path')
2
+ const { pathExistsSync } = require('fs-extra')
3
+
4
+ const JEST_MEDIA_MOCK = resolve(__dirname, 'jest.media.mock.cjs')
5
+ const JEST_STYLE_MOCK = resolve(__dirname, 'jest.style.mock.cjs')
6
+
7
+ function getRootConfig() {
8
+ const file = resolve(process.cwd(), 'jest.config.js')
9
+
10
+ if (pathExistsSync(file)) {
11
+ delete require.cache[require.resolve(file)]
12
+ return require(file)
13
+ }
14
+
15
+ return {}
16
+ }
17
+
18
+ module.exports = {
19
+ moduleNameMapper: {
20
+ '^@config$': '<rootDir>/.varlet/site.config.json',
21
+ '\\.(css|less)$': JEST_STYLE_MOCK,
22
+ '\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$': JEST_MEDIA_MOCK,
23
+ },
24
+ transform: {
25
+ '\\.(vue)$': 'vue-jest',
26
+ '\\.(js|jsx|ts|tsx)$': 'babel-jest',
27
+ },
28
+ collectCoverage: true,
29
+ collectCoverageFrom: ['src/**/*.{js,jsx,ts,tsx,vue}', `!**/example/**`, `!**/docs/**`, `!**/__tests__/**`],
30
+ moduleFileExtensions: ['js', 'jsx', 'ts', 'tsx', 'vue'],
31
+ transformIgnorePatterns: [],
32
+ ...getRootConfig(),
33
+ }
@@ -0,0 +1 @@
1
+ module.exports = {}
@@ -0,0 +1 @@
1
+ module.exports = {}
package/client.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './lib/client/index'
package/client.js ADDED
@@ -0,0 +1 @@
1
+ export * from './lib/client/index.js'
@@ -0,0 +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;
@@ -0,0 +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
+ });
@@ -0,0 +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 };
@@ -0,0 +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,2 +1,2 @@
1
- #!/usr/bin/env node
2
- export {};
1
+ #!/usr/bin/env node
2
+ export {};
@@ -0,0 +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 +1 @@
1
- export declare function build(): Promise<void>;
1
+ export declare function build(): Promise<void>;
@@ -0,0 +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,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 {};
@@ -0,0 +1,20 @@
1
+ import ora from 'ora';
2
+ import conventionalChangelog from 'conventional-changelog';
3
+ import fse from 'fs-extra';
4
+ import { resolve as resolvePath } from 'path';
5
+ import { CWD } from '../shared/constant.js';
6
+ const { createWriteStream } = fse;
7
+ export function changelog({ releaseCount = 0, file = 'CHANGELOG.md' } = {}) {
8
+ const s = ora().start(`Generating changelog`);
9
+ return new Promise((resolve) => {
10
+ conventionalChangelog({
11
+ preset: 'angular',
12
+ releaseCount,
13
+ })
14
+ .pipe(createWriteStream(resolvePath(CWD, file)))
15
+ .on('close', () => {
16
+ s.succeed(`Changelog generated success!`);
17
+ resolve();
18
+ });
19
+ });
20
+ }
@@ -1 +1 @@
1
- export declare function commitLint(gitParams: string): void;
1
+ export declare function commitLint(gitParams: string): void;
@@ -0,0 +1,45 @@
1
+ import logger from '../shared/logger.js';
2
+ import semver from 'semver';
3
+ import fse from 'fs-extra';
4
+ const { readFileSync } = fse;
5
+ function isVersion(message) {
6
+ return message.startsWith('v') && semver.valid(message.slice(1));
7
+ }
8
+ export function commitLint(gitParams) {
9
+ const message = readFileSync(gitParams, 'utf-8').trim();
10
+ const COMMIT_MESSAGE_RE = /^(revert|fix|feat|docs|perf|test|types|style|build|chore|release|refactor)(\(.+\))?!?: (.|\n)+/;
11
+ if (!isVersion(message) && !COMMIT_MESSAGE_RE.test(message)) {
12
+ logger.error(`Commit message invalid`);
13
+ logger.warning(`\
14
+ The rules for commit messages are as follows
15
+
16
+ Example:
17
+
18
+ feat: add a new feature
19
+ feat(ui/button): add a new feature in the ui/button scope
20
+
21
+ fix: fix a bug
22
+ fix(ui/button): fix a bug in the ui/button scope
23
+
24
+ docs: fix an error in the documentation
25
+ docs(ui/button): fix a documentation error in the ui/button scope
26
+
27
+ Allowed types:
28
+ - fix
29
+ - feat
30
+ - docs
31
+ - perf
32
+ - test
33
+ - types
34
+ - style
35
+ - build
36
+ - chore
37
+ - release
38
+ - refactor
39
+ - revert
40
+
41
+ Commit message reference: https://docs.google.com/document/d/1QrDFcIiPjSLDn3EL15IJygNPiHORgU1_OOAqWjiDU5Y
42
+ 参考阮一峰Commit message编写指南: https://www.ruanyifeng.com/blog/2016/01/commit_message_change_log.html`);
43
+ process.exit(1);
44
+ }
45
+ }
@@ -1,7 +1,7 @@
1
- export declare function removeDir(): Promise<[void, void, void, void]>;
2
- export declare function runTask(taskName: string, task: () => any): Promise<void>;
3
- interface CompileCommandOptions {
4
- noUmd?: boolean;
5
- }
6
- export declare function compile(options: CompileCommandOptions): Promise<void>;
7
- export {};
1
+ export declare function removeDir(): Promise<[void, void, void, void]>;
2
+ export declare function runTask(taskName: string, task: () => any): Promise<void>;
3
+ interface CompileCommandOptions {
4
+ noUmd?: boolean;
5
+ }
6
+ export declare function compile(options: CompileCommandOptions): Promise<void>;
7
+ export {};
@@ -0,0 +1,35 @@
1
+ import ora from 'ora';
2
+ import logger from '../shared/logger.js';
3
+ import fse from 'fs-extra';
4
+ import { ES_DIR, HL_DIR, LIB_DIR, UMD_DIR } from '../shared/constant.js';
5
+ import { compileModule } from '../compiler/compileModule.js';
6
+ import { compileTemplateHighlight } from '../compiler/compileTemplateHighlight.js';
7
+ import { compileTypes } from '../compiler/compileTypes.js';
8
+ const { remove } = fse;
9
+ export function removeDir() {
10
+ return Promise.all([remove(ES_DIR), remove(LIB_DIR), remove(HL_DIR), remove(UMD_DIR)]);
11
+ }
12
+ export async function runTask(taskName, task) {
13
+ const s = ora().start(`Compiling ${taskName}`);
14
+ try {
15
+ await task();
16
+ s.succeed(`Compilation ${taskName} completed!`);
17
+ }
18
+ catch (e) {
19
+ s.fail(`Compilation ${taskName} failed!`);
20
+ logger.error(e.toString());
21
+ }
22
+ }
23
+ export async function compile(options) {
24
+ process.env.NODE_ENV = 'compile';
25
+ await removeDir();
26
+ await Promise.all([runTask('types', compileTypes), runTask('template highlight', compileTemplateHighlight)]);
27
+ process.env.TARGET_MODULE = 'module';
28
+ await runTask('module', compileModule);
29
+ process.env.TARGET_MODULE = 'esm-bundle';
30
+ await runTask('esm bundle', () => compileModule('esm-bundle'));
31
+ process.env.TARGET_MODULE = 'commonjs';
32
+ await runTask('commonjs', () => compileModule('commonjs'));
33
+ process.env.TARGET_MODULE = 'umd';
34
+ !options.noUmd && (await runTask('umd', () => compileModule('umd')));
35
+ }
@@ -1,8 +1,8 @@
1
- interface CreateCommandOptions {
2
- name?: string;
3
- locale?: boolean;
4
- sfc?: boolean;
5
- tsx?: boolean;
6
- }
7
- export declare function create(options: CreateCommandOptions): Promise<void>;
8
- export {};
1
+ interface CreateCommandOptions {
2
+ name?: string;
3
+ locale?: boolean;
4
+ sfc?: boolean;
5
+ tsx?: boolean;
6
+ }
7
+ export declare function create(options: CreateCommandOptions): Promise<void>;
8
+ export {};
@@ -0,0 +1,91 @@
1
+ import ejs from 'ejs';
2
+ import fse from 'fs-extra';
3
+ import logger from '../shared/logger.js';
4
+ import { bigCamelize, camelize, kebabCase } from '@varlet/shared';
5
+ import inquirer from 'inquirer';
6
+ import { get } from 'lodash-es';
7
+ import { resolve } from 'path';
8
+ import { glob } from '../shared/fsUtils.js';
9
+ import { getVarletConfig } from '../config/varlet.config.js';
10
+ import { SRC_DIR, dirname } from '../shared/constant.js';
11
+ const { removeSync, readFileSync, copySync, pathExistsSync, writeFileSync } = fse;
12
+ const { prompt } = inquirer;
13
+ async function renderTemplates(componentFolder, componentFolderName, renderData) {
14
+ const templates = await glob(`${componentFolder}/**/*.ejs`);
15
+ templates.forEach((template) => {
16
+ const templateCode = readFileSync(template, { encoding: 'utf-8' });
17
+ const code = ejs.render(templateCode, renderData);
18
+ const file = template
19
+ .replace('[componentName]', camelize(componentFolderName))
20
+ .replace('[ComponentName]', bigCamelize(componentFolderName))
21
+ .replace('.ejs', '');
22
+ writeFileSync(file, code);
23
+ removeSync(template);
24
+ });
25
+ }
26
+ export async function create(options) {
27
+ logger.title('\n📦📦 Create a component ! \n');
28
+ const namespace = get(await getVarletConfig(), 'namespace');
29
+ const renderData = {
30
+ namespace,
31
+ bigCamelizeNamespace: bigCamelize(namespace),
32
+ kebabCaseName: 'component-name',
33
+ bigCamelizeName: 'ComponentName',
34
+ camelizeName: 'componentName',
35
+ style: 'vue',
36
+ };
37
+ const { name } = options.name
38
+ ? options
39
+ : await prompt({
40
+ name: 'name',
41
+ message: 'Name of the component created: ',
42
+ default: renderData.kebabCaseName,
43
+ });
44
+ renderData.kebabCaseName = kebabCase(name);
45
+ renderData.camelizeName = camelize(name);
46
+ renderData.bigCamelizeName = bigCamelize(name);
47
+ const componentFolder = resolve(SRC_DIR, renderData.kebabCaseName);
48
+ const componentFolderName = renderData.kebabCaseName;
49
+ if (pathExistsSync(componentFolder)) {
50
+ logger.warning(`${componentFolderName} already exist and cannot be recreated...`);
51
+ return;
52
+ }
53
+ const { locale } = options.locale
54
+ ? options
55
+ : await prompt({
56
+ name: 'locale',
57
+ type: 'confirm',
58
+ message: 'Whether to use i18n?',
59
+ default: false,
60
+ });
61
+ renderData.locale = locale;
62
+ // Determine whether the parameter carries a component style
63
+ if (options.sfc || options.tsx) {
64
+ renderData.style = options.sfc ? 'vue' : 'tsx';
65
+ }
66
+ else {
67
+ const { style } = await prompt({
68
+ name: 'style',
69
+ type: 'list',
70
+ message: 'Which style do you use to write your component ?',
71
+ choices: [
72
+ { name: 'sfc', value: 'vue' },
73
+ { name: 'tsx', value: 'tsx' },
74
+ ],
75
+ default: 'vue',
76
+ });
77
+ renderData.style = style;
78
+ }
79
+ copySync(resolve(dirname, '../../../template/create'), componentFolder);
80
+ await renderTemplates(componentFolder, componentFolderName, renderData);
81
+ if (!renderData.locale) {
82
+ removeSync(resolve(componentFolder, '/example/locale'));
83
+ }
84
+ if (renderData.style !== 'vue') {
85
+ removeSync(resolve(componentFolder, `${renderData.bigCamelizeName}.vue`));
86
+ }
87
+ if (renderData.style !== 'tsx') {
88
+ removeSync(resolve(componentFolder, `${renderData.bigCamelizeName}.tsx`));
89
+ }
90
+ logger.success(`Create ${componentFolderName} component success!`);
91
+ }