@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,150 +1,150 @@
|
|
|
1
|
-
import { createSpinner } from 'nanospinner';
|
|
2
|
-
import fse from 'fs-extra';
|
|
3
|
-
import execa from 'execa';
|
|
4
|
-
import logger from '../shared/logger.js';
|
|
5
|
-
import semver from 'semver';
|
|
6
|
-
import glob from 'glob';
|
|
7
|
-
import inquirer from 'inquirer';
|
|
8
|
-
import { CWD } from '../shared/constant.js';
|
|
9
|
-
import { resolve } from 'path';
|
|
10
|
-
import { changelog } from './changelog.js';
|
|
11
|
-
import { getVersion } from '../shared/fsUtils.js';
|
|
12
|
-
const { writeFileSync, readJSONSync } = fse;
|
|
13
|
-
const { prompt } = inquirer;
|
|
14
|
-
const releaseTypes = ['premajor', 'preminor', 'prepatch', 'major', 'minor', 'patch'];
|
|
15
|
-
async function isWorktreeEmpty() {
|
|
16
|
-
const ret = await execa('git', ['status', '--porcelain']);
|
|
17
|
-
return !ret.stdout;
|
|
18
|
-
}
|
|
19
|
-
async function publish(preRelease) {
|
|
20
|
-
const s = createSpinner('Publishing all packages').start();
|
|
21
|
-
const args = ['-r', 'publish', '--no-git-checks', '--access', 'public'];
|
|
22
|
-
preRelease && args.push('--tag', 'alpha');
|
|
23
|
-
const ret = await execa('pnpm', args);
|
|
24
|
-
if (ret.stderr && ret.stderr.includes('npm ERR!')) {
|
|
25
|
-
throw new Error('\n' + ret.stderr);
|
|
26
|
-
}
|
|
27
|
-
else {
|
|
28
|
-
s.success({ text: 'Publish all packages successfully' });
|
|
29
|
-
ret.stdout && logger.info(ret.stdout);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
async function pushGit(version, remote = 'origin') {
|
|
33
|
-
const s = createSpinner('Pushing to remote git repository').start();
|
|
34
|
-
await execa('git', ['add', '.']);
|
|
35
|
-
await execa('git', ['commit', '-m', `v${version}`]);
|
|
36
|
-
await execa('git', ['tag', `v${version}`]);
|
|
37
|
-
await execa('git', ['push', remote, `v${version}`]);
|
|
38
|
-
const ret = await execa('git', ['push']);
|
|
39
|
-
s.success({ text: 'Push remote repository successfully' });
|
|
40
|
-
ret.stdout && logger.info(ret.stdout);
|
|
41
|
-
}
|
|
42
|
-
function updateVersion(version) {
|
|
43
|
-
const packageJsons = glob.sync('packages/*/package.json');
|
|
44
|
-
packageJsons.push('package.json');
|
|
45
|
-
packageJsons.forEach((path) => {
|
|
46
|
-
const file = resolve(CWD, path);
|
|
47
|
-
const config = readJSONSync(file);
|
|
48
|
-
config.version = version;
|
|
49
|
-
writeFileSync(file, JSON.stringify(config, null, 2));
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
async function confirmRegistry() {
|
|
53
|
-
const registry = (await execa('npm', ['config', 'get', 'registry'])).stdout;
|
|
54
|
-
const name = 'Registry confirm';
|
|
55
|
-
const ret = await prompt([
|
|
56
|
-
{
|
|
57
|
-
name,
|
|
58
|
-
type: 'confirm',
|
|
59
|
-
message: `Current registry is: ${registry}`,
|
|
60
|
-
},
|
|
61
|
-
]);
|
|
62
|
-
return ret[name];
|
|
63
|
-
}
|
|
64
|
-
async function confirmVersion(currentVersion, expectVersion) {
|
|
65
|
-
const name = 'Version confirm';
|
|
66
|
-
const ret = await prompt([
|
|
67
|
-
{
|
|
68
|
-
name,
|
|
69
|
-
type: 'confirm',
|
|
70
|
-
message: `All packages version ${currentVersion} -> ${expectVersion}:`,
|
|
71
|
-
},
|
|
72
|
-
]);
|
|
73
|
-
return ret[name];
|
|
74
|
-
}
|
|
75
|
-
async function confirmRefs(remote = 'origin') {
|
|
76
|
-
var _a;
|
|
77
|
-
const { stdout } = await execa('git', ['remote', '-v']);
|
|
78
|
-
const reg = new RegExp(`${remote}\t(.*) \\(push`);
|
|
79
|
-
const repo = (_a = stdout.match(reg)) === null || _a === void 0 ? void 0 : _a[1];
|
|
80
|
-
const { stdout: branch } = await execa('git', ['branch', '--show-current']);
|
|
81
|
-
const name = 'Refs confirm';
|
|
82
|
-
const ret = await prompt([
|
|
83
|
-
{
|
|
84
|
-
name,
|
|
85
|
-
type: 'confirm',
|
|
86
|
-
message: `Current refs ${repo}:refs/for/${branch}`,
|
|
87
|
-
},
|
|
88
|
-
]);
|
|
89
|
-
return ret[name];
|
|
90
|
-
}
|
|
91
|
-
async function getReleaseType() {
|
|
92
|
-
const name = 'Please select release type';
|
|
93
|
-
const ret = await prompt([
|
|
94
|
-
{
|
|
95
|
-
name,
|
|
96
|
-
type: 'list',
|
|
97
|
-
choices: releaseTypes,
|
|
98
|
-
},
|
|
99
|
-
]);
|
|
100
|
-
return ret[name];
|
|
101
|
-
}
|
|
102
|
-
export async function release(options) {
|
|
103
|
-
try {
|
|
104
|
-
const currentVersion = getVersion();
|
|
105
|
-
if (!currentVersion) {
|
|
106
|
-
logger.error('Your package is missing the version field');
|
|
107
|
-
return;
|
|
108
|
-
}
|
|
109
|
-
if (!(await isWorktreeEmpty())) {
|
|
110
|
-
logger.error('Git worktree is not empty, please commit changed');
|
|
111
|
-
return;
|
|
112
|
-
}
|
|
113
|
-
if (!(await confirmRefs(options.remote))) {
|
|
114
|
-
return;
|
|
115
|
-
}
|
|
116
|
-
if (!(await confirmRegistry())) {
|
|
117
|
-
return;
|
|
118
|
-
}
|
|
119
|
-
const type = await getReleaseType();
|
|
120
|
-
const isPreRelease = type.startsWith('pre');
|
|
121
|
-
let expectVersion = semver.inc(currentVersion, type, `alpha.${Date.now()}`);
|
|
122
|
-
expectVersion = isPreRelease ? expectVersion.slice(0, -2) : expectVersion;
|
|
123
|
-
if (!(await confirmVersion(currentVersion, expectVersion))) {
|
|
124
|
-
return;
|
|
125
|
-
}
|
|
126
|
-
updateVersion(expectVersion);
|
|
127
|
-
if (options.task) {
|
|
128
|
-
await options.task();
|
|
129
|
-
}
|
|
130
|
-
await publish(isPreRelease);
|
|
131
|
-
if (!isPreRelease) {
|
|
132
|
-
await changelog();
|
|
133
|
-
await pushGit(expectVersion, options.remote);
|
|
134
|
-
}
|
|
135
|
-
logger.success(`Release version ${expectVersion} successfully!`);
|
|
136
|
-
if (isPreRelease) {
|
|
137
|
-
try {
|
|
138
|
-
await execa('git', ['restore', '**/package.json']);
|
|
139
|
-
await execa('git', ['restore', 'package.json']);
|
|
140
|
-
}
|
|
141
|
-
catch (_a) {
|
|
142
|
-
logger.error('Restore package.json has failed, please restore manually');
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
catch (error) {
|
|
147
|
-
logger.error(error.toString());
|
|
148
|
-
process.exit(1);
|
|
149
|
-
}
|
|
150
|
-
}
|
|
1
|
+
import { createSpinner } from 'nanospinner';
|
|
2
|
+
import fse from 'fs-extra';
|
|
3
|
+
import execa from 'execa';
|
|
4
|
+
import logger from '../shared/logger.js';
|
|
5
|
+
import semver from 'semver';
|
|
6
|
+
import glob from 'glob';
|
|
7
|
+
import inquirer from 'inquirer';
|
|
8
|
+
import { CWD } from '../shared/constant.js';
|
|
9
|
+
import { resolve } from 'path';
|
|
10
|
+
import { changelog } from './changelog.js';
|
|
11
|
+
import { getVersion } from '../shared/fsUtils.js';
|
|
12
|
+
const { writeFileSync, readJSONSync } = fse;
|
|
13
|
+
const { prompt } = inquirer;
|
|
14
|
+
const releaseTypes = ['premajor', 'preminor', 'prepatch', 'major', 'minor', 'patch'];
|
|
15
|
+
async function isWorktreeEmpty() {
|
|
16
|
+
const ret = await execa('git', ['status', '--porcelain']);
|
|
17
|
+
return !ret.stdout;
|
|
18
|
+
}
|
|
19
|
+
async function publish(preRelease) {
|
|
20
|
+
const s = createSpinner('Publishing all packages').start();
|
|
21
|
+
const args = ['-r', 'publish', '--no-git-checks', '--access', 'public'];
|
|
22
|
+
preRelease && args.push('--tag', 'alpha');
|
|
23
|
+
const ret = await execa('pnpm', args);
|
|
24
|
+
if (ret.stderr && ret.stderr.includes('npm ERR!')) {
|
|
25
|
+
throw new Error('\n' + ret.stderr);
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
s.success({ text: 'Publish all packages successfully' });
|
|
29
|
+
ret.stdout && logger.info(ret.stdout);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
async function pushGit(version, remote = 'origin') {
|
|
33
|
+
const s = createSpinner('Pushing to remote git repository').start();
|
|
34
|
+
await execa('git', ['add', '.']);
|
|
35
|
+
await execa('git', ['commit', '-m', `v${version}`]);
|
|
36
|
+
await execa('git', ['tag', `v${version}`]);
|
|
37
|
+
await execa('git', ['push', remote, `v${version}`]);
|
|
38
|
+
const ret = await execa('git', ['push']);
|
|
39
|
+
s.success({ text: 'Push remote repository successfully' });
|
|
40
|
+
ret.stdout && logger.info(ret.stdout);
|
|
41
|
+
}
|
|
42
|
+
function updateVersion(version) {
|
|
43
|
+
const packageJsons = glob.sync('packages/*/package.json');
|
|
44
|
+
packageJsons.push('package.json');
|
|
45
|
+
packageJsons.forEach((path) => {
|
|
46
|
+
const file = resolve(CWD, path);
|
|
47
|
+
const config = readJSONSync(file);
|
|
48
|
+
config.version = version;
|
|
49
|
+
writeFileSync(file, JSON.stringify(config, null, 2));
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
async function confirmRegistry() {
|
|
53
|
+
const registry = (await execa('npm', ['config', 'get', 'registry'])).stdout;
|
|
54
|
+
const name = 'Registry confirm';
|
|
55
|
+
const ret = await prompt([
|
|
56
|
+
{
|
|
57
|
+
name,
|
|
58
|
+
type: 'confirm',
|
|
59
|
+
message: `Current registry is: ${registry}`,
|
|
60
|
+
},
|
|
61
|
+
]);
|
|
62
|
+
return ret[name];
|
|
63
|
+
}
|
|
64
|
+
async function confirmVersion(currentVersion, expectVersion) {
|
|
65
|
+
const name = 'Version confirm';
|
|
66
|
+
const ret = await prompt([
|
|
67
|
+
{
|
|
68
|
+
name,
|
|
69
|
+
type: 'confirm',
|
|
70
|
+
message: `All packages version ${currentVersion} -> ${expectVersion}:`,
|
|
71
|
+
},
|
|
72
|
+
]);
|
|
73
|
+
return ret[name];
|
|
74
|
+
}
|
|
75
|
+
async function confirmRefs(remote = 'origin') {
|
|
76
|
+
var _a;
|
|
77
|
+
const { stdout } = await execa('git', ['remote', '-v']);
|
|
78
|
+
const reg = new RegExp(`${remote}\t(.*) \\(push`);
|
|
79
|
+
const repo = (_a = stdout.match(reg)) === null || _a === void 0 ? void 0 : _a[1];
|
|
80
|
+
const { stdout: branch } = await execa('git', ['branch', '--show-current']);
|
|
81
|
+
const name = 'Refs confirm';
|
|
82
|
+
const ret = await prompt([
|
|
83
|
+
{
|
|
84
|
+
name,
|
|
85
|
+
type: 'confirm',
|
|
86
|
+
message: `Current refs ${repo}:refs/for/${branch}`,
|
|
87
|
+
},
|
|
88
|
+
]);
|
|
89
|
+
return ret[name];
|
|
90
|
+
}
|
|
91
|
+
async function getReleaseType() {
|
|
92
|
+
const name = 'Please select release type';
|
|
93
|
+
const ret = await prompt([
|
|
94
|
+
{
|
|
95
|
+
name,
|
|
96
|
+
type: 'list',
|
|
97
|
+
choices: releaseTypes,
|
|
98
|
+
},
|
|
99
|
+
]);
|
|
100
|
+
return ret[name];
|
|
101
|
+
}
|
|
102
|
+
export async function release(options) {
|
|
103
|
+
try {
|
|
104
|
+
const currentVersion = getVersion();
|
|
105
|
+
if (!currentVersion) {
|
|
106
|
+
logger.error('Your package is missing the version field');
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
if (!(await isWorktreeEmpty())) {
|
|
110
|
+
logger.error('Git worktree is not empty, please commit changed');
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
if (!(await confirmRefs(options.remote))) {
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
if (!(await confirmRegistry())) {
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
const type = await getReleaseType();
|
|
120
|
+
const isPreRelease = type.startsWith('pre');
|
|
121
|
+
let expectVersion = semver.inc(currentVersion, type, `alpha.${Date.now()}`);
|
|
122
|
+
expectVersion = isPreRelease ? expectVersion.slice(0, -2) : expectVersion;
|
|
123
|
+
if (!(await confirmVersion(currentVersion, expectVersion))) {
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
updateVersion(expectVersion);
|
|
127
|
+
if (options.task) {
|
|
128
|
+
await options.task();
|
|
129
|
+
}
|
|
130
|
+
await publish(isPreRelease);
|
|
131
|
+
if (!isPreRelease) {
|
|
132
|
+
await changelog();
|
|
133
|
+
await pushGit(expectVersion, options.remote);
|
|
134
|
+
}
|
|
135
|
+
logger.success(`Release version ${expectVersion} successfully!`);
|
|
136
|
+
if (isPreRelease) {
|
|
137
|
+
try {
|
|
138
|
+
await execa('git', ['restore', '**/package.json']);
|
|
139
|
+
await execa('git', ['restore', 'package.json']);
|
|
140
|
+
}
|
|
141
|
+
catch (_a) {
|
|
142
|
+
logger.error('Restore package.json has failed, please restore manually');
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
catch (error) {
|
|
147
|
+
logger.error(error.toString());
|
|
148
|
+
process.exit(1);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare type ViteCommandMode = 'dev' | 'build';
|
|
2
|
-
export declare function vite(mode: ViteCommandMode): Promise<void>;
|
|
1
|
+
export declare type ViteCommandMode = 'dev' | 'build';
|
|
2
|
+
export declare function vite(mode: ViteCommandMode): Promise<void>;
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import vue from '@vitejs/plugin-vue';
|
|
2
|
-
import jsx from '@vitejs/plugin-vue-jsx';
|
|
3
|
-
import { build, createServer } from 'vite';
|
|
4
|
-
export async function vite(mode) {
|
|
5
|
-
process.env.NODE_ENV = mode === 'dev' ? 'development' : 'production';
|
|
6
|
-
const run = mode === 'build' ? build : createServer;
|
|
7
|
-
const result = await run({
|
|
8
|
-
plugins: [vue(), jsx()],
|
|
9
|
-
});
|
|
10
|
-
if (mode === 'dev') {
|
|
11
|
-
await result.listen();
|
|
12
|
-
result.printUrls();
|
|
13
|
-
}
|
|
14
|
-
}
|
|
1
|
+
import vue from '@vitejs/plugin-vue';
|
|
2
|
+
import jsx from '@vitejs/plugin-vue-jsx';
|
|
3
|
+
import { build, createServer } from 'vite';
|
|
4
|
+
export async function vite(mode) {
|
|
5
|
+
process.env.NODE_ENV = mode === 'dev' ? 'development' : 'production';
|
|
6
|
+
const run = mode === 'build' ? build : createServer;
|
|
7
|
+
const result = await run({
|
|
8
|
+
plugins: [vue(), jsx()],
|
|
9
|
+
});
|
|
10
|
+
if (mode === 'dev') {
|
|
11
|
+
await result.listen();
|
|
12
|
+
result.printUrls();
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare function compileBundle(): Promise<void>;
|
|
2
|
-
export declare function compileDir(dir: string): Promise<void>;
|
|
3
|
-
export declare function compileFile(file: string): Promise<void>;
|
|
4
|
-
export declare function compileModule(): Promise<void>;
|
|
1
|
+
export declare function compileBundle(): Promise<void>;
|
|
2
|
+
export declare function compileDir(dir: string): Promise<void>;
|
|
3
|
+
export declare function compileFile(file: string): Promise<void>;
|
|
4
|
+
export declare function compileModule(): Promise<void>;
|
|
@@ -1,71 +1,71 @@
|
|
|
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, UMD_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, compileScriptFile, getScriptExtname } from './compileScript.js';
|
|
8
|
-
import { clearLessFiles, compileLess } from './compileStyle.js';
|
|
9
|
-
import { getBundleConfig } from '../config/vite.config.js';
|
|
10
|
-
import { getVarletConfig } from '../config/varlet.config.js';
|
|
11
|
-
import { generateReference } from './compileTypes.js';
|
|
12
|
-
import { get } from 'lodash-es';
|
|
13
|
-
import { kebabCase } from '@varlet/shared';
|
|
14
|
-
const { copy, ensureFileSync, readdir, removeSync } = fse;
|
|
15
|
-
export async function compileBundle() {
|
|
16
|
-
const varletConfig = await getVarletConfig();
|
|
17
|
-
const name = kebabCase(get(varletConfig, 'name'));
|
|
18
|
-
const buildOptions = [
|
|
19
|
-
{
|
|
20
|
-
format: 'es',
|
|
21
|
-
fileName: `${name}.esm.js`,
|
|
22
|
-
output: ES_DIR,
|
|
23
|
-
emptyOutDir: false,
|
|
24
|
-
},
|
|
25
|
-
{
|
|
26
|
-
format: 'cjs',
|
|
27
|
-
fileName: `${name}.cjs.js`,
|
|
28
|
-
output: LIB_DIR,
|
|
29
|
-
emptyOutDir: false,
|
|
30
|
-
},
|
|
31
|
-
{
|
|
32
|
-
format: 'umd',
|
|
33
|
-
fileName: `${name}.js`,
|
|
34
|
-
output: UMD_DIR,
|
|
35
|
-
emptyOutDir: true,
|
|
36
|
-
},
|
|
37
|
-
];
|
|
38
|
-
const tasks = buildOptions.map((options) => build(getBundleConfig(varletConfig, options)));
|
|
39
|
-
await Promise.all(tasks);
|
|
40
|
-
}
|
|
41
|
-
export async function compileDir(dir) {
|
|
42
|
-
const dirs = await readdir(dir);
|
|
43
|
-
await Promise.all(dirs.map((filename) => {
|
|
44
|
-
const file = resolve(dir, filename);
|
|
45
|
-
[TESTS_DIR_NAME, EXAMPLE_DIR_NAME, DOCS_DIR_NAME].includes(filename) && removeSync(file);
|
|
46
|
-
if (isDTS(file) || filename === STYLE_DIR_NAME) {
|
|
47
|
-
return Promise.resolve();
|
|
48
|
-
}
|
|
49
|
-
return compileFile(file);
|
|
50
|
-
}));
|
|
51
|
-
}
|
|
52
|
-
export async function compileFile(file) {
|
|
53
|
-
isSFC(file) && (await compileSFC(file));
|
|
54
|
-
isScript(file) && (await compileScriptFile(file));
|
|
55
|
-
isLess(file) && (await compileLess(file));
|
|
56
|
-
isDir(file) && (await compileDir(file));
|
|
57
|
-
}
|
|
58
|
-
export async function compileModule() {
|
|
59
|
-
const dest = ES_DIR;
|
|
60
|
-
await copy(SRC_DIR, dest);
|
|
61
|
-
const moduleDir = await readdir(dest);
|
|
62
|
-
await Promise.all(moduleDir.map((filename) => {
|
|
63
|
-
const file = resolve(dest, filename);
|
|
64
|
-
isDir(file) && ensureFileSync(resolve(file, `./style/index${getScriptExtname()}`));
|
|
65
|
-
return isDir(file) ? compileDir(file) : null;
|
|
66
|
-
}));
|
|
67
|
-
const publicDirs = await getPublicDirs();
|
|
68
|
-
await compileESEntry(dest, publicDirs);
|
|
69
|
-
clearLessFiles(dest);
|
|
70
|
-
generateReference(dest);
|
|
71
|
-
}
|
|
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, UMD_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, compileScriptFile, getScriptExtname } from './compileScript.js';
|
|
8
|
+
import { clearLessFiles, compileLess } from './compileStyle.js';
|
|
9
|
+
import { getBundleConfig } from '../config/vite.config.js';
|
|
10
|
+
import { getVarletConfig } from '../config/varlet.config.js';
|
|
11
|
+
import { generateReference } from './compileTypes.js';
|
|
12
|
+
import { get } from 'lodash-es';
|
|
13
|
+
import { kebabCase } from '@varlet/shared';
|
|
14
|
+
const { copy, ensureFileSync, readdir, removeSync } = fse;
|
|
15
|
+
export async function compileBundle() {
|
|
16
|
+
const varletConfig = await getVarletConfig();
|
|
17
|
+
const name = kebabCase(get(varletConfig, 'name'));
|
|
18
|
+
const buildOptions = [
|
|
19
|
+
{
|
|
20
|
+
format: 'es',
|
|
21
|
+
fileName: `${name}.esm.js`,
|
|
22
|
+
output: ES_DIR,
|
|
23
|
+
emptyOutDir: false,
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
format: 'cjs',
|
|
27
|
+
fileName: `${name}.cjs.js`,
|
|
28
|
+
output: LIB_DIR,
|
|
29
|
+
emptyOutDir: false,
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
format: 'umd',
|
|
33
|
+
fileName: `${name}.js`,
|
|
34
|
+
output: UMD_DIR,
|
|
35
|
+
emptyOutDir: true,
|
|
36
|
+
},
|
|
37
|
+
];
|
|
38
|
+
const tasks = buildOptions.map((options) => build(getBundleConfig(varletConfig, options)));
|
|
39
|
+
await Promise.all(tasks);
|
|
40
|
+
}
|
|
41
|
+
export async function compileDir(dir) {
|
|
42
|
+
const dirs = await readdir(dir);
|
|
43
|
+
await Promise.all(dirs.map((filename) => {
|
|
44
|
+
const file = resolve(dir, filename);
|
|
45
|
+
[TESTS_DIR_NAME, EXAMPLE_DIR_NAME, DOCS_DIR_NAME].includes(filename) && removeSync(file);
|
|
46
|
+
if (isDTS(file) || filename === STYLE_DIR_NAME) {
|
|
47
|
+
return Promise.resolve();
|
|
48
|
+
}
|
|
49
|
+
return compileFile(file);
|
|
50
|
+
}));
|
|
51
|
+
}
|
|
52
|
+
export async function compileFile(file) {
|
|
53
|
+
isSFC(file) && (await compileSFC(file));
|
|
54
|
+
isScript(file) && (await compileScriptFile(file));
|
|
55
|
+
isLess(file) && (await compileLess(file));
|
|
56
|
+
isDir(file) && (await compileDir(file));
|
|
57
|
+
}
|
|
58
|
+
export async function compileModule() {
|
|
59
|
+
const dest = ES_DIR;
|
|
60
|
+
await copy(SRC_DIR, dest);
|
|
61
|
+
const moduleDir = await readdir(dest);
|
|
62
|
+
await Promise.all(moduleDir.map((filename) => {
|
|
63
|
+
const file = resolve(dest, filename);
|
|
64
|
+
isDir(file) && ensureFileSync(resolve(file, `./style/index${getScriptExtname()}`));
|
|
65
|
+
return isDir(file) ? compileDir(file) : null;
|
|
66
|
+
}));
|
|
67
|
+
const publicDirs = await getPublicDirs();
|
|
68
|
+
await compileESEntry(dest, publicDirs);
|
|
69
|
+
clearLessFiles(dest);
|
|
70
|
+
generateReference(dest);
|
|
71
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export declare function declareEmptySFC(): string;
|
|
2
|
-
export declare function replaceExportToDeclare(script: string): string;
|
|
3
|
-
export declare function injectExport(script: string): string;
|
|
4
|
-
export declare function injectScopeId(script: string, scopeId: string): string;
|
|
5
|
-
export declare function injectRender(script: string, render: string): string;
|
|
6
|
-
export declare function compileSFC(sfc: string): Promise<void>;
|
|
1
|
+
export declare function declareEmptySFC(): string;
|
|
2
|
+
export declare function replaceExportToDeclare(script: string): string;
|
|
3
|
+
export declare function injectExport(script: string): string;
|
|
4
|
+
export declare function injectScopeId(script: string, scopeId: string): string;
|
|
5
|
+
export declare function injectRender(script: string, render: string): string;
|
|
6
|
+
export declare function compileSFC(sfc: string): Promise<void>;
|