@ldsg/cli 0.3.46 → 0.3.48

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 (30) hide show
  1. package/.rush/temp/package-deps_build.json +11 -9
  2. package/.rush/temp/shrinkwrap-deps.json +1 -2
  3. package/.tsbuildinfo +1 -1
  4. package/CHANGELOG.json +52 -0
  5. package/CHANGELOG.md +15 -1
  6. package/dist/commands/generate/utils/generate-application/index.js +36 -3
  7. package/dist/commands/generate/utils/generate-application/index.js.map +1 -1
  8. package/dist/commands/generate/utils/generate-application/utils/build-app-generator-app/index.js +7 -14
  9. package/dist/commands/generate/utils/generate-application/utils/build-app-generator-app/index.js.map +1 -1
  10. package/dist/commands/generate/utils/generate-application/utils/build-meta-generator-app/index.js +8 -24
  11. package/dist/commands/generate/utils/generate-application/utils/build-meta-generator-app/index.js.map +1 -1
  12. package/dist/commands/generate/utils/generate-application/utils/generate-app/index.js +1 -1
  13. package/dist/commands/generate/utils/generate-application/utils/generate-app/index.js.map +1 -1
  14. package/dist/commands/generate/utils/generate-application/utils/index.d.ts +1 -0
  15. package/dist/commands/generate/utils/generate-application/utils/index.js +1 -0
  16. package/dist/commands/generate/utils/generate-application/utils/index.js.map +1 -1
  17. package/dist/commands/generate/utils/generate-application/utils/load-generator-app/index.d.ts +7 -0
  18. package/dist/commands/generate/utils/generate-application/utils/load-generator-app/index.js +29 -0
  19. package/dist/commands/generate/utils/generate-application/utils/load-generator-app/index.js.map +1 -0
  20. package/dist/commands/generate/utils/generate-application/utils/load-generator-app/types.d.ts +2 -0
  21. package/dist/commands/generate/utils/generate-application/utils/load-generator-app/types.js +3 -0
  22. package/dist/commands/generate/utils/generate-application/utils/load-generator-app/types.js.map +1 -0
  23. package/package.json +6 -4
  24. package/src/commands/generate/utils/generate-application/index.ts +73 -7
  25. package/src/commands/generate/utils/generate-application/utils/build-app-generator-app/index.ts +11 -19
  26. package/src/commands/generate/utils/generate-application/utils/build-meta-generator-app/index.ts +9 -66
  27. package/src/commands/generate/utils/generate-application/utils/generate-app/index.ts +1 -1
  28. package/src/commands/generate/utils/generate-application/utils/index.ts +1 -0
  29. package/src/commands/generate/utils/generate-application/utils/load-generator-app/index.ts +64 -0
  30. package/src/commands/generate/utils/generate-application/utils/load-generator-app/types.ts +3 -0
@@ -0,0 +1,64 @@
1
+ import { buildWithPnpmWorkspace, extractZipToFolder, installDependencies } from "@ldsg/utils";
2
+ import { GeneratorApp, GeneratorAppResource } from "@ldsg/generator-app";
3
+ import fs from "fs-extra";
4
+ import path from "node:path";
5
+ import { pathToFileURL } from "node:url";
6
+ import { InstantiateAppResource } from "./types";
7
+
8
+ export interface LoadGeneratorAppParams {
9
+ archive: Buffer<ArrayBufferLike>;
10
+
11
+ /**
12
+ * 生成器应用的解压与构建目录
13
+ */
14
+ outputPath: string;
15
+ }
16
+
17
+ export type LoadGeneratorApp = (params: LoadGeneratorAppParams) => Promise<GeneratorApp>;
18
+
19
+ /**
20
+ * 解压、安装依赖、构建并加载生成器应用,返回其 generate 能力
21
+ */
22
+ export const loadGeneratorApp: LoadGeneratorApp = async (params) => {
23
+ const { archive, outputPath } = params;
24
+
25
+ /**
26
+ * 清理上一次构建产物,避免旧的 dist 残留被动态导入
27
+ */
28
+ await fs.remove(outputPath);
29
+
30
+ extractZipToFolder({
31
+ archive,
32
+ outputPath,
33
+ });
34
+
35
+ await installDependencies({ cwd: outputPath });
36
+
37
+ await buildWithPnpmWorkspace({ cwd: outputPath });
38
+
39
+ /**
40
+ * 产物为 ESM 单文件模块(模板 package.json 的 type 为 module,vite ssr 构建全量内联),
41
+ * 而 @ldsg/cli 编译为 commonjs,tsc 会把 import() 降级为 require(),
42
+ * 故通过 Function 保留原生动态 import。
43
+ */
44
+ const importModule = new Function("specifier", "return import(specifier)") as (
45
+ specifier: string,
46
+ ) => Promise<unknown>;
47
+
48
+ const entryPath = path.join(outputPath, "dist", "index.js");
49
+
50
+ /**
51
+ * 追加时间戳,避免 Node 的 ESM 模块缓存复用上一次构建的产物
52
+ */
53
+ const entryUrl = `${pathToFileURL(entryPath).href}?t=${Date.now()}`;
54
+
55
+ const { instantiateAppResource } = (await importModule(entryUrl)) as {
56
+ instantiateAppResource: InstantiateAppResource<GeneratorAppResource>;
57
+ };
58
+
59
+ const appResource = await instantiateAppResource();
60
+
61
+ const { app: generatorApp } = appResource.createGeneratorApp();
62
+
63
+ return generatorApp;
64
+ };
@@ -0,0 +1,3 @@
1
+ import { Resource } from "@ldsg/resource";
2
+
3
+ export type InstantiateAppResource<T extends Resource> = () => Promise<T>;