glyphix 1.0.8 → 1.0.10

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 (2) hide show
  1. package/glyphix.js +86 -22
  2. package/package.json +2 -1
package/glyphix.js CHANGED
@@ -108,6 +108,7 @@ function findGlyphixTools() {
108
108
  }
109
109
  function buildGlyphix(args) {
110
110
  var _a, _b;
111
+ console.log(findGlyphixTools(), reconstructArgs(args));
111
112
  const childProcess = (0, import_child_process2.execFile)(findGlyphixTools(), reconstructArgs(args), {
112
113
  cwd: process.cwd()
113
114
  });
@@ -117,6 +118,9 @@ function buildGlyphix(args) {
117
118
  (_b = childProcess.stderr) == null ? void 0 : _b.on("data", (data) => {
118
119
  console.error(data);
119
120
  });
121
+ childProcess.on("error", (err) => {
122
+ console.error(err);
123
+ });
120
124
  childProcess.on("exit", () => {
121
125
  console.log("exit");
122
126
  });
@@ -134,6 +138,32 @@ var import_eslint = require("eslint");
134
138
  var import_glob = require("glob");
135
139
  var import_chalk2 = __toESM(require("chalk"));
136
140
  var import_node_process = require("process");
141
+ var import_dotenv = __toESM(require("dotenv"));
142
+ function loadEnv() {
143
+ const dotenvTags = [
144
+ // 本地环境
145
+ "development",
146
+ // 测试环境
147
+ // 比如:单元测试
148
+ "test",
149
+ // 部署环境
150
+ // 比如:日常、预发、线上
151
+ "production"
152
+ ];
153
+ if (!dotenvTags.includes(process.env.GLYPHIX_ENV ?? "")) {
154
+ process.env.GLYPHIX_ENV = dotenvTags[0];
155
+ }
156
+ const dotenvPath = (0, import_node_path3.resolve)(".env");
157
+ const dotenvFiles = [
158
+ dotenvPath,
159
+ `${dotenvPath}.local`,
160
+ `${dotenvPath}.${process.env.GLYPHIX_ENV}`,
161
+ `${dotenvPath}.${process.env.GLYPHIX_ENV}.local`
162
+ ].filter(import_node_fs.existsSync);
163
+ dotenvFiles.reverse().forEach((dotenvFile) => {
164
+ import_dotenv.default.config({ path: dotenvFile });
165
+ });
166
+ }
137
167
  function getOriginFilePath(filePath, rootPath) {
138
168
  const relativePath = (0, import_node_path3.relative)(rootPath, filePath);
139
169
  const projectRoot = process.cwd();
@@ -165,8 +195,11 @@ function lintFile(rootPath) {
165
195
  warnIgnored: true,
166
196
  overrideConfig: {
167
197
  rules: {
168
- "prettier/prettier": "off",
169
- "@typescript-eslint/ban-ts-comment": "off"
198
+ "prettier/prettier": "warn",
199
+ "@typescript-eslint/ban-ts-comment": "warn",
200
+ "@typescript-eslint/no-explicit-any": "warn",
201
+ "@typescript-eslint/no-unused-vars": "warn",
202
+ quotes: "off"
170
203
  }
171
204
  }
172
205
  });
@@ -192,15 +225,6 @@ function dealResource() {
192
225
  const entries = entryFileContent.entry;
193
226
  (0, import_fs_extra2.removeSync)((0, import_node_path3.resolve)(rootPath, ".vite-dist"));
194
227
  let entriedFullPath = entries.map((item) => (0, import_node_path3.resolve)(rootPath, item));
195
- entriedFullPath = entriedFullPath.map((item) => {
196
- if ((0, import_node_fs.existsSync)(item)) {
197
- const dest = item.replace(".js", ".ts");
198
- if ((0, import_node_fs.existsSync)(dest)) (0, import_fs_extra2.removeSync)(dest);
199
- (0, import_fs_extra2.moveSync)(item, dest);
200
- return dest;
201
- }
202
- return item;
203
- });
204
228
  return {
205
229
  root: rootPath,
206
230
  entry: entriedFullPath
@@ -208,6 +232,11 @@ function dealResource() {
208
232
  }
209
233
  function build(rootPath, entriedFullPath) {
210
234
  const resolveExtensions = [".ts", ".js"];
235
+ let envDefine = {};
236
+ Array.from(Object.keys(process.env)).forEach((key) => {
237
+ if (key.startsWith("GLYPHIX"))
238
+ envDefine[`process.env.${key}`] = JSON.stringify(process.env[key]);
239
+ });
211
240
  import_esbuild.default.build({
212
241
  entryPoints: entriedFullPath,
213
242
  // 入口文件
@@ -225,6 +254,7 @@ function build(rootPath, entriedFullPath) {
225
254
  platform: "node",
226
255
  target: "node14",
227
256
  // 目标平台设置为最新 ECMAScript
257
+ define: envDefine,
228
258
  minify: process.env.GLYPHIX_ENV === "development" ? false : true,
229
259
  plugins: [
230
260
  {
@@ -262,6 +292,7 @@ function build(rootPath, entriedFullPath) {
262
292
  }
263
293
  function generateGlyphix() {
264
294
  const config = dealResource();
295
+ loadEnv();
265
296
  lintFile(config.root).then((res) => {
266
297
  if (res.length) {
267
298
  (0, import_node_process.exit)(1);
@@ -271,25 +302,58 @@ function generateGlyphix() {
271
302
  }
272
303
 
273
304
  // src/index.ts
274
- import_yargs.default.option("create", { describe: "create a new project" }).command("create", "create a glyphix project", {}, (args) => {
305
+ import_yargs.default.command("create", "create a glyphix project", {}, (args) => {
275
306
  console.debug("create project", __dirname);
276
307
  if (args._.length < 2) {
277
308
  console.error("miss project name");
278
309
  return;
279
310
  }
280
311
  createProject(process.cwd(), args._[1] + "");
281
- }).command("generate", "compiler glyphix project", {}, generateGlyphix).command("build", "build glyphix project", {}, buildGlyphix).command(
282
- "emu",
283
- "run emulator",
312
+ }).command("generate", "compiler glyphix project", {}, generateGlyphix).command(
313
+ "build",
314
+ "build glyphix project",
284
315
  (yargs2) => {
285
- return yargs2.positional("glyphix emu [OPTIONS]", {
286
- describe: "213",
287
- type: "string"
288
- }).options("device", {
289
- alias: "d",
316
+ return yargs2.options("device", {
317
+ describe: "The name of the device to use when building.\nThereafter, emulation and packaging will use this\nconfiguration.",
318
+ type: "string",
319
+ alias: "d"
320
+ }).options("emulator", {
321
+ describe: "Build packages for the emulator, not the target device",
322
+ type: "boolean",
323
+ alias: "e"
324
+ }).options("image-rules", {
325
+ describe: "Use the specified image rules description file\n(default is config/image-rules.json).",
326
+ type: "string",
327
+ alias: "r"
328
+ }).options("full", {
329
+ describe: "Rebuild all the files for the project.",
290
330
  type: "string",
291
- description: "The name of the device to use when building, \n emulation and packaging"
331
+ alias: "f"
332
+ }).options("dump", {
333
+ describe: "Dump details of the build process to aid debugging.",
334
+ type: "boolean"
292
335
  }).help().argv;
293
336
  },
294
337
  buildGlyphix
295
- ).help().alias("help", "h").argv;
338
+ ).command("emu", "run emulator", (yargs2) => {
339
+ return yargs2.options("device", {
340
+ describe: "The name of the device to use when building,\nemulation and packaging.",
341
+ type: "string",
342
+ alias: "d",
343
+ demandOption: false
344
+ }).options("emulator-exe", {
345
+ describe: "Path to the glyphix-emu executable",
346
+ type: "string",
347
+ alias: "e",
348
+ normalize: true,
349
+ demandOption: false
350
+ }).options("language", {
351
+ describe: "Set the system language name. The default value is zh-CN.",
352
+ type: "string",
353
+ alias: "l"
354
+ }).options("inspector", {
355
+ describe: "Scale the window size to real device screen.",
356
+ type: "string",
357
+ alias: "l"
358
+ }).help().argv;
359
+ }).help().alias("help", "h").argv;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "glyphix",
3
- "version": "1.0.8",
3
+ "version": "1.0.10",
4
4
  "main": "lib/index.js",
5
5
  "types": "types/index.d.ts",
6
6
  "files": [
@@ -18,6 +18,7 @@
18
18
  "dependencies": {
19
19
  "adm-zip": "^0.5.16",
20
20
  "chalk": "^4.1.2",
21
+ "dotenv": "^16.4.7",
21
22
  "esbuild": "^0.24.2",
22
23
  "eslint": "^9.18.0",
23
24
  "fs-extra": "^11.2.0",