dotsec 4.0.0-alpha.4 → 4.0.0-alpha.41

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/index.js CHANGED
@@ -1,2 +1,211 @@
1
- var P=Object.create;var a=Object.defineProperty;var D=Object.getOwnPropertyDescriptor;var R=Object.getOwnPropertyNames;var h=Object.getPrototypeOf,C=Object.prototype.hasOwnProperty;var k=(e,r)=>{for(var o in r)a(e,o,{get:r[o],enumerable:!0})},l=(e,r,o,t)=>{if(r&&typeof r=="object"||typeof r=="function")for(let n of R(r))!C.call(e,n)&&n!==o&&a(e,n,{get:()=>r[n],enumerable:!(t=D(r,n))||t.enumerable});return e};var s=(e,r,o)=>(o=e!=null?P(h(e)):{},l(r||!e||!e.__esModule?a(o,"default",{value:e,enumerable:!0}):o,e)),L=e=>l(a({},"__esModule",{value:!0}),e);var V={};k(V,{Table:()=>p.default,emphasis:()=>b,promptExecute:()=>u,promptOverwriteIfFileExists:()=>v,readContentsFromFile:()=>d,resolveFromEnv:()=>g,strong:()=>F,writeContentsToFile:()=>E,writeLine:()=>y});module.exports=L(V);var m=s(require("prompts"));var u=async({skip:e,message:r,execute:o})=>{let t=!1;(e||(await(0,m.default)({type:"confirm",name:"confirm",message:r})).confirm===!0)&&(t=!0),t&&await o()};var f=require("dotenv-expand"),g=e=>{let{fromEnvValue:r,env:o,variables:t}=e;return r?(0,f.expand)({ignoreProcessEnv:!0,parsed:{...o,...t,RESOLVED:r||""}}).parsed?.RESOLVED:""};var i=s(require("fs/promises")),w=s(require("path")),x=s(require("prompts")),d=async e=>await i.default.readFile(e,"utf-8"),E=async(e,r)=>await i.default.writeFile(e,r,"utf-8"),O=async e=>{try{return await(0,i.stat)(e),!0}catch{return!1}},v=async({filePath:e,skip:r})=>{let o;return await O(e)&&r!==!0?o=await(0,x.default)({type:"confirm",name:"overwrite",message:()=>`Overwrite './${w.default.relative(process.cwd(),e)}' ?`}):o=void 0,o};var c=s(require("chalk")),p=s(require("cli-table"));var y=e=>{process.stdout.write(e)},b=e=>c.default.yellowBright(e),F=e=>c.default.yellow.bold(e);0&&(module.exports={Table,emphasis,promptExecute,promptOverwriteIfFileExists,readContentsFromFile,resolveFromEnv,strong,writeContentsToFile,writeLine});
1
+ 'use strict';
2
+
3
+ var prompts = require('prompts');
4
+ var dotenvExpand = require('dotenv-expand');
5
+ var fs = require('fs/promises');
6
+ var path = require('path');
7
+ var chalk = require('chalk');
8
+ var cliTable = require('cli-table');
9
+
10
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
11
+
12
+ var prompts__default = /*#__PURE__*/_interopDefault(prompts);
13
+ var fs__default = /*#__PURE__*/_interopDefault(fs);
14
+ var path__default = /*#__PURE__*/_interopDefault(path);
15
+ var chalk__default = /*#__PURE__*/_interopDefault(chalk);
16
+ var cliTable__default = /*#__PURE__*/_interopDefault(cliTable);
17
+
18
+ // src/lib/parse.ts
19
+ var LINE = /^(#.*)|(\s?\r?\n)|(?:^|^)\s*(?:export\s+)?([\w.-]*)(?:\s*=\s*?|:\s+?)(\s*'(?:\\'|[^'])*'|\s*"(?:\\"|[^"])*"|\s*`(?:\\`|[^`])*`|[^#\r\n]+)?(\s*)(#.*)?(?:$|$)/gm;
20
+ var parse = (src) => {
21
+ const obj = {};
22
+ const blocks = [];
23
+ let lines = src.toString();
24
+ lines = lines.replace(/\r\n?/gm, "\n");
25
+ let match;
26
+ while ((match = LINE.exec(lines)) != null) {
27
+ const key = match[3];
28
+ if (match?.[1]?.[0] === "#") {
29
+ blocks.push({ type: "comment", raw: match[1] });
30
+ } else if (match?.[2]) {
31
+ blocks.push({ type: "whitespace", raw: match[2] });
32
+ } else {
33
+ let value = match[4] || "";
34
+ value = value.trim();
35
+ const maybeQuote = value[0];
36
+ value = value.replace(/^(['"`])([\s\S]*)\1$/gm, "$2");
37
+ if (maybeQuote === '"') {
38
+ value = value.replace(/\\n/g, "\n");
39
+ value = value.replace(/\\r/g, "\r");
40
+ }
41
+ obj[key] = value;
42
+ blocks.push({
43
+ type: "value",
44
+ key,
45
+ value,
46
+ raw: value + (match[5] ? match[5] : "") + (match[6] ? match[6] : "")
47
+ });
48
+ }
49
+ }
50
+ return { blocks, obj };
51
+ };
52
+ if (undefined) {
53
+ const { it, expect } = undefined;
54
+ it("parse", () => {
55
+ const input1 = "KEY=value";
56
+ const input2 = 'KEY="value"';
57
+ const input3 = "KEY='value'";
58
+ const input4 = "KEY=value # this is a comment";
59
+ expect(parse(input1)).toMatchInlineSnapshot(`
60
+ {
61
+ "blocks": [
62
+ {
63
+ "key": "KEY",
64
+ "raw": "value",
65
+ "type": "value",
66
+ "value": "value",
67
+ },
68
+ ],
69
+ "obj": {
70
+ "KEY": "value",
71
+ },
72
+ }
73
+ `);
74
+ expect(parse(input2)).toMatchInlineSnapshot(`
75
+ {
76
+ "blocks": [
77
+ {
78
+ "key": "KEY",
79
+ "raw": "value",
80
+ "type": "value",
81
+ "value": "value",
82
+ },
83
+ ],
84
+ "obj": {
85
+ "KEY": "value",
86
+ },
87
+ }
88
+ `);
89
+ expect(parse(input3)).toMatchInlineSnapshot(`
90
+ {
91
+ "blocks": [
92
+ {
93
+ "key": "KEY",
94
+ "raw": "value",
95
+ "type": "value",
96
+ "value": "value",
97
+ },
98
+ ],
99
+ "obj": {
100
+ "KEY": "value",
101
+ },
102
+ }
103
+ `);
104
+ expect(parse(input4)).toMatchInlineSnapshot(`
105
+ {
106
+ "blocks": [
107
+ {
108
+ "key": "KEY",
109
+ "raw": "value# this is a comment",
110
+ "type": "value",
111
+ "value": "value",
112
+ },
113
+ ],
114
+ "obj": {
115
+ "KEY": "value",
116
+ },
117
+ }
118
+ `);
119
+ });
120
+ }
121
+ var promptExecute = async ({
122
+ skip,
123
+ message,
124
+ execute
125
+ }) => {
126
+ let shouldExecute = false;
127
+ if (skip) {
128
+ shouldExecute = true;
129
+ } else {
130
+ const promptResponse = await prompts__default.default({
131
+ type: "confirm",
132
+ name: "confirm",
133
+ message
134
+ });
135
+ if (promptResponse.confirm === true) {
136
+ shouldExecute = true;
137
+ }
138
+ }
139
+ if (shouldExecute) {
140
+ await execute();
141
+ }
142
+ };
143
+ var resolveFromEnv = (options) => {
144
+ const { fromEnvValue, env, variables } = options;
145
+ if (!fromEnvValue) {
146
+ return "";
147
+ }
148
+ return dotenvExpand.expand({
149
+ ignoreProcessEnv: true,
150
+ parsed: {
151
+ // add standard env variables
152
+ ...env,
153
+ // add custom env variables, either from .env or .sec, (or empty object if none)
154
+ ...variables,
155
+ RESOLVED: fromEnvValue || ""
156
+ }
157
+ }).parsed?.RESOLVED;
158
+ };
159
+ var readContentsFromFile = async (filePath) => {
160
+ return await fs__default.default.readFile(filePath, "utf-8");
161
+ };
162
+ var writeContentsToFile = async (filePath, contents) => {
163
+ return await fs__default.default.writeFile(filePath, contents, "utf-8");
164
+ };
165
+ var fileExists = async (source) => {
166
+ try {
167
+ await fs.stat(source);
168
+ return true;
169
+ } catch {
170
+ return false;
171
+ }
172
+ };
173
+ var promptOverwriteIfFileExists = async ({
174
+ filePath,
175
+ skip
176
+ }) => {
177
+ let overwriteResponse;
178
+ if (await fileExists(filePath) && skip !== true) {
179
+ overwriteResponse = await prompts__default.default({
180
+ type: "confirm",
181
+ name: "overwrite",
182
+ message: () => {
183
+ return `Overwrite './${path__default.default.relative(process.cwd(), filePath)}' ?`;
184
+ }
185
+ });
186
+ } else {
187
+ overwriteResponse = void 0;
188
+ }
189
+ return overwriteResponse;
190
+ };
191
+ var writeLine = (str) => {
192
+ process.stdout.write(str);
193
+ };
194
+ var emphasis = (str) => chalk__default.default.yellowBright(str);
195
+ var strong = (str) => chalk__default.default.yellow.bold(str);
196
+
197
+ Object.defineProperty(exports, 'Table', {
198
+ enumerable: true,
199
+ get: function () { return cliTable__default.default; }
200
+ });
201
+ exports.emphasis = emphasis;
202
+ exports.parse = parse;
203
+ exports.promptExecute = promptExecute;
204
+ exports.promptOverwriteIfFileExists = promptOverwriteIfFileExists;
205
+ exports.readContentsFromFile = readContentsFromFile;
206
+ exports.resolveFromEnv = resolveFromEnv;
207
+ exports.strong = strong;
208
+ exports.writeContentsToFile = writeContentsToFile;
209
+ exports.writeLine = writeLine;
210
+ //# sourceMappingURL=out.js.map
2
211
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/utils/prompts.ts","../src/utils/fromEnv.ts","../src/lib/io.ts","../src/utils/logging.ts"],"sourcesContent":["export type {\n\tDotsecEncryptionEngine,\n\tDotsecEncryptionEngineFactory,\n\tDotsecEncryptionEngineFactoryProps,\n\tFromEnv,\n\tDotsecPluginUserConfigWithNamespace,\n\tDotsecPluginModule,\n\tDotsecPluginModuleBuilder,\n\tMeh,\n\tDotsecPluginModuleBuilderConfig,\n\tDotsecConfig,\n} from \"./types\";\nexport { promptExecute } from \"./utils/prompts\";\nexport { resolveFromEnv } from \"./utils/fromEnv\";\nexport {\n\tpromptOverwriteIfFileExists,\n\treadContentsFromFile,\n\twriteContentsToFile,\n} from \"./lib/io\";\n// import dotsec from \"./dotsec\";\n// export default dotsec;\n\nexport { Table, emphasis, strong, writeLine } from \"./utils/logging\";\n","import prompts from \"prompts\";\n\nexport const promptConfirm = async ({\n\tpredicate,\n\tskip,\n\tmessage,\n}: {\n\tpredicate?: (...args: unknown[]) => Promise<boolean> | boolean;\n\tskip?: boolean;\n\tmessage: string;\n}): Promise<boolean> => {\n\tif (skip === true) {\n\t\treturn true;\n\t} else {\n\t\tconst result = predicate ? await predicate() : true;\n\t\tif (result) {\n\t\t\tconst confirmResult = await prompts({\n\t\t\t\ttype: \"confirm\",\n\t\t\t\tname: \"confirm\",\n\t\t\t\tmessage: () => {\n\t\t\t\t\treturn message;\n\t\t\t\t},\n\t\t\t});\n\n\t\t\tif (confirmResult.confirm === true) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\t}\n\treturn false;\n};\n\nexport const promptExecute = async ({\n\tskip,\n\tmessage,\n\texecute,\n}: {\n\tskip?: boolean;\n\tmessage: string;\n\texecute: () => unknown | Promise<unknown>;\n}) => {\n\tlet shouldExecute = false;\n\tif (skip) {\n\t\tshouldExecute = true;\n\t} else {\n\t\tconst promptResponse = await prompts({\n\t\t\ttype: \"confirm\",\n\t\t\tname: \"confirm\",\n\t\t\tmessage,\n\t\t});\n\n\t\tif (promptResponse.confirm === true) {\n\t\t\tshouldExecute = true;\n\t\t}\n\t}\n\n\tif (shouldExecute) {\n\t\tawait execute();\n\t}\n};\n","import { expand } from \"dotenv-expand\";\n\nexport const resolveFromEnv = (options: {\n\tfromEnvValue?: string;\n\tenv: NodeJS.ProcessEnv;\n\tvariables: Record<string, string>;\n}) => {\n\tconst { fromEnvValue, env, variables } = options;\n\n\tif (!fromEnvValue) {\n\t\treturn \"\";\n\t}\n\n\treturn (\n\t\texpand({\n\t\t\tignoreProcessEnv: true,\n\t\t\tparsed: {\n\t\t\t\t// add standard env variables\n\t\t\t\t...(env as Record<string, string>),\n\t\t\t\t// add custom env variables, either from .env or .sec, (or empty object if none)\n\t\t\t\t...variables,\n\t\t\t\tRESOLVED: fromEnvValue || \"\",\n\t\t\t},\n\t\t}) as { parsed?: { RESOLVED?: string } }\n\t).parsed?.RESOLVED;\n};\n","import fs, { stat } from \"node:fs/promises\";\nimport path from \"node:path\";\nimport prompts from \"prompts\";\n\nexport const readContentsFromFile = async (\n\tfilePath: string,\n): Promise<string> => {\n\treturn await fs.readFile(filePath, \"utf-8\");\n};\n\nexport const writeContentsToFile = async (\n\tfilePath: string,\n\tcontents: string,\n): Promise<void> => {\n\treturn await fs.writeFile(filePath, contents, \"utf-8\");\n};\n\nexport const fileExists = async (source: string): Promise<boolean> => {\n\ttry {\n\t\tawait stat(source);\n\t\treturn true;\n\t} catch {\n\t\treturn false;\n\t}\n};\n\nexport const promptOverwriteIfFileExists = async ({\n\tfilePath,\n\tskip,\n}: {\n\tfilePath: string;\n\tskip?: boolean;\n}) => {\n\tlet overwriteResponse: prompts.Answers<\"overwrite\"> | undefined;\n\n\tif ((await fileExists(filePath)) && skip !== true) {\n\t\toverwriteResponse = await prompts({\n\t\t\ttype: \"confirm\",\n\t\t\tname: \"overwrite\",\n\t\t\tmessage: () => {\n\t\t\t\treturn `Overwrite './${path.relative(process.cwd(), filePath)}' ?`;\n\t\t\t},\n\t\t});\n\t} else {\n\t\toverwriteResponse = undefined;\n\t}\n\treturn overwriteResponse;\n};\n","import chalk from \"chalk\";\nimport Table from \"cli-table\";\nexport { Table };\n\nlet _logger: Pick<Console, \"info\" | \"error\" | \"table\">;\nexport const getLogger = () => {\n\tif (!_logger) {\n\t\t_logger = console;\n\t}\n\n\treturn _logger;\n};\nexport const writeLine = (str: string) => {\n\tprocess.stdout.write(str);\n};\nexport const emphasis = (str: string): string => chalk.yellowBright(str);\nexport const strong = (str: string): string => chalk.yellow.bold(str);\n\nexport const clientLogger = {\n\tdebug(content: object) {\n\t\tconsole.log(content);\n\t},\n\tinfo(content: object) {\n\t\tconsole.log(content);\n\t},\n\twarn(content: object) {\n\t\tconsole.log(content);\n\t},\n\terror(content: object) {\n\t\tconsole.error(content);\n\t},\n};\n"],"mappings":"6iBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,aAAAE,QAAA,aAAAC,EAAA,kBAAAC,EAAA,gCAAAC,EAAA,yBAAAC,EAAA,mBAAAC,EAAA,WAAAC,EAAA,wBAAAC,EAAA,cAAAC,IAAA,eAAAC,EAAAX,GCAA,IAAAY,EAAoB,sBAgCb,IAAMC,EAAgB,MAAO,CACnC,KAAAC,EACA,QAAAC,EACA,QAAAC,CACD,IAIM,CACL,IAAIC,EAAgB,IAChBH,IAGoB,QAAM,EAAAI,SAAQ,CACpC,KAAM,UACN,KAAM,UACN,QAAAH,CACD,CAAC,GAEkB,UAAY,MAC9BE,EAAgB,IAIdA,GACH,MAAMD,EAAQ,CAEhB,EC3DA,IAAAG,EAAuB,yBAEVC,EAAkBC,GAIzB,CACL,GAAM,CAAE,aAAAC,EAAc,IAAAC,EAAK,UAAAC,CAAU,EAAIH,EAEzC,OAAKC,KAKJ,UAAO,CACN,iBAAkB,GAClB,OAAQ,CAEP,GAAIC,EAEJ,GAAGC,EACH,SAAUF,GAAgB,EAC3B,CACD,CAAC,EACA,QAAQ,SAdF,EAeT,ECzBA,IAAAG,EAAyB,0BACzBC,EAAiB,mBACjBC,EAAoB,sBAEPC,EAAuB,MACnCC,GAEO,MAAM,EAAAC,QAAG,SAASD,EAAU,OAAO,EAG9BE,EAAsB,MAClCF,EACAG,IAEO,MAAM,EAAAF,QAAG,UAAUD,EAAUG,EAAU,OAAO,EAGzCC,EAAa,MAAOC,GAAqC,CACrE,GAAI,CACH,eAAM,QAAKA,CAAM,EACV,EACR,MAAE,CACD,MAAO,EACR,CACD,EAEaC,EAA8B,MAAO,CACjD,SAAAN,EACA,KAAAO,CACD,IAGM,CACL,IAAIC,EAEJ,OAAK,MAAMJ,EAAWJ,CAAQ,GAAMO,IAAS,GAC5CC,EAAoB,QAAM,EAAAC,SAAQ,CACjC,KAAM,UACN,KAAM,YACN,QAAS,IACD,gBAAgB,EAAAC,QAAK,SAAS,QAAQ,IAAI,EAAGV,CAAQ,MAE9D,CAAC,EAEDQ,EAAoB,OAEdA,CACR,EC/CA,IAAAG,EAAkB,oBAClBC,EAAkB,wBAWX,IAAMC,EAAaC,GAAgB,CACzC,QAAQ,OAAO,MAAMA,CAAG,CACzB,EACaC,EAAYD,GAAwB,EAAAE,QAAM,aAAaF,CAAG,EAC1DG,EAAUH,GAAwB,EAAAE,QAAM,OAAO,KAAKF,CAAG","names":["src_exports","__export","Table","emphasis","promptExecute","promptOverwriteIfFileExists","readContentsFromFile","resolveFromEnv","strong","writeContentsToFile","writeLine","__toCommonJS","import_prompts","promptExecute","skip","message","execute","shouldExecute","prompts","import_dotenv_expand","resolveFromEnv","options","fromEnvValue","env","variables","import_promises","import_node_path","import_prompts","readContentsFromFile","filePath","fs","writeContentsToFile","contents","fileExists","source","promptOverwriteIfFileExists","skip","overwriteResponse","prompts","path","import_chalk","import_cli_table","writeLine","str","emphasis","chalk","strong"]}
1
+ {"version":3,"sources":["../src/lib/parse.ts","../src/utils/prompts.ts","../src/utils/fromEnv.ts","../src/lib/io.ts","../src/utils/logging.ts"],"names":["prompts"],"mappings":";AAAA,IAAM,OACL;AAUM,IAAM,QAAQ,CAAC,QAAgB;AACrC,QAAM,MAA8B,CAAC;AACrC,QAAM,SAAsB,CAAC;AAG7B,MAAI,QAAQ,IAAI,SAAS;AAGzB,UAAQ,MAAM,QAAQ,WAAW,IAAI;AAErC,MAAI;AACJ,UAAQ,QAAQ,KAAK,KAAK,KAAK,MAAM,MAAM;AAC1C,UAAM,MAAM,MAAM,CAAC;AAEnB,QAAI,QAAQ,CAAC,IAAI,CAAC,MAAM,KAAK;AAC5B,aAAO,KAAK,EAAE,MAAM,WAAW,KAAK,MAAM,CAAC,EAAE,CAAC;AAAA,IAC/C,WAAW,QAAQ,CAAC,GAAG;AACtB,aAAO,KAAK,EAAE,MAAM,cAAc,KAAK,MAAM,CAAC,EAAE,CAAC;AAAA,IAClD,OAAO;AAEN,UAAI,QAAQ,MAAM,CAAC,KAAK;AAGxB,cAAQ,MAAM,KAAK;AAGnB,YAAM,aAAa,MAAM,CAAC;AAG1B,cAAQ,MAAM,QAAQ,0BAA0B,IAAI;AAGpD,UAAI,eAAe,KAAK;AACvB,gBAAQ,MAAM,QAAQ,QAAQ,IAAI;AAClC,gBAAQ,MAAM,QAAQ,QAAQ,IAAI;AAAA,MACnC;AAEA,UAAI,GAAG,IAAI;AAGX,aAAO,KAAK;AAAA,QACX,MAAM;AAAA,QACN;AAAA,QACA;AAAA,QACA,KAAK,SAAS,MAAM,CAAC,IAAI,MAAM,CAAC,IAAI,OAAO,MAAM,CAAC,IAAI,MAAM,CAAC,IAAI;AAAA,MAClE,CAAC;AAAA,IACF;AAAA,EACD;AAEA,SAAO,EAAE,QAAQ,IAAI;AACtB;AAEA,IAAI,YAAY,QAAQ;AAC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?:\\\\\"|[^\"])*\"|\\s*`(?:\\\\`|[^`])*`|[^#\\r\\n]+)?(\\s*)(#.*)?(?:$|$)/gm;\n\nexport type ParseResult = {\n\ttype: \"value\" | \"comment\" | \"whitespace\";\n\tkey?: string;\n\tvalue?: string;\n\traw?: string;\n}[];\n\n// Parser src into an Object\nexport const parse = (src: string) => {\n\tconst obj: Record<string, string> = {};\n\tconst blocks: ParseResult = [];\n\n\t// Convert buffer to string\n\tlet lines = src.toString();\n\n\t// Convert line breaks to same format\n\tlines = lines.replace(/\\r\\n?/gm, \"\\n\");\n\n\tlet match;\n\twhile ((match = LINE.exec(lines)) != null) {\n\t\tconst key = match[3];\n\n\t\tif (match?.[1]?.[0] === \"#\") {\n\t\t\tblocks.push({ type: \"comment\", raw: match[1] });\n\t\t} else if (match?.[2]) {\n\t\t\tblocks.push({ type: \"whitespace\", raw: match[2] });\n\t\t} else {\n\t\t\t// Default undefined or null to empty string\n\t\t\tlet value = match[4] || \"\";\n\n\t\t\t// Remove whitespace\n\t\t\tvalue = value.trim();\n\n\t\t\t// Check if double quoted\n\t\t\tconst maybeQuote = value[0];\n\n\t\t\t// Remove surrounding quotes\n\t\t\tvalue = value.replace(/^(['\"`])([\\s\\S]*)\\1$/gm, \"$2\");\n\n\t\t\t// Expand newlines if double quoted\n\t\t\tif (maybeQuote === '\"') {\n\t\t\t\tvalue = value.replace(/\\\\n/g, \"\\n\");\n\t\t\t\tvalue = value.replace(/\\\\r/g, \"\\r\");\n\t\t\t}\n\n\t\t\tobj[key] = value;\n\n\t\t\t// Add to object\n\t\t\tblocks.push({\n\t\t\t\ttype: \"value\",\n\t\t\t\tkey,\n\t\t\t\tvalue,\n\t\t\t\traw: value + (match[5] ? match[5] : \"\") + (match[6] ? match[6] : \"\"),\n\t\t\t});\n\t\t}\n\t}\n\n\treturn { blocks, obj };\n};\n\nif (import.meta.vitest) {\n\tconst { it, expect } = import.meta.vitest;\n\n\tit(\"parse\", () => {\n\t\tconst input1 = \"KEY=value\";\n\t\tconst input2 = 'KEY=\"value\"';\n\t\tconst input3 = \"KEY='value'\";\n\t\tconst input4 = \"KEY=value # this is a comment\";\n\n\t\t// const expectedResult1 = [\n\t\t// { type: 'value', key: 'KEY', value: 'value', raw: 'value' },\n\t\t// ];\n\t\t// const expectedResult2 = [\n\t\t// { type: 'value', key: 'KEY', value: 'value', raw: '\"value\"' },\n\t\t// ];\n\t\t// const expectedResult3 = [\n\t\t// { type: 'value', key: 'KEY', value: 'value', raw: \"'value'\" },\n\t\t// ];\n\t\t// const expectedResult4 = [\n\t\t// {\n\t\t// type: 'value',\n\t\t// key: 'KEY',\n\t\t// value: 'value',\n\t\t// raw: 'value # this is a comment',\n\t\t// },\n\t\t// ];\n\n\t\texpect(parse(input1)).toMatchInlineSnapshot(`\n\t\t\t{\n\t\t\t \"blocks\": [\n\t\t\t {\n\t\t\t \"key\": \"KEY\",\n\t\t\t \"raw\": \"value\",\n\t\t\t \"type\": \"value\",\n\t\t\t \"value\": \"value\",\n\t\t\t },\n\t\t\t ],\n\t\t\t \"obj\": {\n\t\t\t \"KEY\": \"value\",\n\t\t\t },\n\t\t\t}\n\t\t`);\n\t\texpect(parse(input2)).toMatchInlineSnapshot(`\n\t\t\t{\n\t\t\t \"blocks\": [\n\t\t\t {\n\t\t\t \"key\": \"KEY\",\n\t\t\t \"raw\": \"value\",\n\t\t\t \"type\": \"value\",\n\t\t\t \"value\": \"value\",\n\t\t\t },\n\t\t\t ],\n\t\t\t \"obj\": {\n\t\t\t \"KEY\": \"value\",\n\t\t\t },\n\t\t\t}\n\t\t`);\n\t\texpect(parse(input3)).toMatchInlineSnapshot(`\n\t\t\t{\n\t\t\t \"blocks\": [\n\t\t\t {\n\t\t\t \"key\": \"KEY\",\n\t\t\t \"raw\": \"value\",\n\t\t\t \"type\": \"value\",\n\t\t\t \"value\": \"value\",\n\t\t\t },\n\t\t\t ],\n\t\t\t \"obj\": {\n\t\t\t \"KEY\": \"value\",\n\t\t\t },\n\t\t\t}\n\t\t`);\n\t\texpect(parse(input4)).toMatchInlineSnapshot(`\n {\n \"blocks\": [\n {\n \"key\": \"KEY\",\n \"raw\": \"value# this is a comment\",\n \"type\": \"value\",\n \"value\": \"value\",\n },\n ],\n \"obj\": {\n \"KEY\": \"value\",\n },\n }\n `);\n\t});\n}\n","import prompts from \"prompts\";\n\nexport const promptConfirm = async ({\n\tpredicate,\n\tskip,\n\tmessage,\n}: {\n\tpredicate?: (...args: unknown[]) => Promise<boolean> | boolean;\n\tskip?: boolean;\n\tmessage: string;\n}): Promise<boolean> => {\n\tif (skip === true) {\n\t\treturn true;\n\t} else {\n\t\tconst result = predicate ? await predicate() : true;\n\t\tif (result) {\n\t\t\tconst confirmResult = await prompts({\n\t\t\t\ttype: \"confirm\",\n\t\t\t\tname: \"confirm\",\n\t\t\t\tmessage: () => {\n\t\t\t\t\treturn message;\n\t\t\t\t},\n\t\t\t});\n\n\t\t\tif (confirmResult.confirm === true) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\t}\n\treturn false;\n};\n\nexport const promptExecute = async ({\n\tskip,\n\tmessage,\n\texecute,\n}: {\n\tskip?: boolean;\n\tmessage: string;\n\texecute: () => unknown | Promise<unknown>;\n}) => {\n\tlet shouldExecute = false;\n\tif (skip) {\n\t\tshouldExecute = true;\n\t} else {\n\t\tconst promptResponse = await prompts({\n\t\t\ttype: \"confirm\",\n\t\t\tname: \"confirm\",\n\t\t\tmessage,\n\t\t});\n\n\t\tif (promptResponse.confirm === true) {\n\t\t\tshouldExecute = true;\n\t\t}\n\t}\n\n\tif (shouldExecute) {\n\t\tawait execute();\n\t}\n};\n","import { expand } from \"dotenv-expand\";\n\nexport const resolveFromEnv = (options: {\n\tfromEnvValue?: string;\n\tenv: NodeJS.ProcessEnv;\n\tvariables: Record<string, string>;\n}) => {\n\tconst { fromEnvValue, env, variables } = options;\n\n\tif (!fromEnvValue) {\n\t\treturn \"\";\n\t}\n\n\treturn (\n\t\texpand({\n\t\t\tignoreProcessEnv: true,\n\t\t\tparsed: {\n\t\t\t\t// add standard env variables\n\t\t\t\t...(env as Record<string, string>),\n\t\t\t\t// add custom env variables, either from .env or .sec, (or empty object if none)\n\t\t\t\t...variables,\n\t\t\t\tRESOLVED: fromEnvValue || \"\",\n\t\t\t},\n\t\t}) as { parsed?: { RESOLVED?: string } }\n\t).parsed?.RESOLVED;\n};\n","import fs, { stat } from \"node:fs/promises\";\nimport path from \"node:path\";\nimport prompts from \"prompts\";\n\nexport const readContentsFromFile = async (\n\tfilePath: string,\n): Promise<string> => {\n\treturn await fs.readFile(filePath, \"utf-8\");\n};\n\nexport const writeContentsToFile = async (\n\tfilePath: string,\n\tcontents: string,\n): Promise<void> => {\n\treturn await fs.writeFile(filePath, contents, \"utf-8\");\n};\n\nexport const fileExists = async (source: string): Promise<boolean> => {\n\ttry {\n\t\tawait stat(source);\n\t\treturn true;\n\t} catch {\n\t\treturn false;\n\t}\n};\n\nexport const promptOverwriteIfFileExists = async ({\n\tfilePath,\n\tskip,\n}: {\n\tfilePath: string;\n\tskip?: boolean;\n}) => {\n\tlet overwriteResponse: prompts.Answers<\"overwrite\"> | undefined;\n\n\tif ((await fileExists(filePath)) && skip !== true) {\n\t\toverwriteResponse = await prompts({\n\t\t\ttype: \"confirm\",\n\t\t\tname: \"overwrite\",\n\t\t\tmessage: () => {\n\t\t\t\treturn `Overwrite './${path.relative(process.cwd(), filePath)}' ?`;\n\t\t\t},\n\t\t});\n\t} else {\n\t\toverwriteResponse = undefined;\n\t}\n\treturn overwriteResponse;\n};\n","import chalk from \"chalk\";\nimport Table from \"cli-table\";\nexport { Table };\n\nlet _logger: Pick<Console, \"info\" | \"error\" | \"table\">;\nexport const getLogger = () => {\n\tif (!_logger) {\n\t\t_logger = console;\n\t}\n\n\treturn _logger;\n};\nexport const writeLine = (str: string) => {\n\tprocess.stdout.write(str);\n};\nexport const emphasis = (str: string): string => chalk.yellowBright(str);\nexport const strong = (str: string): string => chalk.yellow.bold(str);\n\nexport const clientLogger = {\n\tdebug(content: object) {\n\t\tconsole.log(content);\n\t},\n\tinfo(content: object) {\n\t\tconsole.log(content);\n\t},\n\twarn(content: object) {\n\t\tconsole.log(content);\n\t},\n\terror(content: object) {\n\t\tconsole.error(content);\n\t},\n};\n"]}
package/dist/index.mjs CHANGED
@@ -1,2 +1,189 @@
1
- import i from"prompts";var a=async({skip:e,message:r,execute:o})=>{let t=!1;(e||(await i({type:"confirm",name:"confirm",message:r})).confirm===!0)&&(t=!0),t&&await o()};import{expand as c}from"dotenv-expand";var p=e=>{let{fromEnvValue:r,env:o,variables:t}=e;return r?c({ignoreProcessEnv:!0,parsed:{...o,...t,RESOLVED:r||""}}).parsed?.RESOLVED:""};import n,{stat as l}from"node:fs/promises";import m from"node:path";import u from"prompts";var f=async e=>await n.readFile(e,"utf-8"),g=async(e,r)=>await n.writeFile(e,r,"utf-8"),w=async e=>{try{return await l(e),!0}catch{return!1}},x=async({filePath:e,skip:r})=>{let o;return await w(e)&&r!==!0?o=await u({type:"confirm",name:"overwrite",message:()=>`Overwrite './${m.relative(process.cwd(),e)}' ?`}):o=void 0,o};import s from"chalk";import d from"cli-table";var E=e=>{process.stdout.write(e)},v=e=>s.yellowBright(e),y=e=>s.yellow.bold(e);export{d as Table,v as emphasis,a as promptExecute,x as promptOverwriteIfFileExists,f as readContentsFromFile,p as resolveFromEnv,y as strong,g as writeContentsToFile,E as writeLine};
1
+ import prompts from 'prompts';
2
+ import { expand } from 'dotenv-expand';
3
+ import fs, { stat } from 'node:fs/promises';
4
+ import path from 'node:path';
5
+ import chalk from 'chalk';
6
+ export { default as Table } from 'cli-table';
7
+
8
+ // src/lib/parse.ts
9
+ var LINE = /^(#.*)|(\s?\r?\n)|(?:^|^)\s*(?:export\s+)?([\w.-]*)(?:\s*=\s*?|:\s+?)(\s*'(?:\\'|[^'])*'|\s*"(?:\\"|[^"])*"|\s*`(?:\\`|[^`])*`|[^#\r\n]+)?(\s*)(#.*)?(?:$|$)/gm;
10
+ var parse = (src) => {
11
+ const obj = {};
12
+ const blocks = [];
13
+ let lines = src.toString();
14
+ lines = lines.replace(/\r\n?/gm, "\n");
15
+ let match;
16
+ while ((match = LINE.exec(lines)) != null) {
17
+ const key = match[3];
18
+ if (match?.[1]?.[0] === "#") {
19
+ blocks.push({ type: "comment", raw: match[1] });
20
+ } else if (match?.[2]) {
21
+ blocks.push({ type: "whitespace", raw: match[2] });
22
+ } else {
23
+ let value = match[4] || "";
24
+ value = value.trim();
25
+ const maybeQuote = value[0];
26
+ value = value.replace(/^(['"`])([\s\S]*)\1$/gm, "$2");
27
+ if (maybeQuote === '"') {
28
+ value = value.replace(/\\n/g, "\n");
29
+ value = value.replace(/\\r/g, "\r");
30
+ }
31
+ obj[key] = value;
32
+ blocks.push({
33
+ type: "value",
34
+ key,
35
+ value,
36
+ raw: value + (match[5] ? match[5] : "") + (match[6] ? match[6] : "")
37
+ });
38
+ }
39
+ }
40
+ return { blocks, obj };
41
+ };
42
+ if (import.meta.vitest) {
43
+ const { it, expect } = import.meta.vitest;
44
+ it("parse", () => {
45
+ const input1 = "KEY=value";
46
+ const input2 = 'KEY="value"';
47
+ const input3 = "KEY='value'";
48
+ const input4 = "KEY=value # this is a comment";
49
+ expect(parse(input1)).toMatchInlineSnapshot(`
50
+ {
51
+ "blocks": [
52
+ {
53
+ "key": "KEY",
54
+ "raw": "value",
55
+ "type": "value",
56
+ "value": "value",
57
+ },
58
+ ],
59
+ "obj": {
60
+ "KEY": "value",
61
+ },
62
+ }
63
+ `);
64
+ expect(parse(input2)).toMatchInlineSnapshot(`
65
+ {
66
+ "blocks": [
67
+ {
68
+ "key": "KEY",
69
+ "raw": "value",
70
+ "type": "value",
71
+ "value": "value",
72
+ },
73
+ ],
74
+ "obj": {
75
+ "KEY": "value",
76
+ },
77
+ }
78
+ `);
79
+ expect(parse(input3)).toMatchInlineSnapshot(`
80
+ {
81
+ "blocks": [
82
+ {
83
+ "key": "KEY",
84
+ "raw": "value",
85
+ "type": "value",
86
+ "value": "value",
87
+ },
88
+ ],
89
+ "obj": {
90
+ "KEY": "value",
91
+ },
92
+ }
93
+ `);
94
+ expect(parse(input4)).toMatchInlineSnapshot(`
95
+ {
96
+ "blocks": [
97
+ {
98
+ "key": "KEY",
99
+ "raw": "value# this is a comment",
100
+ "type": "value",
101
+ "value": "value",
102
+ },
103
+ ],
104
+ "obj": {
105
+ "KEY": "value",
106
+ },
107
+ }
108
+ `);
109
+ });
110
+ }
111
+ var promptExecute = async ({
112
+ skip,
113
+ message,
114
+ execute
115
+ }) => {
116
+ let shouldExecute = false;
117
+ if (skip) {
118
+ shouldExecute = true;
119
+ } else {
120
+ const promptResponse = await prompts({
121
+ type: "confirm",
122
+ name: "confirm",
123
+ message
124
+ });
125
+ if (promptResponse.confirm === true) {
126
+ shouldExecute = true;
127
+ }
128
+ }
129
+ if (shouldExecute) {
130
+ await execute();
131
+ }
132
+ };
133
+ var resolveFromEnv = (options) => {
134
+ const { fromEnvValue, env, variables } = options;
135
+ if (!fromEnvValue) {
136
+ return "";
137
+ }
138
+ return expand({
139
+ ignoreProcessEnv: true,
140
+ parsed: {
141
+ // add standard env variables
142
+ ...env,
143
+ // add custom env variables, either from .env or .sec, (or empty object if none)
144
+ ...variables,
145
+ RESOLVED: fromEnvValue || ""
146
+ }
147
+ }).parsed?.RESOLVED;
148
+ };
149
+ var readContentsFromFile = async (filePath) => {
150
+ return await fs.readFile(filePath, "utf-8");
151
+ };
152
+ var writeContentsToFile = async (filePath, contents) => {
153
+ return await fs.writeFile(filePath, contents, "utf-8");
154
+ };
155
+ var fileExists = async (source) => {
156
+ try {
157
+ await stat(source);
158
+ return true;
159
+ } catch {
160
+ return false;
161
+ }
162
+ };
163
+ var promptOverwriteIfFileExists = async ({
164
+ filePath,
165
+ skip
166
+ }) => {
167
+ let overwriteResponse;
168
+ if (await fileExists(filePath) && skip !== true) {
169
+ overwriteResponse = await prompts({
170
+ type: "confirm",
171
+ name: "overwrite",
172
+ message: () => {
173
+ return `Overwrite './${path.relative(process.cwd(), filePath)}' ?`;
174
+ }
175
+ });
176
+ } else {
177
+ overwriteResponse = void 0;
178
+ }
179
+ return overwriteResponse;
180
+ };
181
+ var writeLine = (str) => {
182
+ process.stdout.write(str);
183
+ };
184
+ var emphasis = (str) => chalk.yellowBright(str);
185
+ var strong = (str) => chalk.yellow.bold(str);
186
+
187
+ export { emphasis, parse, promptExecute, promptOverwriteIfFileExists, readContentsFromFile, resolveFromEnv, strong, writeContentsToFile, writeLine };
188
+ //# sourceMappingURL=out.js.map
2
189
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/utils/prompts.ts","../src/utils/fromEnv.ts","../src/lib/io.ts","../src/utils/logging.ts"],"sourcesContent":["import prompts from \"prompts\";\n\nexport const promptConfirm = async ({\n\tpredicate,\n\tskip,\n\tmessage,\n}: {\n\tpredicate?: (...args: unknown[]) => Promise<boolean> | boolean;\n\tskip?: boolean;\n\tmessage: string;\n}): Promise<boolean> => {\n\tif (skip === true) {\n\t\treturn true;\n\t} else {\n\t\tconst result = predicate ? await predicate() : true;\n\t\tif (result) {\n\t\t\tconst confirmResult = await prompts({\n\t\t\t\ttype: \"confirm\",\n\t\t\t\tname: \"confirm\",\n\t\t\t\tmessage: () => {\n\t\t\t\t\treturn message;\n\t\t\t\t},\n\t\t\t});\n\n\t\t\tif (confirmResult.confirm === true) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\t}\n\treturn false;\n};\n\nexport const promptExecute = async ({\n\tskip,\n\tmessage,\n\texecute,\n}: {\n\tskip?: boolean;\n\tmessage: string;\n\texecute: () => unknown | Promise<unknown>;\n}) => {\n\tlet shouldExecute = false;\n\tif (skip) {\n\t\tshouldExecute = true;\n\t} else {\n\t\tconst promptResponse = await prompts({\n\t\t\ttype: \"confirm\",\n\t\t\tname: \"confirm\",\n\t\t\tmessage,\n\t\t});\n\n\t\tif (promptResponse.confirm === true) {\n\t\t\tshouldExecute = true;\n\t\t}\n\t}\n\n\tif (shouldExecute) {\n\t\tawait execute();\n\t}\n};\n","import { expand } from \"dotenv-expand\";\n\nexport const resolveFromEnv = (options: {\n\tfromEnvValue?: string;\n\tenv: NodeJS.ProcessEnv;\n\tvariables: Record<string, string>;\n}) => {\n\tconst { fromEnvValue, env, variables } = options;\n\n\tif (!fromEnvValue) {\n\t\treturn \"\";\n\t}\n\n\treturn (\n\t\texpand({\n\t\t\tignoreProcessEnv: true,\n\t\t\tparsed: {\n\t\t\t\t// add standard env variables\n\t\t\t\t...(env as Record<string, string>),\n\t\t\t\t// add custom env variables, either from .env or .sec, (or empty object if none)\n\t\t\t\t...variables,\n\t\t\t\tRESOLVED: fromEnvValue || \"\",\n\t\t\t},\n\t\t}) as { parsed?: { RESOLVED?: string } }\n\t).parsed?.RESOLVED;\n};\n","import fs, { stat } from \"node:fs/promises\";\nimport path from \"node:path\";\nimport prompts from \"prompts\";\n\nexport const readContentsFromFile = async (\n\tfilePath: string,\n): Promise<string> => {\n\treturn await fs.readFile(filePath, \"utf-8\");\n};\n\nexport const writeContentsToFile = async (\n\tfilePath: string,\n\tcontents: string,\n): Promise<void> => {\n\treturn await fs.writeFile(filePath, contents, \"utf-8\");\n};\n\nexport const fileExists = async (source: string): Promise<boolean> => {\n\ttry {\n\t\tawait stat(source);\n\t\treturn true;\n\t} catch {\n\t\treturn false;\n\t}\n};\n\nexport const promptOverwriteIfFileExists = async ({\n\tfilePath,\n\tskip,\n}: {\n\tfilePath: string;\n\tskip?: boolean;\n}) => {\n\tlet overwriteResponse: prompts.Answers<\"overwrite\"> | undefined;\n\n\tif ((await fileExists(filePath)) && skip !== true) {\n\t\toverwriteResponse = await prompts({\n\t\t\ttype: \"confirm\",\n\t\t\tname: \"overwrite\",\n\t\t\tmessage: () => {\n\t\t\t\treturn `Overwrite './${path.relative(process.cwd(), filePath)}' ?`;\n\t\t\t},\n\t\t});\n\t} else {\n\t\toverwriteResponse = undefined;\n\t}\n\treturn overwriteResponse;\n};\n","import chalk from \"chalk\";\nimport Table from \"cli-table\";\nexport { Table };\n\nlet _logger: Pick<Console, \"info\" | \"error\" | \"table\">;\nexport const getLogger = () => {\n\tif (!_logger) {\n\t\t_logger = console;\n\t}\n\n\treturn _logger;\n};\nexport const writeLine = (str: string) => {\n\tprocess.stdout.write(str);\n};\nexport const emphasis = (str: string): string => chalk.yellowBright(str);\nexport const strong = (str: string): string => chalk.yellow.bold(str);\n\nexport const clientLogger = {\n\tdebug(content: object) {\n\t\tconsole.log(content);\n\t},\n\tinfo(content: object) {\n\t\tconsole.log(content);\n\t},\n\twarn(content: object) {\n\t\tconsole.log(content);\n\t},\n\terror(content: object) {\n\t\tconsole.error(content);\n\t},\n};\n"],"mappings":"AAAA,OAAOA,MAAa,UAgCb,IAAMC,EAAgB,MAAO,CACnC,KAAAC,EACA,QAAAC,EACA,QAAAC,CACD,IAIM,CACL,IAAIC,EAAgB,IAChBH,IAGoB,MAAMI,EAAQ,CACpC,KAAM,UACN,KAAM,UACN,QAAAH,CACD,CAAC,GAEkB,UAAY,MAC9BE,EAAgB,IAIdA,GACH,MAAMD,EAAQ,CAEhB,EC3DA,OAAS,UAAAG,MAAc,gBAEhB,IAAMC,EAAkBC,GAIzB,CACL,GAAM,CAAE,aAAAC,EAAc,IAAAC,EAAK,UAAAC,CAAU,EAAIH,EAEzC,OAAKC,EAKJH,EAAO,CACN,iBAAkB,GAClB,OAAQ,CAEP,GAAII,EAEJ,GAAGC,EACH,SAAUF,GAAgB,EAC3B,CACD,CAAC,EACA,QAAQ,SAdF,EAeT,ECzBA,OAAOG,GAAM,QAAAC,MAAY,mBACzB,OAAOC,MAAU,YACjB,OAAOC,MAAa,UAEb,IAAMC,EAAuB,MACnCC,GAEO,MAAML,EAAG,SAASK,EAAU,OAAO,EAG9BC,EAAsB,MAClCD,EACAE,IAEO,MAAMP,EAAG,UAAUK,EAAUE,EAAU,OAAO,EAGzCC,EAAa,MAAOC,GAAqC,CACrE,GAAI,CACH,aAAMR,EAAKQ,CAAM,EACV,EACR,MAAE,CACD,MAAO,EACR,CACD,EAEaC,EAA8B,MAAO,CACjD,SAAAL,EACA,KAAAM,CACD,IAGM,CACL,IAAIC,EAEJ,OAAK,MAAMJ,EAAWH,CAAQ,GAAMM,IAAS,GAC5CC,EAAoB,MAAMT,EAAQ,CACjC,KAAM,UACN,KAAM,YACN,QAAS,IACD,gBAAgBD,EAAK,SAAS,QAAQ,IAAI,EAAGG,CAAQ,MAE9D,CAAC,EAEDO,EAAoB,OAEdA,CACR,EC/CA,OAAOC,MAAW,QAClB,OAAOC,MAAW,YAWX,IAAMC,EAAaC,GAAgB,CACzC,QAAQ,OAAO,MAAMA,CAAG,CACzB,EACaC,EAAYD,GAAwBE,EAAM,aAAaF,CAAG,EAC1DG,EAAUH,GAAwBE,EAAM,OAAO,KAAKF,CAAG","names":["prompts","promptExecute","skip","message","execute","shouldExecute","prompts","expand","resolveFromEnv","options","fromEnvValue","env","variables","fs","stat","path","prompts","readContentsFromFile","filePath","writeContentsToFile","contents","fileExists","source","promptOverwriteIfFileExists","skip","overwriteResponse","chalk","Table","writeLine","str","emphasis","chalk","strong"]}
1
+ {"version":3,"sources":["../src/lib/parse.ts","../src/utils/prompts.ts","../src/utils/fromEnv.ts","../src/lib/io.ts","../src/utils/logging.ts"],"names":["prompts"],"mappings":";AAAA,IAAM,OACL;AAUM,IAAM,QAAQ,CAAC,QAAgB;AACrC,QAAM,MAA8B,CAAC;AACrC,QAAM,SAAsB,CAAC;AAG7B,MAAI,QAAQ,IAAI,SAAS;AAGzB,UAAQ,MAAM,QAAQ,WAAW,IAAI;AAErC,MAAI;AACJ,UAAQ,QAAQ,KAAK,KAAK,KAAK,MAAM,MAAM;AAC1C,UAAM,MAAM,MAAM,CAAC;AAEnB,QAAI,QAAQ,CAAC,IAAI,CAAC,MAAM,KAAK;AAC5B,aAAO,KAAK,EAAE,MAAM,WAAW,KAAK,MAAM,CAAC,EAAE,CAAC;AAAA,IAC/C,WAAW,QAAQ,CAAC,GA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MAAK,MAAM,WAAW,QAAQ,KAAM,SAAS,MAAM;AAClD,wBAAoB,MAAMA,SAAQ;AAAA,MACjC,MAAM;AAAA,MACN,MAAM;AAAA,MACN,SAAS,MAAM;AACd,eAAO,gBAAgB,KAAK,SAAS,QAAQ,IAAI,GAAG,QAAQ;AAAA,MAC7D;AAAA,IACD,CAAC;AAAA,EACF,OAAO;AACN,wBAAoB;AAAA,EACrB;AACA,SAAO;AACR;;;AC/CA,OAAO,WAAW;AAClB,OAAO,WAAW;AAWX,IAAM,YAAY,CAAC,QAAgB;AACzC,UAAQ,OAAO,MAAM,GAAG;AACzB;AACO,IAAM,WAAW,CAAC,QAAwB,MAAM,aAAa,GAAG;AAChE,IAAM,SAAS,CAAC,QAAwB,MAAM,OAAO,KAAK,GAAG","sourcesContent":["const LINE =\n\t/^(#.*)|(\\s?\\r?\\n)|(?:^|^)\\s*(?:export\\s+)?([\\w.-]*)(?:\\s*=\\s*?|:\\s+?)(\\s*'(?:\\\\'|[^'])*'|\\s*\"(?:\\\\\"|[^\"])*\"|\\s*`(?:\\\\`|[^`])*`|[^#\\r\\n]+)?(\\s*)(#.*)?(?:$|$)/gm;\n\nexport type ParseResult = {\n\ttype: \"value\" | \"comment\" | \"whitespace\";\n\tkey?: string;\n\tvalue?: string;\n\traw?: string;\n}[];\n\n// Parser src into an Object\nexport const parse = (src: string) => {\n\tconst obj: Record<string, string> = {};\n\tconst blocks: ParseResult = [];\n\n\t// Convert buffer to string\n\tlet lines = src.toString();\n\n\t// Convert line breaks to same format\n\tlines = lines.replace(/\\r\\n?/gm, \"\\n\");\n\n\tlet match;\n\twhile ((match = LINE.exec(lines)) != null) {\n\t\tconst key = match[3];\n\n\t\tif (match?.[1]?.[0] === \"#\") {\n\t\t\tblocks.push({ type: \"comment\", raw: match[1] });\n\t\t} else if (match?.[2]) {\n\t\t\tblocks.push({ type: \"whitespace\", raw: match[2] });\n\t\t} else {\n\t\t\t// Default undefined or null to empty string\n\t\t\tlet value = match[4] || \"\";\n\n\t\t\t// Remove whitespace\n\t\t\tvalue = value.trim();\n\n\t\t\t// Check if double quoted\n\t\t\tconst maybeQuote = value[0];\n\n\t\t\t// Remove surrounding quotes\n\t\t\tvalue = value.replace(/^(['\"`])([\\s\\S]*)\\1$/gm, \"$2\");\n\n\t\t\t// Expand newlines if double quoted\n\t\t\tif (maybeQuote === '\"') {\n\t\t\t\tvalue = value.replace(/\\\\n/g, \"\\n\");\n\t\t\t\tvalue = value.replace(/\\\\r/g, \"\\r\");\n\t\t\t}\n\n\t\t\tobj[key] = value;\n\n\t\t\t// Add to object\n\t\t\tblocks.push({\n\t\t\t\ttype: \"value\",\n\t\t\t\tkey,\n\t\t\t\tvalue,\n\t\t\t\traw: value + (match[5] ? match[5] : \"\") + (match[6] ? match[6] : \"\"),\n\t\t\t});\n\t\t}\n\t}\n\n\treturn { blocks, obj };\n};\n\nif (import.meta.vitest) {\n\tconst { it, expect } = import.meta.vitest;\n\n\tit(\"parse\", () => {\n\t\tconst input1 = \"KEY=value\";\n\t\tconst input2 = 'KEY=\"value\"';\n\t\tconst input3 = \"KEY='value'\";\n\t\tconst input4 = \"KEY=value # this is a comment\";\n\n\t\t// const expectedResult1 = [\n\t\t// { type: 'value', key: 'KEY', value: 'value', raw: 'value' },\n\t\t// ];\n\t\t// const expectedResult2 = [\n\t\t// { type: 'value', key: 'KEY', value: 'value', raw: '\"value\"' },\n\t\t// ];\n\t\t// const expectedResult3 = [\n\t\t// { type: 'value', key: 'KEY', value: 'value', raw: \"'value'\" },\n\t\t// ];\n\t\t// const expectedResult4 = [\n\t\t// {\n\t\t// type: 'value',\n\t\t// key: 'KEY',\n\t\t// value: 'value',\n\t\t// raw: 'value # this is a comment',\n\t\t// },\n\t\t// ];\n\n\t\texpect(parse(input1)).toMatchInlineSnapshot(`\n\t\t\t{\n\t\t\t \"blocks\": [\n\t\t\t {\n\t\t\t \"key\": \"KEY\",\n\t\t\t \"raw\": \"value\",\n\t\t\t \"type\": \"value\",\n\t\t\t \"value\": \"value\",\n\t\t\t },\n\t\t\t ],\n\t\t\t \"obj\": {\n\t\t\t \"KEY\": \"value\",\n\t\t\t },\n\t\t\t}\n\t\t`);\n\t\texpect(parse(input2)).toMatchInlineSnapshot(`\n\t\t\t{\n\t\t\t \"blocks\": [\n\t\t\t {\n\t\t\t \"key\": \"KEY\",\n\t\t\t \"raw\": \"value\",\n\t\t\t \"type\": \"value\",\n\t\t\t \"value\": \"value\",\n\t\t\t },\n\t\t\t ],\n\t\t\t \"obj\": {\n\t\t\t \"KEY\": \"value\",\n\t\t\t },\n\t\t\t}\n\t\t`);\n\t\texpect(parse(input3)).toMatchInlineSnapshot(`\n\t\t\t{\n\t\t\t \"blocks\": [\n\t\t\t {\n\t\t\t \"key\": \"KEY\",\n\t\t\t \"raw\": \"value\",\n\t\t\t \"type\": \"value\",\n\t\t\t \"value\": \"value\",\n\t\t\t },\n\t\t\t ],\n\t\t\t \"obj\": {\n\t\t\t \"KEY\": \"value\",\n\t\t\t },\n\t\t\t}\n\t\t`);\n\t\texpect(parse(input4)).toMatchInlineSnapshot(`\n {\n \"blocks\": [\n {\n \"key\": \"KEY\",\n \"raw\": \"value# this is a comment\",\n \"type\": \"value\",\n \"value\": \"value\",\n },\n ],\n \"obj\": {\n \"KEY\": \"value\",\n },\n }\n `);\n\t});\n}\n","import prompts from \"prompts\";\n\nexport const promptConfirm = async ({\n\tpredicate,\n\tskip,\n\tmessage,\n}: {\n\tpredicate?: (...args: unknown[]) => Promise<boolean> | boolean;\n\tskip?: boolean;\n\tmessage: string;\n}): Promise<boolean> => {\n\tif (skip === true) {\n\t\treturn true;\n\t} else {\n\t\tconst result = predicate ? await predicate() : true;\n\t\tif (result) {\n\t\t\tconst confirmResult = await prompts({\n\t\t\t\ttype: \"confirm\",\n\t\t\t\tname: \"confirm\",\n\t\t\t\tmessage: () => {\n\t\t\t\t\treturn message;\n\t\t\t\t},\n\t\t\t});\n\n\t\t\tif (confirmResult.confirm === true) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\t}\n\treturn false;\n};\n\nexport const promptExecute = async ({\n\tskip,\n\tmessage,\n\texecute,\n}: {\n\tskip?: boolean;\n\tmessage: string;\n\texecute: () => unknown | Promise<unknown>;\n}) => {\n\tlet shouldExecute = false;\n\tif (skip) {\n\t\tshouldExecute = true;\n\t} else {\n\t\tconst promptResponse = await prompts({\n\t\t\ttype: \"confirm\",\n\t\t\tname: \"confirm\",\n\t\t\tmessage,\n\t\t});\n\n\t\tif (promptResponse.confirm === true) {\n\t\t\tshouldExecute = true;\n\t\t}\n\t}\n\n\tif (shouldExecute) {\n\t\tawait execute();\n\t}\n};\n","import { expand } from \"dotenv-expand\";\n\nexport const resolveFromEnv = (options: {\n\tfromEnvValue?: string;\n\tenv: NodeJS.ProcessEnv;\n\tvariables: Record<string, string>;\n}) => {\n\tconst { fromEnvValue, env, variables } = options;\n\n\tif (!fromEnvValue) {\n\t\treturn \"\";\n\t}\n\n\treturn (\n\t\texpand({\n\t\t\tignoreProcessEnv: true,\n\t\t\tparsed: {\n\t\t\t\t// add standard env variables\n\t\t\t\t...(env as Record<string, string>),\n\t\t\t\t// add custom env variables, either from .env or .sec, (or empty object if none)\n\t\t\t\t...variables,\n\t\t\t\tRESOLVED: fromEnvValue || \"\",\n\t\t\t},\n\t\t}) as { parsed?: { RESOLVED?: string } }\n\t).parsed?.RESOLVED;\n};\n","import fs, { stat } from \"node:fs/promises\";\nimport path from \"node:path\";\nimport prompts from \"prompts\";\n\nexport const readContentsFromFile = async (\n\tfilePath: string,\n): Promise<string> => {\n\treturn await fs.readFile(filePath, \"utf-8\");\n};\n\nexport const writeContentsToFile = async (\n\tfilePath: string,\n\tcontents: string,\n): Promise<void> => {\n\treturn await fs.writeFile(filePath, contents, \"utf-8\");\n};\n\nexport const fileExists = async (source: string): Promise<boolean> => {\n\ttry {\n\t\tawait stat(source);\n\t\treturn true;\n\t} catch {\n\t\treturn false;\n\t}\n};\n\nexport const promptOverwriteIfFileExists = async ({\n\tfilePath,\n\tskip,\n}: {\n\tfilePath: string;\n\tskip?: boolean;\n}) => {\n\tlet overwriteResponse: prompts.Answers<\"overwrite\"> | undefined;\n\n\tif ((await fileExists(filePath)) && skip !== true) {\n\t\toverwriteResponse = await prompts({\n\t\t\ttype: \"confirm\",\n\t\t\tname: \"overwrite\",\n\t\t\tmessage: () => {\n\t\t\t\treturn `Overwrite './${path.relative(process.cwd(), filePath)}' ?`;\n\t\t\t},\n\t\t});\n\t} else {\n\t\toverwriteResponse = undefined;\n\t}\n\treturn overwriteResponse;\n};\n","import chalk from \"chalk\";\nimport Table from \"cli-table\";\nexport { Table };\n\nlet _logger: Pick<Console, \"info\" | \"error\" | \"table\">;\nexport const getLogger = () => {\n\tif (!_logger) {\n\t\t_logger = console;\n\t}\n\n\treturn _logger;\n};\nexport const writeLine = (str: string) => {\n\tprocess.stdout.write(str);\n};\nexport const emphasis = (str: string): string => chalk.yellowBright(str);\nexport const strong = (str: string): string => chalk.yellow.bold(str);\n\nexport const clientLogger = {\n\tdebug(content: object) {\n\t\tconsole.log(content);\n\t},\n\tinfo(content: object) {\n\t\tconsole.log(content);\n\t},\n\twarn(content: object) {\n\t\tconsole.log(content);\n\t},\n\terror(content: object) {\n\t\tconsole.error(content);\n\t},\n};\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dotsec",
3
- "version": "4.0.0-alpha.4",
3
+ "version": "4.0.0-alpha.41",
4
4
  "description": "",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -31,7 +31,8 @@
31
31
  "license": "MIT",
32
32
  "scripts": {
33
33
  "dev": "tsup --watch ./src --onSuccess \"node dist/index.js\"",
34
- "build": "tsup"
34
+ "build": "tsup",
35
+ "clean": "rm -rf dist"
35
36
  },
36
37
  "typedoc": {
37
38
  "entryPoint": "./src/index.ts",
@@ -43,7 +44,7 @@
43
44
  "@types/node": "^18.14.6",
44
45
  "@types/prompts": "^2.0.14",
45
46
  "@types/yargs-parser": "^21.0.0",
46
- "tsup": "^6.6.3"
47
+ "tsup": "^6.7.0"
47
48
  },
48
49
  "dependencies": {
49
50
  "@npmcli/arborist": "^6.1.4",
@@ -57,10 +58,11 @@
57
58
  "cross-spawn": "^7.0.3",
58
59
  "dotenv": "^16.0.0",
59
60
  "dotenv-expand": "^10.0.0",
61
+ "esbuild": "~0.16",
60
62
  "joycon": "^3.1.1",
61
63
  "prompts": "^2.4.2",
62
64
  "typescript": "~4.9.3",
63
65
  "yargs-parser": "^21.1.1"
64
66
  },
65
- "gitHead": "7424686ad3816cc16d138a3417533f33134d3b87"
67
+ "gitHead": "2200d262e0e6c49db8956bc893503afd9b309650"
66
68
  }