|
1 |
| -import sanitizeFilename from "sanitize-filename"; |
2 |
| -import * as npm from "./npm"; |
3 |
| -import pacote from "pacote"; |
4 | 1 | import path from "node:path";
|
5 | 2 |
|
6 | 3 | import esbuild from "esbuild";
|
7 | 4 | import { fileExists } from "../files";
|
8 | 5 |
|
9 | 6 | import { copyFileSync, writeFileSync } from "fs";
|
10 |
| -import { getLocalRepositoryManifests } from "./local-repository"; |
11 | 7 | import { ExtractedPluginManifest } from "./plugin-manifest";
|
12 | 8 |
|
13 | 9 | const cwd = process.cwd();
|
14 | 10 | const outDir = path.join(cwd, "dist", "plugins");
|
15 |
| -// rmSync(outDir, { recursive: true, force: true }); |
16 |
| -console.log("outDir", outDir); |
17 | 11 |
|
18 | 12 | const external = [
|
19 | 13 | "@titan-reactor-runtime/ui",
|
@@ -48,66 +42,89 @@ export const build = async (repository: Repository) => {
|
48 | 42 | if (manifest.deprecated) {
|
49 | 43 | continue;
|
50 | 44 | }
|
51 |
| - const hostFilePath = path.join(sourceFolderPath, "host", "index.ts"); |
52 |
| - const uiFilePath = path.join(sourceFolderPath, "ui", "index"); |
53 |
| - const readmeFilePath = path.join(sourceFolderPath, "readme.md"); |
| 45 | + const hostFilePath = path.join(sourceFolderPath, "src", "index.ts"); |
| 46 | + const uiFilePath = path.join(sourceFolderPath, "src", "components", "index"); |
54 | 47 |
|
55 |
| - const files = [ |
| 48 | + const searchFiles = [ |
56 | 49 | { path: hostFilePath, type: "host.js" },
|
57 | 50 | { path: uiFilePath + ".tsx", type: "ui.js" },
|
58 | 51 | { path: uiFilePath + ".jsx", type: "ui.js" },
|
59 |
| - { path: readmeFilePath, type: "readme.md" }, |
60 | 52 | ];
|
61 | 53 |
|
62 |
| - for (const file of files) { |
| 54 | + const files: { path: string; type: string }[] = []; |
| 55 | + |
| 56 | + for (const file of searchFiles) { |
63 | 57 | if (await fileExists(file.path)) {
|
| 58 | + files.push(file); |
| 59 | + } |
| 60 | + } |
| 61 | + |
| 62 | + if (files.length === 0) { |
| 63 | + console.warn("no files found for", manifest.name); |
| 64 | + continue; |
| 65 | + } |
| 66 | + |
| 67 | + const idx = { |
| 68 | + name: manifest.name, |
| 69 | + version: manifest.version, |
| 70 | + description: manifest.description, |
| 71 | + rootUrl: folderName, |
| 72 | + files: [], |
| 73 | + } |
| 74 | + |
| 75 | + for (const file of files) { |
64 | 76 | console.log(file.type + " file found", file);
|
65 | 77 |
|
66 | 78 | try {
|
67 |
| - const outfile = path.join(outDir, folderName, file.type); |
68 |
| - |
69 |
| - if (file.type === "readme.md") { |
70 |
| - copyFileSync(file.path, outfile); |
71 |
| - } else { |
72 |
| - await esbuild.build({ |
73 |
| - entryPoints: [file.path], |
74 |
| - bundle: true, |
75 |
| - format: "esm", |
76 |
| - outfile, |
77 |
| - external, |
78 |
| - banner: { |
79 |
| - js: |
80 |
| - file.type === "ui.js" |
81 |
| - ? `import { _rc } from "@titan-reactor-runtime/ui"; const registerComponent = (...args) => _rc("${manifest.name}", ...args);` |
82 |
| - : "", |
83 |
| - }, |
84 |
| - }); |
85 |
| - } |
| 79 | + const outfile = path.join(outDir, folderName, "dist", file.type); |
| 80 | + |
| 81 | + await esbuild.build({ |
| 82 | + entryPoints: [file.path], |
| 83 | + bundle: true, |
| 84 | + format: "esm", |
| 85 | + outfile, |
| 86 | + external, |
| 87 | + banner: { |
| 88 | + js: |
| 89 | + file.type === "ui.js" |
| 90 | + ? `import { _rc } from "@titan-reactor-runtime/ui"; const registerComponent = (...args) => _rc("${manifest.name}", ...args);` |
| 91 | + : "", |
| 92 | + }, |
| 93 | + }); |
86 | 94 |
|
87 |
| - copyFileSync( |
88 |
| - path.join(sourceFolderPath, "package.json"), |
89 |
| - path.join(outDir, folderName, "package.json") |
90 |
| - ); |
91 |
| - |
92 |
| - const idx = index.get(manifest.name) ?? { |
93 |
| - name: manifest.name, |
94 |
| - version: manifest.version, |
95 |
| - description: manifest.description, |
96 |
| - rootUrl: folderName, |
97 |
| - files: [], |
98 |
| - }; |
99 | 95 | idx.files.push(file.type);
|
100 |
| - index.set(manifest.name, idx); |
101 | 96 | } catch (error) {
|
102 |
| - console.log("error building", file.path, error); |
| 97 | + console.error("error building", file.path, error); |
103 | 98 | }
|
104 | 99 | }
|
| 100 | + |
| 101 | + try { |
| 102 | + copyFileSync( |
| 103 | + path.join(sourceFolderPath, "package.json"), |
| 104 | + path.join(outDir, folderName, "package.json") |
| 105 | + ); |
| 106 | + |
| 107 | + if (await fileExists(path.join(sourceFolderPath, "readme.md"))) { |
| 108 | + copyFileSync( |
| 109 | + path.join(sourceFolderPath, "readme.md"), |
| 110 | + path.join(outDir, folderName, "readme.md") |
| 111 | + ); |
| 112 | + } |
| 113 | + index.set(manifest.name, idx); |
| 114 | + } catch (error) { |
| 115 | + console.error("error building manifest", error); |
| 116 | + } |
105 | 117 | }
|
106 |
| - } |
107 | 118 |
|
108 | 119 | if (cleanup) {
|
109 | 120 | cleanup();
|
110 | 121 | }
|
111 | 122 |
|
112 |
| - writeFileSync(path.join(outDir, "index.json"), JSON.stringify([...index.values()])); |
| 123 | + const indexJson = { |
| 124 | + indexVersion: 1, |
| 125 | + buildVersion: 0, |
| 126 | + packages: [...index.values()], |
| 127 | + } |
| 128 | + |
| 129 | + writeFileSync(path.join(outDir, "index.json"), JSON.stringify(indexJson)); |
113 | 130 | };
|
0 commit comments