glyphix 1.1.1 → 1.2.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/bin/glyphix.js CHANGED
@@ -171,6 +171,7 @@ var GxGenerate = class {
171
171
  );
172
172
  // gx 工具传递过来的入口文件,包括 app.{t,j}s 和各个页面的 js 文件路径
173
173
  this.entries = [];
174
+ process.env.GLYPHIX_EXEC_ROOT = this.workspaceRoot;
174
175
  const entryFile = process.env["GLYPHIX_BUILD_DIR"] ? ".node-entry.json" : "entry.vite.json";
175
176
  const content = JSON.parse(
176
177
  (0, import_node_fs.readFileSync)((0, import_node_path3.resolve)(this.buildRoot, entryFile)).toString()
@@ -210,7 +211,10 @@ var GxGenerate = class {
210
211
  if (key.startsWith("GLYPHIX"))
211
212
  envDefine[`process.env.${key}`] = JSON.stringify(process.env[key]);
212
213
  });
213
- return envDefine;
214
+ return {
215
+ ...envDefine,
216
+ GLYPHIX_EXEC_ROOT: JSON.stringify(this.workspaceRoot)
217
+ };
214
218
  }
215
219
  generateEsbuildConfig() {
216
220
  const resolveExtensions = [".ts", ".js"];
@@ -279,16 +283,29 @@ var GxGenerate = class {
279
283
  }
280
284
  ]
281
285
  };
