@adonisjs/env 6.0.1 → 6.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/README.md +12 -0
- package/build/src/editor.d.ts +3 -1
- package/build/src/editor.js +8 -2
- package/build/src/editor.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -139,6 +139,18 @@ editor.add('HOST', 'localhost')
|
|
|
139
139
|
await editor.save()
|
|
140
140
|
```
|
|
141
141
|
|
|
142
|
+
You can also insert an empty value for the `.env.example` file by setting the last argument to `true`.
|
|
143
|
+
|
|
144
|
+
```ts
|
|
145
|
+
editor.add('SECRET_VARIABLE', 'secret-value', true)
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
This will add the following line to the `.env.example` file.
|
|
149
|
+
|
|
150
|
+
```env
|
|
151
|
+
SECRET_VARIABLE=
|
|
152
|
+
```
|
|
153
|
+
|
|
142
154
|
## Known Exceptions
|
|
143
155
|
|
|
144
156
|
### E_INVALID_ENV_VARIABLES
|
package/build/src/editor.d.ts
CHANGED
|
@@ -14,8 +14,10 @@ export declare class EnvEditor {
|
|
|
14
14
|
load(): Promise<void>;
|
|
15
15
|
/**
|
|
16
16
|
* Add key-value pair to the dot-env files.
|
|
17
|
+
* If `withEmptyExampleValue` is true then the key will be added with an empty value
|
|
18
|
+
* to the `.env.example` file.
|
|
17
19
|
*/
|
|
18
|
-
add(key: string, value: string | number | boolean): void;
|
|
20
|
+
add(key: string, value: string | number | boolean, withEmptyExampleValue?: boolean): void;
|
|
19
21
|
toJSON(): {
|
|
20
22
|
contents: string[];
|
|
21
23
|
path: string;
|
package/build/src/editor.js
CHANGED
|
@@ -40,12 +40,18 @@ var EnvEditor = class _EnvEditor {
|
|
|
40
40
|
}
|
|
41
41
|
/**
|
|
42
42
|
* Add key-value pair to the dot-env files.
|
|
43
|
+
* If `withEmptyExampleValue` is true then the key will be added with an empty value
|
|
44
|
+
* to the `.env.example` file.
|
|
43
45
|
*/
|
|
44
|
-
add(key, value) {
|
|
46
|
+
add(key, value, withEmptyExampleValue = false) {
|
|
45
47
|
this.#files.forEach((file) => {
|
|
46
48
|
let entryIndex = file.contents.findIndex((line) => line.startsWith(`${key}=`));
|
|
47
49
|
entryIndex = entryIndex === -1 ? file.contents.length : entryIndex;
|
|
48
|
-
|
|
50
|
+
if (withEmptyExampleValue && file.path.endsWith(".env.example")) {
|
|
51
|
+
lodash.set(file.contents, entryIndex, `${key}=`);
|
|
52
|
+
} else {
|
|
53
|
+
lodash.set(file.contents, entryIndex, `${key}=${value}`);
|
|
54
|
+
}
|
|
49
55
|
});
|
|
50
56
|
}
|
|
51
57
|
toJSON() {
|
package/build/src/editor.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/editor.ts"],"sourcesContent":["/*\n * @adonisjs/env\n *\n * (c) AdonisJS\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport splitLines from 'split-lines'\nimport lodash from '@poppinss/utils/lodash'\nimport { writeFile } from 'node:fs/promises'\n\nimport { EnvLoader } from './loader.js'\n\nexport class EnvEditor {\n #appRoot: URL\n #loader: EnvLoader\n #files: { contents: string[]; path: string }[] = []\n\n /**\n * Creates an instance of env editor and loads .env files\n * contents.\n */\n static async create(appRoot: URL) {\n const editor = new EnvEditor(appRoot)\n await editor.load()\n\n return editor\n }\n\n constructor(appRoot: URL) {\n this.#appRoot = appRoot\n this.#loader = new EnvLoader(this.#appRoot, true)\n }\n\n /**\n * Loads .env files for editing. Only \".env\" and \".env.example\"\n * files are picked for editing.\n */\n async load() {\n const envFiles = await this.#loader.load()\n\n this.#files = envFiles\n .filter(\n (envFile) =>\n envFile.fileExists &&\n (envFile.path.endsWith('.env') || envFile.path.endsWith('.env.example'))\n )\n .map((envFile) => {\n return {\n contents: splitLines(envFile.contents.trim()),\n path: envFile.path,\n }\n })\n }\n\n /**\n * Add key-value pair to the dot-env files.\n */\n add(key: string, value: string | number | boolean) {\n this.#files.forEach((file) => {\n let entryIndex = file.contents.findIndex((line) => line.startsWith(`${key}=`))\n\n entryIndex = entryIndex === -1 ? file.contents.length : entryIndex\n lodash.set(file.contents, entryIndex, `${key}=${
|
|
1
|
+
{"version":3,"sources":["../../src/editor.ts"],"sourcesContent":["/*\n * @adonisjs/env\n *\n * (c) AdonisJS\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport splitLines from 'split-lines'\nimport lodash from '@poppinss/utils/lodash'\nimport { writeFile } from 'node:fs/promises'\n\nimport { EnvLoader } from './loader.js'\n\nexport class EnvEditor {\n #appRoot: URL\n #loader: EnvLoader\n #files: { contents: string[]; path: string }[] = []\n\n /**\n * Creates an instance of env editor and loads .env files\n * contents.\n */\n static async create(appRoot: URL) {\n const editor = new EnvEditor(appRoot)\n await editor.load()\n\n return editor\n }\n\n constructor(appRoot: URL) {\n this.#appRoot = appRoot\n this.#loader = new EnvLoader(this.#appRoot, true)\n }\n\n /**\n * Loads .env files for editing. Only \".env\" and \".env.example\"\n * files are picked for editing.\n */\n async load() {\n const envFiles = await this.#loader.load()\n\n this.#files = envFiles\n .filter(\n (envFile) =>\n envFile.fileExists &&\n (envFile.path.endsWith('.env') || envFile.path.endsWith('.env.example'))\n )\n .map((envFile) => {\n return {\n contents: splitLines(envFile.contents.trim()),\n path: envFile.path,\n }\n })\n }\n\n /**\n * Add key-value pair to the dot-env files.\n * If `withEmptyExampleValue` is true then the key will be added with an empty value\n * to the `.env.example` file.\n */\n add(key: string, value: string | number | boolean, withEmptyExampleValue = false) {\n this.#files.forEach((file) => {\n let entryIndex = file.contents.findIndex((line) => line.startsWith(`${key}=`))\n\n entryIndex = entryIndex === -1 ? file.contents.length : entryIndex\n\n if (withEmptyExampleValue && file.path.endsWith('.env.example')) {\n lodash.set(file.contents, entryIndex, `${key}=`)\n } else {\n lodash.set(file.contents, entryIndex, `${key}=${value}`)\n }\n })\n }\n\n toJSON() {\n return this.#files\n }\n\n /**\n * Save changes to the disk\n */\n async save() {\n await Promise.all(\n this.#files.map((file) => {\n return writeFile(file.path, file.contents.join('\\n'))\n })\n )\n }\n}\n"],"mappings":";;;;;AASA,OAAO,gBAAgB;AACvB,OAAO,YAAY;AACnB,SAAS,iBAAiB;AAInB,IAAM,YAAN,MAAM,WAAU;AAAA,EACrB;AAAA,EACA;AAAA,EACA,SAAiD,CAAC;AAAA;AAAA;AAAA;AAAA;AAAA,EAMlD,aAAa,OAAO,SAAc;AAChC,UAAM,SAAS,IAAI,WAAU,OAAO;AACpC,UAAM,OAAO,KAAK;AAElB,WAAO;AAAA,EACT;AAAA,EAEA,YAAY,SAAc;AACxB,SAAK,WAAW;AAChB,SAAK,UAAU,IAAI,UAAU,KAAK,UAAU,IAAI;AAAA,EAClD;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,MAAM,OAAO;AACX,UAAM,WAAW,MAAM,KAAK,QAAQ,KAAK;AAEzC,SAAK,SAAS,SACX;AAAA,MACC,CAAC,YACC,QAAQ,eACP,QAAQ,KAAK,SAAS,MAAM,KAAK,QAAQ,KAAK,SAAS,cAAc;AAAA,IAC1E,EACC,IAAI,CAAC,YAAY;AAChB,aAAO;AAAA,QACL,UAAU,WAAW,QAAQ,SAAS,KAAK,CAAC;AAAA,QAC5C,MAAM,QAAQ;AAAA,MAChB;AAAA,IACF,CAAC;AAAA,EACL;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,IAAI,KAAa,OAAkC,wBAAwB,OAAO;AAChF,SAAK,OAAO,QAAQ,CAAC,SAAS;AAC5B,UAAI,aAAa,KAAK,SAAS,UAAU,CAAC,SAAS,KAAK,WAAW,GAAG,GAAG,GAAG,CAAC;AAE7E,mBAAa,eAAe,KAAK,KAAK,SAAS,SAAS;AAExD,UAAI,yBAAyB,KAAK,KAAK,SAAS,cAAc,GAAG;AAC/D,eAAO,IAAI,KAAK,UAAU,YAAY,GAAG,GAAG,GAAG;AAAA,MACjD,OAAO;AACL,eAAO,IAAI,KAAK,UAAU,YAAY,GAAG,GAAG,IAAI,KAAK,EAAE;AAAA,MACzD;AAAA,IACF,CAAC;AAAA,EACH;AAAA,EAEA,SAAS;AACP,WAAO,KAAK;AAAA,EACd;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,OAAO;AACX,UAAM,QAAQ;AAAA,MACZ,KAAK,OAAO,IAAI,CAAC,SAAS;AACxB,eAAO,UAAU,KAAK,MAAM,KAAK,SAAS,KAAK,IAAI,CAAC;AAAA,MACtD,CAAC;AAAA,IACH;AAAA,EACF;AACF;","names":[]}
|