ph-cmd 0.32.4 → 0.33.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.
@@ -0,0 +1,29 @@
1
+ // src/commands/init.ts
2
+ import { createProject, parseVersion } from "@powerhousedao/codegen";
3
+ var init = async (projectName, options) => {
4
+ console.log("Initializing a new project...");
5
+ try {
6
+ await createProject({
7
+ name: options.project ?? projectName,
8
+ interactive: options.interactive ?? false,
9
+ version: parseVersion(options),
10
+ packageManager: options.packageManager
11
+ });
12
+ } catch (error) {
13
+ console.error("Failed to initialize the project", error);
14
+ }
15
+ };
16
+ function initCommand(program) {
17
+ program.command("init").description("Initialize a new project").argument("[project-name]", "Name of the project").option("-p, --project", "Name of the project").option("-i, --interactive", "Run the command in interactive mode").option(
18
+ "-v, --version",
19
+ 'Specify development version to use. Defaults to "main"'
20
+ ).option("--dev", 'Use "development" version of the boilerplate').option("--staging", 'Use "development" version of the boilerplate').option(
21
+ "--package-manager <packageManager>",
22
+ "force package manager to use"
23
+ ).action(init);
24
+ }
25
+
26
+ export {
27
+ init,
28
+ initCommand
29
+ };
@@ -0,0 +1,43 @@
1
+ import {
2
+ forwardPHCommand,
3
+ getPackageManagerFromLockfile,
4
+ getProjectInfo
5
+ } from "./chunk-ZNKFHKHU.js";
6
+
7
+ // src/commands/forward.ts
8
+ var forwardCommand = (args, options) => {
9
+ if (options.debug) {
10
+ console.log(">>> command arguments:", { options });
11
+ }
12
+ const projectInfo = getProjectInfo(options.debug);
13
+ if (options.debug) {
14
+ console.log("\n>>> projectInfo:", projectInfo);
15
+ }
16
+ const packageManager = getPackageManagerFromLockfile(projectInfo.path);
17
+ if (options.debug) {
18
+ console.log("\n>>> forwardCommand arguments:");
19
+ console.log(">>> packageManager:", packageManager);
20
+ console.log(">>> projectPath:", projectInfo.path);
21
+ console.log(">>> args:", args);
22
+ console.log(">>> isPackageScript:", options.isPackageScript ?? false);
23
+ }
24
+ try {
25
+ forwardPHCommand(
26
+ packageManager,
27
+ projectInfo.path,
28
+ args,
29
+ options.isPackageScript ?? false,
30
+ options.debug
31
+ );
32
+ } catch (error) {
33
+ console.error("\u274C Failed to forward command");
34
+ if (error.code === "ENOENT") {
35
+ console.error("Have you run `ph setup-globals` or `ph init`?");
36
+ }
37
+ throw error;
38
+ }
39
+ };
40
+
41
+ export {
42
+ forwardCommand
43
+ };
@@ -0,0 +1,49 @@
1
+ import {
2
+ HOME_DIR,
3
+ PH_BIN_PATH,
4
+ PH_GLOBAL_PROJECT_NAME,
5
+ POWERHOUSE_GLOBAL_DIR,
6
+ getPackageManagerFromPath
7
+ } from "./chunk-ZNKFHKHU.js";
8
+
9
+ // src/commands/setup-globals.ts
10
+ import { createProject, parseVersion } from "@powerhousedao/codegen";
11
+ import fs from "node:fs";
12
+ var setupGlobals = async (projectName, options) => {
13
+ const globalProjectExists = fs.existsSync(POWERHOUSE_GLOBAL_DIR);
14
+ if (globalProjectExists) {
15
+ console.log(
16
+ `\u{1F4E6} Global project already exists at: ${POWERHOUSE_GLOBAL_DIR}`
17
+ );
18
+ return;
19
+ }
20
+ console.log("\u{1F4E6} Initializing global project...");
21
+ process.chdir(HOME_DIR);
22
+ try {
23
+ await createProject({
24
+ name: PH_GLOBAL_PROJECT_NAME,
25
+ interactive: false,
26
+ version: parseVersion(options),
27
+ packageManager: options.packageManager ?? getPackageManagerFromPath(PH_BIN_PATH)
28
+ });
29
+ console.log(
30
+ `\u{1F680} Global project initialized successfully: ${POWERHOUSE_GLOBAL_DIR}`
31
+ );
32
+ } catch (error) {
33
+ console.error("\u274C Failed to initialize the global project", error);
34
+ }
35
+ };
36
+ function setupGlobalsCommand(program) {
37
+ program.command("setup-globals").description("Initialize a new project").argument("[project-name]", "Name of the project").option("-p, --project", "Name of the project").option("-i, --interactive", "Run the command in interactive mode").option(
38
+ "-v, --version",
39
+ 'Specify development version to use. Defaults to "main"'
40
+ ).option("--dev", 'Use "development" version of the boilerplate').option("--staging", 'Use "development" version of the boilerplate').option(
41
+ "--package-manager <packageManager>",
42
+ "force package manager to use"
43
+ ).action(setupGlobals);
44
+ }
45
+
46
+ export {
47
+ setupGlobals,
48
+ setupGlobalsCommand
49
+ };
@@ -0,0 +1,17 @@
1
+ import {
2
+ initCommand
3
+ } from "./chunk-5HAGY755.js";
4
+ import {
5
+ setupGlobalsCommand
6
+ } from "./chunk-PRTJI6ZS.js";
7
+
8
+ // src/commands/index.ts
9
+ var commands = [setupGlobalsCommand, initCommand];
10
+ function registerCommands(program) {
11
+ commands.forEach((command) => command(program));
12
+ }
13
+
14
+ export {
15
+ commands,
16
+ registerCommands
17
+ };
@@ -0,0 +1,144 @@
1
+ // src/utils.ts
2
+ import { execSync } from "node:child_process";
3
+ import fs from "node:fs";
4
+ import { homedir } from "node:os";
5
+ import path, { dirname } from "node:path";
6
+ var PH_BIN_PATH = process.argv[1];
7
+ var PH_BIN = "ph-cli";
8
+ var PH_CLI_COMMANDS = [
9
+ "init",
10
+ "dev",
11
+ "connect",
12
+ "generate",
13
+ "reactor",
14
+ "switchboard",
15
+ "help",
16
+ "install",
17
+ "add",
18
+ "i",
19
+ "remove",
20
+ "uninstall",
21
+ "service"
22
+ ];
23
+ var POWERHOUSE_CONFIG_FILE = "powerhouse.config.json";
24
+ var HOME_DIR = homedir();
25
+ var PH_GLOBAL_PROJECT_NAME = ".ph";
26
+ var POWERHOUSE_GLOBAL_DIR = path.join(
27
+ HOME_DIR,
28
+ PH_GLOBAL_PROJECT_NAME
29
+ );
30
+ var packageManagers = {
31
+ bun: {
32
+ execCommand: `bun ${PH_BIN} {{arguments}}`,
33
+ execScript: `bun {{arguments}}`,
34
+ lockfile: "bun.lock",
35
+ globalPathRegexp: /[\\/].bun[\\/]/
36
+ },
37
+ pnpm: {
38
+ execCommand: `pnpm exec ${PH_BIN} {{arguments}}`,
39
+ execScript: `pnpm {{arguments}}`,
40
+ lockfile: "pnpm-lock.yaml",
41
+ globalPathRegexp: /[\\/]pnpm[\\/]/
42
+ },
43
+ yarn: {
44
+ execCommand: `yarn ${PH_BIN} {{arguments}}`,
45
+ execScript: `yarn {{arguments}}`,
46
+ lockfile: "yarn.lock",
47
+ globalPathRegexp: /[\\/]yarn[\\/]/
48
+ },
49
+ npm: {
50
+ execCommand: `npx ${PH_BIN} {{arguments}}`,
51
+ execScript: `npm run {{arguments}}`,
52
+ lockfile: "package-lock.json"
53
+ }
54
+ };
55
+ function defaultPathValidation() {
56
+ return true;
57
+ }
58
+ function isPowerhouseProject(dir) {
59
+ const powerhouseConfigPath = path.join(dir, POWERHOUSE_CONFIG_FILE);
60
+ return fs.existsSync(powerhouseConfigPath);
61
+ }
62
+ function findNodeProjectRoot(dir, pathValidation = defaultPathValidation) {
63
+ const packageJsonPath = path.join(dir, "package.json");
64
+ if (fs.existsSync(packageJsonPath) && pathValidation(dir)) {
65
+ return dir;
66
+ }
67
+ const parentDir = dirname(dir);
68
+ if (parentDir === dir) {
69
+ return null;
70
+ }
71
+ return findNodeProjectRoot(parentDir, pathValidation);
72
+ }
73
+ function getPackageManagerFromPath(dir) {
74
+ const lowerCasePath = dir.toLowerCase();
75
+ if (packageManagers.bun.globalPathRegexp.test(lowerCasePath)) {
76
+ return "bun";
77
+ } else if (packageManagers.pnpm.globalPathRegexp.test(lowerCasePath)) {
78
+ return "pnpm";
79
+ } else if (packageManagers.yarn.globalPathRegexp.test(lowerCasePath)) {
80
+ return "yarn";
81
+ }
82
+ return "npm";
83
+ }
84
+ function getPackageManagerFromLockfile(dir) {
85
+ if (fs.existsSync(path.join(dir, packageManagers.pnpm.lockfile))) {
86
+ return "pnpm";
87
+ } else if (fs.existsSync(path.join(dir, packageManagers.yarn.lockfile))) {
88
+ return "yarn";
89
+ } else if (fs.existsSync(path.join(dir, packageManagers.bun.lockfile))) {
90
+ return "bun";
91
+ }
92
+ return "npm";
93
+ }
94
+ function getProjectInfo(debug) {
95
+ const currentPath = process.cwd();
96
+ if (debug) {
97
+ console.log(">>> currentPath:", currentPath);
98
+ }
99
+ const projectPath = findNodeProjectRoot(currentPath, isPowerhouseProject);
100
+ if (!projectPath) {
101
+ return {
102
+ isGlobal: true,
103
+ path: POWERHOUSE_GLOBAL_DIR
104
+ };
105
+ }
106
+ return {
107
+ isGlobal: false,
108
+ path: projectPath
109
+ };
110
+ }
111
+ function forwardPHCommand(packageManager, projectPath, args, isPackageScript, debug) {
112
+ const manager = packageManagers[packageManager];
113
+ const command = isPackageScript ? manager.execScript : manager.execCommand;
114
+ const execCommand = command.replace("{{arguments}}", args);
115
+ const commandOptions = { cwd: projectPath };
116
+ if (debug) {
117
+ console.log(">>> execCommand:", execCommand);
118
+ console.log(">>> commandOptions:", commandOptions);
119
+ console.log(">>> projectPath:", projectPath);
120
+ console.log(">>> packageManager:", packageManager);
121
+ }
122
+ execSync(execCommand, {
123
+ stdio: "inherit",
124
+ ...commandOptions
125
+ });
126
+ }
127
+
128
+ export {
129
+ PH_BIN_PATH,
130
+ PH_BIN,
131
+ PH_CLI_COMMANDS,
132
+ POWERHOUSE_CONFIG_FILE,
133
+ HOME_DIR,
134
+ PH_GLOBAL_PROJECT_NAME,
135
+ POWERHOUSE_GLOBAL_DIR,
136
+ packageManagers,
137
+ defaultPathValidation,
138
+ isPowerhouseProject,
139
+ findNodeProjectRoot,
140
+ getPackageManagerFromPath,
141
+ getPackageManagerFromLockfile,
142
+ getProjectInfo,
143
+ forwardPHCommand
144
+ };
package/dist/cli.js CHANGED
@@ -1,13 +1,20 @@
1
1
  #!/usr/bin/env node
