@varlet/cli 1.25.0 → 1.25.1
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/commands/compile.js +8 -5
- package/lib/compiler/compileModule.d.ts +2 -1
- package/lib/compiler/compileModule.js +21 -6
- package/lib/config/vite.config.d.ts +1 -0
- package/lib/config/vite.config.js +29 -1
- package/package.json +5 -5
- package/site/components/code-example/CodeExample.vue +10 -14
- package/site/components/code-example/codeExample.less +6 -0
- package/site/components/utils/shared.ts +2 -3
- package/varlet.default.config.js +1 -5
package/lib/commands/compile.js
CHANGED
|
@@ -93,16 +93,19 @@ function compile(cmd) {
|
|
|
93
93
|
return [4 /*yield*/, runTask('module', compileModule_1.compileModule)];
|
|
94
94
|
case 3:
|
|
95
95
|
_b.sent();
|
|
96
|
-
return [4 /*yield*/, runTask('
|
|
96
|
+
return [4 /*yield*/, runTask('esm bundle', function () { return (0, compileModule_1.compileModule)('esm-bundle'); })];
|
|
97
97
|
case 4:
|
|
98
|
+
_b.sent();
|
|
99
|
+
return [4 /*yield*/, runTask('commonjs', function () { return (0, compileModule_1.compileModule)('commonjs'); })];
|
|
100
|
+
case 5:
|
|
98
101
|
_b.sent();
|
|
99
102
|
_a = !cmd.noUmd;
|
|
100
|
-
if (!_a) return [3 /*break*/,
|
|
103
|
+
if (!_a) return [3 /*break*/, 7];
|
|
101
104
|
return [4 /*yield*/, runTask('umd', function () { return (0, compileModule_1.compileModule)('umd'); })];
|
|
102
|
-
case 5:
|
|
103
|
-
_a = (_b.sent());
|
|
104
|
-
_b.label = 6;
|
|
105
105
|
case 6:
|
|
106
|
+
_a = (_b.sent());
|
|
107
|
+
_b.label = 7;
|
|
108
|
+
case 7:
|
|
106
109
|
_a;
|
|
107
110
|
return [2 /*return*/];
|
|
108
111
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export declare function compileUMD(): Promise<void>;
|
|
2
|
+
export declare function compileESMBundle(): Promise<void>;
|
|
2
3
|
export declare function compileDir(dir: string): Promise<void>;
|
|
3
4
|
export declare function compileFile(file: string): Promise<void>;
|
|
4
|
-
export declare function compileModule(modules?: 'umd' | 'commonjs' | boolean): Promise<void>;
|
|
5
|
+
export declare function compileModule(modules?: 'umd' | 'commonjs' | 'esm-bundle' | boolean): Promise<void>;
|
|
@@ -36,7 +36,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
36
36
|
}
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.compileModule = exports.compileFile = exports.compileDir = exports.compileUMD = void 0;
|
|
39
|
+
exports.compileModule = exports.compileFile = exports.compileDir = exports.compileESMBundle = exports.compileUMD = void 0;
|
|
40
40
|
var vite_1 = require("vite");
|
|
41
41
|
var path_1 = require("path");
|
|
42
42
|
var fs_extra_1 = require("fs-extra");
|
|
@@ -57,6 +57,15 @@ function compileUMD() {
|
|
|
57
57
|
});
|
|
58
58
|
}
|
|
59
59
|
exports.compileUMD = compileUMD;
|
|
60
|
+
function compileESMBundle() {
|
|
61
|
+
return new Promise(function (resolve, reject) {
|
|
62
|
+
var config = (0, vite_config_1.getESMBundleConfig)((0, varlet_config_1.getVarletConfig)());
|
|
63
|
+
(0, vite_1.build)(config)
|
|
64
|
+
.then(function () { return resolve(); })
|
|
65
|
+
.catch(reject);
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
exports.compileESMBundle = compileESMBundle;
|
|
60
69
|
function compileDir(dir) {
|
|
61
70
|
return __awaiter(this, void 0, void 0, function () {
|
|
62
71
|
var dirs;
|
|
@@ -138,13 +147,19 @@ function compileModule(modules) {
|
|
|
138
147
|
_a.sent();
|
|
139
148
|
return [2 /*return*/];
|
|
140
149
|
case 2:
|
|
150
|
+
if (!(modules === 'esm-bundle')) return [3 /*break*/, 4];
|
|
151
|
+
return [4 /*yield*/, compileESMBundle()];
|
|
152
|
+
case 3:
|
|
153
|
+
_a.sent();
|
|
154
|
+
return [2 /*return*/];
|
|
155
|
+
case 4:
|
|
141
156
|
process.env.BABEL_MODULE = modules === 'commonjs' ? 'commonjs' : 'module';
|
|
142
157
|
dest = modules === 'commonjs' ? constant_1.LIB_DIR : constant_1.ES_DIR;
|
|
143
158
|
return [4 /*yield*/, (0, fs_extra_1.copy)(constant_1.SRC_DIR, dest)];
|
|
144
|
-
case
|
|
159
|
+
case 5:
|
|
145
160
|
_a.sent();
|
|
146
161
|
return [4 /*yield*/, (0, fs_extra_1.readdir)(dest)];
|
|
147
|
-
case
|
|
162
|
+
case 6:
|
|
148
163
|
moduleDir = _a.sent();
|
|
149
164
|
return [4 /*yield*/, Promise.all(moduleDir.map(function (filename) {
|
|
150
165
|
var file = (0, path_1.resolve)(dest, filename);
|
|
@@ -154,13 +169,13 @@ function compileModule(modules) {
|
|
|
154
169
|
}
|
|
155
170
|
return (0, fsUtils_1.isDir)(file) ? compileDir(file) : null;
|
|
156
171
|
}))];
|
|
157
|
-
case
|
|
172
|
+
case 7:
|
|
158
173
|
_a.sent();
|
|
159
174
|
return [4 /*yield*/, (0, fsUtils_1.getPublicDirs)()];
|
|
160
|
-
case
|
|
175
|
+
case 8:
|
|
161
176
|
publicDirs = _a.sent();
|
|
162
177
|
return [4 /*yield*/, (modules === 'commonjs' ? (0, compileScript_1.compileCommonJSEntry)(dest, publicDirs) : (0, compileScript_1.compileESEntry)(dest, publicDirs))];
|
|
163
|
-
case
|
|
178
|
+
case 9:
|
|
164
179
|
_a.sent();
|
|
165
180
|
(0, compileTypes_1.generateReference)(dest);
|
|
166
181
|
return [2 /*return*/];
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { InlineConfig } from 'vite';
|
|
2
2
|
export declare function getDevConfig(varletConfig: Record<string, any>): InlineConfig;
|
|
3
3
|
export declare function getBuildConfig(varletConfig: Record<string, any>): InlineConfig;
|
|
4
|
+
export declare function getESMBundleConfig(varletConfig: Record<string, any>): InlineConfig;
|
|
4
5
|
export declare function getUMDConfig(varletConfig: Record<string, any>): InlineConfig;
|
|
@@ -14,7 +14,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
14
14
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.getUMDConfig = exports.getBuildConfig = exports.getDevConfig = void 0;
|
|
17
|
+
exports.getUMDConfig = exports.getESMBundleConfig = exports.getBuildConfig = exports.getDevConfig = void 0;
|
|
18
18
|
var plugin_vue_1 = __importDefault(require("@vitejs/plugin-vue"));
|
|
19
19
|
var markdown_vite_plugin_1 = __importDefault(require("@varlet/markdown-vite-plugin"));
|
|
20
20
|
var plugin_vue_jsx_1 = __importDefault(require("@vitejs/plugin-vue-jsx"));
|
|
@@ -102,6 +102,34 @@ function clear() {
|
|
|
102
102
|
},
|
|
103
103
|
};
|
|
104
104
|
}
|
|
105
|
+
function getESMBundleConfig(varletConfig) {
|
|
106
|
+
var name = (0, lodash_1.get)(varletConfig, 'name');
|
|
107
|
+
var fileName = "".concat((0, lodash_1.kebabCase)(name), ".esm.js");
|
|
108
|
+
return {
|
|
109
|
+
logLevel: 'silent',
|
|
110
|
+
build: {
|
|
111
|
+
emptyOutDir: true,
|
|
112
|
+
lib: {
|
|
113
|
+
name: name,
|
|
114
|
+
formats: ['es'],
|
|
115
|
+
fileName: function () { return fileName; },
|
|
116
|
+
entry: (0, path_1.resolve)(constant_1.ES_DIR, 'umdIndex.js'),
|
|
117
|
+
},
|
|
118
|
+
rollupOptions: {
|
|
119
|
+
external: ['vue'],
|
|
120
|
+
output: {
|
|
121
|
+
dir: constant_1.ES_DIR,
|
|
122
|
+
exports: 'named',
|
|
123
|
+
globals: {
|
|
124
|
+
vue: 'Vue',
|
|
125
|
+
},
|
|
126
|
+
},
|
|
127
|
+
},
|
|
128
|
+
},
|
|
129
|
+
plugins: [clear()],
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
exports.getESMBundleConfig = getESMBundleConfig;
|
|
105
133
|
function getUMDConfig(varletConfig) {
|
|
106
134
|
var name = (0, lodash_1.get)(varletConfig, 'name');
|
|
107
135
|
var fileName = "".concat((0, lodash_1.kebabCase)(name), ".js");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@varlet/cli",
|
|
3
|
-
"version": "1.25.
|
|
3
|
+
"version": "1.25.1",
|
|
4
4
|
"description": "cli of varlet",
|
|
5
5
|
"bin": {
|
|
6
6
|
"varlet-cli": "./lib/index.js"
|
|
@@ -33,9 +33,9 @@
|
|
|
33
33
|
"@babel/helper-plugin-utils": "^7.14.5",
|
|
34
34
|
"@babel/preset-env": "^7.14.8",
|
|
35
35
|
"@babel/preset-typescript": "^7.14.5",
|
|
36
|
-
"@varlet/icons": "1.25.
|
|
37
|
-
"@varlet/markdown-vite-plugin": "1.25.
|
|
38
|
-
"@varlet/touch-emulator": "1.25.
|
|
36
|
+
"@varlet/icons": "1.25.1",
|
|
37
|
+
"@varlet/markdown-vite-plugin": "1.25.1",
|
|
38
|
+
"@varlet/touch-emulator": "1.25.1",
|
|
39
39
|
"@vitejs/plugin-vue": "1.9.2",
|
|
40
40
|
"@vitejs/plugin-vue-jsx": "1.1.8",
|
|
41
41
|
"@vue/babel-plugin-jsx": "1.0.7",
|
|
@@ -74,7 +74,7 @@
|
|
|
74
74
|
"@types/semver": "^7.3.9"
|
|
75
75
|
},
|
|
76
76
|
"peerDependencies": {
|
|
77
|
-
"@varlet/touch-emulator": "1.25.
|
|
77
|
+
"@varlet/touch-emulator": "1.25.1",
|
|
78
78
|
"@vue/test-utils": "^2.0.0-rc.6",
|
|
79
79
|
"clipboard": "^2.0.6",
|
|
80
80
|
"live-server": "^1.2.1",
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<div class="var-site-code-example">
|
|
3
3
|
<div class="var-site-code-example__toolbar">
|
|
4
|
-
<var-site-button text round @click="toggle" v-if="fold">
|
|
4
|
+
<var-site-button text round @click="toggle" v-if="fold && !disabledFold">
|
|
5
5
|
<var-site-icon name="xml" size="18" />
|
|
6
6
|
</var-site-button>
|
|
7
7
|
|
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
<div
|
|
19
19
|
:id="`clip-target-${cid}`"
|
|
20
20
|
class="var-site-code-example__code"
|
|
21
|
+
:class="[disabledFold ? 'var-site-code-example--scroller' : null]"
|
|
21
22
|
ref="code"
|
|
22
23
|
:style="{
|
|
23
24
|
height: height >= 0 ? `${height}px` : undefined,
|
|
@@ -53,8 +54,9 @@ export default defineComponent({
|
|
|
53
54
|
const code: Ref<HTMLElement | null> = ref(null)
|
|
54
55
|
const cid: Ref<number> = ref(clipId++)
|
|
55
56
|
const fold: Ref = ref(get(config, 'pc.fold'))
|
|
57
|
+
const disabledFold: Ref<boolean> = ref(false)
|
|
56
58
|
const clipboard: Ref = ref(get(config, 'pc.clipboard', {}))
|
|
57
|
-
const height: Ref<number> = ref(
|
|
59
|
+
const height: Ref<number> = ref(-1)
|
|
58
60
|
|
|
59
61
|
const toggle = async () => {
|
|
60
62
|
const foldHeight = fold.value.foldHeight
|
|
@@ -63,21 +65,10 @@ export default defineComponent({
|
|
|
63
65
|
height.value = -1
|
|
64
66
|
await nextTick()
|
|
65
67
|
const { offsetHeight } = code.value as HTMLElement
|
|
66
|
-
|
|
67
68
|
height.value = foldHeight
|
|
68
69
|
await doubleRaf()
|
|
69
|
-
|
|
70
|
-
if (offsetHeight - foldHeight < offset) {
|
|
71
|
-
Snackbar(get(config, `pc.fold.message.${getPCLocationInfo().language}`))
|
|
72
|
-
height.value = foldHeight
|
|
73
|
-
} else {
|
|
74
|
-
height.value = offsetHeight
|
|
75
|
-
}
|
|
76
|
-
} else {
|
|
77
|
-
const { offsetHeight } = code.value as HTMLElement
|
|
78
|
-
|
|
79
70
|
height.value = offsetHeight
|
|
80
|
-
|
|
71
|
+
} else {
|
|
81
72
|
height.value = foldHeight
|
|
82
73
|
}
|
|
83
74
|
}
|
|
@@ -88,6 +79,10 @@ export default defineComponent({
|
|
|
88
79
|
trigger.on('success', () => {
|
|
89
80
|
Snackbar.success(clipboard.value[getPCLocationInfo().language])
|
|
90
81
|
})
|
|
82
|
+
|
|
83
|
+
const { offsetHeight } = code.value as HTMLElement
|
|
84
|
+
disabledFold.value = offsetHeight - fold.value.foldHeight < offset
|
|
85
|
+
height.value = fold.value?.defaultFold ? fold.value?.foldHeight : -1
|
|
91
86
|
})
|
|
92
87
|
|
|
93
88
|
return {
|
|
@@ -95,6 +90,7 @@ export default defineComponent({
|
|
|
95
90
|
height,
|
|
96
91
|
cid,
|
|
97
92
|
fold,
|
|
93
|
+
disabledFold,
|
|
98
94
|
clipboard,
|
|
99
95
|
toggle
|
|
100
96
|
}
|
|
@@ -16,9 +16,8 @@ export const isPlainObject = (val: unknown): val is Record<string, any> =>
|
|
|
16
16
|
Object.prototype.toString.call(val) === '[object Object]'
|
|
17
17
|
|
|
18
18
|
export function kebabCase(str: string): string {
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
return str.replace(reg, '$1-$2').replace(reg, '$1-$2').toLowerCase()
|
|
19
|
+
const ret = str.replace(/([A-Z])/g, ' $1').trim()
|
|
20
|
+
return ret.split(' ').join('-').toLowerCase()
|
|
22
21
|
}
|
|
23
22
|
|
|
24
23
|
export const isString = (val: unknown): val is string => typeof val === 'string'
|
package/varlet.default.config.js
CHANGED
|
@@ -37,10 +37,6 @@ module.exports = {
|
|
|
37
37
|
'en-US': 'The code has been copied to the clipboard',
|
|
38
38
|
},
|
|
39
39
|
fold: {
|
|
40
|
-
message: {
|
|
41
|
-
'zh-CN': '已显示完整代码',
|
|
42
|
-
'en-US': 'Complete code displayed',
|
|
43
|
-
},
|
|
44
40
|
defaultFold: true,
|
|
45
41
|
foldHeight: 60,
|
|
46
42
|
},
|
|
@@ -100,7 +96,7 @@ module.exports = {
|
|
|
100
96
|
'color-progress-track': '#202020',
|
|
101
97
|
'color-side-bar': '#4a7afe',
|
|
102
98
|
'color-side-bar-active-background': '#4a7afe1a',
|
|
103
|
-
'color-app-bar': '#
|
|
99
|
+
'color-app-bar': '#272727',
|
|
104
100
|
'color-nav-button-hover-background': 'rgba(255, 255, 255, 0.08)',
|
|
105
101
|
'color-mobile-cell-hover': '#4a7afe',
|
|
106
102
|
'color-pc-language-active': '#4a7afe',
|