@ubean/vue 0.4.9 → 0.5.0
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/dist/generator.js +28 -9
- package/package.json +3 -3
package/dist/generator.js
CHANGED
|
@@ -59,15 +59,15 @@ ${scan.pages.map((p) => this.renderRouteRecord(p)).join(",\n")}
|
|
|
59
59
|
}
|
|
60
60
|
renderRouteRecord(page) {
|
|
61
61
|
const parts = [];
|
|
62
|
-
parts.push(` name: ${
|
|
63
|
-
parts.push(` path: ${
|
|
62
|
+
parts.push(` name: ${jsStringLiteral(page.name)}`);
|
|
63
|
+
parts.push(` path: ${jsStringLiteral(this.toLocalePath(page.route))}`);
|
|
64
64
|
const componentKey = page.isReuse && page.reuseTarget ? page.reuseTarget : page.name;
|
|
65
|
-
parts.push(` component: ${
|
|
65
|
+
parts.push(` component: ${jsStringLiteral(componentKey)}`);
|
|
66
66
|
if (page.layout !== void 0) {
|
|
67
67
|
let layoutVal;
|
|
68
68
|
if (page.layout === false) layoutVal = "false";
|
|
69
|
-
else if (Array.isArray(page.layout)) layoutVal =
|
|
70
|
-
else layoutVal =
|
|
69
|
+
else if (Array.isArray(page.layout)) layoutVal = `[${page.layout.map(jsStringLiteral).join(", ")}]`;
|
|
70
|
+
else layoutVal = jsStringLiteral(page.layout);
|
|
71
71
|
parts.push(` layout: ${layoutVal}`);
|
|
72
72
|
}
|
|
73
73
|
if (page.isReuse) parts.push(` reuse: true`);
|
|
@@ -156,14 +156,14 @@ ${views}
|
|
|
156
156
|
}
|
|
157
157
|
renderLayoutImport(layout) {
|
|
158
158
|
const importPath = this.opts.getLayoutImportPath?.(layout) ?? defaultLayoutImportPath(layout, this.opts.srcDir);
|
|
159
|
-
if (typeof this.opts.layoutLazy === "function" ? this.opts.layoutLazy(layout) : this.opts.layoutLazy) return ` ${layout.name}: () => import(${
|
|
159
|
+
if (typeof this.opts.layoutLazy === "function" ? this.opts.layoutLazy(layout) : this.opts.layoutLazy) return ` ${layout.name}: () => import(${jsStringLiteral(importPath)})`;
|
|
160
160
|
const importName = `__layout_${layout.name}`;
|
|
161
|
-
return ` ${layout.name}: ${importName}, // import ${importName} from ${
|
|
161
|
+
return ` ${layout.name}: ${importName}, // import ${importName} from ${jsStringLiteral(importPath)}`;
|
|
162
162
|
}
|
|
163
163
|
renderViewImport(page) {
|
|
164
164
|
const importPath = this.opts.getImportPath?.(page) ?? defaultPageImportPath(page, this.opts.srcDir);
|
|
165
|
-
if (typeof this.opts.routeLazy === "function" ? this.opts.routeLazy(page) : this.opts.routeLazy) return ` ${page.name}: () => import(${
|
|
166
|
-
return ` ${page.name}: ${page.name}, // import ${page.name} from ${
|
|
165
|
+
if (typeof this.opts.routeLazy === "function" ? this.opts.routeLazy(page) : this.opts.routeLazy) return ` ${page.name}: () => import(${jsStringLiteral(importPath)})`;
|
|
166
|
+
return ` ${page.name}: ${page.name}, // import ${page.name} from ${jsStringLiteral(importPath)}`;
|
|
167
167
|
}
|
|
168
168
|
renderDtsFile(scan) {
|
|
169
169
|
const header = this.opts.headerComment;
|
|
@@ -287,6 +287,25 @@ function defaultLayoutImportPath(layout, srcDir) {
|
|
|
287
287
|
return `@/${relativePosix(srcDir, layout.fullPath).replace(STRIPPABLE_IMPORT_EXT, "")}`;
|
|
288
288
|
}
|
|
289
289
|
/**
|
|
290
|
+
* 渲染单引号 JS 字符串字面量。
|
|
291
|
+
*
|
|
292
|
+
* 生成文件(`routes.ts` / `imports.ts`)会被提交进 git 并由仓库格式化器
|
|
293
|
+
* (`singleQuote: true`)统一风格;若用 `JSON.stringify` 输出双引号,每次
|
|
294
|
+
* 重新生成都会与格式化结果产生纯引号的 diff。这里按格式化器约定输出单引号,
|
|
295
|
+
* 只转义 JS 字符串字面量必需的部分(反斜杠、单引号、行终止符)。
|
|
296
|
+
*/
|
|
297
|
+
const JS_STRING_ESCAPES = {
|
|
298
|
+
"\\": "\\\\",
|
|
299
|
+
"'": "\\'",
|
|
300
|
+
"\n": "\\n",
|
|
301
|
+
"\r": "\\r",
|
|
302
|
+
"\u2028": "\\u2028",
|
|
303
|
+
"\u2029": "\\u2029"
|
|
304
|
+
};
|
|
305
|
+
function jsStringLiteral(value) {
|
|
306
|
+
return `'${value.replace(/[\\'\n\r\u2028\u2029]/g, (ch) => JS_STRING_ESCAPES[ch])}'`;
|
|
307
|
+
}
|
|
308
|
+
/**
|
|
290
309
|
* 从 vue-router 风格路径中提取参数信息。
|
|
291
310
|
*
|
|
292
311
|
* 支持的语法:
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ubean/vue",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "Lean Vue client kernel & page-routing owner for ubean — plugin-first page routing outlet, page cache (keep-alive), transitions, reload signal, definePage macro + file-routing Vite plugin (/vite: multi-dir scan, reuse routes, markdown & page-head opt-in). Runtime deps: vue + vue-router only.",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist"
|
|
@@ -33,10 +33,10 @@
|
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"@types/node": "^26.5.0",
|
|
36
|
-
"@ubean/markdown": "0.
|
|
36
|
+
"@ubean/markdown": "0.5.0",
|
|
37
37
|
"@unhead/vue": "^3.4.0",
|
|
38
38
|
"@vue/server-renderer": "^3.5.42",
|
|
39
|
-
"happy-dom": "^20.14.
|
|
39
|
+
"happy-dom": "^20.14.5",
|
|
40
40
|
"typescript": "npm:typescript-native-bridge@latest",
|
|
41
41
|
"vite": "npm:@voidzero-dev/vite-plus-core@0.3.1",
|
|
42
42
|
"vite-plus": "0.3.1",
|