ph-cmd 5.0.0-staging.9 → 5.0.1-staging.10

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.
Files changed (85) hide show
  1. package/README.md +7 -2
  2. package/dist/src/cli.js +12 -0
  3. package/dist/src/cli.js.map +1 -1
  4. package/dist/src/commands/__tests__/update.test.js.map +1 -1
  5. package/dist/src/commands/__tests__/use.test.js +43 -24
  6. package/dist/src/commands/__tests__/use.test.js.map +1 -1
  7. package/dist/src/commands/checkout.d.ts +9 -0
  8. package/dist/src/commands/checkout.d.ts.map +1 -0
  9. package/dist/src/commands/checkout.js +37 -0
  10. package/dist/src/commands/checkout.js.map +1 -0
  11. package/dist/src/commands/forward.d.ts.map +1 -1
  12. package/dist/src/commands/forward.js +5 -2
  13. package/dist/src/commands/forward.js.map +1 -1
  14. package/dist/src/commands/help.d.ts +1 -1
  15. package/dist/src/commands/help.d.ts.map +1 -1
  16. package/dist/src/commands/index.d.ts +8 -1
  17. package/dist/src/commands/index.d.ts.map +1 -1
  18. package/dist/src/commands/index.js +3 -0
  19. package/dist/src/commands/index.js.map +1 -1
  20. package/dist/src/commands/init.d.ts +4 -2
  21. package/dist/src/commands/init.d.ts.map +1 -1
  22. package/dist/src/commands/init.js +44 -8
  23. package/dist/src/commands/init.js.map +1 -1
  24. package/dist/src/commands/setup-globals.d.ts +3 -2
  25. package/dist/src/commands/setup-globals.d.ts.map +1 -1
  26. package/dist/src/commands/setup-globals.js +2 -1
  27. package/dist/src/commands/setup-globals.js.map +1 -1
  28. package/dist/src/commands/update.d.ts +2 -2
  29. package/dist/src/commands/update.d.ts.map +1 -1
  30. package/dist/src/commands/update.js +1 -1
  31. package/dist/src/commands/update.js.map +1 -1
  32. package/dist/src/commands/use.d.ts +3 -3
  33. package/dist/src/commands/use.d.ts.map +1 -1
  34. package/dist/src/commands/use.js +2 -1
  35. package/dist/src/commands/use.js.map +1 -1
  36. package/dist/src/commands/version.d.ts +1 -1
  37. package/dist/src/commands/version.d.ts.map +1 -1
  38. package/dist/src/commands/version.js +1 -0
  39. package/dist/src/commands/version.js.map +1 -1
  40. package/dist/src/help.d.ts +5 -1
  41. package/dist/src/help.d.ts.map +1 -1
  42. package/dist/src/help.js +37 -4
  43. package/dist/src/help.js.map +1 -1
  44. package/dist/src/utils/constants.d.ts +53 -0
  45. package/dist/src/utils/constants.d.ts.map +1 -0
  46. package/dist/src/utils/constants.js +72 -0
  47. package/dist/src/utils/constants.js.map +1 -0
  48. package/dist/src/utils/dependencies.d.ts +4 -0
  49. package/dist/src/utils/dependencies.d.ts.map +1 -0
  50. package/dist/src/utils/dependencies.js +61 -0
  51. package/dist/src/utils/dependencies.js.map +1 -0
  52. package/dist/src/utils/help-formatting.d.ts +1 -1
  53. package/dist/src/utils/help-formatting.d.ts.map +1 -1
  54. package/dist/src/utils/help-formatting.js +1 -1
  55. package/dist/src/utils/help-formatting.js.map +1 -1
  56. package/dist/src/utils/help.d.ts +31 -0
  57. package/dist/src/utils/help.d.ts.map +1 -0
  58. package/dist/src/utils/help.js +72 -0
  59. package/dist/src/utils/help.js.map +1 -0
  60. package/dist/src/utils/index.d.ts +6 -130
  61. package/dist/src/utils/index.d.ts.map +1 -1
  62. package/dist/src/utils/index.js +5 -367
  63. package/dist/src/utils/index.js.map +1 -1
  64. package/dist/src/utils/package-manager.d.ts +34 -0
  65. package/dist/src/utils/package-manager.d.ts.map +1 -0
  66. package/dist/src/utils/package-manager.js +175 -0
  67. package/dist/src/utils/package-manager.js.map +1 -0
  68. package/dist/src/utils/types.d.ts +21 -0
  69. package/dist/src/utils/types.d.ts.map +1 -0
  70. package/dist/src/utils/types.js +2 -0
  71. package/dist/src/utils/types.js.map +1 -0
  72. package/dist/src/utils/validate-remote-drive-checkout.d.ts +7 -0
  73. package/dist/src/utils/validate-remote-drive-checkout.d.ts.map +1 -0
  74. package/dist/src/utils/validate-remote-drive-checkout.js +45 -0
  75. package/dist/src/utils/validate-remote-drive-checkout.js.map +1 -0
  76. package/dist/src/utils/validate-remote-drive.d.ts +6 -0
  77. package/dist/src/utils/validate-remote-drive.d.ts.map +1 -0
  78. package/dist/src/utils/validate-remote-drive.js +37 -0
  79. package/dist/src/utils/validate-remote-drive.js.map +1 -0
  80. package/dist/tsconfig.tsbuildinfo +1 -1
  81. package/package.json +10 -11
  82. package/dist/src/version.d.ts +0 -2
  83. package/dist/src/version.d.ts.map +0 -1
  84. package/dist/src/version.js +0 -3
  85. package/dist/src/version.js.map +0 -1
