ph-cmd 0.43.9-dev.1 → 0.43.9-dev.4
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__/update.test.js +27 -26
- package/dist/src/commands/__tests__/use.test.js +115 -12
- package/dist/src/commands/update.d.ts.map +1 -1
- package/dist/src/commands/update.js +24 -3
- package/dist/src/commands/use.d.ts +5 -1
- package/dist/src/commands/use.d.ts.map +1 -1
- package/dist/src/commands/use.js +51 -9
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
|
@@ -44,6 +44,8 @@ describe("updateCommand", () => {
|
|
|
44
44
|
return JSON.stringify({
|
|
45
45
|
dependencies: {
|
|
46
46
|
"@powerhousedao/builder-tools": "link:/user/powerhouse/monorepo/packages/builder-tools",
|
|
47
|
+
"@powerhousedao/common": "^0.40.0",
|
|
48
|
+
"@powerhousedao/design-system": "^0.40.0",
|
|
47
49
|
},
|
|
48
50
|
});
|
|
49
51
|
}
|
|
@@ -88,37 +90,18 @@ describe("updateCommand", () => {
|
|
|
88
90
|
vi.mocked(fs.readFileSync).mockImplementation((filePath) => {
|
|
89
91
|
if (filePath === path.join("/test/project", "package.json")) {
|
|
90
92
|
return JSON.stringify({
|
|
91
|
-
dependencies: {
|
|
92
|
-
|
|
93
|
+
dependencies: {
|
|
94
|
+
"@powerhousedao/common": "^0.40.0",
|
|
95
|
+
"@powerhousedao/design-system": "^0.40.0",
|
|
96
|
+
},
|
|
93
97
|
});
|
|
94
98
|
}
|
|
95
99
|
throw new Error(`Unexpected file read: ${String(filePath)}`);
|
|
96
100
|
});
|
|
97
|
-
// Mock fs.existsSync to return true for test paths
|
|
98
|
-
vi.spyOn(fs, "existsSync").mockImplementation((p) => {
|
|
99
|
-
const validPaths = [
|
|
100
|
-
"/test/project",
|
|
101
|
-
"/user/powerhouse/monorepo",
|
|
102
|
-
"/test/project/package.json",
|
|
103
|
-
path.join("/test/project", "package.json"),
|
|
104
|
-
path.join("/test/project", "pnpm-lock.yaml"),
|
|
105
|
-
];
|
|
106
|
-
return validPaths.includes(p);
|
|
107
|
-
});
|
|
108
101
|
const cmd = program.commands.find((c) => c.name() === "update");
|
|
109
102
|
await cmd?.parseAsync(["node", "test", "--force", "prod"]);
|
|
110
103
|
// When using --force, it should call installDependency with the latest versions
|
|
111
|
-
expect(installDependency).toHaveBeenCalledWith("pnpm", [
|
|
112
|
-
"@powerhousedao/common@latest",
|
|
113
|
-
"@powerhousedao/design-system@latest",
|
|
114
|
-
"@powerhousedao/reactor-browser@latest",
|
|
115
|
-
"@powerhousedao/builder-tools@latest",
|
|
116
|
-
"@powerhousedao/codegen@latest",
|
|
117
|
-
"@powerhousedao/reactor-api@latest",
|
|
118
|
-
"@powerhousedao/reactor-local@latest",
|
|
119
|
-
"@powerhousedao/scalars@latest",
|
|
120
|
-
"@powerhousedao/ph-cli@latest",
|
|
121
|
-
], "/test/project");
|
|
104
|
+
expect(installDependency).toHaveBeenCalledWith("pnpm", ["@powerhousedao/common@latest", "@powerhousedao/design-system@latest"], "/test/project");
|
|
122
105
|
});
|
|
123
106
|
it("should handle debug flag", async () => {
|
|
124
107
|
const consoleSpy = vi.spyOn(console, "log");
|
|
@@ -141,10 +124,28 @@ describe("updateCommand", () => {
|
|
|
141
124
|
});
|
|
142
125
|
const cmd = program.commands.find((c) => c.name() === "update");
|
|
143
126
|
await cmd?.parseAsync(["node", "test"]);
|
|
144
|
-
// Should call execSync with pnpm update for
|
|
145
|
-
expect(childProcess.execSync).toHaveBeenCalledWith("pnpm update @powerhousedao/
|
|
127
|
+
// Should call execSync with pnpm update for only the installed dependencies (sorted alphabetically)
|
|
128
|
+
expect(childProcess.execSync).toHaveBeenCalledWith("pnpm update @powerhousedao/builder-tools @powerhousedao/common", expect.objectContaining({
|
|
146
129
|
stdio: "inherit",
|
|
147
130
|
cwd: "/test/project",
|
|
148
131
|
}));
|
|
149
132
|
});
|
|
133
|
+
it("should show message when no Powerhouse dependencies are found", async () => {
|
|
134
|
+
// Mock fs.readFileSync to return package.json without any Powerhouse dependencies
|
|
135
|
+
vi.mocked(fs.readFileSync).mockImplementation((filePath) => {
|
|
136
|
+
if (filePath === path.join("/test/project", "package.json")) {
|
|
137
|
+
return JSON.stringify({
|
|
138
|
+
dependencies: {
|
|
139
|
+
"some-other-package": "^1.0.0",
|
|
140
|
+
},
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
throw new Error(`Unexpected file read: ${String(filePath)}`);
|
|
144
|
+
});
|
|
145
|
+
const consoleSpy = vi.spyOn(console, "log");
|
|
146
|
+
const cmd = program.commands.find((c) => c.name() === "update");
|
|
147
|
+
await cmd?.parseAsync(["node", "test"]);
|
|
148
|
+
expect(consoleSpy).toHaveBeenCalledWith("ℹ️ No Powerhouse dependencies found to update");
|
|
149
|
+
expect(childProcess.execSync).not.toHaveBeenCalled();
|
|
150
|
+
});
|
|
150
151
|
});
|
|
@@ -44,6 +44,26 @@ describe("useCommand", () => {
|
|
|
44
44
|
];
|
|
45
45
|
return validPaths.includes(p);
|
|
46
46
|
});
|
|
47
|
+
// Mock fs.readFileSync to return a test package.json
|
|
48
|
+
vi.spyOn(fs, "readFileSync").mockImplementation((p) => {
|
|
49
|
+
if (p === path.join("/test/project", "package.json")) {
|
|
50
|
+
return JSON.stringify({
|
|
51
|
+
dependencies: {
|
|
52
|
+
"@powerhousedao/common": "1.0.0",
|
|
53
|
+
"@powerhousedao/design-system": "1.0.0",
|
|
54
|
+
"@powerhousedao/reactor-browser": "1.0.0",
|
|
55
|
+
"document-model": "1.0.0",
|
|
56
|
+
"document-drive": "1.0.0",
|
|
57
|
+
"some-other-package": "1.0.0",
|
|
58
|
+
},
|
|
59
|
+
devDependencies: {
|
|
60
|
+
"@powerhousedao/builder-tools": "1.0.0",
|
|
61
|
+
"@powerhousedao/codegen": "1.0.0",
|
|
62
|
+
},
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
return "";
|
|
66
|
+
});
|
|
47
67
|
// Mock installDependency
|
|
48
68
|
vi.mocked(installDependency).mockImplementation(() => { });
|
|
49
69
|
});
|
|
@@ -64,10 +84,8 @@ describe("useCommand", () => {
|
|
|
64
84
|
"@powerhousedao/reactor-browser@dev",
|
|
65
85
|
"@powerhousedao/builder-tools@dev",
|
|
66
86
|
"@powerhousedao/codegen@dev",
|
|
67
|
-
"
|
|
68
|
-
"
|
|
69
|
-
"@powerhousedao/scalars@dev",
|
|
70
|
-
"@powerhousedao/ph-cli@dev",
|
|
87
|
+
"document-model@dev",
|
|
88
|
+
"document-drive@dev",
|
|
71
89
|
], "/test/project");
|
|
72
90
|
});
|
|
73
91
|
it("should execute use command with prod environment", async () => {
|
|
@@ -79,10 +97,8 @@ describe("useCommand", () => {
|
|
|
79
97
|
"@powerhousedao/reactor-browser@latest",
|
|
80
98
|
"@powerhousedao/builder-tools@latest",
|
|
81
99
|
"@powerhousedao/codegen@latest",
|
|
82
|
-
"
|
|
83
|
-
"
|
|
84
|
-
"@powerhousedao/scalars@latest",
|
|
85
|
-
"@powerhousedao/ph-cli@latest",
|
|
100
|
+
"document-model@latest",
|
|
101
|
+
"document-drive@latest",
|
|
86
102
|
], "/test/project");
|
|
87
103
|
});
|
|
88
104
|
it("should execute use command with local environment", async () => {
|
|
@@ -94,10 +110,8 @@ describe("useCommand", () => {
|
|
|
94
110
|
"/path/to/local/packages/reactor-browser",
|
|
95
111
|
"/path/to/local/packages/builder-tools",
|
|
96
112
|
"/path/to/local/packages/codegen",
|
|
97
|
-
"/path/to/local/packages/
|
|
98
|
-
"/path/to/local/packages/
|
|
99
|
-
"/path/to/local/packages/scalars",
|
|
100
|
-
"/path/to/local/clis/ph-cli",
|
|
113
|
+
"/path/to/local/packages/document-model",
|
|
114
|
+
"/path/to/local/packages/document-drive",
|
|
101
115
|
], "/test/project");
|
|
102
116
|
});
|
|
103
117
|
it("should handle debug flag", async () => {
|
|
@@ -105,6 +119,9 @@ describe("useCommand", () => {
|
|
|
105
119
|
const cmd = program.commands.find((c) => c.name() === "use");
|
|
106
120
|
await cmd?.parseAsync(["node", "test", "dev", "--debug"]);
|
|
107
121
|
expect(consoleSpy).toHaveBeenCalledWith(">>> options", expect.any(Object));
|
|
122
|
+
expect(consoleSpy).toHaveBeenCalledWith(">>> projectInfo", expect.any(Object));
|
|
123
|
+
expect(consoleSpy).toHaveBeenCalledWith(">>> pkgManager", "pnpm");
|
|
124
|
+
expect(consoleSpy).toHaveBeenCalledWith(">>> dependencies to update", expect.any(Array));
|
|
108
125
|
});
|
|
109
126
|
it("should throw error when no environment is specified", async () => {
|
|
110
127
|
const cmd = program.commands.find((c) => c.name() === "use");
|
|
@@ -119,4 +136,90 @@ describe("useCommand", () => {
|
|
|
119
136
|
await cmd?.parseAsync(["node", "test", "dev", "--package-manager", "npm"]);
|
|
120
137
|
expect(installDependency).toHaveBeenCalledWith("npm", expect.any(Array), "/test/project");
|
|
121
138
|
});
|
|
139
|
+
it("should not update dependencies that are not installed", async () => {
|
|
140
|
+
const cmd = program.commands.find((c) => c.name() === "use");
|
|
141
|
+
await cmd?.parseAsync(["node", "test", "dev"]);
|
|
142
|
+
// Verify that only installed dependencies are updated
|
|
143
|
+
const call = vi.mocked(installDependency).mock.calls[0];
|
|
144
|
+
const updatedDependencies = call[1];
|
|
145
|
+
expect(updatedDependencies).not.toContain("@powerhousedao/reactor-api@dev");
|
|
146
|
+
expect(updatedDependencies).not.toContain("@powerhousedao/reactor-local@dev");
|
|
147
|
+
expect(updatedDependencies).not.toContain("@powerhousedao/scalars@dev");
|
|
148
|
+
expect(updatedDependencies).not.toContain("@powerhousedao/ph-cli@dev");
|
|
149
|
+
});
|
|
150
|
+
it("should show message when no Powerhouse dependencies are found", async () => {
|
|
151
|
+
// Mock package.json with no Powerhouse dependencies
|
|
152
|
+
vi.spyOn(fs, "readFileSync").mockImplementation((p) => {
|
|
153
|
+
if (p === path.join("/test/project", "package.json")) {
|
|
154
|
+
return JSON.stringify({
|
|
155
|
+
dependencies: {
|
|
156
|
+
"some-other-package": "1.0.0",
|
|
157
|
+
},
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
return "";
|
|
161
|
+
});
|
|
162
|
+
const consoleSpy = vi.spyOn(console, "log");
|
|
163
|
+
const cmd = program.commands.find((c) => c.name() === "use");
|
|
164
|
+
await cmd?.parseAsync(["node", "test", "dev"]);
|
|
165
|
+
expect(consoleSpy).toHaveBeenCalledWith("ℹ️ No Powerhouse dependencies found to update");
|
|
166
|
+
expect(installDependency).not.toHaveBeenCalled();
|
|
167
|
+
});
|
|
168
|
+
it("should handle special packages without @powerhousedao prefix", async () => {
|
|
169
|
+
// Mock package.json with only special packages
|
|
170
|
+
vi.spyOn(fs, "readFileSync").mockImplementation((p) => {
|
|
171
|
+
if (p === path.join("/test/project", "package.json")) {
|
|
172
|
+
return JSON.stringify({
|
|
173
|
+
dependencies: {
|
|
174
|
+
"document-model": "1.0.0",
|
|
175
|
+
"document-drive": "1.0.0",
|
|
176
|
+
},
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
return "";
|
|
180
|
+
});
|
|
181
|
+
const cmd = program.commands.find((c) => c.name() === "use");
|
|
182
|
+
await cmd?.parseAsync(["node", "test", "dev"]);
|
|
183
|
+
expect(installDependency).toHaveBeenCalledWith("pnpm", ["document-model@dev", "document-drive@dev"], "/test/project");
|
|
184
|
+
});
|
|
185
|
+
it("should update only existing @powerhousedao dependencies", async () => {
|
|
186
|
+
// Mock package.json with only common and design-system
|
|
187
|
+
vi.spyOn(fs, "readFileSync").mockImplementation((p) => {
|
|
188
|
+
if (p === path.join("/test/project", "package.json")) {
|
|
189
|
+
return JSON.stringify({
|
|
190
|
+
dependencies: {
|
|
191
|
+
"@powerhousedao/common": "1.0.0",
|
|
192
|
+
"@powerhousedao/design-system": "1.0.0",
|
|
193
|
+
},
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
return "";
|
|
197
|
+
});
|
|
198
|
+
const cmd = program.commands.find((c) => c.name() === "use");
|
|
199
|
+
await cmd?.parseAsync(["node", "test", "dev"]);
|
|
200
|
+
expect(installDependency).toHaveBeenCalledWith("pnpm", ["@powerhousedao/common@dev", "@powerhousedao/design-system@dev"], "/test/project");
|
|
201
|
+
});
|
|
202
|
+
it("should update only existing document-model and document-drive without adding @powerhousedao prefix", async () => {
|
|
203
|
+
// Mock package.json with only document-model and document-drive
|
|
204
|
+
vi.spyOn(fs, "readFileSync").mockImplementation((p) => {
|
|
205
|
+
if (p === path.join("/test/project", "package.json")) {
|
|
206
|
+
return JSON.stringify({
|
|
207
|
+
dependencies: {
|
|
208
|
+
"document-model": "1.0.0",
|
|
209
|
+
"document-drive": "1.0.0",
|
|
210
|
+
},
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
return "";
|
|
214
|
+
});
|
|
215
|
+
const cmd = program.commands.find((c) => c.name() === "use");
|
|
216
|
+
await cmd?.parseAsync(["node", "test", "dev"]);
|
|
217
|
+
const updatedDependencies = vi.mocked(installDependency).mock.calls[0][1];
|
|
218
|
+
expect(updatedDependencies).toEqual([
|
|
219
|
+
"document-model@dev",
|
|
220
|
+
"document-drive@dev",
|
|
221
|
+
]);
|
|
222
|
+
expect(updatedDependencies).not.toContain("@powerhousedao/document-model@dev");
|
|
223
|
+
expect(updatedDependencies).not.toContain("@powerhousedao/document-drive@dev");
|
|
224
|
+
});
|
|
122
225
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"update.d.ts","sourceRoot":"","sources":["../../../src/commands/update.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,OAAO,EAAE,MAAM,WAAW,CAAC;AAIzC,OAAO,EAAE,KAAK,iBAAiB,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"update.d.ts","sourceRoot":"","sources":["../../../src/commands/update.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,OAAO,EAAE,MAAM,WAAW,CAAC;AAIzC,OAAO,EAAE,KAAK,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAsFrD,eAAO,MAAM,MAAM,EAAE,iBAAiB,CACpC;IACE;QACE,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,KAAK,CAAC,EAAE,OAAO,CAAC;QAChB,cAAc,CAAC,EAAE,MAAM,CAAC;KACzB;CACF,CA6DF,CAAC;AAEF,wBAAgB,aAAa,CAAC,OAAO,EAAE,OAAO,QA6B7C"}
|
|
@@ -23,8 +23,8 @@ const getLocalDependencyPath = (projectPath) => {
|
|
|
23
23
|
const packageJson = JSON.parse(fs.readFileSync(path.join(projectPath, "package.json"), "utf-8"));
|
|
24
24
|
// filter dependencies
|
|
25
25
|
const filteredDependencies = Object.entries({
|
|
26
|
-
...packageJson.dependencies,
|
|
27
|
-
...packageJson.devDependencies,
|
|
26
|
+
...(packageJson.dependencies || {}),
|
|
27
|
+
...(packageJson.devDependencies || {}),
|
|
28
28
|
}).filter(([name]) => PH_PROJECT_DEPENDENCIES.includes(name));
|
|
29
29
|
const [_, localDependencyPath] = filteredDependencies.find(([_, version]) => version.startsWith(FILE_PROTOCOL) || version.startsWith(LINK_PROTOCOL)) || [null, null];
|
|
30
30
|
if (!localDependencyPath)
|
|
@@ -33,6 +33,18 @@ const getLocalDependencyPath = (projectPath) => {
|
|
|
33
33
|
.replace(FILE_PROTOCOL, "")
|
|
34
34
|
.replace(LINK_PROTOCOL, "");
|
|
35
35
|
};
|
|
36
|
+
const getInstalledDependencies = (projectPath) => {
|
|
37
|
+
// read package json from projectInfo.path
|
|
38
|
+
const packageJson = JSON.parse(fs.readFileSync(path.join(projectPath, "package.json"), "utf-8"));
|
|
39
|
+
// Get all installed Powerhouse dependencies
|
|
40
|
+
const installedDeps = Object.keys({
|
|
41
|
+
...(packageJson.dependencies || {}),
|
|
42
|
+
...(packageJson.devDependencies || {}),
|
|
43
|
+
})
|
|
44
|
+
.filter((name) => PH_PROJECT_DEPENDENCIES.includes(name))
|
|
45
|
+
.sort(); // Sort dependencies alphabetically
|
|
46
|
+
return installedDeps;
|
|
47
|
+
};
|
|
36
48
|
export const update = (options) => {
|
|
37
49
|
const { force, packageManager, debug } = options;
|
|
38
50
|
if (debug) {
|
|
@@ -59,9 +71,17 @@ export const update = (options) => {
|
|
|
59
71
|
updatePackageJson(env, undefined, pkgManagerName, debug);
|
|
60
72
|
return;
|
|
61
73
|
}
|
|
74
|
+
const installedDeps = getInstalledDependencies(projectInfo.path);
|
|
75
|
+
if (installedDeps.length === 0) {
|
|
76
|
+
console.log("ℹ️ No Powerhouse dependencies found to update");
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
62
79
|
const pkgManager = packageManagers[pkgManagerName];
|
|
63
|
-
const deps =
|
|
80
|
+
const deps = installedDeps.join(" ");
|
|
64
81
|
const updateCommand = pkgManager.updateCommand.replace("{{dependency}}", deps);
|
|
82
|
+
if (options.debug) {
|
|
83
|
+
console.log(">>> dependencies to update", installedDeps);
|
|
84
|
+
}
|
|
65
85
|
const commandOptions = { cwd: projectInfo.path };
|
|
66
86
|
execSync(updateCommand, {
|
|
67
87
|
stdio: "inherit",
|
|
@@ -71,6 +91,7 @@ export const update = (options) => {
|
|
|
71
91
|
export function updateCommand(program) {
|
|
72
92
|
program
|
|
73
93
|
.command("update")
|
|
94
|
+
.alias("up")
|
|
74
95
|
.description("Allows you to update your dependencies to the latest version based on the specified range in package.json. If you want to update to the latest available version, use the --force flag.")
|
|
75
96
|
.option("--force <env>", "Force update to latest available version for the environment specified (dev, prod, latest)")
|
|
76
97
|
.option("--package-manager <packageManager>", "force package manager to use")
|
|
@@ -2,12 +2,15 @@ import { type Command } from "commander";
|
|
|
2
2
|
import { type CommandActionType } from "../types.js";
|
|
3
3
|
import { type PackageManager } from "../utils.js";
|
|
4
4
|
export declare const ORG = "@powerhousedao";
|
|
5
|
-
export declare const
|
|
5
|
+
export declare const SPECIAL_PACKAGES: string[];
|
|
6
6
|
export declare const PACKAGES: string[];
|
|
7
|
+
export declare const CLIS: string[];
|
|
8
|
+
export declare const APPS: string[];
|
|
7
9
|
export declare const PH_PROJECT_DEPENDENCIES: string[];
|
|
8
10
|
export declare const PH_PROJECT_LOCAL_DEPENDENCIES: string[];
|
|
9
11
|
export declare const ENV_MAP: {
|
|
10
12
|
dev: string;
|
|
13
|
+
staging: string;
|
|
11
14
|
prod: string;
|
|
12
15
|
latest: string;
|
|
13
16
|
};
|
|
@@ -22,6 +25,7 @@ export declare const use: CommandActionType<[
|
|
|
22
25
|
local?: string;
|
|
23
26
|
debug?: boolean;
|
|
24
27
|
latest?: boolean;
|
|
28
|
+
force?: boolean;
|
|
25
29
|
packageManager?: string;
|
|
26
30
|
}
|
|
27
31
|
]>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use.d.ts","sourceRoot":"","sources":["../../../src/commands/use.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,OAAO,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"use.d.ts","sourceRoot":"","sources":["../../../src/commands/use.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,OAAO,EAAE,MAAM,WAAW,CAAC;AAGzC,OAAO,EAAE,KAAK,iBAAiB,EAAE,MAAM,aAAa,CAAC;AACrD,OAAO,EAIL,KAAK,cAAc,EACpB,MAAM,aAAa,CAAC;AAErB,eAAO,MAAM,GAAG,mBAAmB,CAAC;AAGpC,eAAO,MAAM,gBAAgB,UAAuC,CAAC;AAGrE,eAAO,MAAM,QAAQ,UAapB,CAAC;AAEF,eAAO,MAAM,IAAI,UAAuB,CAAC;AAEzC,eAAO,MAAM,IAAI,UAA6B,CAAC;AAE/C,eAAO,MAAM,uBAAuB,UAOnC,CAAC;AAEF,eAAO,MAAM,6BAA6B,UAIzC,CAAC;AAEF,eAAO,MAAM,OAAO;;;;;CAKnB,CAAC;AAGF,MAAM,MAAM,WAAW,GAAG,MAAM,OAAO,OAAO,CAAC;AAE/C,eAAO,MAAM,iBAAiB,GAC5B,KAAK,WAAW,EAChB,YAAY,MAAM,EAClB,iBAAiB,cAAc,EAC/B,QAAQ,OAAO,SAgEhB,CAAC;AAEF,eAAO,MAAM,GAAG,EAAE,iBAAiB,CACjC;IACE,MAAM,GAAG,SAAS;IAClB,MAAM,GAAG,SAAS;IAClB;QACE,GAAG,CAAC,EAAE,OAAO,CAAC;QACd,IAAI,CAAC,EAAE,OAAO,CAAC;QACf,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,KAAK,CAAC,EAAE,OAAO,CAAC;QAChB,MAAM,CAAC,EAAE,OAAO,CAAC;QACjB,KAAK,CAAC,EAAE,OAAO,CAAC;QAChB,cAAc,CAAC,EAAE,MAAM,CAAC;KACzB;CACF,CA4BF,CAAC;AAEF,wBAAgB,UAAU,CAAC,OAAO,EAAE,OAAO,QAqB1C"}
|
package/dist/src/commands/use.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
1
2
|
import path from "node:path";
|
|
2
3
|
import { getPackageManagerFromLockfile, getProjectInfo, installDependency, } from "../utils.js";
|
|
3
4
|
export const ORG = "@powerhousedao";
|
|
4
|
-
|
|
5
|
+
// Special packages that don't use the @powerhousedao organization
|
|
6
|
+
export const SPECIAL_PACKAGES = ["document-model", "document-drive"];
|
|
7
|
+
// Dynamically list all packages, clis, and apps
|
|
5
8
|
export const PACKAGES = [
|
|
6
9
|
"common",
|
|
7
10
|
"design-system",
|
|
@@ -11,37 +14,73 @@ export const PACKAGES = [
|
|
|
11
14
|
"reactor-api",
|
|
12
15
|
"reactor-local",
|
|
13
16
|
"scalars",
|
|
17
|
+
"switchboard-gui",
|
|
18
|
+
"renown",
|
|
19
|
+
"config",
|
|
20
|
+
...SPECIAL_PACKAGES,
|
|
14
21
|
];
|
|
22
|
+
export const CLIS = ["ph-cli", "ph-cmd"];
|
|
23
|
+
export const APPS = ["switchboard", "connect"];
|
|
15
24
|
export const PH_PROJECT_DEPENDENCIES = [
|
|
16
|
-
...PACKAGES.map((dependency) => `${ORG}/${dependency}`),
|
|
25
|
+
...PACKAGES.filter((pkg) => !SPECIAL_PACKAGES.includes(pkg)).map((dependency) => `${ORG}/${dependency}`),
|
|
26
|
+
...SPECIAL_PACKAGES,
|
|
17
27
|
...CLIS.map((dependency) => `${ORG}/${dependency}`),
|
|
28
|
+
...APPS.map((dependency) => `${ORG}/${dependency}`),
|
|
18
29
|
];
|
|
19
30
|
export const PH_PROJECT_LOCAL_DEPENDENCIES = [
|
|
20
31
|
...PACKAGES.map((dependency) => path.join("packages", dependency)),
|
|
21
32
|
...CLIS.map((dependency) => path.join("clis", dependency)),
|
|
33
|
+
...APPS.map((dependency) => path.join("apps", dependency)),
|
|
22
34
|
];
|
|
23
35
|
export const ENV_MAP = {
|
|
24
36
|
dev: "dev",
|
|
37
|
+
staging: "staging",
|
|
25
38
|
prod: "latest",
|
|
26
39
|
latest: "latest",
|
|
27
40
|
};
|
|
28
41
|
export const updatePackageJson = (env, localPath, packageManager, debug) => {
|
|
29
|
-
const dependencies = [];
|
|
30
42
|
const projectInfo = getProjectInfo();
|
|
31
43
|
const pkgManager = packageManager || getPackageManagerFromLockfile(projectInfo.path);
|
|
32
44
|
if (debug) {
|
|
33
45
|
console.log(">>> projectInfo", projectInfo);
|
|
34
46
|
console.log(">>> pkgManager", pkgManager);
|
|
35
47
|
}
|
|
48
|
+
// Read the project's package.json
|
|
49
|
+
const packageJsonPath = path.join(projectInfo.path, "package.json");
|
|
50
|
+
const packageJsonContent = readFileSync(packageJsonPath, "utf-8");
|
|
51
|
+
const packageJson = JSON.parse(packageJsonContent);
|
|
52
|
+
const existingDependencies = {
|
|
53
|
+
...(packageJson.dependencies || {}),
|
|
54
|
+
...(packageJson.devDependencies || {}),
|
|
55
|
+
};
|
|
56
|
+
const dependencies = [];
|
|
36
57
|
if (localPath) {
|
|
37
|
-
|
|
38
|
-
|
|
58
|
+
// For local path, only include dependencies that exist in package.json
|
|
59
|
+
PH_PROJECT_LOCAL_DEPENDENCIES.forEach((dependency) => {
|
|
60
|
+
const fullPath = path.join(localPath, dependency);
|
|
61
|
+
const packageName = path.basename(dependency);
|
|
62
|
+
const depName = SPECIAL_PACKAGES.includes(packageName)
|
|
63
|
+
? packageName
|
|
64
|
+
: `${ORG}/${packageName}`;
|
|
65
|
+
if (existingDependencies[depName]) {
|
|
66
|
+
dependencies.push(fullPath);
|
|
67
|
+
}
|
|
68
|
+
});
|
|
39
69
|
}
|
|
40
70
|
else {
|
|
41
|
-
dependencies
|
|
71
|
+
// For remote dependencies, only include those that exist in package.json
|
|
72
|
+
PH_PROJECT_DEPENDENCIES.forEach((dependency) => {
|
|
73
|
+
if (existingDependencies[dependency]) {
|
|
74
|
+
dependencies.push(`${dependency}@${ENV_MAP[env]}`);
|
|
75
|
+
}
|
|
76
|
+
});
|
|
42
77
|
}
|
|
43
78
|
if (debug) {
|
|
44
|
-
console.log(">>> dependencies", dependencies);
|
|
79
|
+
console.log(">>> dependencies to update", dependencies);
|
|
80
|
+
}
|
|
81
|
+
if (dependencies.length === 0) {
|
|
82
|
+
console.log("ℹ️ No Powerhouse dependencies found to update");
|
|
83
|
+
return;
|
|
45
84
|
}
|
|
46
85
|
try {
|
|
47
86
|
console.log("⚙️ Updating dependencies...");
|
|
@@ -55,8 +94,10 @@ export const updatePackageJson = (env, localPath, packageManager, debug) => {
|
|
|
55
94
|
};
|
|
56
95
|
export const use = (environment, localPath, options) => {
|
|
57
96
|
if (!environment ||
|
|
58
|
-
(
|
|
59
|
-
|
|
97
|
+
(!options.force &&
|
|
98
|
+
environment !== "local" &&
|
|
99
|
+
!Object.keys(ENV_MAP).includes(environment))) {
|
|
100
|
+
throw new Error(`❌ Invalid environment, use --force or use one of the following: ${Object.keys(ENV_MAP).join(", ")}`);
|
|
60
101
|
}
|
|
61
102
|
if (environment === "local" && !localPath) {
|
|
62
103
|
throw new Error("❌ Local environment requires a local path, please specify the path to the local environment");
|
|
@@ -74,6 +115,7 @@ export function useCommand(program) {
|
|
|
74
115
|
.description("Allows you to change your environment (latest, development, production, local)")
|
|
75
116
|
.argument("<environment>", "The environment to use (latest, dev, prod, local)")
|
|
76
117
|
.argument("[localPath]", "The path to the local environment (you have to specify the path to the local environment)")
|
|
118
|
+
.option("--force", "force environment to use")
|
|
77
119
|
.option("--package-manager <packageManager>", "force package manager to use")
|
|
78
120
|
.option("--debug", "Show additional logs")
|
|
79
121
|
.action(use);
|