deepstrike 6.1.0 → 8.0.0
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/cli.js +93 -0
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -23296,6 +23296,8 @@ Usage:
|
|
|
23296
23296
|
deepstrike push <environment>
|
|
23297
23297
|
deepstrike pull <environment>
|
|
23298
23298
|
deepstrike export <environment>
|
|
23299
|
+
deepstrike import <dotfilePath> <environment>
|
|
23300
|
+
deepstrike add-secret <environment> <secretName> <secretValue> [--push]
|
|
23299
23301
|
|
|
23300
23302
|
Notes:
|
|
23301
23303
|
Config directory: ${deepstrikeDirName}
|
|
@@ -23379,6 +23381,78 @@ var exportCommand = async (environmentRaw) => {
|
|
|
23379
23381
|
process.stdout.write(`Exported secrets for environment ${environmentRaw} to ${outPath}
|
|
23380
23382
|
`);
|
|
23381
23383
|
};
|
|
23384
|
+
var parseEnvText = (text) => {
|
|
23385
|
+
const envMap = new Map;
|
|
23386
|
+
const lines = text.split(/\r?\n/);
|
|
23387
|
+
for (const line of lines) {
|
|
23388
|
+
const trimmed = line.trim();
|
|
23389
|
+
if (!trimmed)
|
|
23390
|
+
continue;
|
|
23391
|
+
if (trimmed.startsWith("#"))
|
|
23392
|
+
continue;
|
|
23393
|
+
const equalIndex = trimmed.indexOf("=");
|
|
23394
|
+
if (equalIndex <= 0)
|
|
23395
|
+
continue;
|
|
23396
|
+
const key = trimmed.slice(0, equalIndex).trim();
|
|
23397
|
+
const value = trimmed.slice(equalIndex + 1);
|
|
23398
|
+
envMap.set(key, value);
|
|
23399
|
+
}
|
|
23400
|
+
return envMap;
|
|
23401
|
+
};
|
|
23402
|
+
var importCommand = async (dotfilePathRaw, environmentRaw) => {
|
|
23403
|
+
const dotfilePath = path5.isAbsolute(dotfilePathRaw) ? dotfilePathRaw : path5.join(getProjectRoot(), dotfilePathRaw);
|
|
23404
|
+
if (!await fileExists(dotfilePath)) {
|
|
23405
|
+
throw new Error(`Dotfile not found: ${dotfilePath}`);
|
|
23406
|
+
}
|
|
23407
|
+
const targetSecretsFilePath = path5.join(deepstrikeDirName, formatEnvironmentFileName(environmentRaw));
|
|
23408
|
+
if (!await fileExists(targetSecretsFilePath)) {
|
|
23409
|
+
throw new Error(`Missing environment file: ${targetSecretsFilePath}`);
|
|
23410
|
+
}
|
|
23411
|
+
const dotfileContent = await fs6.readFile(dotfilePath, "utf8");
|
|
23412
|
+
const envMap = parseEnvText(dotfileContent);
|
|
23413
|
+
const secretsFile = await readEnvironmentSecretsFile(environmentRaw);
|
|
23414
|
+
const updatedSecrets = (secretsFile.secrets ?? []).map((secret) => {
|
|
23415
|
+
const value = envMap.get(secret.name);
|
|
23416
|
+
if (value === undefined)
|
|
23417
|
+
return secret;
|
|
23418
|
+
return { ...secret, value };
|
|
23419
|
+
});
|
|
23420
|
+
const updatedFile = { ...secretsFile, secrets: updatedSecrets };
|
|
23421
|
+
const fileContent = JSON.stringify(updatedFile, null, 4) + `
|
|
23422
|
+
`;
|
|
23423
|
+
await fs6.writeFile(targetSecretsFilePath, fileContent, "utf8");
|
|
23424
|
+
const updatedCount = updatedSecrets.reduce((count, secret, index) => {
|
|
23425
|
+
const before = (secretsFile.secrets ?? [])[index]?.value ?? "";
|
|
23426
|
+
return before !== secret.value ? count + 1 : count;
|
|
23427
|
+
}, 0);
|
|
23428
|
+
process.stdout.write(`Imported ${updatedCount} value${updatedCount === 1 ? "" : "s"} into ${targetSecretsFilePath} from ${dotfilePath}
|
|
23429
|
+
`);
|
|
23430
|
+
};
|
|
23431
|
+
var addSecretCommand = async (environmentRaw, secretName, secretValue, shouldPush) => {
|
|
23432
|
+
await ensureDir(getDeepstrikeDir());
|
|
23433
|
+
const templateFile = await readTemplateFile();
|
|
23434
|
+
const templateSecretNames = templateFile.secretNames ?? [];
|
|
23435
|
+
if (!templateSecretNames.includes(secretName)) {
|
|
23436
|
+
const updatedTemplateFile = { ...templateFile, secretNames: [...templateSecretNames, secretName] };
|
|
23437
|
+
await fs6.writeFile(getEnvTemplatePath(), JSON.stringify(updatedTemplateFile, null, 4) + `
|
|
23438
|
+
`, "utf8");
|
|
23439
|
+
}
|
|
23440
|
+
const environmentFilePath = path5.join(deepstrikeDirName, formatEnvironmentFileName(environmentRaw));
|
|
23441
|
+
if (!await fileExists(environmentFilePath)) {
|
|
23442
|
+
await createEmptySecretsFile(environmentRaw);
|
|
23443
|
+
}
|
|
23444
|
+
const environmentSecretsFile = await readEnvironmentSecretsFile(environmentRaw);
|
|
23445
|
+
const existingSecrets = environmentSecretsFile.secrets ?? [];
|
|
23446
|
+
const updatedSecrets = existingSecrets.some((secret) => secret.name === secretName) ? existingSecrets.map((secret) => secret.name === secretName ? { ...secret, value: secretValue } : secret) : [...existingSecrets, { name: secretName, value: secretValue }];
|
|
23447
|
+
const updatedEnvironmentFile = { ...environmentSecretsFile, secrets: updatedSecrets };
|
|
23448
|
+
await fs6.writeFile(environmentFilePath, JSON.stringify(updatedEnvironmentFile, null, 4) + `
|
|
23449
|
+
`, "utf8");
|
|
23450
|
+
process.stdout.write(`Added secret ${secretName} to ${environmentFilePath}
|
|
23451
|
+
`);
|
|
23452
|
+
if (shouldPush) {
|
|
23453
|
+
await pushCommand(environmentRaw);
|
|
23454
|
+
}
|
|
23455
|
+
};
|
|
23382
23456
|
var main = async () => {
|
|
23383
23457
|
const [, , command, ...args] = process.argv;
|
|
23384
23458
|
if (!command || command === "help" || command === "--help" || command === "-h") {
|
|
@@ -23417,6 +23491,25 @@ var main = async () => {
|
|
|
23417
23491
|
await exportCommand(environment);
|
|
23418
23492
|
return;
|
|
23419
23493
|
}
|
|
23494
|
+
if (command === "import") {
|
|
23495
|
+
const dotfilePath = args[0];
|
|
23496
|
+
const environment = args[1];
|
|
23497
|
+
if (!dotfilePath || !environment)
|
|
23498
|
+
throw new Error("import requires <dotfilePath> <environment>");
|
|
23499
|
+
await importCommand(dotfilePath, environment);
|
|
23500
|
+
return;
|
|
23501
|
+
}
|
|
23502
|
+
if (command === "add-secret") {
|
|
23503
|
+
const environment = args[0];
|
|
23504
|
+
const secretName = args[1];
|
|
23505
|
+
const secretValue = args[2];
|
|
23506
|
+
const shouldPush = args.includes("--push");
|
|
23507
|
+
if (!environment || !secretName || secretValue === undefined) {
|
|
23508
|
+
throw new Error("add-secret requires <environment> <secretName> <secretValue> [--push]");
|
|
23509
|
+
}
|
|
23510
|
+
await addSecretCommand(environment, secretName, secretValue, shouldPush);
|
|
23511
|
+
return;
|
|
23512
|
+
}
|
|
23420
23513
|
throw new Error(`Unknown command: ${command}`);
|
|
23421
23514
|
};
|
|
23422
23515
|
main().catch((error) => {
|
package/package.json
CHANGED