@@ -0,0 +1,72 @@
1
+ /**
2
+ * Helper to handle help flag detection for commands
3
+ * This centralizes the pattern of checking for help flags and showing command-specific help
4
+ *
5
+ * @param command - The Command instance
6
+ * @param actionFn - The original action function to call if help is not requested
7
+ * @returns A wrapped action function
8
+ */
9
+ export function withHelpHandler(command, actionFn) {
10
+ return (...args) => {
11
+ // Check if help was requested
12
+ const rawArgs = process.argv;
13
+ const isHelpRequested = rawArgs.includes("--help") || rawArgs.includes("-h");
14
+ // If help was explicitly requested, show the help and exit
15
+ if (isHelpRequested) {
16
+ command.outputHelp();
17
+ process.exit(0);
18
+ }
19
+ // Otherwise, run the original action
20
+ return actionFn(...args);
21
+ };
22
+ }
23
+ /**
24
+ * Simplified utility to connect a command with an action function that includes help handling
25
+ * This reduces boilerplate in command files by automatically setting up the action with help handling
26
+ *
27
+ * @param command - The Command instance
28
+ * @param actionFn - The action function to call when the command is executed
29
+ * @param preCheck - Optional validation function that runs before the action
30
+ * @returns The command for chaining
31
+ */
32
+ export function withHelpAction(command, actionFn, preCheck) {
33
+ command.action(withHelpHandler(command, (...args) => {
34
+ // If there's a pre-check function, run it before the action
35
+ if (preCheck) {
36
+ const result = preCheck(...args);
37
+ // If the pre-check returns false explicitly, don't run the action
38
+ if (result === false)
39
+ return;
40
+ }
41
+ return actionFn(...args);
42
+ }));
43
+ return command;
44
+ }
45
+ /**
46
+ * Enhanced version of withHelpAction that allows custom help text without duplication
47
+ *
48
+ * @param command - The Command instance
49
+ * @param actionFn - The action function to call when the command is executed
50
+ * @param helpText - The custom help text to display (replacing the auto-generated help)
51
+ * @param preCheck - Optional validation function that runs before the action
52
+ * @returns The command for chaining
53
+ */
54
+ export function withCustomHelp(command, actionFn, helpText, preCheck) {
55
+ // Clear any existing help text
56
+ command.helpInformation = function () {
57
+ const name = command.name();
58
+ const args = command.usage();
59
+ const description = command.description();
60
+ // Create a minimal header
61
+ let header = `\nUsage: ph ${name}`;
62
+ if (args)
63
+ header += ` ${args}`;
64
+ if (description)
65
+ header += `\n\n${description}\n`;
66
+ // Return the custom help text
67
+ return header + "\n" + helpText;
68
+ };
69
+ // Add help action handler
70
+ return withHelpAction(command, actionFn, preCheck);
71
+ }
72
+ //# sourceMappingURL=help.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"help.js","sourceRoot":"","sources":["../../../src/utils/help.ts"],"names":[],"mappings":"AAEA;;;;;;;GAOG;AACH,MAAM,UAAU,eAAe,CAC7B,OAAgB,EAChB,QAA8C;IAE9C,OAAO,CAAC,GAAG,IAAO,EAAE,EAAE;QACpB,8BAA8B;QAC9B,MAAM,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;QAC7B,MAAM,eAAe,GACnB,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;QAEvD,2DAA2D;QAC3D,IAAI,eAAe,EAAE,CAAC;YACpB,OAAO,CAAC,UAAU,EAAE,CAAC;YACrB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC;QAED,qCAAqC;QACrC,OAAO,QAAQ,CAAC,GAAG,IAAI,CAAC,CAAC;IAC3B,CAAC,CAAC;AACJ,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,cAAc,CAC5B,OAAgB,EAChB,QAA8C,EAC9C,QAA8C;IAE9C,OAAO,CAAC,MAAM,CACZ,eAAe,CAAI,OAAO,EAAE,CAAC,GAAG,IAAO,EAAE,EAAE;QACzC,4DAA4D;QAC5D,IAAI,QAAQ,EAAE,CAAC;YACb,MAAM,MAAM,GAAG,QAAQ,CAAC,GAAG,IAAI,CAAC,CAAC;YACjC,kEAAkE;YAClE,IAAI,MAAM,KAAK,KAAK;gBAAE,OAAO;QAC/B,CAAC;QAED,OAAO,QAAQ,CAAC,GAAG,IAAI,CAAC,CAAC;IAC3B,CAAC,CAAC,CACH,CAAC;IAEF,OAAO,OAAO,CAAC;AACjB,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,cAAc,CAC5B,OAAgB,EAChB,QAA8C,EAC9C,QAAgB,EAChB,QAA8C;IAE9C,+BAA+B;IAC/B,OAAO,CAAC,eAAe,GAAG;QACxB,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;QAC5B,MAAM,IAAI,GAAG,OAAO,CAAC,KAAK,EAAE,CAAC;QAC7B,MAAM,WAAW,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC;QAE1C,0BAA0B;QAC1B,IAAI,MAAM,GAAG,eAAe,IAAI,EAAE,CAAC;QACnC,IAAI,IAAI;YAAE,MAAM,IAAI,IAAI,IAAI,EAAE,CAAC;QAC/B,IAAI,WAAW;YAAE,MAAM,IAAI,OAAO,WAAW,IAAI,CAAC;QAElD,8BAA8B;QAC9B,OAAO,MAAM,GAAG,IAAI,GAAG,QAAQ,CAAC;IAClC,CAAC,CAAC;IAEF,0BAA0B;IAC1B,OAAO,cAAc,CAAC,OAAO,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC;AACrD,CAAC"}
@@ -1,132 +1,8 @@
1
- import { type Command } from "commander";
1
+ export * from "./constants.js";
2
+ export * from "./dependencies.js";
2
3
  export * from "./help-formatting.js";
