@neuxnet/neux-cli 0.2.3

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.
Files changed (73) hide show
  1. package/README.md +438 -0
  2. package/README.zh-CN.md +554 -0
  3. package/assets/container/assets/index.css +1 -0
  4. package/assets/container/assets/index.js +137 -0
  5. package/assets/container/assets/pageFrame.css +1 -0
  6. package/assets/container/assets/pageFrame.js +56 -0
  7. package/assets/container/assets/service.js +6 -0
  8. package/assets/container/assets/vconsole.js +931 -0
  9. package/assets/container/favicon.ico +0 -0
  10. package/assets/container/images/icon-arrow.png +0 -0
  11. package/assets/container/images/mini-action-white.png +0 -0
  12. package/assets/container/images/mini-action.png +0 -0
  13. package/assets/container/images/mini-arrow-left-white.png +0 -0
  14. package/assets/container/images/mini-arrow-left.jpg +0 -0
  15. package/assets/container/images/mini-arrow-left.png +0 -0
  16. package/assets/container/images/mini-close-white.png +0 -0
  17. package/assets/container/images/mini-close.png +0 -0
  18. package/assets/container/images/more.png +0 -0
  19. package/assets/container/images/search.jpg +0 -0
  20. package/assets/container/index.html +1 -0
  21. package/assets/container/pageFrame.html +1 -0
  22. package/assets/init/tabbar/home-active.png +0 -0
  23. package/assets/init/tabbar/home.png +0 -0
  24. package/assets/init/tabbar/list-active.png +0 -0
  25. package/assets/init/tabbar/list.png +0 -0
  26. package/assets/init/types/neux-api.d.ts +1402 -0
  27. package/package.json +68 -0
  28. package/scripts/generate-init-types.js +210 -0
  29. package/scripts/sync-compiler.js +22 -0
  30. package/scripts/sync-web-container.js +34 -0
  31. package/src/bin/cli.js +646 -0
  32. package/src/core/brand.js +11 -0
  33. package/src/core/compiler.js +305 -0
  34. package/src/core/defaults.js +12 -0
  35. package/src/core/dev.js +15 -0
  36. package/src/core/errors.js +17 -0
  37. package/src/core/fs.js +66 -0
  38. package/src/core/i18n.js +37 -0
  39. package/src/core/init.js +866 -0
  40. package/src/core/lifecycle.js +32 -0
  41. package/src/core/manifest.js +72 -0
  42. package/src/core/pack.js +156 -0
  43. package/src/core/package-info.js +27 -0
  44. package/src/core/preview-server.js +123 -0
  45. package/src/core/project.js +101 -0
  46. package/src/core/prompts.js +71 -0
  47. package/src/core/proxy-security.js +141 -0
  48. package/src/core/proxy.js +156 -0
  49. package/src/core/qr.js +41 -0
  50. package/src/core/terminal-qr.js +72 -0
  51. package/src/core/update.js +278 -0
  52. package/src/core/watch.js +113 -0
  53. package/src/core/web.js +649 -0
  54. package/src/core/zip.js +120 -0
  55. package/src/index.js +20 -0
  56. package/src/providers/service-client.js +149 -0
  57. package/src/providers/service-config.js +264 -0
  58. package/src/providers/service.js +146 -0
  59. package/src/providers/upload.js +112 -0
  60. package/vendor/dimina-compiler/bin/index.cjs +265 -0
  61. package/vendor/dimina-compiler/bin/index.js +263 -0
  62. package/vendor/dimina-compiler/compatibility-B-DoZtUX.cjs +395 -0
  63. package/vendor/dimina-compiler/compatibility-Cl3-DO6V.js +366 -0
  64. package/vendor/dimina-compiler/core/logic-compiler.cjs +378 -0
  65. package/vendor/dimina-compiler/core/logic-compiler.js +374 -0
  66. package/vendor/dimina-compiler/core/style-compiler.cjs +392 -0
  67. package/vendor/dimina-compiler/core/style-compiler.js +377 -0
  68. package/vendor/dimina-compiler/core/view-compiler.cjs +1601 -0
  69. package/vendor/dimina-compiler/core/view-compiler.js +1582 -0
  70. package/vendor/dimina-compiler/index.cjs +762 -0
  71. package/vendor/dimina-compiler/index.js +751 -0
  72. package/vendor/dimina-compiler/sourcemap-BgtIgqkC.cjs +1377 -0
  73. package/vendor/dimina-compiler/sourcemap-CKjhV9h7.js +1135 -0
