@branchly/resolver-env-file 0.1.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/index.d.ts +11 -0
- package/dist/index.js +36 -0
- package/dist/index.js.map +1 -0
- package/package.json +30 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ConnectionResolver } from 'branchly';
|
|
2
|
+
|
|
3
|
+
interface EnvFileResolverOptions {
|
|
4
|
+
readonly file?: string;
|
|
5
|
+
readonly key?: string;
|
|
6
|
+
readonly cwd?: string;
|
|
7
|
+
}
|
|
8
|
+
declare const upsertLine: (content: string, key: string, value: string) => string;
|
|
9
|
+
declare const createEnvFileResolver: (options?: EnvFileResolverOptions) => ConnectionResolver;
|
|
10
|
+
|
|
11
|
+
export { type EnvFileResolverOptions, createEnvFileResolver, createEnvFileResolver as default, upsertLine };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import { readFile, writeFile } from "fs/promises";
|
|
3
|
+
import { join } from "path";
|
|
4
|
+
var DEFAULT_FILE = ".env";
|
|
5
|
+
var DEFAULT_KEY = "DATABASE_URL";
|
|
6
|
+
var upsertLine = (content, key, value) => {
|
|
7
|
+
const line = `${key}=${value}`;
|
|
8
|
+
const existing = content.length === 0 ? [] : content.replace(/\n+$/, "").split("\n");
|
|
9
|
+
const replaced = existing.map((current) => current.startsWith(`${key}=`) ? line : current);
|
|
10
|
+
const next = replaced.includes(line) ? replaced : [...replaced, line];
|
|
11
|
+
return `${next.join("\n")}
|
|
12
|
+
`;
|
|
13
|
+
};
|
|
14
|
+
var readExisting = (path) => readFile(path, "utf8").then(
|
|
15
|
+
(content) => content,
|
|
16
|
+
() => ""
|
|
17
|
+
);
|
|
18
|
+
var createEnvFileResolver = (options = {}) => {
|
|
19
|
+
const path = join(options.cwd ?? ".", options.file ?? DEFAULT_FILE);
|
|
20
|
+
const key = options.key ?? DEFAULT_KEY;
|
|
21
|
+
return {
|
|
22
|
+
id: "env-file",
|
|
23
|
+
apiVersion: 1,
|
|
24
|
+
inject: async (connection) => {
|
|
25
|
+
const existing = await readExisting(path);
|
|
26
|
+
await writeFile(path, upsertLine(existing, key, connection), "utf8");
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
var index_default = createEnvFileResolver;
|
|
31
|
+
export {
|
|
32
|
+
createEnvFileResolver,
|
|
33
|
+
index_default as default,
|
|
34
|
+
upsertLine
|
|
35
|
+
};
|
|
36
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { readFile, writeFile } from 'node:fs/promises';\nimport { join } from 'node:path';\n\nimport type { ConnectionResolver } from 'branchly';\n\nconst DEFAULT_FILE = '.env';\nconst DEFAULT_KEY = 'DATABASE_URL';\n\nexport interface EnvFileResolverOptions {\n readonly file?: string;\n readonly key?: string;\n readonly cwd?: string;\n}\n\nexport const upsertLine = (content: string, key: string, value: string): string => {\n const line = `${key}=${value}`;\n const existing = content.length === 0 ? [] : content.replace(/\\n+$/, '').split('\\n');\n const replaced = existing.map((current) => (current.startsWith(`${key}=`) ? line : current));\n const next = replaced.includes(line) ? replaced : [...replaced, line];\n return `${next.join('\\n')}\\n`;\n};\n\nconst readExisting = (path: string): Promise<string> =>\n readFile(path, 'utf8').then(\n (content) => content,\n () => '',\n );\n\nexport const createEnvFileResolver = (options: EnvFileResolverOptions = {}): ConnectionResolver => {\n const path = join(options.cwd ?? '.', options.file ?? DEFAULT_FILE);\n const key = options.key ?? DEFAULT_KEY;\n return {\n id: 'env-file',\n apiVersion: 1,\n inject: async (connection) => {\n const existing = await readExisting(path);\n await writeFile(path, upsertLine(existing, key, connection), 'utf8');\n },\n };\n};\n\nexport default createEnvFileResolver;\n"],"mappings":";AAAA,SAAS,UAAU,iBAAiB;AACpC,SAAS,YAAY;AAIrB,IAAM,eAAe;AACrB,IAAM,cAAc;AAQb,IAAM,aAAa,CAAC,SAAiB,KAAa,UAA0B;AACjF,QAAM,OAAO,GAAG,GAAG,IAAI,KAAK;AAC5B,QAAM,WAAW,QAAQ,WAAW,IAAI,CAAC,IAAI,QAAQ,QAAQ,QAAQ,EAAE,EAAE,MAAM,IAAI;AACnF,QAAM,WAAW,SAAS,IAAI,CAAC,YAAa,QAAQ,WAAW,GAAG,GAAG,GAAG,IAAI,OAAO,OAAQ;AAC3F,QAAM,OAAO,SAAS,SAAS,IAAI,IAAI,WAAW,CAAC,GAAG,UAAU,IAAI;AACpE,SAAO,GAAG,KAAK,KAAK,IAAI,CAAC;AAAA;AAC3B;AAEA,IAAM,eAAe,CAAC,SACpB,SAAS,MAAM,MAAM,EAAE;AAAA,EACrB,CAAC,YAAY;AAAA,EACb,MAAM;AACR;AAEK,IAAM,wBAAwB,CAAC,UAAkC,CAAC,MAA0B;AACjG,QAAM,OAAO,KAAK,QAAQ,OAAO,KAAK,QAAQ,QAAQ,YAAY;AAClE,QAAM,MAAM,QAAQ,OAAO;AAC3B,SAAO;AAAA,IACL,IAAI;AAAA,IACJ,YAAY;AAAA,IACZ,QAAQ,OAAO,eAAe;AAC5B,YAAM,WAAW,MAAM,aAAa,IAAI;AACxC,YAAM,UAAU,MAAM,WAAW,UAAU,KAAK,UAAU,GAAG,MAAM;AAAA,IACrE;AAAA,EACF;AACF;AAEA,IAAO,gBAAQ;","names":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@branchly/resolver-env-file",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Reference env-file connection resolver for branchly.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"default": "./dist/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
18
|
+
"devDependencies": {
|
|
19
|
+
"@branchly/adapter-test-kit": "0.1.0",
|
|
20
|
+
"branchly": "0.1.0"
|
|
21
|
+
},
|
|
22
|
+
"publishConfig": {
|
|
23
|
+
"access": "public"
|
|
24
|
+
},
|
|
25
|
+
"scripts": {
|
|
26
|
+
"build": "tsup",
|
|
27
|
+
"dev": "tsup --watch",
|
|
28
|
+
"typecheck": "tsc --noEmit"
|
|
29
|
+
}
|
|
30
|
+
}
|