@dimina/compiler 1.0.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/README.md +119 -0
- package/dist/bin/index.cjs +32 -0
- package/dist/bin/index.js +31 -0
- package/dist/core/logic-compiler.cjs +184 -0
- package/dist/core/logic-compiler.js +185 -0
- package/dist/core/style-compiler.cjs +154 -0
- package/dist/core/style-compiler.js +155 -0
- package/dist/core/view-compiler.cjs +651 -0
- package/dist/core/view-compiler.js +634 -0
- package/dist/env-CezfCSQz.js +299 -0
- package/dist/env-Chow6VXH.cjs +298 -0
- package/dist/index.cjs +237 -0
- package/dist/index.js +237 -0
- package/package.json +70 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const path = require("node:path");
|
|
3
|
+
const node_worker_threads = require("node:worker_threads");
|
|
4
|
+
const node_url = require("node:url");
|
|
5
|
+
const listr2 = require("listr2");
|
|
6
|
+
const env = require("./env-Chow6VXH.cjs");
|
|
7
|
+
const fs = require("node:fs");
|
|
8
|
+
const process = require("node:process");
|
|
9
|
+
const shelljs = require("shelljs");
|
|
10
|
+
const os = require("node:os");
|
|
11
|
+
var _documentCurrentScript = typeof document !== "undefined" ? document.currentScript : null;
|
|
12
|
+
const artCode = `
|
|
13
|
+
██████╗ ██╗███╗ ███╗██╗███╗ ██╗ █████╗
|
|
14
|
+
██╔══██╗██║████╗ ████║██║████╗ ██║██╔══██╗
|
|
15
|
+
██║ ██║██║██╔████╔██║██║██╔██╗ ██║███████║
|
|
16
|
+
██║ ██║██║██║╚██╔╝██║██║██║╚██╗██║██╔══██║
|
|
17
|
+
██████╔╝██║██║ ╚═╝ ██║██║██║ ╚████║██║ ██║
|
|
18
|
+
╚═════╝ ╚═╝╚═╝ ╚═╝╚═╝╚═╝ ╚═══╝╚═╝ ╚═╝
|
|
19
|
+
`;
|
|
20
|
+
function artCode$1() {
|
|
21
|
+
console.log(artCode);
|
|
22
|
+
}
|
|
23
|
+
function compileConfig() {
|
|
24
|
+
const compileResInfo = {
|
|
25
|
+
app: env.getAppConfigInfo(),
|
|
26
|
+
modules: env.getPageConfigInfo()
|
|
27
|
+
};
|
|
28
|
+
const json = JSON.stringify(compileResInfo, null, 4);
|
|
29
|
+
const mainDir = `${env.getTargetPath()}/main`;
|
|
30
|
+
if (!fs.existsSync(mainDir)) {
|
|
31
|
+
fs.mkdirSync(mainDir);
|
|
32
|
+
}
|
|
33
|
+
fs.writeFileSync(`${mainDir}/app-config.json`, json);
|
|
34
|
+
}
|
|
35
|
+
function createDist() {
|
|
36
|
+
const distPath = env.getTargetPath();
|
|
37
|
+
if (shelljs.test("-d", distPath)) {
|
|
38
|
+
shelljs.rm("-rf", distPath);
|
|
39
|
+
}
|
|
40
|
+
shelljs.mkdir("-p", `${distPath}`);
|
|
41
|
+
}
|
|
42
|
+
function publishToDist(dist) {
|
|
43
|
+
const distPath = env.getTargetPath();
|
|
44
|
+
const appId = env.getAppId();
|
|
45
|
+
const absolutePath = `${path.resolve(process.cwd(), dist)}/${appId}`;
|
|
46
|
+
shelljs.rm("-rf", absolutePath);
|
|
47
|
+
shelljs.mkdir("-p", absolutePath);
|
|
48
|
+
shelljs.cp("-r", `${distPath}/*`, absolutePath);
|
|
49
|
+
}
|
|
50
|
+
function getCGroupCPUCount() {
|
|
51
|
+
try {
|
|
52
|
+
const quotaPath = "/sys/fs/cgroup/cpu/cpu.cfs_quota_us";
|
|
53
|
+
const periodPath = "/sys/fs/cgroup/cpu/cpu.cfs_period_us";
|
|
54
|
+
if (fs.existsSync(quotaPath) && fs.existsSync(periodPath)) {
|
|
55
|
+
const quota = Number.parseInt(fs.readFileSync(quotaPath, "utf8"));
|
|
56
|
+
const period = Number.parseInt(fs.readFileSync(periodPath, "utf8"));
|
|
57
|
+
if (quota > 0) {
|
|
58
|
+
return Math.max(1, Math.floor(quota / period));
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
} catch (e) {
|
|
62
|
+
console.warn("Failed to read CPU limits from cgroup:", e.message);
|
|
63
|
+
}
|
|
64
|
+
return os.cpus().length;
|
|
65
|
+
}
|
|
66
|
+
function getCGroupMemoryLimit() {
|
|
67
|
+
try {
|
|
68
|
+
const memLimitPath = "/sys/fs/cgroup/memory/memory.limit_in_bytes";
|
|
69
|
+
if (fs.existsSync(memLimitPath)) {
|
|
70
|
+
const memLimit = Number.parseInt(fs.readFileSync(memLimitPath, "utf8"));
|
|
71
|
+
if (memLimit < Infinity && memLimit > 0) {
|
|
72
|
+
return memLimit;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
} catch (e) {
|
|
76
|
+
console.warn("Failed to read memory limits from cgroup:", e.message);
|
|
77
|
+
}
|
|
78
|
+
return os.totalmem();
|
|
79
|
+
}
|
|
80
|
+
const MAX_WORKERS = Math.max(1, Math.floor(getCGroupCPUCount() / 4));
|
|
81
|
+
class WorkerPool {
|
|
82
|
+
constructor(maxWorkers = MAX_WORKERS) {
|
|
83
|
+
this.maxWorkers = maxWorkers;
|
|
84
|
+
this.activeWorkers = 0;
|
|
85
|
+
this.queue = [];
|
|
86
|
+
this.memoryLimit = Math.floor(getCGroupMemoryLimit() * 0.7 / maxWorkers);
|
|
87
|
+
}
|
|
88
|
+
async runWorker(workerCreator) {
|
|
89
|
+
if (this.activeWorkers >= this.maxWorkers) {
|
|
90
|
+
await new Promise((resolve) => this.queue.push(resolve));
|
|
91
|
+
}
|
|
92
|
+
this.activeWorkers++;
|
|
93
|
+
try {
|
|
94
|
+
return await workerCreator();
|
|
95
|
+
} finally {
|
|
96
|
+
this.activeWorkers--;
|
|
97
|
+
if (this.queue.length > 0) {
|
|
98
|
+
const next = this.queue.shift();
|
|
99
|
+
next();
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
getWorkerOptions() {
|
|
104
|
+
return {
|
|
105
|
+
resourceLimits: {
|
|
106
|
+
maxOldGenerationSizeMb: Math.floor(this.memoryLimit / (1024 * 1024)),
|
|
107
|
+
// Convert bytes to MB
|
|
108
|
+
maxYoungGenerationSizeMb: Math.floor(this.memoryLimit / (1024 * 1024) / 4),
|
|
109
|
+
codeRangeSizeMb: 128
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
const workerPool = new WorkerPool();
|
|
115
|
+
let isPrinted = false;
|
|
116
|
+
async function build(targetPath, workPath) {
|
|
117
|
+
if (!isPrinted) {
|
|
118
|
+
artCode$1();
|
|
119
|
+
isPrinted = true;
|
|
120
|
+
}
|
|
121
|
+
const tasks = new listr2.Listr(
|
|
122
|
+
[
|
|
123
|
+
{
|
|
124
|
+
title: "准备项目编译环境",
|
|
125
|
+
task: (_, task) => task.newListr(
|
|
126
|
+
[
|
|
127
|
+
{
|
|
128
|
+
title: "收集配置信息",
|
|
129
|
+
task: (ctx) => {
|
|
130
|
+
ctx.storeInfo = env.storeInfo(workPath);
|
|
131
|
+
}
|
|
132
|
+
},
|
|
133
|
+
{
|
|
134
|
+
title: "准备产物目录",
|
|
135
|
+
task: () => {
|
|
136
|
+
createDist();
|
|
137
|
+
}
|
|
138
|
+
},
|
|
139
|
+
{
|
|
140
|
+
title: "编译配置信息",
|
|
141
|
+
task: () => {
|
|
142
|
+
compileConfig();
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
],
|
|
146
|
+
{ concurrent: false }
|
|
147
|
+
)
|
|
148
|
+
},
|
|
149
|
+
{
|
|
150
|
+
title: `开始编译:${workPath.split("/").pop()}`,
|
|
151
|
+
task: (ctx, task) => {
|
|
152
|
+
const pages = env.getPages();
|
|
153
|
+
ctx.pages = pages;
|
|
154
|
+
return task.newListr(
|
|
155
|
+
[
|
|
156
|
+
{
|
|
157
|
+
title: "编译页面文件",
|
|
158
|
+
task: async (ctx2, task2) => {
|
|
159
|
+
return runCompileInWorker("view", ctx2, task2);
|
|
160
|
+
}
|
|
161
|
+
},
|
|
162
|
+
{
|
|
163
|
+
title: "编译页面逻辑",
|
|
164
|
+
task: async (ctx2, task2) => {
|
|
165
|
+
return runCompileInWorker("logic", ctx2, task2);
|
|
166
|
+
}
|
|
167
|
+
},
|
|
168
|
+
{
|
|
169
|
+
title: "编译样式文件",
|
|
170
|
+
task: async (ctx2, task2) => {
|
|
171
|
+
pages.mainPages.unshift({
|
|
172
|
+
path: "app",
|
|
173
|
+
id: ""
|
|
174
|
+
});
|
|
175
|
+
return runCompileInWorker("style", ctx2, task2);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
],
|
|
179
|
+
{ concurrent: true }
|
|
180
|
+
);
|
|
181
|
+
}
|
|
182
|
+
},
|
|
183
|
+
{
|
|
184
|
+
title: "输出编译产物",
|
|
185
|
+
task: () => {
|
|
186
|
+
publishToDist(targetPath);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
],
|
|
190
|
+
{ concurrent: false }
|
|
191
|
+
);
|
|
192
|
+
try {
|
|
193
|
+
const context = await tasks.run();
|
|
194
|
+
return {
|
|
195
|
+
appId: env.getAppId(),
|
|
196
|
+
name: env.getAppName(),
|
|
197
|
+
path: env.getAppConfigInfo().entryPagePath || context.pages.mainPages[1].path
|
|
198
|
+
};
|
|
199
|
+
} catch (e) {
|
|
200
|
+
console.error(`${workPath} 编译出错: ${e.message}
|
|
201
|
+
${e.stack}`);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
function runCompileInWorker(script, ctx, task) {
|
|
205
|
+
return workerPool.runWorker(() => new Promise((resolve, reject) => {
|
|
206
|
+
const worker = new node_worker_threads.Worker(
|
|
207
|
+
path.join(path.dirname(node_url.fileURLToPath(typeof document === "undefined" ? require("url").pathToFileURL(__filename).href : _documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === "SCRIPT" && _documentCurrentScript.src || new URL("index.cjs", document.baseURI).href)), `core/${script}-compiler.js`),
|
|
208
|
+
workerPool.getWorkerOptions()
|
|
209
|
+
);
|
|
210
|
+
const totalTasks = Object.keys(ctx.pages.mainPages).length + Object.values(ctx.pages.subPages).reduce((sum, item) => sum + item.info.length, 0);
|
|
211
|
+
worker.postMessage({ pages: ctx.pages, storeInfo: ctx.storeInfo });
|
|
212
|
+
worker.on("message", (message) => {
|
|
213
|
+
if (message.completedTasks) {
|
|
214
|
+
const progress = message.completedTasks / totalTasks;
|
|
215
|
+
const percentage = progress * 100;
|
|
216
|
+
const barLength = 30;
|
|
217
|
+
const filledLength = Math.ceil(barLength * progress);
|
|
218
|
+
const bar = "█".repeat(filledLength) + "░".repeat(barLength - filledLength);
|
|
219
|
+
task.output = `[${bar}] ${percentage.toFixed(2)}%`;
|
|
220
|
+
}
|
|
221
|
+
if (message.success) {
|
|
222
|
+
resolve();
|
|
223
|
+
worker.terminate();
|
|
224
|
+
} else if (message.error) {
|
|
225
|
+
reject(new Error(message.error));
|
|
226
|
+
worker.terminate();
|
|
227
|
+
}
|
|
228
|
+
});
|
|
229
|
+
worker.on("error", reject);
|
|
230
|
+
worker.on("exit", (code) => {
|
|
231
|
+
if (code !== 0) {
|
|
232
|
+
reject(new Error(`Worker stopped with exit code ${code}`));
|
|
233
|
+
}
|
|
234
|
+
});
|
|
235
|
+
}));
|
|
236
|
+
}
|
|
237
|
+
module.exports = build;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { Worker } from "node:worker_threads";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
import { Listr } from "listr2";
|
|
5
|
+
import { k as getPageConfigInfo, j as getAppConfigInfo, g as getTargetPath, e as getAppId, s as storeInfo, l as getPages, m as getAppName } from "./env-CezfCSQz.js";
|
|
6
|
+
import fs from "node:fs";
|
|
7
|
+
import process from "node:process";
|
|
8
|
+
import shelljs from "shelljs";
|
|
9
|
+
import os from "node:os";
|
|
10
|
+
const artCode = `
|
|
11
|
+
██████╗ ██╗███╗ ███╗██╗███╗ ██╗ █████╗
|
|
12
|
+
██╔══██╗██║████╗ ████║██║████╗ ██║██╔══██╗
|
|
13
|
+
██║ ██║██║██╔████╔██║██║██╔██╗ ██║███████║
|
|
14
|
+
██║ ██║██║██║╚██╔╝██║██║██║╚██╗██║██╔══██║
|
|
15
|
+
██████╔╝██║██║ ╚═╝ ██║██║██║ ╚████║██║ ██║
|
|
16
|
+
╚═════╝ ╚═╝╚═╝ ╚═╝╚═╝╚═╝ ╚═══╝╚═╝ ╚═╝
|
|
17
|
+
`;
|
|
18
|
+
function artCode$1() {
|
|
19
|
+
console.log(artCode);
|
|
20
|
+
}
|
|
21
|
+
function compileConfig() {
|
|
22
|
+
const compileResInfo = {
|
|
23
|
+
app: getAppConfigInfo(),
|
|
24
|
+
modules: getPageConfigInfo()
|
|
25
|
+
};
|
|
26
|
+
const json = JSON.stringify(compileResInfo, null, 4);
|
|
27
|
+
const mainDir = `${getTargetPath()}/main`;
|
|
28
|
+
if (!fs.existsSync(mainDir)) {
|
|
29
|
+
fs.mkdirSync(mainDir);
|
|
30
|
+
}
|
|
31
|
+
fs.writeFileSync(`${mainDir}/app-config.json`, json);
|
|
32
|
+
}
|
|
33
|
+
function createDist() {
|
|
34
|
+
const distPath = getTargetPath();
|
|
35
|
+
if (shelljs.test("-d", distPath)) {
|
|
36
|
+
shelljs.rm("-rf", distPath);
|
|
37
|
+
}
|
|
38
|
+
shelljs.mkdir("-p", `${distPath}`);
|
|
39
|
+
}
|
|
40
|
+
function publishToDist(dist) {
|
|
41
|
+
const distPath = getTargetPath();
|
|
42
|
+
const appId = getAppId();
|
|
43
|
+
const absolutePath = `${path.resolve(process.cwd(), dist)}/${appId}`;
|
|
44
|
+
shelljs.rm("-rf", absolutePath);
|
|
45
|
+
shelljs.mkdir("-p", absolutePath);
|
|
46
|
+
shelljs.cp("-r", `${distPath}/*`, absolutePath);
|
|
47
|
+
}
|
|
48
|
+
function getCGroupCPUCount() {
|
|
49
|
+
try {
|
|
50
|
+
const quotaPath = "/sys/fs/cgroup/cpu/cpu.cfs_quota_us";
|
|
51
|
+
const periodPath = "/sys/fs/cgroup/cpu/cpu.cfs_period_us";
|
|
52
|
+
if (fs.existsSync(quotaPath) && fs.existsSync(periodPath)) {
|
|
53
|
+
const quota = Number.parseInt(fs.readFileSync(quotaPath, "utf8"));
|
|
54
|
+
const period = Number.parseInt(fs.readFileSync(periodPath, "utf8"));
|
|
55
|
+
if (quota > 0) {
|
|
56
|
+
return Math.max(1, Math.floor(quota / period));
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
} catch (e) {
|
|
60
|
+
console.warn("Failed to read CPU limits from cgroup:", e.message);
|
|
61
|
+
}
|
|
62
|
+
return os.cpus().length;
|
|
63
|
+
}
|
|
64
|
+
function getCGroupMemoryLimit() {
|
|
65
|
+
try {
|
|
66
|
+
const memLimitPath = "/sys/fs/cgroup/memory/memory.limit_in_bytes";
|
|
67
|
+
if (fs.existsSync(memLimitPath)) {
|
|
68
|
+
const memLimit = Number.parseInt(fs.readFileSync(memLimitPath, "utf8"));
|
|
69
|
+
if (memLimit < Infinity && memLimit > 0) {
|
|
70
|
+
return memLimit;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
} catch (e) {
|
|
74
|
+
console.warn("Failed to read memory limits from cgroup:", e.message);
|
|
75
|
+
}
|
|
76
|
+
return os.totalmem();
|
|
77
|
+
}
|
|
78
|
+
const MAX_WORKERS = Math.max(1, Math.floor(getCGroupCPUCount() / 4));
|
|
79
|
+
class WorkerPool {
|
|
80
|
+
constructor(maxWorkers = MAX_WORKERS) {
|
|
81
|
+
this.maxWorkers = maxWorkers;
|
|
82
|
+
this.activeWorkers = 0;
|
|
83
|
+
this.queue = [];
|
|
84
|
+
this.memoryLimit = Math.floor(getCGroupMemoryLimit() * 0.7 / maxWorkers);
|
|
85
|
+
}
|
|
86
|
+
async runWorker(workerCreator) {
|
|
87
|
+
if (this.activeWorkers >= this.maxWorkers) {
|
|
88
|
+
await new Promise((resolve) => this.queue.push(resolve));
|
|
89
|
+
}
|
|
90
|
+
this.activeWorkers++;
|
|
91
|
+
try {
|
|
92
|
+
return await workerCreator();
|
|
93
|
+
} finally {
|
|
94
|
+
this.activeWorkers--;
|
|
95
|
+
if (this.queue.length > 0) {
|
|
96
|
+
const next = this.queue.shift();
|
|
97
|
+
next();
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
getWorkerOptions() {
|
|
102
|
+
return {
|
|
103
|
+
resourceLimits: {
|
|
104
|
+
maxOldGenerationSizeMb: Math.floor(this.memoryLimit / (1024 * 1024)),
|
|
105
|
+
// Convert bytes to MB
|
|
106
|
+
maxYoungGenerationSizeMb: Math.floor(this.memoryLimit / (1024 * 1024) / 4),
|
|
107
|
+
codeRangeSizeMb: 128
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
const workerPool = new WorkerPool();
|
|
113
|
+
let isPrinted = false;
|
|
114
|
+
async function build(targetPath, workPath) {
|
|
115
|
+
if (!isPrinted) {
|
|
116
|
+
artCode$1();
|
|
117
|
+
isPrinted = true;
|
|
118
|
+
}
|
|
119
|
+
const tasks = new Listr(
|
|
120
|
+
[
|
|
121
|
+
{
|
|
122
|
+
title: "准备项目编译环境",
|
|
123
|
+
task: (_, task) => task.newListr(
|
|
124
|
+
[
|
|
125
|
+
{
|
|
126
|
+
title: "收集配置信息",
|
|
127
|
+
task: (ctx) => {
|
|
128
|
+
ctx.storeInfo = storeInfo(workPath);
|
|
129
|
+
}
|
|
130
|
+
},
|
|
131
|
+
{
|
|
132
|
+
title: "准备产物目录",
|
|
133
|
+
task: () => {
|
|
134
|
+
createDist();
|
|
135
|
+
}
|
|
136
|
+
},
|
|
137
|
+
{
|
|
138
|
+
title: "编译配置信息",
|
|
139
|
+
task: () => {
|
|
140
|
+
compileConfig();
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
],
|
|
144
|
+
{ concurrent: false }
|
|
145
|
+
)
|
|
146
|
+
},
|
|
147
|
+
{
|
|
148
|
+
title: `开始编译:${workPath.split("/").pop()}`,
|
|
149
|
+
task: (ctx, task) => {
|
|
150
|
+
const pages = getPages();
|
|
151
|
+
ctx.pages = pages;
|
|
152
|
+
return task.newListr(
|
|
153
|
+
[
|
|
154
|
+
{
|
|
155
|
+
title: "编译页面文件",
|
|
156
|
+
task: async (ctx2, task2) => {
|
|
157
|
+
return runCompileInWorker("view", ctx2, task2);
|
|
158
|
+
}
|
|
159
|
+
},
|
|
160
|
+
{
|
|
161
|
+
title: "编译页面逻辑",
|
|
162
|
+
task: async (ctx2, task2) => {
|
|
163
|
+
return runCompileInWorker("logic", ctx2, task2);
|
|
164
|
+
}
|
|
165
|
+
},
|
|
166
|
+
{
|
|
167
|
+
title: "编译样式文件",
|
|
168
|
+
task: async (ctx2, task2) => {
|
|
169
|
+
pages.mainPages.unshift({
|
|
170
|
+
path: "app",
|
|
171
|
+
id: ""
|
|
172
|
+
});
|
|
173
|
+
return runCompileInWorker("style", ctx2, task2);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
],
|
|
177
|
+
{ concurrent: true }
|
|
178
|
+
);
|
|
179
|
+
}
|
|
180
|
+
},
|
|
181
|
+
{
|
|
182
|
+
title: "输出编译产物",
|
|
183
|
+
task: () => {
|
|
184
|
+
publishToDist(targetPath);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
],
|
|
188
|
+
{ concurrent: false }
|
|
189
|
+
);
|
|
190
|
+
try {
|
|
191
|
+
const context = await tasks.run();
|
|
192
|
+
return {
|
|
193
|
+
appId: getAppId(),
|
|
194
|
+
name: getAppName(),
|
|
195
|
+
path: getAppConfigInfo().entryPagePath || context.pages.mainPages[1].path
|
|
196
|
+
};
|
|
197
|
+
} catch (e) {
|
|
198
|
+
console.error(`${workPath} 编译出错: ${e.message}
|
|
199
|
+
${e.stack}`);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
function runCompileInWorker(script, ctx, task) {
|
|
203
|
+
return workerPool.runWorker(() => new Promise((resolve, reject) => {
|
|
204
|
+
const worker = new Worker(
|
|
205
|
+
path.join(path.dirname(fileURLToPath(import.meta.url)), `core/${script}-compiler.js`),
|
|
206
|
+
workerPool.getWorkerOptions()
|
|
207
|
+
);
|
|
208
|
+
const totalTasks = Object.keys(ctx.pages.mainPages).length + Object.values(ctx.pages.subPages).reduce((sum, item) => sum + item.info.length, 0);
|
|
209
|
+
worker.postMessage({ pages: ctx.pages, storeInfo: ctx.storeInfo });
|
|
210
|
+
worker.on("message", (message) => {
|
|
211
|
+
if (message.completedTasks) {
|
|
212
|
+
const progress = message.completedTasks / totalTasks;
|
|
213
|
+
const percentage = progress * 100;
|
|
214
|
+
const barLength = 30;
|
|
215
|
+
const filledLength = Math.ceil(barLength * progress);
|
|
216
|
+
const bar = "█".repeat(filledLength) + "░".repeat(barLength - filledLength);
|
|
217
|
+
task.output = `[${bar}] ${percentage.toFixed(2)}%`;
|
|
218
|
+
}
|
|
219
|
+
if (message.success) {
|
|
220
|
+
resolve();
|
|
221
|
+
worker.terminate();
|
|
222
|
+
} else if (message.error) {
|
|
223
|
+
reject(new Error(message.error));
|
|
224
|
+
worker.terminate();
|
|
225
|
+
}
|
|
226
|
+
});
|
|
227
|
+
worker.on("error", reject);
|
|
228
|
+
worker.on("exit", (code) => {
|
|
229
|
+
if (code !== 0) {
|
|
230
|
+
reject(new Error(`Worker stopped with exit code ${code}`));
|
|
231
|
+
}
|
|
232
|
+
});
|
|
233
|
+
}));
|
|
234
|
+
}
|
|
235
|
+
export {
|
|
236
|
+
build as default
|
|
237
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@dimina/compiler",
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"description": "星河编译工具",
|
|
5
|
+
"main": "./dist/index.cjs",
|
|
6
|
+
"module": "./dist/index.js",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"files": [
|
|
9
|
+
"dist"
|
|
10
|
+
],
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"import": "./dist/index.js",
|
|
14
|
+
"require": "./dist/index.cjs"
|
|
15
|
+
},
|
|
16
|
+
"./view-compiler": {
|
|
17
|
+
"import": "./dist/core/view-compiler.js",
|
|
18
|
+
"require": "./dist/core/view-compiler.cjs"
|
|
19
|
+
},
|
|
20
|
+
"./logic-compiler": {
|
|
21
|
+
"import": "./dist/core/logic-compiler.mjs",
|
|
22
|
+
"require": "./dist/core/logic-compiler.js"
|
|
23
|
+
},
|
|
24
|
+
"./style-compiler": {
|
|
25
|
+
"import": "./dist/core/style-compiler.js",
|
|
26
|
+
"require": "./dist/core/style-compiler.cjs"
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
"bin": {
|
|
30
|
+
"dmcc": "dist/bin/index.js"
|
|
31
|
+
},
|
|
32
|
+
"scripts": {
|
|
33
|
+
"build": "vite build",
|
|
34
|
+
"test": "vitest run",
|
|
35
|
+
"test:dev": "vitest",
|
|
36
|
+
"coverage": "vitest run --coverage"
|
|
37
|
+
},
|
|
38
|
+
"author": "doslin",
|
|
39
|
+
"license": "Apache-2.0",
|
|
40
|
+
"keywords": [
|
|
41
|
+
"dimina",
|
|
42
|
+
"compiler",
|
|
43
|
+
"miniapp",
|
|
44
|
+
"小程序",
|
|
45
|
+
"星河"
|
|
46
|
+
],
|
|
47
|
+
"dependencies": {
|
|
48
|
+
"@babel/core": "^7.26.10",
|
|
49
|
+
"@babel/traverse": "^7.27.0",
|
|
50
|
+
"@babel/types": "^7.27.0",
|
|
51
|
+
"@vue/compiler-sfc": "^3.5.13",
|
|
52
|
+
"autoprefixer": "^10.4.21",
|
|
53
|
+
"cheerio": "1.0.0-rc.12",
|
|
54
|
+
"chokidar": "^3.6.0",
|
|
55
|
+
"commander": "^12.1.0",
|
|
56
|
+
"cssnano": "^6.1.2",
|
|
57
|
+
"esbuild": "^0.24.2",
|
|
58
|
+
"htmlparser2": "^9.1.0",
|
|
59
|
+
"listr2": "^8.3.2",
|
|
60
|
+
"postcss": "^8.5.3",
|
|
61
|
+
"postcss-selector-parser": "^6.1.2",
|
|
62
|
+
"shelljs": "^0.8.5"
|
|
63
|
+
},
|
|
64
|
+
"devDependencies": {
|
|
65
|
+
"vitest": "2.1.8"
|
|
66
|
+
},
|
|
67
|
+
"publishConfig": {
|
|
68
|
+
"registry": "https://registry.npmjs.org/"
|
|
69
|
+
}
|
|
70
|
+
}
|