@lowdefy/node-utils 3.23.2 → 4.0.0-alpha.6

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.
@@ -1,28 +1,20 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
- var _rimraf = _interopRequireDefault(require("rimraf"));
9
-
10
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
-
12
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
13
-
14
- function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
15
-
16
- function cleanDirectory(_x) {
17
- return _cleanDirectory.apply(this, arguments);
18
- }
19
-
20
- function _cleanDirectory() {
21
- _cleanDirectory = _asyncToGenerator(function* (dirPath) {
22
- yield new Promise(resolve => (0, _rimraf.default)(dirPath, resolve));
23
- });
24
- return _cleanDirectory.apply(this, arguments);
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 rimraf from 'rimraf';
16
+ async function cleanDirectory(dirPath) {
17
+ await new Promise((resolve)=>rimraf(dirPath, resolve)
18
+ );
25
19
  }
26
-
27
- var _default = cleanDirectory;
28
- exports.default = _default;
20
+ export default cleanDirectory;
@@ -1,10 +1,3 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
1
  /*
9
2
  Copyright 2020-2021 Lowdefy, Inc
10
3
 
@@ -19,17 +12,13 @@ exports.default = void 0;
19
12
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20
13
  See the License for the specific language governing permissions and
21
14
  limitations under the License.
22
- */
23
- function createGetSecretsFromEnv() {
24
- var secrets = {};
25
- Object.keys(process.env).forEach(key => {
26
- if (key.startsWith('LOWDEFY_SECRET_')) {
27
- secrets[key.replace('LOWDEFY_SECRET_', '')] = process.env[key];
28
- }
29
- });
30
- Object.freeze(secrets);
31
- return () => secrets;
15
+ */ function getConfigFromEnv() {
16
+ return {
17
+ buildDirectory: process.env.LOWDEFY_SERVER_BUILD_DIRECTORY,
18
+ logLevel: process.env.LOWDEFY_SERVER_LOG_LEVEL,
19
+ publicDirectory: process.env.LOWDEFY_SERVER_PUBLIC_DIRECTORY,
20
+ port: process.env.LOWDEFY_SERVER_PORT && parseInt(process.env.LOWDEFY_SERVER_PORT),
21
+ serverBasePath: process.env.LOWDEFY_SERVER_BASE_PATH
22
+ };
32
23
  }
33
-
34
- var _default = createGetSecretsFromEnv;
35
- exports.default = _default;
24
+ export default getConfigFromEnv;
@@ -1,11 +1,3 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.getFileSubExtension = getFileSubExtension;
7
- exports.default = void 0;
8
-
9
1
  /*
10
2
  Copyright 2020-2021 Lowdefy, Inc
11
3
 
@@ -20,26 +12,19 @@ exports.default = void 0;
20
12
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21
13
  See the License for the specific language governing permissions and
22
14
  limitations under the License.
23
- */
24
- function getFileExtension(filePath) {
25
- var arr = filePath.split('.');
26
-
27
- if (arr.length === 1) {
28
- return null;
29
- }
30
-
31
- return arr[arr.length - 1];
15
+ */ function getFileExtension(filePath) {
16
+ const arr = filePath.split('.');
17
+ if (arr.length === 1) {
18
+ return null;
19
+ }
20
+ return arr[arr.length - 1];
32
21
  }
33
-
34
22
  function getFileSubExtension(path) {
35
- var arr = path.split('.');
36
-
37
- if (arr.length < 3) {
38
- return null;
39
- }
40
-
41
- return arr[arr.length - 2];
23
+ const arr = path.split('.');
24
+ if (arr.length < 3) {
25
+ return null;
26
+ }
27
+ return arr[arr.length - 2];
42
28
  }
43
-
44
- var _default = getFileExtension;
45
- exports.default = _default;
29
+ export { getFileSubExtension };
30
+ export default getFileExtension;
@@ -0,0 +1,25 @@
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
+ */ function getSecretsFromEnv() {
16
+ const secrets = {};
17
+ Object.keys(process.env).forEach((key)=>{
18
+ if (key.startsWith('LOWDEFY_SECRET_')) {
19
+ secrets[key.replace('LOWDEFY_SECRET_', '')] = process.env[key];
20
+ }
21
+ });
22
+ Object.freeze(secrets);
23
+ return secrets;
24
+ }
25
+ export default getSecretsFromEnv;
package/dist/index.js CHANGED
@@ -1,57 +1,22 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- Object.defineProperty(exports, "cleanDirectory", {
7
- enumerable: true,
8
- get: function get() {
9
- return _cleanDirectory.default;
10
- }
11
- });
12
- Object.defineProperty(exports, "createGetSecretsFromEnv", {
13
- enumerable: true,
14
- get: function get() {
15
- return _createGetSecretsFromEnv.default;
16
- }
17
- });
18
- Object.defineProperty(exports, "getFileExtension", {
19
- enumerable: true,
20
- get: function get() {
21
- return _getFileExtension.default;
22
- }
23
- });
24
- Object.defineProperty(exports, "getFileSubExtension", {
25
- enumerable: true,
26
- get: function get() {
27
- return _getFileExtension.getFileSubExtension;
28
- }
29
- });
30
- Object.defineProperty(exports, "readFile", {
31
- enumerable: true,
32
- get: function get() {
33
- return _readFile.default;
34
- }
35
- });
36
- Object.defineProperty(exports, "writeFile", {
37
- enumerable: true,
38
- get: function get() {
39
- return _writeFile.default;
40
- }
41
- });
42
-
43
- var _cleanDirectory = _interopRequireDefault(require("./cleanDirectory"));
44
-
45
- var _createGetSecretsFromEnv = _interopRequireDefault(require("./createGetSecretsFromEnv"));
46
-
47
- var _getFileExtension = _interopRequireWildcard(require("./getFileExtension"));
48
-
49
- var _readFile = _interopRequireDefault(require("./readFile"));
50
-
51
- var _writeFile = _interopRequireDefault(require("./writeFile"));
52
-
53
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
54
-
55
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
56
-
57
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
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 cleanDirectory from './cleanDirectory.js';
16
+ import getConfigFromEnv from './getConfigFromEnv.js';
17
+ import getFileExtension, { getFileSubExtension } from './getFileExtension.js';
18
+ import getSecretsFromEnv from './getSecretsFromEnv.js';
19
+ import spawnProcess from './spawnProcess.js';
20
+ import readFile from './readFile.js';
21
+ import writeFile from './writeFile.js';
22
+ export { cleanDirectory, getConfigFromEnv, getFileExtension, getFileSubExtension, getSecretsFromEnv, spawnProcess, readFile, writeFile };
package/dist/readFile.js CHANGED
@@ -1,54 +1,38 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
- var _fs = _interopRequireDefault(require("fs"));
9
-
10
- var _path = _interopRequireDefault(require("path"));
11
-
12
- var _util = require("util");
13
-
14
- var _helpers = require("@lowdefy/helpers");
15
-
16
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
-
18
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
19
-
20
- function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
21
-
22
- var readFilePromise = (0, _util.promisify)(_fs.default.readFile);
23
-
24
- function readFile(_x) {
25
- return _readFile.apply(this, arguments);
26
- }
27
-
28
- function _readFile() {
29
- _readFile = _asyncToGenerator(function* (filePath) {
30
- if (!_helpers.type.isString(filePath)) {
31
- throw new Error("Could not read file, file path should be a string, received ".concat(JSON.stringify(filePath), "."));
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 fs from 'fs';
16
+ import path from 'path';
17
+ import { promisify } from 'util';
18
+ import { type } from '@lowdefy/helpers';
19
+ const readFilePromise = promisify(fs.readFile);
20
+ async function readFile(filePath) {
21
+ if (!type.isString(filePath)) {
22
+ throw new Error(`Could not read file, file path should be a string, received ${JSON.stringify(filePath)}.`);
32
23
  }
33
-
34
- if (filePath !== _path.default.resolve(filePath)) {
35
- throw new Error("Could not read file, file path was not resolved, received ".concat(JSON.stringify(filePath), "."));
24
+ if (filePath !== path.resolve(filePath)) {
25
+ throw new Error(`Could not read file, file path was not resolved, received ${JSON.stringify(filePath)}.`);
36
26
  }
37
-
38
27
  try {
39
- // By specifying encoding, readFile returns a string instead of a buffer.
40
- var file = yield readFilePromise(filePath, 'utf8');
41
- return file;
28
+ // By specifying encoding, readFile returns a string instead of a buffer.
29
+ const file = await readFilePromise(filePath, 'utf8');
30
+ return file;
42
31
  } catch (error) {
43
- if (error.code === 'ENOENT' || error.code === 'EISDIR') {
44
- return null;
45
- }
46
-
47
- throw error;
32
+ if (error.code === 'ENOENT' || error.code === 'EISDIR') {
33
+ return null;
34
+ }
35
+ throw error;
48
36
  }
49
- });
50
- return _readFile.apply(this, arguments);
51
37
  }
52
-
53
- var _default = readFile;
54
- exports.default = _default;
38
+ export default readFile;
@@ -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
@@ -1,62 +1,38 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
- var _fs = _interopRequireDefault(require("fs"));
9
-
10
- var _path = _interopRequireDefault(require("path"));
11
-
12
- var _util = require("util");
13
-
14
- var _helpers = require("@lowdefy/helpers");
15
-
16
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
-
18
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
19
-
20
- function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
21
-
22
- var mkdirPromise = (0, _util.promisify)(_fs.default.mkdir);
23
- var writeFilePromise = (0, _util.promisify)(_fs.default.writeFile);
24
-
25
- function writeFile(_x) {
26
- return _writeFile.apply(this, arguments);
27
- }
28
-
29
- function _writeFile() {
30
- _writeFile = _asyncToGenerator(function* (_ref) {
31
- var {
32
- filePath,
33
- content
34
- } = _ref;
35
-
36
- if (!_helpers.type.isString(filePath)) {
37
- throw new Error("Could not write file, file path should be a string, received ".concat(JSON.stringify(filePath), "."));
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 fs from 'fs';
16
+ import path from 'path';
17
+ import { promisify } from 'util';
18
+ import { type } from '@lowdefy/helpers';
19
+ const mkdirPromise = promisify(fs.mkdir);
20
+ const writeFilePromise = promisify(fs.writeFile);
21
+ async function writeFile({ filePath , content }) {
22
+ if (!type.isString(filePath)) {
23
+ throw new Error(`Could not write file, file path should be a string, received ${JSON.stringify(filePath)}.`);
38
24
  }
39
-
40
- if (filePath !== _path.default.resolve(filePath)) {
41
- throw new Error("Could not write file, file path was not resolved, received ".concat(JSON.stringify(filePath), "."));
42
- }
43
-
44
25
  try {
45
- yield writeFilePromise(filePath, content);
26
+ await writeFilePromise(path.resolve(filePath), content);
46
27
  } catch (error) {
47
- if (error.code === 'ENOENT') {
48
- yield mkdirPromise(_path.default.dirname(filePath), {
49
- recursive: true
50
- });
51
- yield writeFilePromise(filePath, content);
52
- return;
53
- }
54
-
55
- throw error;
28
+ if (error.code === 'ENOENT') {
29
+ await mkdirPromise(path.dirname(filePath), {
30
+ recursive: true
31
+ });
32
+ await writeFilePromise(filePath, content);
33
+ return;
34
+ }
35
+ throw error;
56
36
  }
57
- });
58
- return _writeFile.apply(this, arguments);
59
37
  }
60
-
61
- var _default = writeFile;
62
- exports.default = _default;
38
+ export default writeFile;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lowdefy/node-utils",
3
- "version": "3.23.2",
3
+ "version": "4.0.0-alpha.6",
4
4
  "licence": "Apache-2.0",
5
5
  "description": "",
6
6
  "homepage": "https://lowdefy.com",
@@ -25,30 +25,33 @@
25
25
  "type": "git",
26
26
  "url": "https://github.com/lowdefy/lowdefy.git"
27
27
  },
28
- "main": "dist/index.js",
28
+ "type": "module",
29
+ "exports": {
30
+ ".": "./dist/index.js",
31
+ "./*": "./dist/*"
32
+ },
29
33
  "files": [
30
34
  "dist/*"
31
35
  ],
32
36
  "scripts": {
33
- "build": "babel src --out-dir dist",
37
+ "build": "yarn swc",
34
38
  "clean": "rm -rf dist",
35
- "test": "jest --coverage",
36
- "prepare": "yarn build"
39
+ "prepare": "yarn build",
40
+ "swc": "swc src --out-dir dist --config-file ../../../.swcrc --delete-dir-on-start",
41
+ "test": "jest --coverage"
37
42
  },
38
43
  "dependencies": {
39
- "@lowdefy/helpers": "3.23.2",
44
+ "@lowdefy/helpers": "4.0.0-alpha.6",
40
45
  "rimraf": "3.0.2"
41
46
  },
42
47
  "devDependencies": {
43
- "@babel/cli": "7.14.3",
44
- "@babel/core": "7.14.3",
45
- "@babel/preset-env": "7.14.4",
46
- "babel-jest": "26.6.3",
47
- "jest": "26.6.3",
48
- "jest-diff": "26.6.2"
48
+ "@swc/cli": "0.1.55",
49
+ "@swc/core": "1.2.130",
50
+ "@swc/jest": "0.2.17",
51
+ "jest": "27.3.1"
49
52
  },
50
53
  "publishConfig": {
51
54
  "access": "public"
52
55
  },
53
- "gitHead": "4c30d3cdfa99ae4e90fc891825938c28bad45760"
56
+ "gitHead": "2530e31af795b6a3c75ac8f72c8dbe0ab5d1251b"
54
57
  }