@varlet/cli 2.1.0 → 2.2.0-alpha.1667668287880

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
@@ -1,74 +1,74 @@
1
- import fse from 'fs-extra';
2
- import { build } from 'vite';
3
- import { resolve } from 'path';
4
- import { EXAMPLE_DIR_NAME, TESTS_DIR_NAME, DOCS_DIR_NAME, SRC_DIR, ES_DIR, STYLE_DIR_NAME, LIB_DIR, } from '../shared/constant.js';
5
- import { getPublicDirs, isDir, isDTS, isLess, isScript, isSFC } from '../shared/fsUtils.js';
6
- import { compileSFC } from './compileSFC.js';
7
- import { compileESEntry, compileCommonJSEntry, compileScriptFile } from './compileScript.js';
8
- import { compileLess } from './compileStyle.js';
9
- import { getESMBundleConfig, getUMDConfig } from '../config/vite.config.js';
10
- import { getVarletConfig } from '../config/varlet.config.js';
11
- import { generateReference } from './compileTypes.js';
12
- const { copy, ensureFileSync, readdir, removeSync } = fse;
13
- export function compileUMD() {
14
- return new Promise((resolve, reject) => {
15
- getVarletConfig().then((varletConfig) => {
16
- build(getUMDConfig(varletConfig))
17
- .then(() => resolve())
18
- .catch(reject);
19
- });
20
- });
21
- }
22
- export function compileESMBundle() {
23
- return new Promise((resolve, reject) => {
24
- getVarletConfig().then((varletConfig) => {
25
- build(getESMBundleConfig(varletConfig))
26
- .then(() => resolve())
27
- .catch(reject);
28
- });
29
- });
30
- }
31
- export async function compileDir(dir) {
32
- const dirs = await readdir(dir);
33
- await Promise.all(dirs.map((filename) => {
34
- const file = resolve(dir, filename);
35
- [TESTS_DIR_NAME, EXAMPLE_DIR_NAME, DOCS_DIR_NAME].includes(filename) && removeSync(file);
36
- if (isDTS(file) || filename === STYLE_DIR_NAME) {
37
- return Promise.resolve();
38
- }
39
- return compileFile(file);
40
- }));
41
- }
42
- export async function compileFile(file) {
43
- isSFC(file) && (await compileSFC(file));
44
- isScript(file) && (await compileScriptFile(file));
45
- isLess(file) && (await compileLess(file));
46
- isDir(file) && (await compileDir(file));
47
- }
48
- export async function compileModule(modules = false) {
49
- if (modules === 'umd') {
50
- await compileUMD();
51
- return;
52
- }
53
- if (modules === 'esm-bundle') {
54
- await compileESMBundle();
55
- return;
56
- }
57
- process.env.BABEL_MODULE = modules === 'commonjs' ? 'commonjs' : 'module';
58
- const dest = modules === 'commonjs' ? LIB_DIR : ES_DIR;
59
- await copy(SRC_DIR, dest);
60
- const moduleDir = await readdir(dest);
61
- await Promise.all(moduleDir.map((filename) => {
62
- const file = resolve(dest, filename);
63
- isDir(file) && ensureFileSync(resolve(file, './style/index.js'));
64
- return isDir(file) ? compileDir(file) : null;
65
- }));
66
- const publicDirs = await getPublicDirs();
67
- if (modules === 'commonjs') {
68
- await compileCommonJSEntry(dest, publicDirs);
69
- }
70
- else {
71
- await compileESEntry(dest, publicDirs);
72
- }
73
- generateReference(dest);
74
- }
1
+ import fse from 'fs-extra';
2
+ import { build } from 'vite';
3
+ import { resolve } from 'path';
4
+ import { EXAMPLE_DIR_NAME, TESTS_DIR_NAME, DOCS_DIR_NAME, SRC_DIR, ES_DIR, STYLE_DIR_NAME, LIB_DIR, } from '../shared/constant.js';
5
+ import { getPublicDirs, isDir, isDTS, isLess, isScript, isSFC } from '../shared/fsUtils.js';
6
+ import { compileSFC } from './compileSFC.js';
7
+ import { compileESEntry, compileCommonJSEntry, compileScriptFile } from './compileScript.js';
8
+ import { compileLess } from './compileStyle.js';
9
+ import { getESMBundleConfig, getUMDConfig } from '../config/vite.config.js';
10
+ import { getVarletConfig } from '../config/varlet.config.js';
11
+ import { generateReference } from './compileTypes.js';
12
+ const { copy, ensureFileSync, readdir, removeSync } = fse;
13
+ export function compileUMD() {
14
+ return new Promise((resolve, reject) => {
15
+ getVarletConfig().then((varletConfig) => {
16
+ build(getUMDConfig(varletConfig))
17
+ .then(() => resolve())
18
+ .catch(reject);
19
+ });
20
+ });
21
+ }
22
+ export function compileESMBundle() {
23
+ return new Promise((resolve, reject) => {
24
+ getVarletConfig().then((varletConfig) => {
25
+ build(getESMBundleConfig(varletConfig))
26
+ .then(() => resolve())
27
+ .catch(reject);
28
+ });
29
+ });
30
+ }
31
+ export async function compileDir(dir) {
32
+ const dirs = await readdir(dir);
33
+ await Promise.all(dirs.map((filename) => {
34
+ const file = resolve(dir, filename);
35
+ [TESTS_DIR_NAME, EXAMPLE_DIR_NAME, DOCS_DIR_NAME].includes(filename) && removeSync(file);
36
+ if (isDTS(file) || filename === STYLE_DIR_NAME) {
37
+ return Promise.resolve();
38
+ }
39
+ return compileFile(file);
40
+ }));
41
+ }
42
+ export async function compileFile(file) {
43
+ isSFC(file) && (await compileSFC(file));
44
+ isScript(file) && (await compileScriptFile(file));
45
+ isLess(file) && (await compileLess(file));
46
+ isDir(file) && (await compileDir(file));
47
+ }
48
+ export async function compileModule(modules = false) {
49
+ if (modules === 'umd') {
50
+ await compileUMD();
51
+ return;
52
+ }
53
+ if (modules === 'esm-bundle') {
54
+ await compileESMBundle();
55
+ return;
56
+ }
57
+ process.env.BABEL_MODULE = modules === 'commonjs' ? 'commonjs' : 'module';
58
+ const dest = modules === 'commonjs' ? LIB_DIR : ES_DIR;
59
+ await copy(SRC_DIR, dest);
60
+ const moduleDir = await readdir(dest);
61
+ await Promise.all(moduleDir.map((filename) => {
62
+ const file = resolve(dest, filename);
63
+ isDir(file) && ensureFileSync(resolve(file, './style/index.js'));
64
+ return isDir(file) ? compileDir(file) : null;
65
+ }));
66
+ const publicDirs = await getPublicDirs();
67
+ if (modules === 'commonjs') {
68
+ await compileCommonJSEntry(dest, publicDirs);
69
+ }
70
+ else {
71
+ await compileESEntry(dest, publicDirs);
72
+ }
73
+ generateReference(dest);
74
+ }
@@ -1,2 +1,2 @@
1
- export declare function injectRender(script: string, render: string): string;
2
- export declare function compileSFC(sfc: string): Promise<void>;
1
+ export declare function injectRender(script: string, render: string): string;
2
+ export declare function compileSFC(sfc: string): Promise<void>;
@@ -1,79 +1,79 @@
1
- import fse from 'fs-extra';
2
- import hash from 'hash-sum';
3
- import { parse, resolve } from 'path';
4
- import { parse as parseSFC, compileTemplate, compileStyle } from '@vue/compiler-sfc';
5
- import { replaceExt, smartAppendFileSync } from '../shared/fsUtils.js';
6
- import { compileScript } from './compileScript.js';
7
- import { clearEmptyLine, compileLess, extractStyleDependencies, normalizeStyleDependency, STYLE_IMPORT_RE, } from './compileStyle.js';
8
- import logger from '../shared/logger.js';
9
- const { readFile, writeFileSync } = fse;
10
- const NORMAL_EXPORT_START_RE = /export\s+default\s+{/;
11
- const DEFINE_EXPORT_START_RE = /export\s+default\s+defineComponent\s*\(\s*{/;
12
- export function injectRender(script, render) {
13
- if (DEFINE_EXPORT_START_RE.test(script.trim())) {
1
+ import fse from 'fs-extra';
2
+ import hash from 'hash-sum';
3
+ import { parse, resolve } from 'path';
4
+ import { parse as parseSFC, compileTemplate, compileStyle } from '@vue/compiler-sfc';
5
+ import { replaceExt, smartAppendFileSync } from '../shared/fsUtils.js';
6
+ import { compileScript } from './compileScript.js';
7
+ import { clearEmptyLine, compileLess, extractStyleDependencies, normalizeStyleDependency, STYLE_IMPORT_RE, } from './compileStyle.js';
8
+ import logger from '../shared/logger.js';
9
+ const { readFile, writeFileSync } = fse;
10
+ const NORMAL_EXPORT_START_RE = /export\s+default\s+{/;
11
+ const DEFINE_EXPORT_START_RE = /export\s+default\s+defineComponent\s*\(\s*{/;
12
+ export function injectRender(script, render) {
13
+ if (DEFINE_EXPORT_START_RE.test(script.trim())) {
14
14
  return script.trim().replace(DEFINE_EXPORT_START_RE, `${render}\nexport default defineComponent({
15
15
  render,\
16
- `);
17
- }
18
- if (NORMAL_EXPORT_START_RE.test(script.trim())) {
16
+ `);
17
+ }
18
+ if (NORMAL_EXPORT_START_RE.test(script.trim())) {
19
19
  return script.trim().replace(NORMAL_EXPORT_START_RE, `${render}\nexport default {
20
20
  render,\
21
- `);
22
- }
23
- return script;
24
- }
25
- export async function compileSFC(sfc) {
26
- const sources = await readFile(sfc, 'utf-8');
27
- const { descriptor } = parseSFC(sources, { sourceMap: false });
28
- const { script, scriptSetup, template, styles } = descriptor;
29
- if (scriptSetup) {
21
+ `);
22
+ }
23
+ return script;
24
+ }
25
+ export async function compileSFC(sfc) {
26
+ const sources = await readFile(sfc, 'utf-8');
27
+ const { descriptor } = parseSFC(sources, { sourceMap: false });
28
+ const { script, scriptSetup, template, styles } = descriptor;
29
+ if (scriptSetup) {
30
30
  logger.warning(`\n Varlet Cli does not support compiling script setup syntax\
31
- \n The error in ${sfc}`);
32
- return;
33
- }
34
- // scoped
35
- const hasScope = styles.some((style) => style.scoped);
36
- const id = hash(sources);
37
- const scopeId = hasScope ? `data-v-${id}` : '';
38
- if (script) {
39
- // template
40
- const render = template &&
41
- compileTemplate({
42
- id,
43
- source: template.content,
44
- filename: sfc,
45
- compilerOptions: {
46
- scopeId,
47
- },
48
- });
49
- let { content } = script;
50
- if (render) {
51
- const { code } = render;
52
- content = injectRender(content, code);
53
- }
54
- // script
55
- await compileScript(content, sfc);
56
- // style
57
- for (let index = 0; index < styles.length; index++) {
58
- const style = styles[index];
59
- const file = replaceExt(sfc, `Sfc${index || ''}.${style.lang || 'css'}`);
60
- const { base, dir } = parse(file);
61
- const dependencyPath = normalizeStyleDependency(base, STYLE_IMPORT_RE);
62
- const cssFile = resolve(dir, './style/index.js');
63
- let { code } = compileStyle({
64
- source: style.content,
65
- filename: file,
66
- id: scopeId,
67
- scoped: style.scoped,
68
- });
69
- code = extractStyleDependencies(file, code, STYLE_IMPORT_RE);
70
- writeFileSync(file, clearEmptyLine(code), 'utf-8');
71
- smartAppendFileSync(cssFile, process.env.BABEL_MODULE === 'commonjs'
72
- ? `require('${dependencyPath}.css')\n`
73
- : `import '${dependencyPath}.css'\n`);
74
- if (style.lang === 'less') {
75
- await compileLess(file);
76
- }
77
- }
78
- }
79
- }
31
+ \n The error in ${sfc}`);
32
+ return;
33
+ }
34
+ // scoped
35
+ const hasScope = styles.some((style) => style.scoped);
36
+ const id = hash(sources);
37
+ const scopeId = hasScope ? `data-v-${id}` : '';
38
+ if (script) {
39
+ // template
40
+ const render = template &&
41
+ compileTemplate({
42
+ id,
43
+ source: template.content,
44
+ filename: sfc,
45
+ compilerOptions: {
46
+ scopeId,
47
+ },
48
+ });
49
+ let { content } = script;
50
+ if (render) {
51
+ const { code } = render;
52
+ content = injectRender(content, code);
53
+ }
54
+ // script
55
+ await compileScript(content, sfc);
56
+ // style
57
+ for (let index = 0; index < styles.length; index++) {
58
+ const style = styles[index];
59
+ const file = replaceExt(sfc, `Sfc${index || ''}.${style.lang || 'css'}`);
60
+ const { base, dir } = parse(file);
61
+ const dependencyPath = normalizeStyleDependency(base, STYLE_IMPORT_RE);
62
+ const cssFile = resolve(dir, './style/index.js');
63
+ let { code } = compileStyle({
64
+ source: style.content,
65
+ filename: file,
66
+ id: scopeId,
67
+ scoped: style.scoped,
68
+ });
69
+ code = extractStyleDependencies(file, code, STYLE_IMPORT_RE);
70
+ writeFileSync(file, clearEmptyLine(code), 'utf-8');
71
+ smartAppendFileSync(cssFile, process.env.BABEL_MODULE === 'commonjs'
72
+ ? `require('${dependencyPath}.css')\n`
73
+ : `import '${dependencyPath}.css'\n`);
74
+ if (style.lang === 'less') {
75
+ await compileLess(file);
76
+ }
77
+ }
78
+ }
79
+ }
@@ -1,17 +1,17 @@
1
- export declare const IMPORT_VUE_PATH_RE: RegExp;
2
- export declare const IMPORT_TS_PATH_RE: RegExp;
3
- export declare const IMPORT_JSX_PATH_RE: RegExp;
4
- export declare const IMPORT_TSX_PATH_RE: RegExp;
5
- export declare const REQUIRE_VUE_PATH_RE: RegExp;
6
- export declare const REQUIRE_TS_PATH_RE: RegExp;
7
- export declare const REQUIRE_JSX_PATH_RE: RegExp;
8
- export declare const REQUIRE_TSX_PATH_RE: RegExp;
9
- export declare const replaceVueExt: (script: string) => string;
10
- export declare const replaceTSExt: (script: string) => string;
11
- export declare const replaceJSXExt: (script: string) => string;
12
- export declare const replaceTSXExt: (script: string) => string;
13
- export declare const moduleCompatible: (script: string) => Promise<string>;
14
- export declare function compileScript(script: string, file: string): Promise<void>;
15
- export declare function compileScriptFile(file: string): Promise<void>;
16
- export declare function compileESEntry(dir: string, publicDirs: string[]): Promise<void>;
17
- export declare function compileCommonJSEntry(dir: string, publicDirs: string[]): Promise<void>;
1
+ export declare const IMPORT_VUE_PATH_RE: RegExp;
2
+ export declare const IMPORT_TS_PATH_RE: RegExp;
3
+ export declare const IMPORT_JSX_PATH_RE: RegExp;
4
+ export declare const IMPORT_TSX_PATH_RE: RegExp;
5
+ export declare const REQUIRE_VUE_PATH_RE: RegExp;
6
+ export declare const REQUIRE_TS_PATH_RE: RegExp;
7
+ export declare const REQUIRE_JSX_PATH_RE: RegExp;
8
+ export declare const REQUIRE_TSX_PATH_RE: RegExp;
9
+ export declare const replaceVueExt: (script: string) => string;
10
+ export declare const replaceTSExt: (script: string) => string;
11
+ export declare const replaceJSXExt: (script: string) => string;
12
+ export declare const replaceTSXExt: (script: string) => string;
13
+ export declare const moduleCompatible: (script: string) => Promise<string>;
14
+ export declare function compileScript(script: string, file: string): Promise<void>;
15
+ export declare function compileScriptFile(file: string): Promise<void>;
16
+ export declare function compileESEntry(dir: string, publicDirs: string[]): Promise<void>;
17
+ export declare function compileCommonJSEntry(dir: string, publicDirs: string[]): Promise<void>;
@@ -1,73 +1,73 @@
1
- import fse from 'fs-extra';
2
- import { transformAsync } from '@babel/core';
3
- import { bigCamelize } from '@varlet/shared';
4
- import { replaceExt } from '../shared/fsUtils.js';
5
- import { extractStyleDependencies, IMPORT_CSS_RE, IMPORT_LESS_RE, REQUIRE_CSS_RE, REQUIRE_LESS_RE, } from './compileStyle.js';
6
- import { resolve } from 'path';
7
- import { get } from 'lodash-es';
8
- import { getVarletConfig } from '../config/varlet.config.js';
9
- const { writeFileSync, readFileSync, removeSync, writeFile } = fse;
10
- export const IMPORT_VUE_PATH_RE = /((?<!['"`])import\s+.+from\s+['"]\s*\.{1,2}\/.+)\.vue(\s*['"`]);?(?!\s*['"`])/g;
11
- export const IMPORT_TS_PATH_RE = /((?<!['"`])import\s+.+from\s+['"]\s*\.{1,2}\/.+)\.ts(\s*['"`]);?(?!\s*['"`])/g;
12
- export const IMPORT_JSX_PATH_RE = /((?<!['"`])import\s+.+from\s+['"]\s*\.{1,2}\/.+)\.jsx(\s*['"`]);?(?!\s*['"`])/g;
13
- export const IMPORT_TSX_PATH_RE = /((?<!['"`])import\s+.+from\s+['"]\s*\.{1,2}\/.+)\.tsx(\s*['"`]);?(?!\s*['"`])/g;
14
- export const REQUIRE_VUE_PATH_RE = /(?<!['"`]\s*)(require\s*\(\s*['"]\s*\.{1,2}\/.+)\.vue(\s*['"`]\))(?!\s*['"`])/g;
15
- export const REQUIRE_TS_PATH_RE = /(?<!['"`]\s*)(require\s*\(\s*['"]\s*\.{1,2}\/.+)\.ts(\s*['"`]\))(?!\s*['"`])/g;
16
- export const REQUIRE_JSX_PATH_RE = /(?<!['"`]\s*)(require\s*\(\s*['"]\s*\.{1,2}\/.+)\.jsx(\s*['"`]\))(?!\s*['"`])/g;
17
- export const REQUIRE_TSX_PATH_RE = /(?<!['"`]\s*)(require\s*\(\s*['"]\s*\.{1,2}\/.+)\.tsx(\s*['"`]\))(?!\s*['"`])/g;
18
- const scriptReplacer = (_, p1, p2) => `${p1}.js${p2}`;
19
- export const replaceVueExt = (script) => script.replace(IMPORT_VUE_PATH_RE, scriptReplacer).replace(REQUIRE_VUE_PATH_RE, scriptReplacer);
20
- export const replaceTSExt = (script) => script.replace(IMPORT_TS_PATH_RE, scriptReplacer).replace(REQUIRE_TS_PATH_RE, scriptReplacer);
21
- export const replaceJSXExt = (script) => script.replace(IMPORT_JSX_PATH_RE, scriptReplacer).replace(REQUIRE_JSX_PATH_RE, scriptReplacer);
22
- export const replaceTSXExt = (script) => script.replace(IMPORT_TSX_PATH_RE, scriptReplacer).replace(REQUIRE_TSX_PATH_RE, scriptReplacer);
23
- export const moduleCompatible = async (script) => {
24
- const moduleCompatible = get(await getVarletConfig(), 'moduleCompatible', {});
25
- Object.keys(moduleCompatible).forEach((esm) => {
26
- const commonjs = moduleCompatible[esm];
27
- script = script.replace(esm, commonjs);
28
- });
29
- return script;
30
- };
31
- export async function compileScript(script, file) {
32
- const modules = process.env.BABEL_MODULE;
33
- if (modules === 'commonjs') {
34
- script = await moduleCompatible(script);
35
- }
36
- let { code } = (await transformAsync(script, {
37
- filename: file,
38
- }));
39
- code = extractStyleDependencies(file, code, modules === 'commonjs' ? REQUIRE_CSS_RE : IMPORT_CSS_RE);
40
- code = extractStyleDependencies(file, code, modules === 'commonjs' ? REQUIRE_LESS_RE : IMPORT_LESS_RE);
41
- code = replaceVueExt(code);
42
- code = replaceTSXExt(code);
43
- code = replaceJSXExt(code);
44
- code = replaceTSExt(code);
45
- removeSync(file);
46
- writeFileSync(replaceExt(file, '.js'), code, 'utf8');
47
- }
48
- export async function compileScriptFile(file) {
49
- const sources = readFileSync(file, 'utf-8');
50
- await compileScript(sources, file);
51
- }
52
- export async function compileESEntry(dir, publicDirs) {
53
- const imports = [];
54
- const plugins = [];
55
- const constInternalComponents = [];
56
- const cssImports = [];
57
- const publicComponents = [];
58
- publicDirs.forEach((dirname) => {
59
- const publicComponent = bigCamelize(dirname);
60
- publicComponents.push(publicComponent);
61
- imports.push(`import ${publicComponent}, * as ${publicComponent}Module from './${dirname}'`);
62
- constInternalComponents.push(`export const _${publicComponent}Component = ${publicComponent}Module._${publicComponent}Component || {}`);
63
- plugins.push(`${publicComponent}.install && app.use(${publicComponent})`);
64
- cssImports.push(`import './${dirname}/style'`);
65
- });
1
+ import fse from 'fs-extra';
2
+ import { transformAsync } from '@babel/core';
3
+ import { bigCamelize } from '@varlet/shared';
4
+ import { replaceExt } from '../shared/fsUtils.js';
5
+ import { extractStyleDependencies, IMPORT_CSS_RE, IMPORT_LESS_RE, REQUIRE_CSS_RE, REQUIRE_LESS_RE, } from './compileStyle.js';
6
+ import { resolve } from 'path';
7
+ import { get } from 'lodash-es';
8
+ import { getVarletConfig } from '../config/varlet.config.js';
9
+ const { writeFileSync, readFileSync, removeSync, writeFile } = fse;
10
+ export const IMPORT_VUE_PATH_RE = /((?<!['"`])import\s+.+from\s+['"]\s*\.{1,2}\/.+)\.vue(\s*['"`]);?(?!\s*['"`])/g;
11
+ export const IMPORT_TS_PATH_RE = /((?<!['"`])import\s+.+from\s+['"]\s*\.{1,2}\/.+)\.ts(\s*['"`]);?(?!\s*['"`])/g;
12
+ export const IMPORT_JSX_PATH_RE = /((?<!['"`])import\s+.+from\s+['"]\s*\.{1,2}\/.+)\.jsx(\s*['"`]);?(?!\s*['"`])/g;
13
+ export const IMPORT_TSX_PATH_RE = /((?<!['"`])import\s+.+from\s+['"]\s*\.{1,2}\/.+)\.tsx(\s*['"`]);?(?!\s*['"`])/g;
14
+ export const REQUIRE_VUE_PATH_RE = /(?<!['"`]\s*)(require\s*\(\s*['"]\s*\.{1,2}\/.+)\.vue(\s*['"`]\))(?!\s*['"`])/g;
15
+ export const REQUIRE_TS_PATH_RE = /(?<!['"`]\s*)(require\s*\(\s*['"]\s*\.{1,2}\/.+)\.ts(\s*['"`]\))(?!\s*['"`])/g;
16
+ export const REQUIRE_JSX_PATH_RE = /(?<!['"`]\s*)(require\s*\(\s*['"]\s*\.{1,2}\/.+)\.jsx(\s*['"`]\))(?!\s*['"`])/g;
17
+ export const REQUIRE_TSX_PATH_RE = /(?<!['"`]\s*)(require\s*\(\s*['"]\s*\.{1,2}\/.+)\.tsx(\s*['"`]\))(?!\s*['"`])/g;
18
+ const scriptReplacer = (_, p1, p2) => `${p1}.js${p2}`;
19
+ export const replaceVueExt = (script) => script.replace(IMPORT_VUE_PATH_RE, scriptReplacer).replace(REQUIRE_VUE_PATH_RE, scriptReplacer);
20
+ export const replaceTSExt = (script) => script.replace(IMPORT_TS_PATH_RE, scriptReplacer).replace(REQUIRE_TS_PATH_RE, scriptReplacer);
21
+ export const replaceJSXExt = (script) => script.replace(IMPORT_JSX_PATH_RE, scriptReplacer).replace(REQUIRE_JSX_PATH_RE, scriptReplacer);
22
+ export const replaceTSXExt = (script) => script.replace(IMPORT_TSX_PATH_RE, scriptReplacer).replace(REQUIRE_TSX_PATH_RE, scriptReplacer);
23
+ export const moduleCompatible = async (script) => {
24
+ const moduleCompatible = get(await getVarletConfig(), 'moduleCompatible', {});
25
+ Object.keys(moduleCompatible).forEach((esm) => {
26
+ const commonjs = moduleCompatible[esm];
27
+ script = script.replace(esm, commonjs);
28
+ });
29
+ return script;
30
+ };
31
+ export async function compileScript(script, file) {
32
+ const modules = process.env.BABEL_MODULE;
33
+ if (modules === 'commonjs') {
34
+ script = await moduleCompatible(script);
35
+ }
36
+ let { code } = (await transformAsync(script, {
37
+ filename: file,
38
+ }));
39
+ code = extractStyleDependencies(file, code, modules === 'commonjs' ? REQUIRE_CSS_RE : IMPORT_CSS_RE);
40
+ code = extractStyleDependencies(file, code, modules === 'commonjs' ? REQUIRE_LESS_RE : IMPORT_LESS_RE);
41
+ code = replaceVueExt(code);
42
+ code = replaceTSXExt(code);
43
+ code = replaceJSXExt(code);
44
+ code = replaceTSExt(code);
45
+ removeSync(file);
46
+ writeFileSync(replaceExt(file, '.js'), code, 'utf8');
47
+ }
48
+ export async function compileScriptFile(file) {
49
+ const sources = readFileSync(file, 'utf-8');
50
+ await compileScript(sources, file);
51
+ }
52
+ export async function compileESEntry(dir, publicDirs) {
53
+ const imports = [];
54
+ const plugins = [];
55
+ const constInternalComponents = [];
56
+ const cssImports = [];
57
+ const publicComponents = [];
58
+ publicDirs.forEach((dirname) => {
59
+ const publicComponent = bigCamelize(dirname);
60
+ publicComponents.push(publicComponent);
61
+ imports.push(`import ${publicComponent}, * as ${publicComponent}Module from './${dirname}'`);
62
+ constInternalComponents.push(`export const _${publicComponent}Component = ${publicComponent}Module._${publicComponent}Component || {}`);
63
+ plugins.push(`${publicComponent}.install && app.use(${publicComponent})`);
64
+ cssImports.push(`import './${dirname}/style'`);
65
+ });
66
66
  const install = `
67
67
  function install(app) {
68
68
  ${plugins.join('\n ')}
69
69
  }
70
- `;
70
+ `;
71
71
  const indexTemplate = `\
72
72
  ${imports.join('\n')}\n
73
73
  ${constInternalComponents.join('\n')}\n
@@ -81,10 +81,10 @@ export default {
81
81
  install,
82
82
  ${publicComponents.join(',\n ')}
83
83
  }
84
- `;
84
+ `;
85
85
  const styleTemplate = `\
86
86
  ${cssImports.join('\n')}
87
- `;
87
+ `;
88
88
  const umdTemplate = `\
89
89
  ${imports.join('\n')}\n
90
90
  ${cssImports.join('\n')}\n
@@ -98,30 +98,30 @@ export default {
98
98
  install,
99
99
  ${publicComponents.join(',\n ')}
100
100
  }
101
- `;
102
- await Promise.all([
103
- writeFile(resolve(dir, 'index.js'), indexTemplate, 'utf-8'),
104
- writeFile(resolve(dir, 'umdIndex.js'), umdTemplate, 'utf-8'),
105
- writeFile(resolve(dir, 'style.js'), styleTemplate, 'utf-8'),
106
- ]);
107
- }
108
- export async function compileCommonJSEntry(dir, publicDirs) {
109
- const requires = [];
110
- const plugins = [];
111
- const cssRequires = [];
112
- const publicComponents = [];
113
- publicDirs.forEach((dirname) => {
114
- const publicComponent = bigCamelize(dirname);
115
- publicComponents.push(publicComponent);
116
- requires.push(`var ${publicComponent} = require('./${dirname}')['default']`);
117
- plugins.push(`${publicComponent}.install && app.use(${publicComponent})`);
118
- cssRequires.push(`require('./${dirname}/style')`);
119
- });
101
+ `;
102
+ await Promise.all([
103
+ writeFile(resolve(dir, 'index.js'), indexTemplate, 'utf-8'),
104
+ writeFile(resolve(dir, 'umdIndex.js'), umdTemplate, 'utf-8'),
105
+ writeFile(resolve(dir, 'style.js'), styleTemplate, 'utf-8'),
106
+ ]);
107
+ }
108
+ export async function compileCommonJSEntry(dir, publicDirs) {
109
+ const requires = [];
110
+ const plugins = [];
111
+ const cssRequires = [];
112
+ const publicComponents = [];
113
+ publicDirs.forEach((dirname) => {
114
+ const publicComponent = bigCamelize(dirname);
115
+ publicComponents.push(publicComponent);
116
+ requires.push(`var ${publicComponent} = require('./${dirname}')['default']`);
117
+ plugins.push(`${publicComponent}.install && app.use(${publicComponent})`);
118
+ cssRequires.push(`require('./${dirname}/style')`);
119
+ });
120
120
  const install = `
121
121
  function install(app) {
122
122
  ${plugins.join('\n ')}
123
123
  }
124
- `;
124
+ `;
125
125
  const indexTemplate = `\
126
126
  ${requires.join('\n')}\n
127
127
  ${install}
@@ -130,12 +130,12 @@ module.exports = {
130
130
  install,
131
131
  ${publicComponents.join(',\n ')}
132
132
  }
133
- `;
133
+ `;
134
134
  const styleTemplate = `\
135
135
  ${cssRequires.join('\n')}
136
- `;
137
- await Promise.all([
138
- writeFile(resolve(dir, 'index.js'), indexTemplate, 'utf-8'),
139
- writeFile(resolve(dir, 'style.js'), styleTemplate, 'utf-8'),
140
- ]);
141
- }
136
+ `;
137
+ await Promise.all([
138
+ writeFile(resolve(dir, 'index.js'), indexTemplate, 'utf-8'),
139
+ writeFile(resolve(dir, 'style.js'), styleTemplate, 'utf-8'),
140
+ ]);
141
+ }
@@ -1,13 +1,13 @@
1
- export declare function getExampleRoutePath(examplePath: string): string;
2
- export declare function getComponentDocRoutePath(componentDocsPath: string): string;
3
- export declare function getRootDocRoutePath(rootDocsPath: string): string;
4
- export declare function getRootRoutePath(rootLocalePath: string): string;
5
- export declare function getRootFilePath(rootLocalePath: string): string;
6
- export declare function findExamples(): Promise<string[]>;
7
- export declare function findComponentDocs(): Promise<string[]>;
8
- export declare function findRootDocs(): Promise<string[]>;
9
- export declare function findRootLocales(): Promise<string[]>;
10
- export declare function buildMobileSiteRoutes(): Promise<void>;
11
- export declare function buildPcSiteRoutes(): Promise<void>;
12
- export declare function buildSiteSource(): Promise<void>;
13
- export declare function buildSiteEntry(): Promise<void>;
1
+ export declare function getExampleRoutePath(examplePath: string): string;
2
+ export declare function getComponentDocRoutePath(componentDocsPath: string): string;
3
+ export declare function getRootDocRoutePath(rootDocsPath: string): string;
4
+ export declare function getRootRoutePath(rootLocalePath: string): string;
5
+ export declare function getRootFilePath(rootLocalePath: string): string;
6
+ export declare function findExamples(): Promise<string[]>;
7
+ export declare function findComponentDocs(): Promise<string[]>;
8
+ export declare function findRootDocs(): Promise<string[]>;
9
+ export declare function findRootLocales(): Promise<string[]>;
10
+ export declare function buildMobileSiteRoutes(): Promise<void>;
11
+ export declare function buildPcSiteRoutes(): Promise<void>;
12
+ export declare function buildSiteSource(): Promise<void>;
13
+ export declare function buildSiteEntry(): Promise<void>;