@varlet/cli 2.1.0-alpha.1667210582672 → 2.1.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 (90) hide show
  1. package/lib/client/appType.d.ts +4 -4
  2. package/lib/client/appType.js +7 -7
  3. package/lib/client/index.d.ts +17 -17
  4. package/lib/client/index.js +106 -106
  5. package/lib/node/bin.d.ts +2 -2
  6. package/lib/node/bin.js +122 -122
  7. package/lib/node/commands/build.d.ts +1 -1
  8. package/lib/node/commands/build.js +15 -15
  9. package/lib/node/commands/changelog.d.ts +6 -6
  10. package/lib/node/commands/changelog.js +20 -20
  11. package/lib/node/commands/commitLint.d.ts +1 -1
  12. package/lib/node/commands/commitLint.js +16 -16
  13. package/lib/node/commands/compile.d.ts +7 -7
  14. package/lib/node/commands/compile.js +35 -35
  15. package/lib/node/commands/create.d.ts +8 -8
  16. package/lib/node/commands/create.js +91 -91
  17. package/lib/node/commands/dev.d.ts +5 -5
  18. package/lib/node/commands/dev.js +38 -38
  19. package/lib/node/commands/gen.d.ts +8 -8
  20. package/lib/node/commands/gen.js +69 -68
  21. package/lib/node/commands/jest.d.ts +8 -8
  22. package/lib/node/commands/jest.js +27 -27
  23. package/lib/node/commands/lint.d.ts +1 -1
  24. package/lib/node/commands/lint.js +42 -42
  25. package/lib/node/commands/preview.d.ts +1 -1
  26. package/lib/node/commands/preview.js +18 -18
  27. package/lib/node/commands/release.d.ts +5 -5
  28. package/lib/node/commands/release.js +146 -146
  29. package/lib/node/commands/vite.d.ts +3 -3
  30. package/lib/node/commands/vite.js +13 -13
  31. package/lib/node/compiler/compileModule.d.ts +5 -5
  32. package/lib/node/compiler/compileModule.js +74 -74
  33. package/lib/node/compiler/compileSFC.d.ts +2 -2
  34. package/lib/node/compiler/compileSFC.js +74 -74
  35. package/lib/node/compiler/compileScript.d.ts +17 -17
  36. package/lib/node/compiler/compileScript.js +95 -95
  37. package/lib/node/compiler/compileSiteEntry.d.ts +13 -13
  38. package/lib/node/compiler/compileSiteEntry.js +95 -95
  39. package/lib/node/compiler/compileStyle.d.ts +11 -11
  40. package/lib/node/compiler/compileStyle.js +39 -39
  41. package/lib/node/compiler/compileTemplateHighlight.d.ts +10 -10
  42. package/lib/node/compiler/compileTemplateHighlight.js +133 -133
  43. package/lib/node/compiler/compileTypes.d.ts +2 -2
  44. package/lib/node/compiler/compileTypes.js +30 -30
  45. package/lib/node/config/varlet.config.d.ts +45 -45
  46. package/lib/node/config/varlet.config.js +27 -27
  47. package/lib/node/config/varlet.default.config.d.ts +2 -2
  48. package/lib/node/config/varlet.default.config.js +264 -264
  49. package/lib/node/config/vite.config.d.ts +6 -6
  50. package/lib/node/config/vite.config.js +142 -142
  51. package/lib/node/index.d.ts +1 -1
  52. package/lib/node/index.js +1 -1
  53. package/lib/node/shared/constant.d.ts +42 -42
  54. package/lib/node/shared/constant.js +47 -47
  55. package/lib/node/shared/fsUtils.d.ts +13 -13
  56. package/lib/node/shared/fsUtils.js +48 -48
  57. package/lib/node/shared/logger.d.ts +8 -8
  58. package/lib/node/shared/logger.js +18 -18
  59. package/package.json +7 -7
  60. package/site/components/button/index.ts +10 -10
  61. package/site/components/cell/index.ts +10 -10
  62. package/site/components/code-example/codeExample.less +41 -41
  63. package/site/components/code-example/index.ts +10 -10
  64. package/site/components/context/zIndex.ts +20 -20
  65. package/site/components/icon/icon.less +26 -26
  66. package/site/components/icon/index.ts +10 -10
  67. package/site/components/icon/props.ts +24 -24
  68. package/site/components/loading/index.ts +10 -10
  69. package/site/components/progress/index.ts +10 -10
  70. package/site/components/snackbar/snackbar.less +135 -135
  71. package/site/components/styles/common.less +64 -64
  72. package/site/components/styles/elevation.less +126 -126
  73. package/site/components/styles/var.less +27 -27
  74. package/site/index.html +49 -49
  75. package/site/mobile/components/app-bar/index.ts +10 -10
  76. package/site/mobile/components/app-bar/props.ts +25 -25
  77. package/site/mobile.html +41 -41
  78. package/site/module.d.ts +5 -5
  79. package/site/tsconfig.json +11 -11
  80. package/template/create/example/index.vue.ejs +4 -2
  81. package/template/generators/base/_gitignore +5 -1
  82. package/template/generators/base/babel.config.js +1 -1
  83. package/template/generators/config/default/sfc/src/button/example/index.vue +1 -1
  84. package/template/generators/config/default/tsx/src/button/example/index.vue +1 -1
  85. package/template/generators/config/i18n/sfc/src/button/example/BasicUse.vue +1 -1
  86. package/template/generators/config/i18n/sfc/src/button/example/ModifyColor.vue +1 -1
  87. package/template/generators/config/i18n/sfc/src/button/example/index.vue +1 -2
  88. package/template/generators/config/i18n/tsx/src/button/example/BasicUse.vue +1 -1
  89. package/template/generators/config/i18n/tsx/src/button/example/ModifyColor.vue +1 -1
  90. package/template/generators/config/i18n/tsx/src/button/example/index.vue +1 -2
