ph-cmd 5.2.0-staging.9 → 5.3.0-staging.2

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 (67) hide show
  1. package/dist/src/cli.js +30 -1
  2. package/dist/src/cli.js.map +1 -1
  3. package/dist/src/commands/__tests__/update.test.js +1 -1
  4. package/dist/src/commands/__tests__/update.test.js.map +1 -1
  5. package/dist/src/commands/__tests__/use.test.js +1 -1
  6. package/dist/src/commands/__tests__/use.test.js.map +1 -1
  7. package/dist/src/commands/index.d.ts +1 -4
  8. package/dist/src/commands/index.d.ts.map +1 -1
  9. package/dist/src/commands/index.js +1 -7
  10. package/dist/src/commands/index.js.map +1 -1
  11. package/dist/src/commands/init.d.ts +1 -21
  12. package/dist/src/commands/init.d.ts.map +1 -1
  13. package/dist/src/commands/init.js +153 -65
  14. package/dist/src/commands/init.js.map +1 -1
  15. package/dist/src/commands/setup-globals.js +1 -1
  16. package/dist/src/commands/setup-globals.js.map +1 -1
  17. package/dist/src/commands/update.d.ts +1 -12
  18. package/dist/src/commands/update.d.ts.map +1 -1
  19. package/dist/src/commands/update.js +92 -101
  20. package/dist/src/commands/update.js.map +1 -1
  21. package/dist/src/commands/update.old.d.ts +13 -0
  22. package/dist/src/commands/update.old.d.ts.map +1 -0
  23. package/dist/src/commands/update.old.js +105 -0
  24. package/dist/src/commands/update.old.js.map +1 -0
  25. package/dist/src/commands/use-local.d.ts +2 -0
  26. package/dist/src/commands/use-local.d.ts.map +1 -0
  27. package/dist/src/commands/use-local.js +115 -0
  28. package/dist/src/commands/use-local.js.map +1 -0
  29. package/dist/src/commands/use.d.ts +1 -49
  30. package/dist/src/commands/use.d.ts.map +1 -1
  31. package/dist/src/commands/use.js +106 -188
  32. package/dist/src/commands/use.js.map +1 -1
  33. package/dist/src/commands/use.old.d.ts +55 -0
  34. package/dist/src/commands/use.old.d.ts.map +1 -0
  35. package/dist/src/commands/use.old.js +219 -0
  36. package/dist/src/commands/use.old.js.map +1 -0
  37. package/dist/src/help.d.ts +1 -1
  38. package/dist/src/help.d.ts.map +1 -1
  39. package/dist/src/help.js +12 -7
  40. package/dist/src/help.js.map +1 -1
  41. package/dist/src/utils/constants.d.ts +4 -0
  42. package/dist/src/utils/constants.d.ts.map +1 -1
  43. package/dist/src/utils/constants.js +26 -0
  44. package/dist/src/utils/constants.js.map +1 -1
  45. package/dist/src/utils/file-system.d.ts +2 -0
  46. package/dist/src/utils/file-system.d.ts.map +1 -0
  47. package/dist/src/utils/file-system.js +12 -0
  48. package/dist/src/utils/file-system.js.map +1 -0
  49. package/dist/src/utils/help-formatting.d.ts.map +1 -1
  50. package/dist/src/utils/help-formatting.js +13 -1
  51. package/dist/src/utils/help-formatting.js.map +1 -1
  52. package/dist/src/utils/package-manager.d.ts +0 -7
  53. package/dist/src/utils/package-manager.d.ts.map +1 -1
  54. package/dist/src/utils/package-manager.js +3 -22
  55. package/dist/src/utils/package-manager.js.map +1 -1
  56. package/dist/src/utils/parsing.d.ts +20 -0
  57. package/dist/src/utils/parsing.d.ts.map +1 -0
  58. package/dist/src/utils/parsing.js +52 -0
  59. package/dist/src/utils/parsing.js.map +1 -0
  60. package/dist/src/utils/run-cmd.d.ts +2 -0
  61. package/dist/src/utils/run-cmd.d.ts.map +1 -0
  62. package/dist/src/utils/run-cmd.js +11 -0
  63. package/dist/src/utils/run-cmd.js.map +1 -0
  64. package/dist/src/version.d.ts +1 -1
  65. package/dist/src/version.js +1 -1
  66. package/dist/tsconfig.tsbuildinfo +1 -1
  67. package/package.json +10 -3
