@embeddable.com/sdk-utils 0.0.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/lib/findFiles.d.ts +2 -0
- package/lib/index.cjs.js +59 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.esm.js +56 -0
- package/lib/runProcess.d.ts +2 -0
- package/package.json +15 -0
package/lib/index.cjs.js
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var promises = require('node:fs/promises');
|
|
4
|
+
var node_path = require('node:path');
|
|
5
|
+
var node_child_process = require('node:child_process');
|
|
6
|
+
|
|
7
|
+
var findFiles = async (initialSrcDir, regex) => {
|
|
8
|
+
const filesList = [];
|
|
9
|
+
async function findFilesRec(srcDir) {
|
|
10
|
+
const allFiles = await promises.readdir(srcDir);
|
|
11
|
+
for (const file of allFiles) {
|
|
12
|
+
const filePath = node_path.join(srcDir, file);
|
|
13
|
+
const status = await promises.lstat(filePath);
|
|
14
|
+
if (status.isDirectory()) {
|
|
15
|
+
await findFilesRec(filePath);
|
|
16
|
+
}
|
|
17
|
+
const fileName = file.match(regex);
|
|
18
|
+
if (fileName) {
|
|
19
|
+
filesList.push([fileName[1], filePath]);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
await findFilesRec(initialSrcDir);
|
|
24
|
+
return filesList;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
var runProcess = async ({ processFile, ctx, initMessage, successMessage, failMessage, }) => {
|
|
28
|
+
const ora = (await import('ora')).default;
|
|
29
|
+
const spinner = ora(initMessage).start();
|
|
30
|
+
try {
|
|
31
|
+
await promisifyForkedProcess(processFile, ctx);
|
|
32
|
+
spinner.succeed(successMessage);
|
|
33
|
+
}
|
|
34
|
+
catch (error) {
|
|
35
|
+
spinner.fail(failMessage);
|
|
36
|
+
console.error(error);
|
|
37
|
+
// await core.globalCleanup(ctx);
|
|
38
|
+
process.exit(1);
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
function promisifyForkedProcess(filePath, ctx) {
|
|
42
|
+
const forkedProcess = node_child_process.fork(filePath, [], process.env.NODE_ENV === "dev" ? undefined : { silent: true });
|
|
43
|
+
forkedProcess.send({ ctx });
|
|
44
|
+
return new Promise((resolve, reject) => {
|
|
45
|
+
forkedProcess.on("exit", (code) => {
|
|
46
|
+
if (code === 0)
|
|
47
|
+
resolve();
|
|
48
|
+
});
|
|
49
|
+
// @ts-ignore
|
|
50
|
+
forkedProcess.on("message", ({ error }) => {
|
|
51
|
+
if (!error)
|
|
52
|
+
return;
|
|
53
|
+
reject(error);
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
exports.findFiles = findFiles;
|
|
59
|
+
exports.runProcess = runProcess;
|
package/lib/index.d.ts
ADDED
package/lib/index.esm.js
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { readdir, lstat } from 'node:fs/promises';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { fork } from 'node:child_process';
|
|
4
|
+
|
|
5
|
+
var findFiles = async (initialSrcDir, regex) => {
|
|
6
|
+
const filesList = [];
|
|
7
|
+
async function findFilesRec(srcDir) {
|
|
8
|
+
const allFiles = await readdir(srcDir);
|
|
9
|
+
for (const file of allFiles) {
|
|
10
|
+
const filePath = join(srcDir, file);
|
|
11
|
+
const status = await lstat(filePath);
|
|
12
|
+
if (status.isDirectory()) {
|
|
13
|
+
await findFilesRec(filePath);
|
|
14
|
+
}
|
|
15
|
+
const fileName = file.match(regex);
|
|
16
|
+
if (fileName) {
|
|
17
|
+
filesList.push([fileName[1], filePath]);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
await findFilesRec(initialSrcDir);
|
|
22
|
+
return filesList;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
var runProcess = async ({ processFile, ctx, initMessage, successMessage, failMessage, }) => {
|
|
26
|
+
const ora = (await import('ora')).default;
|
|
27
|
+
const spinner = ora(initMessage).start();
|
|
28
|
+
try {
|
|
29
|
+
await promisifyForkedProcess(processFile, ctx);
|
|
30
|
+
spinner.succeed(successMessage);
|
|
31
|
+
}
|
|
32
|
+
catch (error) {
|
|
33
|
+
spinner.fail(failMessage);
|
|
34
|
+
console.error(error);
|
|
35
|
+
// await core.globalCleanup(ctx);
|
|
36
|
+
process.exit(1);
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
function promisifyForkedProcess(filePath, ctx) {
|
|
40
|
+
const forkedProcess = fork(filePath, [], process.env.NODE_ENV === "dev" ? undefined : { silent: true });
|
|
41
|
+
forkedProcess.send({ ctx });
|
|
42
|
+
return new Promise((resolve, reject) => {
|
|
43
|
+
forkedProcess.on("exit", (code) => {
|
|
44
|
+
if (code === 0)
|
|
45
|
+
resolve();
|
|
46
|
+
});
|
|
47
|
+
// @ts-ignore
|
|
48
|
+
forkedProcess.on("message", ({ error }) => {
|
|
49
|
+
if (!error)
|
|
50
|
+
return;
|
|
51
|
+
reject(error);
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export { findFiles, runProcess };
|
package/package.json
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@embeddable.com/sdk-utils",
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"description": "Internal SDK utilities",
|
|
5
|
+
"main": "lib/index.cjs.js",
|
|
6
|
+
"module": "lib/index.esm.js",
|
|
7
|
+
"types": "lib/index.d.ts",
|
|
8
|
+
"files": ["lib/"],
|
|
9
|
+
"scripts": {
|
|
10
|
+
"build": "rollup -c"
|
|
11
|
+
},
|
|
12
|
+
"keywords": [],
|
|
13
|
+
"author": "Oleg Kapustin <oleg@trevor.io>",
|
|
14
|
+
"license": "MIT"
|
|
15
|
+
}
|