@varlet/cli 2.18.0 → 2.18.2-alpha.1698728560863
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/commands/dev.js +28 -4
- package/lib/node/compiler/compileScript.d.ts +10 -0
- package/lib/node/compiler/compileScript.js +12 -4
- package/lib/node/config/vite.config.d.ts +1 -1
- package/lib/node/shared/constant.d.ts +1 -0
- package/lib/node/shared/constant.js +2 -1
- package/package.json +9 -9
package/lib/node/commands/dev.js
CHANGED
|
@@ -2,23 +2,47 @@ import chokidar from 'chokidar';
|
|
|
2
2
|
import fse from 'fs-extra';
|
|
3
3
|
import logger from '../shared/logger.js';
|
|
4
4
|
import { createServer } from 'vite';
|
|
5
|
-
import { SRC_DIR, VARLET_CONFIG } from '../shared/constant.js';
|
|
5
|
+
import { ES_DIR, SRC, SRC_DIR, VARLET_CONFIG } from '../shared/constant.js';
|
|
6
6
|
import { buildSiteEntry } from '../compiler/compileSiteEntry.js';
|
|
7
7
|
import { getDevConfig } from '../config/vite.config.js';
|
|
8
8
|
import { getVarletConfig } from '../config/varlet.config.js';
|
|
9
|
-
import { merge } from 'lodash-es';
|
|
10
|
-
|
|
9
|
+
import { get, merge } from 'lodash-es';
|
|
10
|
+
import { resolve } from 'path';
|
|
11
|
+
import { generateEsEntryTemplate, getScriptExtname } from '../compiler/compileScript.js';
|
|
12
|
+
import { getPublicDirs } from '../shared/fsUtils.js';
|
|
13
|
+
import { kebabCase } from '@varlet/shared';
|
|
14
|
+
const { ensureDirSync, pathExistsSync, readFileSync, outputFileSync, removeSync } = fse;
|
|
11
15
|
let server;
|
|
12
16
|
let watcher;
|
|
17
|
+
async function stub(varletConfig) {
|
|
18
|
+
const name = kebabCase(get(varletConfig, 'name'));
|
|
19
|
+
// keep esm and css file for playground
|
|
20
|
+
const esmFile = resolve(ES_DIR, `${name}.esm.js`);
|
|
21
|
+
const cssFile = resolve(ES_DIR, `style.css`);
|
|
22
|
+
const esmContent = pathExistsSync(esmFile) ? readFileSync(esmFile, 'utf-8') : '';
|
|
23
|
+
const cssContent = pathExistsSync(cssFile) ? readFileSync(cssFile, 'utf-8') : '';
|
|
24
|
+
removeSync(ES_DIR);
|
|
25
|
+
const { indexTemplate } = generateEsEntryTemplate({
|
|
26
|
+
publicDirs: await getPublicDirs(),
|
|
27
|
+
root: `../${SRC}/`,
|
|
28
|
+
scriptExtname: '',
|
|
29
|
+
});
|
|
30
|
+
outputFileSync(resolve(ES_DIR, `index${getScriptExtname()}`), indexTemplate);
|
|
31
|
+
outputFileSync(resolve(ES_DIR, `style${getScriptExtname()}`), '');
|
|
32
|
+
outputFileSync(esmFile, esmContent);
|
|
33
|
+
outputFileSync(cssFile, cssContent);
|
|
34
|
+
}
|
|
13
35
|
async function startServer(options) {
|
|
36
|
+
const varletConfig = await getVarletConfig();
|
|
14
37
|
const isRestart = Boolean(server);
|
|
15
38
|
logger.info(`${isRestart ? 'Res' : 'S'}tarting server...`);
|
|
16
39
|
// close all instance
|
|
17
40
|
server && (await server.close());
|
|
18
41
|
watcher && (await watcher.close());
|
|
42
|
+
// stub library index
|
|
43
|
+
await stub(varletConfig);
|
|
19
44
|
// build all config
|
|
20
45
|
await buildSiteEntry(options.draft ?? false);
|
|
21
|
-
const varletConfig = await getVarletConfig();
|
|
22
46
|
const devConfig = getDevConfig(varletConfig);
|
|
23
47
|
const inlineConfig = merge(devConfig, options.force ? { optimizeDeps: { force: true } } : {});
|
|
24
48
|
// create all instance
|
|
@@ -12,4 +12,14 @@ export declare function compileScriptByEsbuild(script: string): Promise<string>;
|
|
|
12
12
|
export declare function compileScript(script: string, file: string): Promise<void>;
|
|
13
13
|
export declare function compileScriptFile(file: string): Promise<void>;
|
|
14
14
|
export declare function getScriptExtname(): string;
|
|
15
|
+
export interface GenerateEsEntryTemplateOptions {
|
|
16
|
+
publicDirs: string[];
|
|
17
|
+
scriptExtname?: string;
|
|
18
|
+
root?: string;
|
|
19
|
+
}
|
|
20
|
+
export declare function generateEsEntryTemplate(options: GenerateEsEntryTemplateOptions): {
|
|
21
|
+
indexTemplate: string;
|
|
22
|
+
styleTemplate: string;
|
|
23
|
+
bundleTemplate: string;
|
|
24
|
+
};
|
|
15
25
|
export declare function compileESEntry(dir: string, publicDirs: string[]): Promise<void>;
|
|
@@ -124,21 +124,21 @@ export async function compileScriptFile(file) {
|
|
|
124
124
|
export function getScriptExtname() {
|
|
125
125
|
return '.mjs';
|
|
126
126
|
}
|
|
127
|
-
export
|
|
127
|
+
export function generateEsEntryTemplate(options) {
|
|
128
|
+
const { publicDirs, scriptExtname = getScriptExtname(), root = './' } = options;
|
|
128
129
|
const imports = [];
|
|
129
130
|
const plugins = [];
|
|
130
131
|
const exports = [];
|
|
131
132
|
const cssImports = [];
|
|
132
133
|
const publicComponents = [];
|
|
133
|
-
const scriptExtname = getScriptExtname();
|
|
134
134
|
publicDirs.forEach((dirname) => {
|
|
135
135
|
const publicComponent = bigCamelize(dirname);
|
|
136
|
-
const module = `'
|
|
136
|
+
const module = `'${root}${dirname}/index${scriptExtname}'`;
|
|
137
137
|
publicComponents.push(publicComponent);
|
|
138
138
|
imports.push(`import ${publicComponent} from ${module}`);
|
|
139
139
|
exports.push(`export * from ${module}`);
|
|
140
140
|
plugins.push(`${publicComponent}.install && app.use(${publicComponent})`);
|
|
141
|
-
cssImports.push(`import '
|
|
141
|
+
cssImports.push(`import '${root}${dirname}/style/index${scriptExtname}'`);
|
|
142
142
|
});
|
|
143
143
|
const install = `
|
|
144
144
|
function install(app) {
|
|
@@ -184,6 +184,14 @@ export default {
|
|
|
184
184
|
${publicComponents.join(',\n ')}
|
|
185
185
|
}
|
|
186
186
|
`;
|
|
187
|
+
return {
|
|
188
|
+
indexTemplate,
|
|
189
|
+
styleTemplate,
|
|
190
|
+
bundleTemplate,
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
export async function compileESEntry(dir, publicDirs) {
|
|
194
|
+
const { indexTemplate, bundleTemplate, styleTemplate } = generateEsEntryTemplate({ publicDirs });
|
|
187
195
|
await Promise.all([
|
|
188
196
|
writeFile(resolve(dir, 'index.mjs'), indexTemplate, 'utf-8'),
|
|
189
197
|
writeFile(resolve(dir, 'index.bundle.mjs'), bundleTemplate, 'utf-8'),
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { InlineConfig } from 'vite';
|
|
2
|
-
import { VarletConfig } from './varlet.config';
|
|
2
|
+
import { VarletConfig } from './varlet.config.js';
|
|
3
3
|
export declare function getDevConfig(varletConfig: Required<VarletConfig>): InlineConfig;
|
|
4
4
|
export declare function getBuildConfig(varletConfig: Required<VarletConfig>): InlineConfig;
|
|
5
5
|
export interface BundleBuildOptions {
|
|
@@ -2,6 +2,7 @@ export declare const dirname: string;
|
|
|
2
2
|
export declare const CWD: string;
|
|
3
3
|
export declare const VARLET_CONFIG: string;
|
|
4
4
|
export declare const VITEST_CONFIG: string;
|
|
5
|
+
export declare const SRC = "src";
|
|
5
6
|
export declare const SRC_DIR: string;
|
|
6
7
|
export declare const ES_DIR: string;
|
|
7
8
|
export declare const LIB_DIR: string;
|
|
@@ -4,7 +4,8 @@ export const dirname = getDirname(import.meta.url);
|
|
|
4
4
|
export const CWD = process.cwd();
|
|
5
5
|
export const VARLET_CONFIG = resolve(CWD, 'varlet.config.mjs');
|
|
6
6
|
export const VITEST_CONFIG = resolve(dirname, '../config/vitest.config.js');
|
|
7
|
-
export const
|
|
7
|
+
export const SRC = 'src';
|
|
8
|
+
export const SRC_DIR = resolve(CWD, SRC);
|
|
8
9
|
export const ES_DIR = resolve(CWD, 'es');
|
|
9
10
|
export const LIB_DIR = resolve(CWD, 'lib');
|
|
10
11
|
export const UMD_DIR = resolve(CWD, 'umd');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@varlet/cli",
|
|
3
|
-
"version": "2.18.
|
|
3
|
+
"version": "2.18.2-alpha.1698728560863",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "cli of varlet",
|
|
6
6
|
"bin": {
|
|
@@ -64,8 +64,8 @@
|
|
|
64
64
|
"vite": "4.3.5",
|
|
65
65
|
"vue": "3.3.4",
|
|
66
66
|
"webfont": "^9.0.0",
|
|
67
|
-
"@varlet/shared": "2.18.
|
|
68
|
-
"@varlet/vite-plugins": "2.18.
|
|
67
|
+
"@varlet/shared": "2.18.2-alpha.1698728560863",
|
|
68
|
+
"@varlet/vite-plugins": "2.18.2-alpha.1698728560863"
|
|
69
69
|
},
|
|
70
70
|
"devDependencies": {
|
|
71
71
|
"@types/babel__core": "^7.20.1",
|
|
@@ -80,9 +80,9 @@
|
|
|
80
80
|
"@types/semver": "^7.3.9",
|
|
81
81
|
"@types/sharp": "0.31.1",
|
|
82
82
|
"rimraf": "^5.0.1",
|
|
83
|
-
"@varlet/ui": "2.18.
|
|
84
|
-
"@varlet/
|
|
85
|
-
"@varlet/
|
|
83
|
+
"@varlet/ui": "2.18.2-alpha.1698728560863",
|
|
84
|
+
"@varlet/icons": "2.18.2-alpha.1698728560863",
|
|
85
|
+
"@varlet/touch-emulator": "2.18.2-alpha.1698728560863"
|
|
86
86
|
},
|
|
87
87
|
"peerDependencies": {
|
|
88
88
|
"@vue/runtime-core": "3.3.4",
|
|
@@ -95,9 +95,9 @@
|
|
|
95
95
|
"lodash-es": "^4.17.21",
|
|
96
96
|
"vue": "3.3.4",
|
|
97
97
|
"vue-router": "4.2.0",
|
|
98
|
-
"@varlet/
|
|
99
|
-
"@varlet/
|
|
100
|
-
"@varlet/
|
|
98
|
+
"@varlet/ui": "2.18.2-alpha.1698728560863",
|
|
99
|
+
"@varlet/icons": "2.18.2-alpha.1698728560863",
|
|
100
|
+
"@varlet/touch-emulator": "2.18.2-alpha.1698728560863"
|
|
101
101
|
},
|
|
102
102
|
"scripts": {
|
|
103
103
|
"dev": "tsc --watch",
|