ph-cmd 4.1.0-dev.58 → 4.1.0-dev.59
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/src/commands/__tests__/use.test.js +43 -23
- package/dist/src/commands/__tests__/use.test.js.map +1 -1
- package/dist/src/utils/constants.d.ts +53 -0
- package/dist/src/utils/constants.d.ts.map +1 -0
- package/dist/src/utils/constants.js +72 -0
- package/dist/src/utils/constants.js.map +1 -0
- package/dist/src/utils/create-global-project.d.ts +3 -0
- package/dist/src/utils/create-global-project.d.ts.map +1 -0
- package/dist/src/utils/create-global-project.js +28 -0
- package/dist/src/utils/create-global-project.js.map +1 -0
- package/dist/src/utils/dependencies.d.ts +4 -0
- package/dist/src/utils/dependencies.d.ts.map +1 -0
- package/dist/src/utils/dependencies.js +61 -0
- package/dist/src/utils/dependencies.js.map +1 -0
- package/dist/src/utils/help.d.ts +31 -0
- package/dist/src/utils/help.d.ts.map +1 -0
- package/dist/src/utils/help.js +72 -0
- package/dist/src/utils/help.js.map +1 -0
- package/dist/src/utils/index.d.ts +6 -130
- package/dist/src/utils/index.d.ts.map +1 -1
- package/dist/src/utils/index.js +5 -367
- package/dist/src/utils/index.js.map +1 -1
- package/dist/src/utils/package-manager.d.ts +32 -0
- package/dist/src/utils/package-manager.d.ts.map +1 -0
- package/dist/src/utils/package-manager.js +149 -0
- package/dist/src/utils/package-manager.js.map +1 -0
- package/dist/src/utils/types.d.ts +21 -0
- package/dist/src/utils/types.d.ts.map +1 -0
- package/dist/src/utils/types.js +2 -0
- package/dist/src/utils/types.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { execSync } from "node:child_process";
|
|
2
|
+
import { existsSync } from "node:fs";
|
|
3
|
+
import path, { dirname } from "node:path";
|
|
4
|
+
import { POWERHOUSE_CONFIG_FILE, POWERHOUSE_GLOBAL_DIR, packageManagers, } from "./constants.js";
|
|
5
|
+
import { createGlobalProject } from "./create-global-project.js";
|
|
6
|
+
export function resolvePackageManagerOptions(options) {
|
|
7
|
+
if (options.packageManager) {
|
|
8
|
+
return options.packageManager;
|
|
9
|
+
}
|
|
10
|
+
if (options.pnpm) {
|
|
11
|
+
return "pnpm";
|
|
12
|
+
}
|
|
13
|
+
if (options.yarn) {
|
|
14
|
+
return "yarn";
|
|
15
|
+
}
|
|
16
|
+
if (options.bun) {
|
|
17
|
+
return "bun";
|
|
18
|
+
}
|
|
19
|
+
return undefined;
|
|
20
|
+
}
|
|
21
|
+
export function defaultPathValidation() {
|
|
22
|
+
return true;
|
|
23
|
+
}
|
|
24
|
+
export function isPowerhouseProject(dir) {
|
|
25
|
+
const powerhouseConfigPath = path.join(dir, POWERHOUSE_CONFIG_FILE);
|
|
26
|
+
return existsSync(powerhouseConfigPath);
|
|
27
|
+
}
|
|
28
|
+
export function findNodeProjectRoot(dir, pathValidation = defaultPathValidation) {
|
|
29
|
+
const packageJsonPath = path.join(dir, "package.json");
|
|
30
|
+
if (existsSync(packageJsonPath) && pathValidation(dir)) {
|
|
31
|
+
return dir;
|
|
32
|
+
}
|
|
33
|
+
const parentDir = dirname(dir);
|
|
34
|
+
if (parentDir === dir) {
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
return findNodeProjectRoot(parentDir, pathValidation);
|
|
38
|
+
}
|
|
39
|
+
export function getPackageManagerFromPath(dir) {
|
|
40
|
+
const lowerCasePath = dir.toLowerCase();
|
|
41
|
+
if (packageManagers.bun.globalPathRegexp.test(lowerCasePath)) {
|
|
42
|
+
return "bun";
|
|
43
|
+
}
|
|
44
|
+
else if (packageManagers.pnpm.globalPathRegexp.test(lowerCasePath)) {
|
|
45
|
+
return "pnpm";
|
|
46
|
+
}
|
|
47
|
+
else if (packageManagers.yarn.globalPathRegexp.test(lowerCasePath)) {
|
|
48
|
+
return "yarn";
|
|
49
|
+
}
|
|
50
|
+
return "npm";
|
|
51
|
+
}
|
|
52
|
+
export function getPackageManagerFromLockfile(dir) {
|
|
53
|
+
if (existsSync(path.join(dir, packageManagers.pnpm.lockfile))) {
|
|
54
|
+
return "pnpm";
|
|
55
|
+
}
|
|
56
|
+
else if (existsSync(path.join(dir, packageManagers.yarn.lockfile))) {
|
|
57
|
+
return "yarn";
|
|
58
|
+
}
|
|
59
|
+
else if (existsSync(path.join(dir, packageManagers.bun.lockfile))) {
|
|
60
|
+
return "bun";
|
|
61
|
+
}
|
|
62
|
+
return "npm";
|
|
63
|
+
}
|
|
64
|
+
export async function getProjectInfo(debug, generateGlobalProject = true) {
|
|
65
|
+
const currentPath = process.cwd();
|
|
66
|
+
if (debug) {
|
|
67
|
+
console.log(">>> currentPath:", currentPath);
|
|
68
|
+
}
|
|
69
|
+
const projectPath = findNodeProjectRoot(currentPath, isPowerhouseProject);
|
|
70
|
+
if (!projectPath) {
|
|
71
|
+
let available = existsSync(POWERHOUSE_GLOBAL_DIR);
|
|
72
|
+
if (generateGlobalProject) {
|
|
73
|
+
await createGlobalProject();
|
|
74
|
+
available = true;
|
|
75
|
+
}
|
|
76
|
+
return {
|
|
77
|
+
available,
|
|
78
|
+
isGlobal: true,
|
|
79
|
+
path: POWERHOUSE_GLOBAL_DIR,
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
return {
|
|
83
|
+
isGlobal: false,
|
|
84
|
+
available: true,
|
|
85
|
+
path: projectPath,
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
export function forwardPHCommand(packageManager, projectPath, args, debug, captureOutput = false) {
|
|
89
|
+
const manager = packageManagers[packageManager];
|
|
90
|
+
const command = manager.execCommand;
|
|
91
|
+
const execCommand = command.replace("{{arguments}}", args);
|
|
92
|
+
const commandOptions = { cwd: projectPath };
|
|
93
|
+
if (debug) {
|
|
94
|
+
console.log(">>> execCommand:", execCommand);
|
|
95
|
+
console.log(">>> commandOptions:", commandOptions);
|
|
96
|
+
console.log(">>> projectPath:", projectPath);
|
|
97
|
+
console.log(">>> packageManager:", packageManager);
|
|
98
|
+
}
|
|
99
|
+
if (captureOutput) {
|
|
100
|
+
// Capture output and return it
|
|
101
|
+
try {
|
|
102
|
+
return execSync(execCommand, {
|
|
103
|
+
stdio: "pipe",
|
|
104
|
+
encoding: "utf8",
|
|
105
|
+
...commandOptions,
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
catch (error) {
|
|
109
|
+
throw new Error(`Failed to execute command: ${execCommand}\nError: ${error instanceof Error ? error.message : String(error)}`);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
// Original behavior - pipe directly to stdout/stderr
|
|
114
|
+
execSync(execCommand, {
|
|
115
|
+
stdio: "inherit",
|
|
116
|
+
...commandOptions,
|
|
117
|
+
});
|
|
118
|
+
return "";
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Recursively searches for a specific file by traversing up the directory tree.
|
|
123
|
+
* Starting from the given path, it checks each parent directory until it finds
|
|
124
|
+
* the target file or reaches the root directory.
|
|
125
|
+
*
|
|
126
|
+
* @param startPath - The absolute path of the directory to start searching from
|
|
127
|
+
* @param targetFile - The name of the file to search for (e.g., 'package.json', 'pnpm-workspace.yaml')
|
|
128
|
+
* @returns The absolute path of the directory containing the target file, or null if not found
|
|
129
|
+
*
|
|
130
|
+
* @example
|
|
131
|
+
* // Find the workspace root directory
|
|
132
|
+
* const workspaceRoot = findContainerDirectory('/path/to/project/src', 'pnpm-workspace.yaml');
|
|
133
|
+
*
|
|
134
|
+
* // Find the nearest package.json
|
|
135
|
+
* const packageDir = findContainerDirectory('/path/to/project/src/components', 'package.json');
|
|
136
|
+
*/
|
|
137
|
+
export const findContainerDirectory = (startPath, targetFile) => {
|
|
138
|
+
const filePath = path.join(startPath, targetFile);
|
|
139
|
+
if (existsSync(filePath)) {
|
|
140
|
+
return startPath;
|
|
141
|
+
}
|
|
142
|
+
const parentDir = path.dirname(startPath);
|
|
143
|
+
//reached the root directory and haven't found the file
|
|
144
|
+
if (parentDir === startPath) {
|
|
145
|
+
return null;
|
|
146
|
+
}
|
|
147
|
+
return findContainerDirectory(parentDir, targetFile);
|
|
148
|
+
};
|
|
149
|
+
//# sourceMappingURL=package-manager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"package-manager.js","sourceRoot":"","sources":["../../../src/utils/package-manager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,IAAI,EAAE,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EACL,sBAAsB,EACtB,qBAAqB,EACrB,eAAe,GAChB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAGjE,MAAM,UAAU,4BAA4B,CAAC,OAK5C;IACC,IAAI,OAAO,CAAC,cAAc,EAAE,CAAC;QAC3B,OAAO,OAAO,CAAC,cAAc,CAAC;IAChC,CAAC;IAED,IAAI,OAAO,CAAC,IAAI,EAAE,CAAC;QACjB,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,IAAI,OAAO,CAAC,IAAI,EAAE,CAAC;QACjB,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC;QAChB,OAAO,KAAK,CAAC;IACf,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,MAAM,UAAU,qBAAqB;IACnC,OAAO,IAAI,CAAC;AACd,CAAC;AAED,MAAM,UAAU,mBAAmB,CAAC,GAAW;IAC7C,MAAM,oBAAoB,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,sBAAsB,CAAC,CAAC;IAEpE,OAAO,UAAU,CAAC,oBAAoB,CAAC,CAAC;AAC1C,CAAC;AAED,MAAM,UAAU,mBAAmB,CACjC,GA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,uDAAuD;IACvD,IAAI,SAAS,KAAK,SAAS,EAAE,CAAC;QAC5B,OAAO,IAAI,CAAC;IACd,CAAC;IAED,OAAO,sBAAsB,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC;AACvD,CAAC,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export type ProjectInfo = {
|
|
2
|
+
isGlobal: boolean;
|
|
3
|
+
available: boolean;
|
|
4
|
+
path: string;
|
|
5
|
+
};
|
|
6
|
+
export type PackageManager = "npm" | "yarn" | "pnpm" | "bun";
|
|
7
|
+
export type PathValidation = (dir: string) => boolean;
|
|
8
|
+
export interface PackageJson {
|
|
9
|
+
dependencies?: Record<string, string>;
|
|
10
|
+
devDependencies?: Record<string, string>;
|
|
11
|
+
[key: string]: unknown;
|
|
12
|
+
}
|
|
13
|
+
export type GlobalProjectOptions = {
|
|
14
|
+
project?: string;
|
|
15
|
+
interactive?: boolean;
|
|
16
|
+
version?: string;
|
|
17
|
+
dev?: boolean;
|
|
18
|
+
staging?: boolean;
|
|
19
|
+
packageManager?: string;
|
|
20
|
+
};
|
|
21
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/utils/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,WAAW,GAAG;IACxB,QAAQ,EAAE,OAAO,CAAC;IAClB,SAAS,EAAE,OAAO,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG,KAAK,GAAG,MAAM,GAAG,MAAM,GAAG,KAAK,CAAC;AAE7D,MAAM,MAAM,cAAc,GAAG,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC;AAEtD,MAAM,WAAW,WAAW;IAC1B,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACtC,eAAe,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACzC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED,MAAM,MAAM,oBAAoB,GAAG;IACjC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/utils/types.ts"],"names":[],"mappings":""}
|