3
- export declare const PH_BIN_PATH: string;
4
- export declare const PH_BIN = "ph-cli";
5
- export declare const PH_CLI_COMMANDS: string[];
6
- export declare const POWERHOUSE_CONFIG_FILE = "powerhouse.config.json";
7
- export declare const HOME_DIR: string;
8
- export declare const PH_GLOBAL_PROJECT_NAME = ".ph";
9
- export declare const POWERHOUSE_GLOBAL_DIR: string;
10
- export declare function resolvePackageManagerOptions(options: {
11
- packageManager?: string;
12
- pnpm?: boolean;
13
- yarn?: boolean;
14
- bun?: boolean;
15
- }): string | undefined;
16
- export declare const packageManagers: {
17
- readonly bun: {
18
- readonly installCommand: "bun add {{dependency}}";
19
- readonly execCommand: "bun ph-cli {{arguments}}";
20
- readonly execScript: "bun {{arguments}}";
21
- readonly lockfile: "bun.lock";
22
- readonly globalPathRegexp: RegExp;
23
- readonly updateCommand: "bun update {{dependency}}";
24
- readonly buildAffected: "bun run build:affected";
25
- readonly workspaceOption: "";
26
- readonly installDepsCommand: "bun install";
27
- };
28
- readonly pnpm: {
29
- readonly installCommand: "pnpm add {{dependency}}";
30
- readonly execCommand: "pnpm exec ph-cli {{arguments}}";
31
- readonly execScript: "pnpm {{arguments}}";
32
- readonly lockfile: "pnpm-lock.yaml";
33
- readonly globalPathRegexp: RegExp;
34
- readonly updateCommand: "pnpm update {{dependency}}";
35
- readonly buildAffected: "pnpm run build:affected";
36
- readonly workspaceOption: "--workspace-root";
37
- readonly installDepsCommand: "pnpm install";
38
- };
39
- readonly yarn: {
40
- readonly installCommand: "yarn add {{dependency}}";
41
- readonly execCommand: "yarn ph-cli {{arguments}}";
42
- readonly execScript: "yarn {{arguments}}";
43
- readonly lockfile: "yarn.lock";
44
- readonly globalPathRegexp: RegExp;
45
- readonly updateCommand: "yarn upgrade {{dependency}}";
46
- readonly buildAffected: "yarn run build:affected";
47
- readonly workspaceOption: "-W";
48
- readonly installDepsCommand: "yarn install";
49
- };
50
- readonly npm: {
51
- readonly installCommand: "npm install {{dependency}}";
52
- readonly execCommand: "npx ph-cli {{arguments}}";
53
- readonly execScript: "npm run {{arguments}}";
54
- readonly lockfile: "package-lock.json";
55
- readonly updateCommand: "npm update {{dependency}} --save";
56
- readonly buildAffected: "npm run build:affected";
57
- readonly workspaceOption: "";
58
- readonly installDepsCommand: "npm install";
59
- };
60
- };
61
- export type ProjectInfo = {
62
- isGlobal: boolean;
63
- available: boolean;
64
- path: string;
65
- };
66
- export type PackageManager = "npm" | "yarn" | "pnpm" | "bun";
67
- type PathValidation = (dir: string) => boolean;
68
- export declare function defaultPathValidation(): boolean;
69
- export declare function isPowerhouseProject(dir: string): boolean;
70
- export declare function findNodeProjectRoot(dir: string, pathValidation?: PathValidation): string | null;
71
- export declare function getPackageManagerFromPath(dir: string): PackageManager;
72
- export declare function getPackageManagerFromLockfile(dir: string): PackageManager;
73
- export declare function getProjectInfo(debug?: boolean, generateGlobalProject?: boolean): Promise<ProjectInfo>;
74
- export declare function forwardPHCommand(packageManager: PackageManager, projectPath: string, args: string, debug?: boolean, captureOutput?: boolean): string;
75
- /**
76
- * Recursively searches for a specific file by traversing up the directory tree.
77
- * Starting from the given path, it checks each parent directory until it finds
78
- * the target file or reaches the root directory.
79
- *
80
- * @param startPath - The absolute path of the directory to start searching from
81
- * @param targetFile - The name of the file to search for (e.g., 'package.json', 'pnpm-workspace.yaml')
82
- * @returns The absolute path of the directory containing the target file, or null if not found
83
- *
84
- * @example
85
- * // Find the workspace root directory
86
- * const workspaceRoot = findContainerDirectory('/path/to/project/src', 'pnpm-workspace.yaml');
87
- *
88
- * // Find the nearest package.json
89
- * const packageDir = findContainerDirectory('/path/to/project/src/components', 'package.json');
90
- */
91
- export declare const findContainerDirectory: (startPath: string, targetFile: string) => string | null;
92
- export declare function updateDependencyVersionString(packageManager: PackageManager, dependencies: string[], projectPath: string): void;
93
- export declare function installDependency(packageManager: PackageManager, dependencies: string[], projectPath: string, workspace?: boolean): void;
94
- export type GlobalProjectOptions = {
95
- project?: string;
96
- interactive?: boolean;
97
- version?: string;
98
- dev?: boolean;
99
- staging?: boolean;
100
- packageManager?: string;
101
- };
102
- export declare const createGlobalProject: (projectName?: string, options?: GlobalProjectOptions) => Promise<void>;
103
- /**
104
- * Helper to handle help flag detection for commands
105
- * This centralizes the pattern of checking for help flags and showing command-specific help
106
- *
107
- * @param command - The Command instance
108
- * @param actionFn - The original action function to call if help is not requested
109
- * @returns A wrapped action function
110
- */
111
- export declare function withHelpHandler<T extends unknown[]>(command: Command, actionFn: (...args: T) => Promise<void> | void): (...args: T) => Promise<void> | void;
112
- /**
113
- * Simplified utility to connect a command with an action function that includes help handling
114
- * This reduces boilerplate in command files by automatically setting up the action with help handling
115
- *
116
- * @param command - The Command instance
117
- * @param actionFn - The action function to call when the command is executed
118
- * @param preCheck - Optional validation function that runs before the action
119
- * @returns The command for chaining
120
- */
121
- export declare function withHelpAction<T extends unknown[]>(command: Command, actionFn: (...args: T) => Promise<void> | void, preCheck?: (...args: T) => boolean | undefined): Command;
122
- /**
123
- * Enhanced version of withHelpAction that allows custom help text without duplication
124
- *
125
- * @param command - The Command instance
126
- * @param actionFn - The action function to call when the command is executed
127
- * @param helpText - The custom help text to display (replacing the auto-generated help)
128
- * @param preCheck - Optional validation function that runs before the action
129
- * @returns The command for chaining
130
- */
131
- export declare function withCustomHelp<T extends unknown[]>(command: Command, actionFn: (...args: T) => Promise<void> | void, helpText: string, preCheck?: (...args: T) => boolean | undefined): Command;
4
+ export * from "./help.js";
5
+ export * from "./package-manager.js";
6
+ export type * from "./types.js";
7
+ export * from "./validate-remote-drive.js";
132
8
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utils/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,OAAO,EAAE,MAAM,WAAW,CAAC;AAMzC,cAAc,sBAAsB,CAAC;AACrC,eAAO,MAAM,WAAW,QAAkB,CAAC;AAC3C,eAAO,MAAM,MAAM,WAAW,CAAC;AAC/B,eAAO,MAAM,eAAe,UAiB3B,CAAC;AACF,eAAO,MAAM,sBAAsB,2BAA2B,CAAC;AAC/D,eAAO,MAAM,QAAQ,QAAY,CAAC;AAClC,eAAO,MAAM,sBAAsB,QAAQ,CAAC;AAC5C,eAAO,MAAM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OAAO,EAAE,EAChD,OAAO,EAAE,OAAO,EAChB,QAAQ,EAAE,CAAC,GAAG,IAAI,EAAE,CAAC,KAAK,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,EAC9C,QAAQ,EAAE,MAAM,EAChB,QAAQ,CAAC,EAAE,CAAC,GAAG,IAAI,EAAE,CAAC,KAAK,OAAO,GAAG,SAAS,GAC7C,OAAO,CAkBT"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,mBAAmB,CAAC;AAClC,cAAc,sBAAsB,CAAC;AACrC,cAAc,WAAW,CAAC;AAC1B,cAAc,sBAAsB,CAAC;AACrC,mBAAmB,YAAY,CAAC;AAChC,cAAc,4BAA4B,CAAC"}
@@ -1,369 +1,7 @@
1
- import { createProject, parseVersion } from "@powerhousedao/codegen";
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";
1
+ export * from "./constants.js";
2
+ export * from "./dependencies.js";
6
3
  export * from "./help-formatting.js";
