@lowdefy/node-utils 4.0.0-alpha.1 → 4.0.0-alpha.7
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/cleanDirectory.js +2 -3
- package/dist/copyDirectory.js +19 -0
- package/dist/getConfigFromEnv.js +1 -1
- package/dist/getSecretsFromEnv.js +1 -2
- package/dist/index.js +3 -1
- package/dist/readFile.js +1 -4
- package/dist/spawnProcess.js +48 -0
- package/dist/writeFile.js +2 -5
- package/package.json +8 -8
package/dist/cleanDirectory.js
CHANGED
|
@@ -12,9 +12,8 @@
|
|
|
12
12
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
13
|
See the License for the specific language governing permissions and
|
|
14
14
|
limitations under the License.
|
|
15
|
-
*/ import
|
|
15
|
+
*/ import fsExtra from 'fs-extra';
|
|
16
16
|
async function cleanDirectory(dirPath) {
|
|
17
|
-
await
|
|
18
|
-
);
|
|
17
|
+
await fsExtra.emptyDir(dirPath);
|
|
19
18
|
}
|
|
20
19
|
export default cleanDirectory;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2021 Lowdefy, Inc
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/ import fsExtra from 'fs-extra';
|
|
16
|
+
async function copyDirectory(dirPathFrom, dirPathTo) {
|
|
17
|
+
await fsExtra.copy(dirPathFrom, dirPathTo);
|
|
18
|
+
}
|
|
19
|
+
export default copyDirectory;
|
package/dist/getConfigFromEnv.js
CHANGED
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
logLevel: process.env.LOWDEFY_SERVER_LOG_LEVEL,
|
|
19
19
|
publicDirectory: process.env.LOWDEFY_SERVER_PUBLIC_DIRECTORY,
|
|
20
20
|
port: process.env.LOWDEFY_SERVER_PORT && parseInt(process.env.LOWDEFY_SERVER_PORT),
|
|
21
|
-
|
|
21
|
+
basePath: process.env.LOWDEFY_BASE_PATH
|
|
22
22
|
};
|
|
23
23
|
}
|
|
24
24
|
export default getConfigFromEnv;
|
|
@@ -13,8 +13,7 @@
|
|
|
13
13
|
See the License for the specific language governing permissions and
|
|
14
14
|
limitations under the License.
|
|
15
15
|
*/ function getSecretsFromEnv() {
|
|
16
|
-
const secrets = {
|
|
17
|
-
};
|
|
16
|
+
const secrets = {};
|
|
18
17
|
Object.keys(process.env).forEach((key)=>{
|
|
19
18
|
if (key.startsWith('LOWDEFY_SECRET_')) {
|
|
20
19
|
secrets[key.replace('LOWDEFY_SECRET_', '')] = process.env[key];
|
package/dist/index.js
CHANGED
|
@@ -13,9 +13,11 @@
|
|
|
13
13
|
See the License for the specific language governing permissions and
|
|
14
14
|
limitations under the License.
|
|
15
15
|
*/ import cleanDirectory from './cleanDirectory.js';
|
|
16
|
+
import copyDirectory from './copyDirectory.js';
|
|
16
17
|
import getConfigFromEnv from './getConfigFromEnv.js';
|
|
17
18
|
import getFileExtension, { getFileSubExtension } from './getFileExtension.js';
|
|
18
19
|
import getSecretsFromEnv from './getSecretsFromEnv.js';
|
|
20
|
+
import spawnProcess from './spawnProcess.js';
|
|
19
21
|
import readFile from './readFile.js';
|
|
20
22
|
import writeFile from './writeFile.js';
|
|
21
|
-
export { cleanDirectory, getConfigFromEnv, getFileExtension, getFileSubExtension, getSecretsFromEnv, readFile, writeFile };
|
|
23
|
+
export { cleanDirectory, copyDirectory, getConfigFromEnv, getFileExtension, getFileSubExtension, getSecretsFromEnv, spawnProcess, readFile, writeFile };
|
package/dist/readFile.js
CHANGED
|
@@ -21,12 +21,9 @@ async function readFile(filePath) {
|
|
|
21
21
|
if (!type.isString(filePath)) {
|
|
22
22
|
throw new Error(`Could not read file, file path should be a string, received ${JSON.stringify(filePath)}.`);
|
|
23
23
|
}
|
|
24
|
-
if (filePath !== path.resolve(filePath)) {
|
|
25
|
-
throw new Error(`Could not read file, file path was not resolved, received ${JSON.stringify(filePath)}.`);
|
|
26
|
-
}
|
|
27
24
|
try {
|
|
28
25
|
// By specifying encoding, readFile returns a string instead of a buffer.
|
|
29
|
-
const file = await readFilePromise(filePath, 'utf8');
|
|
26
|
+
const file = await readFilePromise(path.resolve(filePath), 'utf8');
|
|
30
27
|
return file;
|
|
31
28
|
} catch (error) {
|
|
32
29
|
if (error.code === 'ENOENT' || error.code === 'EISDIR') {
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2021 Lowdefy, Inc
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/ import { spawn } from 'child_process';
|
|
16
|
+
async function spawnProcess({ logger , command , args , processOptions , silent }) {
|
|
17
|
+
return new Promise((resolve, reject)=>{
|
|
18
|
+
const process = spawn(command, args, processOptions);
|
|
19
|
+
process.stdout.on('data', (data)=>{
|
|
20
|
+
if (!silent) {
|
|
21
|
+
data.toString('utf8').split('\n').forEach((line)=>{
|
|
22
|
+
if (line) {
|
|
23
|
+
logger.log(line);
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
process.stderr.on('data', (data)=>{
|
|
29
|
+
if (!silent) {
|
|
30
|
+
data.toString('utf8').split('\n').forEach((line)=>{
|
|
31
|
+
if (line) {
|
|
32
|
+
logger.warn(line);
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
process.on('error', (error)=>{
|
|
38
|
+
reject(error);
|
|
39
|
+
});
|
|
40
|
+
process.on('exit', (code)=>{
|
|
41
|
+
if (code !== 0) {
|
|
42
|
+
reject(new Error(`${command} exited with code ${code}`));
|
|
43
|
+
}
|
|
44
|
+
resolve();
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
export default spawnProcess;
|
package/dist/writeFile.js
CHANGED
|
@@ -18,15 +18,12 @@ import { promisify } from 'util';
|
|
|
18
18
|
import { type } from '@lowdefy/helpers';
|
|
19
19
|
const mkdirPromise = promisify(fs.mkdir);
|
|
20
20
|
const writeFilePromise = promisify(fs.writeFile);
|
|
21
|
-
async function writeFile(
|
|
21
|
+
async function writeFile(filePath, content) {
|
|
22
22
|
if (!type.isString(filePath)) {
|
|
23
23
|
throw new Error(`Could not write file, file path should be a string, received ${JSON.stringify(filePath)}.`);
|
|
24
24
|
}
|
|
25
|
-
if (filePath !== path.resolve(filePath)) {
|
|
26
|
-
throw new Error(`Could not write file, file path was not resolved, received ${JSON.stringify(filePath)}.`);
|
|
27
|
-
}
|
|
28
25
|
try {
|
|
29
|
-
await writeFilePromise(filePath, content);
|
|
26
|
+
await writeFilePromise(path.resolve(filePath), content);
|
|
30
27
|
} catch (error) {
|
|
31
28
|
if (error.code === 'ENOENT') {
|
|
32
29
|
await mkdirPromise(path.dirname(filePath), {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lowdefy/node-utils",
|
|
3
|
-
"version": "4.0.0-alpha.
|
|
3
|
+
"version": "4.0.0-alpha.7",
|
|
4
4
|
"licence": "Apache-2.0",
|
|
5
5
|
"description": "",
|
|
6
6
|
"homepage": "https://lowdefy.com",
|
|
@@ -41,17 +41,17 @@
|
|
|
41
41
|
"test": "jest --coverage"
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@lowdefy/helpers": "4.0.0-alpha.
|
|
45
|
-
"
|
|
44
|
+
"@lowdefy/helpers": "4.0.0-alpha.7",
|
|
45
|
+
"fs-extra": "10.0.0"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
|
-
"@swc/cli": "0.1.
|
|
49
|
-
"@swc/core": "1.2.
|
|
50
|
-
"@swc/jest": "0.2.
|
|
51
|
-
"jest": "27.
|
|
48
|
+
"@swc/cli": "0.1.55",
|
|
49
|
+
"@swc/core": "1.2.135",
|
|
50
|
+
"@swc/jest": "0.2.17",
|
|
51
|
+
"jest": "27.5.1"
|
|
52
52
|
},
|
|
53
53
|
"publishConfig": {
|
|
54
54
|
"access": "public"
|
|
55
55
|
},
|
|
56
|
-
"gitHead": "
|
|
56
|
+
"gitHead": "52ec14639d00de910cf9b8ab25bf933ca891cff5"
|
|
57
57
|
}
|