@@ -0,0 +1,377 @@
1
+ import { C as resetStoreInfo, E as collectAssets, M as tagWhiteList, N as transformRpx, S as getWorkPath, _ as getTargetPath, d as getDependencyGraph, g as getStyleExts, i as remapSourcemap, j as resolveAssetSourcePath, l as getComponent, n as createLineSourcemap, o as getAppId, t as concatSourcemap, u as getContentByPath } from "../sourcemap-CKjhV9h7.js";
2
+ import fs from "node:fs";
3
+ import path from "node:path";
4
+ import { fileURLToPath, pathToFileURL } from "node:url";
5
+ import { isMainThread, parentPort } from "node:worker_threads";
6
+ import { compileStyle } from "@vue/compiler-sfc";
7
+ import autoprefixer from "autoprefixer";
8
+ import cssnano from "cssnano";
9
+ import less from "less";
10
+ import postcss from "postcss";
11
+ import selectorParser from "postcss-selector-parser";
12
+ import * as sass from "sass";
13
+ //#region src/core/style-compiler.js
14
+ var compileRes = /* @__PURE__ */ new Map();
15
+ if (!isMainThread) parentPort.on("message", async ({ pages, storeInfo, sourcemap }) => {
16
+ try {
17
+ resetStoreInfo(storeInfo);
18
+ const progress = {
19
+ _completedTasks: 0,
20
+ get completedTasks() {
21
+ return this._completedTasks;
22
+ },
23
+ set completedTasks(value) {
24
+ this._completedTasks = value;
25
+ parentPort.postMessage({ completedTasks: this._completedTasks });
26
+ }
27
+ };
28
+ await compileSS(pages.mainPages, null, progress, { sourcemap });
29
+ for (const [root, subPages] of Object.entries(pages.subPages)) await compileSS(subPages.info, root, progress, { sourcemap });
30
+ compileRes.clear();
31
+ parentPort.postMessage({
32
+ success: true,
33
+ dependencyGraph: getDependencyGraph().toJSON()
34
+ });
35
+ } catch (error) {
36
+ compileRes.clear();
37
+ parentPort.postMessage({
38
+ success: false,
39
+ error: {
40
+ message: error.message,
41
+ stack: error.stack,
42
+ name: error.name,
43
+ file: error.file,
44
+ line: error.line,
45
+ column: error.column,
46
+ stage: error.stage
47
+ }
48
+ });
49
+ }
50
+ });
51
+ /**
52
+ * 编译样式文件
53
+ */
54
+ async function compileSS(pages, root, progress, options = {}) {
55
+ for (const page of pages) {
56
+ const result = await buildCompileCss(page, /* @__PURE__ */ new Set(), options);
57
+ let code = result.code;
58
+ const filename = `${page.path.replace(/\//g, "_")}`;
59
+ const outputDir = root ? `${getTargetPath()}/${root}` : `${getTargetPath()}/main`;
60
+ if (!fs.existsSync(outputDir)) fs.mkdirSync(outputDir, { recursive: true });
61
+ if (options.sourcemap) {
62
+ const mapFileName = `${filename}.css.map`;
63
+ const map = JSON.parse(result.map);
64
+ map.file = `${filename}.css`;
65
+ code += `\n/*# sourceMappingURL=${mapFileName} */\n`;
66
+ fs.writeFileSync(`${outputDir}/${mapFileName}`, JSON.stringify(map));
67
+ }
68
+ fs.writeFileSync(`${outputDir}/${filename}.css`, code);
69
+ progress.completedTasks++;
70
+ }
71
+ }
72
+ async function buildCompileCss(module, compiledPaths = /* @__PURE__ */ new Set(), options = {}) {
73
+ const chunks = [];
74
+ const pendingModules = [module];
75
+ while (pendingModules.length > 0) {
76
+ const currentModule = pendingModules.pop();
77
+ const currentPath = currentModule.path || currentModule.absolutePath;
78
+ if (compiledPaths.has(currentPath)) continue;
79
+ compiledPaths.add(currentPath);
80
+ const result = await enhanceCSS(currentModule, options);
81
+ if (result.code) chunks.push(result);
82
+ const graphDependencies = getDependencyGraph().getDirectDependencies(currentPath, "component");
83
+ const componentPaths = graphDependencies.length > 0 ? graphDependencies : Object.values(currentModule.usingComponents || {});
84
+ for (let index = componentPaths.length - 1; index >= 0; index--) {
85
+ const componentModule = getComponent(componentPaths[index]);
86
+ if (componentModule) pendingModules.push(componentModule);
87
+ }
88
+ }
89
+ if (options.sourcemap) {
90
+ const { code, sourcemap: map } = concatSourcemap(chunks);
91
+ return {
92
+ code,
93
+ map
94
+ };
95
+ }
96
+ return {
97
+ code: chunks.map((chunk) => chunk.code).join(""),
98
+ map: null
99
+ };
100
+ }
101
+ function createExternalClassPlugin(moduleId) {
102
+ const scopeAttribute = `data-v-${moduleId}`;
103
+ const externalScopeAttribute = "data-dd-external-class-scope";
104
+ const processedRules = /* @__PURE__ */ new WeakSet();
105
+ return {
106
+ postcssPlugin: "dimina-external-class",
107
+ Rule(rule) {
108
+ if (processedRules.has(rule) || !moduleId || !rule.selector.includes(`[${scopeAttribute}]`)) return;
109
+ processedRules.add(rule);
110
+ try {
111
+ rule.selector = selectorParser((selectors) => {
112
+ for (const selector of [...selectors.nodes]) {
113
+ const boostedSelector = selector.clone();
114
+ const scopeNodes = [];
115
+ boostedSelector.walkAttributes((attribute) => {
116
+ if (attribute.attribute === scopeAttribute) scopeNodes.push(attribute);
117
+ });
118
+ const targetScope = scopeNodes.at(-1);
119
+ if (!targetScope) continue;
120
+ targetScope.parent.insertAfter(targetScope, selectorParser.attribute({
121
+ attribute: externalScopeAttribute,
122
+ operator: "~=",
123
+ quoteMark: "\"",
124
+ value: scopeAttribute
125
+ }));
126
+ selectors.append(boostedSelector);
127
+ }
128
+ }).processSync(rule.selector);
129
+ } catch (error) {
130
+ throw rule.error(error.message, { plugin: "dimina-external-class" });
131
+ }
132
+ }
133
+ };
134
+ }
135
+ function boostExternalClassSelectors(cssCode, moduleId) {
136
+ if (!moduleId || !cssCode) return cssCode;
137
+ return postcss([createExternalClassPlugin(moduleId)]).process(cssCode, { from: void 0 }).css;
138
+ }
139
+ function getStyleSourcePath(absolutePath) {
140
+ const workPath = getWorkPath();
141
+ if (absolutePath === workPath || absolutePath.startsWith(`${workPath}${path.sep}`)) return `/${path.relative(workPath, absolutePath).split(path.sep).join("/")}`;
142
+ return absolutePath.split(path.sep).join("/");
143
+ }
144
+ function createStyleCompileError(stage, absolutePath, cause) {
145
+ if (cause?.name === "StyleCompileError") return cause;
146
+ const line = cause?.line ?? (Number.isInteger(cause?.span?.start?.line) ? cause.span.start.line + 1 : void 0);
147
+ const column = cause?.column ?? (Number.isInteger(cause?.span?.start?.column) ? cause.span.start.column + 1 : void 0);
148
+ const file = getStyleSourcePath(absolutePath);
149
+ const location = line == null ? file : `${file}:${line}${column == null ? "" : `:${column}`}`;
150
+ const reason = cause?.reason || cause?.sassMessage || cause?.message || String(cause);
151
+ const error = new Error(`[style:${stage}] ${location} ${reason}`, { cause });
152
+ error.name = "StyleCompileError";
153
+ error.file = file;
154
+ error.line = line;
155
+ error.column = column;
156
+ error.stage = stage;
157
+ return error;
158
+ }
159
+ function normalizePreprocessorMap(inputMap, absolutePath, inputCSS) {
160
+ const map = typeof inputMap === "string" ? JSON.parse(inputMap) : structuredClone(inputMap);
161
+ const sourcePaths = map.sources.map((source) => {
162
+ let resolvedPath = source;
163
+ if (source.startsWith("file:")) resolvedPath = fileURLToPath(source);
164
+ else if (!path.isAbsolute(source)) resolvedPath = path.resolve(path.dirname(absolutePath), source);
165
+ return resolvedPath;
166
+ });
167
+ map.sources = sourcePaths.map(getStyleSourcePath);
168
+ map.sourcesContent = map.sources.map((_, index) => {
169
+ if (sourcePaths[index] === absolutePath) return inputCSS;
170
+ return map.sourcesContent?.[index] ?? null;
171
+ });
172
+ return map;
173
+ }
174
+ function getPostcssMapOptions(sourcemap, prev) {
175
+ if (!sourcemap) return false;
176
+ return {
177
+ inline: false,
178
+ annotation: false,
179
+ sourcesContent: true,
180
+ prev
181
+ };
182
+ }
183
+ function createStyleTransformPlugin(module, absolutePath, importResults, options) {
184
+ const processedRules = /* @__PURE__ */ new WeakSet();
185
+ return {
186
+ postcssPlugin: "dimina-style-transform",
187
+ AtRule(node) {
188
+ if (node.name !== "import") return;
189
+ const importFullPath = resolveStyleImportPath(absolutePath, node.params.replace(/^['"]|['"]$/g, ""));
190
+ node.remove();
191
+ importResults.push(buildCompileCss({
192
+ absolutePath: importFullPath,
193
+ id: module.id,
194
+ ownerPath: module.ownerPath || module.path
195
+ }, /* @__PURE__ */ new Set(), options));
196
+ },
197
+ Rule(rule) {
198
+ if (processedRules.has(rule)) return;
199
+ processedRules.add(rule);
200
+ if (rule.selector.includes("::v-deep")) rule.selector = rule.selector.replace(/::v-deep\s+(\S[^{]*)/g, ":deep($1)");
201
+ if (rule.selector.includes(":host")) rule.selector = processHostSelector(rule.selector, module.id);
202
+ try {
203
+ rule.selector = selectorParser((selectors) => {
204
+ selectors.walkTags((tag) => {
205
+ if (tagWhiteList.includes(tag.value)) tag.value = `.dd-${tag.value}`;
206
+ });
207
+ }).processSync(rule.selector);
208
+ } catch (error) {
209
+ throw rule.error(error.message, { plugin: "dimina-style-transform" });
210
+ }
211
+ },
212
+ Comment(comment) {
213
+ comment.remove();
214
+ },
215
+ Declaration(declaration) {
216
+ declaration.value = normalizeCssUrlValue(declaration.value, absolutePath, module.ownerPath || module.path);
217
+ declaration.value = transformRpx(declaration.value);
218
+ }
219
+ };
220
+ }
221
+ async function enhanceCSS(module, options = {}) {
222
+ const absolutePath = module.absolutePath ? module.absolutePath : getAbsolutePath(module.path);
223
+ if (!absolutePath) return {
224
+ code: "",
225
+ map: null
226
+ };
227
+ const graphOwnerPath = module.ownerPath || module.path;
228
+ if (graphOwnerPath) getDependencyGraph().addFile(graphOwnerPath, absolutePath, "style");
229
+ const cacheKey = `${absolutePath}::${module.id || ""}::${options.sourcemap ? "map" : "plain"}`;
230
+ const inputCSS = getContentByPath(absolutePath);
231
+ if (!inputCSS) return {
232
+ code: "",
233
+ map: null
234
+ };
235
+ if (compileRes.has(cacheKey)) return compileRes.get(cacheKey);
236
+ let processedCSS = normalizeRootStyleImports(inputCSS);
237
+ let processedMap = options.sourcemap ? createLineSourcemap(processedCSS, getStyleSourcePath(absolutePath), inputCSS) : null;
238
+ const ext = path.extname(absolutePath).toLowerCase();
239
+ try {
240
+ if (ext === ".less") {
241
+ const result = await less.render(processedCSS, {
242
+ filename: absolutePath,
243
+ paths: [path.dirname(absolutePath), getWorkPath()],
244
+ sourceMap: options.sourcemap ? {
245
+ outputSourceFiles: true,
246
+ disableSourcemapAnnotation: true
247
+ } : void 0
248
+ });
249
+ processedCSS = result.css;
250
+ if (options.sourcemap) processedMap = normalizePreprocessorMap(result.map, absolutePath, inputCSS);
251
+ } else if (ext === ".scss" || ext === ".sass") {
252
+ const result = sass.compileString(processedCSS, {
253
+ loadPaths: [path.dirname(absolutePath), getWorkPath()],
254
+ syntax: ext === ".sass" ? "indented" : "scss",
255
+ url: options.sourcemap ? pathToFileURL(absolutePath) : void 0,
256
+ sourceMap: !!options.sourcemap,
257
+ sourceMapIncludeSources: !!options.sourcemap
258
+ });
259
+ processedCSS = result.css;
260
+ if (options.sourcemap) processedMap = normalizePreprocessorMap(result.sourceMap, absolutePath, inputCSS);
261
+ }
262
+ } catch (error) {
263
+ throw createStyleCompileError("preprocess", absolutePath, error);
264
+ }
265
+ const fixedCSS = ensureImportSemicolons(processedCSS);
266
+ if (options.sourcemap && fixedCSS !== processedCSS) processedMap = remapSourcemap(createLineSourcemap(fixedCSS, absolutePath, processedCSS), processedMap);
267
+ const importResults = [];
268
+ let transformedResult;
269
+ try {
270
+ transformedResult = await postcss([createStyleTransformPlugin(module, absolutePath, importResults, options)]).process(fixedCSS, {
271
+ from: void 0,
272
+ map: getPostcssMapOptions(options.sourcemap, processedMap)
273
+ });
274
+ } catch (error) {
275
+ throw createStyleCompileError("transform", absolutePath, error);
276
+ }
277
+ const moduleId = module.id;
278
+ let scopedResult;
279
+ try {
280
+ scopedResult = compileStyle({
281
+ source: transformedResult.css,
282
+ filename: getStyleSourcePath(absolutePath),
283
+ id: moduleId,
284
+ scoped: !!moduleId,
285
+ inMap: options.sourcemap ? transformedResult.map.toJSON() : void 0
286
+ });
287
+ if (scopedResult.errors.length > 0) throw scopedResult.errors[0];
288
+ } catch (error) {
289
+ throw createStyleCompileError("scope", absolutePath, error);
290
+ }
291
+ let externalResult;
292
+ try {
293
+ externalResult = await postcss([createExternalClassPlugin(moduleId)]).process(scopedResult.code, {
294
+ from: void 0,
295
+ map: getPostcssMapOptions(options.sourcemap, scopedResult.map)
296
+ });
297
+ } catch (error) {
298
+ throw createStyleCompileError("external-class", absolutePath, error);
299
+ }
300
+ let finalResult;
301
+ try {
302
+ finalResult = await postcss([autoprefixer({ overrideBrowserslist: ["cover 99.5%"] }), cssnano()]).process(externalResult.css, {
303
+ from: void 0,
304
+ map: getPostcssMapOptions(options.sourcemap, externalResult.map?.toJSON())
305
+ });
306
+ } catch (error) {
307
+ throw createStyleCompileError("postprocess", absolutePath, error);
308
+ }
309
+ const importedChunks = (await Promise.all(importResults)).filter((result) => result.code);
310
+ let result;
311
+ if (options.sourcemap) {
312
+ const { code, sourcemap: map } = concatSourcemap([...importedChunks, {
313
+ code: finalResult.css,
314
+ map: finalResult.map.toString()
315
+ }]);
316
+ result = {
317
+ code,
318
+ map
319
+ };
320
+ } else result = {
321
+ code: importedChunks.map((chunk) => chunk.code).join("") + finalResult.css,
322
+ map: null
323
+ };
324
+ compileRes.set(cacheKey, result);
325
+ return result;
326
+ }
327
+ function normalizeCssUrlValue(value, absolutePath, graphOwnerPath) {
328
+ return value.replace(/url\(([^)]+)\)/g, (fullMatch, rawUrl) => {
329
+ const cleanedUrl = rawUrl.trim().replace(/^['"]|['"]$/g, "");
330
+ if (!cleanedUrl || cleanedUrl.startsWith("data:image")) return fullMatch;
331
+ if (cleanedUrl.startsWith("//")) return `url(https:${cleanedUrl})`;
332
+ if (/^(https?:|blob:|data:)/.test(cleanedUrl)) return fullMatch;
333
+ if (graphOwnerPath && /\.(?:png|jpe?g|gif|svg)(?:\?.*)?$/.test(cleanedUrl)) getDependencyGraph().addFile(graphOwnerPath, resolveAssetSourcePath(getWorkPath(), absolutePath, cleanedUrl), "style");
334
+ return `url(${collectAssets(getWorkPath(), absolutePath, cleanedUrl, getTargetPath(), getAppId())})`;
335
+ });
336
+ }
337
+ function getAbsolutePath(modulePath) {
338
+ const workPath = getWorkPath();
339
+ const src = modulePath.startsWith("/") ? modulePath : `/${modulePath}`;
340
+ for (const ssType of getStyleExts()) {
341
+ const ssFullPath = `${workPath}${src}${ssType}`;
342
+ if (fs.existsSync(ssFullPath)) return ssFullPath;
343
+ const indexSsFullPath = `${workPath}${src}/index${ssType}`;
344
+ if (fs.existsSync(indexSsFullPath)) return indexSsFullPath;
345
+ }
346
+ }
347
+ function resolveStyleImportPath(absolutePath, importPath, workPath = getWorkPath()) {
348
+ if (importPath.startsWith("/")) return path.join(workPath, importPath);
349
+ return path.resolve(path.dirname(absolutePath), importPath);
350
+ }
351
+ function normalizeRootStyleImports(source, workPath = getWorkPath()) {
352
+ return source.replace(/(@import\s+(?:\(.*?\)\s*)?(?:url\()?['"])(\/[^'")]+)(['"]\)?)/g, (_, prefix, importPath, suffix) => {
353
+ return `${prefix}${path.join(workPath, importPath)}${suffix}`;
354
+ });
355
+ }
356
+ /**
357
+ * Ensures that all @import statements in CSS end with semicolons
358
+ * @param {string} css - The CSS content to process
359
+ * @returns {string} - The processed CSS with semicolons added to @import statements as needed
360
+ */
361
+ function ensureImportSemicolons(css) {
362
+ return css.replace(/@import[^;\n]*$/gm, (match) => {
363
+ return match.endsWith(";") ? match : `${match};`;
364
+ });
365
+ }
366
+ /**
367
+ * 处理 :host 选择器,将其转换为适合组件根节点的选择器
368
+ * @param {string} selector - 包含 :host 的选择器
369
+ * @param {string} moduleId - 组件的模块ID
370
+ * @returns {string} - 转换后的选择器
371
+ */
372
+ function processHostSelector(selector, moduleId) {
373
+ const hostSelector = `[data-dd-style-host~="${moduleId}"]`;
374
+ return selector.replace(/:host\(([^)]+)\)/g, `${hostSelector}$1`).replace(/:host(?![\w-])/g, hostSelector);
375
+ }
376
+ //#endregion
377
+ export { boostExternalClassSelectors, compileSS, ensureImportSemicolons, normalizeCssUrlValue, normalizeRootStyleImports, processHostSelector, resolveStyleImportPath };