@dimina/compiler 1.0.5 → 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/index.cjs CHANGED
@@ -1,12 +1,11 @@
1
1
  "use strict";
2
2
  const path = require("node:path");
3
- const node_worker_threads = require("node:worker_threads");
4
3
  const node_url = require("node:url");
4
+ const node_worker_threads = require("node:worker_threads");
5
5
  const listr2 = require("listr2");
6
- const env = require("./env-Chow6VXH.cjs");
7
- const fs = require("node:fs");
8
6
  const process = require("node:process");
9
- const shelljs = require("shelljs");
7
+ const fs = require("node:fs");
8
+ const env = require("./env-CGYKCSjT.cjs");
10
9
  const os = require("node:os");
11
10
  var _documentCurrentScript = typeof document !== "undefined" ? document.currentScript : null;
12
11
  const artCode = `
@@ -20,32 +19,35 @@ const artCode = `
20
19
  function artCode$1() {
21
20
  console.log(artCode);
22
21
  }
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
22
  function createDist() {
36
23
  const distPath = env.getTargetPath();
37
- if (shelljs.test("-d", distPath)) {
38
- shelljs.rm("-rf", distPath);
24
+ if (fs.existsSync(distPath)) {
25
+ fs.rmSync(distPath, { recursive: true, force: true });
39
26
  }
40
- shelljs.mkdir("-p", `${distPath}`);
27
+ fs.mkdirSync(distPath, { recursive: true });
41
28
  }
42
29
  function publishToDist(dist, useAppIdDir = true) {
43
30
  const distPath = env.getTargetPath();
44
31
  const appId = env.getAppId();
45
- const absolutePath = useAppIdDir ? `${path.resolve(process.cwd(), dist)}/${appId}` : `${path.resolve(process.cwd(), dist)}`;
46
- shelljs.rm("-rf", absolutePath);
47
- shelljs.mkdir("-p", absolutePath);
48
- shelljs.cp("-r", `${distPath}/*`, absolutePath);
32
+ const absolutePath = useAppIdDir ? `${path.resolve(process.cwd(), dist)}${path.sep}${appId}` : `${path.resolve(process.cwd(), dist)}`;
33
+ if (fs.existsSync(absolutePath)) {
34
+ fs.rmSync(absolutePath, { recursive: true, force: true });
35
+ }
36
+ fs.mkdirSync(absolutePath, { recursive: true });
37
+ function copyDir(src, dest) {
38
+ fs.mkdirSync(dest, { recursive: true });
39
+ const entries = fs.readdirSync(src, { withFileTypes: true });
40
+ for (const entry of entries) {
41
+ const srcPath = path.join(src, entry.name);
42
+ const destPath = path.join(dest, entry.name);
43
+ if (entry.isDirectory()) {
44
+ copyDir(srcPath, destPath);
45
+ } else {
46
+ fs.copyFileSync(srcPath, destPath);
47
+ }
48
+ }
49
+ }
50
+ copyDir(distPath, absolutePath);
49
51
  }
50
52
  function getCGroupCPUCount() {
51
53
  try {
@@ -68,7 +70,7 @@ function getCGroupMemoryLimit() {
68
70
  const memLimitPath = "/sys/fs/cgroup/memory/memory.limit_in_bytes";
69
71
  if (fs.existsSync(memLimitPath)) {
70
72
  const memLimit = Number.parseInt(fs.readFileSync(memLimitPath, "utf8"));
71
- if (memLimit < Infinity && memLimit > 0) {
73
+ if (memLimit < Number.Infinity && memLimit > 0) {
72
74
  return memLimit;
73
75
  }
74
76
  }
@@ -112,6 +114,19 @@ class WorkerPool {
112
114
  }
113
115
  }
114
116
  const workerPool = new WorkerPool();
117
+ function compileConfig() {
118
+ const compileResInfo = {
119
+ app: env.getAppConfigInfo(),
120
+ modules: env.getPageConfigInfo(),
121
+ projectName: env.getAppName()
122
+ };
123
+ const json = JSON.stringify(compileResInfo, null, 4);
124
+ const mainDir = `${env.getTargetPath()}/main`;
125
+ if (!fs.existsSync(mainDir)) {
126
+ fs.mkdirSync(mainDir, { recursive: true });
127
+ }
128
+ fs.writeFileSync(`${mainDir}/app-config.json`, json);
129
+ }
115
130
  let isPrinted = false;
116
131
  async function build(targetPath, workPath, useAppIdDir = true) {
117
132
  if (!isPrinted) {
@@ -210,19 +225,32 @@ function runCompileInWorker(script, ctx, task) {
210
225
  const totalTasks = Object.keys(ctx.pages.mainPages).length + Object.values(ctx.pages.subPages).reduce((sum, item) => sum + item.info.length, 0);
211
226
  worker.postMessage({ pages: ctx.pages, storeInfo: ctx.storeInfo });
212
227
  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));
228
+ try {
229
+ if (message.completedTasks) {
230
+ const progress = message.completedTasks / totalTasks;
231
+ const percentage = progress * 100;
232
+ const barLength = 30;
233
+ const filledLength = Math.ceil(barLength * progress);
234
+ const bar = "█".repeat(filledLength) + "░".repeat(barLength - filledLength);
235
+ task.output = `[${bar}] ${percentage.toFixed(2)}%`;
236
+ }
237
+ if (message.success) {
238
+ resolve();
239
+ worker.terminate();
240
+ } else if (message.error) {
241
+ const error = new Error(message.error.message || message.error);
242
+ if (message.error.stack)
243
+ error.stack = message.error.stack;
244
+ if (message.error.file)
245
+ error.file = message.error.file;
246
+ if (message.error.line)
247
+ error.line = message.error.line;
248
+ reject(error);
249
+ worker.terminate();
250
+ }
251
+ } catch (err) {
252
+ reject(new Error(`Error processing worker message: ${err.message}
253
+ ${err.stack}`));
226
254
  worker.terminate();
227
255
  }
228
256
  });
package/dist/index.js CHANGED
@@ -1,11 +1,10 @@
1
1
  import path from "node:path";
2
- import { Worker } from "node:worker_threads";
3
2
  import { fileURLToPath } from "node:url";
3
+ import { Worker } from "node:worker_threads";
4
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
5
  import process from "node:process";
8
- import shelljs from "shelljs";
6
+ import fs from "node:fs";
7
+ import { g as getTargetPath, f as getAppId, k as getAppName, l as getPageConfigInfo, j as getAppConfigInfo, s as storeInfo, m as getPages } from "./env-fkuCnng-.js";
9
8
  import os from "node:os";
10
9
  const artCode = `
11
10
  ██████╗ ██╗███╗ ███╗██╗███╗ ██╗ █████╗
@@ -18,32 +17,35 @@ const artCode = `
18
17
  function artCode$1() {
19
18
  console.log(artCode);
20
19
  }
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
20
  function createDist() {
34
21
  const distPath = getTargetPath();
35
- if (shelljs.test("-d", distPath)) {
36
- shelljs.rm("-rf", distPath);
22
+ if (fs.existsSync(distPath)) {
23
+ fs.rmSync(distPath, { recursive: true, force: true });
37
24
  }
38
- shelljs.mkdir("-p", `${distPath}`);
25
+ fs.mkdirSync(distPath, { recursive: true });
39
26
  }
40
27
  function publishToDist(dist, useAppIdDir = true) {
41
28
  const distPath = getTargetPath();
42
29
  const appId = getAppId();
43
- const absolutePath = useAppIdDir ? `${path.resolve(process.cwd(), dist)}/${appId}` : `${path.resolve(process.cwd(), dist)}`;
44
- shelljs.rm("-rf", absolutePath);
45
- shelljs.mkdir("-p", absolutePath);
46
- shelljs.cp("-r", `${distPath}/*`, absolutePath);
30
+ const absolutePath = useAppIdDir ? `${path.resolve(process.cwd(), dist)}${path.sep}${appId}` : `${path.resolve(process.cwd(), dist)}`;
31
+ if (fs.existsSync(absolutePath)) {
32
+ fs.rmSync(absolutePath, { recursive: true, force: true });
33
+ }
34
+ fs.mkdirSync(absolutePath, { recursive: true });
35
+ function copyDir(src, dest) {
36
+ fs.mkdirSync(dest, { recursive: true });
37
+ const entries = fs.readdirSync(src, { withFileTypes: true });
38
+ for (const entry of entries) {
39
+ const srcPath = path.join(src, entry.name);
40
+ const destPath = path.join(dest, entry.name);
41
+ if (entry.isDirectory()) {
42
+ copyDir(srcPath, destPath);
43
+ } else {
44
+ fs.copyFileSync(srcPath, destPath);
45
+ }
46
+ }
47
+ }
48
+ copyDir(distPath, absolutePath);
47
49
  }
48
50
  function getCGroupCPUCount() {
49
51
  try {
@@ -66,7 +68,7 @@ function getCGroupMemoryLimit() {
66
68
  const memLimitPath = "/sys/fs/cgroup/memory/memory.limit_in_bytes";
67
69
  if (fs.existsSync(memLimitPath)) {
68
70
  const memLimit = Number.parseInt(fs.readFileSync(memLimitPath, "utf8"));
69
- if (memLimit < Infinity && memLimit > 0) {
71
+ if (memLimit < Number.Infinity && memLimit > 0) {
70
72
  return memLimit;
71
73
  }
72
74
  }
@@ -110,6 +112,19 @@ class WorkerPool {
110
112
  }
111
113
  }
112
114
  const workerPool = new WorkerPool();
115
+ function compileConfig() {
116
+ const compileResInfo = {
117
+ app: getAppConfigInfo(),
118
+ modules: getPageConfigInfo(),
119
+ projectName: getAppName()
120
+ };
121
+ const json = JSON.stringify(compileResInfo, null, 4);
122
+ const mainDir = `${getTargetPath()}/main`;
123
+ if (!fs.existsSync(mainDir)) {
124
+ fs.mkdirSync(mainDir, { recursive: true });
125
+ }
126
+ fs.writeFileSync(`${mainDir}/app-config.json`, json);
127
+ }
113
128
  let isPrinted = false;
114
129
  async function build(targetPath, workPath, useAppIdDir = true) {
115
130
  if (!isPrinted) {
@@ -208,19 +223,32 @@ function runCompileInWorker(script, ctx, task) {
208
223
  const totalTasks = Object.keys(ctx.pages.mainPages).length + Object.values(ctx.pages.subPages).reduce((sum, item) => sum + item.info.length, 0);
209
224
  worker.postMessage({ pages: ctx.pages, storeInfo: ctx.storeInfo });
210
225
  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));
226
+ try {
227
+ if (message.completedTasks) {
228
+ const progress = message.completedTasks / totalTasks;
229
+ const percentage = progress * 100;
230
+ const barLength = 30;
231
+ const filledLength = Math.ceil(barLength * progress);
232
+ const bar = "█".repeat(filledLength) + "░".repeat(barLength - filledLength);
233
+ task.output = `[${bar}] ${percentage.toFixed(2)}%`;
234
+ }
235
+ if (message.success) {
236
+ resolve();
237
+ worker.terminate();
238
+ } else if (message.error) {
239
+ const error = new Error(message.error.message || message.error);
240
+ if (message.error.stack)
241
+ error.stack = message.error.stack;
242
+ if (message.error.file)
243
+ error.file = message.error.file;
244
+ if (message.error.line)
245
+ error.line = message.error.line;
246
+ reject(error);
247
+ worker.terminate();
248
+ }
249
+ } catch (err) {
250
+ reject(new Error(`Error processing worker message: ${err.message}
251
+ ${err.stack}`));
224
252
  worker.terminate();
225
253
  }
226
254
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dimina/compiler",
3
- "version": "1.0.5",
3
+ "version": "1.0.7",
4
4
  "description": "星河编译工具",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.js",
@@ -45,21 +45,20 @@
45
45
  "星河"
46
46
  ],
47
47
  "dependencies": {
48
- "@babel/core": "^7.27.1",
49
- "@babel/traverse": "^7.27.1",
50
- "@babel/types": "^7.27.1",
51
- "@vue/compiler-sfc": "^3.5.14",
48
+ "@babel/core": "^7.27.4",
49
+ "@babel/traverse": "^7.27.4",
50
+ "@babel/types": "^7.27.6",
51
+ "@vue/compiler-sfc": "^3.5.16",
52
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",
53
+ "cheerio": "^1.1.0",
54
+ "chokidar": "^4.0.3",
55
+ "commander": "^14.0.0",
56
+ "cssnano": "^7.0.7",
57
+ "esbuild": "^0.25.5",
58
+ "htmlparser2": "^10.0.0",
59
59
  "listr2": "^8.3.3",
60
- "postcss": "^8.5.3",
61
- "postcss-selector-parser": "^6.1.2",
62
- "shelljs": "^0.8.5"
60
+ "postcss": "^8.5.5",
61
+ "postcss-selector-parser": "^7.1.0"
63
62
  },
64
63
  "publishConfig": {
65
64
  "registry": "https://registry.npmjs.org/"