@dimina/compiler 1.0.6 → 1.0.7
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/bin/index.cjs +3 -3
- package/dist/bin/index.js +3 -3
- package/dist/core/logic-compiler.cjs +37 -24
- package/dist/core/logic-compiler.js +37 -25
- package/dist/core/style-compiler.cjs +20 -15
- package/dist/core/style-compiler.js +19 -15
- package/dist/core/view-compiler.cjs +152 -119
- package/dist/core/view-compiler.js +150 -118
- package/dist/{env-Chow6VXH.cjs → env-CGYKCSjT.cjs} +35 -11
- package/dist/{env-CezfCSQz.js → env-fkuCnng-.js} +41 -17
- package/dist/index.cjs +65 -37
- package/dist/index.js +65 -37
- package/package.json +9 -10
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
2
|
import { isMainThread, parentPort } from "node:worker_threads";
|
|
3
3
|
import babel from "@babel/core";
|
|
4
|
-
import types from "@babel/types";
|
|
5
4
|
import _traverse from "@babel/traverse";
|
|
5
|
+
import types from "@babel/types";
|
|
6
6
|
import { compileTemplate } from "@vue/compiler-sfc";
|
|
7
7
|
import * as cheerio from "cheerio";
|
|
8
|
-
import * as htmlparser2 from "htmlparser2";
|
|
9
8
|
import { transform } from "esbuild";
|
|
10
|
-
import
|
|
9
|
+
import * as htmlparser2 from "htmlparser2";
|
|
10
|
+
import { r as resetStoreInfo, g as getTargetPath, a as getComponent, b as getContentByPath, c as getAbsolutePath, d as getWorkPath, e as collectAssets, f as getAppId, t as transformRpx, h as tagWhiteList } from "../env-fkuCnng-.js";
|
|
11
11
|
const traverse = _traverse.default ? _traverse.default : _traverse;
|
|
12
12
|
const fileType = [".wxml", ".ddml"];
|
|
13
13
|
const compileResCache = /* @__PURE__ */ new Map();
|
|
14
|
-
const processedModules = /* @__PURE__ */ new Set();
|
|
15
14
|
if (!isMainThread) {
|
|
16
15
|
parentPort.on("message", async ({ pages, storeInfo }) => {
|
|
17
16
|
try {
|
|
@@ -56,13 +55,13 @@ async function compileML(pages, root, progress) {
|
|
|
56
55
|
if (root) {
|
|
57
56
|
const subDir = `${getTargetPath()}/${root}`;
|
|
58
57
|
if (!fs.existsSync(subDir)) {
|
|
59
|
-
fs.mkdirSync(subDir);
|
|
58
|
+
fs.mkdirSync(subDir, { recursive: true });
|
|
60
59
|
}
|
|
61
60
|
fs.writeFileSync(`${subDir}/${filename}.js`, mergeRender);
|
|
62
61
|
} else {
|
|
63
62
|
const mainDir = `${getTargetPath()}/main`;
|
|
64
63
|
if (!fs.existsSync(mainDir)) {
|
|
65
|
-
fs.mkdirSync(mainDir);
|
|
64
|
+
fs.mkdirSync(mainDir, { recursive: true });
|
|
66
65
|
}
|
|
67
66
|
fs.writeFileSync(`${mainDir}/${filename}.js`, mergeRender);
|
|
68
67
|
}
|
|
@@ -72,10 +71,12 @@ async function compileML(pages, root, progress) {
|
|
|
72
71
|
function buildCompileView(module, isComponent = false, scriptRes, depthChain = []) {
|
|
73
72
|
const currentPath = module.path;
|
|
74
73
|
if (depthChain.includes(currentPath)) {
|
|
75
|
-
console.warn(`检测到循环依赖: ${[...depthChain, currentPath].join(" -> ")}`);
|
|
74
|
+
console.warn("[view]", `检测到循环依赖: ${[...depthChain, currentPath].join(" -> ")}`);
|
|
75
|
+
return;
|
|
76
76
|
}
|
|
77
|
-
if (depthChain.length >
|
|
78
|
-
console.warn(`检测到深度依赖: ${[...depthChain, currentPath].join(" -> ")}`);
|
|
77
|
+
if (depthChain.length > 20) {
|
|
78
|
+
console.warn("[view]", `检测到深度依赖: ${[...depthChain, currentPath].join(" -> ")}`);
|
|
79
|
+
return;
|
|
79
80
|
}
|
|
80
81
|
depthChain = [...depthChain, currentPath];
|
|
81
82
|
compileModule(module, isComponent, scriptRes);
|
|
@@ -85,10 +86,13 @@ function buildCompileView(module, isComponent = false, scriptRes, depthChain = [
|
|
|
85
86
|
if (!componentModule) {
|
|
86
87
|
continue;
|
|
87
88
|
}
|
|
89
|
+
if (componentModule.path === module.path) {
|
|
90
|
+
console.warn("[view]", `检测到自依赖,跳过处理: ${module.path}`);
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
88
93
|
buildCompileView(componentModule, true, scriptRes, depthChain);
|
|
89
94
|
}
|
|
90
95
|
}
|
|
91
|
-
processedModules.add(currentPath);
|
|
92
96
|
}
|
|
93
97
|
function compileModule(module, isComponent, scriptRes) {
|
|
94
98
|
const { tpl, instruction } = toCompileTemplate(isComponent, module.path, module.usingComponents, module.componentPlaceholder);
|
|
@@ -124,7 +128,7 @@ function compileModule(module, isComponent, scriptRes) {
|
|
|
124
128
|
});
|
|
125
129
|
let tplComponents = "{";
|
|
126
130
|
for (const tm of instruction.templateModule) {
|
|
127
|
-
|
|
131
|
+
let { code: code2 } = compileTemplate({
|
|
128
132
|
source: tm.tpl,
|
|
129
133
|
filename: tm.path,
|
|
130
134
|
id: `data-v-${module.id}`,
|
|
@@ -137,36 +141,17 @@ function compileModule(module, isComponent, scriptRes) {
|
|
|
137
141
|
mode: "function",
|
|
138
142
|
inline: true
|
|
139
143
|
}
|
|
140
|
-
})
|
|
144
|
+
});
|
|
145
|
+
const ast = babel.parseSync(code2);
|
|
146
|
+
insertWxsToRenderAst(ast, instruction.scriptModule, scriptRes);
|
|
147
|
+
code2 = babel.transformFromAstSync(ast, "", {
|
|
148
|
+
comments: false
|
|
149
|
+
}).code;
|
|
150
|
+
tplComponents += `'${tm.path}':${code2.replace(/;$/, "").replace(/^"use strict";\s*/, "")},`;
|
|
141
151
|
}
|
|
142
152
|
tplComponents += "}";
|
|
143
153
|
const tplAst = babel.parseSync(tplCode.code);
|
|
144
|
-
|
|
145
|
-
if (!scriptRes.has(sm.path)) {
|
|
146
|
-
scriptRes.set(sm.path, sm.code);
|
|
147
|
-
}
|
|
148
|
-
const assignmentExpression = types.assignmentExpression(
|
|
149
|
-
"=",
|
|
150
|
-
// 创建赋值表达式
|
|
151
|
-
types.memberExpression(
|
|
152
|
-
types.identifier("_ctx"),
|
|
153
|
-
// 对象标识符
|
|
154
|
-
types.identifier(sm.path),
|
|
155
|
-
// 属性标识符
|
|
156
|
-
false
|
|
157
|
-
// 是否是计算属性
|
|
158
|
-
),
|
|
159
|
-
// 创建require调用表达式
|
|
160
|
-
types.callExpression(
|
|
161
|
-
types.identifier("require"),
|
|
162
|
-
// 函数标识符
|
|
163
|
-
[types.stringLiteral(sm.path)]
|
|
164
|
-
// 参数列表,这里传入字符串字面量'foo'
|
|
165
|
-
)
|
|
166
|
-
);
|
|
167
|
-
const expressionStatement = types.expressionStatement(assignmentExpression);
|
|
168
|
-
tplAst.program.body[0].expression.body.body.splice(0, 0, expressionStatement);
|
|
169
|
-
}
|
|
154
|
+
insertWxsToRenderAst(tplAst, instruction.scriptModule, scriptRes);
|
|
170
155
|
const { code: transCode } = babel.transformFromAstSync(tplAst, "", {
|
|
171
156
|
comments: false
|
|
172
157
|
});
|
|
@@ -192,9 +177,19 @@ function toCompileTemplate(isComponent, path, components, componentPlaceholder)
|
|
|
192
177
|
} else {
|
|
193
178
|
if (isComponent) {
|
|
194
179
|
content = `<wrapper>${content}</wrapper>`;
|
|
180
|
+
} else {
|
|
181
|
+
const tempRoot = cheerio.load(content, {
|
|
182
|
+
xmlMode: true,
|
|
183
|
+
decodeEntities: false
|
|
184
|
+
});
|
|
185
|
+
const rootNodes = tempRoot.root().children().toArray().filter((node) => node.type !== "comment");
|
|
186
|
+
if (rootNodes.length > 1) {
|
|
187
|
+
content = `<view>${content}</view>`;
|
|
188
|
+
}
|
|
195
189
|
}
|
|
196
190
|
}
|
|
197
191
|
const templateModule = [];
|
|
192
|
+
const scriptModule = [];
|
|
198
193
|
const $ = cheerio.load(content, {
|
|
199
194
|
xmlMode: true,
|
|
200
195
|
decodeEntities: false
|
|
@@ -217,70 +212,34 @@ function toCompileTemplate(isComponent, path, components, componentPlaceholder)
|
|
|
217
212
|
}
|
|
218
213
|
});
|
|
219
214
|
transTagTemplate($, templateModule, path, components);
|
|
215
|
+
transTagWxs($, scriptModule, path);
|
|
220
216
|
const importNodes = $("import");
|
|
221
217
|
importNodes.each((_, elem) => {
|
|
222
218
|
const src = $(elem).attr("src");
|
|
223
219
|
if (src) {
|
|
224
|
-
const
|
|
220
|
+
const importFullPath = getAbsolutePath(workPath, path, src);
|
|
221
|
+
const importPath = importFullPath.replace(workPath, "").split("/").slice(0, -1).join("/");
|
|
222
|
+
const importContent = getContentByPath(importFullPath).trim();
|
|
225
223
|
if (importContent) {
|
|
224
|
+
const $$ = cheerio.load(importContent, {
|
|
225
|
+
xmlMode: true,
|
|
226
|
+
decodeEntities: false
|
|
227
|
+
});
|
|
226
228
|
transTagTemplate(
|
|
227
|
-
|
|
228
|
-
xmlMode: true,
|
|
229
|
-
decodeEntities: false
|
|
230
|
-
}),
|
|
229
|
+
$$,
|
|
231
230
|
templateModule,
|
|
232
231
|
path,
|
|
233
232
|
components
|
|
234
233
|
);
|
|
234
|
+
transTagWxs(
|
|
235
|
+
$$,
|
|
236
|
+
scriptModule,
|
|
237
|
+
importPath
|
|
238
|
+
);
|
|
235
239
|
}
|
|
236
240
|
}
|
|
237
241
|
});
|
|
238
242
|
importNodes.remove();
|
|
239
|
-
const scriptModule = [];
|
|
240
|
-
let wxsNodes = $("wxs");
|
|
241
|
-
if (wxsNodes.length === 0) {
|
|
242
|
-
wxsNodes = $("dds");
|
|
243
|
-
}
|
|
244
|
-
wxsNodes.each((_, elem) => {
|
|
245
|
-
const smName = $(elem).attr("module");
|
|
246
|
-
if (smName) {
|
|
247
|
-
let wxsContent;
|
|
248
|
-
if (compileResCache.has(smName)) {
|
|
249
|
-
wxsContent = compileResCache.get(smName);
|
|
250
|
-
} else {
|
|
251
|
-
const src = $(elem).attr("src");
|
|
252
|
-
if (src) {
|
|
253
|
-
wxsContent = getContentByPath(getAbsolutePath(workPath, path, src)).trim();
|
|
254
|
-
} else {
|
|
255
|
-
wxsContent = $(elem).html();
|
|
256
|
-
}
|
|
257
|
-
const wxsAst = babel.parseSync(wxsContent);
|
|
258
|
-
traverse(wxsAst, {
|
|
259
|
-
CallExpression(path2) {
|
|
260
|
-
if (path2.node.callee.name === "getRegExp" || path2.node.callee.name === "getDate") {
|
|
261
|
-
const args = [];
|
|
262
|
-
for (let i = 0; i < path2.node.arguments.length; i++) {
|
|
263
|
-
args.push(path2.node.arguments[i]);
|
|
264
|
-
}
|
|
265
|
-
const newExpr = types.newExpression(types.identifier(path2.node.callee.name.substring(3)), args);
|
|
266
|
-
path2.replaceWith(newExpr);
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
});
|
|
270
|
-
wxsContent = babel.transformFromAstSync(wxsAst, "", {
|
|
271
|
-
comments: false
|
|
272
|
-
}).code;
|
|
273
|
-
compileResCache.set(smName, wxsContent);
|
|
274
|
-
}
|
|
275
|
-
if (wxsContent) {
|
|
276
|
-
scriptModule.push({
|
|
277
|
-
path: smName,
|
|
278
|
-
code: wxsContent
|
|
279
|
-
});
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
});
|
|
283
|
-
wxsNodes.remove();
|
|
284
243
|
transAsses($, $("image"), path);
|
|
285
244
|
const res = [];
|
|
286
245
|
transHtmlTag($.html(), res, components);
|
|
@@ -297,7 +256,6 @@ function transTagTemplate($, templateModule, path, components, componentPlacehol
|
|
|
297
256
|
templateNodes.each((_, elem) => {
|
|
298
257
|
const name = $(elem).attr("name");
|
|
299
258
|
const templateContent = $(elem);
|
|
300
|
-
templateContent.find("template").remove();
|
|
301
259
|
templateContent.find("import").remove();
|
|
302
260
|
templateContent.find("include").remove();
|
|
303
261
|
templateContent.find("wxs").remove();
|
|
@@ -358,20 +316,20 @@ function transTag(opts) {
|
|
|
358
316
|
res = `dd-${tag}`;
|
|
359
317
|
}
|
|
360
318
|
let tagRes;
|
|
361
|
-
const propsAry = getProps(attrs, tag);
|
|
319
|
+
const propsAry = isStart ? getProps(attrs, tag) : [];
|
|
362
320
|
const multipleSlots = attrs?.slot;
|
|
363
321
|
if (attrs?.slot) {
|
|
364
|
-
const withVIf = [];
|
|
365
|
-
const withoutVIf = [];
|
|
366
|
-
for (let i = 0; i < propsAry.length; i++) {
|
|
367
|
-
const prop = propsAry[i];
|
|
368
|
-
if (prop.includes("v-if") || prop.includes("v-else-if") || prop.includes("v-else")) {
|
|
369
|
-
withVIf.push(prop);
|
|
370
|
-
} else {
|
|
371
|
-
withoutVIf.push(prop);
|
|
372
|
-
}
|
|
373
|
-
}
|
|
374
322
|
if (isStart) {
|
|
323
|
+
const withVIf = [];
|
|
324
|
+
const withoutVIf = [];
|
|
325
|
+
for (let i = 0; i < propsAry.length; i++) {
|
|
326
|
+
const prop = propsAry[i];
|
|
327
|
+
if (prop.includes("v-if") || prop.includes("v-else-if") || prop.includes("v-else")) {
|
|
328
|
+
withVIf.push(prop);
|
|
329
|
+
} else {
|
|
330
|
+
withoutVIf.push(prop);
|
|
331
|
+
}
|
|
332
|
+
}
|
|
375
333
|
tagRes = `<template ${`${withVIf.join(" ")}`} #${multipleSlots}><${res}${` ${withoutVIf.join(" ")}`}>`;
|
|
376
334
|
} else {
|
|
377
335
|
tagRes = `</${res}></template>`;
|
|
@@ -411,14 +369,7 @@ function getProps(attrs, tag) {
|
|
|
411
369
|
});
|
|
412
370
|
} else if (name.endsWith(":for-item") || name.endsWith(":for-index")) ;
|
|
413
371
|
else if (name.endsWith(":key")) {
|
|
414
|
-
|
|
415
|
-
if (/\*this/.test(value)) {
|
|
416
|
-
tranValue = JSON.stringify("item");
|
|
417
|
-
} else if (/item/.test(value)) {
|
|
418
|
-
tranValue = getForItemName(attrs);
|
|
419
|
-
} else {
|
|
420
|
-
tranValue = parseKeyExpression(value, getForItemName(attrs));
|
|
421
|
-
}
|
|
372
|
+
const tranValue = parseKeyExpression(value, getForItemName(attrs));
|
|
422
373
|
attrsList.push({
|
|
423
374
|
name: ":key",
|
|
424
375
|
value: tranValue
|
|
@@ -537,12 +488,22 @@ function generateVModelTemplate(expression) {
|
|
|
537
488
|
}
|
|
538
489
|
function parseKeyExpression(exp, itemName = "item") {
|
|
539
490
|
exp = exp.trim();
|
|
491
|
+
if (/\*this/.test(exp) || /\*item/.test(exp)) {
|
|
492
|
+
return `${itemName}.toString()`;
|
|
493
|
+
}
|
|
540
494
|
if (!exp.includes("{{")) {
|
|
541
|
-
|
|
495
|
+
if (/^-?\d+(\.\d+)?$/.test(exp)) {
|
|
496
|
+
return exp;
|
|
497
|
+
}
|
|
498
|
+
return exp.startsWith(itemName) ? `${exp}` : `${itemName}.${exp}`;
|
|
542
499
|
}
|
|
543
500
|
if (exp.startsWith("{{") && exp.endsWith("}}")) {
|
|
544
501
|
const content = exp.slice(2, -2).trim();
|
|
545
|
-
|
|
502
|
+
if (content === "this") {
|
|
503
|
+
return `${itemName}.toString()`;
|
|
504
|
+
} else {
|
|
505
|
+
return content.startsWith(itemName) ? `${content}` : `${itemName}.${content}`;
|
|
506
|
+
}
|
|
546
507
|
}
|
|
547
508
|
const parts = exp.split(/(\{\{.*?\}\})/);
|
|
548
509
|
const result = parts.map((part) => {
|
|
@@ -653,14 +614,85 @@ function parseBraceExp(exp) {
|
|
|
653
614
|
}
|
|
654
615
|
return group.join("").replace(/^\+|\+$/g, "");
|
|
655
616
|
}
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
617
|
+
function transTagWxs($, scriptModule, path) {
|
|
618
|
+
let wxsNodes = $("wxs");
|
|
619
|
+
if (wxsNodes.length === 0) {
|
|
620
|
+
wxsNodes = $("dds");
|
|
621
|
+
}
|
|
622
|
+
wxsNodes.each((_, elem) => {
|
|
623
|
+
const smName = $(elem).attr("module");
|
|
624
|
+
if (smName) {
|
|
625
|
+
let wxsContent;
|
|
626
|
+
if (compileResCache.has(smName)) {
|
|
627
|
+
wxsContent = compileResCache.get(smName);
|
|
628
|
+
} else {
|
|
629
|
+
const src = $(elem).attr("src");
|
|
630
|
+
if (src) {
|
|
631
|
+
wxsContent = getContentByPath(getAbsolutePath(getWorkPath(), path, src)).trim();
|
|
632
|
+
} else {
|
|
633
|
+
wxsContent = $(elem).html();
|
|
634
|
+
}
|
|
635
|
+
const wxsAst = babel.parseSync(wxsContent);
|
|
636
|
+
traverse(wxsAst, {
|
|
637
|
+
CallExpression(path2) {
|
|
638
|
+
if (path2.node.callee.name === "getRegExp" || path2.node.callee.name === "getDate") {
|
|
639
|
+
const args = [];
|
|
640
|
+
for (let i = 0; i < path2.node.arguments.length; i++) {
|
|
641
|
+
args.push(path2.node.arguments[i]);
|
|
642
|
+
}
|
|
643
|
+
const newExpr = types.newExpression(types.identifier(path2.node.callee.name.substring(3)), args);
|
|
644
|
+
path2.replaceWith(newExpr);
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
});
|
|
648
|
+
wxsContent = babel.transformFromAstSync(wxsAst, "", {
|
|
649
|
+
comments: false
|
|
650
|
+
}).code;
|
|
651
|
+
compileResCache.set(smName, wxsContent);
|
|
652
|
+
}
|
|
653
|
+
if (wxsContent) {
|
|
654
|
+
scriptModule.push({
|
|
655
|
+
path: smName,
|
|
656
|
+
code: wxsContent
|
|
657
|
+
});
|
|
658
|
+
}
|
|
659
|
+
}
|
|
660
|
+
});
|
|
661
|
+
wxsNodes.remove();
|
|
662
|
+
}
|
|
663
|
+
function insertWxsToRenderAst(ast, scriptModule, scriptRes) {
|
|
664
|
+
for (const sm of scriptModule) {
|
|
665
|
+
if (!scriptRes.has(sm.path)) {
|
|
666
|
+
scriptRes.set(sm.path, sm.code);
|
|
667
|
+
}
|
|
668
|
+
const assignmentExpression = types.assignmentExpression(
|
|
669
|
+
"=",
|
|
670
|
+
// 创建赋值表达式
|
|
671
|
+
types.memberExpression(
|
|
672
|
+
types.identifier("_ctx"),
|
|
673
|
+
// 对象标识符
|
|
674
|
+
types.identifier(sm.path),
|
|
675
|
+
// 属性标识符
|
|
676
|
+
false
|
|
677
|
+
// 是否是计算属性
|
|
678
|
+
),
|
|
679
|
+
// 创建require调用表达式
|
|
680
|
+
types.callExpression(
|
|
681
|
+
types.identifier("require"),
|
|
682
|
+
// 函数标识符
|
|
683
|
+
[types.stringLiteral(sm.path)]
|
|
684
|
+
// 参数列表,这里传入字符串字面量'foo'
|
|
685
|
+
)
|
|
686
|
+
);
|
|
687
|
+
const expressionStatement = types.expressionStatement(assignmentExpression);
|
|
688
|
+
ast.program.body[0].expression.body.body.unshift(expressionStatement);
|
|
689
|
+
}
|
|
690
|
+
}
|
|
691
|
+
export {
|
|
692
|
+
compileML,
|
|
693
|
+
generateVModelTemplate,
|
|
659
694
|
parseBraceExp,
|
|
695
|
+
parseClassRules,
|
|
660
696
|
parseKeyExpression,
|
|
661
|
-
|
|
662
|
-
generateVModelTemplate
|
|
663
|
-
};
|
|
664
|
-
export {
|
|
665
|
-
viewCompiler as default
|
|
697
|
+
splitWithBraces
|
|
666
698
|
};
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
const fs = require("node:fs");
|
|
3
|
-
const path = require("node:path");
|
|
4
3
|
const os = require("node:os");
|
|
4
|
+
const path = require("node:path");
|
|
5
|
+
const process = require("node:process");
|
|
5
6
|
function hasCompileInfo(modulePath, list, preList) {
|
|
6
7
|
const mergeList = Array.isArray(preList) ? [...preList, ...list] : list;
|
|
7
8
|
for (const element of mergeList) {
|
|
@@ -30,17 +31,18 @@ function collectAssets(workPath, pagePath, src, targetPath, appId) {
|
|
|
30
31
|
}
|
|
31
32
|
try {
|
|
32
33
|
const ext = `.${src.split(".").pop()}`;
|
|
33
|
-
const dirPath = absolutePath.split(
|
|
34
|
+
const dirPath = absolutePath.split(path.sep).slice(0, -1).join("/");
|
|
34
35
|
const prefix = uuid();
|
|
35
36
|
const targetStatic = `${targetPath}/main/static`;
|
|
36
37
|
if (!fs.existsSync(targetStatic)) {
|
|
37
|
-
fs.mkdirSync(targetStatic);
|
|
38
|
+
fs.mkdirSync(targetStatic, { recursive: true });
|
|
38
39
|
}
|
|
39
40
|
getFilesWithExtension(dirPath, ext).forEach((file) => {
|
|
40
41
|
fs.copyFileSync(path.resolve(dirPath, file), `${targetStatic}/${prefix}_${file}`);
|
|
41
42
|
});
|
|
42
43
|
const filename = src.split("/").pop();
|
|
43
|
-
|
|
44
|
+
const pathPrefix = process.env.ASSETS_PATH_PREFIX ? "" : "/";
|
|
45
|
+
assetsMap[absolutePath] = `${pathPrefix}${appId}/main/static/${prefix}_${filename}`;
|
|
44
46
|
} catch (error) {
|
|
45
47
|
console.log(error);
|
|
46
48
|
}
|
|
@@ -132,18 +134,40 @@ function resetStoreInfo(opts) {
|
|
|
132
134
|
}
|
|
133
135
|
function storePathInfo(workPath) {
|
|
134
136
|
pathInfo.workPath = workPath;
|
|
135
|
-
|
|
137
|
+
const tempDir = process.env.GITHUB_WORKSPACE || os.tmpdir();
|
|
138
|
+
const targetDir = path.join(tempDir, `dimina-fe-dist-${Date.now()}`);
|
|
139
|
+
if (!fs.existsSync(targetDir)) {
|
|
140
|
+
fs.mkdirSync(targetDir, { recursive: true });
|
|
141
|
+
}
|
|
142
|
+
pathInfo.targetPath = targetDir;
|
|
136
143
|
}
|
|
137
144
|
function storeProjectConfig() {
|
|
138
|
-
const
|
|
139
|
-
|
|
145
|
+
const privateConfigPath = `${pathInfo.workPath}/project.private.config.json`;
|
|
146
|
+
const defaultConfigPath = `${pathInfo.workPath}/project.config.json`;
|
|
147
|
+
let privateConfig = {};
|
|
148
|
+
let defaultConfig = {};
|
|
149
|
+
if (fs.existsSync(defaultConfigPath)) {
|
|
150
|
+
try {
|
|
151
|
+
defaultConfig = parseContentByPath(defaultConfigPath);
|
|
152
|
+
} catch (e) {
|
|
153
|
+
console.warn("Failed to parse project.config.json:", e.message);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
if (fs.existsSync(privateConfigPath)) {
|
|
157
|
+
try {
|
|
158
|
+
privateConfig = parseContentByPath(privateConfigPath);
|
|
159
|
+
} catch (e) {
|
|
160
|
+
console.warn("Failed to parse project.private.config.json:", e.message);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
configInfo.projectInfo = { ...defaultConfig, ...privateConfig };
|
|
140
164
|
}
|
|
141
165
|
function storeAppConfig() {
|
|
142
166
|
const filePath = `${pathInfo.workPath}/app.json`;
|
|
143
167
|
const content = parseContentByPath(filePath);
|
|
144
168
|
const newObj = {};
|
|
145
169
|
for (const key in content) {
|
|
146
|
-
if (Object.
|
|
170
|
+
if (Object.hasOwn(content, key)) {
|
|
147
171
|
if (key === "subpackages") {
|
|
148
172
|
newObj.subPackages = content[key];
|
|
149
173
|
} else {
|
|
@@ -196,10 +220,10 @@ function storeComponentConfig(pageJsonContent, pageFilePath) {
|
|
|
196
220
|
}
|
|
197
221
|
for (const [componentName, componentPath] of Object.entries(pageJsonContent.usingComponents)) {
|
|
198
222
|
const moduleId = getModuleId(componentPath, pageFilePath);
|
|
223
|
+
pageJsonContent.usingComponents[componentName] = moduleId;
|
|
199
224
|
if (configInfo.componentInfo[moduleId]) {
|
|
200
225
|
continue;
|
|
201
226
|
}
|
|
202
|
-
pageJsonContent.usingComponents[componentName] = moduleId;
|
|
203
227
|
const componentFilePath = path.resolve(getWorkPath(), `./${moduleId}.json`);
|
|
204
228
|
if (!fs.existsSync(componentFilePath)) {
|
|
205
229
|
continue;
|
|
@@ -208,7 +232,7 @@ function storeComponentConfig(pageJsonContent, pageFilePath) {
|
|
|
208
232
|
const cUsing = cContent.usingComponents || {};
|
|
209
233
|
const isComponent = cContent.component || false;
|
|
210
234
|
const cComponents = Object.keys(cUsing).reduce((acc, key) => {
|
|
211
|
-
acc[key] = getModuleId(cUsing[key],
|
|
235
|
+
acc[key] = getModuleId(cUsing[key], componentFilePath);
|
|
212
236
|
return acc;
|
|
213
237
|
}, {});
|
|
214
238
|
configInfo.componentInfo[moduleId] = {
|
|
@@ -217,7 +241,7 @@ function storeComponentConfig(pageJsonContent, pageFilePath) {
|
|
|
217
241
|
component: isComponent,
|
|
218
242
|
usingComponents: cComponents
|
|
219
243
|
};
|
|
220
|
-
storeComponentConfig(configInfo.componentInfo[moduleId],
|
|
244
|
+
storeComponentConfig(configInfo.componentInfo[moduleId], componentFilePath);
|
|
221
245
|
}
|
|
222
246
|
}
|
|
223
247
|
function getModuleId(src, pageFilePath) {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
|
-
import path from "node:path";
|
|
3
2
|
import os from "node:os";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import process from "node:process";
|
|
4
5
|
function hasCompileInfo(modulePath, list, preList) {
|
|
5
6
|
const mergeList = Array.isArray(preList) ? [...preList, ...list] : list;
|
|
6
7
|
for (const element of mergeList) {
|
|
@@ -29,17 +30,18 @@ function collectAssets(workPath, pagePath, src, targetPath, appId) {
|
|
|
29
30
|
}
|
|
30
31
|
try {
|
|
31
32
|
const ext = `.${src.split(".").pop()}`;
|
|
32
|
-
const dirPath = absolutePath.split(
|
|
33
|
+
const dirPath = absolutePath.split(path.sep).slice(0, -1).join("/");
|
|
33
34
|
const prefix = uuid();
|
|
34
35
|
const targetStatic = `${targetPath}/main/static`;
|
|
35
36
|
if (!fs.existsSync(targetStatic)) {
|
|
36
|
-
fs.mkdirSync(targetStatic);
|
|
37
|
+
fs.mkdirSync(targetStatic, { recursive: true });
|
|
37
38
|
}
|
|
38
39
|
getFilesWithExtension(dirPath, ext).forEach((file) => {
|
|
39
40
|
fs.copyFileSync(path.resolve(dirPath, file), `${targetStatic}/${prefix}_${file}`);
|
|
40
41
|
});
|
|
41
42
|
const filename = src.split("/").pop();
|
|
42
|
-
|
|
43
|
+
const pathPrefix = process.env.ASSETS_PATH_PREFIX ? "" : "/";
|
|
44
|
+
assetsMap[absolutePath] = `${pathPrefix}${appId}/main/static/${prefix}_${filename}`;
|
|
43
45
|
} catch (error) {
|
|
44
46
|
console.log(error);
|
|
45
47
|
}
|
|
@@ -131,18 +133,40 @@ function resetStoreInfo(opts) {
|
|
|
131
133
|
}
|
|
132
134
|
function storePathInfo(workPath) {
|
|
133
135
|
pathInfo.workPath = workPath;
|
|
134
|
-
|
|
136
|
+
const tempDir = process.env.GITHUB_WORKSPACE || os.tmpdir();
|
|
137
|
+
const targetDir = path.join(tempDir, `dimina-fe-dist-${Date.now()}`);
|
|
138
|
+
if (!fs.existsSync(targetDir)) {
|
|
139
|
+
fs.mkdirSync(targetDir, { recursive: true });
|
|
140
|
+
}
|
|
141
|
+
pathInfo.targetPath = targetDir;
|
|
135
142
|
}
|
|
136
143
|
function storeProjectConfig() {
|
|
137
|
-
const
|
|
138
|
-
|
|
144
|
+
const privateConfigPath = `${pathInfo.workPath}/project.private.config.json`;
|
|
145
|
+
const defaultConfigPath = `${pathInfo.workPath}/project.config.json`;
|
|
146
|
+
let privateConfig = {};
|
|
147
|
+
let defaultConfig = {};
|
|
148
|
+
if (fs.existsSync(defaultConfigPath)) {
|
|
149
|
+
try {
|
|
150
|
+
defaultConfig = parseContentByPath(defaultConfigPath);
|
|
151
|
+
} catch (e) {
|
|
152
|
+
console.warn("Failed to parse project.config.json:", e.message);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
if (fs.existsSync(privateConfigPath)) {
|
|
156
|
+
try {
|
|
157
|
+
privateConfig = parseContentByPath(privateConfigPath);
|
|
158
|
+
} catch (e) {
|
|
159
|
+
console.warn("Failed to parse project.private.config.json:", e.message);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
configInfo.projectInfo = { ...defaultConfig, ...privateConfig };
|
|
139
163
|
}
|
|
140
164
|
function storeAppConfig() {
|
|
141
165
|
const filePath = `${pathInfo.workPath}/app.json`;
|
|
142
166
|
const content = parseContentByPath(filePath);
|
|
143
167
|
const newObj = {};
|
|
144
168
|
for (const key in content) {
|
|
145
|
-
if (Object.
|
|
169
|
+
if (Object.hasOwn(content, key)) {
|
|
146
170
|
if (key === "subpackages") {
|
|
147
171
|
newObj.subPackages = content[key];
|
|
148
172
|
} else {
|
|
@@ -195,10 +219,10 @@ function storeComponentConfig(pageJsonContent, pageFilePath) {
|
|
|
195
219
|
}
|
|
196
220
|
for (const [componentName, componentPath] of Object.entries(pageJsonContent.usingComponents)) {
|
|
197
221
|
const moduleId = getModuleId(componentPath, pageFilePath);
|
|
222
|
+
pageJsonContent.usingComponents[componentName] = moduleId;
|
|
198
223
|
if (configInfo.componentInfo[moduleId]) {
|
|
199
224
|
continue;
|
|
200
225
|
}
|
|
201
|
-
pageJsonContent.usingComponents[componentName] = moduleId;
|
|
202
226
|
const componentFilePath = path.resolve(getWorkPath(), `./${moduleId}.json`);
|
|
203
227
|
if (!fs.existsSync(componentFilePath)) {
|
|
204
228
|
continue;
|
|
@@ -207,7 +231,7 @@ function storeComponentConfig(pageJsonContent, pageFilePath) {
|
|
|
207
231
|
const cUsing = cContent.usingComponents || {};
|
|
208
232
|
const isComponent = cContent.component || false;
|
|
209
233
|
const cComponents = Object.keys(cUsing).reduce((acc, key) => {
|
|
210
|
-
acc[key] = getModuleId(cUsing[key],
|
|
234
|
+
acc[key] = getModuleId(cUsing[key], componentFilePath);
|
|
211
235
|
return acc;
|
|
212
236
|
}, {});
|
|
213
237
|
configInfo.componentInfo[moduleId] = {
|
|
@@ -216,7 +240,7 @@ function storeComponentConfig(pageJsonContent, pageFilePath) {
|
|
|
216
240
|
component: isComponent,
|
|
217
241
|
usingComponents: cComponents
|
|
218
242
|
};
|
|
219
|
-
storeComponentConfig(configInfo.componentInfo[moduleId],
|
|
243
|
+
storeComponentConfig(configInfo.componentInfo[moduleId], componentFilePath);
|
|
220
244
|
}
|
|
221
245
|
}
|
|
222
246
|
function getModuleId(src, pageFilePath) {
|
|
@@ -283,16 +307,16 @@ export {
|
|
|
283
307
|
getComponent as a,
|
|
284
308
|
getContentByPath as b,
|
|
285
309
|
getAbsolutePath as c,
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
310
|
+
getWorkPath as d,
|
|
311
|
+
collectAssets as e,
|
|
312
|
+
getAppId as f,
|
|
289
313
|
getTargetPath as g,
|
|
290
314
|
tagWhiteList as h,
|
|
291
315
|
hasCompileInfo as i,
|
|
292
316
|
getAppConfigInfo as j,
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
317
|
+
getAppName as k,
|
|
318
|
+
getPageConfigInfo as l,
|
|
319
|
+
getPages as m,
|
|
296
320
|
resetStoreInfo as r,
|
|
297
321
|
storeInfo as s,
|
|
298
322
|
transformRpx as t
|