@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,136 +1,136 @@
|
|
|
1
|
-
import slash from 'slash';
|
|
2
|
-
import fse from 'fs-extra';
|
|
3
|
-
import { DOCS_DIR_NAME, 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 ROOT_DOCS_RE = /\/docs\/([-\w]+)\.([-\w]+)(?:.draft)?\.md/;
|
|
9
|
-
const PAGE_LOCALE_RE = /\/pages\/([-\w]+)\/locale\/([-\w]+)\.ts/;
|
|
10
|
-
const EXAMPLE_INDEX_RE = /\/([-\w]+)\/example\/index(?:.draft)?\.vue/;
|
|
11
|
-
const COMPONENT_DOCS_RE = /\/([-\w]+)\/docs\/([-\w]+)(?:.draft)?\.md/;
|
|
12
|
-
export function getExampleRoutePath(examplePath) {
|
|
13
|
-
var _a;
|
|
14
|
-
return '/' + ((_a = examplePath.match(EXAMPLE_INDEX_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 getPageRoutePath(rootLocalePath) {
|
|
27
|
-
var _a;
|
|
28
|
-
const [, routePath, language] = (_a = rootLocalePath.match(PAGE_LOCALE_RE)) !== null && _a !== void 0 ? _a : [];
|
|
29
|
-
return `/${language}/${routePath}`;
|
|
30
|
-
}
|
|
31
|
-
export function getPageFilePath(rootLocalePath) {
|
|
32
|
-
return rootLocalePath.replace(/locale\/.+/, 'index.vue');
|
|
33
|
-
}
|
|
34
|
-
export function isDraftExample(example) {
|
|
35
|
-
return example.endsWith('index.draft.vue');
|
|
36
|
-
}
|
|
37
|
-
export function hasDraftExample(examples, example) {
|
|
38
|
-
return examples.includes(example.replace('index.vue', 'index.draft.vue'));
|
|
39
|
-
}
|
|
40
|
-
export function isDraftDoc(doc) {
|
|
41
|
-
return doc.endsWith('.draft.md');
|
|
42
|
-
}
|
|
43
|
-
export function hasDraftDoc(docs, doc) {
|
|
44
|
-
return docs.includes(doc.replace('.md', '.draft.md'));
|
|
45
|
-
}
|
|
46
|
-
export async function findExamples(draftMode) {
|
|
47
|
-
const [examples, draftExamples] = await Promise.all([
|
|
48
|
-
glob(`${SRC_DIR}/**/${EXAMPLE_DIR_NAME}/index.vue`),
|
|
49
|
-
glob(`${SRC_DIR}/**/${EXAMPLE_DIR_NAME}/index.draft.vue`),
|
|
50
|
-
]);
|
|
51
|
-
const mergedExamples = [...examples, ...draftExamples];
|
|
52
|
-
return mergedExamples.filter((example) => {
|
|
53
|
-
return draftMode ? isDraftExample(example) || !hasDraftExample(mergedExamples, example) : !isDraftExample(example);
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
export function filterDraftDocs(docs, draftMode) {
|
|
57
|
-
return docs.filter((doc) => {
|
|
58
|
-
return draftMode ? isDraftDoc(doc) || !hasDraftDoc(docs, doc) : !isDraftDoc(doc);
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
export async function findComponentDocs(draftMode) {
|
|
62
|
-
const componentDocs = await glob(`${SRC_DIR}/**/${DOCS_DIR_NAME}/*.md`);
|
|
63
|
-
return filterDraftDocs(componentDocs, draftMode);
|
|
64
|
-
}
|
|
65
|
-
export async function findRootDocs(draftMode) {
|
|
66
|
-
const rootDocs = await glob(`${ROOT_DOCS_DIR}/*.md`);
|
|
67
|
-
return filterDraftDocs(rootDocs, draftMode);
|
|
68
|
-
}
|
|
69
|
-
export async function findPageLocales() {
|
|
70
|
-
const defaultLanguage = get(await getVarletConfig(), 'defaultLanguage');
|
|
71
|
-
const userPages = await glob(`${ROOT_PAGES_DIR}/*`);
|
|
72
|
-
const baseLocales = await glob(`${SITE}/pc/pages/**/${LOCALE_DIR_NAME}/*.ts`);
|
|
73
|
-
const userLocales = await userPages.reduce(async (userLocales, page) => {
|
|
74
|
-
if (isDir(page)) {
|
|
75
|
-
const locales = await glob(`${page}/${LOCALE_DIR_NAME}/*.ts`);
|
|
76
|
-
if (!locales.length)
|
|
77
|
-
locales.push(`${page}/${LOCALE_DIR_NAME}/${defaultLanguage}.ts`);
|
|
78
|
-
(await userLocales).push(...locales);
|
|
79
|
-
}
|
|
80
|
-
return userLocales;
|
|
81
|
-
}, Promise.resolve([]));
|
|
82
|
-
// filter
|
|
83
|
-
const filterMap = new Map();
|
|
84
|
-
baseLocales.forEach((locale) => {
|
|
85
|
-
var _a;
|
|
86
|
-
const [, routePath, language] = (_a = locale.match(PAGE_LOCALE_RE)) !== null && _a !== void 0 ? _a : [];
|
|
87
|
-
filterMap.set(routePath + language, slash(`${SITE_PC_DIR}/pages/${routePath}/locale/${language}.ts`));
|
|
88
|
-
});
|
|
89
|
-
userLocales.forEach((locale) => {
|
|
90
|
-
var _a;
|
|
91
|
-
const [, routePath, language] = (_a = locale.match(PAGE_LOCALE_RE)) !== null && _a !== void 0 ? _a : [];
|
|
92
|
-
filterMap.set(routePath + language, locale);
|
|
93
|
-
});
|
|
94
|
-
return Promise.resolve(Array.from(filterMap.values()));
|
|
95
|
-
}
|
|
96
|
-
export async function buildMobileSiteRoutes(draftMode) {
|
|
97
|
-
const examples = await findExamples(draftMode);
|
|
1
|
+
import slash from 'slash';
|
|
2
|
+
import fse from 'fs-extra';
|
|
3
|
+
import { DOCS_DIR_NAME, 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 ROOT_DOCS_RE = /\/docs\/([-\w]+)\.([-\w]+)(?:.draft)?\.md/;
|
|
9
|
+
const PAGE_LOCALE_RE = /\/pages\/([-\w]+)\/locale\/([-\w]+)\.ts/;
|
|
10
|
+
const EXAMPLE_INDEX_RE = /\/([-\w]+)\/example\/index(?:.draft)?\.vue/;
|
|
11
|
+
const COMPONENT_DOCS_RE = /\/([-\w]+)\/docs\/([-\w]+)(?:.draft)?\.md/;
|
|
12
|
+
export function getExampleRoutePath(examplePath) {
|
|
13
|
+
var _a;
|
|
14
|
+
return '/' + ((_a = examplePath.match(EXAMPLE_INDEX_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 getPageRoutePath(rootLocalePath) {
|
|
27
|
+
var _a;
|
|
28
|
+
const [, routePath, language] = (_a = rootLocalePath.match(PAGE_LOCALE_RE)) !== null && _a !== void 0 ? _a : [];
|
|
29
|
+
return `/${language}/${routePath}`;
|
|
30
|
+
}
|
|
31
|
+
export function getPageFilePath(rootLocalePath) {
|
|
32
|
+
return rootLocalePath.replace(/locale\/.+/, 'index.vue');
|
|
33
|
+
}
|
|
34
|
+
export function isDraftExample(example) {
|
|
35
|
+
return example.endsWith('index.draft.vue');
|
|
36
|
+
}
|
|
37
|
+
export function hasDraftExample(examples, example) {
|
|
38
|
+
return examples.includes(example.replace('index.vue', 'index.draft.vue'));
|
|
39
|
+
}
|
|
40
|
+
export function isDraftDoc(doc) {
|
|
41
|
+
return doc.endsWith('.draft.md');
|
|
42
|
+
}
|
|
43
|
+
export function hasDraftDoc(docs, doc) {
|
|
44
|
+
return docs.includes(doc.replace('.md', '.draft.md'));
|
|
45
|
+
}
|
|
46
|
+
export async function findExamples(draftMode) {
|
|
47
|
+
const [examples, draftExamples] = await Promise.all([
|
|
48
|
+
glob(`${SRC_DIR}/**/${EXAMPLE_DIR_NAME}/index.vue`),
|
|
49
|
+
glob(`${SRC_DIR}/**/${EXAMPLE_DIR_NAME}/index.draft.vue`),
|
|
50
|
+
]);
|
|
51
|
+
const mergedExamples = [...examples, ...draftExamples];
|
|
52
|
+
return mergedExamples.filter((example) => {
|
|
53
|
+
return draftMode ? isDraftExample(example) || !hasDraftExample(mergedExamples, example) : !isDraftExample(example);
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
export function filterDraftDocs(docs, draftMode) {
|
|
57
|
+
return docs.filter((doc) => {
|
|
58
|
+
return draftMode ? isDraftDoc(doc) || !hasDraftDoc(docs, doc) : !isDraftDoc(doc);
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
export async function findComponentDocs(draftMode) {
|
|
62
|
+
const componentDocs = await glob(`${SRC_DIR}/**/${DOCS_DIR_NAME}/*.md`);
|
|
63
|
+
return filterDraftDocs(componentDocs, draftMode);
|
|
64
|
+
}
|
|
65
|
+
export async function findRootDocs(draftMode) {
|
|
66
|
+
const rootDocs = await glob(`${ROOT_DOCS_DIR}/*.md`);
|
|
67
|
+
return filterDraftDocs(rootDocs, draftMode);
|
|
68
|
+
}
|
|
69
|
+
export async function findPageLocales() {
|
|
70
|
+
const defaultLanguage = get(await getVarletConfig(), 'defaultLanguage');
|
|
71
|
+
const userPages = await glob(`${ROOT_PAGES_DIR}/*`);
|
|
72
|
+
const baseLocales = await glob(`${SITE}/pc/pages/**/${LOCALE_DIR_NAME}/*.ts`);
|
|
73
|
+
const userLocales = await userPages.reduce(async (userLocales, page) => {
|
|
74
|
+
if (isDir(page)) {
|
|
75
|
+
const locales = await glob(`${page}/${LOCALE_DIR_NAME}/*.ts`);
|
|
76
|
+
if (!locales.length)
|
|
77
|
+
locales.push(`${page}/${LOCALE_DIR_NAME}/${defaultLanguage}.ts`);
|
|
78
|
+
(await userLocales).push(...locales);
|
|
79
|
+
}
|
|
80
|
+
return userLocales;
|
|
81
|
+
}, Promise.resolve([]));
|
|
82
|
+
// filter
|
|
83
|
+
const filterMap = new Map();
|
|
84
|
+
baseLocales.forEach((locale) => {
|
|
85
|
+
var _a;
|
|
86
|
+
const [, routePath, language] = (_a = locale.match(PAGE_LOCALE_RE)) !== null && _a !== void 0 ? _a : [];
|
|
87
|
+
filterMap.set(routePath + language, slash(`${SITE_PC_DIR}/pages/${routePath}/locale/${language}.ts`));
|
|
88
|
+
});
|
|
89
|
+
userLocales.forEach((locale) => {
|
|
90
|
+
var _a;
|
|
91
|
+
const [, routePath, language] = (_a = locale.match(PAGE_LOCALE_RE)) !== null && _a !== void 0 ? _a : [];
|
|
92
|
+
filterMap.set(routePath + language, locale);
|
|
93
|
+
});
|
|
94
|
+
return Promise.resolve(Array.from(filterMap.values()));
|
|
95
|
+
}
|
|
96
|
+
export async function buildMobileSiteRoutes(draftMode) {
|
|
97
|
+
const examples = await findExamples(draftMode);
|
|
98
98
|
const routes = examples.map((example) => `
|
|
99
99
|
{
|
|
100
100
|
path: '${getExampleRoutePath(example)}',
|
|
101
101
|
// @ts-ignore
|
|
102
102
|
component: () => import('${example}')
|
|
103
|
-
}`);
|
|
103
|
+
}`);
|
|
104
104
|
const source = `export default [\
|
|
105
105
|
${routes.join(',')}
|
|
106
|
-
]`;
|
|
107
|
-
await outputFileSyncOnChange(SITE_MOBILE_ROUTES, source);
|
|
108
|
-
}
|
|
109
|
-
export async function buildPcSiteRoutes(draftMode) {
|
|
110
|
-
const [componentDocs, rootDocs, rootLocales] = await Promise.all([
|
|
111
|
-
findComponentDocs(draftMode),
|
|
112
|
-
findRootDocs(draftMode),
|
|
113
|
-
findPageLocales(),
|
|
114
|
-
]);
|
|
106
|
+
]`;
|
|
107
|
+
await outputFileSyncOnChange(SITE_MOBILE_ROUTES, source);
|
|
108
|
+
}
|
|
109
|
+
export async function buildPcSiteRoutes(draftMode) {
|
|
110
|
+
const [componentDocs, rootDocs, rootLocales] = await Promise.all([
|
|
111
|
+
findComponentDocs(draftMode),
|
|
112
|
+
findRootDocs(draftMode),
|
|
113
|
+
findPageLocales(),
|
|
114
|
+
]);
|
|
115
115
|
const pageRoutes = rootLocales.map((locale) => `
|
|
116
116
|
{
|
|
117
117
|
path: '${getPageRoutePath(locale)}',
|
|
118
118
|
// @ts-ignore
|
|
119
119
|
component: () => import('${getPageFilePath(locale)}')
|
|
120
120
|
}\
|
|
121
|
-
`);
|
|
121
|
+
`);
|
|
122
122
|
const componentDocsRoutes = componentDocs.map((componentDoc) => `
|
|
123
123
|
{
|
|
124
124
|
path: '${getComponentDocRoutePath(componentDoc)}',
|
|
125
125
|
// @ts-ignore
|
|
126
126
|
component: () => import('${componentDoc}')
|
|
127
|
-
}`);
|
|
127
|
+
}`);
|
|
128
128
|
const rootDocsRoutes = rootDocs.map((rootDoc) => `
|
|
129
129
|
{
|
|
130
130
|
path: '${getRootDocRoutePath(rootDoc)}',
|
|
131
131
|
// @ts-ignore
|
|
132
132
|
component: () => import('${rootDoc}')
|
|
133
|
-
}`);
|
|
133
|
+
}`);
|
|
134
134
|
const layoutRoutes = `{
|
|
135
135
|
path: '/layout',
|
|
136
136
|
// @ts-ignore
|
|
@@ -138,17 +138,17 @@ export async function buildPcSiteRoutes(draftMode) {
|
|
|
138
138
|
children: [
|
|
139
139
|
${[...componentDocsRoutes, rootDocsRoutes].join(',')},
|
|
140
140
|
]
|
|
141
|
-
}`;
|
|
141
|
+
}`;
|
|
142
142
|
const source = `export default [\
|
|
143
143
|
${pageRoutes.join(',')},
|
|
144
144
|
${layoutRoutes}
|
|
145
|
-
]`;
|
|
146
|
-
outputFileSyncOnChange(SITE_PC_ROUTES, source);
|
|
147
|
-
}
|
|
148
|
-
export async function buildSiteSource() {
|
|
149
|
-
return copy(SITE, SITE_DIR);
|
|
150
|
-
}
|
|
151
|
-
export async function buildSiteEntry(draftMode) {
|
|
152
|
-
await getVarletConfig(true);
|
|
153
|
-
await Promise.all([buildMobileSiteRoutes(draftMode), buildPcSiteRoutes(draftMode), buildSiteSource()]);
|
|
154
|
-
}
|
|
145
|
+
]`;
|
|
146
|
+
outputFileSyncOnChange(SITE_PC_ROUTES, source);
|
|
147
|
+
}
|
|
148
|
+
export async function buildSiteSource() {
|
|
149
|
+
return copy(SITE, SITE_DIR);
|
|
150
|
+
}
|
|
151
|
+
export async function buildSiteEntry(draftMode) {
|
|
152
|
+
await getVarletConfig(true);
|
|
153
|
+
await Promise.all([buildMobileSiteRoutes(draftMode), buildPcSiteRoutes(draftMode), buildSiteSource()]);
|
|
154
|
+
}
|
|
@@ -1,10 +1,10 @@
|
|
|
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 STYLE_IMPORT_RE: RegExp;
|
|
6
|
-
export declare const clearEmptyLine: (s: string) => string;
|
|
7
|
-
export declare function normalizeStyleDependency(styleImport: string, reg: RegExp): string;
|
|
8
|
-
export declare function extractStyleDependencies(file: string, code: string, styleReg: RegExp): string;
|
|
9
|
-
export declare function compileLess(file: string): Promise<void>;
|
|
10
|
-
export declare function clearLessFiles(dir: string): 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 STYLE_IMPORT_RE: RegExp;
|
|
6
|
+
export declare const clearEmptyLine: (s: string) => string;
|
|
7
|
+
export declare function normalizeStyleDependency(styleImport: string, reg: RegExp): string;
|
|
8
|
+
export declare function extractStyleDependencies(file: string, code: string, styleReg: RegExp): string;
|
|
9
|
+
export declare function compileLess(file: string): Promise<void>;
|
|
10
|
+
export declare function clearLessFiles(dir: string): void;
|
|
@@ -1,41 +1,41 @@
|
|
|
1
|
-
import fse from 'fs-extra';
|
|
2
|
-
import less from 'less';
|
|
3
|
-
import glob from 'glob';
|
|
4
|
-
import { replaceExt, smartAppendFileSync } from '../shared/fsUtils.js';
|
|
5
|
-
import { parse, resolve } from 'path';
|
|
6
|
-
import { getScriptExtname } from './compileScript.js';
|
|
7
|
-
const { render } = less;
|
|
8
|
-
const { readFileSync, writeFileSync, unlinkSync } = fse;
|
|
9
|
-
export const EMPTY_SPACE_RE = /[\s]+/g;
|
|
10
|
-
export const EMPTY_LINE_RE = /[\n\r]*/g;
|
|
11
|
-
export const IMPORT_CSS_RE = /(?<!['"`])import\s+['"](\.{1,2}\/.+\.css)['"]\s*;?(?!\s*['"`])/g;
|
|
12
|
-
export const IMPORT_LESS_RE = /(?<!['"`])import\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${getScriptExtname()}`);
|
|
27
|
-
styleImports.forEach((styleImport) => {
|
|
28
|
-
const normalizedPath = normalizeStyleDependency(styleImport, styleReg);
|
|
29
|
-
smartAppendFileSync(cssFile, `import '${normalizedPath}.css'\n`);
|
|
30
|
-
});
|
|
31
|
-
return code.replace(styleReg, '');
|
|
32
|
-
}
|
|
33
|
-
export async function compileLess(file) {
|
|
34
|
-
const source = readFileSync(file, 'utf-8');
|
|
35
|
-
const { css } = await render(source, { filename: file });
|
|
36
|
-
writeFileSync(replaceExt(file, '.css'), clearEmptyLine(css), 'utf-8');
|
|
37
|
-
}
|
|
38
|
-
export function clearLessFiles(dir) {
|
|
39
|
-
const files = glob.sync(`${dir}/**/*.less`);
|
|
40
|
-
files.forEach(unlinkSync);
|
|
41
|
-
}
|
|
1
|
+
import fse from 'fs-extra';
|
|
2
|
+
import less from 'less';
|
|
3
|
+
import glob from 'glob';
|
|
4
|
+
import { replaceExt, smartAppendFileSync } from '../shared/fsUtils.js';
|
|
5
|
+
import { parse, resolve } from 'path';
|
|
6
|
+
import { getScriptExtname } from './compileScript.js';
|
|
7
|
+
const { render } = less;
|
|
8
|
+
const { readFileSync, writeFileSync, unlinkSync } = fse;
|
|
9
|
+
export const EMPTY_SPACE_RE = /[\s]+/g;
|
|
10
|
+
export const EMPTY_LINE_RE = /[\n\r]*/g;
|
|
11
|
+
export const IMPORT_CSS_RE = /(?<!['"`])import\s+['"](\.{1,2}\/.+\.css)['"]\s*;?(?!\s*['"`])/g;
|
|
12
|
+
export const IMPORT_LESS_RE = /(?<!['"`])import\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${getScriptExtname()}`);
|
|
27
|
+
styleImports.forEach((styleImport) => {
|
|
28
|
+
const normalizedPath = normalizeStyleDependency(styleImport, styleReg);
|
|
29
|
+
smartAppendFileSync(cssFile, `import '${normalizedPath}.css'\n`);
|
|
30
|
+
});
|
|
31
|
+
return code.replace(styleReg, '');
|
|
32
|
+
}
|
|
33
|
+
export async function compileLess(file) {
|
|
34
|
+
const source = readFileSync(file, 'utf-8');
|
|
35
|
+
const { css } = await render(source, { filename: file });
|
|
36
|
+
writeFileSync(replaceExt(file, '.css'), clearEmptyLine(css), 'utf-8');
|
|
37
|
+
}
|
|
38
|
+
export function clearLessFiles(dir) {
|
|
39
|
+
const files = glob.sync(`${dir}/**/*.less`);
|
|
40
|
+
files.forEach(unlinkSync);
|
|
41
|
+
}
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import { type VarletConfig } from '../config/varlet.config.js';
|
|
2
|
-
export interface TemplateHighlightCompilerOptions {
|
|
3
|
-
md: string;
|
|
4
|
-
json: string;
|
|
5
|
-
titleAttributes: RegExp;
|
|
6
|
-
titleEvents: RegExp;
|
|
7
|
-
titleSlots: RegExp;
|
|
8
|
-
}
|
|
9
|
-
export declare const replaceDot: (s: string) => string;
|
|
10
|
-
export declare const replaceVersion: (s: string) => string;
|
|
11
|
-
export declare const replaceUnderline: (s: string) => string;
|
|
12
|
-
export declare function parseTable(table: string): string[][];
|
|
13
|
-
export declare function compileTable(md: string, titleRe: RegExp): string;
|
|
14
|
-
export declare function compileWebTypes(table: Record<string, any>, webTypes: Record<string, any>, componentName: string, varletConfig: Required<VarletConfig>): void;
|
|
15
|
-
export declare function compileMD(path: string, webTypes: Record<string, any>, varletConfig: Required<VarletConfig>, options: TemplateHighlightCompilerOptions): void;
|
|
16
|
-
export declare function compileDir(path: string, webTypes: Record<string, any>, varletConfig: Required<VarletConfig>, options: TemplateHighlightCompilerOptions): void;
|
|
17
|
-
export declare function compileLanguageMD(varletConfig: Required<VarletConfig>, options: TemplateHighlightCompilerOptions): void;
|
|
18
|
-
export declare function compileTemplateHighlight(): Promise<void>;
|
|
1
|
+
import { type VarletConfig } from '../config/varlet.config.js';
|
|
2
|
+
export interface TemplateHighlightCompilerOptions {
|
|
3
|
+
md: string;
|
|
4
|
+
json: string;
|
|
5
|
+
titleAttributes: RegExp;
|
|
6
|
+
titleEvents: RegExp;
|
|
7
|
+
titleSlots: RegExp;
|
|
8
|
+
}
|
|
9
|
+
export declare const replaceDot: (s: string) => string;
|
|
10
|
+
export declare const replaceVersion: (s: string) => string;
|
|
11
|
+
export declare const replaceUnderline: (s: string) => string;
|
|
12
|
+
export declare function parseTable(table: string): string[][];
|
|
13
|
+
export declare function compileTable(md: string, titleRe: RegExp): string;
|
|
14
|
+
export declare function compileWebTypes(table: Record<string, any>, webTypes: Record<string, any>, componentName: string, varletConfig: Required<VarletConfig>): void;
|
|
15
|
+
export declare function compileMD(path: string, webTypes: Record<string, any>, varletConfig: Required<VarletConfig>, options: TemplateHighlightCompilerOptions): void;
|
|
16
|
+
export declare function compileDir(path: string, webTypes: Record<string, any>, varletConfig: Required<VarletConfig>, options: TemplateHighlightCompilerOptions): void;
|
|
17
|
+
export declare function compileLanguageMD(varletConfig: Required<VarletConfig>, options: TemplateHighlightCompilerOptions): void;
|
|
18
|
+
export declare function compileTemplateHighlight(): Promise<void>;
|