@yancyyu/openhermit 1.6.11 → 1.6.12
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/hermit.mjs +29 -12
- package/package.json +1 -1
package/bin/hermit.mjs
CHANGED
|
@@ -84,7 +84,8 @@ const ccConnectConfigPath =
|
|
|
84
84
|
process.env.HERMIT_CC_CONNECT_CONFIG ||
|
|
85
85
|
process.env.CC_CONNECT_CONFIG ||
|
|
86
86
|
path.join(hermitHome, 'cc-connect', 'config.toml');
|
|
87
|
-
const bootstrapProjectName = '
|
|
87
|
+
const bootstrapProjectName = 'default';
|
|
88
|
+
const legacyBootstrapProjectName = '__openhermit_bootstrap__';
|
|
88
89
|
|
|
89
90
|
// ---------------------------------------------------------------------------
|
|
90
91
|
// Update command
|
|
@@ -216,21 +217,37 @@ callback_path = "/openhermit-bootstrap"
|
|
|
216
217
|
`;
|
|
217
218
|
}
|
|
218
219
|
|
|
219
|
-
function
|
|
220
|
-
|
|
220
|
+
function escapeRegExp(value) {
|
|
221
|
+
return value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
function findProjectBlock(raw, name) {
|
|
225
|
+
const projectPattern = new RegExp(
|
|
226
|
+
`\\[\\[projects\\]\\]\\nname\\s*=\\s*"${escapeRegExp(name)}"[\\s\\S]*?(?=\\n\\[\\[projects\\]\\]|\\s*$)`
|
|
227
|
+
);
|
|
221
228
|
const match = raw.match(projectPattern);
|
|
222
|
-
|
|
229
|
+
return match ? { pattern: projectPattern, match } : null;
|
|
230
|
+
}
|
|
223
231
|
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
block.includes('
|
|
227
|
-
block.includes('app_id = "placeholder"')
|
|
228
|
-
|
|
232
|
+
function isManagedBootstrapBlock(block) {
|
|
233
|
+
return (
|
|
234
|
+
block.includes('disabled_commands = ["*"]') &&
|
|
235
|
+
(block.includes('app_id = "placeholder"') ||
|
|
236
|
+
block.includes('channel_token = "openhermit-bootstrap"') ||
|
|
237
|
+
block.includes('callback_path = "/openhermit-bootstrap"'))
|
|
238
|
+
);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
function migrateManagedBootstrapProject(raw) {
|
|
242
|
+
const legacyBlock = findProjectBlock(raw, legacyBootstrapProjectName);
|
|
243
|
+
if (!legacyBlock || !isManagedBootstrapBlock(legacyBlock.match[0])) return raw;
|
|
229
244
|
|
|
230
|
-
|
|
245
|
+
const withoutLegacy = raw.replace(legacyBlock.pattern, '').replace(/\n{3,}/g, '\n\n').trimEnd();
|
|
246
|
+
if (findProjectBlock(withoutLegacy, bootstrapProjectName)) {
|
|
247
|
+
return `${withoutLegacy}\n`;
|
|
248
|
+
}
|
|
231
249
|
|
|
232
|
-
|
|
233
|
-
return raw.replace(projectPattern, `${prefix}${buildBootstrapProjectToml().trimStart()}`);
|
|
250
|
+
return `${withoutLegacy}\n${buildBootstrapProjectToml()}`;
|
|
234
251
|
}
|
|
235
252
|
|
|
236
253
|
function ensureCcConnectConfig() {
|