@@ -1,199 +1,117 @@
1
- import { existsSync, readdirSync, readFileSync } from "node:fs";
2
- import path from "node:path";
3
- import { useHelp } from "../help.js";
4
- import { getPackageManagerFromLockfile, getProjectInfo, installDependency, resolvePackageManagerOptions, updateDependencyVersionString, withCustomHelp, } from "../utils/index.js";
5
- export const ORG = "@powerhousedao";
6
- // Special packages that don't use the @powerhousedao organization
7
- export const SPECIAL_PACKAGES = [
8
- "document-model",
9
- "document-drive",
10
- "@renown/sdk",
11
- ];
12
- // Packages to exclude from dynamic detection (external dependencies)
13
- export const EXCLUDED_PACKAGES = [
14
- "@powerhousedao/document-engineering",
15
- "@powerhousedao/scalars",
16
- "@powerhousedao/diff-analyzer",
17
- "@powerhousedao/analytics-engine-core",
18
- "@powerhousedao/analytics-engine-graphql",
19
- "@powerhousedao/analytics-engine-pg",
20
- "@powerhousedao/analytics-engine-browser",
21
- "@powerhousedao/analytics-engine-knex",
22
- ];
23
- /**
24
- * Detects all Powerhouse packages from package.json dependencies
25
- * @param packageJson - The parsed package.json object
26
- * @returns Array of package names to process
27
- */
28
- export function detectPowerhousePackages(packageJson) {
29
- const allDependencies = {
30
- ...(packageJson.dependencies || {}),
31
- ...(packageJson.devDependencies || {}),
32
- };
33
- const powerhousePackages = [];
34
- // Find all @powerhousedao packages (excluding document-engineering)
35
- Object.keys(allDependencies).forEach((dep) => {
36
- if (dep.startsWith(ORG + "/") && !EXCLUDED_PACKAGES.includes(dep)) {
37
- powerhousePackages.push(dep);
1
+ import { getPackageVersion } from "@powerhousedao/codegen/utils";
2
+ import chalk from "chalk";
3
+ import { boolean, command, flag, oneOf, option, optional, positional, run, string, } from "cmd-ts";
4
+ import { detect } from "package-manager-detector/detect";
5
+ import { readPackage } from "read-pkg";
6
+ import { clean, valid } from "semver";
7
+ import { writePackage } from "write-package";
8
+ import { ALL_POWERHOUSE_DEPENDENCIES } from "../utils/constants.js";
9
+ import { handleMutuallyExclusiveOptions, logVersionUpdate, } from "../utils/parsing.js";
10
+ import { runCmd } from "../utils/run-cmd.js";
11
+ const commandParser = command({
12
+ name: "ph use",
13
+ description: "Specify the release version of Powerhouse dependencies to use.\nTo use a release tag, specify `staging`, `dev`, or `latest` as the first argument to this command or with the --tag option.\n You can also use a specific version with the --version option.",
14
+ args: {
15
+ tagPositional: positional({
16
+ type: optional(oneOf(["latest", "staging", "dev"])),
17
+ displayName: "tag",
18
+ description: `Specify the release tag to use for your project. Can be one of: "latest", "staging", or "dev".`,
19
+ }),
20
+ tagOption: option({
21
+ type: optional(oneOf(["latest", "staging", "dev"])),
22
+ long: "tag",
23
+ short: "t",
24
+ description: `Specify the release tag to use for your project. Can be one of: "latest", "staging", or "dev".`,
25
+ }),
26
+ version: option({
27
+ type: optional(string),
28
+ long: "version",
29
+ short: "v",
30
+ description: "Specify the exact semver release version to use for your project.",
31
+ }),
32
+ skipInstall: flag({
33
+ type: optional(boolean),
34
+ long: "skip-install",
35
+ short: "s",
36
+ description: "Skip running `install` with your package manager",
37
+ }),
38
+ },
39
+ handler: async ({ tagPositional, tagOption, version, skipInstall }) => {
40
+ const tag = tagPositional ?? tagOption;
41
+ handleMutuallyExclusiveOptions({ tag, version }, "versioning strategy");
42
+ if (!tag && !version) {
43
+ throw new Error("Please specify either a release tag or a version to use.");
38
44
  }
39
- });
40
- // Add special packages if they exist
41
- SPECIAL_PACKAGES.forEach((pkg) => {
42
- if (allDependencies[pkg]) {
43
- powerhousePackages.push(pkg);
45
+ if (version && !valid(clean(version))) {
46
+ throw new Error(`❌ Invalid version: ${chalk.bold(version)}`);
44
47
  }
45
- });
46
- return powerhousePackages;
47
- }
48
- /**
49
- * Maps a package name to its monorepo directory path by reading package.json files
50
- * @param packageName - The package name (e.g., '@powerhousedao/common' or 'document-model')
51
- * @param localPath - The base path to the monorepo
52
- * @returns The full path to the package directory
53
- */
54
- export function mapPackageToMonorepoPath(packageName, localPath) {
55
- // Search in all possible locations
56
- const searchDirs = [
57
- path.join(localPath, "packages"),
58
- path.join(localPath, "apps"),
59
- path.join(localPath, "clis"),
60
- ];
61
- for (const searchDir of searchDirs) {
62
- if (!existsSync(searchDir))
63
- continue;
64
- try {
65
- // Read all subdirectories
66
- const subdirs = readdirSync(searchDir, { withFileTypes: true })
67
- .filter((dirent) => dirent.isDirectory())
68
- .map((dirent) => dirent.name);
69
- // Check each subdirectory's package.json
70
- for (const subdir of subdirs) {
71
- const packageJsonPath = path.join(searchDir, subdir, "package.json");
72
- if (existsSync(packageJsonPath)) {
73
- try {
74
- const content = readFileSync(packageJsonPath, "utf-8");
75
- const pkg = JSON.parse(content);
76
- if (pkg.name === packageName) {
77
- return path.join(searchDir, subdir);
78
- }
79
- }
80
- catch {
81
- // Ignore invalid package.json files
82
- }
48
+ console.log(`▶️ Updating project to use ${chalk.bold(version ?? tag)}...\n`);
49
+ const packageJson = await readPackage();
50
+ if (packageJson.dependencies) {
51
+ for (const [name, existingVersion] of Object.entries(packageJson.dependencies)) {
52
+ if (existingVersion && ALL_POWERHOUSE_DEPENDENCIES.includes(name)) {
53
+ const newVersion = await getPackageVersion({ name, tag, version });
54
+ packageJson.dependencies[name] = newVersion;
55
+ logVersionUpdate({
56
+ name,
57
+ version: existingVersion,
58
+ newVersion,
59
+ });
83
60
  }
84
61
  }
85
62
  }
86
- catch {
87
- // Ignore errors reading directory
88
- continue;
63
+ if (packageJson.devDependencies) {
64
+ for (const [name, existingVersion] of Object.entries(packageJson.devDependencies)) {
65
+ if (existingVersion && ALL_POWERHOUSE_DEPENDENCIES.includes(name)) {
66
+ const newVersion = await getPackageVersion({ name, tag, version });
67
+ packageJson.devDependencies[name] = newVersion;
68
+ logVersionUpdate({
69
+ name,
70
+ version: existingVersion,
71
+ newVersion,
72
+ });
73
+ }
74
+ }
89
75
  }
90
- }
91
- // Fallback to old behavior if not found
92
- const baseName = packageName.startsWith(ORG + "/")
93
- ? packageName.substring(ORG.length + 1)
94
- : packageName;
95
- return path.join(localPath, "packages", baseName);
96
- }
97
- export const ENV_MAP = {
98
- dev: "dev",
99
- staging: "staging",
100
- prod: "latest",
101
- latest: "latest",
102
- };
103
- export const updatePackageJson = async (env, localPath, packageManager, debug, useResolved) => {
104
- const projectInfo = await getProjectInfo();
105
- const pkgManager = packageManager || getPackageManagerFromLockfile(projectInfo.path);
106
- if (debug) {
107
- console.log(">>> projectInfo", projectInfo);
108
- console.log(">>> pkgManager", pkgManager);
109
- }
110
- // Read the project's package.json
111
- const packageJsonPath = path.join(projectInfo.path, "package.json");
112
- const packageJsonContent = readFileSync(packageJsonPath, "utf-8");
113
- const packageJson = JSON.parse(packageJsonContent);
114
- // Detect all Powerhouse packages from the current package.json
115
- const powerhousePackages = detectPowerhousePackages(packageJson);
116
- const dependencies = [];
117
- if (localPath) {
118
- // For local path, map each detected package to its monorepo path
119
- powerhousePackages.forEach((packageName) => {
120
- const fullPath = mapPackageToMonorepoPath(packageName, localPath);
121
- dependencies.push(fullPath);
122
- });
123
- }
124
- else {
125
- // For remote dependencies, add version tags
126
- powerhousePackages.forEach((packageName) => {
127
- dependencies.push(`${packageName}@${ENV_MAP[env]}`);
128
- });
129
- }
130
- if (debug) {
131
- console.log(">>> dependencies to update", dependencies);
132
- }
133
- if (dependencies.length === 0) {
134
- console.log("ℹ️ No Powerhouse dependencies found to update");
135
- return;
136
- }
137
- try {
138
- console.log("⚙️ Updating dependencies...");
139
- if (localPath || useResolved) {
140
- installDependency(pkgManager, dependencies, projectInfo.path);
76
+ if (packageJson.optionalDependencies) {
77
+ for (const [name, existingVersion] of Object.entries(packageJson.optionalDependencies)) {
78
+ if (existingVersion && ALL_POWERHOUSE_DEPENDENCIES.includes(name)) {
79
+ const newVersion = await getPackageVersion({ name, tag, version });
80
+ packageJson.optionalDependencies[name] = newVersion;
81
+ logVersionUpdate({
82
+ name,
83
+ version: existingVersion,
84
+ newVersion,
85
+ });
86
+ }
87
+ }
141
88
  }
142
- else {
143
- updateDependencyVersionString(pkgManager, dependencies, projectInfo.path);
89
+ if (packageJson.peerDependencies) {
90
+ for (const [name, existingVersion] of Object.entries(packageJson.peerDependencies)) {
91
+ if (existingVersion && ALL_POWERHOUSE_DEPENDENCIES.includes(name)) {
92
+ const newVersion = await getPackageVersion({ name, tag, version });
93
+ packageJson.peerDependencies[name] = newVersion;
94
+ logVersionUpdate({
95
+ name,
96
+ version: existingVersion,
97
+ newVersion,
98
+ });
99
+ }
100
+ }
144
101
  }
145
- console.log("✅ Dependencies updated successfully");
146
- }
147
- catch (error) {
148
- console.error("❌ Failed to update dependencies");
149
- throw error;
150
- }
151
- };
152
- export const use = async (environment, localPath, options) => {
153
- if (!environment ||
154
- (!options.force &&
155
- environment !== "local" &&
156
- !Object.keys(ENV_MAP).includes(environment))) {
157
- throw new Error(`❌ Invalid environment, use --force or use one of the following: ${Object.keys(ENV_MAP).join(", ")}`);
158
- }
159
- if (environment === "local" && !localPath) {
160
- throw new Error("❌ Local environment requires a local path, please specify the path to the local environment");
161
- }
162
- const { debug } = options;
163
- const env = environment;
164
- if (debug) {
165
- console.log(">>> options", options);
166
- }
167
- const projectInfo = await getProjectInfo();
168
- const packageManager = resolvePackageManagerOptions(options) ??
169
- getPackageManagerFromLockfile(projectInfo.path);
170
- await updatePackageJson(env, localPath, packageManager, debug, options.useResolved);
171
- };
172
- export function useCommand(program) {
173
- const useCmd = program
174
- .command("use")
175
- .description("Allows you to change your environment (latest, development, production, local)")
176
- .argument("[environment]", "The environment to use (latest, dev, prod, local)")
177
- .argument("[localPath]", "The path to the local environment (you have to specify the path to the local environment)")
178
- .option("--force", "force environment to use")
179
- .option("--use-resolved", "Use resolved dependency versions")
180
- .option("--package-manager <packageManager>", "package manager to be used")
181
- .option("--pnpm", "Use 'pnpm' as package manager")
182
- .option("--yarn", "Use 'yarn' as package manager")
183
- .option("--bun", "Use 'bun' as package manager")
184
- .option("--debug", "Show additional logs");
185
- // Use withCustomHelp instead of withHelpAction and addHelpText
186
- return withCustomHelp(useCmd, use, useHelp,
187
- // Pre-check function to validate environment before running the action
188
- (environment) => {
189
- if (!environment &&
190
- !process.argv.includes("--help") &&
191
- !process.argv.includes("-h")) {
192
- console.error('Error: Missing required argument "environment"');
193
- process.exit(1);
194
- return false;
102
+ await writePackage(packageJson);
103
+ console.log(chalk.green(`\n✅ Project updated to use ${chalk.bold(version ?? tag)}\n`));
104
+ if (skipInstall)
105
+ return;
106
+ const packageManager = await detect();
107
+ if (!packageManager) {
108
+ throw new Error(`❌ Failed to detect your package manager. Run install manually.`);
195
109
  }
196
- return true;
197
- });
110
+ console.log(`▶️ Installing updated dependencies with \`${packageManager.agent}\`\n`);
111
+ runCmd(`${packageManager.agent} install`);
112
+ },
113
+ });
114
+ export async function use(args) {
115
+ await run(commandParser, args);
198
116
  }
199
117
  //# sourceMappingURL=use.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"use.js","sourceRoot":"","sources":["../../../src/commands/use.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAChE,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAGrC,OAAO,EACL,6BAA6B,EAC7B,cAAc,EACd,iBAAiB,EACjB,4BAA4B,EAC5B,6BAA6B,EAC7B,cAAc,GACf,MAAM,mBAAmB,CAAC;AAE3B,MAAM,CAAC,MAAM,GAAG,GAAG,gBAAgB,CAAC;AAEpC,kEAAkE;AAClE,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC9B,gBAAgB;IAChB,gBAAgB;IAChB,aAAa;CACd,CAAC;AAEF,qEAAqE;AACrE,MAAM,CAAC,MAAM,iBAAiB,GAAG;IAC/B,qCAAqC;IACrC,wBAAwB;IACxB,8BAA8B;IAC9B,sCAAsC;IACtC,yCAAyC;IACzC,oCAAoC;IACpC,yCAAyC;IACzC,sCAAsC;CACvC,CAAC;AAEF;;;;GAIG;AACH,MAAM,UAAU,wBAAwB,CAAC,WAGxC;IACC,MAAM,eAAe,GAAG;QACtB,GAAG,CAAC,WAAW,CAAC,YAAY,IAAI,EAAE,CAAC;QACnC,GAAG,CAAC,WAAW,CAAC,eAAe,IAAI,EAAE,CAAC;KACvC,CAAC;IAEF,MAAM,kBAAkB,GAAa,EAAE,CAAC;IAExC,oEAAoE;IACpE,MAAM,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE;QAC3C,IAAI,G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"../types.js";
3
+ import type { PackageManager } from "../utils/index.js";
4
+ export declare const ORG = "@powerhousedao";
5
+ export declare const SPECIAL_PACKAGES: string[];
6
+ export declare const EXCLUDED_PACKAGES: string[];
7
+ /**
8
+ * Detects all Powerhouse packages from package.json dependencies
9
+ * @param packageJson - The parsed package.json object
10
+ * @returns Array of package names to process
11
+ */
12
+ export declare function detectPowerhousePackages(packageJson: {
13
+ dependencies?: Record<string, string>;
14
+ devDependencies?: Record<string, string>;
15
+ }): string[];
16
+ /**
17
+ * Maps a package name to its monorepo directory path by reading package.json files
18
+ * @param packageName - The package name (e.g., '@powerhousedao/common' or 'document-model')
19
+ * @param localPath - The base path to the monorepo
20
+ * @returns The full path to the package directory
21
+ */
22
+ export declare function mapPackageToMonorepoPath(packageName: string, localPath: string): string;
23
+ export declare const ENV_MAP: {
24
+ dev: string;
25
+ staging: string;
26
+ prod: string;
27
+ latest: string;
28
+ };
29
+ export type Environment = keyof typeof ENV_MAP;
30
+ /**
31
+ * Checks if a string is a valid semver version
32
+ * Supports formats like: 1.0.0, 1.0.0-beta.1, 1.0.0-dev.123, v1.0.0
33
+ */
34
+ export declare function isVersionString(str: string): boolean;
35
+ export declare const updatePackageJson: (envOrVersion: (typeof ENV_MAP)[keyof typeof ENV_MAP], localPath?: string, packageManager?: PackageManager, debug?: boolean, useResolved?: boolean) => Promise<void>;
36
+ export type UseOptions = {
37
+ dev?: boolean;
38
+ prod?: boolean;
39
+ local?: string;
40
+ debug?: boolean;
41
+ latest?: boolean;
42
+ force?: boolean;
43
+ packageManager?: string;
44
+ pnpm?: boolean;
45
+ yarn?: boolean;
46
+ bun?: boolean;
47
+ useResolved?: boolean;
48
+ };
49
+ export declare const use: CommandActionType<[
50
+ string | undefined,
51
+ string | undefined,
52
+ UseOptions
53
+ ]>;
54
+ export declare function useCommand(program: Command): Command;
55
+ //# sourceMappingURL=use.old.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use.old.d.ts","sourceRoot":"","sources":["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O,CAAC;IAChB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB,CAAC;AAEF,eAAO,MAAM,GAAG,EAAE,iBAAiB,CACjC;IAAC,MAAM,GAAG,SAAS;IAAE,MAAM,GAAG,SAAS;IAAE,UAAU;CAAC,CA0CrD,CAAC;AAEF,wBAAgB,UAAU,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAyCpD"}
@@ -0,0 +1,219 @@
1
+ import { existsSync, readdirSync, readFileSync } from "node:fs";
2
+ import path from "node:path";
3
+ import { useHelp } from "../help.js";
4
+ import { getPackageManagerFromLockfile, getProjectInfo, installDependency, updateDependencyVersionString, withCustomHelp, } from "../utils/index.js";
5
+ import { parsePackageManager } from "../utils/parsing.js";
6
+ export const ORG = "@powerhousedao";
7
+ // Special packages that don't use the @powerhousedao organization
8
+ export const SPECIAL_PACKAGES = [
9
+ "document-model",
10
+ "document-drive",
11
+ "@renown/sdk",
12
+ ];
13
+ // Packages to exclude from dynamic detection (external dependencies)
14
+ export const EXCLUDED_PACKAGES = [
15
+ "@powerhousedao/document-engineering",
16
+ "@powerhousedao/scalars",
17
+ "@powerhousedao/diff-analyzer",
18
+ "@powerhousedao/analytics-engine-core",
19
+ "@powerhousedao/analytics-engine-graphql",
20
+ "@powerhousedao/analytics-engine-pg",
21
+ "@powerhousedao/analytics-engine-browser",
22
+ "@powerhousedao/analytics-engine-knex",
23
+ ];
24
+ /**
25
+ * Detects all Powerhouse packages from package.json dependencies
26
+ * @param packageJson - The parsed package.json object
27
+ * @returns Array of package names to process
28
+ */
29
+ export function detectPowerhousePackages(packageJson) {
30
+ const allDependencies = {
31
+ ...(packageJson.dependencies || {}),
32
+ ...(packageJson.devDependencies || {}),
33
+ };
34
+ const powerhousePackages = [];
35
+ // Find all @powerhousedao packages (excluding document-engineering)
36
+ Object.keys(allDependencies).forEach((dep) => {
37
+ if (dep.startsWith(ORG + "/") && !EXCLUDED_PACKAGES.includes(dep)) {
38
+ powerhousePackages.push(dep);
39
+ }
40
+ });
41
+ // Add special packages if they exist
42
+ SPECIAL_PACKAGES.forEach((pkg) => {
43
+ if (allDependencies[pkg]) {
44
+ powerhousePackages.push(pkg);
45
+ }
46
+ });
47
+ return powerhousePackages;
48
+ }
49
+ /**
50
+ * Maps a package name to its monorepo directory path by reading package.json files
51
+ * @param packageName - The package name (e.g., '@powerhousedao/common' or 'document-model')
52
+ * @param localPath - The base path to the monorepo
53
+ * @returns The full path to the package directory
54
+ */
55
+ export function mapPackageToMonorepoPath(packageName, localPath) {
56
+ // Search in all possible locations
57
+ const searchDirs = [
58
+ path.join(localPath, "packages"),
59
+ path.join(localPath, "apps"),
60
+ path.join(localPath, "clis"),
61
+ ];
62
+ for (const searchDir of searchDirs) {
63
+ if (!existsSync(searchDir))
64
+ continue;
65
+ try {
66
+ // Read all subdirectories
67
+ const subdirs = readdirSync(searchDir, { withFileTypes: true })
68
+ .filter((dirent) => dirent.isDirectory())
69
+ .map((dirent) => dirent.name);
70
+ // Check each subdirectory's package.json
71
+ for (const subdir of subdirs) {
72
+ const packageJsonPath = path.join(searchDir, subdir, "package.json");
73
+ if (existsSync(packageJsonPath)) {
74
+ try {
75
+ const content = readFileSync(packageJsonPath, "utf-8");
76
+ const pkg = JSON.parse(content);
77
+ if (pkg.name === packageName) {
78
+ return path.join(searchDir, subdir);
79
+ }
80
+ }
81
+ catch {
82
+ // Ignore invalid package.json files
83
+ }
84
+ }
85
+ }
86
+ }
87
+ catch {
88
+ // Ignore errors reading directory
89
+ continue;
90
+ }
91
+ }
92
+ // Fallback to old behavior if not found
93
+ const baseName = packageName.startsWith(ORG + "/")
94
+ ? packageName.substring(ORG.length + 1)
95
+ : packageName;
96
+ return path.join(localPath, "packages", baseName);
97
+ }
98
+ export const ENV_MAP = {
99
+ dev: "dev",
100
+ staging: "staging",
101
+ prod: "latest",
102
+ latest: "latest",
103
+ };
104
+ /**
105
+ * Checks if a string is a valid semver version
106
+ * Supports formats like: 1.0.0, 1.0.0-beta.1, 1.0.0-dev.123, v1.0.0
107
+ */
108
+ export function isVersionString(str) {
109
+ // Remove leading 'v' if present
110
+ const version = str.startsWith("v") ? str.slice(1) : str;
111
+ // Semver regex pattern
112
+ const semverPattern = /^\d+\.\d+\.\d+(-[a-zA-Z0-9]+(\.[a-zA-Z0-9]+)*)?(\+[a-zA-Z0-9]+(\.[a-zA-Z0-9]+)*)?$/;
113
+ return semverPattern.test(version);
114
+ }
115
+ export const updatePackageJson = async (envOrVersion, localPath, packageManager, debug, useResolved) => {
116
+ const projectInfo = await getProjectInfo();
117
+ const pkgManager = packageManager || getPackageManagerFromLockfile(projectInfo.path);
118
+ if (debug) {
119
+ console.log(">>> projectInfo", projectInfo);
120
+ console.log(">>> pkgManager", pkgManager);
121
+ }
122
+ // Read the project's package.json
123
+ const packageJsonPath = path.join(projectInfo.path, "package.json");
124
+ const packageJsonContent = readFileSync(packageJsonPath, "utf-8");
125
+ const packageJson = JSON.parse(packageJsonContent);
126
+ // Detect all Powerhouse packages from the current package.json
127
+ const powerhousePackages = detectPowerhousePackages(packageJson);
128
+ const dependencies = [];
129
+ if (localPath) {
130
+ // For local path, map each detected package to its monorepo path
131
+ powerhousePackages.forEach((packageName) => {
132
+ const fullPath = mapPackageToMonorepoPath(packageName, localPath);
133
+ dependencies.push(fullPath);
134
+ });
135
+ }
136
+ else {
137
+ // Determine the version tag to use
138
+ // For specific versions, add ^ prefix to allow semver range updates
139
+ const versionTag = isVersionString(envOrVersion)
140
+ ? `^${envOrVersion.replace(/^v/, "")}` // Remove leading 'v' if present and add ^
141
+ : ENV_MAP[envOrVersion];
142
+ // For remote dependencies, add version tags
143
+ powerhousePackages.forEach((packageName) => {
144
+ dependencies.push(`${packageName}@${versionTag}`);
145
+ });
146
+ }
147
+ if (debug) {
148
+ console.log(">>> dependencies to update", dependencies);
149
+ }
150
+ if (dependencies.length === 0) {
151
+ console.log("ℹ️ No Powerhouse dependencies found to update");
152
+ return;
153
+ }
154
+ try {
155
+ console.log("⚙️ Updating dependencies...");
156
+ if (localPath || useResolved) {
157
+ installDependency(pkgManager, dependencies, projectInfo.path);
158
+ }
159
+ else {
160
+ updateDependencyVersionString(pkgManager, dependencies, projectInfo.path);
161
+ }
162
+ console.log("✅ Dependencies updated successfully");
163
+ }
164
+ catch (error) {
165
+ console.error("❌ Failed to update dependencies");
166
+ throw error;
167
+ }
168
+ };
169
+ export const use = async (environment, localPath, options) => {
170
+ const isVersion = environment ? isVersionString(environment) : false;
171
+ if (!environment ||
172
+ (!options.force &&
173
+ environment !== "local" &&
174
+ !isVersion &&
175
+ !Object.keys(ENV_MAP).includes(environment))) {
176
+ throw new Error(`❌ Invalid environment, use --force or use one of the following: ${Object.keys(ENV_MAP).join(", ")}, or a specific version (e.g., 5.1.0)`);
177
+ }
178
+ if (environment === "local" && !localPath) {
179
+ throw new Error("❌ Local environment requires a local path, please specify the path to the local environment");
180
+ }
181
+ const { debug } = options;
182
+ // environment can be an Environment key or a version string
183
+ const envOrVersion = environment;
184
+ if (debug) {
185
+ console.log(">>> options", options);
186
+ }
187
+ const projectInfo = await getProjectInfo();
188
+ const packageManager = parsePackageManager(options) ??
189
+ getPackageManagerFromLockfile(projectInfo.path);
190
+ await updatePackageJson(envOrVersion, localPath, packageManager, debug, options.useResolved);
191
+ };
192
+ export function useCommand(program) {
193
+ const useCmd = program
194
+ .command("use")
195
+ .description("Allows you to change your environment (latest, dev, staging, prod, local) or use a specific version (e.g., 5.1.0)")
196
+ .argument("[environment]", "The environment to use (latest, dev, staging, prod, local) or a specific version (e.g., 5.1.0)")
197
+ .argument("[localPath]", "The path to the local environment (you have to specify the path to the local environment)")
198
+ .option("--force", "force environment to use")
199
+ .option("--use-resolved", "Use resolved dependency versions")
200
+ .option("--package-manager <packageManager>", "package manager to be used")
201
+ .option("--pnpm", "Use 'pnpm' as package manager")
202
+ .option("--yarn", "Use 'yarn' as package manager")
203
+ .option("--bun", "Use 'bun' as package manager")
204
+ .option("--debug", "Show additional logs");
205
+ // Use withCustomHelp instead of withHelpAction and addHelpText
206
+ return withCustomHelp(useCmd, use, useHelp,
207
+ // Pre-check function to validate environment before running the action
208
+ (environment) => {
209
+ if (!environment &&
210
+ !process.argv.includes("--help") &&
211
+ !process.argv.includes("-h")) {
212
+ console.error('Error: Missing required argument "environment"');
213
+ process.exit(1);
214
+ return false;
215
+ }
216
+ return true;
217
+ });
218
+ }
219
+ //# sourceMappingURL=use.old.js.map