282
- const customConfigPath = (0, import_node_path3.resolve)(
286
+ let customConfigPath = (0, import_node_path3.resolve)(
283
287
  this.sourceRoot,
284
288
  "..",
285
- "glyphix.config.js"
289
+ "glyphix.config.ts"
286
290
  );
291
+ if (!(0, import_node_fs.existsSync)(customConfigPath))
292
+ customConfigPath = (0, import_node_path3.resolve)(
293
+ this.sourceRoot,
294
+ "..",
295
+ "glyphix.config.js"
296
+ );
287
297
  if (!(0, import_node_fs.existsSync)(customConfigPath)) return internalConfig;
288
298
  try {
299
+ if (customConfigPath.endsWith(".ts")) {
300
+ require("ts-node").register({
301
+ transpileOnly: true,
302
+ compilerOptions: {
303
+ module: "commonjs"
304
+ }
305
+ });
306
+ }
289
307
  const useConfig = require(customConfigPath);
290
308
  const a = mergeEsbuildConfigs(internalConfig, useConfig);
291
- console.log(a.plugins);
292
309
  return a;
293
310
  } catch (error) {
294
311
  console.error(error);
@@ -347,10 +364,6 @@ var GxGenerate = class {
347
364
  }
348
365
  };
349
366
  function generateGlyphix() {
350
- console.log(
351
- "process",
352
- !process.env["VITE_BUILD_DIR"] || !process.env["VITE_SOURCE_DIR"]
353
- );
354
367
  if ((!process.env["VITE_BUILD_DIR"] || !process.env["VITE_SOURCE_DIR"]) && (!process.env["GLYPHIX_BUILD_DIR"] || !process.env["GLYPHIX_SOURCE_DIR"]))
355
368
  throw Error("not set glyphix project path");
356
369
  const generate = new GxGenerate();
@@ -0,0 +1,132 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var buildServer_exports = {};
30
+ __export(buildServer_exports, {
31
+ buildServerPlugin: () => buildServerPlugin
32
+ });
33
+ module.exports = __toCommonJS(buildServer_exports);
34
+ var import_esbuild = __toESM(require("esbuild"));
35
+ var path = __toESM(require("path"));
36
+ var import_fs_extra = __toESM(require("fs-extra"));
37
+ const disallowed = [
38
+ "@system.router",
39
+ "@system.prompt",
40
+ "@system.device",
41
+ "@system.battery",
42
+ "@system.schedule",
43
+ "@system.notification",
44
+ "@system.notification",
45
+ "@system.vibrator",
46
+ "@system.internal",
47
+ "@system.test",
48
+ "@system.media",
49
+ "@system.audiokit",
50
+ "@system.calendar",
51
+ "@system.geolocation"
52
+ ];
53
+ function buildServerPlugin(options) {
54
+ return {
55
+ name: "build-server",
56
+ async setup(build) {
57
+ build.onEnd(async (result) => {
58
+ });
59
+ const resolveExtensions = [".ts", ".js"];
60
+ console.log("00000", build.initialOptions.define);
61
+ const execRoot = JSON.parse(
62
+ build.initialOptions.define["GLYPHIX_EXEC_ROOT"]
63
+ );
64
+ const serverOutputPath = path.resolve(
65
+ execRoot,
66
+ process.env["GLYPHIX_BUILD_DIR"],
67
+ "assets"
68
+ );
69
+ if (!import_fs_extra.default.existsSync(serverOutputPath)) {
70
+ import_fs_extra.default.mkdirSync(serverOutputPath);
71
+ }
72
+ const manifestPath = path.resolve(
73
+ execRoot,
74
+ process.env["GLYPHIX_SOURCE_DIR"],
75
+ "manifest.json"
76
+ );
77
+ const packageName = JSON.parse(
78
+ import_fs_extra.default.readFileSync(manifestPath).toString()
79
+ ).package;
80
+ try {
81
+ await import_esbuild.default.build({
82
+ entryPoints: [options.entry],
83
+ // 入口文件
84
+ bundle: true,
85
+ // 启用打包
86
+ outfile: path.resolve(serverOutputPath, "server.jsc"),
87
+ splitting: false,
88
+ // 启用代码分割
89
+ format: "esm",
90
+ // 输出为 ESM 格式
91
+ resolveExtensions,
92
+ external: ["@system*"],
93
+ platform: "node",
94
+ target: "node14",
95
+ // 目标平台设置为最新 ECMAScript
96
+ define: build.initialOptions.define,
97
+ sourcemap: false,
98
+ minify: options.minify,
99
+ banner: {
100
+ js: `const packageName = "${packageName}";`
101
+ },
102
+ plugins: [
103
+ {
104
+ name: "forbid-modules",
105
+ setup(build2) {
106
+ build2.onResolve({ filter: /.*/ }, (args) => {
107
+ if (disallowed.includes(args.path)) {
108
+ return {
109
+ errors: [
110
+ {
111
+ text: `\u274C worker \u4E2D\u4F7F\u7528\u4E86\u88AB\u7981\u6B62\u7684\u6A21\u5757 "${args.path}"\uFF0C\u8BF7\u79FB\u9664\uFF01`
112
+ }
113
+ ]
114
+ };
115
+ }
116
+ return null;
117
+ });
118
+ }
119
+ },
120
+ ...options.plugins ?? []
121
+ ]
122
+ });
123
+ } catch (err) {
124
+ process.exit(21);
125
+ }
126
+ }
127
+ };
128
+ }
129
+ // Annotate the CommonJS export names for ESM import in node:
130
+ 0 && (module.exports = {
131
+ buildServerPlugin
132
+ });
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __copyProps = (to, from, except, desc) => {
7
+ if (from && typeof from === "object" || typeof from === "function") {
8
+ for (let key of __getOwnPropNames(from))
9
+ if (!__hasOwnProp.call(to, key) && key !== except)
10
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
+ }
12
+ return to;
13
+ };
14
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
15
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
16
+ var index_exports = {};
17
+ module.exports = __toCommonJS(index_exports);
18
+ __reExport(index_exports, require("./buildServer"), module.exports);
19
+ // Annotate the CommonJS export names for ESM import in node:
20
+ 0 && (module.exports = {
21
+ ...require("./buildServer")
22
+ });
@@ -0,0 +1,121 @@
1
+ var __async = (__this, __arguments, generator) => {
2
+ return new Promise((resolve, reject) => {
3
+ var fulfilled = (value) => {
4
+ try {
5
+ step(generator.next(value));
6
+ } catch (e) {
7
+ reject(e);
8
+ }
9
+ };
10
+ var rejected = (value) => {
11
+ try {
12
+ step(generator.throw(value));
13
+ } catch (e) {
14
+ reject(e);
15
+ }
16
+ };
17
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
18
+ step((generator = generator.apply(__this, __arguments)).next());
19
+ });
20
+ };
21
+ import esbuild from "esbuild";
22
+ import * as path from "path";
23
+ import fse from "fs-extra";
24
+ const disallowed = [
25
+ "@system.router",
26
+ "@system.prompt",
27
+ "@system.device",
28
+ "@system.battery",
29
+ "@system.schedule",
30
+ "@system.notification",
31
+ "@system.notification",
32
+ "@system.vibrator",
33
+ "@system.internal",
34
+ "@system.test",
35
+ "@system.media",
36
+ "@system.audiokit",
37
+ "@system.calendar",
38
+ "@system.geolocation"
39
+ ];
40
+ function buildServerPlugin(options) {
41
+ return {
42
+ name: "build-server",
43
+ setup(build) {
44
+ return __async(this, null, function* () {
45
+ var _a2;
46
+ build.onEnd((result) => __async(this, null, function* () {
47
+ }));
48
+ const resolveExtensions = [".ts", ".js"];
49
+ console.log("00000", build.initialOptions.define);
50
+ const execRoot = JSON.parse(
51
+ build.initialOptions.define["GLYPHIX_EXEC_ROOT"]
52
+ );
53
+ const serverOutputPath = path.resolve(
54
+ execRoot,
55
+ process.env["GLYPHIX_BUILD_DIR"],
56
+ "assets"
57
+ );
58
+ if (!fse.existsSync(serverOutputPath)) {
59
+ fse.mkdirSync(serverOutputPath);
60
+ }
61
+ const manifestPath = path.resolve(
62
+ execRoot,
63
+ process.env["GLYPHIX_SOURCE_DIR"],
64
+ "manifest.json"
65
+ );
66
+ const packageName = JSON.parse(
67
+ fse.readFileSync(manifestPath).toString()
68
+ ).package;
69
+ try {
70
+ yield esbuild.build({
71
+ entryPoints: [options.entry],
72
+ // 入口文件
73
+ bundle: true,
74
+ // 启用打包
75
+ outfile: path.resolve(serverOutputPath, "server.jsc"),
76
+ splitting: false,
77
+ // 启用代码分割
78
+ format: "esm",
79
+ // 输出为 ESM 格式
80
+ resolveExtensions,
81
+ external: ["@system*"],
82
+ platform: "node",
83
+ target: "node14",
84
+ // 目标平台设置为最新 ECMAScript
85
+ define: build.initialOptions.define,
86
+ sourcemap: false,
87
+ minify: options.minify,
88
+ banner: {
89
+ js: `const packageName = "${packageName}";`
90
+ },
91
+ plugins: [
92
+ {
93
+ name: "forbid-modules",
94
+ setup(build2) {
95
+ build2.onResolve({ filter: /.*/ }, (args) => {
96
+ if (disallowed.includes(args.path)) {
97
+ return {
98
+ errors: [
99
+ {
100
+ text: `\u274C worker \u4E2D\u4F7F\u7528\u4E86\u88AB\u7981\u6B62\u7684\u6A21\u5757 "${args.path}"\uFF0C\u8BF7\u79FB\u9664\uFF01`
101
+ }
102
+ ]
103
+ };
104
+ }
105
+ return null;
106
+ });
107
+ }
108
+ },
109
+ ...(_a2 = options.plugins) != null ? _a2 : []
110
+ ]
111
+ });
112
+ } catch (err) {
113
+ process.exit(21);
114
+ }
115
+ });
116
+ }
117
+ };
118
+ }
119
+ export {
120
+ buildServerPlugin
121
+ };
@@ -0,0 +1 @@
1
+ export * from "./buildServer";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "glyphix",
3
- "version": "1.1.1",
3
+ "version": "1.2.1",
4
4
  "main": "lib/index.js",
5
5
  "types": "types/index.d.ts",
6
6
  "files": [
@@ -8,7 +8,8 @@
8
8
  "types/",
9
9
  "template/",
10
10
  "script/",
11
- "libs/"
11
+ "libs/",
12
+ "cjs/"
12
13
  ],
13
14
  "bin": {
14
15
  "glyphix": "./bin/glyphix.js"
@@ -19,12 +20,26 @@
19
20
  "import": {
20
21
  "types": "./types/index.d.ts",
21
22
  "default": "./libs/index.js"
23
+ },
24
+ "require": {
25
+ "types": "./types/index.d.ts",
26
+ "default": "./cjs/index.js"
27
+ }
28
+ },
29
+ "./plugin": {
30
+ "import": {
31
+ "types": "./types/plugin/index.d.ts",
32
+ "default": "./libs/plugin/index.js"
33
+ },
34
+ "require": {
35
+ "types": "./types/plugin/index.d.ts",
36
+ "default": "./cjs/plugin/index.js"
22
37
  }
23
38
  }
24
39
  },
25
40
  "scripts": {
26
41
  "dev": "cross-env NODE_ENV=development ts-node src/index.ts generate",
27
- "build": "rimraf dist && ts-node script/build.ts",
42
+ "build": "rimraf dist && ts-node script/build.ts && ts-node script/buildPlugin.ts",
28
43
  "dev:local": "ts-node script/build.ts && sudo npm install /Users/hui/Documents/workspaces/work/appstore/develop-tools/gxTools/dist -g"
29
44
  },
30
45
  "keywords": [
@@ -37,7 +52,7 @@
37
52
  "@types/adm-zip": "^0.5.7",
38
53
  "@types/fs-extra": "^11.0.4",
39
54
  "@types/lodash": "^4.17.15",
40
- "@types/node": "^22.10.5",
55
+ "@types/node": "^24.1.0",
41
56
  "@types/ramda": "^0.30.2",
42
57
  "@types/yargs": "^17.0.33",
43
58
  "cross-env": "^7.0.3",
@@ -60,4 +75,4 @@
60
75
  "yargs": "^17.7.2"
61
76
  },
62
77
  "packageManager": "yarn@1.22.22+sha1.ac34549e6aa8e7ead463a7407e1c7390f61a6610"
63
- }
78
+ }
@@ -0,0 +1,7 @@
1
+ import { Plugin } from 'esbuild';
2
+ export declare function buildServerPlugin(options: {
3
+ entry: string;
4
+ minify?: boolean;
5
+ plugins?: Array<Plugin>;
6
+ }): Plugin;
7
+ //# sourceMappingURL=buildServer.d.ts.map
@@ -0,0 +1,2 @@
1
+ export * from './buildServer';
2
+ //# sourceMappingURL=index.d.ts.map