@dimina/compiler 1.0.7 → 1.0.9
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/README.md +48 -0
- package/dist/core/logic-compiler.cjs +90 -13
- package/dist/core/logic-compiler.js +90 -13
- package/dist/core/style-compiler.cjs +59 -6
- package/dist/core/style-compiler.js +43 -7
- package/dist/core/view-compiler.cjs +538 -69
- package/dist/core/view-compiler.js +538 -69
- package/dist/env-Cmen1qwy.cjs +543 -0
- package/dist/env-Csj3AHY4.js +544 -0
- package/dist/index.cjs +195 -1
- package/dist/index.js +195 -1
- package/package.json +15 -11
- package/dist/env-CGYKCSjT.cjs +0 -322
- package/dist/env-fkuCnng-.js +0 -323
package/dist/env-CGYKCSjT.cjs
DELETED
|
@@ -1,322 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
const fs = require("node:fs");
|
|
3
|
-
const os = require("node:os");
|
|
4
|
-
const path = require("node:path");
|
|
5
|
-
const process = require("node:process");
|
|
6
|
-
function hasCompileInfo(modulePath, list, preList) {
|
|
7
|
-
const mergeList = Array.isArray(preList) ? [...preList, ...list] : list;
|
|
8
|
-
for (const element of mergeList) {
|
|
9
|
-
if (element.path === modulePath) {
|
|
10
|
-
return true;
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
return false;
|
|
14
|
-
}
|
|
15
|
-
function getAbsolutePath(workPath, pagePath, src) {
|
|
16
|
-
const relativePath = pagePath.split("/").filter((part) => part !== "").slice(0, -1).join("/");
|
|
17
|
-
return path.resolve(workPath, relativePath, src);
|
|
18
|
-
}
|
|
19
|
-
const assetsMap = {};
|
|
20
|
-
function collectAssets(workPath, pagePath, src, targetPath, appId) {
|
|
21
|
-
if (src.startsWith("http") || src.startsWith("//")) {
|
|
22
|
-
return src;
|
|
23
|
-
}
|
|
24
|
-
if (!/\.(?:png|jpe?g|gif|svg)(?:\?.*)?$/.test(src)) {
|
|
25
|
-
return src;
|
|
26
|
-
}
|
|
27
|
-
const relativePath = pagePath.split("/").slice(0, -1).join("/");
|
|
28
|
-
const absolutePath = src.startsWith("/") ? workPath + src : path.resolve(workPath, relativePath, src);
|
|
29
|
-
if (assetsMap[absolutePath]) {
|
|
30
|
-
return assetsMap[absolutePath];
|
|
31
|
-
}
|
|
32
|
-
try {
|
|
33
|
-
const ext = `.${src.split(".").pop()}`;
|
|
34
|
-
const dirPath = absolutePath.split(path.sep).slice(0, -1).join("/");
|
|
35
|
-
const prefix = uuid();
|
|
36
|
-
const targetStatic = `${targetPath}/main/static`;
|
|
37
|
-
if (!fs.existsSync(targetStatic)) {
|
|
38
|
-
fs.mkdirSync(targetStatic, { recursive: true });
|
|
39
|
-
}
|
|
40
|
-
getFilesWithExtension(dirPath, ext).forEach((file) => {
|
|
41
|
-
fs.copyFileSync(path.resolve(dirPath, file), `${targetStatic}/${prefix}_${file}`);
|
|
42
|
-
});
|
|
43
|
-
const filename = src.split("/").pop();
|
|
44
|
-
const pathPrefix = process.env.ASSETS_PATH_PREFIX ? "" : "/";
|
|
45
|
-
assetsMap[absolutePath] = `${pathPrefix}${appId}/main/static/${prefix}_${filename}`;
|
|
46
|
-
} catch (error) {
|
|
47
|
-
console.log(error);
|
|
48
|
-
}
|
|
49
|
-
return assetsMap[absolutePath] || src;
|
|
50
|
-
}
|
|
51
|
-
function getFilesWithExtension(directory, extension) {
|
|
52
|
-
const files = fs.readdirSync(directory);
|
|
53
|
-
const filteredFiles = files.filter((file) => path.extname(file) === extension);
|
|
54
|
-
return filteredFiles;
|
|
55
|
-
}
|
|
56
|
-
function isObjectEmpty(objectName) {
|
|
57
|
-
if (!objectName) {
|
|
58
|
-
return true;
|
|
59
|
-
}
|
|
60
|
-
return Object.keys(objectName).length === 0 && objectName.constructor === Object;
|
|
61
|
-
}
|
|
62
|
-
function isString(o) {
|
|
63
|
-
return Object.prototype.toString.call(o) === "[object String]";
|
|
64
|
-
}
|
|
65
|
-
function transformRpx(styleText) {
|
|
66
|
-
if (!isString(styleText)) {
|
|
67
|
-
return styleText;
|
|
68
|
-
}
|
|
69
|
-
return styleText.replace(/([+-]?\d+(?:\.\d+)?)rpx/g, (_, pixel) => {
|
|
70
|
-
return `${Number(pixel)}rem`;
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
function uuid() {
|
|
74
|
-
return Math.random().toString(36).slice(2, 7);
|
|
75
|
-
}
|
|
76
|
-
const tagWhiteList = [
|
|
77
|
-
"page",
|
|
78
|
-
"wrapper",
|
|
79
|
-
"block",
|
|
80
|
-
"button",
|
|
81
|
-
"camera",
|
|
82
|
-
"checkbox-group",
|
|
83
|
-
"checkbox",
|
|
84
|
-
"cover-image",
|
|
85
|
-
"cover-view",
|
|
86
|
-
"form",
|
|
87
|
-
"icon",
|
|
88
|
-
"image",
|
|
89
|
-
"input",
|
|
90
|
-
"keyboard-accessory",
|
|
91
|
-
"label",
|
|
92
|
-
"map",
|
|
93
|
-
"movable-area",
|
|
94
|
-
"movable-view",
|
|
95
|
-
"navigation-bar",
|
|
96
|
-
"navigator",
|
|
97
|
-
"open-data",
|
|
98
|
-
"page-meta",
|
|
99
|
-
"picker-view-column",
|
|
100
|
-
"picker-view",
|
|
101
|
-
"picker",
|
|
102
|
-
"progress",
|
|
103
|
-
"radio-group",
|
|
104
|
-
"radio",
|
|
105
|
-
"rich-text",
|
|
106
|
-
"root-portal",
|
|
107
|
-
"scroll-view",
|
|
108
|
-
"slider",
|
|
109
|
-
"swiper-item",
|
|
110
|
-
"swiper",
|
|
111
|
-
"switch",
|
|
112
|
-
"template",
|
|
113
|
-
"text",
|
|
114
|
-
"textarea",
|
|
115
|
-
"video",
|
|
116
|
-
"view",
|
|
117
|
-
"web-view"
|
|
118
|
-
];
|
|
119
|
-
let pathInfo = {};
|
|
120
|
-
let configInfo = {};
|
|
121
|
-
function storeInfo(workPath) {
|
|
122
|
-
storePathInfo(workPath);
|
|
123
|
-
storeProjectConfig();
|
|
124
|
-
storeAppConfig();
|
|
125
|
-
storePageConfig();
|
|
126
|
-
return {
|
|
127
|
-
pathInfo,
|
|
128
|
-
configInfo
|
|
129
|
-
};
|
|
130
|
-
}
|
|
131
|
-
function resetStoreInfo(opts) {
|
|
132
|
-
pathInfo = opts.pathInfo;
|
|
133
|
-
configInfo = opts.configInfo;
|
|
134
|
-
}
|
|
135
|
-
function storePathInfo(workPath) {
|
|
136
|
-
pathInfo.workPath = workPath;
|
|
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;
|
|
143
|
-
}
|
|
144
|
-
function storeProjectConfig() {
|
|
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 };
|
|
164
|
-
}
|
|
165
|
-
function storeAppConfig() {
|
|
166
|
-
const filePath = `${pathInfo.workPath}/app.json`;
|
|
167
|
-
const content = parseContentByPath(filePath);
|
|
168
|
-
const newObj = {};
|
|
169
|
-
for (const key in content) {
|
|
170
|
-
if (Object.hasOwn(content, key)) {
|
|
171
|
-
if (key === "subpackages") {
|
|
172
|
-
newObj.subPackages = content[key];
|
|
173
|
-
} else {
|
|
174
|
-
newObj[key] = content[key];
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
configInfo.appInfo = newObj;
|
|
179
|
-
}
|
|
180
|
-
function getContentByPath(path2) {
|
|
181
|
-
return fs.readFileSync(path2, { encoding: "utf-8" });
|
|
182
|
-
}
|
|
183
|
-
function parseContentByPath(path2) {
|
|
184
|
-
return JSON.parse(getContentByPath(path2));
|
|
185
|
-
}
|
|
186
|
-
function storePageConfig() {
|
|
187
|
-
const { pages, subPackages } = configInfo.appInfo;
|
|
188
|
-
configInfo.pageInfo = {};
|
|
189
|
-
configInfo.componentInfo = {};
|
|
190
|
-
collectionPageJson(pages);
|
|
191
|
-
if (subPackages) {
|
|
192
|
-
subPackages.forEach((subPkg) => {
|
|
193
|
-
collectionPageJson(subPkg.pages, subPkg.root);
|
|
194
|
-
});
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
function collectionPageJson(pages, root) {
|
|
198
|
-
pages.forEach((pagePath) => {
|
|
199
|
-
let np = pagePath;
|
|
200
|
-
if (root) {
|
|
201
|
-
if (!root.endsWith("/")) {
|
|
202
|
-
root += "/";
|
|
203
|
-
}
|
|
204
|
-
np = root + np;
|
|
205
|
-
}
|
|
206
|
-
const pageFilePath = `${pathInfo.workPath}/${np}.json`;
|
|
207
|
-
if (fs.existsSync(pageFilePath)) {
|
|
208
|
-
const pageJsonContent = parseContentByPath(pageFilePath);
|
|
209
|
-
if (root) {
|
|
210
|
-
pageJsonContent.root = transSubDir(root);
|
|
211
|
-
}
|
|
212
|
-
configInfo.pageInfo[np] = pageJsonContent;
|
|
213
|
-
storeComponentConfig(pageJsonContent, pageFilePath);
|
|
214
|
-
}
|
|
215
|
-
});
|
|
216
|
-
}
|
|
217
|
-
function storeComponentConfig(pageJsonContent, pageFilePath) {
|
|
218
|
-
if (isObjectEmpty(pageJsonContent.usingComponents)) {
|
|
219
|
-
return;
|
|
220
|
-
}
|
|
221
|
-
for (const [componentName, componentPath] of Object.entries(pageJsonContent.usingComponents)) {
|
|
222
|
-
const moduleId = getModuleId(componentPath, pageFilePath);
|
|
223
|
-
pageJsonContent.usingComponents[componentName] = moduleId;
|
|
224
|
-
if (configInfo.componentInfo[moduleId]) {
|
|
225
|
-
continue;
|
|
226
|
-
}
|
|
227
|
-
const componentFilePath = path.resolve(getWorkPath(), `./${moduleId}.json`);
|
|
228
|
-
if (!fs.existsSync(componentFilePath)) {
|
|
229
|
-
continue;
|
|
230
|
-
}
|
|
231
|
-
const cContent = parseContentByPath(componentFilePath);
|
|
232
|
-
const cUsing = cContent.usingComponents || {};
|
|
233
|
-
const isComponent = cContent.component || false;
|
|
234
|
-
const cComponents = Object.keys(cUsing).reduce((acc, key) => {
|
|
235
|
-
acc[key] = getModuleId(cUsing[key], componentFilePath);
|
|
236
|
-
return acc;
|
|
237
|
-
}, {});
|
|
238
|
-
configInfo.componentInfo[moduleId] = {
|
|
239
|
-
id: uuid(),
|
|
240
|
-
path: moduleId,
|
|
241
|
-
component: isComponent,
|
|
242
|
-
usingComponents: cComponents
|
|
243
|
-
};
|
|
244
|
-
storeComponentConfig(configInfo.componentInfo[moduleId], componentFilePath);
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
function getModuleId(src, pageFilePath) {
|
|
248
|
-
const lastIndex = pageFilePath.lastIndexOf("/");
|
|
249
|
-
const newPath = pageFilePath.slice(0, lastIndex);
|
|
250
|
-
const workPath = getWorkPath();
|
|
251
|
-
const res = path.resolve(newPath, src);
|
|
252
|
-
return res.replace(workPath, "");
|
|
253
|
-
}
|
|
254
|
-
function getTargetPath() {
|
|
255
|
-
return pathInfo.targetPath;
|
|
256
|
-
}
|
|
257
|
-
function getComponent(src) {
|
|
258
|
-
return configInfo.componentInfo[src];
|
|
259
|
-
}
|
|
260
|
-
function getPageConfigInfo() {
|
|
261
|
-
return configInfo.pageInfo;
|
|
262
|
-
}
|
|
263
|
-
function getAppConfigInfo() {
|
|
264
|
-
return configInfo.appInfo;
|
|
265
|
-
}
|
|
266
|
-
function getWorkPath() {
|
|
267
|
-
return pathInfo.workPath;
|
|
268
|
-
}
|
|
269
|
-
function getAppId() {
|
|
270
|
-
return configInfo.projectInfo.appid;
|
|
271
|
-
}
|
|
272
|
-
function getAppName() {
|
|
273
|
-
if (configInfo.projectInfo.projectname) {
|
|
274
|
-
return decodeURIComponent(configInfo.projectInfo.projectname);
|
|
275
|
-
}
|
|
276
|
-
return getAppId();
|
|
277
|
-
}
|
|
278
|
-
function transSubDir(name) {
|
|
279
|
-
return `sub_${name.replace(/\/$/, "")}`;
|
|
280
|
-
}
|
|
281
|
-
function getPages() {
|
|
282
|
-
const { pages, subPackages = [] } = getAppConfigInfo();
|
|
283
|
-
const pageInfo = getPageConfigInfo();
|
|
284
|
-
const mainPages = pages.map((path2) => ({
|
|
285
|
-
id: uuid(),
|
|
286
|
-
path: path2,
|
|
287
|
-
usingComponents: pageInfo[path2]?.usingComponents || {}
|
|
288
|
-
}));
|
|
289
|
-
const subPages = {};
|
|
290
|
-
subPackages.forEach((subPkg) => {
|
|
291
|
-
const rootPath = subPkg.root.endsWith("/") ? subPkg.root : `${subPkg.root}/`;
|
|
292
|
-
const independent = subPkg.independent ? subPkg.independent : false;
|
|
293
|
-
subPages[transSubDir(rootPath)] = {
|
|
294
|
-
independent,
|
|
295
|
-
info: subPkg.pages.map((path2) => ({
|
|
296
|
-
id: uuid(),
|
|
297
|
-
path: rootPath + path2,
|
|
298
|
-
usingComponents: pageInfo[rootPath + path2]?.usingComponents || {}
|
|
299
|
-
}))
|
|
300
|
-
};
|
|
301
|
-
});
|
|
302
|
-
return {
|
|
303
|
-
mainPages,
|
|
304
|
-
subPages
|
|
305
|
-
};
|
|
306
|
-
}
|
|
307
|
-
exports.collectAssets = collectAssets;
|
|
308
|
-
exports.getAbsolutePath = getAbsolutePath;
|
|
309
|
-
exports.getAppConfigInfo = getAppConfigInfo;
|
|
310
|
-
exports.getAppId = getAppId;
|
|
311
|
-
exports.getAppName = getAppName;
|
|
312
|
-
exports.getComponent = getComponent;
|
|
313
|
-
exports.getContentByPath = getContentByPath;
|
|
314
|
-
exports.getPageConfigInfo = getPageConfigInfo;
|
|
315
|
-
exports.getPages = getPages;
|
|
316
|
-
exports.getTargetPath = getTargetPath;
|
|
317
|
-
exports.getWorkPath = getWorkPath;
|
|
318
|
-
exports.hasCompileInfo = hasCompileInfo;
|
|
319
|
-
exports.resetStoreInfo = resetStoreInfo;
|
|
320
|
-
exports.storeInfo = storeInfo;
|
|
321
|
-
exports.tagWhiteList = tagWhiteList;
|
|
322
|
-
exports.transformRpx = transformRpx;
|
package/dist/env-fkuCnng-.js
DELETED
|
@@ -1,323 +0,0 @@
|
|
|
1
|
-
import fs from "node:fs";
|
|
2
|
-
import os from "node:os";
|
|
3
|
-
import path from "node:path";
|
|
4
|
-
import process from "node:process";
|
|
5
|
-
function hasCompileInfo(modulePath, list, preList) {
|
|
6
|
-
const mergeList = Array.isArray(preList) ? [...preList, ...list] : list;
|
|
7
|
-
for (const element of mergeList) {
|
|
8
|
-
if (element.path === modulePath) {
|
|
9
|
-
return true;
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
return false;
|
|
13
|
-
}
|
|
14
|
-
function getAbsolutePath(workPath, pagePath, src) {
|
|
15
|
-
const relativePath = pagePath.split("/").filter((part) => part !== "").slice(0, -1).join("/");
|
|
16
|
-
return path.resolve(workPath, relativePath, src);
|
|
17
|
-
}
|
|
18
|
-
const assetsMap = {};
|
|
19
|
-
function collectAssets(workPath, pagePath, src, targetPath, appId) {
|
|
20
|
-
if (src.startsWith("http") || src.startsWith("//")) {
|
|
21
|
-
return src;
|
|
22
|
-
}
|
|
23
|
-
if (!/\.(?:png|jpe?g|gif|svg)(?:\?.*)?$/.test(src)) {
|
|
24
|
-
return src;
|
|
25
|
-
}
|
|
26
|
-
const relativePath = pagePath.split("/").slice(0, -1).join("/");
|
|
27
|
-
const absolutePath = src.startsWith("/") ? workPath + src : path.resolve(workPath, relativePath, src);
|
|
28
|
-
if (assetsMap[absolutePath]) {
|
|
29
|
-
return assetsMap[absolutePath];
|
|
30
|
-
}
|
|
31
|
-
try {
|
|
32
|
-
const ext = `.${src.split(".").pop()}`;
|
|
33
|
-
const dirPath = absolutePath.split(path.sep).slice(0, -1).join("/");
|
|
34
|
-
const prefix = uuid();
|
|
35
|
-
const targetStatic = `${targetPath}/main/static`;
|
|
36
|
-
if (!fs.existsSync(targetStatic)) {
|
|
37
|
-
fs.mkdirSync(targetStatic, { recursive: true });
|
|
38
|
-
}
|
|
39
|
-
getFilesWithExtension(dirPath, ext).forEach((file) => {
|
|
40
|
-
fs.copyFileSync(path.resolve(dirPath, file), `${targetStatic}/${prefix}_${file}`);
|
|
41
|
-
});
|
|
42
|
-
const filename = src.split("/").pop();
|
|
43
|
-
const pathPrefix = process.env.ASSETS_PATH_PREFIX ? "" : "/";
|
|
44
|
-
assetsMap[absolutePath] = `${pathPrefix}${appId}/main/static/${prefix}_${filename}`;
|
|
45
|
-
} catch (error) {
|
|
46
|
-
console.log(error);
|
|
47
|
-
}
|
|
48
|
-
return assetsMap[absolutePath] || src;
|
|
49
|
-
}
|
|
50
|
-
function getFilesWithExtension(directory, extension) {
|
|
51
|
-
const files = fs.readdirSync(directory);
|
|
52
|
-
const filteredFiles = files.filter((file) => path.extname(file) === extension);
|
|
53
|
-
return filteredFiles;
|
|
54
|
-
}
|
|
55
|
-
function isObjectEmpty(objectName) {
|
|
56
|
-
if (!objectName) {
|
|
57
|
-
return true;
|
|
58
|
-
}
|
|
59
|
-
return Object.keys(objectName).length === 0 && objectName.constructor === Object;
|
|
60
|
-
}
|
|
61
|
-
function isString(o) {
|
|
62
|
-
return Object.prototype.toString.call(o) === "[object String]";
|
|
63
|
-
}
|
|
64
|
-
function transformRpx(styleText) {
|
|
65
|
-
if (!isString(styleText)) {
|
|
66
|
-
return styleText;
|
|
67
|
-
}
|
|
68
|
-
return styleText.replace(/([+-]?\d+(?:\.\d+)?)rpx/g, (_, pixel) => {
|
|
69
|
-
return `${Number(pixel)}rem`;
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
function uuid() {
|
|
73
|
-
return Math.random().toString(36).slice(2, 7);
|
|
74
|
-
}
|
|
75
|
-
const tagWhiteList = [
|
|
76
|
-
"page",
|
|
77
|
-
"wrapper",
|
|
78
|
-
"block",
|
|
79
|
-
"button",
|
|
80
|
-
"camera",
|
|
81
|
-
"checkbox-group",
|
|
82
|
-
"checkbox",
|
|
83
|
-
"cover-image",
|
|
84
|
-
"cover-view",
|
|
85
|
-
"form",
|
|
86
|
-
"icon",
|
|
87
|
-
"image",
|
|
88
|
-
"input",
|
|
89
|
-
"keyboard-accessory",
|
|
90
|
-
"label",
|
|
91
|
-
"map",
|
|
92
|
-
"movable-area",
|
|
93
|
-
"movable-view",
|
|
94
|
-
"navigation-bar",
|
|
95
|
-
"navigator",
|
|
96
|
-
"open-data",
|
|
97
|
-
"page-meta",
|
|
98
|
-
"picker-view-column",
|
|
99
|
-
"picker-view",
|
|
100
|
-
"picker",
|
|
101
|
-
"progress",
|
|
102
|
-
"radio-group",
|
|
103
|
-
"radio",
|
|
104
|
-
"rich-text",
|
|
105
|
-
"root-portal",
|
|
106
|
-
"scroll-view",
|
|
107
|
-
"slider",
|
|
108
|
-
"swiper-item",
|
|
109
|
-
"swiper",
|
|
110
|
-
"switch",
|
|
111
|
-
"template",
|
|
112
|
-
"text",
|
|
113
|
-
"textarea",
|
|
114
|
-
"video",
|
|
115
|
-
"view",
|
|
116
|
-
"web-view"
|
|
117
|
-
];
|
|
118
|
-
let pathInfo = {};
|
|
119
|
-
let configInfo = {};
|
|
120
|
-
function storeInfo(workPath) {
|
|
121
|
-
storePathInfo(workPath);
|
|
122
|
-
storeProjectConfig();
|
|
123
|
-
storeAppConfig();
|
|
124
|
-
storePageConfig();
|
|
125
|
-
return {
|
|
126
|
-
pathInfo,
|
|
127
|
-
configInfo
|
|
128
|
-
};
|
|
129
|
-
}
|
|
130
|
-
function resetStoreInfo(opts) {
|
|
131
|
-
pathInfo = opts.pathInfo;
|
|
132
|
-
configInfo = opts.configInfo;
|
|
133
|
-
}
|
|
134
|
-
function storePathInfo(workPath) {
|
|
135
|
-
pathInfo.workPath = workPath;
|
|
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;
|
|
142
|
-
}
|
|
143
|
-
function storeProjectConfig() {
|
|
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 };
|
|
163
|
-
}
|
|
164
|
-
function storeAppConfig() {
|
|
165
|
-
const filePath = `${pathInfo.workPath}/app.json`;
|
|
166
|
-
const content = parseContentByPath(filePath);
|
|
167
|
-
const newObj = {};
|
|
168
|
-
for (const key in content) {
|
|
169
|
-
if (Object.hasOwn(content, key)) {
|
|
170
|
-
if (key === "subpackages") {
|
|
171
|
-
newObj.subPackages = content[key];
|
|
172
|
-
} else {
|
|
173
|
-
newObj[key] = content[key];
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
configInfo.appInfo = newObj;
|
|
178
|
-
}
|
|
179
|
-
function getContentByPath(path2) {
|
|
180
|
-
return fs.readFileSync(path2, { encoding: "utf-8" });
|
|
181
|
-
}
|
|
182
|
-
function parseContentByPath(path2) {
|
|
183
|
-
return JSON.parse(getContentByPath(path2));
|
|
184
|
-
}
|
|
185
|
-
function storePageConfig() {
|
|
186
|
-
const { pages, subPackages } = configInfo.appInfo;
|
|
187
|
-
configInfo.pageInfo = {};
|
|
188
|
-
configInfo.componentInfo = {};
|
|
189
|
-
collectionPageJson(pages);
|
|
190
|
-
if (subPackages) {
|
|
191
|
-
subPackages.forEach((subPkg) => {
|
|
192
|
-
collectionPageJson(subPkg.pages, subPkg.root);
|
|
193
|
-
});
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
function collectionPageJson(pages, root) {
|
|
197
|
-
pages.forEach((pagePath) => {
|
|
198
|
-
let np = pagePath;
|
|
199
|
-
if (root) {
|
|
200
|
-
if (!root.endsWith("/")) {
|
|
201
|
-
root += "/";
|
|
202
|
-
}
|
|
203
|
-
np = root + np;
|
|
204
|
-
}
|
|
205
|
-
const pageFilePath = `${pathInfo.workPath}/${np}.json`;
|
|
206
|
-
if (fs.existsSync(pageFilePath)) {
|
|
207
|
-
const pageJsonContent = parseContentByPath(pageFilePath);
|
|
208
|
-
if (root) {
|
|
209
|
-
pageJsonContent.root = transSubDir(root);
|
|
210
|
-
}
|
|
211
|
-
configInfo.pageInfo[np] = pageJsonContent;
|
|
212
|
-
storeComponentConfig(pageJsonContent, pageFilePath);
|
|
213
|
-
}
|
|
214
|
-
});
|
|
215
|
-
}
|
|
216
|
-
function storeComponentConfig(pageJsonContent, pageFilePath) {
|
|
217
|
-
if (isObjectEmpty(pageJsonContent.usingComponents)) {
|
|
218
|
-
return;
|
|
219
|
-
}
|
|
220
|
-
for (const [componentName, componentPath] of Object.entries(pageJsonContent.usingComponents)) {
|
|
221
|
-
const moduleId = getModuleId(componentPath, pageFilePath);
|
|
222
|
-
pageJsonContent.usingComponents[componentName] = moduleId;
|
|
223
|
-
if (configInfo.componentInfo[moduleId]) {
|
|
224
|
-
continue;
|
|
225
|
-
}
|
|
226
|
-
const componentFilePath = path.resolve(getWorkPath(), `./${moduleId}.json`);
|
|
227
|
-
if (!fs.existsSync(componentFilePath)) {
|
|
228
|
-
continue;
|
|
229
|
-
}
|
|
230
|
-
const cContent = parseContentByPath(componentFilePath);
|
|
231
|
-
const cUsing = cContent.usingComponents || {};
|
|
232
|
-
const isComponent = cContent.component || false;
|
|
233
|
-
const cComponents = Object.keys(cUsing).reduce((acc, key) => {
|
|
234
|
-
acc[key] = getModuleId(cUsing[key], componentFilePath);
|
|
235
|
-
return acc;
|
|
236
|
-
}, {});
|
|
237
|
-
configInfo.componentInfo[moduleId] = {
|
|
238
|
-
id: uuid(),
|
|
239
|
-
path: moduleId,
|
|
240
|
-
component: isComponent,
|
|
241
|
-
usingComponents: cComponents
|
|
242
|
-
};
|
|
243
|
-
storeComponentConfig(configInfo.componentInfo[moduleId], componentFilePath);
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
function getModuleId(src, pageFilePath) {
|
|
247
|
-
const lastIndex = pageFilePath.lastIndexOf("/");
|
|
248
|
-
const newPath = pageFilePath.slice(0, lastIndex);
|
|
249
|
-
const workPath = getWorkPath();
|
|
250
|
-
const res = path.resolve(newPath, src);
|
|
251
|
-
return res.replace(workPath, "");
|
|
252
|
-
}
|
|
253
|
-
function getTargetPath() {
|
|
254
|
-
return pathInfo.targetPath;
|
|
255
|
-
}
|
|
256
|
-
function getComponent(src) {
|
|
257
|
-
return configInfo.componentInfo[src];
|
|
258
|
-
}
|
|
259
|
-
function getPageConfigInfo() {
|
|
260
|
-
return configInfo.pageInfo;
|
|
261
|
-
}
|
|
262
|
-
function getAppConfigInfo() {
|
|
263
|
-
return configInfo.appInfo;
|
|
264
|
-
}
|
|
265
|
-
function getWorkPath() {
|
|
266
|
-
return pathInfo.workPath;
|
|
267
|
-
}
|
|
268
|
-
function getAppId() {
|
|
269
|
-
return configInfo.projectInfo.appid;
|
|
270
|
-
}
|
|
271
|
-
function getAppName() {
|
|
272
|
-
if (configInfo.projectInfo.projectname) {
|
|
273
|
-
return decodeURIComponent(configInfo.projectInfo.projectname);
|
|
274
|
-
}
|
|
275
|
-
return getAppId();
|
|
276
|
-
}
|
|
277
|
-
function transSubDir(name) {
|
|
278
|
-
return `sub_${name.replace(/\/$/, "")}`;
|
|
279
|
-
}
|
|
280
|
-
function getPages() {
|
|
281
|
-
const { pages, subPackages = [] } = getAppConfigInfo();
|
|
282
|
-
const pageInfo = getPageConfigInfo();
|
|
283
|
-
const mainPages = pages.map((path2) => ({
|
|
284
|
-
id: uuid(),
|
|
285
|
-
path: path2,
|
|
286
|
-
usingComponents: pageInfo[path2]?.usingComponents || {}
|
|
287
|
-
}));
|
|
288
|
-
const subPages = {};
|
|
289
|
-
subPackages.forEach((subPkg) => {
|
|
290
|
-
const rootPath = subPkg.root.endsWith("/") ? subPkg.root : `${subPkg.root}/`;
|
|
291
|
-
const independent = subPkg.independent ? subPkg.independent : false;
|
|
292
|
-
subPages[transSubDir(rootPath)] = {
|
|
293
|
-
independent,
|
|
294
|
-
info: subPkg.pages.map((path2) => ({
|
|
295
|
-
id: uuid(),
|
|
296
|
-
path: rootPath + path2,
|
|
297
|
-
usingComponents: pageInfo[rootPath + path2]?.usingComponents || {}
|
|
298
|
-
}))
|
|
299
|
-
};
|
|
300
|
-
});
|
|
301
|
-
return {
|
|
302
|
-
mainPages,
|
|
303
|
-
subPages
|
|
304
|
-
};
|
|
305
|
-
}
|
|
306
|
-
export {
|
|
307
|
-
getComponent as a,
|
|
308
|
-
getContentByPath as b,
|
|
309
|
-
getAbsolutePath as c,
|
|
310
|
-
getWorkPath as d,
|
|
311
|
-
collectAssets as e,
|
|
312
|
-
getAppId as f,
|
|
313
|
-
getTargetPath as g,
|
|
314
|
-
tagWhiteList as h,
|
|
315
|
-
hasCompileInfo as i,
|
|
316
|
-
getAppConfigInfo as j,
|
|
317
|
-
getAppName as k,
|
|
318
|
-
getPageConfigInfo as l,
|
|
319
|
-
getPages as m,
|
|
320
|
-
resetStoreInfo as r,
|
|
321
|
-
storeInfo as s,
|
|
322
|
-
transformRpx as t
|
|
323
|
-
};
|