deepstrike 6.0.0 → 7.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 +56 -0
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -23296,6 +23296,7 @@ Usage:
|
|
|
23296
23296
|
deepstrike push <environment>
|
|
23297
23297
|
deepstrike pull <environment>
|
|
23298
23298
|
deepstrike export <environment>
|
|
23299
|
+
deepstrike import <dotfilePath> <environment>
|
|
23299
23300
|
|
|
23300
23301
|
Notes:
|
|
23301
23302
|
Config directory: ${deepstrikeDirName}
|
|
@@ -23379,6 +23380,53 @@ var exportCommand = async (environmentRaw) => {
|
|
|
23379
23380
|
process.stdout.write(`Exported secrets for environment ${environmentRaw} to ${outPath}
|
|
23380
23381
|
`);
|
|
23381
23382
|
};
|
|
23383
|
+
var parseEnvText = (text) => {
|
|
23384
|
+
const envMap = new Map;
|
|
23385
|
+
const lines = text.split(/\r?\n/);
|
|
23386
|
+
for (const line of lines) {
|
|
23387
|
+
const trimmed = line.trim();
|
|
23388
|
+
if (!trimmed)
|
|
23389
|
+
continue;
|
|
23390
|
+
if (trimmed.startsWith("#"))
|
|
23391
|
+
continue;
|
|
23392
|
+
const equalIndex = trimmed.indexOf("=");
|
|
23393
|
+
if (equalIndex <= 0)
|
|
23394
|
+
continue;
|
|
23395
|
+
const key = trimmed.slice(0, equalIndex).trim();
|
|
23396
|
+
const value = trimmed.slice(equalIndex + 1);
|
|
23397
|
+
envMap.set(key, value);
|
|
23398
|
+
}
|
|
23399
|
+
return envMap;
|
|
23400
|
+
};
|
|
23401
|
+
var importCommand = async (dotfilePathRaw, environmentRaw) => {
|
|
23402
|
+
const dotfilePath = path5.isAbsolute(dotfilePathRaw) ? dotfilePathRaw : path5.join(getProjectRoot(), dotfilePathRaw);
|
|
23403
|
+
if (!await fileExists(dotfilePath)) {
|
|
23404
|
+
throw new Error(`Dotfile not found: ${dotfilePath}`);
|
|
23405
|
+
}
|
|
23406
|
+
const targetSecretsFilePath = path5.join(deepstrikeDirName, formatEnvironmentFileName(environmentRaw));
|
|
23407
|
+
if (!await fileExists(targetSecretsFilePath)) {
|
|
23408
|
+
throw new Error(`Missing environment file: ${targetSecretsFilePath}`);
|
|
23409
|
+
}
|
|
23410
|
+
const dotfileContent = await fs6.readFile(dotfilePath, "utf8");
|
|
23411
|
+
const envMap = parseEnvText(dotfileContent);
|
|
23412
|
+
const secretsFile = await readEnvironmentSecretsFile(environmentRaw);
|
|
23413
|
+
const updatedSecrets = (secretsFile.secrets ?? []).map((secret) => {
|
|
23414
|
+
const value = envMap.get(secret.name);
|
|
23415
|
+
if (value === undefined)
|
|
23416
|
+
return secret;
|
|
23417
|
+
return { ...secret, value };
|
|
23418
|
+
});
|
|
23419
|
+
const updatedFile = { ...secretsFile, secrets: updatedSecrets };
|
|
23420
|
+
const fileContent = JSON.stringify(updatedFile, null, 4) + `
|
|
23421
|
+
`;
|
|
23422
|
+
await fs6.writeFile(targetSecretsFilePath, fileContent, "utf8");
|
|
23423
|
+
const updatedCount = updatedSecrets.reduce((count, secret, index) => {
|
|
23424
|
+
const before = (secretsFile.secrets ?? [])[index]?.value ?? "";
|
|
23425
|
+
return before !== secret.value ? count + 1 : count;
|
|
23426
|
+
}, 0);
|
|
23427
|
+
process.stdout.write(`Imported ${updatedCount} value${updatedCount === 1 ? "" : "s"} into ${targetSecretsFilePath} from ${dotfilePath}
|
|
23428
|
+
`);
|
|
23429
|
+
};
|
|
23382
23430
|
var main = async () => {
|
|
23383
23431
|
const [, , command, ...args] = process.argv;
|
|
23384
23432
|
if (!command || command === "help" || command === "--help" || command === "-h") {
|
|
@@ -23417,6 +23465,14 @@ var main = async () => {
|
|
|
23417
23465
|
await exportCommand(environment);
|
|
23418
23466
|
return;
|
|
23419
23467
|
}
|
|
23468
|
+
if (command === "import") {
|
|
23469
|
+
const dotfilePath = args[0];
|
|
23470
|
+
const environment = args[1];
|
|
23471
|
+
if (!dotfilePath || !environment)
|
|
23472
|
+
throw new Error("import requires <dotfilePath> <environment>");
|
|
23473
|
+
await importCommand(dotfilePath, environment);
|
|
23474
|
+
return;
|
|
23475
|
+
}
|
|
23420
23476
|
throw new Error(`Unknown command: ${command}`);
|
|
23421
23477
|
};
|
|
23422
23478
|
main().catch((error) => {
|
package/package.json
CHANGED