@epilot/sdk 2.2.0 → 2.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/dist/bin/cli.js +31 -1
- package/package.json +1 -1
package/dist/bin/cli.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
// src/bin/cli.ts
|
|
4
|
-
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
|
|
4
|
+
import { existsSync, mkdirSync, readFileSync, readdirSync, writeFileSync } from "fs";
|
|
5
5
|
import { dirname, resolve } from "path";
|
|
6
6
|
var OVERRIDES_PATH = ".epilot/sdk-overrides.json";
|
|
7
7
|
var usage = () => {
|
|
@@ -121,6 +121,31 @@ var findSdkRoot = () => {
|
|
|
121
121
|
}
|
|
122
122
|
return null;
|
|
123
123
|
};
|
|
124
|
+
var patchRuntimeChunk = (distDir, kebabName, compactSpec) => {
|
|
125
|
+
if (!existsSync(distDir)) return;
|
|
126
|
+
const runtimeFnName = `require_${kebabName.replace(/-/g, "_")}_runtime`;
|
|
127
|
+
const files = readdirSync(distDir);
|
|
128
|
+
let patched = false;
|
|
129
|
+
for (const file of files) {
|
|
130
|
+
if (!file.endsWith(".js") && !file.endsWith(".cjs")) continue;
|
|
131
|
+
if (file.startsWith("apis/")) continue;
|
|
132
|
+
const filePath = resolve(distDir, file);
|
|
133
|
+
const content = readFileSync(filePath, "utf-8");
|
|
134
|
+
if (!content.includes(runtimeFnName)) continue;
|
|
135
|
+
const newContent = content.replace(
|
|
136
|
+
/module\.exports\s*=\s*\{.*\};/,
|
|
137
|
+
`module.exports = ${JSON.stringify(compactSpec)};`
|
|
138
|
+
);
|
|
139
|
+
if (newContent !== content) {
|
|
140
|
+
writeFileSync(filePath, newContent);
|
|
141
|
+
console.log(` -> patched ${file} (runtime chunk)`);
|
|
142
|
+
patched = true;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
if (!patched) {
|
|
146
|
+
console.log(` (no runtime chunk found to patch for ${kebabName})`);
|
|
147
|
+
}
|
|
148
|
+
};
|
|
124
149
|
var overrideCmd = async (args) => {
|
|
125
150
|
if (args.length === 2) {
|
|
126
151
|
const [apiName, specPath] = args;
|
|
@@ -142,6 +167,10 @@ var overrideCmd = async (args) => {
|
|
|
142
167
|
process.exit(1);
|
|
143
168
|
}
|
|
144
169
|
const defsDir = resolve(sdkRoot, "definitions");
|
|
170
|
+
const distDir = resolve(sdkRoot, "dist");
|
|
171
|
+
if (!existsSync(defsDir)) {
|
|
172
|
+
mkdirSync(defsDir, { recursive: true });
|
|
173
|
+
}
|
|
145
174
|
console.log(`Applying ${entries.length} override(s)...`);
|
|
146
175
|
for (const [apiName, specPath] of entries) {
|
|
147
176
|
try {
|
|
@@ -157,6 +186,7 @@ var overrideCmd = async (args) => {
|
|
|
157
186
|
const runtimeDest = resolve(defsDir, `${kebabName}-runtime.json`);
|
|
158
187
|
writeFileSync(runtimeDest, JSON.stringify(compactSpec));
|
|
159
188
|
console.log(` -> definitions/${kebabName}-runtime.json`);
|
|
189
|
+
patchRuntimeChunk(distDir, kebabName, compactSpec);
|
|
160
190
|
} catch (err) {
|
|
161
191
|
console.error(` Error: ${err.message}`);
|
|
162
192
|
}
|