@schilderlabs/pitown 0.1.2 → 0.2.1

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.
@@ -0,0 +1,61 @@
1
+ import { realpathSync } from "node:fs";
2
+ import { resolve } from "node:path";
3
+ import { spawnSync } from "node:child_process";
4
+ import { fileURLToPath } from "node:url";
5
+
6
+ //#region ../core/src/shell.ts
7
+ function runCommandSync(command, args, options) {
8
+ const result = spawnSync(command, args, {
9
+ cwd: options?.cwd,
10
+ env: options?.env,
11
+ encoding: "utf-8"
12
+ });
13
+ const errorText = result.error instanceof Error ? `${result.error.message}
14
+ ` : "";
15
+ return {
16
+ stdout: result.stdout ?? "",
17
+ stderr: `${errorText}${result.stderr ?? ""}`,
18
+ exitCode: result.status ?? 1
19
+ };
20
+ }
21
+ function assertCommandAvailable(command) {
22
+ const result = spawnSync(command, ["--help"], {
23
+ encoding: "utf-8",
24
+ stdio: "ignore"
25
+ });
26
+ if (result.error instanceof Error) throw new Error(result.error.message);
27
+ }
28
+ function runCommandInteractive(command, args, options) {
29
+ const result = spawnSync(command, args, {
30
+ cwd: options?.cwd,
31
+ env: options?.env,
32
+ stdio: "inherit"
33
+ });
34
+ if (result.error instanceof Error) throw new Error(result.error.message);
35
+ return result.status ?? 1;
36
+ }
37
+ function assertSuccess(result, context) {
38
+ if (result.exitCode === 0) return;
39
+ const details = [result.stdout.trim(), result.stderr.trim()].filter(Boolean).join("\n");
40
+ throw new Error(`${context} failed${details ? `\n${details}` : ""}`);
41
+ }
42
+
43
+ //#endregion
44
+ //#region src/entrypoint.ts
45
+ function normalizePath(path) {
46
+ if (!path) return null;
47
+ try {
48
+ return realpathSync(path);
49
+ } catch {
50
+ return resolve(path);
51
+ }
52
+ }
53
+ function isDirectExecution(fileUrl, argv1 = process.argv[1]) {
54
+ const modulePath = normalizePath(fileURLToPath(fileUrl));
55
+ const invokedPath = normalizePath(argv1);
56
+ return modulePath !== null && invokedPath !== null && modulePath === invokedPath;
57
+ }
58
+
59
+ //#endregion
60
+ export { runCommandSync as a, runCommandInteractive as i, assertCommandAvailable as n, assertSuccess as r, isDirectExecution as t };
61
+ //# sourceMappingURL=entrypoint-CyJDLudQ.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"entrypoint-CyJDLudQ.mjs","names":[],"sources":["../../core/src/shell.ts","../src/entrypoint.ts"],"sourcesContent":["import { spawnSync } from \"node:child_process\"\n\nexport interface CommandResult {\n\tstdout: string\n\tstderr: string\n\texitCode: number\n}\n\nexport function runCommandSync(\n\tcommand: string,\n\targs: string[],\n\toptions?: { cwd?: string; env?: NodeJS.ProcessEnv },\n): CommandResult {\n\tconst result = spawnSync(command, args, {\n\t\tcwd: options?.cwd,\n\t\tenv: options?.env,\n\t\tencoding: \"utf-8\",\n\t})\n\tconst errorText = result.error instanceof Error ? `${result.error.message}\n` : \"\"\n\n\treturn {\n\t\tstdout: result.stdout ?? \"\",\n\t\tstderr: `${errorText}${result.stderr ?? \"\"}`,\n\t\texitCode: result.status ?? 1,\n\t}\n}\n\nexport function assertCommandAvailable(command: string) {\n\tconst result = spawnSync(command, [\"--help\"], {\n\t\tencoding: \"utf-8\",\n\t\tstdio: \"ignore\",\n\t})\n\n\tif (result.error instanceof Error) {\n\t\tthrow new Error(result.error.message)\n\t}\n}\n\nexport function runCommandInteractive(\n\tcommand: string,\n\targs: string[],\n\toptions?: { cwd?: string; env?: NodeJS.ProcessEnv },\n): number {\n\tconst result = spawnSync(command, args, {\n\t\tcwd: options?.cwd,\n\t\tenv: options?.env,\n\t\tstdio: \"inherit\",\n\t})\n\n\tif (result.error instanceof Error) {\n\t\tthrow new Error(result.error.message)\n\t}\n\n\treturn result.status ?? 1\n}\n\nexport function assertSuccess(result: CommandResult, context: string) {\n\tif (result.exitCode === 0) return\n\tconst details = [result.stdout.trim(), result.stderr.trim()].filter(Boolean).join(\"\\n\")\n\tthrow new Error(`${context} failed${details ? `\\n${details}` : \"\"}`)\n}\n","import { realpathSync } from \"node:fs\"\nimport { resolve } from \"node:path\"\nimport { fileURLToPath } from \"node:url\"\n\nfunction normalizePath(path: string | undefined): string | null {\n\tif (!path) return null\n\ttry {\n\t\treturn realpathSync(path)\n\t} catch {\n\t\treturn resolve(path)\n\t}\n}\n\nexport function isDirectExecution(fileUrl: string, argv1 = process.argv[1]): boolean {\n\tconst modulePath = normalizePath(fileURLToPath(fileUrl))\n\tconst invokedPath = normalizePath(argv1)\n\treturn modulePath !== null && invokedPath !== null && modulePath === invokedPath\n}\n"],"mappings":";;;;;;AAQA,SAAgB,eACf,SACA,MACA,SACgB;CAChB,MAAM,SAAS,UAAU,SAAS,MAAM;EACvC,KAAK,SAAS;EACd,KAAK,SAAS;EACd,UAAU;EACV,CAAC;CACF,MAAM,YAAY,OAAO,iBAAiB,QAAQ,GAAG,OAAO,MAAM,QAAQ;IACvE;AAEH,QAAO;EACN,QAAQ,OAAO,UAAU;EACzB,QAAQ,GAAG,YAAY,OAAO,UAAU;EACxC,UAAU,OAAO,UAAU;EAC3B;;AAGF,SAAgB,uBAAuB,SAAiB;CACvD,MAAM,SAAS,UAAU,SAAS,CAAC,SAAS,EAAE;EAC7C,UAAU;EACV,OAAO;EACP,CAAC;AAEF,KAAI,OAAO,iBAAiB,MAC3B,OAAM,IAAI,MAAM,OAAO,MAAM,QAAQ;;AAIvC,SAAgB,sBACf,SACA,MACA,SACS;CACT,MAAM,SAAS,UAAU,SAAS,MAAM;EACvC,KAAK,SAAS;EACd,KAAK,SAAS;EACd,OAAO;EACP,CAAC;AAEF,KAAI,OAAO,iBAAiB,MAC3B,OAAM,IAAI,MAAM,OAAO,MAAM,QAAQ;AAGtC,QAAO,OAAO,UAAU;;AAGzB,SAAgB,cAAc,QAAuB,SAAiB;AACrE,KAAI,OAAO,aAAa,EAAG;CAC3B,MAAM,UAAU,CAAC,OAAO,OAAO,MAAM,EAAE,OAAO,OAAO,MAAM,CAAC,CAAC,OAAO,QAAQ,CAAC,KAAK,KAAK;AACvF,OAAM,IAAI,MAAM,GAAG,QAAQ,SAAS,UAAU,KAAK,YAAY,KAAK;;;;;ACxDrE,SAAS,cAAc,MAAyC;AAC/D,KAAI,CAAC,KAAM,QAAO;AAClB,KAAI;AACH,SAAO,aAAa,KAAK;SAClB;AACP,SAAO,QAAQ,KAAK;;;AAItB,SAAgB,kBAAkB,SAAiB,QAAQ,QAAQ,KAAK,IAAa;CACpF,MAAM,aAAa,cAAc,cAAc,QAAQ,CAAC;CACxD,MAAM,cAAc,cAAc,MAAM;AACxC,QAAO,eAAe,QAAQ,gBAAgB,QAAQ,eAAe"}
package/dist/index.d.mts CHANGED
@@ -1,5 +1,5 @@
1
1
  //#region src/index.d.ts
2
- declare function printHelp(): void;
2
+ declare function printHelp(showAdvanced?: boolean): void;
3
3
  declare function runCli(argv?: string[]): void;
4
4
  //#endregion
5
5
  export { printHelp, runCli };