@varlet/cli 1.23.3-alpha.1 → 1.23.4-alpha.16
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/CHANGELOG.md +11 -0
- package/README.en-US.md +28 -2
- package/README.md +26 -0
- package/generators/sfc/.gitignore +1 -0
- package/generators/sfc/package.json +3 -0
- package/generators/tsx/.gitignore +1 -0
- package/generators/tsx/package.json +3 -0
- package/lib/commands/compile.d.ts +1 -1
- package/lib/commands/compile.js +12 -10
- package/lib/commands/gen.js +1 -1
- package/lib/compiler/compileModule.d.ts +1 -1
- package/lib/compiler/compileModule.js +19 -14
- package/lib/compiler/compileScript.d.ts +7 -1
- package/lib/compiler/compileScript.js +77 -13
- package/lib/compiler/compileStyle.d.ts +2 -0
- package/lib/compiler/compileStyle.js +12 -5
- package/lib/compiler/compileTypes.d.ts +1 -0
- package/lib/compiler/compileTypes.js +5 -1
- package/lib/config/babel.config.js +2 -2
- package/lib/config/vite.config.js +5 -1
- package/lib/shared/constant.d.ts +1 -0
- package/lib/shared/constant.js +2 -1
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,17 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [1.23.3](https://github.com/haoziqaq/varlet/compare/v1.23.2...v1.23.3) (2021-11-20)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* **cli/jest:** add watchAll mode ([84ebb4e](https://github.com/haoziqaq/varlet/commit/84ebb4efe823cb9d7f22995d429b82d8fc3e05c8))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
6
17
|
# [1.23.0](https://github.com/haoziqaq/varlet/compare/v1.22.10...v1.23.0) (2021-11-19)
|
|
7
18
|
|
|
8
19
|
|
package/README.en-US.md
CHANGED
|
@@ -55,6 +55,32 @@ The `varlet.config.js` in the project root directory is used to manage the speci
|
|
|
55
55
|
| `analysis` | Document statistics related | _SiteAnalysis_ | `-` |
|
|
56
56
|
| `pc` | PC-side document structure configuration | _SitePC_ | `-` |
|
|
57
57
|
| `mobile` | Mobile document structure configuration | _SiteMobile_ | `-` |
|
|
58
|
+
| `moduleCompatible` | Module compatible config | _Record<string, string>_ | `-` |
|
|
59
|
+
|
|
60
|
+
#### Module Compatible
|
|
61
|
+
|
|
62
|
+
Some external dependencies may need to be compatible with module syntax to achieve the purpose of compiling correctly to `commonjs` and `esmodule`. For example, the wording of `esmodule` of `dayjs` is
|
|
63
|
+
|
|
64
|
+
```js
|
|
65
|
+
import dayjs from 'dayjs/esm'
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
In order to build `commonjs`, the writing method is
|
|
69
|
+
|
|
70
|
+
```js
|
|
71
|
+
import * as dayjs from 'dayjs'
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
In the project, we embrace the first way of writing the `esmodule` module, and make the following configuration for adaptation
|
|
75
|
+
|
|
76
|
+
```js
|
|
77
|
+
// varlet.config.js
|
|
78
|
+
module.exports = {
|
|
79
|
+
moduleCompatible: {
|
|
80
|
+
"import dayjs from 'dayjs/esm'\n": "import * as dayjs from 'dayjs'\n"
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
```
|
|
58
84
|
|
|
59
85
|
#### SiteThemes
|
|
60
86
|
|
|
@@ -93,7 +119,7 @@ Code snippets are highlighted, based on [highlight.js](https://highlightjs.org/)
|
|
|
93
119
|
|
|
94
120
|
| Parameter | Description | Type | Default |
|
|
95
121
|
| ----- | -------------- | -------- | ---------- |
|
|
96
|
-
| `style` | highlight
|
|
122
|
+
| `style` | highlight css link | _string_ | `-` |
|
|
97
123
|
|
|
98
124
|
#### SiteAnalysis
|
|
99
125
|
|
|
@@ -101,7 +127,7 @@ Statistics related to buried points
|
|
|
101
127
|
|
|
102
128
|
| Parameter | Description | Type | Default |
|
|
103
129
|
| ----- | -------------- | -------- | ---------- |
|
|
104
|
-
| `baidu` |
|
|
130
|
+
| `baidu` | Baidu statistics script address | _string_ | `-` |
|
|
105
131
|
|
|
106
132
|
#### SitePC, SiteMobile
|
|
107
133
|
|
package/README.md
CHANGED
|
@@ -53,6 +53,32 @@ yarn dev
|
|
|
53
53
|
| `analysis` | 文档统计相关 | _SiteAnalysis_ | `-` |
|
|
54
54
|
| `pc` | pc端文档结构配置 | _SitePC_ | `-` |
|
|
55
55
|
| `mobile` | mobile端文档结构配置 | _SiteMobile_ | `-` |
|
|
56
|
+
| `moduleCompatible` | 模块兼容配置 | _Record<string, string>_ | `-` |
|
|
57
|
+
|
|
58
|
+
#### 模块适配对象
|
|
59
|
+
|
|
60
|
+
一些外部依赖可能需要进行模块语法的适配,以达到可以正确编译到`commonjs`和`esmodule`的目的,例如`dayjs`的`esmodule`写法是
|
|
61
|
+
|
|
62
|
+
```js
|
|
63
|
+
import dayjs from 'dayjs/esm'
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
而为了构建`commonjs`时的写法是
|
|
67
|
+
|
|
68
|
+
```js
|
|
69
|
+
import * as dayjs from 'dayjs'
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
在项目中我们拥抱`esmodule`模块使用第一种写法,并做如下配置进行适配
|
|
73
|
+
|
|
74
|
+
```js
|
|
75
|
+
// varlet.config.js
|
|
76
|
+
module.exports = {
|
|
77
|
+
moduleCompatible: {
|
|
78
|
+
"import dayjs from 'dayjs/esm'\n": "import * as dayjs from 'dayjs'\n"
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
```
|
|
56
82
|
|
|
57
83
|
#### SiteThemes
|
|
58
84
|
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
"name": "basic-ui",
|
|
3
3
|
"version": "0.0.0",
|
|
4
4
|
"description": "A basic components library",
|
|
5
|
+
"main": "lib/index.js",
|
|
5
6
|
"module": "es/index.js",
|
|
6
7
|
"typings": "types/index.d.ts",
|
|
7
8
|
"vetur": {
|
|
@@ -64,6 +65,7 @@
|
|
|
64
65
|
"eslintConfig": {
|
|
65
66
|
"root": true,
|
|
66
67
|
"ignorePatterns": [
|
|
68
|
+
"lib/**",
|
|
67
69
|
"es/**",
|
|
68
70
|
"umd/**",
|
|
69
71
|
"site/**",
|
|
@@ -80,6 +82,7 @@
|
|
|
80
82
|
"@varlet/stylelint-config"
|
|
81
83
|
],
|
|
82
84
|
"ignoreFiles": [
|
|
85
|
+
"lib/**",
|
|
83
86
|
"es/**",
|
|
84
87
|
"umd/**",
|
|
85
88
|
"site/**",
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
"name": "basic-ui",
|
|
3
3
|
"version": "0.0.0",
|
|
4
4
|
"description": "A basic components library",
|
|
5
|
+
"main": "lib/index.js",
|
|
5
6
|
"module": "es/index.js",
|
|
6
7
|
"typings": "types/index.d.ts",
|
|
7
8
|
"vetur": {
|
|
@@ -64,6 +65,7 @@
|
|
|
64
65
|
"eslintConfig": {
|
|
65
66
|
"root": true,
|
|
66
67
|
"ignorePatterns": [
|
|
68
|
+
"lib/**",
|
|
67
69
|
"es/**",
|
|
68
70
|
"umd/**",
|
|
69
71
|
"site/**",
|
|
@@ -80,6 +82,7 @@
|
|
|
80
82
|
"@varlet/stylelint-config"
|
|
81
83
|
],
|
|
82
84
|
"ignoreFiles": [
|
|
85
|
+
"lib/**",
|
|
83
86
|
"es/**",
|
|
84
87
|
"umd/**",
|
|
85
88
|
"site/**",
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare function removeDir(): Promise<[void, void, void]>;
|
|
1
|
+
export declare function removeDir(): Promise<[void, void, void, void]>;
|
|
2
2
|
export declare function runTask(taskName: string, task: () => any): Promise<void>;
|
|
3
3
|
export declare function compile(cmd: {
|
|
4
4
|
noUmd: boolean;
|
package/lib/commands/compile.js
CHANGED
|
@@ -48,7 +48,7 @@ var compileModule_1 = require("../compiler/compileModule");
|
|
|
48
48
|
var compileTemplateHighlight_1 = require("../compiler/compileTemplateHighlight");
|
|
49
49
|
var compileTypes_1 = require("../compiler/compileTypes");
|
|
50
50
|
function removeDir() {
|
|
51
|
-
return Promise.all([(0, fs_extra_1.remove)(constant_1.ES_DIR), (0, fs_extra_1.remove)(constant_1.HL_DIR), (0, fs_extra_1.remove)(constant_1.UMD_DIR)]);
|
|
51
|
+
return Promise.all([(0, fs_extra_1.remove)(constant_1.ES_DIR), (0, fs_extra_1.remove)(constant_1.LIB_DIR), (0, fs_extra_1.remove)(constant_1.HL_DIR), (0, fs_extra_1.remove)(constant_1.UMD_DIR)]);
|
|
52
52
|
}
|
|
53
53
|
exports.removeDir = removeDir;
|
|
54
54
|
function runTask(taskName, task) {
|
|
@@ -87,20 +87,22 @@ function compile(cmd) {
|
|
|
87
87
|
return [4 /*yield*/, removeDir()];
|
|
88
88
|
case 1:
|
|
89
89
|
_b.sent();
|
|
90
|
-
return [4 /*yield*/, Promise.all([
|
|
91
|
-
runTask('types', compileTypes_1.compileTypes),
|
|
92
|
-
runTask('template highlight', compileTemplateHighlight_1.compileTemplateHighlight),
|
|
93
|
-
runTask('module', compileModule_1.compileModule),
|
|
94
|
-
])];
|
|
90
|
+
return [4 /*yield*/, Promise.all([runTask('types', compileTypes_1.compileTypes), runTask('template highlight', compileTemplateHighlight_1.compileTemplateHighlight)])];
|
|
95
91
|
case 2:
|
|
92
|
+
_b.sent();
|
|
93
|
+
return [4 /*yield*/, runTask('module', compileModule_1.compileModule)];
|
|
94
|
+
case 3:
|
|
95
|
+
_b.sent();
|
|
96
|
+
return [4 /*yield*/, runTask('commonjs', function () { return (0, compileModule_1.compileModule)('commonjs'); })];
|
|
97
|
+
case 4:
|
|
96
98
|
_b.sent();
|
|
97
99
|
_a = !cmd.noUmd;
|
|
98
|
-
if (!_a) return [3 /*break*/,
|
|
100
|
+
if (!_a) return [3 /*break*/, 6];
|
|
99
101
|
return [4 /*yield*/, runTask('umd', function () { return (0, compileModule_1.compileModule)('umd'); })];
|
|
100
|
-
case
|
|
102
|
+
case 5:
|
|
101
103
|
_a = (_b.sent());
|
|
102
|
-
_b.label =
|
|
103
|
-
case
|
|
104
|
+
_b.label = 6;
|
|
105
|
+
case 6:
|
|
104
106
|
_a;
|
|
105
107
|
return [2 /*return*/];
|
|
106
108
|
}
|
package/lib/commands/gen.js
CHANGED
|
@@ -54,7 +54,7 @@ function syncVersion(name) {
|
|
|
54
54
|
var pkg = JSON.parse((0, fs_extra_1.readFileSync)(file, 'utf-8'));
|
|
55
55
|
var cliPkg = JSON.parse((0, fs_extra_1.readFileSync)(constant_1.CLI_PACKAGE_JSON, 'utf-8'));
|
|
56
56
|
pkg.devDependencies['@varlet/cli'] = "^" + cliPkg.version;
|
|
57
|
-
pkg.files = ['es', 'umd', 'highlight', 'types', 'README.md'];
|
|
57
|
+
pkg.files = ['es', 'lib', 'umd', 'highlight', 'types', 'README.md'];
|
|
58
58
|
(0, fs_extra_1.writeFileSync)(file, JSON.stringify(pkg, null, 2));
|
|
59
59
|
}
|
|
60
60
|
function gen(name) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export declare function compileUMD(): Promise<void>;
|
|
2
2
|
export declare function compileDir(dir: string): Promise<void>;
|
|
3
3
|
export declare function compileFile(file: string): Promise<void>;
|
|
4
|
-
export declare function compileModule(modules?:
|
|
4
|
+
export declare function compileModule(modules?: 'umd' | 'commonjs' | boolean): Promise<void>;
|
|
@@ -47,6 +47,7 @@ var compileScript_1 = require("./compileScript");
|
|
|
47
47
|
var compileStyle_1 = require("./compileStyle");
|
|
48
48
|
var vite_config_1 = require("../config/vite.config");
|
|
49
49
|
var varlet_config_1 = require("../config/varlet.config");
|
|
50
|
+
var compileTypes_1 = require("./compileTypes");
|
|
50
51
|
function compileUMD() {
|
|
51
52
|
return new Promise(function (resolve, reject) {
|
|
52
53
|
var config = (0, vite_config_1.getUMDConfig)((0, varlet_config_1.getVarletConfig)());
|
|
@@ -127,23 +128,26 @@ exports.compileFile = compileFile;
|
|
|
127
128
|
function compileModule(modules) {
|
|
128
129
|
if (modules === void 0) { modules = false; }
|
|
129
130
|
return __awaiter(this, void 0, void 0, function () {
|
|
130
|
-
var
|
|
131
|
-
return __generator(this, function (
|
|
132
|
-
switch (
|
|
131
|
+
var dest, moduleDir, publicDirs;
|
|
132
|
+
return __generator(this, function (_a) {
|
|
133
|
+
switch (_a.label) {
|
|
133
134
|
case 0:
|
|
134
135
|
if (!(modules === 'umd')) return [3 /*break*/, 2];
|
|
135
136
|
return [4 /*yield*/, compileUMD()];
|
|
136
137
|
case 1:
|
|
137
|
-
|
|
138
|
+
_a.sent();
|
|
138
139
|
return [2 /*return*/];
|
|
139
|
-
case 2:
|
|
140
|
+
case 2:
|
|
141
|
+
process.env.BABEL_MODULE = modules === 'commonjs' ? 'commonjs' : 'module';
|
|
142
|
+
dest = modules === 'commonjs' ? constant_1.LIB_DIR : constant_1.ES_DIR;
|
|
143
|
+
return [4 /*yield*/, (0, fs_extra_1.copy)(constant_1.SRC_DIR, dest)];
|
|
140
144
|
case 3:
|
|
141
|
-
|
|
142
|
-
return [4 /*yield*/, (0, fs_extra_1.readdir)(
|
|
145
|
+
_a.sent();
|
|
146
|
+
return [4 /*yield*/, (0, fs_extra_1.readdir)(dest)];
|
|
143
147
|
case 4:
|
|
144
|
-
moduleDir =
|
|
148
|
+
moduleDir = _a.sent();
|
|
145
149
|
return [4 /*yield*/, Promise.all(moduleDir.map(function (filename) {
|
|
146
|
-
var file = (0, path_1.resolve)(
|
|
150
|
+
var file = (0, path_1.resolve)(dest, filename);
|
|
147
151
|
if ((0, fsUtils_1.isDir)(file)) {
|
|
148
152
|
(0, fs_extra_1.ensureFileSync)((0, path_1.resolve)(file, './style/index.js'));
|
|
149
153
|
(0, fs_extra_1.ensureFileSync)((0, path_1.resolve)(file, './style/less.js'));
|
|
@@ -151,13 +155,14 @@ function compileModule(modules) {
|
|
|
151
155
|
return (0, fsUtils_1.isDir)(file) ? compileDir(file) : null;
|
|
152
156
|
}))];
|
|
153
157
|
case 5:
|
|
154
|
-
|
|
155
|
-
_a = compileScript_1.compileLibraryEntry;
|
|
156
|
-
_b = [constant_1.ES_DIR];
|
|
158
|
+
_a.sent();
|
|
157
159
|
return [4 /*yield*/, (0, fsUtils_1.getPublicDirs)()];
|
|
158
|
-
case 6:
|
|
160
|
+
case 6:
|
|
161
|
+
publicDirs = _a.sent();
|
|
162
|
+
return [4 /*yield*/, (modules === 'commonjs' ? (0, compileScript_1.compileCommonJSEntry)(dest, publicDirs) : (0, compileScript_1.compileESEntry)(dest, publicDirs))];
|
|
159
163
|
case 7:
|
|
160
|
-
|
|
164
|
+
_a.sent();
|
|
165
|
+
(0, compileTypes_1.generateReference)(dest);
|
|
161
166
|
return [2 /*return*/];
|
|
162
167
|
}
|
|
163
168
|
});
|
|
@@ -2,10 +2,16 @@ export declare const IMPORT_VUE_PATH_RE: RegExp;
|
|
|
2
2
|
export declare const IMPORT_TS_PATH_RE: RegExp;
|
|
3
3
|
export declare const IMPORT_JSX_PATH_RE: RegExp;
|
|
4
4
|
export declare const IMPORT_TSX_PATH_RE: RegExp;
|
|
5
|
+
export declare const REQUIRE_VUE_PATH_RE: RegExp;
|
|
6
|
+
export declare const REQUIRE_TS_PATH_RE: RegExp;
|
|
7
|
+
export declare const REQUIRE_JSX_PATH_RE: RegExp;
|
|
8
|
+
export declare const REQUIRE_TSX_PATH_RE: RegExp;
|
|
5
9
|
export declare const replaceVueExt: (script: string) => string;
|
|
6
10
|
export declare const replaceTSExt: (script: string) => string;
|
|
7
11
|
export declare const replaceJSXExt: (script: string) => string;
|
|
8
12
|
export declare const replaceTSXExt: (script: string) => string;
|
|
13
|
+
export declare const moduleCompatible: (script: string) => string;
|
|
9
14
|
export declare function compileScript(script: string, file: string): Promise<void>;
|
|
10
15
|
export declare function compileScriptFile(file: string): Promise<void>;
|
|
11
|
-
export declare function
|
|
16
|
+
export declare function compileESEntry(dir: string, publicDirs: string[]): Promise<void>;
|
|
17
|
+
export declare function compileCommonJSEntry(dir: string, publicDirs: string[]): Promise<void>;
|
|
@@ -36,37 +36,65 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
36
36
|
}
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.
|
|
39
|
+
exports.compileCommonJSEntry = exports.compileESEntry = exports.compileScriptFile = exports.compileScript = exports.moduleCompatible = exports.replaceTSXExt = exports.replaceJSXExt = exports.replaceTSExt = exports.replaceVueExt = exports.REQUIRE_TSX_PATH_RE = exports.REQUIRE_JSX_PATH_RE = exports.REQUIRE_TS_PATH_RE = exports.REQUIRE_VUE_PATH_RE = exports.IMPORT_TSX_PATH_RE = exports.IMPORT_JSX_PATH_RE = exports.IMPORT_TS_PATH_RE = exports.IMPORT_VUE_PATH_RE = void 0;
|
|
40
40
|
var core_1 = require("@babel/core");
|
|
41
41
|
var fsUtils_1 = require("../shared/fsUtils");
|
|
42
42
|
var fs_extra_1 = require("fs-extra");
|
|
43
43
|
var compileStyle_1 = require("./compileStyle");
|
|
44
44
|
var path_1 = require("path");
|
|
45
|
+
var lodash_1 = require("lodash");
|
|
46
|
+
var varlet_config_1 = require("../config/varlet.config");
|
|
45
47
|
exports.IMPORT_VUE_PATH_RE = /((?<!['"`])import\s+.+from\s+['"]\s*\.{1,2}\/.+)\.vue(\s*['"`]);?(?!\s*['"`])/g;
|
|
46
48
|
exports.IMPORT_TS_PATH_RE = /((?<!['"`])import\s+.+from\s+['"]\s*\.{1,2}\/.+)\.ts(\s*['"`]);?(?!\s*['"`])/g;
|
|
47
49
|
exports.IMPORT_JSX_PATH_RE = /((?<!['"`])import\s+.+from\s+['"]\s*\.{1,2}\/.+)\.jsx(\s*['"`]);?(?!\s*['"`])/g;
|
|
48
50
|
exports.IMPORT_TSX_PATH_RE = /((?<!['"`])import\s+.+from\s+['"]\s*\.{1,2}\/.+)\.tsx(\s*['"`]);?(?!\s*['"`])/g;
|
|
51
|
+
exports.REQUIRE_VUE_PATH_RE = /(?<!['"`]\s*)(require\s*\(\s*['"]\s*\.{1,2}\/.+)\.vue(\s*['"`]\))(?!\s*['"`])/g;
|
|
52
|
+
exports.REQUIRE_TS_PATH_RE = /(?<!['"`]\s*)(require\s*\(\s*['"]\s*\.{1,2}\/.+)\.ts(\s*['"`]\))(?!\s*['"`])/g;
|
|
53
|
+
exports.REQUIRE_JSX_PATH_RE = /(?<!['"`]\s*)(require\s*\(\s*['"]\s*\.{1,2}\/.+)\.jsx(\s*['"`]\))(?!\s*['"`])/g;
|
|
54
|
+
exports.REQUIRE_TSX_PATH_RE = /(?<!['"`]\s*)(require\s*\(\s*['"]\s*\.{1,2}\/.+)\.tsx(\s*['"`]\))(?!\s*['"`])/g;
|
|
49
55
|
var scriptReplacer = function (_, p1, p2) { return p1 + ".js" + p2; };
|
|
50
|
-
var replaceVueExt = function (script) {
|
|
56
|
+
var replaceVueExt = function (script) {
|
|
57
|
+
return script.replace(exports.IMPORT_VUE_PATH_RE, scriptReplacer).replace(exports.REQUIRE_VUE_PATH_RE, scriptReplacer);
|
|
58
|
+
};
|
|
51
59
|
exports.replaceVueExt = replaceVueExt;
|
|
52
|
-
var replaceTSExt = function (script) {
|
|
60
|
+
var replaceTSExt = function (script) {
|
|
61
|
+
return script.replace(exports.IMPORT_TS_PATH_RE, scriptReplacer).replace(exports.REQUIRE_TS_PATH_RE, scriptReplacer);
|
|
62
|
+
};
|
|
53
63
|
exports.replaceTSExt = replaceTSExt;
|
|
54
|
-
var replaceJSXExt = function (script) {
|
|
64
|
+
var replaceJSXExt = function (script) {
|
|
65
|
+
return script.replace(exports.IMPORT_JSX_PATH_RE, scriptReplacer).replace(exports.REQUIRE_JSX_PATH_RE, scriptReplacer);
|
|
66
|
+
};
|
|
55
67
|
exports.replaceJSXExt = replaceJSXExt;
|
|
56
|
-
var replaceTSXExt = function (script) {
|
|
68
|
+
var replaceTSXExt = function (script) {
|
|
69
|
+
return script.replace(exports.IMPORT_TSX_PATH_RE, scriptReplacer).replace(exports.REQUIRE_TSX_PATH_RE, scriptReplacer);
|
|
70
|
+
};
|
|
57
71
|
exports.replaceTSXExt = replaceTSXExt;
|
|
72
|
+
var moduleCompatible = function (script) {
|
|
73
|
+
var moduleCompatible = (0, lodash_1.get)((0, varlet_config_1.getVarletConfig)(), 'moduleCompatible', {});
|
|
74
|
+
Object.keys(moduleCompatible).forEach(function (esm) {
|
|
75
|
+
var commonjs = moduleCompatible[esm];
|
|
76
|
+
script = script.replace(esm, commonjs);
|
|
77
|
+
});
|
|
78
|
+
return script;
|
|
79
|
+
};
|
|
80
|
+
exports.moduleCompatible = moduleCompatible;
|
|
58
81
|
function compileScript(script, file) {
|
|
59
82
|
return __awaiter(this, void 0, void 0, function () {
|
|
60
|
-
var code;
|
|
83
|
+
var modules, code;
|
|
61
84
|
return __generator(this, function (_a) {
|
|
62
85
|
switch (_a.label) {
|
|
63
|
-
case 0:
|
|
64
|
-
|
|
65
|
-
|
|
86
|
+
case 0:
|
|
87
|
+
modules = process.env.BABEL_MODULE;
|
|
88
|
+
if (modules === 'commonjs') {
|
|
89
|
+
script = (0, exports.moduleCompatible)(script);
|
|
90
|
+
}
|
|
91
|
+
return [4 /*yield*/, (0, core_1.transformAsync)(script, {
|
|
92
|
+
filename: file,
|
|
93
|
+
})];
|
|
66
94
|
case 1:
|
|
67
95
|
code = (_a.sent()).code;
|
|
68
|
-
code = (0, compileStyle_1.extractStyleDependencies)(file, code, compileStyle_1.IMPORT_CSS_RE, 'css', false);
|
|
69
|
-
code = (0, compileStyle_1.extractStyleDependencies)(file, code, compileStyle_1.IMPORT_LESS_RE, 'less', false);
|
|
96
|
+
code = (0, compileStyle_1.extractStyleDependencies)(file, code, modules === 'commonjs' ? compileStyle_1.REQUIRE_CSS_RE : compileStyle_1.IMPORT_CSS_RE, 'css', false);
|
|
97
|
+
code = (0, compileStyle_1.extractStyleDependencies)(file, code, modules === 'commonjs' ? compileStyle_1.REQUIRE_LESS_RE : compileStyle_1.IMPORT_LESS_RE, 'less', false);
|
|
70
98
|
code = (0, exports.replaceVueExt)(code);
|
|
71
99
|
code = (0, exports.replaceTSXExt)(code);
|
|
72
100
|
code = (0, exports.replaceJSXExt)(code);
|
|
@@ -95,7 +123,7 @@ function compileScriptFile(file) {
|
|
|
95
123
|
});
|
|
96
124
|
}
|
|
97
125
|
exports.compileScriptFile = compileScriptFile;
|
|
98
|
-
function
|
|
126
|
+
function compileESEntry(dir, publicDirs) {
|
|
99
127
|
return __awaiter(this, void 0, void 0, function () {
|
|
100
128
|
var imports, plugins, constInternalComponents, cssImports, lessImports, publicComponents, install, indexTemplate, styleTemplate, umdTemplate, lessTemplate;
|
|
101
129
|
return __generator(this, function (_a) {
|
|
@@ -134,4 +162,40 @@ function compileLibraryEntry(dir, publicDirs) {
|
|
|
134
162
|
});
|
|
135
163
|
});
|
|
136
164
|
}
|
|
137
|
-
exports.
|
|
165
|
+
exports.compileESEntry = compileESEntry;
|
|
166
|
+
function compileCommonJSEntry(dir, publicDirs) {
|
|
167
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
168
|
+
var requires, plugins, cssRequires, lessRequires, publicComponents, install, indexTemplate, styleTemplate, lessTemplate;
|
|
169
|
+
return __generator(this, function (_a) {
|
|
170
|
+
switch (_a.label) {
|
|
171
|
+
case 0:
|
|
172
|
+
requires = [];
|
|
173
|
+
plugins = [];
|
|
174
|
+
cssRequires = [];
|
|
175
|
+
lessRequires = [];
|
|
176
|
+
publicComponents = [];
|
|
177
|
+
publicDirs.forEach(function (dirname) {
|
|
178
|
+
var publicComponent = (0, fsUtils_1.bigCamelize)(dirname);
|
|
179
|
+
publicComponents.push(publicComponent);
|
|
180
|
+
requires.push("var " + publicComponent + " = require('./" + dirname + "')['default']");
|
|
181
|
+
plugins.push(publicComponent + ".install && app.use(" + publicComponent + ")");
|
|
182
|
+
cssRequires.push("require('./" + dirname + "/style')");
|
|
183
|
+
lessRequires.push("require('./" + dirname + "/style/less')");
|
|
184
|
+
});
|
|
185
|
+
install = "\nfunction install(app) {\n " + plugins.join('\n ') + "\n}\n";
|
|
186
|
+
indexTemplate = requires.join('\n') + "\n\n" + install + "\n\nmodule.exports = {\n install,\n " + publicComponents.join(',\n ') + "\n}\n";
|
|
187
|
+
styleTemplate = cssRequires.join('\n') + "\n";
|
|
188
|
+
lessTemplate = lessRequires.join('\n') + "\n";
|
|
189
|
+
return [4 /*yield*/, Promise.all([
|
|
190
|
+
(0, fs_extra_1.writeFile)((0, path_1.resolve)(dir, 'index.js'), indexTemplate, 'utf-8'),
|
|
191
|
+
(0, fs_extra_1.writeFile)((0, path_1.resolve)(dir, 'style.js'), styleTemplate, 'utf-8'),
|
|
192
|
+
(0, fs_extra_1.writeFile)((0, path_1.resolve)(dir, 'less.js'), lessTemplate, 'utf-8'),
|
|
193
|
+
])];
|
|
194
|
+
case 1:
|
|
195
|
+
_a.sent();
|
|
196
|
+
return [2 /*return*/];
|
|
197
|
+
}
|
|
198
|
+
});
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
exports.compileCommonJSEntry = compileCommonJSEntry;
|
|
@@ -2,6 +2,8 @@ export declare const EMPTY_SPACE_RE: RegExp;
|
|
|
2
2
|
export declare const EMPTY_LINE_RE: RegExp;
|
|
3
3
|
export declare const IMPORT_CSS_RE: RegExp;
|
|
4
4
|
export declare const IMPORT_LESS_RE: RegExp;
|
|
5
|
+
export declare const REQUIRE_CSS_RE: RegExp;
|
|
6
|
+
export declare const REQUIRE_LESS_RE: RegExp;
|
|
5
7
|
export declare const STYLE_IMPORT_RE: RegExp;
|
|
6
8
|
export declare const clearEmptyLine: (s: string) => string;
|
|
7
9
|
export declare function normalizeStyleDependency(styleImport: string, reg: RegExp): string;
|
|
@@ -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.compileLess = exports.extractStyleDependencies = exports.normalizeStyleDependency = exports.clearEmptyLine = exports.STYLE_IMPORT_RE = exports.IMPORT_LESS_RE = exports.IMPORT_CSS_RE = exports.EMPTY_LINE_RE = exports.EMPTY_SPACE_RE = void 0;
|
|
39
|
+
exports.compileLess = exports.extractStyleDependencies = exports.normalizeStyleDependency = exports.clearEmptyLine = exports.STYLE_IMPORT_RE = exports.REQUIRE_LESS_RE = exports.REQUIRE_CSS_RE = exports.IMPORT_LESS_RE = exports.IMPORT_CSS_RE = exports.EMPTY_LINE_RE = exports.EMPTY_SPACE_RE = void 0;
|
|
40
40
|
var fs_extra_1 = require("fs-extra");
|
|
41
41
|
var less_1 = require("less");
|
|
42
42
|
var fsUtils_1 = require("../shared/fsUtils");
|
|
@@ -45,6 +45,8 @@ exports.EMPTY_SPACE_RE = /[\s]+/g;
|
|
|
45
45
|
exports.EMPTY_LINE_RE = /[\n\r]*/g;
|
|
46
46
|
exports.IMPORT_CSS_RE = /(?<!['"`])import\s+['"](\.{1,2}\/.+\.css)['"]\s*;?(?!\s*['"`])/g;
|
|
47
47
|
exports.IMPORT_LESS_RE = /(?<!['"`])import\s+['"](\.{1,2}\/.+\.less)['"]\s*;?(?!\s*['"`])/g;
|
|
48
|
+
exports.REQUIRE_CSS_RE = /(?<!['"`])require\(\s*['"](\.{1,2}\/.+\.css)['"]\s*\);?(?!\s*['"`])/g;
|
|
49
|
+
exports.REQUIRE_LESS_RE = /(?<!['"`])require\(\s*['"](\.{1,2}\/.+\.less)['"]\s*\);?(?!\s*['"`])/g;
|
|
48
50
|
exports.STYLE_IMPORT_RE = /@import\s+['"](.+)['"]\s*;/g;
|
|
49
51
|
var clearEmptyLine = function (s) { return s.replace(exports.EMPTY_LINE_RE, '').replace(exports.EMPTY_SPACE_RE, ' '); };
|
|
50
52
|
exports.clearEmptyLine = clearEmptyLine;
|
|
@@ -63,14 +65,19 @@ function extractStyleDependencies(file, code, reg, expect, self) {
|
|
|
63
65
|
var styleImports = (_a = code.match(reg)) !== null && _a !== void 0 ? _a : [];
|
|
64
66
|
var cssFile = (0, path_1.resolve)(dir, './style/index.js');
|
|
65
67
|
var lessFile = (0, path_1.resolve)(dir, './style/less.js');
|
|
68
|
+
var modules = process.env.BABEL_MODULE;
|
|
66
69
|
styleImports.forEach(function (styleImport) {
|
|
67
70
|
var normalizedPath = normalizeStyleDependency(styleImport, reg);
|
|
68
|
-
(0, fsUtils_1.smartAppendFileSync)(cssFile, "import '" + normalizedPath + ".css'\n");
|
|
69
|
-
(0, fsUtils_1.smartAppendFileSync)(lessFile, "import '" + normalizedPath + "." + expect + "'\n");
|
|
71
|
+
(0, fsUtils_1.smartAppendFileSync)(cssFile, modules === 'commonjs' ? "require('" + normalizedPath + ".css')\n" : "import '" + normalizedPath + ".css'\n");
|
|
72
|
+
(0, fsUtils_1.smartAppendFileSync)(lessFile, modules === 'commonjs' ? "require('" + normalizedPath + "." + expect + "')\n" : "import '" + normalizedPath + "." + expect + "'\n");
|
|
70
73
|
});
|
|
71
74
|
if (self) {
|
|
72
|
-
(0, fsUtils_1.smartAppendFileSync)(cssFile,
|
|
73
|
-
|
|
75
|
+
(0, fsUtils_1.smartAppendFileSync)(cssFile, modules === 'commonjs'
|
|
76
|
+
? "require('" + normalizeStyleDependency(base, reg) + ".css')\n"
|
|
77
|
+
: "import '" + normalizeStyleDependency(base, reg) + ".css'\n");
|
|
78
|
+
(0, fsUtils_1.smartAppendFileSync)(lessFile, modules === 'commonjs'
|
|
79
|
+
? "require('" + normalizeStyleDependency(base, reg) + "." + expect + "')\n"
|
|
80
|
+
: "import '" + normalizeStyleDependency(base, reg) + "." + expect + "'\n");
|
|
74
81
|
}
|
|
75
82
|
return code.replace(reg, '');
|
|
76
83
|
}
|
|
@@ -36,13 +36,17 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
36
36
|
}
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.compileTypes = void 0;
|
|
39
|
+
exports.compileTypes = exports.generateReference = void 0;
|
|
40
40
|
var fs_extra_1 = require("fs-extra");
|
|
41
41
|
var constant_1 = require("../shared/constant");
|
|
42
42
|
var fsUtils_1 = require("../shared/fsUtils");
|
|
43
43
|
var path_1 = require("path");
|
|
44
44
|
var varlet_config_1 = require("../config/varlet.config");
|
|
45
45
|
var lodash_1 = require("lodash");
|
|
46
|
+
function generateReference(moduleDir) {
|
|
47
|
+
(0, fs_extra_1.writeFileSync)((0, path_1.resolve)(moduleDir, 'index.d.ts'), "export * from '" + (0, path_1.relative)(moduleDir, constant_1.TYPES_DIR) + "'\n");
|
|
48
|
+
}
|
|
49
|
+
exports.generateReference = generateReference;
|
|
46
50
|
function compileTypes() {
|
|
47
51
|
return __awaiter(this, void 0, void 0, function () {
|
|
48
52
|
var varletConfig, namespace, name, dir, ignoreEntryDir, exports, declares, template, globalTemplate;
|
|
@@ -5,13 +5,13 @@ module.exports = function (api, options) {
|
|
|
5
5
|
if (api) {
|
|
6
6
|
api.cache.never();
|
|
7
7
|
}
|
|
8
|
-
var
|
|
8
|
+
var isCommonJS = process.env.NODE_ENV === 'test' || process.env.BABEL_MODULE === 'commonjs';
|
|
9
9
|
return {
|
|
10
10
|
presets: [
|
|
11
11
|
[
|
|
12
12
|
require.resolve('@babel/preset-env'),
|
|
13
13
|
{
|
|
14
|
-
modules:
|
|
14
|
+
modules: isCommonJS ? 'commonjs' : false,
|
|
15
15
|
loose: options.loose,
|
|
16
16
|
},
|
|
17
17
|
],
|
|
@@ -80,12 +80,16 @@ function inlineCSS(fileName, dir) {
|
|
|
80
80
|
apply: 'build',
|
|
81
81
|
closeBundle: function () {
|
|
82
82
|
var cssFile = (0, path_1.resolve)(dir, 'style.css');
|
|
83
|
+
if (!(0, fs_extra_1.pathExistsSync)(cssFile)) {
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
83
86
|
var jsFile = (0, path_1.resolve)(dir, fileName);
|
|
84
87
|
var cssCode = (0, fs_extra_1.readFileSync)(cssFile, 'utf-8');
|
|
85
88
|
var jsCode = (0, fs_extra_1.readFileSync)(jsFile, 'utf-8');
|
|
86
89
|
var injectCode = ";(function(){var style=document.createElement('style');style.type='text/css';style.rel='stylesheet';style.appendChild(document.createTextNode(`" + cssCode.replace(/\\/g, '\\\\') + "`));var head=document.querySelector('head');head.appendChild(style)})();";
|
|
87
|
-
(0, fs_extra_1.removeSync)(cssFile);
|
|
88
90
|
(0, fs_extra_1.writeFileSync)(jsFile, "" + injectCode + jsCode);
|
|
91
|
+
(0, fs_extra_1.copyFileSync)(cssFile, (0, path_1.resolve)(constant_1.LIB_DIR, 'style.css'));
|
|
92
|
+
(0, fs_extra_1.removeSync)(cssFile);
|
|
89
93
|
},
|
|
90
94
|
};
|
|
91
95
|
}
|
package/lib/shared/constant.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ export declare const CWD: string;
|
|
|
2
2
|
export declare const VARLET_CONFIG: string;
|
|
3
3
|
export declare const SRC_DIR: string;
|
|
4
4
|
export declare const ES_DIR: string;
|
|
5
|
+
export declare const LIB_DIR: string;
|
|
5
6
|
export declare const UMD_DIR: string;
|
|
6
7
|
export declare const TYPES_DIR: string;
|
|
7
8
|
export declare const ROOT_DOCS_DIR: string;
|
package/lib/shared/constant.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.JEST_STYLE_MOCK = exports.JEST_MEDIA_MOCK = exports.JEST_CONFIG = exports.HL_WEB_TYPES_JSON = exports.HL_ATTRIBUTES_JSON = exports.HL_TAGS_JSON = exports.HL_DIR = exports.HL_MD = exports.HL_TITLE_SLOTS_RE = exports.HL_TITLE_EVENTS_RE = exports.HL_TITLE_ATTRIBUTES_RE = exports.HL_API_RE = exports.HL_COMPONENT_NAME_RE = exports.SITE_CONFIG = exports.SITE_MOBILE_ROUTES = exports.SITE_PC_ROUTES = exports.SITE_DIR = exports.SITE_PUBLIC_PATH = exports.SITE_OUTPUT_PATH = exports.SITE = exports.CLI_PACKAGE_JSON = exports.UI_PACKAGE_JSON = exports.GENERATORS_DIR = exports.TESTS_DIR_NAME = exports.EXAMPLE_DIR_INDEX = exports.DOCS_DIR_NAME = exports.EXAMPLE_LOCALE_DIR_NAME = exports.EXAMPLE_DIR_NAME = exports.STYLE_DIR_NAME = exports.PUBLIC_DIR_INDEXES = exports.SCRIPTS_EXTENSIONS = exports.VITE_RESOLVE_EXTENSIONS = exports.ESLINT_EXTENSIONS = exports.ROOT_DOCS_DIR = exports.TYPES_DIR = exports.UMD_DIR = exports.ES_DIR = exports.SRC_DIR = exports.VARLET_CONFIG = exports.CWD = void 0;
|
|
3
|
+
exports.JEST_STYLE_MOCK = exports.JEST_MEDIA_MOCK = exports.JEST_CONFIG = exports.HL_WEB_TYPES_JSON = exports.HL_ATTRIBUTES_JSON = exports.HL_TAGS_JSON = exports.HL_DIR = exports.HL_MD = exports.HL_TITLE_SLOTS_RE = exports.HL_TITLE_EVENTS_RE = exports.HL_TITLE_ATTRIBUTES_RE = exports.HL_API_RE = exports.HL_COMPONENT_NAME_RE = exports.SITE_CONFIG = exports.SITE_MOBILE_ROUTES = exports.SITE_PC_ROUTES = exports.SITE_DIR = exports.SITE_PUBLIC_PATH = exports.SITE_OUTPUT_PATH = exports.SITE = exports.CLI_PACKAGE_JSON = exports.UI_PACKAGE_JSON = exports.GENERATORS_DIR = exports.TESTS_DIR_NAME = exports.EXAMPLE_DIR_INDEX = exports.DOCS_DIR_NAME = exports.EXAMPLE_LOCALE_DIR_NAME = exports.EXAMPLE_DIR_NAME = exports.STYLE_DIR_NAME = exports.PUBLIC_DIR_INDEXES = exports.SCRIPTS_EXTENSIONS = exports.VITE_RESOLVE_EXTENSIONS = exports.ESLINT_EXTENSIONS = exports.ROOT_DOCS_DIR = exports.TYPES_DIR = exports.UMD_DIR = exports.LIB_DIR = exports.ES_DIR = exports.SRC_DIR = exports.VARLET_CONFIG = exports.CWD = void 0;
|
|
4
4
|
var path_1 = require("path");
|
|
5
5
|
exports.CWD = process.cwd();
|
|
6
6
|
exports.VARLET_CONFIG = (0, path_1.resolve)(exports.CWD, 'varlet.config.js');
|
|
7
7
|
exports.SRC_DIR = (0, path_1.resolve)(exports.CWD, 'src');
|
|
8
8
|
exports.ES_DIR = (0, path_1.resolve)(exports.CWD, 'es');
|
|
9
|
+
exports.LIB_DIR = (0, path_1.resolve)(exports.CWD, 'lib');
|
|
9
10
|
exports.UMD_DIR = (0, path_1.resolve)(exports.CWD, 'umd');
|
|
10
11
|
exports.TYPES_DIR = (0, path_1.resolve)(exports.CWD, 'types');
|
|
11
12
|
exports.ROOT_DOCS_DIR = (0, path_1.resolve)(exports.CWD, 'docs');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@varlet/cli",
|
|
3
|
-
"version": "1.23.
|
|
3
|
+
"version": "1.23.4-alpha.16+3e8b7b4e",
|
|
4
4
|
"description": "cli of varlet",
|
|
5
5
|
"bin": {
|
|
6
6
|
"varlet-cli": "./lib/index.js"
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"dev": "tsc --watch",
|
|
32
32
|
"build": "tsc"
|
|
33
33
|
},
|
|
34
|
-
"gitHead": "
|
|
34
|
+
"gitHead": "3e8b7b4e5489bc67dd38f8787477f07e2a13e7ac",
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"@babel/core": "^7.14.8",
|
|
37
37
|
"@babel/preset-env": "^7.14.8",
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"@vitejs/plugin-vue": "1.9.2",
|
|
48
48
|
"@vitejs/plugin-vue-jsx": "1.1.8",
|
|
49
49
|
"@vue/babel-plugin-jsx": "^1.0.7",
|
|
50
|
-
"@vue/compiler-sfc": "3.2.
|
|
50
|
+
"@vue/compiler-sfc": "3.2.22",
|
|
51
51
|
"@vue/test-utils": "^2.0.0-rc.6",
|
|
52
52
|
"babel-jest": "26.6.3",
|
|
53
53
|
"chalk": "^4.1.0",
|