@awesomeness-js/utils 1.0.10 → 1.0.11
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/index.js +3 -0
- package/package.json +1 -1
- package/secrets/dev.env +1 -0
- package/secrets/local.env +1 -0
- package/src/setLocalEnvs.js +33 -0
- package/test.js +5 -0
package/index.js
CHANGED
|
@@ -11,6 +11,7 @@ import _eachAsync from './src/eachAsync.js';
|
|
|
11
11
|
import _getAllFiles from './src/getAllFiles.js';
|
|
12
12
|
import _isUUID from './src/isUUID.js';
|
|
13
13
|
import _md5 from './src/md5.js';
|
|
14
|
+
import _setLocalEnvs from './src/setLocalEnvs.js';
|
|
14
15
|
import _toPennies from './src/toPennies.js';
|
|
15
16
|
import _uuid from './src/uuid.js';
|
|
16
17
|
|
|
@@ -22,6 +23,7 @@ export { _eachAsync as eachAsync };
|
|
|
22
23
|
export { _getAllFiles as getAllFiles };
|
|
23
24
|
export { _isUUID as isUUID };
|
|
24
25
|
export { _md5 as md5 };
|
|
26
|
+
export { _setLocalEnvs as setLocalEnvs };
|
|
25
27
|
export { _toPennies as toPennies };
|
|
26
28
|
export { _uuid as uuid };
|
|
27
29
|
|
|
@@ -42,6 +44,7 @@ export default {
|
|
|
42
44
|
getAllFiles: _getAllFiles,
|
|
43
45
|
isUUID: _isUUID,
|
|
44
46
|
md5: _md5,
|
|
47
|
+
setLocalEnvs: _setLocalEnvs,
|
|
45
48
|
toPennies: _toPennies,
|
|
46
49
|
uuid: _uuid
|
|
47
50
|
};
|
package/package.json
CHANGED
package/secrets/dev.env
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
JUST_A_TEST='Dev just a test'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
JUST_A_TEST='Local just a test'
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { readFile } from 'fs/promises';
|
|
2
|
+
export default async (localSecretsPath = './secrets/local.env') => {
|
|
3
|
+
|
|
4
|
+
// get the file
|
|
5
|
+
let localSecrets = await readFile(localSecretsPath, 'utf8');
|
|
6
|
+
|
|
7
|
+
// parse the file
|
|
8
|
+
let lines = localSecrets.split('\n');
|
|
9
|
+
for(let line of lines){
|
|
10
|
+
|
|
11
|
+
// skip #
|
|
12
|
+
if(line[0] === '#'){ continue; }
|
|
13
|
+
|
|
14
|
+
let parts = line.split('=');
|
|
15
|
+
if(parts.length === 2){
|
|
16
|
+
// remove outside single quotes
|
|
17
|
+
if(
|
|
18
|
+
parts[1][0] === "'"
|
|
19
|
+
&& parts[1][parts[1].length - 1] === "'"
|
|
20
|
+
){
|
|
21
|
+
parts[1] = parts[1].substring(1, parts[1].length - 1);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// remove \r
|
|
25
|
+
if(parts[1][parts[1].length - 1] === '\r'){
|
|
26
|
+
parts[1] = parts[1].substring(0, parts[1].length - 1);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
process.env[parts[0]] = parts[1];
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
}
|
package/test.js
CHANGED
|
@@ -20,3 +20,8 @@ let combineTestBrowser = utils.combineFiles('./src', 'js', {
|
|
|
20
20
|
});
|
|
21
21
|
console.log('combineTestBrowser', combineTestBrowser.length);
|
|
22
22
|
|
|
23
|
+
await utils.setLocalEnvs('./secrets/local.env');
|
|
24
|
+
console.log('localEnv', process.env.JUST_A_TEST);
|
|
25
|
+
|
|
26
|
+
await utils.setLocalEnvs('./secrets/dev.env');
|
|
27
|
+
console.log('localEnv', process.env.JUST_A_TEST);
|