@dlzn-ui/node-utils 0.0.1 → 1.63.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/dist/index.d.mts CHANGED
@@ -7,6 +7,8 @@ declare function execCommand<T extends () => Awaitable<any>>(fnc: T, overrideNam
7
7
  declare function getPackageDependencies(pkgPath: string): Record<'dependencies' | 'peerDependencies', string[]>;
8
8
  declare function getPackageManifest(pkgPath: string): ProjectManifest;
9
9
 
10
+ declare function run(command: string, cwd: string): Promise<void>;
11
+
10
12
  declare function upperFirst(str: string): string;
11
13
 
12
- export { errorAndExit, execCommand, getPackageDependencies, getPackageManifest, upperFirst };
14
+ export { errorAndExit, execCommand, getPackageDependencies, getPackageManifest, run, upperFirst };
package/dist/index.d.ts CHANGED
@@ -7,6 +7,8 @@ declare function execCommand<T extends () => Awaitable<any>>(fnc: T, overrideNam
7
7
  declare function getPackageDependencies(pkgPath: string): Record<'dependencies' | 'peerDependencies', string[]>;
8
8
  declare function getPackageManifest(pkgPath: string): ProjectManifest;
9
9
 
10
+ declare function run(command: string, cwd: string): Promise<void>;
11
+
10
12
  declare function upperFirst(str: string): string;
11
13
 
12
- export { errorAndExit, execCommand, getPackageDependencies, getPackageManifest, upperFirst };
14
+ export { errorAndExit, execCommand, getPackageDependencies, getPackageManifest, run, upperFirst };
package/dist/index.mjs CHANGED
@@ -3,6 +3,7 @@ import process from 'node:process';
3
3
  import { styleText } from 'node:util';
4
4
  import consola from 'consola';
5
5
  import { readFileSync } from 'node:fs';
6
+ import { spawn } from 'node:child_process';
6
7
 
7
8
  function errorAndExit(err) {
8
9
  consola.error(err);
@@ -34,8 +35,32 @@ function getPackageManifest(pkgPath) {
34
35
  return JSON.parse(readFileSync(pkgPath, "utf8"));
35
36
  }
36
37
 
38
+ async function run(command, cwd) {
39
+ return new Promise((resolve, reject) => {
40
+ const [cmd, ...args] = command.split(" ");
41
+ consola.info(`run: ${styleText("green", `${cmd} ${args.join(" ")}`)}`);
42
+ const app = spawn(cmd, args, {
43
+ cwd,
44
+ shell: process.platform === "win32",
45
+ stdio: "inherit"
46
+ });
47
+ const onProcessExit = () => app.kill("SIGHUP");
48
+ app.on("close", (code) => {
49
+ process.removeListener("exit", onProcessExit);
50
+ if (code === 0) {
51
+ resolve();
52
+ } else {
53
+ reject(new Error(`Command failed.
54
+ Command: ${command}
55
+ Code: ${code}`));
56
+ }
57
+ });
58
+ process.on("exit", onProcessExit);
59
+ });
60
+ }
61
+
37
62
  function upperFirst(str) {
38
63
  return str.charAt(0).toUpperCase() + str.slice(1);
39
64
  }
40
65
 
41
- export { errorAndExit, execCommand, getPackageDependencies, getPackageManifest, upperFirst };
66
+ export { errorAndExit, execCommand, getPackageDependencies, getPackageManifest, run, upperFirst };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@dlzn-ui/node-utils",
3
3
  "type": "module",
4
- "version": "0.0.1",
4
+ "version": "1.63.0",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
7
7
  "access": "public"
@@ -20,11 +20,13 @@
20
20
  "consola": "^3.4.2"
21
21
  },
22
22
  "devDependencies": {
23
+ "rimraf": "^6.1.3",
23
24
  "unbuild": "^3.6.1"
24
25
  },
25
26
  "scripts": {
26
27
  "build": "unbuild",
27
28
  "dev": "pnpm run stub",
29
+ "clean": "rimraf dist",
28
30
  "stub": "unbuild --stub"
29
31
  }
30
32
  }