2
- import { Command } from 'commander';
3
- import { readPackageUpSync } from 'read-package-up';
4
- import registerCommands from './commands/index.js';
5
- import { forwardCommand } from './commands/forward.js';
6
- import { PH_CLI_COMMANDS } from './utils.js';
2
+ import {
3
+ forwardCommand
4
+ } from "./chunk-APQST5R3.js";
5
+ import {
6
+ registerCommands
7
+ } from "./chunk-TCTQ4POZ.js";
8
+ import "./chunk-5HAGY755.js";
9
+ import "./chunk-PRTJI6ZS.js";
10
+ import {
11
+ PH_CLI_COMMANDS
12
+ } from "./chunk-ZNKFHKHU.js";
7
13
 
8
- const pkg = readPackageUpSync();
9
- const program = new Command();
10
- const defaultCommand = (options) => {
14
+ // src/cli.ts
15
+ import { Command } from "commander";
16
+ var program = new Command();
17
+ var defaultCommand = (options) => {
11
18
  const allArgs = process.argv.slice(2);
12
19
  const filteredArgs = allArgs.filter((arg) => arg !== "--verbose").filter((arg) => arg !== "--script");
13
20
  const command = filteredArgs.at(0);
@@ -15,8 +22,6 @@ const defaultCommand = (options) => {
15
22
  const args = filteredArgs.join(" ");
16
23
  forwardCommand(args, { debug: !!options.verbose, isPackageScript });
17
24
  };
18
- program.name("ph-cmd").description("CLI tool for Powerhouse DAO").allowUnknownOption().option("--verbose", "Enable debug mode").option("--script", "Run the command as a package.json script").action(defaultCommand).version(pkg?.packageJson.version ?? "1.0.0");
25
+ program.name("ph-cmd").description("CLI tool for Powerhouse DAO").allowUnknownOption().option("--verbose", "Enable debug mode").option("--script", "Run the command as a package.json script").action(defaultCommand).version("0.33.0");
19
26
  registerCommands(program);
20
27
  program.parse(process.argv);
21
- //# sourceMappingURL=cli.js.map
22
- //# sourceMappingURL=cli.js.map
@@ -1,38 +1,7 @@
1
- import { getProjectInfo, getPackageManagerFromLockfile, forwardPHCommand } from '../utils.js';
2
-
3
- const forwardCommand = (args, options) => {
4
- if (options.debug) {
5
- console.log(">>> command arguments:", { options });
6
- }
7
- const projectInfo = getProjectInfo(options.debug);
8
- if (options.debug) {
9
- console.log("\n>>> projectInfo:", projectInfo);
10
- }
11
- const packageManager = getPackageManagerFromLockfile(projectInfo.path);
12
- if (options.debug) {
13
- console.log("\n>>> forwardCommand arguments:");
14
- console.log(">>> packageManager:", packageManager);
15
- console.log(">>> projectPath:", projectInfo.path);
16
- console.log(">>> args:", args);
17
- console.log(">>> isPackageScript:", options.isPackageScript ?? false);
18
- }
19
- try {
20
- forwardPHCommand(
21
- packageManager,
22
- projectInfo.path,
23
- args,
24
- options.isPackageScript ?? false,
25
- options.debug
26
- );
27
- } catch (error) {
28
- console.error("\u274C Failed to forward command");
29
- if (error.code === "ENOENT") {
30
- console.error("Have you run `ph setup-globals` or `ph init`?");
31
- }
32
- throw error;
33
- }
1
+ import {
2
+ forwardCommand
3
+ } from "../chunk-APQST5R3.js";
4
+ import "../chunk-ZNKFHKHU.js";
5
+ export {
6
+ forwardCommand
34
7
  };
35
-
36
- export { forwardCommand };
37
- //# sourceMappingURL=forward.js.map
38
- //# sourceMappingURL=forward.js.map
@@ -1,11 +1,21 @@
1
- import { setupGlobalsCommand } from './setup-globals.js';
2
- export * from './setup-globals.js';
3
-
4
- const commands = [setupGlobalsCommand];
5
- function registerCommands(program) {
6
- commands.forEach((command) => command(program));
7
- }
8
-
9
- export { commands, registerCommands as default };
10
- //# sourceMappingURL=index.js.map
11
- //# sourceMappingURL=index.js.map
1
+ import {
2
+ commands,
3
+ registerCommands
4
+ } from "../chunk-TCTQ4POZ.js";
5
+ import {
6
+ init,
7
+ initCommand
8
+ } from "../chunk-5HAGY755.js";
9
+ import {
10
+ setupGlobals,
11
+ setupGlobalsCommand
12
+ } from "../chunk-PRTJI6ZS.js";
13
+ import "../chunk-ZNKFHKHU.js";
14
+ export {
15
+ commands,
16
+ registerCommands as default,
17
+ init,
18
+ initCommand,
19
+ setupGlobals,
20
+ setupGlobalsCommand
21
+ };
@@ -0,0 +1,8 @@
1
+ import {
2
+ init,
3
+ initCommand
4
+ } from "../chunk-5HAGY755.js";
5
+ export {
6
+ init,
7
+ initCommand
8
+ };
@@ -1,41 +1,9 @@
1
- import { createProject, parseVersion } from '@powerhousedao/codegen';
2
- import fs from 'node:fs';
3
- import { POWERHOUSE_GLOBAL_DIR, HOME_DIR, PH_GLOBAL_PROJECT_NAME, getPackageManagerFromPath, PH_BIN_PATH } from '../utils.js';
4
-
5
- const init = async (projectName, options) => {
6
- const globalProjectExists = fs.existsSync(POWERHOUSE_GLOBAL_DIR);
7
- if (globalProjectExists) {
8
- console.log(
9
- `\u{1F4E6} Global project already exists at: ${POWERHOUSE_GLOBAL_DIR}`
10
- );
11
- return;
12
- }
13
- console.log("\u{1F4E6} Initializing global project...");
14
- process.chdir(HOME_DIR);
15
- try {
16
- await createProject({
17
- name: PH_GLOBAL_PROJECT_NAME,
18
- interactive: false,
19
- version: parseVersion(options),
20
- packageManager: options.packageManager ?? getPackageManagerFromPath(PH_BIN_PATH)
21
- });
22
- console.log(
23
- `\u{1F680} Global project initialized successfully: ${POWERHOUSE_GLOBAL_DIR}`
24
- );
25
- } catch (error) {
26
- console.error("\u274C Failed to initialize the global project", error);
27
- }
1
+ import {
2
+ setupGlobals,
3
+ setupGlobalsCommand
4
+ } from "../chunk-PRTJI6ZS.js";
5
+ import "../chunk-ZNKFHKHU.js";
6
+ export {
7
+ setupGlobals,
8
+ setupGlobalsCommand
28
9
  };
29
- function setupGlobalsCommand(program) {
30
- program.command("setup-globals").description("Initialize a new project").argument("[project-name]", "Name of the project").option("-p, --project", "Name of the project").option("-i, --interactive", "Run the command in interactive mode").option(
31
- "-v, --version",
32
- 'Specify development version to use. Defaults to "main"'
33
- ).option("--dev", 'Use "development" version of the boilerplate').option("--staging", 'Use "development" version of the boilerplate').option(
34
- "--package-manager <packageManager>",
35
- "force package manager to use"
36
- ).action(init);
37
- }
38
-
39
- export { init, setupGlobalsCommand };
40
- //# sourceMappingURL=setup-globals.js.map
41
- //# sourceMappingURL=setup-globals.js.map
package/dist/index.js CHANGED
@@ -1,4 +1,50 @@
1
- export * from './commands/index.js';
2
- export * from './utils.js';
3
- //# sourceMappingURL=index.js.map
4
- //# sourceMappingURL=index.js.map
1
+ import {
2
+ commands
3
+ } from "./chunk-TCTQ4POZ.js";
4
+ import {
5
+ init,
6
+ initCommand
7
+ } from "./chunk-5HAGY755.js";
8
+ import {
9
+ setupGlobals,
10
+ setupGlobalsCommand
11
+ } from "./chunk-PRTJI6ZS.js";
12
+ import {
13
+ HOME_DIR,
14
+ PH_BIN,
15
+ PH_BIN_PATH,
16
+ PH_CLI_COMMANDS,
17
+ PH_GLOBAL_PROJECT_NAME,
18
+ POWERHOUSE_CONFIG_FILE,
19
+ POWERHOUSE_GLOBAL_DIR,
20
+ defaultPathValidation,
21
+ findNodeProjectRoot,
22
+ forwardPHCommand,
23
+ getPackageManagerFromLockfile,
24
+ getPackageManagerFromPath,
25
+ getProjectInfo,
26
+ isPowerhouseProject,
27
+ packageManagers
28
+ } from "./chunk-ZNKFHKHU.js";
29
+ export {
30
+ HOME_DIR,
31
+ PH_BIN,
32
+ PH_BIN_PATH,
33
+ PH_CLI_COMMANDS,
34
+ PH_GLOBAL_PROJECT_NAME,
35
+ POWERHOUSE_CONFIG_FILE,
36
+ POWERHOUSE_GLOBAL_DIR,
37
+ commands,
38
+ defaultPathValidation,
39
+ findNodeProjectRoot,
40
+ forwardPHCommand,
41
+ getPackageManagerFromLockfile,
42
+ getPackageManagerFromPath,
43
+ getProjectInfo,
44
+ init,
45
+ initCommand,
46
+ isPowerhouseProject,
47
+ packageManagers,
48
+ setupGlobals,
49
+ setupGlobalsCommand
50
+ };
package/dist/types.js CHANGED
@@ -1,3 +0,0 @@
1
-
2
- //# sourceMappingURL=types.js.map
3
- //# sourceMappingURL=types.js.map
package/dist/utils.js CHANGED
@@ -1,125 +1,34 @@
1
- import path, { dirname } from 'node:path';
2
- import fs from 'node:fs';
3
- import { execSync } from 'node:child_process';
4
- import { homedir } from 'node:os';
5
-
6
- const PH_BIN_PATH = process.argv[1];
7
- const PH_BIN = "ph-cli";
8
- const PH_CLI_COMMANDS = [
9
- "init",
10
- "dev",
11
- "connect",
12
- "generate",
13
- "reactor",
14
- "help",
15
- "install",
16
- "service"
17
- ];
18
- const POWERHOUSE_CONFIG_FILE = "powerhouse.config.json";
19
- const HOME_DIR = homedir();
20
- const PH_GLOBAL_PROJECT_NAME = ".ph";
21
- const POWERHOUSE_GLOBAL_DIR = path.join(
1
+ import {
22
2
  HOME_DIR,
23
- PH_GLOBAL_PROJECT_NAME
24
- );
25
- const packageManagers = {
26
- bun: {
27
- execCommand: `bun ${PH_BIN} {{arguments}}`,
28
- execScript: `bun {{arguments}}`,
29
- lockfile: "bun.lock",
30
- globalPathRegexp: /[\\/].bun[\\/]/
31
- },
32
- pnpm: {
33
- execCommand: `pnpm exec ${PH_BIN} {{arguments}}`,
34
- execScript: `pnpm {{arguments}}`,
35
- lockfile: "pnpm-lock.yaml",
36
- globalPathRegexp: /[\\/]pnpm[\\/]/
37
- },
38
- yarn: {
39
- execCommand: `yarn ${PH_BIN} {{arguments}}`,
40
- execScript: `yarn {{arguments}}`,
41
- lockfile: "yarn.lock",
42
- globalPathRegexp: /[\\/]yarn[\\/]/
43
- },
44
- npm: {
45
- execCommand: `npx ${PH_BIN} {{arguments}}`,
46
- execScript: `npm run {{arguments}}`,
47
- lockfile: "package-lock.json"
48
- }
3
+ PH_BIN,
4
+ PH_BIN_PATH,
5
+ PH_CLI_COMMANDS,
6
+ PH_GLOBAL_PROJECT_NAME,
7
+ POWERHOUSE_CONFIG_FILE,
8
+ POWERHOUSE_GLOBAL_DIR,
9
+ defaultPathValidation,
10
+ findNodeProjectRoot,
11
+ forwardPHCommand,
12
+ getPackageManagerFromLockfile,
13
+ getPackageManagerFromPath,
14
+ getProjectInfo,
15
+ isPowerhouseProject,
16
+ packageManagers
17
+ } from "./chunk-ZNKFHKHU.js";
18
+ export {
19
+ HOME_DIR,
20
+ PH_BIN,
21
+ PH_BIN_PATH,
22
+ PH_CLI_COMMANDS,
23
+ PH_GLOBAL_PROJECT_NAME,
24
+ POWERHOUSE_CONFIG_FILE,
25
+ POWERHOUSE_GLOBAL_DIR,
26
+ defaultPathValidation,
27
+ findNodeProjectRoot,
28
+ forwardPHCommand,
29
+ getPackageManagerFromLockfile,
30
+ getPackageManagerFromPath,
31
+ getProjectInfo,
32
+ isPowerhouseProject,
33
+ packageManagers
49
34
  };
50
- function defaultPathValidation() {
51
- return true;
52
- }
53
- function isPowerhouseProject(dir) {
54
- const powerhouseConfigPath = path.join(dir, POWERHOUSE_CONFIG_FILE);
55
- return fs.existsSync(powerhouseConfigPath);
56
- }
57
- function findNodeProjectRoot(dir, pathValidation = defaultPathValidation) {
58
- const packageJsonPath = path.join(dir, "package.json");
59
- if (fs.existsSync(packageJsonPath) && pathValidation(dir)) {
60
- return dir;
61
- }
62
- const parentDir = dirname(dir);
63
- if (parentDir === dir) {
64
- return null;
65
- }
66
- return findNodeProjectRoot(parentDir, pathValidation);
67
- }
68
- function getPackageManagerFromPath(dir) {
69
- const lowerCasePath = dir.toLowerCase();
70
- if (packageManagers.bun.globalPathRegexp.test(lowerCasePath)) {
71
- return "bun";
72
- } else if (packageManagers.pnpm.globalPathRegexp.test(lowerCasePath)) {
73
- return "pnpm";
74
- } else if (packageManagers.yarn.globalPathRegexp.test(lowerCasePath)) {
75
- return "yarn";
76
- }
77
- return "npm";
78
- }
79
- function getPackageManagerFromLockfile(dir) {
80
- if (fs.existsSync(path.join(dir, packageManagers.pnpm.lockfile))) {
81
- return "pnpm";
82
- } else if (fs.existsSync(path.join(dir, packageManagers.yarn.lockfile))) {
83
- return "yarn";
84
- } else if (fs.existsSync(path.join(dir, packageManagers.bun.lockfile))) {
85
- return "bun";
86
- }
87
- return "npm";
88
- }
89
- function getProjectInfo(debug) {
90
- const currentPath = process.cwd();
91
- if (debug) {
92
- console.log(">>> currentPath:", currentPath);
93
- }
94
- const projectPath = findNodeProjectRoot(currentPath, isPowerhouseProject);
95
- if (!projectPath) {
96
- return {
97
- isGlobal: true,
98
- path: POWERHOUSE_GLOBAL_DIR
99
- };
100
- }
101
- return {
102
- isGlobal: false,
103
- path: projectPath
104
- };
105
- }
106
- function forwardPHCommand(packageManager, projectPath, args, isPackageScript, debug) {
107
- const manager = packageManagers[packageManager];
108
- const command = isPackageScript ? manager.execScript : manager.execCommand;
109
- const execCommand = command.replace("{{arguments}}", args);
110
- const commandOptions = { cwd: projectPath };
111
- if (debug) {
112
- console.log(">>> execCommand:", execCommand);
113
- console.log(">>> commandOptions:", commandOptions);
114
- console.log(">>> projectPath:", projectPath);
115
- console.log(">>> packageManager:", packageManager);
116
- }
117
- execSync(execCommand, {
118
- stdio: "inherit",
119
- ...commandOptions
120
- });
121
- }
122
-
123
- export { HOME_DIR, PH_BIN, PH_BIN_PATH, PH_CLI_COMMANDS, PH_GLOBAL_PROJECT_NAME, POWERHOUSE_CONFIG_FILE, POWERHOUSE_GLOBAL_DIR, defaultPathValidation, findNodeProjectRoot, forwardPHCommand, getPackageManagerFromLockfile, getPackageManagerFromPath, getProjectInfo, isPowerhouseProject, packageManagers };
124
- //# sourceMappingURL=utils.js.map
125
- //# sourceMappingURL=utils.js.map
package/package.json CHANGED
@@ -1,22 +1,15 @@
1
1
  {
2
2
  "name": "ph-cmd",
3
- "version": "0.32.4",
3
+ "version": "0.33.0",
4
4
  "description": "",
5
5
  "license": "AGPL-3.0-only",
6
6
  "type": "module",
7
- "main": "dist/index.js",
8
- "types": "dist/index.d.ts",
9
7
  "publishConfig": {
10
8
  "access": "public"
11
9
  },
12
10
  "bin": {
13
11
  "ph": "dist/cli.js"
14
12
  },
15
- "exports": {
16
- ".": "./dist/index.js",
17
- "./cli": "./dist/cli.js",
18
- "./utils": "./dist/utils.js"
19
- },
20
13
  "files": [
21
14
  "dist"
22
15
  ],
@@ -24,9 +17,8 @@
24
17
  "author": "",
25
18
  "dependencies": {
26
19
  "commander": "^12.1.0",
27
- "read-package-up": "^11.0.0",
28
- "@powerhousedao/codegen": "0.32.1",
29
- "@powerhousedao/scalars": "1.21.0"
20
+ "@powerhousedao/codegen": "0.33.0",
21
+ "@powerhousedao/scalars": "1.22.0"
30
22
  },
31
23
  "scripts": {
32
24
  "build": "tsup",
package/dist/cli.d.ts DELETED
@@ -1 +0,0 @@
1
- #!/usr/bin/env node
package/dist/cli.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/cli.ts"],"names":[],"mappings":";;;;;;;AASA,MAAM,MAAM,iBAAkB,EAAA;AAE9B,MAAM,OAAA,GAAU,IAAI,OAAQ,EAAA;AAE5B,MAAM,cAAA,GAEF,CAAC,OAAY,KAAA;AACf,EAAA,MAAM,OAAU,GAAA,OAAA,CAAQ,IAAK,CAAA,KAAA,CAAM,CAAC,CAAA;AACpC,EAAA,MAAM,YAAe,GAAA,OAAA,CAClB,MAAO,CAAA,CAAC,GAAQ,KAAA,GAAA,KAAQ,WAAW,CAAA,CACnC,MAAO,CAAA,CAAC,GAAQ,KAAA,GAAA,KAAQ,UAAU,CAAA;AACrC,EAAM,MAAA,OAAA,GAAU,YAAa,CAAA,EAAA,CAAG,CAAC,CAAA;AAEjC,EAAA,MAAM,kBACJ,OAAQ,CAAA,MAAA,IAAU,CAAC,eAAgB,CAAA,QAAA,CAAS,WAAW,EAAE,CAAA;AAC3D,EAAM,MAAA,IAAA,GAAO,YAAa,CAAA,IAAA,CAAK,GAAG,CAAA;AAElC,EAAe,cAAA,CAAA,IAAA,EAAM,EAAE,KAAO,EAAA,CAAC,CAAC,OAAQ,CAAA,OAAA,EAAS,iBAAiB,CAAA;AACpE,CAAA;AAEA,OACG,CAAA,IAAA,CAAK,QAAQ,CACb,CAAA,WAAA,CAAY,6BAA6B,CACzC,CAAA,kBAAA,EACA,CAAA,MAAA,CAAO,WAAa,EAAA,mBAAmB,EACvC,MAAO,CAAA,UAAA,EAAY,0CAA0C,CAAA,CAC7D,MAAO,CAAA,cAAc,EACrB,OAAQ,CAAA,GAAA,EAAK,WAAY,CAAA,OAAA,IAAW,OAAO,CAAA;AAE9C,gBAAA,CAAiB,OAAO,CAAA;AAExB,OAAQ,CAAA,KAAA,CAAM,QAAQ,IAAI,CAAA","file":"cli.js","sourcesContent":["#!/usr/bin/env node\nimport { Command } from \"commander\";\nimport { readPackageUpSync } from \"read-package-up\";\n\nimport registerCommands from \"./commands/index.js\";\nimport { forwardCommand } from \"./commands/forward.js\";\nimport { CommandActionType } from \"./types.js\";\nimport { PH_CLI_COMMANDS } from \"./utils.js\";\n\nconst pkg = readPackageUpSync();\n\nconst program = new Command();\n\nconst defaultCommand: CommandActionType<\n [{ verbose?: boolean; script?: boolean }]\n> = (options) => {\n const allArgs = process.argv.slice(2);\n const filteredArgs = allArgs\n .filter((arg) => arg !== \"--verbose\")\n .filter((arg) => arg !== \"--script\");\n const command = filteredArgs.at(0);\n\n const isPackageScript =\n options.script ?? !PH_CLI_COMMANDS.includes(command ?? \"\");\n const args = filteredArgs.join(\" \");\n\n forwardCommand(args, { debug: !!options.verbose, isPackageScript });\n};\n\nprogram\n .name(\"ph-cmd\")\n .description(\"CLI tool for Powerhouse DAO\")\n .allowUnknownOption()\n .option(\"--verbose\", \"Enable debug mode\")\n .option(\"--script\", \"Run the command as a package.json script\")\n .action(defaultCommand)\n .version(pkg?.packageJson.version ?? \"1.0.0\");\n\nregisterCommands(program);\n\nprogram.parse(process.argv);\n"]}
@@ -1,7 +0,0 @@
1
- type ForwardPHCommandOptions = {
2
- debug?: boolean;
3
- isPackageScript?: boolean;
4
- };
5
- declare const forwardCommand: (args: string, options: ForwardPHCommandOptions) => void;
6
-
7
- export { forwardCommand };
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/commands/forward.ts"],"names":[],"mappings":";;AAea,MAAA,cAAA,GAAiB,CAC5B,IAAA,EACA,OACG,KAAA;AACH,EAAA,IAAI,QAAQ,KAAO,EAAA;AACjB,IAAA,OAAA,CAAQ,GAAI,CAAA,wBAAA,EAA0B,EAAE,OAAA,EAAS,CAAA;AAAA;AAGnD,EAAM,MAAA,WAAA,GAAc,cAAe,CAAA,OAAA,CAAQ,KAAK,CAAA;AAEhD,EAAA,IAAI,QAAQ,KAAO,EAAA;AACjB,IAAQ,OAAA,CAAA,GAAA,CAAI,sBAAsB,WAAW,CAAA;AAAA;AAG/C,EAAM,MAAA,cAAA,GAAiB,6BAA8B,CAAA,WAAA,CAAY,IAAI,CAAA;AAErE,EAAA,IAAI,QAAQ,KAAO,EAAA;AACjB,IAAA,OAAA,CAAQ,IAAI,iCAAiC,CAAA;AAC7C,IAAQ,OAAA,CAAA,GAAA,CAAI,uBAAuB,cAAc,CAAA;AACjD,IAAQ,OAAA,CAAA,GAAA,CAAI,kBAAoB,EAAA,WAAA,CAAY,IAAI,CAAA;AAChD,IAAQ,OAAA,CAAA,GAAA,CAAI,aAAa,IAAI,CAAA;AAC7B,IAAA,OAAA,CAAQ,GAAI,CAAA,sBAAA,EAAwB,OAAQ,CAAA,eAAA,IAAmB,KAAK,CAAA;AAAA;AAGtE,EAAI,IAAA;AACF,IAAA,gBAAA;AAAA,MACE,cAAA;AAAA,MACA,WAAY,CAAA,IAAA;AAAA,MACZ,IAAA;AAAA,MACA,QAAQ,eAAmB,IAAA,KAAA;AAAA,MAC3B,OAAQ,CAAA;AAAA,KACV;AAAA,WACO,KAAO,EAAA;AACd,IAAA,OAAA,CAAQ,MAAM,kCAA6B,CAAA;AAC3C,IAAK,IAAA,KAAA,CAAkB,SAAS,QAAU,EAAA;AACxC,MAAA,OAAA,CAAQ,MAAM,+CAA+C,CAAA;AAAA;AAG/D,IAAM,MAAA,KAAA;AAAA;AAEV","file":"forward.js","sourcesContent":["import {\n getProjectInfo,\n getPackageManagerFromLockfile,\n forwardPHCommand,\n} from \"../utils.js\";\n\ntype ForwardPHCommandOptions = {\n debug?: boolean;\n isPackageScript?: boolean;\n};\n\ntype FSError = {\n code: string;\n};\n\nexport const forwardCommand = (\n args: string,\n options: ForwardPHCommandOptions,\n) => {\n if (options.debug) {\n console.log(\">>> command arguments:\", { options });\n }\n\n const projectInfo = getProjectInfo(options.debug);\n\n if (options.debug) {\n console.log(\"\\n>>> projectInfo:\", projectInfo);\n }\n\n const packageManager = getPackageManagerFromLockfile(projectInfo.path);\n\n if (options.debug) {\n console.log(\"\\n>>> forwardCommand arguments:\");\n console.log(\">>> packageManager:\", packageManager);\n console.log(\">>> projectPath:\", projectInfo.path);\n console.log(\">>> args:\", args);\n console.log(\">>> isPackageScript:\", options.isPackageScript ?? false);\n }\n\n try {\n forwardPHCommand(\n packageManager,\n projectInfo.path,\n args,\n options.isPackageScript ?? false,\n options.debug,\n );\n } catch (error) {\n console.error(\"❌ Failed to forward command\");\n if ((error as FSError).code === \"ENOENT\") {\n console.error(\"Have you run `ph setup-globals` or `ph init`?\");\n }\n\n throw error;\n }\n};\n"]}
@@ -1,9 +0,0 @@
1
- import { Command } from 'commander';
2
- import { setupGlobalsCommand } from './setup-globals.js';
3
- export { init } from './setup-globals.js';
4
- import '../types.js';
5
-
6
- declare const commands: (typeof setupGlobalsCommand)[];
7
- declare function registerCommands(program: Command): void;
8
-
9
- export { commands, registerCommands as default, setupGlobalsCommand };
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/commands/index.ts"],"names":[],"mappings":";;;AAGa,MAAA,QAAA,GAAW,CAAC,mBAAmB;AAE7B,SAAR,iBAAkC,OAAkB,EAAA;AACzD,EAAA,QAAA,CAAS,OAAQ,CAAA,CAAC,OAAY,KAAA,OAAA,CAAQ,OAAO,CAAC,CAAA;AAChD","file":"index.js","sourcesContent":["import { Command } from \"commander\";\nimport { setupGlobalsCommand } from \"./setup-globals.js\";\n\nexport const commands = [setupGlobalsCommand];\n\nexport default function registerCommands(program: Command) {\n commands.forEach((command) => command(program));\n}\n\nexport * from \"./setup-globals.js\";\n"]}
@@ -1,17 +0,0 @@
1
- import { Command } from 'commander';
2
- import { CommandActionType } from '../types.js';
3
-
4
- declare const init: CommandActionType<[
5
- string | undefined,
6
- {
7
- project?: string;
8
- interactive?: boolean;
9
- version?: string;
10
- dev?: boolean;
11
- staging?: boolean;
12
- packageManager?: string;
13
- }
14
- ]>;
15
- declare function setupGlobalsCommand(program: Command): void;
16
-
17
- export { init, setupGlobalsCommand };
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/commands/setup-globals.ts"],"names":[],"mappings":";;;;AAYa,MAAA,IAAA,GAYT,OAAO,WAAA,EAAa,OAAY,KAAA;AAElC,EAAM,MAAA,mBAAA,GAAsB,EAAG,CAAA,UAAA,CAAW,qBAAqB,CAAA;AAE/D,EAAA,IAAI,mBAAqB,EAAA;AACvB,IAAQ,OAAA,CAAA,GAAA;AAAA,MACN,+CAAwC,qBAAqB,CAAA;AAAA,KAC/D;AACA,IAAA;AAAA;AAGF,EAAA,OAAA,CAAQ,IAAI,0CAAmC,CAAA;AAC/C,EAAA,OAAA,CAAQ,MAAM,QAAQ,CAAA;AAEtB,EAAI,IAAA;AACF,IAAA,MAAM,aAAc,CAAA;AAAA,MAClB,IAAM,EAAA,sBAAA;AAAA,MACN,WAAa,EAAA,KAAA;AAAA,MACb,OAAA,EAAS,aAAa,OAAO,CAAA;AAAA,MAC7B,cACE,EAAA,OAAA,CAAQ,cAAkB,IAAA,yBAAA,CAA0B,WAAW;AAAA,KAClE,CAAA;AAED,IAAQ,OAAA,CAAA,GAAA;AAAA,MACN,sDAA+C,qBAAqB,CAAA;AAAA,KACtE;AAAA,WACO,KAAO,EAAA;AACd,IAAQ,OAAA,CAAA,KAAA,CAAM,kDAA6C,KAAK,CAAA;AAAA;AAEpE;AAEO,SAAS,oBAAoB,OAAkB,EAAA;AACpD,EAAA,OAAA,CACG,QAAQ,eAAe,CAAA,CACvB,WAAY,CAAA,0BAA0B,EACtC,QAAS,CAAA,gBAAA,EAAkB,qBAAqB,CAAA,CAChD,OAAO,eAAiB,EAAA,qBAAqB,EAC7C,MAAO,CAAA,mBAAA,EAAqB,qCAAqC,CACjE,CAAA,MAAA;AAAA,IACC,eAAA;AAAA,IACA;AAAA,GACF,CACC,OAAO,OAAS,EAAA,8CAA8C,EAC9D,MAAO,CAAA,WAAA,EAAa,8CAA8C,CAClE,CAAA,MAAA;AAAA,IACC,oCAAA;AAAA,IACA;AAAA,GACF,CACC,OAAO,IAAI,CAAA;AAChB","file":"setup-globals.js","sourcesContent":["import { Command } from \"commander\";\nimport { createProject, parseVersion } from \"@powerhousedao/codegen\";\nimport fs from \"node:fs\";\nimport { CommandActionType } from \"../types.js\";\nimport {\n HOME_DIR,\n POWERHOUSE_GLOBAL_DIR,\n PH_GLOBAL_PROJECT_NAME,\n getPackageManagerFromPath,\n PH_BIN_PATH,\n} from \"../utils.js\";\n\nexport const init: CommandActionType<\n [\n string | undefined,\n {\n project?: string;\n interactive?: boolean;\n version?: string;\n dev?: boolean;\n staging?: boolean;\n packageManager?: string;\n },\n ]\n> = async (projectName, options) => {\n // check if the global project already exists\n const globalProjectExists = fs.existsSync(POWERHOUSE_GLOBAL_DIR);\n\n if (globalProjectExists) {\n console.log(\n `📦 Global project already exists at: ${POWERHOUSE_GLOBAL_DIR}`,\n );\n return;\n }\n\n console.log(\"📦 Initializing global project...\");\n process.chdir(HOME_DIR);\n\n try {\n await createProject({\n name: PH_GLOBAL_PROJECT_NAME,\n interactive: false,\n version: parseVersion(options),\n packageManager:\n options.packageManager ?? getPackageManagerFromPath(PH_BIN_PATH),\n });\n\n console.log(\n `🚀 Global project initialized successfully: ${POWERHOUSE_GLOBAL_DIR}`,\n );\n } catch (error) {\n console.error(\"❌ Failed to initialize the global project\", error);\n }\n};\n\nexport function setupGlobalsCommand(program: Command) {\n program\n .command(\"setup-globals\")\n .description(\"Initialize a new project\")\n .argument(\"[project-name]\", \"Name of the project\")\n .option(\"-p, --project\", \"Name of the project\")\n .option(\"-i, --interactive\", \"Run the command in interactive mode\")\n .option(\n \"-v, --version\",\n 'Specify development version to use. Defaults to \"main\"',\n )\n .option(\"--dev\", 'Use \"development\" version of the boilerplate')\n .option(\"--staging\", 'Use \"development\" version of the boilerplate')\n .option(\n \"--package-manager <packageManager>\",\n \"force package manager to use\",\n )\n .action(init);\n}\n"]}
package/dist/index.d.ts DELETED
@@ -1,5 +0,0 @@
1
- export { commands } from './commands/index.js';
2
- export { HOME_DIR, PH_BIN, PH_BIN_PATH, PH_CLI_COMMANDS, PH_GLOBAL_PROJECT_NAME, POWERHOUSE_CONFIG_FILE, POWERHOUSE_GLOBAL_DIR, PackageManager, ProjectInfo, defaultPathValidation, findNodeProjectRoot, forwardPHCommand, getPackageManagerFromLockfile, getPackageManagerFromPath, getProjectInfo, isPowerhouseProject, packageManagers } from './utils.js';
3
- export { init, setupGlobalsCommand } from './commands/setup-globals.js';
4
- import 'commander';
5
- import './types.js';
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"sources":[],"names":[],"mappings":"","file":"index.js","sourcesContent":[]}
package/dist/types.d.ts DELETED
@@ -1,3 +0,0 @@
1
- type CommandActionType<Args extends any[], Return = void> = (...args: Args) => Return | Promise<Return>;
2
-
3
- export type { CommandActionType };
package/dist/types.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"sources":[],"names":[],"mappings":"","file":"types.js"}
package/dist/utils.d.ts DELETED
@@ -1,47 +0,0 @@
1
- declare const PH_BIN_PATH: string;
2
- declare const PH_BIN = "ph-cli";
3
- declare const PH_CLI_COMMANDS: string[];
4
- declare const POWERHOUSE_CONFIG_FILE = "powerhouse.config.json";
5
- declare const HOME_DIR: string;
6
- declare const PH_GLOBAL_PROJECT_NAME = ".ph";
7
- declare const POWERHOUSE_GLOBAL_DIR: string;
8
- declare const packageManagers: {
9
- readonly bun: {
10
- readonly execCommand: "bun ph-cli {{arguments}}";
11
- readonly execScript: "bun {{arguments}}";
12
- readonly lockfile: "bun.lock";
13
- readonly globalPathRegexp: RegExp;
14
- };
15
- readonly pnpm: {
16
- readonly execCommand: "pnpm exec ph-cli {{arguments}}";
17
- readonly execScript: "pnpm {{arguments}}";
18
- readonly lockfile: "pnpm-lock.yaml";
19
- readonly globalPathRegexp: RegExp;
20
- };
21
- readonly yarn: {
22
- readonly execCommand: "yarn ph-cli {{arguments}}";
23
- readonly execScript: "yarn {{arguments}}";
24
- readonly lockfile: "yarn.lock";
25
- readonly globalPathRegexp: RegExp;
26
- };
27
- readonly npm: {
28
- readonly execCommand: "npx ph-cli {{arguments}}";
29
- readonly execScript: "npm run {{arguments}}";
30
- readonly lockfile: "package-lock.json";
31
- };
32
- };
33
- type ProjectInfo = {
34
- isGlobal: boolean;
35
- path: string;
36
- };
37
- type PackageManager = "npm" | "yarn" | "pnpm" | "bun";
38
- type PathValidation = (dir: string) => boolean;
39
- declare function defaultPathValidation(): boolean;
40
- declare function isPowerhouseProject(dir: string): boolean;
41
- declare function findNodeProjectRoot(dir: string, pathValidation?: PathValidation): string | null;
42
- declare function getPackageManagerFromPath(dir: string): PackageManager;
43
- declare function getPackageManagerFromLockfile(dir: string): PackageManager;
44
- declare function getProjectInfo(debug?: boolean): ProjectInfo;
45
- declare function forwardPHCommand(packageManager: PackageManager, projectPath: string, args: string, isPackageScript: boolean, debug?: boolean): void;
46
-
47
- export { HOME_DIR, PH_BIN, PH_BIN_PATH, PH_CLI_COMMANDS, PH_GLOBAL_PROJECT_NAME, POWERHOUSE_CONFIG_FILE, POWERHOUSE_GLOBAL_DIR, type PackageManager, type ProjectInfo, defaultPathValidation, findNodeProjectRoot, forwardPHCommand, getPackageManagerFromLockfile, getPackageManagerFromPath, getProjectInfo, isPowerhouseProject, packageManagers };
package/dist/utils.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/utils.ts"],"names":[],"mappings":"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","file":"utils.js","sourcesContent":["import path, { dirname } from \"node:path\";\nimport fs from \"node:fs\";\nimport { execSync } from \"node:child_process\";\nimport { homedir } from \"node:os\";\n\nexport const PH_BIN_PATH = process.argv[1];\nexport const PH_BIN = \"ph-cli\";\nexport const PH_CLI_COMMANDS = [\n \"init\",\n \"dev\",\n \"connect\",\n \"generate\",\n \"reactor\",\n \"help\",\n \"install\",\n \"service\",\n];\nexport const POWERHOUSE_CONFIG_FILE = \"powerhouse.config.json\";\nexport const HOME_DIR = homedir();\nexport const PH_GLOBAL_PROJECT_NAME = \".ph\";\nexport const POWERHOUSE_GLOBAL_DIR = path.join(\n HOME_DIR,\n PH_GLOBAL_PROJECT_NAME,\n);\n\nexport const packageManagers = {\n bun: {\n execCommand: `bun ${PH_BIN} {{arguments}}`,\n execScript: `bun {{arguments}}`,\n lockfile: \"bun.lock\",\n globalPathRegexp: /[\\\\/].bun[\\\\/]/,\n },\n pnpm: {\n execCommand: `pnpm exec ${PH_BIN} {{arguments}}`,\n execScript: `pnpm {{arguments}}`,\n lockfile: \"pnpm-lock.yaml\",\n globalPathRegexp: /[\\\\/]pnpm[\\\\/]/,\n },\n yarn: {\n execCommand: `yarn ${PH_BIN} {{arguments}}`,\n execScript: `yarn {{arguments}}`,\n lockfile: \"yarn.lock\",\n globalPathRegexp: /[\\\\/]yarn[\\\\/]/,\n },\n npm: {\n execCommand: `npx ${PH_BIN} {{arguments}}`,\n execScript: `npm run {{arguments}}`,\n lockfile: \"package-lock.json\",\n },\n} as const;\n\nexport type ProjectInfo = {\n isGlobal: boolean;\n path: string;\n};\n\nexport type PackageManager = \"npm\" | \"yarn\" | \"pnpm\" | \"bun\";\n\ntype PathValidation = (dir: string) => boolean;\n\nexport function defaultPathValidation() {\n return true;\n}\n\nexport function isPowerhouseProject(dir: string) {\n const powerhouseConfigPath = path.join(dir, POWERHOUSE_CONFIG_FILE);\n\n return fs.existsSync(powerhouseConfigPath);\n}\n\nexport function findNodeProjectRoot(\n dir: string,\n pathValidation: PathValidation = defaultPathValidation,\n) {\n const packageJsonPath = path.join(dir, \"package.json\");\n\n if (fs.existsSync(packageJsonPath) && pathValidation(dir)) {\n return dir;\n }\n\n const parentDir = dirname(dir);\n\n if (parentDir === dir) {\n return null;\n }\n\n return findNodeProjectRoot(parentDir, pathValidation);\n}\n\nexport function getPackageManagerFromPath(dir: string): PackageManager {\n const lowerCasePath = dir.toLowerCase();\n\n if (packageManagers.bun.globalPathRegexp.test(lowerCasePath)) {\n return \"bun\";\n } else if (packageManagers.pnpm.globalPathRegexp.test(lowerCasePath)) {\n return \"pnpm\";\n } else if (packageManagers.yarn.globalPathRegexp.test(lowerCasePath)) {\n return \"yarn\";\n }\n\n return \"npm\";\n}\n\nexport function getPackageManagerFromLockfile(dir: string): PackageManager {\n if (fs.existsSync(path.join(dir, packageManagers.pnpm.lockfile))) {\n return \"pnpm\";\n } else if (fs.existsSync(path.join(dir, packageManagers.yarn.lockfile))) {\n return \"yarn\";\n } else if (fs.existsSync(path.join(dir, packageManagers.bun.lockfile))) {\n return \"bun\";\n }\n\n return \"npm\";\n}\n\nexport function getProjectInfo(debug?: boolean): ProjectInfo {\n const currentPath = process.cwd();\n\n if (debug) {\n console.log(\">>> currentPath:\", currentPath);\n }\n\n const projectPath = findNodeProjectRoot(currentPath, isPowerhouseProject);\n\n if (!projectPath) {\n return {\n isGlobal: true,\n path: POWERHOUSE_GLOBAL_DIR,\n };\n }\n\n return {\n isGlobal: false,\n path: projectPath,\n };\n}\n\nexport function forwardPHCommand(\n packageManager: PackageManager,\n projectPath: string,\n args: string,\n isPackageScript: boolean,\n debug?: boolean,\n) {\n const manager = packageManagers[packageManager];\n const command = isPackageScript ? manager.execScript : manager.execCommand;\n\n const execCommand = command.replace(\"{{arguments}}\", args);\n\n const commandOptions = { cwd: projectPath };\n\n if (debug) {\n console.log(\">>> execCommand:\", execCommand);\n console.log(\">>> commandOptions:\", commandOptions);\n console.log(\">>> projectPath:\", projectPath);\n console.log(\">>> packageManager:\", packageManager);\n }\n\n execSync(execCommand, {\n stdio: \"inherit\",\n ...commandOptions,\n });\n}\n"]}