@@ -1,110 +1,110 @@
1
- import slash from 'slash';
2
- import fse from 'fs-extra';
3
- import { DOCS_DIR_NAME, DIR_INDEX, EXAMPLE_DIR_NAME, LOCALE_DIR_NAME, ROOT_DOCS_DIR, ROOT_PAGES_DIR, SITE, SITE_DIR, SITE_MOBILE_ROUTES, SITE_PC_DIR, SITE_PC_ROUTES, SRC_DIR, } from '../shared/constant.js';
4
- import { glob, isDir, outputFileSyncOnChange } from '../shared/fsUtils.js';
5
- import { getVarletConfig } from '../config/varlet.config.js';
6
- import { get } from 'lodash-es';
7
- const { copy } = fse;
8
- const EXAMPLE_COMPONENT_NAME_RE = /\/([-\w]+)\/example\/index.vue/;
9
- const COMPONENT_DOCS_RE = /\/([-\w]+)\/docs\/([-\w]+)\.md/;
10
- const ROOT_DOCS_RE = /\/docs\/([-\w]+)\.([-\w]+)\.md/;
11
- const ROOT_LOCALE_RE = /\/pages\/([-\w]+)\/locale\/([-\w]+)\.ts/;
12
- export function getExampleRoutePath(examplePath) {
13
- var _a;
14
- return '/' + ((_a = examplePath.match(EXAMPLE_COMPONENT_NAME_RE)) === null || _a === void 0 ? void 0 : _a[1]);
15
- }
16
- export function getComponentDocRoutePath(componentDocsPath) {
17
- var _a;
18
- const [, routePath, language] = (_a = componentDocsPath.match(COMPONENT_DOCS_RE)) !== null && _a !== void 0 ? _a : [];
19
- return `/${language}/${routePath}`;
20
- }
21
- export function getRootDocRoutePath(rootDocsPath) {
22
- var _a;
23
- const [, routePath, language] = (_a = rootDocsPath.match(ROOT_DOCS_RE)) !== null && _a !== void 0 ? _a : [];
24
- return `/${language}/${routePath}`;
25
- }
26
- export function getRootRoutePath(rootLocalePath) {
27
- var _a;
28
- const [, routePath, language] = (_a = rootLocalePath.match(ROOT_LOCALE_RE)) !== null && _a !== void 0 ? _a : [];
29
- return `/${language}/${routePath}`;
30
- }
31
- export function getRootFilePath(rootLocalePath) {
32
- return rootLocalePath.replace(/locale\/.+/, DIR_INDEX);
33
- }
34
- export function findExamples() {
35
- return glob(`${SRC_DIR}/**/${EXAMPLE_DIR_NAME}/${DIR_INDEX}`);
36
- }
37
- export function findComponentDocs() {
38
- return glob(`${SRC_DIR}/**/${DOCS_DIR_NAME}/*.md`);
39
- }
40
- export function findRootDocs() {
41
- return glob(`${ROOT_DOCS_DIR}/*.md`);
42
- }
43
- export async function findRootLocales() {
44
- const defaultLanguage = get(await getVarletConfig(), 'defaultLanguage');
45
- const userPages = await glob(`${ROOT_PAGES_DIR}/*`);
46
- const baseLocales = await glob(`${SITE}/pc/pages/**/${LOCALE_DIR_NAME}/*.ts`);
47
- const userLocales = await userPages.reduce(async (userLocales, page) => {
48
- if (isDir(page)) {
49
- const locales = await glob(`${page}/${LOCALE_DIR_NAME}/*.ts`);
50
- if (!locales.length)
51
- locales.push(`${page}/${LOCALE_DIR_NAME}/${defaultLanguage}.ts`);
52
- (await userLocales).push(...locales);
53
- }
54
- return userLocales;
55
- }, Promise.resolve([]));
56
- // filter
57
- const filterMap = new Map();
58
- baseLocales.forEach((locale) => {
59
- var _a;
60
- const [, routePath, language] = (_a = locale.match(ROOT_LOCALE_RE)) !== null && _a !== void 0 ? _a : [];
61
- filterMap.set(routePath + language, slash(`${SITE_PC_DIR}/pages/${routePath}/locale/${language}.ts`));
62
- });
63
- userLocales.forEach((locale) => {
64
- var _a;
65
- const [, routePath, language] = (_a = locale.match(ROOT_LOCALE_RE)) !== null && _a !== void 0 ? _a : [];
66
- filterMap.set(routePath + language, locale);
67
- });
68
- return Promise.resolve(Array.from(filterMap.values()));
69
- }
70
- export async function buildMobileSiteRoutes() {
71
- const examples = await findExamples();
1
+ import slash from 'slash';
2
+ import fse from 'fs-extra';
3
+ import { DOCS_DIR_NAME, DIR_INDEX, EXAMPLE_DIR_NAME, LOCALE_DIR_NAME, ROOT_DOCS_DIR, ROOT_PAGES_DIR, SITE, SITE_DIR, SITE_MOBILE_ROUTES, SITE_PC_DIR, SITE_PC_ROUTES, SRC_DIR, } from '../shared/constant.js';
4
+ import { glob, isDir, outputFileSyncOnChange } from '../shared/fsUtils.js';
5
+ import { getVarletConfig } from '../config/varlet.config.js';
6
+ import { get } from 'lodash-es';
7
+ const { copy } = fse;
8
+ const EXAMPLE_COMPONENT_NAME_RE = /\/([-\w]+)\/example\/index.vue/;
9
+ const COMPONENT_DOCS_RE = /\/([-\w]+)\/docs\/([-\w]+)\.md/;
10
+ const ROOT_DOCS_RE = /\/docs\/([-\w]+)\.([-\w]+)\.md/;
11
+ const ROOT_LOCALE_RE = /\/pages\/([-\w]+)\/locale\/([-\w]+)\.ts/;
12
+ export function getExampleRoutePath(examplePath) {
13
+ var _a;
14
+ return '/' + ((_a = examplePath.match(EXAMPLE_COMPONENT_NAME_RE)) === null || _a === void 0 ? void 0 : _a[1]);
15
+ }
16
+ export function getComponentDocRoutePath(componentDocsPath) {
17
+ var _a;
18
+ const [, routePath, language] = (_a = componentDocsPath.match(COMPONENT_DOCS_RE)) !== null && _a !== void 0 ? _a : [];
19
+ return `/${language}/${routePath}`;
20
+ }
21
+ export function getRootDocRoutePath(rootDocsPath) {
22
+ var _a;
23
+ const [, routePath, language] = (_a = rootDocsPath.match(ROOT_DOCS_RE)) !== null && _a !== void 0 ? _a : [];
24
+ return `/${language}/${routePath}`;
25
+ }
26
+ export function getRootRoutePath(rootLocalePath) {
27
+ var _a;
28
+ const [, routePath, language] = (_a = rootLocalePath.match(ROOT_LOCALE_RE)) !== null && _a !== void 0 ? _a : [];
29
+ return `/${language}/${routePath}`;
30
+ }
31
+ export function getRootFilePath(rootLocalePath) {
32
+ return rootLocalePath.replace(/locale\/.+/, DIR_INDEX);
33
+ }
34
+ export function findExamples() {
35
+ return glob(`${SRC_DIR}/**/${EXAMPLE_DIR_NAME}/${DIR_INDEX}`);
36
+ }
37
+ export function findComponentDocs() {
38
+ return glob(`${SRC_DIR}/**/${DOCS_DIR_NAME}/*.md`);
39
+ }
40
+ export function findRootDocs() {
41
+ return glob(`${ROOT_DOCS_DIR}/*.md`);
42
+ }
43
+ export async function findRootLocales() {
44
+ const defaultLanguage = get(await getVarletConfig(), 'defaultLanguage');
45
+ const userPages = await glob(`${ROOT_PAGES_DIR}/*`);
46
+ const baseLocales = await glob(`${SITE}/pc/pages/**/${LOCALE_DIR_NAME}/*.ts`);
47
+ const userLocales = await userPages.reduce(async (userLocales, page) => {
48
+ if (isDir(page)) {
49
+ const locales = await glob(`${page}/${LOCALE_DIR_NAME}/*.ts`);
50
+ if (!locales.length)
51
+ locales.push(`${page}/${LOCALE_DIR_NAME}/${defaultLanguage}.ts`);
52
+ (await userLocales).push(...locales);
53
+ }
54
+ return userLocales;
55
+ }, Promise.resolve([]));
56
+ // filter
57
+ const filterMap = new Map();
58
+ baseLocales.forEach((locale) => {
59
+ var _a;
60
+ const [, routePath, language] = (_a = locale.match(ROOT_LOCALE_RE)) !== null && _a !== void 0 ? _a : [];
61
+ filterMap.set(routePath + language, slash(`${SITE_PC_DIR}/pages/${routePath}/locale/${language}.ts`));
62
+ });
63
+ userLocales.forEach((locale) => {
64
+ var _a;
65
+ const [, routePath, language] = (_a = locale.match(ROOT_LOCALE_RE)) !== null && _a !== void 0 ? _a : [];
66
+ filterMap.set(routePath + language, locale);
67
+ });
68
+ return Promise.resolve(Array.from(filterMap.values()));
69
+ }
70
+ export async function buildMobileSiteRoutes() {
71
+ const examples = await findExamples();
72
72
  const routes = examples.map((example) => `
73
73
  {
74
74
  path: '${getExampleRoutePath(example)}',
75
75
  // @ts-ignore
76
76
  component: () => import('${example}')
77
- }`);
77
+ }`);
78
78
  const source = `export default [\
79
79
  ${routes.join(',')}
80
- ]`;
81
- await outputFileSyncOnChange(SITE_MOBILE_ROUTES, source);
82
- }
83
- export async function buildPcSiteRoutes() {
84
- const [componentDocs, rootDocs, rootLocales] = await Promise.all([
85
- findComponentDocs(),
86
- findRootDocs(),
87
- findRootLocales(),
88
- ]);
80
+ ]`;
81
+ await outputFileSyncOnChange(SITE_MOBILE_ROUTES, source);
82
+ }
83
+ export async function buildPcSiteRoutes() {
84
+ const [componentDocs, rootDocs, rootLocales] = await Promise.all([
85
+ findComponentDocs(),
86
+ findRootDocs(),
87
+ findRootLocales(),
88
+ ]);
89
89
  const rootPagesRoutes = rootLocales.map((rootLocale) => `
90
90
  {
91
91
  path: '${getRootRoutePath(rootLocale)}',
92
92
  // @ts-ignore
93
93
  component: () => import('${getRootFilePath(rootLocale)}')
94
94
  }\
95
- `);
95
+ `);
96
96
  const componentDocsRoutes = componentDocs.map((componentDoc) => `
97
97
  {
98
98
  path: '${getComponentDocRoutePath(componentDoc)}',
99
99
  // @ts-ignore
100
100
  component: () => import('${componentDoc}')
101
- }`);
101
+ }`);
102
102
  const rootDocsRoutes = rootDocs.map((rootDoc) => `
103
103
  {
104
104
  path: '${getRootDocRoutePath(rootDoc)}',
105
105
  // @ts-ignore
106
106
  component: () => import('${rootDoc}')
107
- }`);
107
+ }`);
108
108
  const layoutRoutes = `{
109
109
  path: '/layout',
110
110
  // @ts-ignore
@@ -112,17 +112,17 @@ export async function buildPcSiteRoutes() {
112
112
  children: [
113
113
  ${[...componentDocsRoutes, rootDocsRoutes].join(',')},
114
114
  ]
115
- }`;
115
+ }`;
116
116
  const source = `export default [\
117
117
  ${rootPagesRoutes.join(',')},
118
118
  ${layoutRoutes}
119
- ]`;
120
- outputFileSyncOnChange(SITE_PC_ROUTES, source);
121
- }
122
- export async function buildSiteSource() {
123
- return copy(SITE, SITE_DIR);
124
- }
125
- export async function buildSiteEntry() {
126
- await getVarletConfig(true);
127
- await Promise.all([buildMobileSiteRoutes(), buildPcSiteRoutes(), buildSiteSource()]);
128
- }
119
+ ]`;
120
+ outputFileSyncOnChange(SITE_PC_ROUTES, source);
121
+ }
122
+ export async function buildSiteSource() {
123
+ return copy(SITE, SITE_DIR);
124
+ }
125
+ export async function buildSiteEntry() {
126
+ await getVarletConfig(true);
127
+ await Promise.all([buildMobileSiteRoutes(), buildPcSiteRoutes(), buildSiteSource()]);
128
+ }
@@ -1,11 +1,11 @@
1
- export declare const EMPTY_SPACE_RE: RegExp;
2
- export declare const EMPTY_LINE_RE: RegExp;
3
- export declare const IMPORT_CSS_RE: RegExp;
4
- export declare const IMPORT_LESS_RE: RegExp;
5
- export declare const REQUIRE_CSS_RE: RegExp;
6
- export declare const REQUIRE_LESS_RE: RegExp;
7
- export declare const STYLE_IMPORT_RE: RegExp;
8
- export declare const clearEmptyLine: (s: string) => string;
9
- export declare function normalizeStyleDependency(styleImport: string, reg: RegExp): string;
10
- export declare function extractStyleDependencies(file: string, code: string, styleReg: RegExp): string;
11
- export declare function compileLess(file: string): Promise<void>;
1
+ export declare const EMPTY_SPACE_RE: RegExp;
2
+ export declare const EMPTY_LINE_RE: RegExp;
3
+ export declare const IMPORT_CSS_RE: RegExp;
4
+ export declare const IMPORT_LESS_RE: RegExp;
5
+ export declare const REQUIRE_CSS_RE: RegExp;
6
+ export declare const REQUIRE_LESS_RE: RegExp;
7
+ export declare const STYLE_IMPORT_RE: RegExp;
8
+ export declare const clearEmptyLine: (s: string) => string;
9
+ export declare function normalizeStyleDependency(styleImport: string, reg: RegExp): string;
10
+ export declare function extractStyleDependencies(file: string, code: string, styleReg: RegExp): string;
11
+ export declare function compileLess(file: string): Promise<void>;
@@ -1,39 +1,39 @@
1
- import fse from 'fs-extra';
2
- import less from 'less';
3
- import { replaceExt, smartAppendFileSync } from '../shared/fsUtils.js';
4
- import { parse, resolve } from 'path';
5
- const { render } = less;
6
- const { readFileSync, removeSync, writeFileSync } = fse;
7
- export const EMPTY_SPACE_RE = /[\s]+/g;
8
- export const EMPTY_LINE_RE = /[\n\r]*/g;
9
- export const IMPORT_CSS_RE = /(?<!['"`])import\s+['"](\.{1,2}\/.+\.css)['"]\s*;?(?!\s*['"`])/g;
10
- export const IMPORT_LESS_RE = /(?<!['"`])import\s+['"](\.{1,2}\/.+\.less)['"]\s*;?(?!\s*['"`])/g;
11
- export const REQUIRE_CSS_RE = /(?<!['"`])require\(\s*['"](\.{1,2}\/.+\.css)['"]\s*\);?(?!\s*['"`])/g;
12
- export const REQUIRE_LESS_RE = /(?<!['"`])require\(\s*['"](\.{1,2}\/.+\.less)['"]\s*\);?(?!\s*['"`])/g;
13
- export const STYLE_IMPORT_RE = /@import\s+['"](.+)['"]\s*;/g;
14
- export const clearEmptyLine = (s) => s.replace(EMPTY_LINE_RE, '').replace(EMPTY_SPACE_RE, ' ');
15
- export function normalizeStyleDependency(styleImport, reg) {
16
- let relativePath = styleImport.replace(reg, '$1');
17
- relativePath = relativePath.replace(/(\.less)|(\.css)/, '');
18
- if (relativePath.startsWith('./')) {
19
- return '.' + relativePath;
20
- }
21
- return '../' + relativePath;
22
- }
23
- export function extractStyleDependencies(file, code, styleReg) {
24
- var _a;
25
- const styleImports = (_a = code.match(styleReg)) !== null && _a !== void 0 ? _a : [];
26
- const cssFile = resolve(parse(file).dir, './style/index.js');
27
- const modules = process.env.BABEL_MODULE;
28
- styleImports.forEach((styleImport) => {
29
- const normalizedPath = normalizeStyleDependency(styleImport, styleReg);
30
- smartAppendFileSync(cssFile, modules === 'commonjs' ? `require('${normalizedPath}.css')\n` : `import '${normalizedPath}.css'\n`);
31
- });
32
- return code.replace(styleReg, '');
33
- }
34
- export async function compileLess(file) {
35
- const source = readFileSync(file, 'utf-8');
36
- const { css } = await render(source, { filename: file });
37
- removeSync(file);
38
- writeFileSync(replaceExt(file, '.css'), clearEmptyLine(css), 'utf-8');
39
- }
1
+ import fse from 'fs-extra';
2
+ import less from 'less';
3
+ import { replaceExt, smartAppendFileSync } from '../shared/fsUtils.js';
4
+ import { parse, resolve } from 'path';
5
+ const { render } = less;
6
+ const { readFileSync, removeSync, writeFileSync } = fse;
7
+ export const EMPTY_SPACE_RE = /[\s]+/g;
8
+ export const EMPTY_LINE_RE = /[\n\r]*/g;
9
+ export const IMPORT_CSS_RE = /(?<!['"`])import\s+['"](\.{1,2}\/.+\.css)['"]\s*;?(?!\s*['"`])/g;
10
+ export const IMPORT_LESS_RE = /(?<!['"`])import\s+['"](\.{1,2}\/.+\.less)['"]\s*;?(?!\s*['"`])/g;
11
+ export const REQUIRE_CSS_RE = /(?<!['"`])require\(\s*['"](\.{1,2}\/.+\.css)['"]\s*\);?(?!\s*['"`])/g;
12
+ export const REQUIRE_LESS_RE = /(?<!['"`])require\(\s*['"](\.{1,2}\/.+\.less)['"]\s*\);?(?!\s*['"`])/g;
13
+ export const STYLE_IMPORT_RE = /@import\s+['"](.+)['"]\s*;/g;
14
+ export const clearEmptyLine = (s) => s.replace(EMPTY_LINE_RE, '').replace(EMPTY_SPACE_RE, ' ');
15
+ export function normalizeStyleDependency(styleImport, reg) {
16
+ let relativePath = styleImport.replace(reg, '$1');
17
+ relativePath = relativePath.replace(/(\.less)|(\.css)/, '');
18
+ if (relativePath.startsWith('./')) {
19
+ return '.' + relativePath;
20
+ }
21
+ return '../' + relativePath;
22
+ }
23
+ export function extractStyleDependencies(file, code, styleReg) {
24
+ var _a;
25
+ const styleImports = (_a = code.match(styleReg)) !== null && _a !== void 0 ? _a : [];
26
+ const cssFile = resolve(parse(file).dir, './style/index.js');
27
+ const modules = process.env.BABEL_MODULE;
28
+ styleImports.forEach((styleImport) => {
29
+ const normalizedPath = normalizeStyleDependency(styleImport, styleReg);
30
+ smartAppendFileSync(cssFile, modules === 'commonjs' ? `require('${normalizedPath}.css')\n` : `import '${normalizedPath}.css'\n`);
31
+ });
32
+ return code.replace(styleReg, '');
33
+ }
34
+ export async function compileLess(file) {
35
+ const source = readFileSync(file, 'utf-8');
36
+ const { css } = await render(source, { filename: file });
37
+ removeSync(file);
38
+ writeFileSync(replaceExt(file, '.css'), clearEmptyLine(css), 'utf-8');
39
+ }
@@ -1,10 +1,10 @@
1
- export declare const replaceDot: (s: string) => string;
2
- export declare const replaceUnderline: (s: string) => string;
3
- export declare function parseTable(table: string): string[][];
4
- export declare function compileTable(md: string, titleRe: RegExp): string;
5
- export declare function compileTags(table: Record<string, any>, tags: Record<string, any>, componentName: string, varletConfig: Record<string, any>): void;
6
- export declare function compileAttributes(table: Record<string, any>, attributes: Record<string, any>, componentName: string, varletConfig: Record<string, any>): void;
7
- export declare function compileWebTypes(table: Record<string, any>, webTypes: Record<string, any>, componentName: string, varletConfig: Record<string, any>): void;
8
- export declare function compileMD(path: string, tags: Record<string, any>, attributes: Record<string, any>, webTypes: Record<string, any>, varletConfig: Record<string, any>): void;
9
- export declare function compileDir(path: string, tags: Record<string, any>, attributes: Record<string, any>, webTypes: Record<string, any>, varletConfig: Record<string, any>): void;
10
- export declare function compileTemplateHighlight(): Promise<void>;
1
+ export declare const replaceDot: (s: string) => string;
2
+ export declare const replaceUnderline: (s: string) => string;
3
+ export declare function parseTable(table: string): string[][];
4
+ export declare function compileTable(md: string, titleRe: RegExp): string;
5
+ export declare function compileTags(table: Record<string, any>, tags: Record<string, any>, componentName: string, varletConfig: Record<string, any>): void;
6
+ export declare function compileAttributes(table: Record<string, any>, attributes: Record<string, any>, componentName: string, varletConfig: Record<string, any>): void;
7
+ export declare function compileWebTypes(table: Record<string, any>, webTypes: Record<string, any>, componentName: string, varletConfig: Record<string, any>): void;
8
+ export declare function compileMD(path: string, tags: Record<string, any>, attributes: Record<string, any>, webTypes: Record<string, any>, varletConfig: Record<string, any>): void;
9
+ export declare function compileDir(path: string, tags: Record<string, any>, attributes: Record<string, any>, webTypes: Record<string, any>, varletConfig: Record<string, any>): void;
10
+ export declare function compileTemplateHighlight(): Promise<void>;
@@ -1,133 +1,133 @@
1
- import fse from 'fs-extra';
2
- import { SRC_DIR, HL_MD, HL_API_RE, HL_COMPONENT_NAME_RE, HL_TITLE_ATTRIBUTES_RE, HL_TITLE_EVENTS_RE, HL_TITLE_SLOTS_RE, HL_WEB_TYPES_JSON, HL_DIR, HL_TAGS_JSON, HL_ATTRIBUTES_JSON, CLI_PACKAGE_JSON, } from '../shared/constant.js';
3
- import { resolve } from 'path';
4
- import { isDir, isMD } from '../shared/fsUtils.js';
5
- import { get } from 'lodash-es';
6
- import { getVarletConfig } from '../config/varlet.config.js';
7
- const { ensureDir, readdirSync, readFileSync, readJSONSync, writeFile } = fse;
8
- const TABLE_HEAD_RE = /\s*\|.*\|\s*\n\s*\|.*---+\s*\|\s*\n+/;
9
- const TABLE_FOOT_RE = /(\|\s*$)|(\|\s*\n(?!\s*\|))/;
10
- export const replaceDot = (s) => s.replace(/`/g, '');
11
- export const replaceUnderline = (s) => s.replace(/_/g, '');
12
- export function parseTable(table) {
13
- const rows = table.split('\n').filter(Boolean);
14
- return rows.map((row) => {
15
- const cols = row.split('|');
16
- cols.shift();
17
- cols.pop();
18
- return cols.map((col) => col.replace(/__varlet_axis__/g, '|').trim());
19
- });
20
- }
21
- export function compileTable(md, titleRe) {
22
- const apiMatched = md.match(HL_API_RE);
23
- if (!apiMatched) {
24
- return '';
25
- }
26
- md = md.slice(apiMatched.index + apiMatched[0].length);
27
- const titleMatched = md.match(titleRe);
28
- if (!titleMatched) {
29
- return '';
30
- }
31
- md = md.slice(titleMatched.index + titleMatched[0].length);
32
- const tableHeadMatched = md.match(TABLE_HEAD_RE);
33
- if (!tableHeadMatched) {
34
- return '';
35
- }
36
- md = md.slice(tableHeadMatched.index + tableHeadMatched[0].length);
37
- const tableFootMatched = md.match(TABLE_FOOT_RE);
38
- if (!tableFootMatched) {
39
- return '';
40
- }
41
- md = md.slice(0, tableFootMatched.index + tableFootMatched[0].length);
42
- return md.replace(/\\\|/g, '__varlet_axis__').trim();
43
- }
44
- export function compileTags(table, tags, componentName, varletConfig) {
45
- tags[`${get(varletConfig, 'namespace')}-${componentName}`] = {
46
- attributes: table.attributesTable.map((row) => replaceDot(row[0])),
47
- };
48
- }
49
- export function compileAttributes(table, attributes, componentName, varletConfig) {
50
- table.attributesTable.forEach((row) => {
51
- const attrNamespace = `${get(varletConfig, 'namespace')}-${componentName}/${replaceDot(row[0])}`;
52
- attributes[attrNamespace] = {
53
- type: replaceUnderline(row[2]),
54
- description: `${row[1]} 默认值:${replaceDot(row[3])}`,
55
- };
56
- });
57
- }
58
- export function compileWebTypes(table, webTypes, componentName, varletConfig) {
59
- const { attributesTable, eventsTable, slotsTable } = table;
60
- const attributes = attributesTable.map((row) => ({
61
- name: replaceDot(row[0]),
62
- description: row[1],
63
- default: replaceDot(row[3]),
64
- value: {
65
- type: replaceUnderline(row[2]),
66
- kind: 'expression',
67
- },
68
- }));
69
- const events = eventsTable.map((row) => ({
70
- name: replaceDot(row[0]),
71
- description: row[1],
72
- }));
73
- const slots = slotsTable.map((row) => ({
74
- name: replaceDot(row[0]),
75
- description: row[1],
76
- }));
77
- webTypes.contributions.html.tags.push({
78
- name: `${get(varletConfig, 'namespace')}-${componentName}`,
79
- attributes,
80
- events,
81
- slots,
82
- });
83
- }
84
- export function compileMD(path, tags, attributes, webTypes, varletConfig) {
85
- if (!path.endsWith(HL_MD)) {
86
- return;
87
- }
88
- const md = readFileSync(path, 'utf-8');
89
- const componentName = path.match(HL_COMPONENT_NAME_RE)[2];
90
- const attributesTable = parseTable(compileTable(md, HL_TITLE_ATTRIBUTES_RE));
91
- const eventsTable = parseTable(compileTable(md, HL_TITLE_EVENTS_RE));
92
- const slotsTable = parseTable(compileTable(md, HL_TITLE_SLOTS_RE));
93
- const table = {
94
- attributesTable,
95
- eventsTable,
96
- slotsTable,
97
- };
98
- compileWebTypes(table, webTypes, componentName, varletConfig);
99
- compileTags(table, tags, componentName, varletConfig);
100
- compileAttributes(table, attributes, componentName, varletConfig);
101
- }
102
- export function compileDir(path, tags, attributes, webTypes, varletConfig) {
103
- const dir = readdirSync(path);
104
- dir.forEach((filename) => {
105
- const filePath = resolve(path, filename);
106
- isDir(filePath) && compileDir(filePath, tags, attributes, webTypes, varletConfig);
107
- isMD(filePath) && compileMD(filePath, tags, attributes, webTypes, varletConfig);
108
- });
109
- }
110
- export async function compileTemplateHighlight() {
111
- await ensureDir(HL_DIR);
112
- const varletConfig = await getVarletConfig();
113
- const tags = {};
114
- const attributes = {};
115
- const webTypes = {
116
- $schema: 'https://raw.githubusercontent.com/JetBrains/web-types/master/schema/web-types.json',
117
- framework: 'vue',
118
- version: readJSONSync(CLI_PACKAGE_JSON).version,
119
- name: get(varletConfig, 'title'),
120
- contributions: {
121
- html: {
122
- tags: [],
123
- 'types-syntax': 'typescript',
124
- },
125
- },
126
- };
127
- compileDir(SRC_DIR, tags, attributes, webTypes, varletConfig);
128
- await Promise.all([
129
- writeFile(HL_WEB_TYPES_JSON, JSON.stringify(webTypes, null, 2)),
130
- writeFile(HL_TAGS_JSON, JSON.stringify(tags, null, 2)),
131
- writeFile(HL_ATTRIBUTES_JSON, JSON.stringify(attributes, null, 2)),
132
- ]);
133
- }
1
+ import fse from 'fs-extra';
2
+ import { SRC_DIR, HL_MD, HL_API_RE, HL_COMPONENT_NAME_RE, HL_TITLE_ATTRIBUTES_RE, HL_TITLE_EVENTS_RE, HL_TITLE_SLOTS_RE, HL_WEB_TYPES_JSON, HL_DIR, HL_TAGS_JSON, HL_ATTRIBUTES_JSON, CLI_PACKAGE_JSON, } from '../shared/constant.js';
3
+ import { resolve } from 'path';
4
+ import { isDir, isMD } from '../shared/fsUtils.js';
5
+ import { get } from 'lodash-es';
6
+ import { getVarletConfig } from '../config/varlet.config.js';
7
+ const { ensureDir, readdirSync, readFileSync, readJSONSync, writeFile } = fse;
8
+ const TABLE_HEAD_RE = /\s*\|.*\|\s*\n\s*\|.*---+\s*\|\s*\n+/;
9
+ const TABLE_FOOT_RE = /(\|\s*$)|(\|\s*\n(?!\s*\|))/;
10
+ export const replaceDot = (s) => s.replace(/`/g, '');
11
+ export const replaceUnderline = (s) => s.replace(/_/g, '');
12
+ export function parseTable(table) {
13
+ const rows = table.split('\n').filter(Boolean);
14
+ return rows.map((row) => {
15
+ const cols = row.split('|');
16
+ cols.shift();
17
+ cols.pop();
18
+ return cols.map((col) => col.replace(/__varlet_axis__/g, '|').trim());
19
+ });
20
+ }
21
+ export function compileTable(md, titleRe) {
22
+ const apiMatched = md.match(HL_API_RE);
23
+ if (!apiMatched) {
24
+ return '';
25
+ }
26
+ md = md.slice(apiMatched.index + apiMatched[0].length);
27
+ const titleMatched = md.match(titleRe);
28
+ if (!titleMatched) {
29
+ return '';
30
+ }
31
+ md = md.slice(titleMatched.index + titleMatched[0].length);
32
+ const tableHeadMatched = md.match(TABLE_HEAD_RE);
33
+ if (!tableHeadMatched) {
34
+ return '';
35
+ }
36
+ md = md.slice(tableHeadMatched.index + tableHeadMatched[0].length);
37
+ const tableFootMatched = md.match(TABLE_FOOT_RE);
38
+ if (!tableFootMatched) {
39
+ return '';
40
+ }
41
+ md = md.slice(0, tableFootMatched.index + tableFootMatched[0].length);
42
+ return md.replace(/\\\|/g, '__varlet_axis__').trim();
43
+ }
44
+ export function compileTags(table, tags, componentName, varletConfig) {
45
+ tags[`${get(varletConfig, 'namespace')}-${componentName}`] = {
46
+ attributes: table.attributesTable.map((row) => replaceDot(row[0])),
47
+ };
48
+ }
49
+ export function compileAttributes(table, attributes, componentName, varletConfig) {
50
+ table.attributesTable.forEach((row) => {
51
+ const attrNamespace = `${get(varletConfig, 'namespace')}-${componentName}/${replaceDot(row[0])}`;
52
+ attributes[attrNamespace] = {
53
+ type: replaceUnderline(row[2]),
54
+ description: `${row[1]} 默认值:${replaceDot(row[3])}`,
55
+ };
56
+ });
57
+ }
58
+ export function compileWebTypes(table, webTypes, componentName, varletConfig) {
59
+ const { attributesTable, eventsTable, slotsTable } = table;
60
+ const attributes = attributesTable.map((row) => ({
61
+ name: replaceDot(row[0]),
62
+ description: row[1],
63
+ default: replaceDot(row[3]),
64
+ value: {
65
+ type: replaceUnderline(row[2]),
66
+ kind: 'expression',
67
+ },
68
+ }));
69
+ const events = eventsTable.map((row) => ({
70
+ name: replaceDot(row[0]),
71
+ description: row[1],
72
+ }));
73
+ const slots = slotsTable.map((row) => ({
74
+ name: replaceDot(row[0]),
75
+ description: row[1],
76
+ }));
77
+ webTypes.contributions.html.tags.push({
78
+ name: `${get(varletConfig, 'namespace')}-${componentName}`,
79
+ attributes,
80
+ events,
81
+ slots,
82
+ });
83
+ }
84
+ export function compileMD(path, tags, attributes, webTypes, varletConfig) {
85
+ if (!path.endsWith(HL_MD)) {
86
+ return;
87
+ }
88
+ const md = readFileSync(path, 'utf-8');
89
+ const componentName = path.match(HL_COMPONENT_NAME_RE)[2];
90
+ const attributesTable = parseTable(compileTable(md, HL_TITLE_ATTRIBUTES_RE));
91
+ const eventsTable = parseTable(compileTable(md, HL_TITLE_EVENTS_RE));
92
+ const slotsTable = parseTable(compileTable(md, HL_TITLE_SLOTS_RE));
93
+ const table = {
94
+ attributesTable,
95
+ eventsTable,
96
+ slotsTable,
97
+ };
98
+ compileWebTypes(table, webTypes, componentName, varletConfig);
99
+ compileTags(table, tags, componentName, varletConfig);
100
+ compileAttributes(table, attributes, componentName, varletConfig);
101
+ }
102
+ export function compileDir(path, tags, attributes, webTypes, varletConfig) {
103
+ const dir = readdirSync(path);
104
+ dir.forEach((filename) => {
105
+ const filePath = resolve(path, filename);
106
+ isDir(filePath) && compileDir(filePath, tags, attributes, webTypes, varletConfig);
107
+ isMD(filePath) && compileMD(filePath, tags, attributes, webTypes, varletConfig);
108
+ });
109
+ }
110
+ export async function compileTemplateHighlight() {
111
+ await ensureDir(HL_DIR);
112
+ const varletConfig = await getVarletConfig();
113
+ const tags = {};
114
+ const attributes = {};
115
+ const webTypes = {
116
+ $schema: 'https://raw.githubusercontent.com/JetBrains/web-types/master/schema/web-types.json',
117
+ framework: 'vue',
118
+ version: readJSONSync(CLI_PACKAGE_JSON).version,
119
+ name: get(varletConfig, 'title'),
120
+ contributions: {
121
+ html: {
122
+ tags: [],
123
+ 'types-syntax': 'typescript',
124
+ },
125
+ },
126
+ };
127
+ compileDir(SRC_DIR, tags, attributes, webTypes, varletConfig);
128
+ await Promise.all([
129
+ writeFile(HL_WEB_TYPES_JSON, JSON.stringify(webTypes, null, 2)),
130
+ writeFile(HL_TAGS_JSON, JSON.stringify(tags, null, 2)),
131
+ writeFile(HL_ATTRIBUTES_JSON, JSON.stringify(attributes, null, 2)),
132
+ ]);
133
+ }
@@ -1,2 +1,2 @@
1
- export declare function generateReference(moduleDir: string): void;
2
- export declare function compileTypes(): Promise<void>;
1
+ export declare function generateReference(moduleDir: string): void;
2
+ export declare function compileTypes(): Promise<void>;