@varlet/cli 2.6.2 → 2.7.0-alpha.1673584157662
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/node/bin.js +2 -4
- package/lib/node/commands/compile.js +5 -3
- package/lib/node/commands/release.d.ts +1 -0
- package/lib/node/commands/release.js +5 -1
- package/lib/node/compiler/compileModule.d.ts +1 -1
- package/lib/node/compiler/compileModule.js +14 -24
- package/lib/node/compiler/compileSFC.js +1 -1
- package/lib/node/compiler/compileScript.d.ts +8 -12
- package/lib/node/compiler/compileScript.js +106 -36
- package/lib/node/compiler/compileStyle.js +4 -3
- package/lib/node/compiler/compileTemplateHighlight.js +4 -4
- package/lib/node/config/vite.config.js +2 -2
- package/lib/node/index.d.ts +12 -0
- package/lib/node/index.js +12 -0
- package/lib/node/shared/fsUtils.d.ts +2 -0
- package/lib/node/shared/fsUtils.js +8 -2
- package/package.json +7 -7
package/lib/node/bin.js
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import fse from 'fs-extra';
|
|
3
2
|
import { Command } from 'commander';
|
|
4
|
-
import {
|
|
5
|
-
const { readJSONSync } = fse;
|
|
3
|
+
import { getCliVersion } from './shared/fsUtils.js';
|
|
6
4
|
const program = new Command();
|
|
7
|
-
program.version(`varlet-cli ${
|
|
5
|
+
program.version(`varlet-cli ${getCliVersion()}`).usage('<command> [options]');
|
|
8
6
|
program
|
|
9
7
|
.command('dev')
|
|
10
8
|
.option('-f --force', 'Force dep pre-optimization regardless of whether deps have changed')
|
|
@@ -25,11 +25,13 @@ export async function compile(options) {
|
|
|
25
25
|
await removeDir();
|
|
26
26
|
await Promise.all([runTask('types', compileTypes), runTask('template highlight', compileTemplateHighlight)]);
|
|
27
27
|
process.env.TARGET_MODULE = 'module';
|
|
28
|
+
process.env.BABEL_MODULE = 'module';
|
|
28
29
|
await runTask('module', compileModule);
|
|
29
30
|
process.env.TARGET_MODULE = 'esm-bundle';
|
|
30
|
-
await runTask('esm bundle',
|
|
31
|
+
await runTask('esm bundle', compileModule);
|
|
31
32
|
process.env.TARGET_MODULE = 'commonjs';
|
|
32
|
-
|
|
33
|
+
process.env.BABEL_MODULE = 'commonjs';
|
|
34
|
+
await runTask('commonjs', compileModule);
|
|
33
35
|
process.env.TARGET_MODULE = 'umd';
|
|
34
|
-
!options.noUmd && (await runTask('umd',
|
|
36
|
+
!options.noUmd && (await runTask('umd', compileModule));
|
|
35
37
|
}
|
|
@@ -8,6 +8,7 @@ import inquirer from 'inquirer';
|
|
|
8
8
|
import { CWD } from '../shared/constant.js';
|
|
9
9
|
import { resolve } from 'path';
|
|
10
10
|
import { changelog } from './changelog.js';
|
|
11
|
+
import { getVersion } from '../shared/fsUtils.js';
|
|
11
12
|
const { writeFileSync, readJSONSync } = fse;
|
|
12
13
|
const { prompt } = inquirer;
|
|
13
14
|
const releaseTypes = ['premajor', 'preminor', 'prepatch', 'major', 'minor', 'patch'];
|
|
@@ -100,7 +101,7 @@ async function getReleaseType() {
|
|
|
100
101
|
}
|
|
101
102
|
export async function release(options) {
|
|
102
103
|
try {
|
|
103
|
-
const currentVersion =
|
|
104
|
+
const currentVersion = getVersion();
|
|
104
105
|
if (!currentVersion) {
|
|
105
106
|
logger.error('Your package is missing the version field');
|
|
106
107
|
return;
|
|
@@ -123,6 +124,9 @@ export async function release(options) {
|
|
|
123
124
|
return;
|
|
124
125
|
}
|
|
125
126
|
updateVersion(expectVersion);
|
|
127
|
+
if (options.task) {
|
|
128
|
+
await options.task();
|
|
129
|
+
}
|
|
126
130
|
await publish(isPreRelease);
|
|
127
131
|
if (!isPreRelease) {
|
|
128
132
|
await changelog();
|
|
@@ -2,4 +2,4 @@ export declare function compileUMD(): Promise<void>;
|
|
|
2
2
|
export declare function compileESMBundle(): Promise<void>;
|
|
3
3
|
export declare function compileDir(dir: string): Promise<void>;
|
|
4
4
|
export declare function compileFile(file: string): Promise<void>;
|
|
5
|
-
export declare function compileModule(
|
|
5
|
+
export declare function compileModule(): Promise<void>;
|
|
@@ -4,29 +4,19 @@ import { resolve } from 'path';
|
|
|
4
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
5
|
import { getPublicDirs, isDir, isDTS, isLess, isScript, isSFC } from '../shared/fsUtils.js';
|
|
6
6
|
import { compileSFC } from './compileSFC.js';
|
|
7
|
-
import { compileESEntry, compileCommonJSEntry, compileScriptFile } from './compileScript.js';
|
|
7
|
+
import { compileESEntry, compileCommonJSEntry, compileScriptFile, getScriptExtname } from './compileScript.js';
|
|
8
8
|
import { clearLessFiles, compileLess } from './compileStyle.js';
|
|
9
9
|
import { getESMBundleConfig, getUMDConfig } from '../config/vite.config.js';
|
|
10
10
|
import { getVarletConfig } from '../config/varlet.config.js';
|
|
11
11
|
import { generateReference } from './compileTypes.js';
|
|
12
12
|
const { copy, ensureFileSync, readdir, removeSync } = fse;
|
|
13
|
-
export function compileUMD() {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
build(getUMDConfig(varletConfig))
|
|
17
|
-
.then(() => resolve())
|
|
18
|
-
.catch(reject);
|
|
19
|
-
});
|
|
20
|
-
});
|
|
13
|
+
export async function compileUMD() {
|
|
14
|
+
const varletConfig = await getVarletConfig();
|
|
15
|
+
await build(getUMDConfig(varletConfig));
|
|
21
16
|
}
|
|
22
|
-
export function compileESMBundle() {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
build(getESMBundleConfig(varletConfig))
|
|
26
|
-
.then(() => resolve())
|
|
27
|
-
.catch(reject);
|
|
28
|
-
});
|
|
29
|
-
});
|
|
17
|
+
export async function compileESMBundle() {
|
|
18
|
+
const varletConfig = await getVarletConfig();
|
|
19
|
+
await build(getESMBundleConfig(varletConfig));
|
|
30
20
|
}
|
|
31
21
|
export async function compileDir(dir) {
|
|
32
22
|
const dirs = await readdir(dir);
|
|
@@ -45,26 +35,26 @@ export async function compileFile(file) {
|
|
|
45
35
|
isLess(file) && (await compileLess(file));
|
|
46
36
|
isDir(file) && (await compileDir(file));
|
|
47
37
|
}
|
|
48
|
-
export async function compileModule(
|
|
49
|
-
|
|
38
|
+
export async function compileModule() {
|
|
39
|
+
const targetModule = process.env.TARGET_MODULE;
|
|
40
|
+
if (targetModule === 'umd') {
|
|
50
41
|
await compileUMD();
|
|
51
42
|
return;
|
|
52
43
|
}
|
|
53
|
-
if (
|
|
44
|
+
if (targetModule === 'esm-bundle') {
|
|
54
45
|
await compileESMBundle();
|
|
55
46
|
return;
|
|
56
47
|
}
|
|
57
|
-
|
|
58
|
-
const dest = modules === 'commonjs' ? LIB_DIR : ES_DIR;
|
|
48
|
+
const dest = targetModule === 'commonjs' ? LIB_DIR : ES_DIR;
|
|
59
49
|
await copy(SRC_DIR, dest);
|
|
60
50
|
const moduleDir = await readdir(dest);
|
|
61
51
|
await Promise.all(moduleDir.map((filename) => {
|
|
62
52
|
const file = resolve(dest, filename);
|
|
63
|
-
isDir(file) && ensureFileSync(resolve(file,
|
|
53
|
+
isDir(file) && ensureFileSync(resolve(file, `./style/index.${getScriptExtname()}`));
|
|
64
54
|
return isDir(file) ? compileDir(file) : null;
|
|
65
55
|
}));
|
|
66
56
|
const publicDirs = await getPublicDirs();
|
|
67
|
-
if (
|
|
57
|
+
if (targetModule === 'commonjs') {
|
|
68
58
|
await compileCommonJSEntry(dest, publicDirs);
|
|
69
59
|
}
|
|
70
60
|
else {
|
|
@@ -68,7 +68,7 @@ export async function compileSFC(sfc) {
|
|
|
68
68
|
});
|
|
69
69
|
code = extractStyleDependencies(file, code, STYLE_IMPORT_RE);
|
|
70
70
|
writeFileSync(file, clearEmptyLine(code), 'utf-8');
|
|
71
|
-
smartAppendFileSync(cssFile, process.env.
|
|
71
|
+
smartAppendFileSync(cssFile, process.env.TARGET_MODULE === 'commonjs'
|
|
72
72
|
? `require('${dependencyPath}.css')\n`
|
|
73
73
|
: `import '${dependencyPath}.css'\n`);
|
|
74
74
|
if (style.lang === 'less') {
|
|
@@ -1,17 +1,13 @@
|
|
|
1
|
-
export declare const
|
|
2
|
-
export declare const
|
|
3
|
-
export declare const
|
|
4
|
-
export declare const
|
|
5
|
-
export declare const
|
|
6
|
-
export declare const
|
|
7
|
-
export declare const
|
|
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;
|
|
1
|
+
export declare const IMPORT_FROM_DEPENDENCE_RE: RegExp;
|
|
2
|
+
export declare const IMPORT_DEPENDENCE_RE: RegExp;
|
|
3
|
+
export declare const REQUIRE_DEPENDENCE_RE: RegExp;
|
|
4
|
+
export declare const scriptExtNames: string[];
|
|
5
|
+
export declare const scriptIndexes: string[];
|
|
6
|
+
export declare const tryMatchExtname: (file: string, extname: string[]) => string | undefined;
|
|
7
|
+
export declare const resolveDependence: (file: string, script: string) => string;
|
|
13
8
|
export declare const moduleCompatible: (script: string) => Promise<string>;
|
|
14
9
|
export declare function compileScript(script: string, file: string): Promise<void>;
|
|
15
10
|
export declare function compileScriptFile(file: string): Promise<void>;
|
|
11
|
+
export declare function getScriptExtname(): "mjs" | "js";
|
|
16
12
|
export declare function compileESEntry(dir: string, publicDirs: string[]): Promise<void>;
|
|
17
13
|
export declare function compileCommonJSEntry(dir: string, publicDirs: string[]): Promise<void>;
|
|
@@ -1,25 +1,65 @@
|
|
|
1
1
|
import fse from 'fs-extra';
|
|
2
2
|
import { transformAsync } from '@babel/core';
|
|
3
3
|
import { bigCamelize } from '@varlet/shared';
|
|
4
|
-
import { replaceExt } from '../shared/fsUtils.js';
|
|
4
|
+
import { getVersion, isDir, replaceExt } from '../shared/fsUtils.js';
|
|
5
5
|
import { extractStyleDependencies, IMPORT_CSS_RE, IMPORT_LESS_RE, REQUIRE_CSS_RE, REQUIRE_LESS_RE, } from './compileStyle.js';
|
|
6
|
-
import { resolve } from 'path';
|
|
6
|
+
import { resolve, extname, dirname } from 'path';
|
|
7
7
|
import { get } from 'lodash-es';
|
|
8
8
|
import { getVarletConfig } from '../config/varlet.config.js';
|
|
9
|
-
const { writeFileSync, readFileSync, removeSync, writeFile } = fse;
|
|
10
|
-
|
|
11
|
-
export const
|
|
12
|
-
|
|
13
|
-
export const
|
|
14
|
-
|
|
15
|
-
export const
|
|
16
|
-
export const
|
|
17
|
-
export const
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
9
|
+
const { writeFileSync, readdirSync, readFileSync, removeSync, writeFile, pathExistsSync } = fse;
|
|
10
|
+
// https://regexr.com/765a4
|
|
11
|
+
export const IMPORT_FROM_DEPENDENCE_RE = /import\s+?[\w\s{},$*]+\s+from\s+?(".*?"|'.*?')/g;
|
|
12
|
+
// https://regexr.com/764ve
|
|
13
|
+
export const IMPORT_DEPENDENCE_RE = /import\s+['"]\s*\.{1,2}\/(.+)\s*['"];?/g;
|
|
14
|
+
// https://regexr.com/764vn
|
|
15
|
+
export const REQUIRE_DEPENDENCE_RE = /require\(['"]\s*(\.{1,2}\/.+)\s*['"]\)/g;
|
|
16
|
+
export const scriptExtNames = ['mjs', 'vue', 'ts', 'tsx', 'js', 'jsx'];
|
|
17
|
+
export const scriptIndexes = ['index.mjs', 'index.vue', 'index.ts', 'index.tsx', 'index.js', 'index.jsx'];
|
|
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
|
+
return script.replace(IMPORT_FROM_DEPENDENCE_RE, (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
|
+
if (inNodeModules) {
|
|
35
|
+
// e.g. @varlet/shared
|
|
36
|
+
return source;
|
|
37
|
+
}
|
|
38
|
+
if (!ext) {
|
|
39
|
+
// e.g. ../button/props -> ../button/props.m?js
|
|
40
|
+
const matched = tryMatchExtname(targetDependenceFile, scriptExtNames);
|
|
41
|
+
if (matched) {
|
|
42
|
+
return source.replace(dependence, `${dependence}.${scriptExtname}`);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
if (!ext && isDir(targetDependenceFile)) {
|
|
46
|
+
// e.g. ../button
|
|
47
|
+
const files = readdirSync(targetDependenceFile);
|
|
48
|
+
const hasScriptIndex = files.some((file) => scriptIndexes.some((name) => file.endsWith(name)));
|
|
49
|
+
if (hasScriptIndex) {
|
|
50
|
+
// e.g. -> ../button/index.m?js
|
|
51
|
+
return source.replace(dependence, `${dependence}/index.${scriptExtname}`);
|
|
52
|
+
}
|
|
53
|
+
const hasStyleIndex = files.some((file) => ['index.less', 'index.css'].some((name) => file.endsWith(name)));
|
|
54
|
+
if (hasStyleIndex) {
|
|
55
|
+
// e.g. -> ../button/index.css
|
|
56
|
+
return source.replace(dependence, `${dependence}/index.css`);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
// e.g. ../button/props.ts -> ../button/props.m?js
|
|
60
|
+
return source.replace(dependence, dependence.replace(ext, `.${scriptExtname}`));
|
|
61
|
+
});
|
|
62
|
+
};
|
|
23
63
|
export const moduleCompatible = async (script) => {
|
|
24
64
|
const moduleCompatible = get(await getVarletConfig(), 'moduleCompatible', {});
|
|
25
65
|
Object.keys(moduleCompatible).forEach((esm) => {
|
|
@@ -29,55 +69,66 @@ export const moduleCompatible = async (script) => {
|
|
|
29
69
|
return script;
|
|
30
70
|
};
|
|
31
71
|
export async function compileScript(script, file) {
|
|
32
|
-
const
|
|
33
|
-
if (
|
|
72
|
+
const targetModule = process.env.TARGET_MODULE;
|
|
73
|
+
if (targetModule === 'commonjs') {
|
|
34
74
|
script = await moduleCompatible(script);
|
|
35
75
|
}
|
|
36
76
|
let { code } = (await transformAsync(script, {
|
|
37
77
|
filename: file,
|
|
38
78
|
}));
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
writeFileSync(replaceExt(file, '.js'), code, 'utf8');
|
|
79
|
+
if (code) {
|
|
80
|
+
code = extractStyleDependencies(file, code, targetModule === 'commonjs' ? REQUIRE_CSS_RE : IMPORT_CSS_RE);
|
|
81
|
+
code = extractStyleDependencies(file, code, targetModule === 'commonjs' ? REQUIRE_LESS_RE : IMPORT_LESS_RE);
|
|
82
|
+
code = resolveDependence(file, code);
|
|
83
|
+
removeSync(file);
|
|
84
|
+
writeFileSync(replaceExt(file, `.${getScriptExtname()}`), code, 'utf8');
|
|
85
|
+
}
|
|
47
86
|
}
|
|
48
87
|
export async function compileScriptFile(file) {
|
|
49
88
|
const sources = readFileSync(file, 'utf-8');
|
|
50
89
|
await compileScript(sources, file);
|
|
51
90
|
}
|
|
91
|
+
export function getScriptExtname() {
|
|
92
|
+
if (process.env.TARGET_MODULE === 'module') {
|
|
93
|
+
return 'mjs';
|
|
94
|
+
}
|
|
95
|
+
return 'js';
|
|
96
|
+
}
|
|
52
97
|
export async function compileESEntry(dir, publicDirs) {
|
|
53
98
|
const imports = [];
|
|
54
99
|
const plugins = [];
|
|
55
|
-
const
|
|
100
|
+
const exports = [];
|
|
56
101
|
const cssImports = [];
|
|
57
102
|
const publicComponents = [];
|
|
103
|
+
const scriptExtname = getScriptExtname();
|
|
58
104
|
publicDirs.forEach((dirname) => {
|
|
59
105
|
const publicComponent = bigCamelize(dirname);
|
|
106
|
+
const module = `'./${dirname}/index.${scriptExtname}'`;
|
|
60
107
|
publicComponents.push(publicComponent);
|
|
61
|
-
imports.push(`import ${publicComponent}
|
|
62
|
-
|
|
108
|
+
imports.push(`import ${publicComponent} from ${module}`);
|
|
109
|
+
exports.push(`export * from ${module}`);
|
|
63
110
|
plugins.push(`${publicComponent}.install && app.use(${publicComponent})`);
|
|
64
|
-
cssImports.push(`import './${dirname}/style'`);
|
|
111
|
+
cssImports.push(`import './${dirname}/style/index.${scriptExtname}'`);
|
|
65
112
|
});
|
|
66
113
|
const install = `
|
|
67
114
|
function install(app) {
|
|
68
115
|
${plugins.join('\n ')}
|
|
69
116
|
}
|
|
70
117
|
`;
|
|
118
|
+
const version = `const version = '${getVersion()}'`;
|
|
71
119
|
const indexTemplate = `\
|
|
72
120
|
${imports.join('\n')}\n
|
|
73
|
-
${
|
|
121
|
+
${exports.join('\n')}\n
|
|
122
|
+
${version}
|
|
74
123
|
${install}
|
|
75
124
|
export {
|
|
125
|
+
version,
|
|
76
126
|
install,
|
|
77
127
|
${publicComponents.join(',\n ')}
|
|
78
128
|
}
|
|
79
129
|
|
|
80
130
|
export default {
|
|
131
|
+
version,
|
|
81
132
|
install,
|
|
82
133
|
${publicComponents.join(',\n ')}
|
|
83
134
|
}
|
|
@@ -88,21 +139,24 @@ ${cssImports.join('\n')}
|
|
|
88
139
|
const umdTemplate = `\
|
|
89
140
|
${imports.join('\n')}\n
|
|
90
141
|
${cssImports.join('\n')}\n
|
|
142
|
+
${version}
|
|
91
143
|
${install}
|
|
92
144
|
export {
|
|
145
|
+
version,
|
|
93
146
|
install,
|
|
94
147
|
${publicComponents.join(',\n ')}
|
|
95
148
|
}
|
|
96
149
|
|
|
97
150
|
export default {
|
|
151
|
+
version,
|
|
98
152
|
install,
|
|
99
153
|
${publicComponents.join(',\n ')}
|
|
100
154
|
}
|
|
101
155
|
`;
|
|
102
156
|
await Promise.all([
|
|
103
|
-
writeFile(resolve(dir, 'index.
|
|
104
|
-
writeFile(resolve(dir, '
|
|
105
|
-
writeFile(resolve(dir, 'style.
|
|
157
|
+
writeFile(resolve(dir, 'index.mjs'), indexTemplate, 'utf-8'),
|
|
158
|
+
writeFile(resolve(dir, 'index.umd.mjs'), umdTemplate, 'utf-8'),
|
|
159
|
+
writeFile(resolve(dir, 'style.mjs'), styleTemplate, 'utf-8'),
|
|
106
160
|
]);
|
|
107
161
|
}
|
|
108
162
|
export async function compileCommonJSEntry(dir, publicDirs) {
|
|
@@ -110,12 +164,15 @@ export async function compileCommonJSEntry(dir, publicDirs) {
|
|
|
110
164
|
const plugins = [];
|
|
111
165
|
const cssRequires = [];
|
|
112
166
|
const publicComponents = [];
|
|
167
|
+
const exports = [];
|
|
113
168
|
publicDirs.forEach((dirname) => {
|
|
114
169
|
const publicComponent = bigCamelize(dirname);
|
|
170
|
+
const module = `'./${dirname}/index.js'`;
|
|
115
171
|
publicComponents.push(publicComponent);
|
|
116
|
-
requires.push(`var ${publicComponent} = require(
|
|
172
|
+
requires.push(`var ${publicComponent} = require(${module})['default']`);
|
|
173
|
+
exports.push(`...ignoreDefault(require(${module}))`);
|
|
117
174
|
plugins.push(`${publicComponent}.install && app.use(${publicComponent})`);
|
|
118
|
-
cssRequires.push(`require('./${dirname}/style')`);
|
|
175
|
+
cssRequires.push(`require('./${dirname}/style/index.js')`);
|
|
119
176
|
});
|
|
120
177
|
const install = `
|
|
121
178
|
function install(app) {
|
|
@@ -126,8 +183,21 @@ function install(app) {
|
|
|
126
183
|
${requires.join('\n')}\n
|
|
127
184
|
${install}
|
|
128
185
|
|
|
186
|
+
function ignoreDefault(module) {
|
|
187
|
+
return Object.keys(module).reduce((exports, key) => {
|
|
188
|
+
if (key !=== 'default') {
|
|
189
|
+
exports[key] = module[key]
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
return exports
|
|
193
|
+
}, {})
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
exports.install = install
|
|
197
|
+
|
|
129
198
|
module.exports = {
|
|
130
199
|
install,
|
|
200
|
+
${exports.join(',\n ')}
|
|
131
201
|
${publicComponents.join(',\n ')}
|
|
132
202
|
}
|
|
133
203
|
`;
|
|
@@ -3,6 +3,7 @@ import less from 'less';
|
|
|
3
3
|
import glob from 'glob';
|
|
4
4
|
import { replaceExt, smartAppendFileSync } from '../shared/fsUtils.js';
|
|
5
5
|
import { parse, resolve } from 'path';
|
|
6
|
+
import { getScriptExtname } from './compileScript.js';
|
|
6
7
|
const { render } = less;
|
|
7
8
|
const { readFileSync, writeFileSync, unlinkSync } = fse;
|
|
8
9
|
export const EMPTY_SPACE_RE = /[\s]+/g;
|
|
@@ -24,11 +25,11 @@ export function normalizeStyleDependency(styleImport, reg) {
|
|
|
24
25
|
export function extractStyleDependencies(file, code, styleReg) {
|
|
25
26
|
var _a;
|
|
26
27
|
const styleImports = (_a = code.match(styleReg)) !== null && _a !== void 0 ? _a : [];
|
|
27
|
-
const cssFile = resolve(parse(file).dir,
|
|
28
|
-
const
|
|
28
|
+
const cssFile = resolve(parse(file).dir, `./style/index.${getScriptExtname()}`);
|
|
29
|
+
const targetModule = process.env.TARGET_MODULE;
|
|
29
30
|
styleImports.forEach((styleImport) => {
|
|
30
31
|
const normalizedPath = normalizeStyleDependency(styleImport, styleReg);
|
|
31
|
-
smartAppendFileSync(cssFile,
|
|
32
|
+
smartAppendFileSync(cssFile, targetModule === 'commonjs' ? `require('${normalizedPath}.css')\n` : `import '${normalizedPath}.css'\n`);
|
|
32
33
|
});
|
|
33
34
|
return code.replace(styleReg, '');
|
|
34
35
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
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,
|
|
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, } from '../shared/constant.js';
|
|
3
3
|
import { resolve } from 'path';
|
|
4
|
-
import { isDir, isMD } from '../shared/fsUtils.js';
|
|
4
|
+
import { getCliVersion, isDir, isMD } from '../shared/fsUtils.js';
|
|
5
5
|
import { get } from 'lodash-es';
|
|
6
6
|
import { getVarletConfig } from '../config/varlet.config.js';
|
|
7
|
-
const { ensureDir, readdirSync, readFileSync,
|
|
7
|
+
const { ensureDir, readdirSync, readFileSync, writeFile } = fse;
|
|
8
8
|
const TABLE_HEAD_RE = /\s*\|.*\|\s*\n\s*\|.*---+\s*\|\s*\n+/;
|
|
9
9
|
const TABLE_FOOT_RE = /(\|\s*$)|(\|\s*\n(?!\s*\|))/;
|
|
10
10
|
export const replaceDot = (s) => s.replace(/`/g, '');
|
|
@@ -115,7 +115,7 @@ export async function compileTemplateHighlight() {
|
|
|
115
115
|
const webTypes = {
|
|
116
116
|
$schema: 'https://raw.githubusercontent.com/JetBrains/web-types/master/schema/web-types.json',
|
|
117
117
|
framework: 'vue',
|
|
118
|
-
version:
|
|
118
|
+
version: getCliVersion(),
|
|
119
119
|
name: get(varletConfig, 'title'),
|
|
120
120
|
contributions: {
|
|
121
121
|
html: {
|
|
@@ -69,7 +69,7 @@ export function getESMBundleConfig(varletConfig) {
|
|
|
69
69
|
name,
|
|
70
70
|
formats: ['es'],
|
|
71
71
|
fileName: () => fileName,
|
|
72
|
-
entry: resolve(ES_DIR, '
|
|
72
|
+
entry: resolve(ES_DIR, 'index.umd.mjs'),
|
|
73
73
|
},
|
|
74
74
|
rollupOptions: {
|
|
75
75
|
external: ['vue'],
|
|
@@ -98,7 +98,7 @@ export function getUMDConfig(varletConfig) {
|
|
|
98
98
|
name,
|
|
99
99
|
formats: ['umd'],
|
|
100
100
|
fileName: () => fileName,
|
|
101
|
-
entry: resolve(ES_DIR, '
|
|
101
|
+
entry: resolve(ES_DIR, 'index.umd.mjs'),
|
|
102
102
|
},
|
|
103
103
|
rollupOptions: {
|
|
104
104
|
external: ['vue'],
|
package/lib/node/index.d.ts
CHANGED
|
@@ -1 +1,13 @@
|
|
|
1
1
|
export { defineConfig } from './config/varlet.config.js';
|
|
2
|
+
export * from './commands/release.js';
|
|
3
|
+
export * from './commands/dev.js';
|
|
4
|
+
export * from './commands/build.js';
|
|
5
|
+
export * from './commands/compile.js';
|
|
6
|
+
export * from './commands/commitLint.js';
|
|
7
|
+
export * from './commands/gen.js';
|
|
8
|
+
export * from './commands/jest.js';
|
|
9
|
+
export * from './commands/create.js';
|
|
10
|
+
export * from './commands/lint.js';
|
|
11
|
+
export * from './commands/changelog.js';
|
|
12
|
+
export * from './commands/preview.js';
|
|
13
|
+
export * from './commands/vite.js';
|
package/lib/node/index.js
CHANGED
|
@@ -1 +1,13 @@
|
|
|
1
1
|
export { defineConfig } from './config/varlet.config.js';
|
|
2
|
+
export * from './commands/release.js';
|
|
3
|
+
export * from './commands/dev.js';
|
|
4
|
+
export * from './commands/build.js';
|
|
5
|
+
export * from './commands/compile.js';
|
|
6
|
+
export * from './commands/commitLint.js';
|
|
7
|
+
export * from './commands/gen.js';
|
|
8
|
+
export * from './commands/jest.js';
|
|
9
|
+
export * from './commands/create.js';
|
|
10
|
+
export * from './commands/lint.js';
|
|
11
|
+
export * from './commands/changelog.js';
|
|
12
|
+
export * from './commands/preview.js';
|
|
13
|
+
export * from './commands/vite.js';
|
|
@@ -11,3 +11,5 @@ export declare function smartAppendFileSync(file: string, code: string): void;
|
|
|
11
11
|
export declare function outputFileSyncOnChange(path: string, code: string): void;
|
|
12
12
|
export declare function glob(pattern: string): Promise<string[]>;
|
|
13
13
|
export declare function getDirname(url: string): string;
|
|
14
|
+
export declare function getVersion(): any;
|
|
15
|
+
export declare function getCliVersion(): any;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import globSync from 'glob';
|
|
2
2
|
import fse from 'fs-extra';
|
|
3
3
|
import { extname, resolve } from 'path';
|
|
4
|
-
import { PUBLIC_DIR_INDEXES, SCRIPTS_EXTENSIONS, SRC_DIR } from './constant.js';
|
|
4
|
+
import { CLI_PACKAGE_JSON, PUBLIC_DIR_INDEXES, SCRIPTS_EXTENSIONS, SRC_DIR, UI_PACKAGE_JSON } from './constant.js';
|
|
5
5
|
import { fileURLToPath } from 'url';
|
|
6
|
-
const { appendFileSync, ensureFileSync, lstatSync, outputFileSync, pathExistsSync, readdir, readFileSync } = fse;
|
|
6
|
+
const { appendFileSync, ensureFileSync, lstatSync, outputFileSync, pathExistsSync, readdir, readFileSync, readJSONSync, } = fse;
|
|
7
7
|
export async function getPublicDirs() {
|
|
8
8
|
const srcDir = await readdir(SRC_DIR);
|
|
9
9
|
return srcDir.filter((filename) => isPublicDir(resolve(SRC_DIR, filename)));
|
|
@@ -46,3 +46,9 @@ export function glob(pattern) {
|
|
|
46
46
|
export function getDirname(url) {
|
|
47
47
|
return fileURLToPath(new URL('.', url));
|
|
48
48
|
}
|
|
49
|
+
export function getVersion() {
|
|
50
|
+
return readJSONSync(UI_PACKAGE_JSON).version;
|
|
51
|
+
}
|
|
52
|
+
export function getCliVersion() {
|
|
53
|
+
return readJSONSync(CLI_PACKAGE_JSON).version;
|
|
54
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@varlet/cli",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.7.0-alpha.1673584157662",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "cli of varlet",
|
|
6
6
|
"bin": {
|
|
@@ -66,8 +66,8 @@
|
|
|
66
66
|
"vite": "4.0.4",
|
|
67
67
|
"vue": "3.2.25",
|
|
68
68
|
"vue-jest": "^5.0.0-alpha.8",
|
|
69
|
-
"@varlet/vite-plugins": "2.
|
|
70
|
-
"@varlet/shared": "2.
|
|
69
|
+
"@varlet/vite-plugins": "2.7.0-alpha.1673584157662",
|
|
70
|
+
"@varlet/shared": "2.7.0-alpha.1673584157662"
|
|
71
71
|
},
|
|
72
72
|
"devDependencies": {
|
|
73
73
|
"@types/babel__core": "^7.1.12",
|
|
@@ -79,8 +79,8 @@
|
|
|
79
79
|
"@types/node": "^18.7.20",
|
|
80
80
|
"@types/semver": "^7.3.9",
|
|
81
81
|
"@types/inquirer": "^9.0.2",
|
|
82
|
-
"@varlet/icons": "2.
|
|
83
|
-
"@varlet/touch-emulator": "2.
|
|
82
|
+
"@varlet/icons": "2.7.0-alpha.1673584157662",
|
|
83
|
+
"@varlet/touch-emulator": "2.7.0-alpha.1673584157662"
|
|
84
84
|
},
|
|
85
85
|
"peerDependencies": {
|
|
86
86
|
"@vue/runtime-core": "3.2.16",
|
|
@@ -90,8 +90,8 @@
|
|
|
90
90
|
"lodash-es": "^4.17.21",
|
|
91
91
|
"vue": "3.2.25",
|
|
92
92
|
"vue-router": "4.0.12",
|
|
93
|
-
"@varlet/icons": "2.
|
|
94
|
-
"@varlet/touch-emulator": "2.
|
|
93
|
+
"@varlet/icons": "2.7.0-alpha.1673584157662",
|
|
94
|
+
"@varlet/touch-emulator": "2.7.0-alpha.1673584157662"
|
|
95
95
|
},
|
|
96
96
|
"scripts": {
|
|
97
97
|
"dev": "tsc --watch",
|