deepstrike 0.1.0 → 2.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 ADDED
@@ -0,0 +1,189 @@
1
+ #!/usr/bin/env bun
2
+ // @bun
3
+
4
+ // src/cli.ts
5
+ import { promises as fs } from "fs";
6
+ import path from "path";
7
+
8
+ // src/fs/common.ts
9
+ var formatEnvironmentFileName = (environment) => {
10
+ const fsSafeEnvironment = environment.replace(/[^a-zA-Z0-9-_]/g, "_").toLowerCase();
11
+ return `.secrets.${fsSafeEnvironment}.json`;
12
+ };
13
+ var BASE_PATH = "./.deepstrike";
14
+ var TEMPLATE_FILE_NAME = formatEnvironmentFileName("env");
15
+
16
+ // src/cli.ts
17
+ var deepstrikeDirName = BASE_PATH;
18
+ var envTemplateFileName = TEMPLATE_FILE_NAME;
19
+ var getProjectRoot = () => process.cwd();
20
+ var getDeepstrikeDir = () => path.join(getProjectRoot(), deepstrikeDirName);
21
+ var getEnvTemplatePath = () => path.join(getDeepstrikeDir(), envTemplateFileName);
22
+ var getEnvironmentSecretsPath = (environmentName) => path.join(getDeepstrikeDir(), formatEnvironmentFileName(environmentName));
23
+ var ensureDir = async (directoryPath) => {
24
+ await fs.mkdir(directoryPath, { recursive: true });
25
+ };
26
+ var fileExists = async (filePath) => {
27
+ try {
28
+ await fs.stat(filePath);
29
+ return true;
30
+ } catch {
31
+ return false;
32
+ }
33
+ };
34
+ var writeJsonIfMissing = async (filePath, data) => {
35
+ if (await fileExists(filePath))
36
+ return false;
37
+ await fs.writeFile(filePath, JSON.stringify(data, null, 2) + `
38
+ `, "utf8");
39
+ return true;
40
+ };
41
+ var writeJsonOverwrite = async (filePath, data) => {
42
+ await fs.writeFile(filePath, JSON.stringify(data, null, 2) + `
43
+ `, "utf8");
44
+ };
45
+ var appendGitignoreRules = async (projectRoot) => {
46
+ const gitignorePath = path.join(projectRoot, ".gitignore");
47
+ const rules = [".deepstrike/.secrets.*.json", "!.deepstrike/.secrets.env.json"];
48
+ let existing = "";
49
+ if (await fileExists(gitignorePath)) {
50
+ existing = await fs.readFile(gitignorePath, "utf8");
51
+ }
52
+ const normalized = existing.replace(/\r\n/g, `
53
+ `);
54
+ const missingRules = rules.filter((rule) => !new RegExp(`^${escapeRegex(rule)}$`, "m").test(normalized));
55
+ if (missingRules.length === 0)
56
+ return false;
57
+ const needsLeadingNewline = normalized.length > 0 && !normalized.endsWith(`
58
+ `);
59
+ const block = (needsLeadingNewline ? `
60
+ ` : "") + missingRules.join(`
61
+ `) + `
62
+ `;
63
+ await fs.writeFile(gitignorePath, normalized + block, "utf8");
64
+ return true;
65
+ };
66
+ var escapeRegex = (value) => value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
67
+ var getTemplateData = () => ({
68
+ projectName: "MyProject",
69
+ secretStoreName: "MyAkv",
70
+ connectionData: {
71
+ subscriptionId: "your-subscription-id",
72
+ tenantId: "your-tenant-id"
73
+ },
74
+ environment: {
75
+ name: "Template",
76
+ secretFileVersion: "latest"
77
+ },
78
+ secretNames: ["DatabasePassword", "ApiKey"]
79
+ });
80
+ var printHelp = () => {
81
+ const text = `deepstrike
82
+
83
+ Usage:
84
+ deepstrike init
85
+ deepstrike create <environment>
86
+ deepstrike push <environment>
87
+ deepstrike pull <environment>
88
+
89
+ Notes:
90
+ Config directory: ./${deepstrikeDirName}
91
+ Template file: ./${deepstrikeDirName}/${envTemplateFileName}
92
+ Env file pattern: ./${deepstrikeDirName}/.secrets.<environment>.json
93
+ `;
94
+ process.stdout.write(text);
95
+ };
96
+ var initCommand = async () => {
97
+ const projectRoot = getProjectRoot();
98
+ const deepstrikeDir = getDeepstrikeDir();
99
+ const templatePath = getEnvTemplatePath();
100
+ await ensureDir(deepstrikeDir);
101
+ const wroteTemplate = await writeJsonIfMissing(templatePath, getTemplateData());
102
+ const updatedGitignore = await appendGitignoreRules(projectRoot);
103
+ const lines = [];
104
+ lines.push("Deepstrike initialized.");
105
+ lines.push(`Directory: ${deepstrikeDirName}`);
106
+ lines.push(`Template: ${path.relative(projectRoot, templatePath)}`);
107
+ lines.push(wroteTemplate ? "Template file created." : "Template file already exists.");
108
+ lines.push(updatedGitignore ? ".gitignore updated." : ".gitignore already up to date.");
109
+ lines.push("Next: deepstrike create <environment>");
110
+ process.stdout.write(lines.join(`
111
+ `) + `
112
+ `);
113
+ };
114
+ var createCommand = async (environmentRaw) => {
115
+ const environmentName = formatEnvironmentFileName(environmentRaw);
116
+ const deepstrikeDir = getDeepstrikeDir();
117
+ const targetPath = getEnvironmentSecretsPath(environmentName);
118
+ await ensureDir(deepstrikeDir);
119
+ if (await fileExists(targetPath)) {
120
+ process.stdout.write(`File already exists: ${path.relative(getProjectRoot(), targetPath)}
121
+ `);
122
+ return;
123
+ }
124
+ const template = getTemplateData();
125
+ const envData = {
126
+ ...template,
127
+ environment: {
128
+ name: environmentName,
129
+ secretFileVersion: "latest"
130
+ }
131
+ };
132
+ await writeJsonOverwrite(targetPath, envData);
133
+ process.stdout.write(`Created: ${path.relative(getProjectRoot(), targetPath)}
134
+ `);
135
+ process.stdout.write(`Edit the file, then run: deepstrike push <environment>
136
+ `);
137
+ };
138
+ var pushCommand = async (environmentRaw) => {
139
+ const environmentName = formatEnvironmentFileName(environmentRaw);
140
+ const filePath = getEnvironmentSecretsPath(environmentName);
141
+ if (!await fileExists(filePath)) {
142
+ throw new Error(`Missing environment file: ${path.relative(getProjectRoot(), filePath)}`);
143
+ }
144
+ throw new Error("push is not implemented yet");
145
+ };
146
+ var pullCommand = async (environmentRaw) => {
147
+ const environmentName = formatEnvironmentFileName(environmentRaw);
148
+ const filePath = getEnvironmentSecretsPath(environmentName);
149
+ throw new Error("pull is not implemented yet");
150
+ };
151
+ var main = async () => {
152
+ const [, , command, ...args] = process.argv;
153
+ if (!command || command === "help" || command === "--help" || command === "-h") {
154
+ printHelp();
155
+ return;
156
+ }
157
+ if (command === "init") {
158
+ await initCommand();
159
+ return;
160
+ }
161
+ if (command === "create") {
162
+ const environment = args[0];
163
+ if (!environment)
164
+ throw new Error("create requires <environment>");
165
+ await createCommand(environment);
166
+ return;
167
+ }
168
+ if (command === "push") {
169
+ const environment = args[0];
170
+ if (!environment)
171
+ throw new Error("push requires <environment>");
172
+ await pushCommand(environment);
173
+ return;
174
+ }
175
+ if (command === "pull") {
176
+ const environment = args[0];
177
+ if (!environment)
178
+ throw new Error("pull requires <environment>");
179
+ await pullCommand(environment);
180
+ return;
181
+ }
182
+ throw new Error(`Unknown command: ${command}`);
183
+ };
184
+ main().catch((error) => {
185
+ const message = error instanceof Error ? error.message : String(error);
186
+ process.stderr.write(`${message}
187
+ `);
188
+ process.exit(1);
189
+ });