glyphix 1.0.31 → 1.0.33
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 +203 -175
- package/package.json +1 -1
- package/types/index.d.ts +2 -0
package/bin/glyphix.js
CHANGED
|
@@ -132,194 +132,222 @@ function buildGlyphix(args) {
|
|
|
132
132
|
var import_esbuild = __toESM(require("esbuild"));
|
|
133
133
|
var import_node_path3 = require("path");
|
|
134
134
|
var import_node_fs = require("fs");
|
|
135
|
-
var import_fs_extra2 = require("fs-extra");
|
|
136
|
-
var import_eslint = require("eslint");
|
|
137
|
-
var import_glob = require("glob");
|
|
138
|
-
var import_chalk2 = __toESM(require("chalk"));
|
|
139
|
-
var import_node_process = require("process");
|
|
140
135
|
var import_dotenv = __toESM(require("dotenv"));
|
|
141
136
|
var import_lodash = require("lodash");
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
//
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
import_dotenv.default.config({ path: dotenvFile });
|
|
165
|
-
});
|
|
166
|
-
}
|
|
167
|
-
function getOriginFilePath(filePath, rootPath) {
|
|
168
|
-
const relativePath = (0, import_node_path3.relative)(rootPath, filePath);
|
|
169
|
-
const projectRoot = process.cwd();
|
|
170
|
-
const originPath = (0, import_node_path3.resolve)(projectRoot, "src", relativePath);
|
|
171
|
-
if (originPath.endsWith(".ts")) {
|
|
172
|
-
const uxOrigin = originPath.slice(0, -3) + ".ux";
|
|
173
|
-
if ((0, import_node_fs.existsSync)(uxOrigin)) {
|
|
174
|
-
return uxOrigin;
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
return originPath;
|
|
178
|
-
}
|
|
179
|
-
function outErrorLog(results, filepath) {
|
|
180
|
-
results.messages.forEach((item) => {
|
|
181
|
-
console.log(
|
|
182
|
-
`${filepath}:${item.line}:${item.column}`,
|
|
183
|
-
"\n ",
|
|
184
|
-
import_chalk2.default.red("error"),
|
|
185
|
-
" ",
|
|
186
|
-
item.message,
|
|
187
|
-
" ",
|
|
188
|
-
import_chalk2.default.gray(item.ruleId)
|
|
137
|
+
var import_node_child_process = require("child_process");
|
|
138
|
+
var GxGenerate = class {
|
|
139
|
+
constructor() {
|
|
140
|
+
// 执行 gx 命令的目录路径
|
|
141
|
+
this.workspaceRoot = process.cwd();
|
|
142
|
+
// 正在构建的应用的 src 目录路径
|
|
143
|
+
this.sourceRoot = (0, import_node_path3.resolve)(
|
|
144
|
+
this.workspaceRoot,
|
|
145
|
+
process.env["VITE_SOURCE_DIR"]
|
|
146
|
+
);
|
|
147
|
+
// 构建的 build 目录路径
|
|
148
|
+
this.buildRoot = (0, import_node_path3.resolve)(
|
|
149
|
+
this.workspaceRoot,
|
|
150
|
+
process.env["VITE_BUILD_DIR"]
|
|
151
|
+
);
|
|
152
|
+
// gx 工具传递过来的入口文件,包括 app.{t,j}s 和各个页面的 js 文件路径
|
|
153
|
+
this.entries = [];
|
|
154
|
+
const content = JSON.parse(
|
|
155
|
+
(0, import_node_fs.readFileSync)((0, import_node_path3.resolve)(this.buildRoot, "entry.vite.json")).toString()
|
|
156
|
+
);
|
|
157
|
+
this.entries = content.entry.map(
|
|
158
|
+
(item) => (0, import_node_path3.resolve)(this.buildRoot, item)
|
|
189
159
|
);
|
|
190
|
-
});
|
|
191
|
-
}
|
|
192
|
-
function lintFile(rootPath) {
|
|
193
|
-
const distPath = (0, import_node_path3.join)(rootPath, ".vite-dist");
|
|
194
|
-
if ((0, import_node_fs.existsSync)(distPath)) {
|
|
195
|
-
(0, import_fs_extra2.removeSync)(distPath);
|
|
196
160
|
}
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
quotes: "off"
|
|
211
|
-
}
|
|
161
|
+
loadEnv() {
|
|
162
|
+
const dotenvTags = [
|
|
163
|
+
// 本地环境
|
|
164
|
+
"development",
|
|
165
|
+
// 测试环境
|
|
166
|
+
// 比如:单元测试
|
|
167
|
+
"test",
|
|
168
|
+
// 部署环境
|
|
169
|
+
// 比如:日常、预发、线上
|
|
170
|
+
"production"
|
|
171
|
+
];
|
|
172
|
+
if (!dotenvTags.includes(process.env.GLYPHIX_ENV ?? "")) {
|
|
173
|
+
process.env.GLYPHIX_ENV = dotenvTags[0];
|
|
212
174
|
}
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
outErrorLog(item, originPath);
|
|
175
|
+
const dotenvPath = (0, import_node_path3.resolve)(this.sourceRoot, "..", ".env");
|
|
176
|
+
const dotenvFiles = [
|
|
177
|
+
dotenvPath,
|
|
178
|
+
`${dotenvPath}.local`,
|
|
179
|
+
`${dotenvPath}.${process.env.GLYPHIX_ENV}`,
|
|
180
|
+
`${dotenvPath}.${process.env.GLYPHIX_ENV}.local`
|
|
181
|
+
].filter((item) => {
|
|
182
|
+
return (0, import_node_fs.existsSync)(item);
|
|
222
183
|
});
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
(
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
if ((0, import_node_fs.existsSync)(args.path)) {
|
|
269
|
-
return {
|
|
270
|
-
path: args.path
|
|
271
|
-
};
|
|
272
|
-
}
|
|
273
|
-
for (let i = 0; i < resolveExtensions.length; i++) {
|
|
274
|
-
const fullPath = (0, import_node_path3.join)(
|
|
275
|
-
rootPath,
|
|
276
|
-
`${args.path}${resolveExtensions[i]}`
|
|
277
|
-
);
|
|
278
|
-
if ((0, import_node_fs.existsSync)(fullPath)) {
|
|
184
|
+
console.info(dotenvFiles);
|
|
185
|
+
dotenvFiles.reverse().forEach((dotenvFile) => {
|
|
186
|
+
import_dotenv.default.config({ path: (0, import_node_path3.resolve)(this.sourceRoot, "..", dotenvFile) });
|
|
187
|
+
});
|
|
188
|
+
let envDefine = {};
|
|
189
|
+
Array.from(Object.keys(process.env)).forEach((key) => {
|
|
190
|
+
if (key.startsWith("GLYPHIX"))
|
|
191
|
+
envDefine[`process.env.${key}`] = JSON.stringify(process.env[key]);
|
|
192
|
+
});
|
|
193
|
+
return envDefine;
|
|
194
|
+
}
|
|
195
|
+
generateEsbuildConfig() {
|
|
196
|
+
const resolveExtensions = [".ts", ".js"];
|
|
197
|
+
const that = this;
|
|
198
|
+
const internalConfig = {
|
|
199
|
+
entryPoints: this.entries,
|
|
200
|
+
// 入口文件
|
|
201
|
+
bundle: true,
|
|
202
|
+
// 启用打包
|
|
203
|
+
outdir: (0, import_node_path3.resolve)(this.buildRoot, ".vite-dist"),
|
|
204
|
+
// 输出目录
|
|
205
|
+
splitting: true,
|
|
206
|
+
// 启用代码分割
|
|
207
|
+
format: "esm",
|
|
208
|
+
// 输出为 ESM 格式
|
|
209
|
+
resolveExtensions,
|
|
210
|
+
external: ["@system*"],
|
|
211
|
+
// 将 lodash 和 axios 作为外部依赖
|
|
212
|
+
platform: "node",
|
|
213
|
+
absWorkingDir: (0, import_node_path3.resolve)(this.sourceRoot, ".."),
|
|
214
|
+
target: "node14",
|
|
215
|
+
// 目标平台设置为最新 ECMAScript
|
|
216
|
+
define: {
|
|
217
|
+
"process.env.GLYPHIX_APP_VERSION": `"${this.getGitVersion()}"`,
|
|
218
|
+
...this.loadEnv()
|
|
219
|
+
},
|
|
220
|
+
nodePaths: [(0, import_node_path3.resolve)(this.sourceRoot, "..", "node_modules")],
|
|
221
|
+
sourcemap: true,
|
|
222
|
+
minify: process.env.GLYPHIX_ENV === "development" ? false : true,
|
|
223
|
+
plugins: [
|
|
224
|
+
{
|
|
225
|
+
name: "glyphix-resolve-path",
|
|
226
|
+
setup(build) {
|
|
227
|
+
build.onResolve({ filter: /^\// }, (args) => {
|
|
228
|
+
if ((0, import_node_fs.existsSync)(args.path)) {
|
|
279
229
|
return {
|
|
280
|
-
path:
|
|
230
|
+
path: args.path
|
|
281
231
|
};
|
|
282
232
|
}
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
233
|
+
for (let i = 0; i < resolveExtensions.length; i++) {
|
|
234
|
+
const fullPath = (0, import_node_path3.join)(
|
|
235
|
+
that.buildRoot,
|
|
236
|
+
`${args.path}${resolveExtensions[i]}`
|
|
237
|
+
);
|
|
238
|
+
if ((0, import_node_fs.existsSync)(fullPath)) {
|
|
239
|
+
return {
|
|
240
|
+
path: fullPath
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
const fullIndexPath = (0, import_node_path3.join)(
|
|
244
|
+
that.buildRoot,
|
|
245
|
+
`${args.path}/index${resolveExtensions[i]}`
|
|
246
|
+
);
|
|
247
|
+
if ((0, import_node_fs.existsSync)(fullIndexPath)) {
|
|
248
|
+
return {
|
|
249
|
+
path: fullIndexPath
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
return {
|
|
254
|
+
path: args.path
|
|
255
|
+
};
|
|
256
|
+
});
|
|
257
|
+
}
|
|
288
258
|
}
|
|
259
|
+
]
|
|
260
|
+
};
|
|
261
|
+
const customConfigPath = (0, import_node_path3.resolve)(this.buildRoot, "glyphix.config.js");
|
|
262
|
+
if (!(0, import_node_fs.existsSync)(customConfigPath)) return internalConfig;
|
|
263
|
+
try {
|
|
264
|
+
const useConfig = require(customConfigPath);
|
|
265
|
+
return (0, import_lodash.merge)(internalConfig, useConfig);
|
|
266
|
+
} catch (error) {
|
|
267
|
+
console.error(error);
|
|
268
|
+
}
|
|
269
|
+
return internalConfig;
|
|
270
|
+
}
|
|
271
|
+
judgeIsWorkspace(parentPath, childPath) {
|
|
272
|
+
const resolvedParent = (0, import_node_path3.resolve)(parentPath);
|
|
273
|
+
const resolvedChild = (0, import_node_path3.resolve)(childPath);
|
|
274
|
+
const normalizedParent = resolvedParent + import_node_path3.sep;
|
|
275
|
+
const normalizedChild = resolvedChild + import_node_path3.sep;
|
|
276
|
+
return !normalizedChild.startsWith(normalizedParent);
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* 安装依赖
|
|
280
|
+
* 1. 判断是否是 workspace, 非 workspace 不用安装
|
|
281
|
+
* 2. workspace 项目,需要将 package.json 拷贝到构建目录,在构建目录安装依赖
|
|
282
|
+
* @returns
|
|
283
|
+
*/
|
|
284
|
+
installDependencies() {
|
|
285
|
+
return new Promise((resolve3, reject) => {
|
|
286
|
+
console.log(
|
|
287
|
+
"is workspace project",
|
|
288
|
+
this.judgeIsWorkspace(
|
|
289
|
+
(0, import_node_path3.resolve)(this.sourceRoot, ".."),
|
|
290
|
+
this.buildRoot
|
|
291
|
+
)
|
|
292
|
+
);
|
|
293
|
+
if (!this.judgeIsWorkspace(
|
|
294
|
+
(0, import_node_path3.resolve)(this.sourceRoot, ".."),
|
|
295
|
+
this.buildRoot
|
|
296
|
+
)) {
|
|
297
|
+
resolve3();
|
|
298
|
+
return;
|
|
289
299
|
}
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
300
|
+
const curDir = process.cwd();
|
|
301
|
+
const userConfig = (0, import_node_path3.resolve)(
|
|
302
|
+
this.sourceRoot,
|
|
303
|
+
"..",
|
|
304
|
+
"glyphix.config.js"
|
|
305
|
+
);
|
|
306
|
+
process.chdir((0, import_node_path3.resolve)(this.sourceRoot, ".."));
|
|
307
|
+
const installDepProcess = (0, import_node_child_process.spawn)("npm", ["install"]);
|
|
308
|
+
installDepProcess.on("message", (msg) => {
|
|
309
|
+
console.debug(msg);
|
|
310
|
+
});
|
|
311
|
+
installDepProcess.on("error", (err) => {
|
|
312
|
+
console.error(err);
|
|
313
|
+
});
|
|
314
|
+
installDepProcess.on("close", (code) => {
|
|
315
|
+
if (code === 0) {
|
|
316
|
+
console.info("dependencies install complete");
|
|
317
|
+
process.chdir(curDir);
|
|
318
|
+
resolve3();
|
|
319
|
+
} else {
|
|
320
|
+
process.chdir(curDir);
|
|
321
|
+
process.exit(1);
|
|
322
|
+
}
|
|
323
|
+
});
|
|
324
|
+
});
|
|
299
325
|
}
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
326
|
+
getGitVersion() {
|
|
327
|
+
return (0, import_node_child_process.execSync)("git rev-parse HEAD").toString().trim();
|
|
328
|
+
}
|
|
329
|
+
build() {
|
|
330
|
+
const curDir = process.cwd();
|
|
331
|
+
this.installDependencies().then(() => {
|
|
332
|
+
const config = this.generateEsbuildConfig();
|
|
333
|
+
process.chdir((0, import_node_path3.resolve)(this.sourceRoot, ".."));
|
|
334
|
+
console.info("cur build directory", process.cwd());
|
|
335
|
+
console.log(JSON.stringify(config));
|
|
336
|
+
return import_esbuild.default.build(config);
|
|
337
|
+
}).then(() => {
|
|
338
|
+
process.chdir(curDir);
|
|
339
|
+
console.log("Build completed!");
|
|
340
|
+
}).catch((error) => {
|
|
341
|
+
console.error("Build failed:", error);
|
|
342
|
+
});
|
|
343
|
+
}
|
|
344
|
+
};
|
|
314
345
|
function generateGlyphix() {
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
}
|
|
321
|
-
build(config.root, config.entry);
|
|
322
|
-
});
|
|
346
|
+
console.info("start gen", process.env["VITE_SOURCE_DIR"]);
|
|
347
|
+
if (!process.env["VITE_BUILD_DIR"] || !process.env["VITE_SOURCE_DIR"])
|
|
348
|
+
throw Error("not set glyphix project path");
|
|
349
|
+
const generate = new GxGenerate();
|
|
350
|
+
generate.build();
|
|
323
351
|
}
|
|
324
352
|
|
|
325
353
|
// src/cli/index.ts
|
package/package.json
CHANGED
package/types/index.d.ts
CHANGED
|
@@ -17,10 +17,12 @@
|
|
|
17
17
|
/// <reference path="./exchange.d.ts" />
|
|
18
18
|
/// <reference path="./audiokit.d.ts" />
|
|
19
19
|
|
|
20
|
+
|
|
20
21
|
declare global {
|
|
21
22
|
function $t(key: string): string;
|
|
22
23
|
}
|
|
23
24
|
|
|
25
|
+
|
|
24
26
|
type ComputedResults<C, D> = {
|
|
25
27
|
readonly [K in keyof C as C[K] extends (this: D) => any
|
|
26
28
|
? K
|