@varlet/cli 2.10.0 → 2.10.1-alpha.1682608027166
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.
- package/lib/client/appType.d.ts +4 -4
- package/lib/client/appType.js +7 -7
- package/lib/client/index.d.ts +18 -18
- package/lib/client/index.js +109 -109
- package/lib/node/bin.d.ts +2 -2
- package/lib/node/bin.js +148 -148
- package/lib/node/commands/build.d.ts +1 -1
- package/lib/node/commands/build.js +15 -15
- package/lib/node/commands/changelog.d.ts +5 -5
- package/lib/node/commands/changelog.js +20 -20
- package/lib/node/commands/checklist.d.ts +6 -6
- package/lib/node/commands/checklist.js +64 -64
- package/lib/node/commands/commitLint.d.ts +4 -4
- package/lib/node/commands/commitLint.js +19 -19
- package/lib/node/commands/compile.d.ts +3 -3
- package/lib/node/commands/compile.js +31 -31
- package/lib/node/commands/create.d.ts +7 -7
- package/lib/node/commands/create.js +91 -91
- package/lib/node/commands/dev.d.ts +6 -6
- package/lib/node/commands/dev.js +42 -42
- package/lib/node/commands/extension.d.ts +3 -3
- package/lib/node/commands/extension.js +5 -5
- package/lib/node/commands/gen.d.ts +7 -7
- package/lib/node/commands/gen.js +68 -68
- package/lib/node/commands/icons.d.ts +1 -1
- package/lib/node/commands/icons.js +82 -82
- package/lib/node/commands/jest.d.ts +7 -7
- package/lib/node/commands/jest.js +27 -27
- package/lib/node/commands/lint.d.ts +1 -1
- package/lib/node/commands/lint.js +42 -42
- package/lib/node/commands/preview.d.ts +1 -1
- package/lib/node/commands/preview.js +18 -18
- package/lib/node/commands/release.d.ts +5 -5
- package/lib/node/commands/release.js +150 -150
- package/lib/node/commands/vite.d.ts +2 -2
- package/lib/node/commands/vite.js +14 -14
- package/lib/node/compiler/compileModule.d.ts +4 -4
- package/lib/node/compiler/compileModule.js +71 -71
- package/lib/node/compiler/compileSFC.d.ts +6 -6
- package/lib/node/compiler/compileSFC.js +97 -96
- package/lib/node/compiler/compileScript.d.ts +13 -13
- package/lib/node/compiler/compileScript.js +126 -126
- package/lib/node/compiler/compileSiteEntry.d.ts +18 -18
- package/lib/node/compiler/compileSiteEntry.js +121 -121
- package/lib/node/compiler/compileStyle.d.ts +10 -10
- package/lib/node/compiler/compileStyle.js +41 -41
- package/lib/node/compiler/compileTemplateHighlight.d.ts +18 -18
- package/lib/node/compiler/compileTemplateHighlight.js +128 -128
- package/lib/node/compiler/compileTypes.d.ts +2 -2
- package/lib/node/compiler/compileTypes.js +40 -40
- package/lib/node/config/varlet.config.d.ts +73 -73
- package/lib/node/config/varlet.config.js +27 -27
- package/lib/node/config/varlet.default.config.d.ts +2 -2
- package/lib/node/config/varlet.default.config.js +271 -271
- package/lib/node/config/vite.config.d.ts +13 -13
- package/lib/node/config/vite.config.js +115 -115
- package/lib/node/index.d.ts +15 -15
- package/lib/node/index.js +15 -15
- package/lib/node/shared/constant.d.ts +51 -51
- package/lib/node/shared/constant.js +58 -58
- package/lib/node/shared/fsUtils.d.ts +15 -15
- package/lib/node/shared/fsUtils.js +54 -54
- package/lib/node/shared/logger.d.ts +8 -8
- package/lib/node/shared/logger.js +18 -18
- package/package.json +7 -7
|
@@ -1,96 +1,97 @@
|
|
|
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, compileScript as compileScriptSFC } from '@vue/compiler-sfc';
|
|
5
|
-
import { replaceExt, smartAppendFileSync } from '../shared/fsUtils.js';
|
|
6
|
-
import { compileScript, getScriptExtname } from './compileScript.js';
|
|
7
|
-
import { clearEmptyLine, compileLess, extractStyleDependencies, normalizeStyleDependency, STYLE_IMPORT_RE, } from './compileStyle.js';
|
|
8
|
-
const { readFile, writeFileSync } = fse;
|
|
9
|
-
const EXPORT = 'export default';
|
|
10
|
-
const SFC = '__sfc__';
|
|
11
|
-
const SFC_DECLARE = `const ${SFC} = `;
|
|
12
|
-
const RENDER = '__render__';
|
|
13
|
-
export function declareEmptySFC() {
|
|
14
|
-
return `${SFC_DECLARE}{}\n`;
|
|
15
|
-
}
|
|
16
|
-
export function replaceExportToDeclare(script) {
|
|
17
|
-
return script.replace(EXPORT, SFC_DECLARE);
|
|
18
|
-
}
|
|
19
|
-
export function injectExport(script) {
|
|
20
|
-
script += `\n${EXPORT} ${SFC}`;
|
|
21
|
-
return script;
|
|
22
|
-
}
|
|
23
|
-
export function injectScopeId(script, scopeId) {
|
|
24
|
-
script += `\n${SFC}.__scopeId = '${scopeId}'`;
|
|
25
|
-
return script;
|
|
26
|
-
}
|
|
27
|
-
export function injectRender(script, render) {
|
|
28
|
-
script = script.trim();
|
|
29
|
-
render = render.replace('export function render', `function ${RENDER}`);
|
|
30
|
-
script = script.replace(SFC_DECLARE, `${render}\n${SFC_DECLARE}`);
|
|
31
|
-
script += `\n${SFC}.render = ${RENDER}`;
|
|
32
|
-
return script;
|
|
33
|
-
}
|
|
34
|
-
export async function compileSFC(sfc) {
|
|
35
|
-
const sources = await readFile(sfc, 'utf-8');
|
|
36
|
-
const id = hash(sources);
|
|
37
|
-
const { descriptor } = parseSFC(sources, { sourceMap: false });
|
|
38
|
-
const { script, scriptSetup, template, styles } = descriptor;
|
|
39
|
-
let scriptContent;
|
|
40
|
-
let bindingMetadata;
|
|
41
|
-
if (script || scriptSetup) {
|
|
42
|
-
if (scriptSetup) {
|
|
43
|
-
const { content, bindings } = compileScriptSFC(descriptor, { id });
|
|
44
|
-
scriptContent = content;
|
|
45
|
-
bindingMetadata = bindings;
|
|
46
|
-
}
|
|
47
|
-
else {
|
|
48
|
-
// script only
|
|
49
|
-
scriptContent = script.content;
|
|
50
|
-
}
|
|
51
|
-
scriptContent = replaceExportToDeclare(scriptContent);
|
|
52
|
-
}
|
|
53
|
-
if (!scriptContent) {
|
|
54
|
-
scriptContent = declareEmptySFC();
|
|
55
|
-
}
|
|
56
|
-
// scoped
|
|
57
|
-
const hasScope = styles.some((style) => style.scoped);
|
|
58
|
-
const scopeId = hasScope ? `data-v-${id}` : '';
|
|
59
|
-
if (template) {
|
|
60
|
-
const render = compileTemplate({
|
|
61
|
-
id,
|
|
62
|
-
source: template.content,
|
|
63
|
-
filename: sfc,
|
|
64
|
-
compilerOptions: {
|
|
65
|
-
scopeId,
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
const
|
|
80
|
-
const
|
|
81
|
-
const
|
|
82
|
-
const
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
}
|
|
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, compileScript as compileScriptSFC } from '@vue/compiler-sfc';
|
|
5
|
+
import { replaceExt, smartAppendFileSync } from '../shared/fsUtils.js';
|
|
6
|
+
import { compileScript, getScriptExtname } from './compileScript.js';
|
|
7
|
+
import { clearEmptyLine, compileLess, extractStyleDependencies, normalizeStyleDependency, STYLE_IMPORT_RE, } from './compileStyle.js';
|
|
8
|
+
const { readFile, writeFileSync } = fse;
|
|
9
|
+
const EXPORT = 'export default';
|
|
10
|
+
const SFC = '__sfc__';
|
|
11
|
+
const SFC_DECLARE = `const ${SFC} = `;
|
|
12
|
+
const RENDER = '__render__';
|
|
13
|
+
export function declareEmptySFC() {
|
|
14
|
+
return `${SFC_DECLARE}{}\n`;
|
|
15
|
+
}
|
|
16
|
+
export function replaceExportToDeclare(script) {
|
|
17
|
+
return script.replace(EXPORT, SFC_DECLARE);
|
|
18
|
+
}
|
|
19
|
+
export function injectExport(script) {
|
|
20
|
+
script += `\n${EXPORT} ${SFC}`;
|
|
21
|
+
return script;
|
|
22
|
+
}
|
|
23
|
+
export function injectScopeId(script, scopeId) {
|
|
24
|
+
script += `\n${SFC}.__scopeId = '${scopeId}'`;
|
|
25
|
+
return script;
|
|
26
|
+
}
|
|
27
|
+
export function injectRender(script, render) {
|
|
28
|
+
script = script.trim();
|
|
29
|
+
render = render.replace('export function render', `function ${RENDER}`);
|
|
30
|
+
script = script.replace(SFC_DECLARE, `${render}\n${SFC_DECLARE}`);
|
|
31
|
+
script += `\n${SFC}.render = ${RENDER}`;
|
|
32
|
+
return script;
|
|
33
|
+
}
|
|
34
|
+
export async function compileSFC(sfc) {
|
|
35
|
+
const sources = await readFile(sfc, 'utf-8');
|
|
36
|
+
const id = hash(sources);
|
|
37
|
+
const { descriptor } = parseSFC(sources, { sourceMap: false });
|
|
38
|
+
const { script, scriptSetup, template, styles } = descriptor;
|
|
39
|
+
let scriptContent;
|
|
40
|
+
let bindingMetadata;
|
|
41
|
+
if (script || scriptSetup) {
|
|
42
|
+
if (scriptSetup) {
|
|
43
|
+
const { content, bindings } = compileScriptSFC(descriptor, { id });
|
|
44
|
+
scriptContent = content;
|
|
45
|
+
bindingMetadata = bindings;
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
// script only
|
|
49
|
+
scriptContent = script.content;
|
|
50
|
+
}
|
|
51
|
+
scriptContent = replaceExportToDeclare(scriptContent);
|
|
52
|
+
}
|
|
53
|
+
if (!scriptContent) {
|
|
54
|
+
scriptContent = declareEmptySFC();
|
|
55
|
+
}
|
|
56
|
+
// scoped
|
|
57
|
+
const hasScope = styles.some((style) => style.scoped);
|
|
58
|
+
const scopeId = hasScope ? `data-v-${id}` : '';
|
|
59
|
+
if (template) {
|
|
60
|
+
const render = compileTemplate({
|
|
61
|
+
id,
|
|
62
|
+
source: template.content,
|
|
63
|
+
filename: sfc,
|
|
64
|
+
compilerOptions: {
|
|
65
|
+
scopeId,
|
|
66
|
+
expressionPlugins: ['typescript'],
|
|
67
|
+
bindingMetadata,
|
|
68
|
+
},
|
|
69
|
+
}).code;
|
|
70
|
+
scriptContent = injectRender(scriptContent, render);
|
|
71
|
+
}
|
|
72
|
+
if (scopeId) {
|
|
73
|
+
scriptContent = injectScopeId(scriptContent, scopeId);
|
|
74
|
+
}
|
|
75
|
+
scriptContent = injectExport(scriptContent);
|
|
76
|
+
await compileScript(scriptContent, sfc);
|
|
77
|
+
// style
|
|
78
|
+
for (let index = 0; index < styles.length; index++) {
|
|
79
|
+
const style = styles[index];
|
|
80
|
+
const file = replaceExt(sfc, `Sfc${index || ''}.${style.lang || 'css'}`);
|
|
81
|
+
const { base, dir } = parse(file);
|
|
82
|
+
const dependencyPath = normalizeStyleDependency(base, STYLE_IMPORT_RE);
|
|
83
|
+
const cssFile = resolve(dir, `./style/index${getScriptExtname()}`);
|
|
84
|
+
let { code } = compileStyle({
|
|
85
|
+
source: style.content,
|
|
86
|
+
filename: file,
|
|
87
|
+
id: scopeId,
|
|
88
|
+
scoped: style.scoped,
|
|
89
|
+
});
|
|
90
|
+
code = extractStyleDependencies(file, code, STYLE_IMPORT_RE);
|
|
91
|
+
writeFileSync(file, clearEmptyLine(code), 'utf-8');
|
|
92
|
+
smartAppendFileSync(cssFile, `import '${dependencyPath}.css'\n`);
|
|
93
|
+
if (style.lang === 'less') {
|
|
94
|
+
await compileLess(file);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
export declare const IMPORT_FROM_DEPENDENCE_RE: RegExp;
|
|
2
|
-
export declare const EXPORT_FROM_DEPENDENCE_RE: RegExp;
|
|
3
|
-
export declare const IMPORT_DEPENDENCE_RE: RegExp;
|
|
4
|
-
export declare const scriptExtNames: string[];
|
|
5
|
-
export declare const styleExtNames: string[];
|
|
6
|
-
export declare const scriptIndexes: string[];
|
|
7
|
-
export declare const styleIndexes: string[];
|
|
8
|
-
export declare const tryMatchExtname: (file: string, extname: string[]) => string | undefined;
|
|
9
|
-
export declare const resolveDependence: (file: string, script: string) => string;
|
|
10
|
-
export declare function compileScript(script: string, file: string): Promise<void>;
|
|
11
|
-
export declare function compileScriptFile(file: string): Promise<void>;
|
|
12
|
-
export declare function getScriptExtname(): string;
|
|
13
|
-
export declare function compileESEntry(dir: string, publicDirs: string[]): Promise<void>;
|
|
1
|
+
export declare const IMPORT_FROM_DEPENDENCE_RE: RegExp;
|
|
2
|
+
export declare const EXPORT_FROM_DEPENDENCE_RE: RegExp;
|
|
3
|
+
export declare const IMPORT_DEPENDENCE_RE: RegExp;
|
|
4
|
+
export declare const scriptExtNames: string[];
|
|
5
|
+
export declare const styleExtNames: string[];
|
|
6
|
+
export declare const scriptIndexes: string[];
|
|
7
|
+
export declare const styleIndexes: string[];
|
|
8
|
+
export declare const tryMatchExtname: (file: string, extname: string[]) => string | undefined;
|
|
9
|
+
export declare const resolveDependence: (file: string, script: string) => string;
|
|
10
|
+
export declare function compileScript(script: string, file: string): Promise<void>;
|
|
11
|
+
export declare function compileScriptFile(file: string): Promise<void>;
|
|
12
|
+
export declare function getScriptExtname(): string;
|
|
13
|
+
export declare function compileESEntry(dir: string, publicDirs: string[]): Promise<void>;
|
|
@@ -1,124 +1,124 @@
|
|
|
1
|
-
import fse from 'fs-extra';
|
|
2
|
-
import { transformAsync } from '@babel/core';
|
|
3
|
-
import { bigCamelize } from '@varlet/shared';
|
|
4
|
-
import { getVersion, isDir, replaceExt } from '../shared/fsUtils.js';
|
|
5
|
-
import { extractStyleDependencies, IMPORT_CSS_RE, IMPORT_LESS_RE } from './compileStyle.js';
|
|
6
|
-
import { resolve, extname, dirname } from 'path';
|
|
7
|
-
const { writeFileSync, readdirSync, readFileSync, removeSync, writeFile, pathExistsSync } = fse;
|
|
8
|
-
// https://regexr.com/765a4
|
|
9
|
-
export const IMPORT_FROM_DEPENDENCE_RE = /import\s+?[\w\s{},$*]+\s+from\s+?(".*?"|'.*?')/g;
|
|
10
|
-
// https://regexr.com/767e6
|
|
11
|
-
export const EXPORT_FROM_DEPENDENCE_RE = /export\s+?[\w\s{},$*]+\s+from\s+?(".*?"|'.*?')/g;
|
|
12
|
-
// https://regexr.com/764ve
|
|
13
|
-
export const IMPORT_DEPENDENCE_RE = /import\s+(".*?"|'.*?')/g;
|
|
14
|
-
export const scriptExtNames = ['.vue', '.ts', '.tsx', '.mjs', '.js', '.jsx'];
|
|
15
|
-
export const styleExtNames = ['.less', '.css'];
|
|
16
|
-
export const scriptIndexes = ['index.mjs', 'index.vue', 'index.ts', 'index.tsx', 'index.js', 'index.jsx'];
|
|
17
|
-
export const styleIndexes = ['index.less', 'index.css'];
|
|
18
|
-
export const tryMatchExtname = (file, extname) => {
|
|
19
|
-
// eslint-disable-next-line no-restricted-syntax
|
|
20
|
-
for (const ext of extname) {
|
|
21
|
-
const matched = `${file}${ext}`;
|
|
22
|
-
if (pathExistsSync(matched)) {
|
|
23
|
-
return ext;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
};
|
|
27
|
-
export const resolveDependence = (file, script) => {
|
|
28
|
-
const replacer = (source, dependence) => {
|
|
29
|
-
dependence = dependence.slice(1, dependence.length - 1);
|
|
30
|
-
const ext = extname(dependence);
|
|
31
|
-
const targetDependenceFile = resolve(dirname(file), dependence);
|
|
32
|
-
const scriptExtname = getScriptExtname();
|
|
33
|
-
const inNodeModules = !dependence.startsWith('.');
|
|
34
|
-
const done = (targetDependence) => source.replace(dependence, targetDependence);
|
|
35
|
-
if (inNodeModules) {
|
|
36
|
-
// e.g. @varlet/shared
|
|
37
|
-
return source;
|
|
38
|
-
}
|
|
39
|
-
if (ext) {
|
|
40
|
-
if (scriptExtNames.includes(ext)) {
|
|
41
|
-
// e.g. './a.vue' -> './a.mjs'
|
|
42
|
-
return done(dependence.replace(ext, scriptExtname));
|
|
43
|
-
}
|
|
44
|
-
if (styleExtNames.includes(ext)) {
|
|
45
|
-
// e.g. './a.css' -> './a.css' './a.less' -> './a.less'
|
|
46
|
-
return source;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
if (!ext) {
|
|
50
|
-
// e.g. ../button/props -> ../button/props.mjs
|
|
51
|
-
const matchedScript = tryMatchExtname(targetDependenceFile, scriptExtNames);
|
|
52
|
-
if (matchedScript) {
|
|
53
|
-
return done(`${dependence}${scriptExtname}`);
|
|
54
|
-
}
|
|
55
|
-
const matchedStyle = tryMatchExtname(targetDependenceFile, styleExtNames);
|
|
56
|
-
if (matchedStyle) {
|
|
57
|
-
return done(`${dependence}${matchedStyle}`);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
if (!ext && isDir(targetDependenceFile)) {
|
|
61
|
-
// e.g. ../button
|
|
62
|
-
const files = readdirSync(targetDependenceFile);
|
|
63
|
-
const hasScriptIndex = files.some((file) => scriptIndexes.some((name) => file.endsWith(name)));
|
|
64
|
-
if (hasScriptIndex) {
|
|
65
|
-
// e.g. -> ../button/index.mjs
|
|
66
|
-
return done(`${dependence}/index${scriptExtname}`);
|
|
67
|
-
}
|
|
68
|
-
const hasStyleIndex = files.some((file) => styleIndexes.some((name) => file.endsWith(name)));
|
|
69
|
-
if (hasStyleIndex) {
|
|
70
|
-
// e.g. -> ../button/index.css
|
|
71
|
-
return done(`${dependence}/index.css`);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
return '';
|
|
75
|
-
};
|
|
76
|
-
return script
|
|
77
|
-
.replace(IMPORT_FROM_DEPENDENCE_RE, replacer)
|
|
78
|
-
.replace(EXPORT_FROM_DEPENDENCE_RE, replacer)
|
|
79
|
-
.replace(IMPORT_DEPENDENCE_RE, replacer);
|
|
80
|
-
};
|
|
81
|
-
export async function compileScript(script, file) {
|
|
82
|
-
let { code } = (await transformAsync(script, {
|
|
83
|
-
filename: file,
|
|
84
|
-
}));
|
|
85
|
-
if (code) {
|
|
86
|
-
code = resolveDependence(file, code);
|
|
87
|
-
code = extractStyleDependencies(file, code, IMPORT_CSS_RE);
|
|
88
|
-
code = extractStyleDependencies(file, code, IMPORT_LESS_RE);
|
|
89
|
-
removeSync(file);
|
|
90
|
-
writeFileSync(replaceExt(file, getScriptExtname()), code, 'utf8');
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
export async function compileScriptFile(file) {
|
|
94
|
-
const sources = readFileSync(file, 'utf-8');
|
|
95
|
-
await compileScript(sources, file);
|
|
96
|
-
}
|
|
97
|
-
export function getScriptExtname() {
|
|
98
|
-
return '.mjs';
|
|
99
|
-
}
|
|
100
|
-
export async function compileESEntry(dir, publicDirs) {
|
|
101
|
-
const imports = [];
|
|
102
|
-
const plugins = [];
|
|
103
|
-
const exports = [];
|
|
104
|
-
const cssImports = [];
|
|
105
|
-
const publicComponents = [];
|
|
106
|
-
const scriptExtname = getScriptExtname();
|
|
107
|
-
publicDirs.forEach((dirname) => {
|
|
108
|
-
const publicComponent = bigCamelize(dirname);
|
|
109
|
-
const module = `'./${dirname}/index${scriptExtname}'`;
|
|
110
|
-
publicComponents.push(publicComponent);
|
|
111
|
-
imports.push(`import ${publicComponent} from ${module}`);
|
|
112
|
-
exports.push(`export * from ${module}`);
|
|
113
|
-
plugins.push(`${publicComponent}.install && app.use(${publicComponent})`);
|
|
114
|
-
cssImports.push(`import './${dirname}/style/index${scriptExtname}'`);
|
|
115
|
-
});
|
|
1
|
+
import fse from 'fs-extra';
|
|
2
|
+
import { transformAsync } from '@babel/core';
|
|
3
|
+
import { bigCamelize } from '@varlet/shared';
|
|
4
|
+
import { getVersion, isDir, replaceExt } from '../shared/fsUtils.js';
|
|
5
|
+
import { extractStyleDependencies, IMPORT_CSS_RE, IMPORT_LESS_RE } from './compileStyle.js';
|
|
6
|
+
import { resolve, extname, dirname } from 'path';
|
|
7
|
+
const { writeFileSync, readdirSync, readFileSync, removeSync, writeFile, pathExistsSync } = fse;
|
|
8
|
+
// https://regexr.com/765a4
|
|
9
|
+
export const IMPORT_FROM_DEPENDENCE_RE = /import\s+?[\w\s{},$*]+\s+from\s+?(".*?"|'.*?')/g;
|
|
10
|
+
// https://regexr.com/767e6
|
|
11
|
+
export const EXPORT_FROM_DEPENDENCE_RE = /export\s+?[\w\s{},$*]+\s+from\s+?(".*?"|'.*?')/g;
|
|
12
|
+
// https://regexr.com/764ve
|
|
13
|
+
export const IMPORT_DEPENDENCE_RE = /import\s+(".*?"|'.*?')/g;
|
|
14
|
+
export const scriptExtNames = ['.vue', '.ts', '.tsx', '.mjs', '.js', '.jsx'];
|
|
15
|
+
export const styleExtNames = ['.less', '.css'];
|
|
16
|
+
export const scriptIndexes = ['index.mjs', 'index.vue', 'index.ts', 'index.tsx', 'index.js', 'index.jsx'];
|
|
17
|
+
export const styleIndexes = ['index.less', 'index.css'];
|
|
18
|
+
export const tryMatchExtname = (file, extname) => {
|
|
19
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
20
|
+
for (const ext of extname) {
|
|
21
|
+
const matched = `${file}${ext}`;
|
|
22
|
+
if (pathExistsSync(matched)) {
|
|
23
|
+
return ext;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
export const resolveDependence = (file, script) => {
|
|
28
|
+
const replacer = (source, dependence) => {
|
|
29
|
+
dependence = dependence.slice(1, dependence.length - 1);
|
|
30
|
+
const ext = extname(dependence);
|
|
31
|
+
const targetDependenceFile = resolve(dirname(file), dependence);
|
|
32
|
+
const scriptExtname = getScriptExtname();
|
|
33
|
+
const inNodeModules = !dependence.startsWith('.');
|
|
34
|
+
const done = (targetDependence) => source.replace(dependence, targetDependence);
|
|
35
|
+
if (inNodeModules) {
|
|
36
|
+
// e.g. @varlet/shared
|
|
37
|
+
return source;
|
|
38
|
+
}
|
|
39
|
+
if (ext) {
|
|
40
|
+
if (scriptExtNames.includes(ext)) {
|
|
41
|
+
// e.g. './a.vue' -> './a.mjs'
|
|
42
|
+
return done(dependence.replace(ext, scriptExtname));
|
|
43
|
+
}
|
|
44
|
+
if (styleExtNames.includes(ext)) {
|
|
45
|
+
// e.g. './a.css' -> './a.css' './a.less' -> './a.less'
|
|
46
|
+
return source;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
if (!ext) {
|
|
50
|
+
// e.g. ../button/props -> ../button/props.mjs
|
|
51
|
+
const matchedScript = tryMatchExtname(targetDependenceFile, scriptExtNames);
|
|
52
|
+
if (matchedScript) {
|
|
53
|
+
return done(`${dependence}${scriptExtname}`);
|
|
54
|
+
}
|
|
55
|
+
const matchedStyle = tryMatchExtname(targetDependenceFile, styleExtNames);
|
|
56
|
+
if (matchedStyle) {
|
|
57
|
+
return done(`${dependence}${matchedStyle}`);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
if (!ext && isDir(targetDependenceFile)) {
|
|
61
|
+
// e.g. ../button
|
|
62
|
+
const files = readdirSync(targetDependenceFile);
|
|
63
|
+
const hasScriptIndex = files.some((file) => scriptIndexes.some((name) => file.endsWith(name)));
|
|
64
|
+
if (hasScriptIndex) {
|
|
65
|
+
// e.g. -> ../button/index.mjs
|
|
66
|
+
return done(`${dependence}/index${scriptExtname}`);
|
|
67
|
+
}
|
|
68
|
+
const hasStyleIndex = files.some((file) => styleIndexes.some((name) => file.endsWith(name)));
|
|
69
|
+
if (hasStyleIndex) {
|
|
70
|
+
// e.g. -> ../button/index.css
|
|
71
|
+
return done(`${dependence}/index.css`);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return '';
|
|
75
|
+
};
|
|
76
|
+
return script
|
|
77
|
+
.replace(IMPORT_FROM_DEPENDENCE_RE, replacer)
|
|
78
|
+
.replace(EXPORT_FROM_DEPENDENCE_RE, replacer)
|
|
79
|
+
.replace(IMPORT_DEPENDENCE_RE, replacer);
|
|
80
|
+
};
|
|
81
|
+
export async function compileScript(script, file) {
|
|
82
|
+
let { code } = (await transformAsync(script, {
|
|
83
|
+
filename: file,
|
|
84
|
+
}));
|
|
85
|
+
if (code) {
|
|
86
|
+
code = resolveDependence(file, code);
|
|
87
|
+
code = extractStyleDependencies(file, code, IMPORT_CSS_RE);
|
|
88
|
+
code = extractStyleDependencies(file, code, IMPORT_LESS_RE);
|
|
89
|
+
removeSync(file);
|
|
90
|
+
writeFileSync(replaceExt(file, getScriptExtname()), code, 'utf8');
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
export async function compileScriptFile(file) {
|
|
94
|
+
const sources = readFileSync(file, 'utf-8');
|
|
95
|
+
await compileScript(sources, file);
|
|
96
|
+
}
|
|
97
|
+
export function getScriptExtname() {
|
|
98
|
+
return '.mjs';
|
|
99
|
+
}
|
|
100
|
+
export async function compileESEntry(dir, publicDirs) {
|
|
101
|
+
const imports = [];
|
|
102
|
+
const plugins = [];
|
|
103
|
+
const exports = [];
|
|
104
|
+
const cssImports = [];
|
|
105
|
+
const publicComponents = [];
|
|
106
|
+
const scriptExtname = getScriptExtname();
|
|
107
|
+
publicDirs.forEach((dirname) => {
|
|
108
|
+
const publicComponent = bigCamelize(dirname);
|
|
109
|
+
const module = `'./${dirname}/index${scriptExtname}'`;
|
|
110
|
+
publicComponents.push(publicComponent);
|
|
111
|
+
imports.push(`import ${publicComponent} from ${module}`);
|
|
112
|
+
exports.push(`export * from ${module}`);
|
|
113
|
+
plugins.push(`${publicComponent}.install && app.use(${publicComponent})`);
|
|
114
|
+
cssImports.push(`import './${dirname}/style/index${scriptExtname}'`);
|
|
115
|
+
});
|
|
116
116
|
const install = `
|
|
117
117
|
function install(app) {
|
|
118
118
|
${plugins.join('\n ')}
|
|
119
119
|
}
|
|
120
|
-
`;
|
|
121
|
-
const version = `const version = '${getVersion()}'`;
|
|
120
|
+
`;
|
|
121
|
+
const version = `const version = '${getVersion()}'`;
|
|
122
122
|
const indexTemplate = `\
|
|
123
123
|
${imports.join('\n')}\n
|
|
124
124
|
${exports.join('\n')}\n
|
|
@@ -135,10 +135,10 @@ export default {
|
|
|
135
135
|
install,
|
|
136
136
|
${publicComponents.join(',\n ')}
|
|
137
137
|
}
|
|
138
|
-
`;
|
|
138
|
+
`;
|
|
139
139
|
const styleTemplate = `\
|
|
140
140
|
${cssImports.join('\n')}
|
|
141
|
-
`;
|
|
141
|
+
`;
|
|
142
142
|
const bundleTemplate = `\
|
|
143
143
|
${imports.join('\n')}\n
|
|
144
144
|
${exports.join('\n')}\n
|
|
@@ -156,10 +156,10 @@ export default {
|
|
|
156
156
|
install,
|
|
157
157
|
${publicComponents.join(',\n ')}
|
|
158
158
|
}
|
|
159
|
-
`;
|
|
160
|
-
await Promise.all([
|
|
161
|
-
writeFile(resolve(dir, 'index.mjs'), indexTemplate, 'utf-8'),
|
|
162
|
-
writeFile(resolve(dir, 'index.bundle.mjs'), bundleTemplate, 'utf-8'),
|
|
163
|
-
writeFile(resolve(dir, 'style.mjs'), styleTemplate, 'utf-8'),
|
|
164
|
-
]);
|
|
165
|
-
}
|
|
159
|
+
`;
|
|
160
|
+
await Promise.all([
|
|
161
|
+
writeFile(resolve(dir, 'index.mjs'), indexTemplate, 'utf-8'),
|
|
162
|
+
writeFile(resolve(dir, 'index.bundle.mjs'), bundleTemplate, 'utf-8'),
|
|
163
|
+
writeFile(resolve(dir, 'style.mjs'), styleTemplate, 'utf-8'),
|
|
164
|
+
]);
|
|
165
|
+
}
|
|
@@ -1,18 +1,18 @@
|
|
|
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 getPageRoutePath(rootLocalePath: string): string;
|
|
5
|
-
export declare function getPageFilePath(rootLocalePath: string): string;
|
|
6
|
-
export declare function isDraftExample(example: string): boolean;
|
|
7
|
-
export declare function hasDraftExample(examples: string[], example: string): boolean;
|
|
8
|
-
export declare function isDraftDoc(doc: string): boolean;
|
|
9
|
-
export declare function hasDraftDoc(docs: string[], doc: string): boolean;
|
|
10
|
-
export declare function findExamples(draftMode: boolean): Promise<string[]>;
|
|
11
|
-
export declare function filterDraftDocs(docs: string[], draftMode: boolean): string[];
|
|
12
|
-
export declare function findComponentDocs(draftMode: boolean): Promise<string[]>;
|
|
13
|
-
export declare function findRootDocs(draftMode: boolean): Promise<string[]>;
|
|
14
|
-
export declare function findPageLocales(): Promise<string[]>;
|
|
15
|
-
export declare function buildMobileSiteRoutes(draftMode: boolean): Promise<void>;
|
|
16
|
-
export declare function buildPcSiteRoutes(draftMode: boolean): Promise<void>;
|
|
17
|
-
export declare function buildSiteSource(): Promise<void>;
|
|
18
|
-
export declare function buildSiteEntry(draftMode: boolean): 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 getPageRoutePath(rootLocalePath: string): string;
|
|
5
|
+
export declare function getPageFilePath(rootLocalePath: string): string;
|
|
6
|
+
export declare function isDraftExample(example: string): boolean;
|
|
7
|
+
export declare function hasDraftExample(examples: string[], example: string): boolean;
|
|
8
|
+
export declare function isDraftDoc(doc: string): boolean;
|
|
9
|
+
export declare function hasDraftDoc(docs: string[], doc: string): boolean;
|
|
10
|
+
export declare function findExamples(draftMode: boolean): Promise<string[]>;
|
|
11
|
+
export declare function filterDraftDocs(docs: string[], draftMode: boolean): string[];
|
|
12
|
+
export declare function findComponentDocs(draftMode: boolean): Promise<string[]>;
|
|
13
|
+
export declare function findRootDocs(draftMode: boolean): Promise<string[]>;
|
|
14
|
+
export declare function findPageLocales(): Promise<string[]>;
|
|
15
|
+
export declare function buildMobileSiteRoutes(draftMode: boolean): Promise<void>;
|
|
16
|
+
export declare function buildPcSiteRoutes(draftMode: boolean): Promise<void>;
|
|
17
|
+
export declare function buildSiteSource(): Promise<void>;
|
|
18
|
+
export declare function buildSiteEntry(draftMode: boolean): Promise<void>;
|