@awesomeness-js/utils 1.0.10 → 1.0.12
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/build.js +5 -4
- 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'
|
package/src/build.js
CHANGED
|
@@ -64,7 +64,7 @@ function extractJSDocComment(filePath) {
|
|
|
64
64
|
}
|
|
65
65
|
|
|
66
66
|
|
|
67
|
-
function generateExports(src) {
|
|
67
|
+
function generateExports(src, exportRoots) {
|
|
68
68
|
const allFiles = [];
|
|
69
69
|
const fnFiles = getAllFiles(src, '.');
|
|
70
70
|
allFiles.push(...fnFiles);
|
|
@@ -96,7 +96,7 @@ function generateExports(src) {
|
|
|
96
96
|
imports += `import ${namespace}_${functionName} from '${importPath}.js';\n`;
|
|
97
97
|
|
|
98
98
|
// generate exports
|
|
99
|
-
if(!namespace){ allExports += `export { _${functionName} as ${functionName} };\n`; }
|
|
99
|
+
if(exportRoots && !namespace){ allExports += `export { _${functionName} as ${functionName} };\n`; }
|
|
100
100
|
|
|
101
101
|
// Populate the API object structure
|
|
102
102
|
let current = apiObject;
|
|
@@ -123,9 +123,10 @@ function generateExports(src) {
|
|
|
123
123
|
|
|
124
124
|
async function build({
|
|
125
125
|
src = './src',
|
|
126
|
-
dest = './index.js'
|
|
126
|
+
dest = './index.js',
|
|
127
|
+
exportRoots = true
|
|
127
128
|
} = {}) {
|
|
128
|
-
const indexContent = generateExports(src);
|
|
129
|
+
const indexContent = generateExports(src, exportRoots);
|
|
129
130
|
writeFileSync(dest, indexContent);
|
|
130
131
|
return true;
|
|
131
132
|
}
|
|
@@ -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);
|