@tolgamorf/env2op-cli 0.2.0 → 0.2.2
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/README.md +25 -5
- package/dist/cli.js +375 -69
- package/dist/index.d.ts +3 -1
- package/dist/index.js +48 -28
- package/dist/op2env-cli.js +365 -59
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -113,7 +113,7 @@ interface TemplateOptions {
|
|
|
113
113
|
* @returns ParseResult containing variables and any errors
|
|
114
114
|
* @throws Env2OpError if file not found
|
|
115
115
|
*/
|
|
116
|
-
declare function parseEnvFile(filePath: string): ParseResult
|
|
116
|
+
declare function parseEnvFile(filePath: string): Promise<ParseResult>;
|
|
117
117
|
/**
|
|
118
118
|
* Validate that the parsed result has variables
|
|
119
119
|
*
|
|
@@ -198,6 +198,7 @@ declare const ErrorCodes: {
|
|
|
198
198
|
readonly VAULT_CREATE_FAILED: "VAULT_CREATE_FAILED";
|
|
199
199
|
readonly ITEM_EXISTS: "ITEM_EXISTS";
|
|
200
200
|
readonly ITEM_CREATE_FAILED: "ITEM_CREATE_FAILED";
|
|
201
|
+
readonly ITEM_EDIT_FAILED: "ITEM_EDIT_FAILED";
|
|
201
202
|
readonly PARSE_ERROR: "PARSE_ERROR";
|
|
202
203
|
readonly TEMPLATE_NOT_FOUND: "TEMPLATE_NOT_FOUND";
|
|
203
204
|
readonly INJECT_FAILED: "INJECT_FAILED";
|
|
@@ -215,6 +216,7 @@ declare const errors: {
|
|
|
215
216
|
vaultCreateFailed: (message: string) => Env2OpError;
|
|
216
217
|
itemExists: (title: string, vault: string) => Env2OpError;
|
|
217
218
|
itemCreateFailed: (message: string) => Env2OpError;
|
|
219
|
+
itemEditFailed: (message: string) => Env2OpError;
|
|
218
220
|
parseError: (line: number, message: string) => Env2OpError;
|
|
219
221
|
};
|
|
220
222
|
export { writeTemplate, vaultExists, validateParseResult, signIn, parseEnvFile, itemExists2 as itemExists, generateUsageInstructions, generateTemplateContent, errors, editSecureNote, createVault, createSecureNote, checkSignedIn, checkOpCli, TemplateOptions, ParseResult, ErrorCodes, EnvVariable, EnvLine, Env2OpError, CreateItemResult, CreateItemOptions, ConvertOptions };
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// src/core/env-parser.ts
|
|
2
|
-
import {
|
|
2
|
+
import { readFile } from "node:fs/promises";
|
|
3
3
|
|
|
4
4
|
// src/utils/errors.ts
|
|
5
5
|
class Env2OpError extends Error {
|
|
@@ -22,6 +22,7 @@ var ErrorCodes = {
|
|
|
22
22
|
VAULT_CREATE_FAILED: "VAULT_CREATE_FAILED",
|
|
23
23
|
ITEM_EXISTS: "ITEM_EXISTS",
|
|
24
24
|
ITEM_CREATE_FAILED: "ITEM_CREATE_FAILED",
|
|
25
|
+
ITEM_EDIT_FAILED: "ITEM_EDIT_FAILED",
|
|
25
26
|
PARSE_ERROR: "PARSE_ERROR",
|
|
26
27
|
TEMPLATE_NOT_FOUND: "TEMPLATE_NOT_FOUND",
|
|
27
28
|
INJECT_FAILED: "INJECT_FAILED"
|
|
@@ -35,6 +36,7 @@ var errors = {
|
|
|
35
36
|
vaultCreateFailed: (message) => new Env2OpError(`Failed to create vault: ${message}`, ErrorCodes.VAULT_CREATE_FAILED),
|
|
36
37
|
itemExists: (title, vault) => new Env2OpError(`Item "${title}" already exists in vault "${vault}"`, ErrorCodes.ITEM_EXISTS, "Use default behavior (overwrites) or choose a different item name"),
|
|
37
38
|
itemCreateFailed: (message) => new Env2OpError(`Failed to create 1Password item: ${message}`, ErrorCodes.ITEM_CREATE_FAILED),
|
|
39
|
+
itemEditFailed: (message) => new Env2OpError(`Failed to edit 1Password item: ${message}`, ErrorCodes.ITEM_EDIT_FAILED),
|
|
38
40
|
parseError: (line, message) => new Env2OpError(`Parse error at line ${line}: ${message}`, ErrorCodes.PARSE_ERROR)
|
|
39
41
|
};
|
|
40
42
|
|
|
@@ -82,12 +84,20 @@ function parseValue(raw) {
|
|
|
82
84
|
const parts = trimmed.split(/\s+#/);
|
|
83
85
|
return (parts[0] ?? trimmed).trim();
|
|
84
86
|
}
|
|
85
|
-
function
|
|
86
|
-
if (
|
|
87
|
+
function stripBom(content) {
|
|
88
|
+
if (content.charCodeAt(0) === 65279) {
|
|
89
|
+
return content.slice(1);
|
|
90
|
+
}
|
|
91
|
+
return content;
|
|
92
|
+
}
|
|
93
|
+
async function parseEnvFile(filePath) {
|
|
94
|
+
let rawContent;
|
|
95
|
+
try {
|
|
96
|
+
rawContent = await readFile(filePath, "utf-8");
|
|
97
|
+
} catch {
|
|
87
98
|
throw errors.envFileNotFound(filePath);
|
|
88
99
|
}
|
|
89
|
-
const
|
|
90
|
-
const content = stripHeaders(rawContent);
|
|
100
|
+
const content = stripHeaders(stripBom(rawContent));
|
|
91
101
|
const rawLines = content.split(`
|
|
92
102
|
`);
|
|
93
103
|
const variables = [];
|
|
@@ -151,33 +161,34 @@ async function exec(command, args = [], options = {}) {
|
|
|
151
161
|
const proc = spawn(command, args, {
|
|
152
162
|
stdio: ["ignore", "pipe", "pipe"]
|
|
153
163
|
});
|
|
154
|
-
|
|
155
|
-
|
|
164
|
+
const stdoutChunks = [];
|
|
165
|
+
const stderrChunks = [];
|
|
156
166
|
proc.stdout?.on("data", (data) => {
|
|
157
|
-
const text = data.toString();
|
|
158
|
-
|
|
167
|
+
const text = Buffer.isBuffer(data) ? data.toString() : String(data);
|
|
168
|
+
stdoutChunks.push(text);
|
|
159
169
|
if (verbose) {
|
|
160
170
|
process.stdout.write(text);
|
|
161
171
|
}
|
|
162
172
|
});
|
|
163
173
|
proc.stderr?.on("data", (data) => {
|
|
164
|
-
const text = data.toString();
|
|
165
|
-
|
|
174
|
+
const text = Buffer.isBuffer(data) ? data.toString() : String(data);
|
|
175
|
+
stderrChunks.push(text);
|
|
166
176
|
if (verbose) {
|
|
167
177
|
process.stderr.write(text);
|
|
168
178
|
}
|
|
169
179
|
});
|
|
170
180
|
proc.on("close", (code) => {
|
|
171
181
|
resolve({
|
|
172
|
-
stdout,
|
|
173
|
-
stderr,
|
|
174
|
-
exitCode: code ??
|
|
182
|
+
stdout: stdoutChunks.join(""),
|
|
183
|
+
stderr: stderrChunks.join(""),
|
|
184
|
+
exitCode: code ?? 1
|
|
175
185
|
});
|
|
176
186
|
});
|
|
177
|
-
proc.on("error", () => {
|
|
187
|
+
proc.on("error", (err) => {
|
|
188
|
+
stderrChunks.push(err.message);
|
|
178
189
|
resolve({
|
|
179
|
-
stdout,
|
|
180
|
-
stderr,
|
|
190
|
+
stdout: stdoutChunks.join(""),
|
|
191
|
+
stderr: stderrChunks.join(""),
|
|
181
192
|
exitCode: 1
|
|
182
193
|
});
|
|
183
194
|
});
|
|
@@ -193,27 +204,36 @@ async function execWithStdin(command, args = [], options) {
|
|
|
193
204
|
const proc = spawn(command, args, {
|
|
194
205
|
stdio: ["pipe", "pipe", "pipe"]
|
|
195
206
|
});
|
|
196
|
-
|
|
197
|
-
|
|
207
|
+
const stdoutChunks = [];
|
|
208
|
+
const stderrChunks = [];
|
|
198
209
|
proc.stdin?.write(stdinContent);
|
|
199
210
|
proc.stdin?.end();
|
|
200
211
|
proc.stdout?.on("data", (data) => {
|
|
201
|
-
const text = data.toString();
|
|
202
|
-
|
|
212
|
+
const text = Buffer.isBuffer(data) ? data.toString() : String(data);
|
|
213
|
+
stdoutChunks.push(text);
|
|
203
214
|
if (verbose)
|
|
204
215
|
process.stdout.write(text);
|
|
205
216
|
});
|
|
206
217
|
proc.stderr?.on("data", (data) => {
|
|
207
|
-
const text = data.toString();
|
|
208
|
-
|
|
218
|
+
const text = Buffer.isBuffer(data) ? data.toString() : String(data);
|
|
219
|
+
stderrChunks.push(text);
|
|
209
220
|
if (verbose)
|
|
210
221
|
process.stderr.write(text);
|
|
211
222
|
});
|
|
212
223
|
proc.on("close", (code) => {
|
|
213
|
-
resolve({
|
|
224
|
+
resolve({
|
|
225
|
+
stdout: stdoutChunks.join(""),
|
|
226
|
+
stderr: stderrChunks.join(""),
|
|
227
|
+
exitCode: code ?? 1
|
|
228
|
+
});
|
|
214
229
|
});
|
|
215
|
-
proc.on("error", () => {
|
|
216
|
-
|
|
230
|
+
proc.on("error", (err) => {
|
|
231
|
+
stderrChunks.push(err.message);
|
|
232
|
+
resolve({
|
|
233
|
+
stdout: stdoutChunks.join(""),
|
|
234
|
+
stderr: stderrChunks.join(""),
|
|
235
|
+
exitCode: 1
|
|
236
|
+
});
|
|
217
237
|
});
|
|
218
238
|
});
|
|
219
239
|
}
|
|
@@ -333,7 +353,7 @@ async function editSecureNote(options) {
|
|
|
333
353
|
};
|
|
334
354
|
} catch (error) {
|
|
335
355
|
const message = error instanceof Error ? error.message : String(error);
|
|
336
|
-
throw errors.
|
|
356
|
+
throw errors.itemEditFailed(message);
|
|
337
357
|
}
|
|
338
358
|
}
|
|
339
359
|
// src/core/template-generator.ts
|
|
@@ -341,7 +361,7 @@ import { writeFileSync } from "node:fs";
|
|
|
341
361
|
// package.json
|
|
342
362
|
var package_default = {
|
|
343
363
|
name: "@tolgamorf/env2op-cli",
|
|
344
|
-
version: "0.2.
|
|
364
|
+
version: "0.2.2",
|
|
345
365
|
description: "Convert .env files to 1Password Secure Notes and generate templates for op inject/run",
|
|
346
366
|
type: "module",
|
|
347
367
|
main: "dist/index.js",
|