7
- export const PH_BIN_PATH = process.argv[1];
8
- export const PH_BIN = "ph-cli";
9
- export const PH_CLI_COMMANDS = [
10
- "init",
11
- "dev",
12
- "connect",
13
- "generate",
14
- "reactor",
15
- "switchboard",
16
- "help",
17
- "install",
18
- "add",
19
- "i",
20
- "remove",
21
- "uninstall",
22
- "service",
23
- "list",
24
- "inspect",
25
- "version",
26
- ];
27
- export const POWERHOUSE_CONFIG_FILE = "powerhouse.config.json";
28
- export const HOME_DIR = homedir();
29
- export const PH_GLOBAL_PROJECT_NAME = ".ph";
30
- export const POWERHOUSE_GLOBAL_DIR = path.join(HOME_DIR, PH_GLOBAL_PROJECT_NAME);
31
- export function resolvePackageManagerOptions(options) {
32
- if (options.packageManager) {
33
- return options.packageManager;
34
- }
35
- if (options.pnpm) {
36
- return "pnpm";
37
- }
38
- if (options.yarn) {
39
- return "yarn";
40
- }
41
- if (options.bun) {
42
- return "bun";
43
- }
44
- return undefined;
45
- }
46
- export const packageManagers = {
47
- bun: {
48
- installCommand: "bun add {{dependency}}",
49
- execCommand: `bun ${PH_BIN} {{arguments}}`,
50
- execScript: `bun {{arguments}}`,
51
- lockfile: "bun.lock",
52
- globalPathRegexp: /[\\/].bun[\\/]/,
53
- updateCommand: "bun update {{dependency}}",
54
- buildAffected: "bun run build:affected",
55
- workspaceOption: "",
56
- installDepsCommand: "bun install",
57
- },
58
- pnpm: {
59
- installCommand: "pnpm add {{dependency}}",
60
- execCommand: `pnpm exec ${PH_BIN} {{arguments}}`,
61
- execScript: `pnpm {{arguments}}`,
62
- lockfile: "pnpm-lock.yaml",
63
- globalPathRegexp: /[\\/]pnpm[\\/]/,
64
- updateCommand: "pnpm update {{dependency}}",
65
- buildAffected: "pnpm run build:affected",
66
- workspaceOption: "--workspace-root",
67
- installDepsCommand: "pnpm install",
68
- },
69
- yarn: {
70
- installCommand: "yarn add {{dependency}}",
71
- execCommand: `yarn ${PH_BIN} {{arguments}}`,
72
- execScript: `yarn {{arguments}}`,
73
- lockfile: "yarn.lock",
74
- globalPathRegexp: /[\\/]yarn[\\/]/,
75
- updateCommand: "yarn upgrade {{dependency}}",
76
- buildAffected: "yarn run build:affected",
77
- workspaceOption: "-W",
78
- installDepsCommand: "yarn install",
79
- },
80
- npm: {
81
- installCommand: "npm install {{dependency}}",
82
- execCommand: `npx ${PH_BIN} {{arguments}}`,
83
- execScript: `npm run {{arguments}}`,
84
- lockfile: "package-lock.json",
85
- updateCommand: "npm update {{dependency}} --save",
86
- buildAffected: "npm run build:affected",
87
- workspaceOption: "",
88
- installDepsCommand: "npm install",
89
- },
90
- };
91
- export function defaultPathValidation() {
92
- return true;
93
- }
94
- export function isPowerhouseProject(dir) {
95
- const powerhouseConfigPath = path.join(dir, POWERHOUSE_CONFIG_FILE);
96
- return fs.existsSync(powerhouseConfigPath);
97
- }
98
- export function findNodeProjectRoot(dir, pathValidation = defaultPathValidation) {
99
- const packageJsonPath = path.join(dir, "package.json");
100
- if (fs.existsSync(packageJsonPath) && pathValidation(dir)) {
101
- return dir;
102
- }
103
- const parentDir = dirname(dir);
104
- if (parentDir === dir) {
105
- return null;
106
- }
107
- return findNodeProjectRoot(parentDir, pathValidation);
108
- }
109
- export function getPackageManagerFromPath(dir) {
110
- const lowerCasePath = dir.toLowerCase();
111
- if (packageManagers.bun.globalPathRegexp.test(lowerCasePath)) {
112
- return "bun";
113
- }
114
- else if (packageManagers.pnpm.globalPathRegexp.test(lowerCasePath)) {
115
- return "pnpm";
116
- }
117
- else if (packageManagers.yarn.globalPathRegexp.test(lowerCasePath)) {
118
- return "yarn";
119
- }
120
- return "npm";
121
- }
122
- export function getPackageManagerFromLockfile(dir) {
123
- if (fs.existsSync(path.join(dir, packageManagers.pnpm.lockfile))) {
124
- return "pnpm";
125
- }
126
- else if (fs.existsSync(path.join(dir, packageManagers.yarn.lockfile))) {
127
- return "yarn";
128
- }
129
- else if (fs.existsSync(path.join(dir, packageManagers.bun.lockfile))) {
130
- return "bun";
131
- }
132
- return "npm";
133
- }
134
- export async function getProjectInfo(debug, generateGlobalProject = true) {
135
- const currentPath = process.cwd();
136
- if (debug) {
137
- console.log(">>> currentPath:", currentPath);
138
- }
139
- const projectPath = findNodeProjectRoot(currentPath, isPowerhouseProject);
140
- if (!projectPath) {
141
- let available = fs.existsSync(POWERHOUSE_GLOBAL_DIR);
142
- if (generateGlobalProject) {
143
- await createGlobalProject();
144
- available = true;
145
- }
146
- return {
147
- available,
148
- isGlobal: true,
149
- path: POWERHOUSE_GLOBAL_DIR,
150
- };
151
- }
152
- return {
153
- isGlobal: false,
154
- available: true,
155
- path: projectPath,
156
- };
157
- }
158
- export function forwardPHCommand(packageManager, projectPath, args, debug, captureOutput = false) {
159
- const manager = packageManagers[packageManager];
160
- const command = manager.execCommand;
161
- const execCommand = command.replace("{{arguments}}", args);
162
- const commandOptions = { cwd: projectPath };
163
- if (debug) {
164
- console.log(">>> execCommand:", execCommand);
165
- console.log(">>> commandOptions:", commandOptions);
166
- console.log(">>> projectPath:", projectPath);
167
- console.log(">>> packageManager:", packageManager);
168
- }
169
- if (captureOutput) {
170
- // Capture output and return it
171
- try {
172
- return execSync(execCommand, {
173
- stdio: "pipe",
174
- encoding: "utf8",
175
- ...commandOptions,
176
- });
177
- }
178
- catch (error) {
179
- throw new Error(`Failed to execute command: ${execCommand}\nError: ${error instanceof Error ? error.message : String(error)}`);
180
- }
181
- }
182
- else {
183
- // Original behavior - pipe directly to stdout/stderr
184
- execSync(execCommand, {
185
- stdio: "inherit",
186
- ...commandOptions,
187
- });
188
- return "";
189
- }
190
- }
191
- /**
192
- * Recursively searches for a specific file by traversing up the directory tree.
193
- * Starting from the given path, it checks each parent directory until it finds
194
- * the target file or reaches the root directory.
195
- *
196
- * @param startPath - The absolute path of the directory to start searching from
197
- * @param targetFile - The name of the file to search for (e.g., 'package.json', 'pnpm-workspace.yaml')
198
- * @returns The absolute path of the directory containing the target file, or null if not found
199
- *
200
- * @example
201
- * // Find the workspace root directory
202
- * const workspaceRoot = findContainerDirectory('/path/to/project/src', 'pnpm-workspace.yaml');
203
- *
204
- * // Find the nearest package.json
205
- * const packageDir = findContainerDirectory('/path/to/project/src/components', 'package.json');
206
- */
207
- export const findContainerDirectory = (startPath, targetFile) => {
208
- const filePath = path.join(startPath, targetFile);
209
- if (fs.existsSync(filePath)) {
210
- return startPath;
211
- }
212
- const parentDir = path.dirname(startPath);
213
- //reached the root directory and haven't found the file
214
- if (parentDir === startPath) {
215
- return null;
216
- }
217
- return findContainerDirectory(parentDir, targetFile);
218
- };
219
- function parseDependencyString(dependency) {
220
- // Handle scoped packages (e.g. @org/package@version)
221
- const lastAtIndex = dependency.lastIndexOf("@");
222
- if (lastAtIndex === 0) {
223
- // This is a scoped package without version
224
- return { name: dependency, version: "latest" };
225
- }
226
- const name = dependency.slice(0, lastAtIndex);
227
- const version = dependency.slice(lastAtIndex + 1);
228
- return {
229
- name,
230
- version: version || "latest",
231
- };
232
- }
233
- export function updateDependencyVersionString(packageManager, dependencies, projectPath) {
234
- const manager = packageManagers[packageManager];
235
- const packageJsonPath = path.join(projectPath, "package.json");
236
- const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf8"));
237
- // Initialize dependencies and devDependencies if they don't exist
238
- packageJson.dependencies = packageJson.dependencies || {};
239
- packageJson.devDependencies = packageJson.devDependencies || {};
240
- // Process each dependency string
241
- for (const dependency of dependencies) {
242
- const { name, version } = parseDependencyString(dependency);
243
- // Check if the package exists in either dependencies or devDependencies
244
- if (name in packageJson.dependencies) {
245
- packageJson.dependencies[name] = version;
246
- }
247
- else if (name in packageJson.devDependencies) {
248
- packageJson.devDependencies[name] = version;
249
- }
250
- }
251
- // Write the updated package.json back to the file
252
- fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2), "utf8");
253
- const installDepsCommand = manager.installDepsCommand;
254
- const commandOptions = { cwd: projectPath };
255
- execSync(installDepsCommand, {
256
- stdio: "inherit",
257
- ...commandOptions,
258
- });
259
- }
260
- export function installDependency(packageManager, dependencies, projectPath, workspace) {
261
- if (!fs.existsSync(projectPath)) {
262
- throw new Error(`Project path not found: ${projectPath}`);
263
- }
264
- const manager = packageManagers[packageManager];
265
- let installCommand = manager.installCommand.replace("{{dependency}}", dependencies.join(" "));
266
- if (workspace) {
267
- installCommand += ` ${manager.workspaceOption}`;
268
- }
269
- const commandOptions = { cwd: projectPath };
270
- execSync(installCommand, {
271
- stdio: "inherit",
272
- ...commandOptions,
273
- });
274
- }
275
- export const createGlobalProject = async (projectName, options = {}) => {
276
- // check if the global project already exists
277
- const globalProjectExists = fs.existsSync(POWERHOUSE_GLOBAL_DIR);
278
- if (globalProjectExists) {
279
- console.log(`📦 Using global project: ${POWERHOUSE_GLOBAL_DIR}`);
280
- return;
281
- }
282
- console.log("📦 Initializing global project...");
283
- process.chdir(HOME_DIR);
284
- try {
285
- await createProject({
286
- name: PH_GLOBAL_PROJECT_NAME,
287
- interactive: false,
288
- version: parseVersion(options),
289
- packageManager: resolvePackageManagerOptions(options) ??
290
- getPackageManagerFromPath(PH_BIN_PATH),
291
- });
292
- console.log(`🚀 Global project initialized successfully: ${POWERHOUSE_GLOBAL_DIR}`);
293
- }
294
- catch (error) {
295
- console.error("❌ Failed to initialize the global project", error);
296
- }
297
- };
298
- /**
299
- * Helper to handle help flag detection for commands
300
- * This centralizes the pattern of checking for help flags and showing command-specific help
301
- *
302
- * @param command - The Command instance
303
- * @param actionFn - The original action function to call if help is not requested
304
- * @returns A wrapped action function
305
- */
306
- export function withHelpHandler(command, actionFn) {
307
- return (...args) => {
308
- // Check if help was requested
309
- const rawArgs = process.argv;
310
- const isHelpRequested = rawArgs.includes("--help") || rawArgs.includes("-h");
311
- // If help was explicitly requested, show the help and exit
312
- if (isHelpRequested) {
313
- command.outputHelp();
314
- process.exit(0);
315
- }
316
- // Otherwise, run the original action
317
- return actionFn(...args);
318
- };
319
- }
320
- /**
321
- * Simplified utility to connect a command with an action function that includes help handling
322
- * This reduces boilerplate in command files by automatically setting up the action with help handling
323
- *
324
- * @param command - The Command instance
325
- * @param actionFn - The action function to call when the command is executed
326
- * @param preCheck - Optional validation function that runs before the action
327
- * @returns The command for chaining
328
- */
329
- export function withHelpAction(command, actionFn, preCheck) {
330
- command.action(withHelpHandler(command, (...args) => {
331
- // If there's a pre-check function, run it before the action
332
- if (preCheck) {
333
- const result = preCheck(...args);
334
- // If the pre-check returns false explicitly, don't run the action
335
- if (result === false)
336
- return;
337
- }
338
- return actionFn(...args);
339
- }));
340
- return command;
341
- }
342
- /**
343
- * Enhanced version of withHelpAction that allows custom help text without duplication
344
- *
345
- * @param command - The Command instance
346
- * @param actionFn - The action function to call when the command is executed
347
- * @param helpText - The custom help text to display (replacing the auto-generated help)
348
- * @param preCheck - Optional validation function that runs before the action
349
- * @returns The command for chaining
350
- */
351
- export function withCustomHelp(command, actionFn, helpText, preCheck) {
352
- // Clear any existing help text
353
- command.helpInformation = function () {
354
- const name = command.name();
355
- const args = command.usage();
356
- const description = command.description();
357
- // Create a minimal header
358
- let header = `\nUsage: ph ${name}`;
359
- if (args)
360
- header += ` ${args}`;
361
- if (description)
362
- header += `\n\n${description}\n`;
363
- // Return the custom help text
364
- return header + "\n" + helpText;
365
- };
366
- // Add help action handler
367
- return withHelpAction(command, actionFn, preCheck);
368
- }
4
+ export * from "./help.js";
5
+ export * from "./package-manager.js";
6
+ export * from "./validate-remote-drive.js";
369
7
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAErE,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,IAAI,EAAE,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAE1C,cAAc,sBAAsB,CAAC;AACrC,MAAM,CAAC,MAAM,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAC3C,MAAM,CAAC,MAAM,MAAM,GAAG,QAAQ,CAAC;AAC/B,MAAM,CAAC,MAAM,eAAe,GAAG;IAC7B,MAAM;IACN,KAAK;IACL,SAAS;IACT,UAAU;IACV,SAAS;IACT,aAAa;IACb,MAAM;IACN,SAAS;IACT,KAAK;IACL,GAAG;IACH,QAAQ;IACR,WAAW;IACX,SAAS;IACT,MAAM;IACN,SAAS;IACT,SAAS;CACV,CAAC;AACF,MAAM,CAAC,MAAM,sBAAsB,GAAG,wBAAwB,CAAC;AAC/D,MAAM,CAAC,MAAM,QAAQ,GAAG,OAAO,EAAE,CAAC;AAClC,MAAM,CAAC,MAAM,sBAAsB,GAAG,KAAK,CAAC;AAC5C,MA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;YACjC,kEAAkE;YAClE,IAAI,MAAM,KAAK,KAAK;gBAAE,OAAO;QAC/B,CAAC;QAED,OAAO,QAAQ,CAAC,GAAG,IAAI,CAAC,CAAC;IAC3B,CAAC,CAAC,CACH,CAAC;IAEF,OAAO,OAAO,CAAC;AACjB,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,cAAc,CAC5B,OAAgB,EAChB,QAA8C,EAC9C,QAAgB,EAChB,QAA8C;IAE9C,+BAA+B;IAC/B,OAAO,CAAC,eAAe,GAAG;QACxB,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;QAC5B,MAAM,IAAI,GAAG,OAAO,CAAC,KAAK,EAAE,CAAC;QAC7B,MAAM,WAAW,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC;QAE1C,0BAA0B;QAC1B,IAAI,MAAM,GAAG,eAAe,IAAI,EAAE,CAAC;QACnC,IAAI,IAAI;YAAE,MAAM,IAAI,IAAI,IAAI,EAAE,CAAC;QAC/B,IAAI,WAAW;YAAE,MAAM,IAAI,OAAO,WAAW,IAAI,CAAC;QAElD,8BAA8B;QAC9B,OAAO,MAAM,GAAG,IAAI,GAAG,QAAQ,CAAC;IAClC,CAAC,CAAC;IAEF,0BAA0B;IAC1B,OAAO,cAAc,CAAC,OAAO,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC;AACrD,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,mBAAmB,CAAC;AAClC,cAAc,sBAAsB,CAAC;AACrC,cAAc,WAAW,CAAC;AAC1B,cAAc,sBAAsB,CAAC;AAErC,cAAc,4BAA4B,CAAC"}
@@ -0,0 +1,34 @@
1
+ import type { GlobalProjectOptions, PackageManager, PathValidation, ProjectInfo } from "./types.js";
2
+ export declare function resolvePackageManagerOptions(options: {
3
+ packageManager?: string;
4
+ npm?: boolean;
5
+ pnpm?: boolean;
6
+ yarn?: boolean;
7
+ bun?: boolean;
8
+ }): string | undefined;
9
+ export declare function defaultPathValidation(): boolean;
10
+ export declare function isPowerhouseProject(dir: string): boolean;
11
+ export declare function findNodeProjectRoot(dir: string, pathValidation?: PathValidation): string | null;
12
+ export declare function getPackageManagerFromPath(dir: string): PackageManager;
13
+ export declare function getPackageManagerFromLockfile(dir: string): PackageManager;
14
+ export declare function getProjectInfo(debug?: boolean, generateGlobalProject?: boolean): Promise<ProjectInfo>;
15
+ export declare function forwardPHCommand(packageManager: PackageManager, projectPath: string, args: string, debug?: boolean, captureOutput?: boolean): string;
16
+ /**
17
+ * Recursively searches for a specific file by traversing up the directory tree.
18
+ * Starting from the given path, it checks each parent directory until it finds
19
+ * the target file or reaches the root directory.
20
+ *
21
+ * @param startPath - The absolute path of the directory to start searching from
22
+ * @param targetFile - The name of the file to search for (e.g., 'package.json', 'pnpm-workspace.yaml')
23
+ * @returns The absolute path of the directory containing the target file, or null if not found
24
+ *
25
+ * @example
26
+ * // Find the workspace root directory
27
+ * const workspaceRoot = findContainerDirectory('/path/to/project/src', 'pnpm-workspace.yaml');
28
+ *
29
+ * // Find the nearest package.json
30
+ * const packageDir = findContainerDirectory('/path/to/project/src/components', 'package.json');
31
+ */
32
+ export declare const findContainerDirectory: (startPath: string, targetFile: string) => string | null;
33
+ export declare const createGlobalProject: (projectName?: string, options?: GlobalProjectOptions) => Promise<void>;
34
+ //# sourceMappingURL=package-manager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"package-manager.d.ts","sourceRoot":"","sources":["../../../src/utils/package-manager.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EACV,oBAAoB,EACpB,cAAc,EACd,cAAc,EACd,WAAW,EACZ,MAAM,YAAY,CAAC;AAEpB,wBAAgB,4BAA4B,CAAC,OAAO,EAAE;IACpD,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,GAAG,CAAC,EAAE,OAAO,CAAC;CACf,sBAsBA;AAED,wBAAgB,qBAAqB,YAEpC;AAED,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,MAAM,WAI9C;AAED,wBAAgB,mBAAmB,CACjC,GAAG,EAAE,MAAM,EACX,cAAc,GAAE,cAAsC,iBAevD;AAED,wBAAgB,yBAAyB,CAAC,GAAG,EAAE,MAAM,GAAG,cAAc,CAYrE;AAED,wBAAgB,6BAA6B,CAAC,GAAG,EAAE,MAAM,GAAG,cAAc,CAUzE;AAED,wBAAsB,cAAc,CAClC,KAAK,CAAC,EAAE,OAAO,EACf,qBAAqB,UAAO,GAC3B,OAAO,CAAC,WAAW,CAAC,CA6BtB;AAED,wBAAgB,gBAAgB,CAC9B,cAAc,EAAE,cAAc,EAC9B,WAAW,EAAE,MAAM,EACnB,IAAI,EAAE,MAAM,EACZ,KAAK,CAAC,EAAE,OAAO,EACf,aAAa,UAAQ,UAoCtB;AAED;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,sBAAsB,GACjC,WAAW,MAAM,EACjB,YAAY,MAAM,KACjB,MAAM,GAAG,IAeX,CAAC;AAEF,eAAO,MAAM,mBAAmB,GAC9B,cAAc,MAAM,EACpB,UAAS,oBAAyB,kBA6BnC,CAAC"}