@powerhousedao/ph-cli 0.40.7-dev.0 → 0.40.7-dev.3
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/package.json +4 -2
- package/dist/src/commands/__tests__/update.test.d.ts +2 -0
- package/dist/src/commands/__tests__/update.test.d.ts.map +1 -0
- package/dist/src/commands/__tests__/update.test.js +152 -0
- package/dist/src/commands/__tests__/use.test.d.ts +2 -0
- package/dist/src/commands/__tests__/use.test.d.ts.map +1 -0
- package/dist/src/commands/__tests__/use.test.js +130 -0
- package/dist/src/commands/connect.d.ts.map +1 -1
- package/dist/src/commands/connect.js +0 -2
- package/dist/src/commands/index.d.ts.map +1 -1
- package/dist/src/commands/index.js +4 -0
- package/dist/src/commands/inspect.d.ts +1 -4
- package/dist/src/commands/inspect.d.ts.map +1 -1
- package/dist/src/commands/update.d.ts +11 -0
- package/dist/src/commands/update.d.ts.map +1 -0
- package/dist/src/commands/update.js +89 -0
- package/dist/src/commands/use.d.ts +27 -0
- package/dist/src/commands/use.d.ts.map +1 -0
- package/dist/src/commands/use.js +82 -0
- package/dist/src/services/connect.d.ts.map +1 -1
- package/dist/src/services/connect.js +1 -3
- package/dist/src/services/dev.d.ts.map +1 -1
- package/dist/src/services/dev.js +0 -2
- package/dist/src/utils.d.ts +25 -0
- package/dist/src/utils.d.ts.map +1 -1
- package/dist/src/utils.js +36 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +11 -9
package/dist/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@powerhousedao/ph-cli",
|
|
3
|
-
"version": "0.40.7-dev.
|
|
3
|
+
"version": "0.40.7-dev.3",
|
|
4
4
|
"description": "",
|
|
5
5
|
"license": "AGPL-3.0-only",
|
|
6
6
|
"type": "module",
|
|
@@ -19,7 +19,9 @@
|
|
|
19
19
|
"prepublishOnly": "npm run build",
|
|
20
20
|
"lint": "eslint .",
|
|
21
21
|
"lint:nx": "eslint . --fix --quiet",
|
|
22
|
-
"lint:fix": "eslint --fix"
|
|
22
|
+
"lint:fix": "eslint --fix",
|
|
23
|
+
"test": "vitest run",
|
|
24
|
+
"test:watch": "vitest watch"
|
|
23
25
|
},
|
|
24
26
|
"keywords": [],
|
|
25
27
|
"author": "",
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"update.test.d.ts","sourceRoot":"","sources":["../../../../src/commands/__tests__/update.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import { Command } from "commander";
|
|
2
|
+
import * as childProcess from "node:child_process";
|
|
3
|
+
import * as fs from "node:fs";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
6
|
+
import { findContainerDirectory, getPackageManagerFromLockfile, getProjectInfo, } from "../../utils.js";
|
|
7
|
+
import { updateCommand } from "../update.js";
|
|
8
|
+
// Mock dependencies
|
|
9
|
+
vi.mock("node:fs");
|
|
10
|
+
vi.mock("node:child_process");
|
|
11
|
+
vi.mock("../install.js", () => ({
|
|
12
|
+
installDependency: vi.fn(),
|
|
13
|
+
}));
|
|
14
|
+
// Import installDependency after mocking
|
|
15
|
+
import { installDependency } from "../install.js";
|
|
16
|
+
vi.mock("../../utils.js", () => ({
|
|
17
|
+
packageManagers: {
|
|
18
|
+
pnpm: {
|
|
19
|
+
buildAffected: "pnpm run build:affected",
|
|
20
|
+
updateCommand: "pnpm update {{dependency}}",
|
|
21
|
+
installCommand: "pnpm install {{dependency}}",
|
|
22
|
+
workspaceOption: "--workspace-root",
|
|
23
|
+
lockfile: "pnpm-lock.yaml",
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
getPackageManagerFromLockfile: vi.fn(),
|
|
27
|
+
getProjectInfo: vi.fn(),
|
|
28
|
+
findContainerDirectory: vi.fn(),
|
|
29
|
+
}));
|
|
30
|
+
describe("updateCommand", () => {
|
|
31
|
+
let program;
|
|
32
|
+
beforeEach(() => {
|
|
33
|
+
vi.clearAllMocks();
|
|
34
|
+
vi.restoreAllMocks();
|
|
35
|
+
program = new Command();
|
|
36
|
+
updateCommand(program);
|
|
37
|
+
// Mock utils functions
|
|
38
|
+
vi.mocked(getPackageManagerFromLockfile).mockReturnValue("pnpm");
|
|
39
|
+
vi.mocked(getProjectInfo).mockReturnValue({
|
|
40
|
+
path: "/test/project",
|
|
41
|
+
});
|
|
42
|
+
vi.mocked(findContainerDirectory).mockReturnValue("/user/powerhouse/monorepo");
|
|
43
|
+
// Mock fs.readFileSync for package.json
|
|
44
|
+
vi.mocked(fs.readFileSync).mockImplementation((filePath) => {
|
|
45
|
+
if (filePath === path.join("/test/project", "package.json")) {
|
|
46
|
+
return JSON.stringify({
|
|
47
|
+
dependencies: {
|
|
48
|
+
"@powerhousedao/builder-tools": "link:/user/powerhouse/monorepo/packages/builder-tools",
|
|
49
|
+
},
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
throw new Error(`Unexpected file read: ${String(filePath)}`);
|
|
53
|
+
});
|
|
54
|
+
// Mock fs.existsSync to return true for test paths
|
|
55
|
+
vi.spyOn(fs, "existsSync").mockImplementation((p) => {
|
|
56
|
+
const validPaths = [
|
|
57
|
+
"/test/project",
|
|
58
|
+
"/user/powerhouse/monorepo",
|
|
59
|
+
"/test/project/package.json",
|
|
60
|
+
path.join("/test/project", "package.json"),
|
|
61
|
+
path.join("/test/project", "pnpm-lock.yaml"),
|
|
62
|
+
];
|
|
63
|
+
return validPaths.includes(p);
|
|
64
|
+
});
|
|
65
|
+
// Mock execSync
|
|
66
|
+
vi.mocked(childProcess.execSync).mockReturnValue(Buffer.from(""));
|
|
67
|
+
// Mock installDependency
|
|
68
|
+
vi.mocked(installDependency).mockImplementation(() => { });
|
|
69
|
+
});
|
|
70
|
+
it("should register the update command with correct options", () => {
|
|
71
|
+
const cmd = program.commands.find((c) => c.name() === "update");
|
|
72
|
+
expect(cmd).toBeDefined();
|
|
73
|
+
expect(cmd?.description()).toContain("update your dependencies");
|
|
74
|
+
// Get options from the command definition, not from parsed args
|
|
75
|
+
const options = cmd?.options.map((opt) => opt.attributeName());
|
|
76
|
+
expect(options).toContain("force");
|
|
77
|
+
expect(options).toContain("packageManager");
|
|
78
|
+
expect(options).toContain("debug");
|
|
79
|
+
});
|
|
80
|
+
it("should execute update command with local dependencies", async () => {
|
|
81
|
+
const cmd = program.commands.find((c) => c.name() === "update");
|
|
82
|
+
await cmd?.parseAsync(["node", "test"]);
|
|
83
|
+
expect(childProcess.execSync).toHaveBeenCalledWith("pnpm run build:affected", expect.objectContaining({
|
|
84
|
+
stdio: "inherit",
|
|
85
|
+
cwd: "/user/powerhouse/monorepo",
|
|
86
|
+
}));
|
|
87
|
+
});
|
|
88
|
+
it("should execute update command with force flag", async () => {
|
|
89
|
+
// Mock fs.readFileSync for the specific package.json read in this test
|
|
90
|
+
vi.mocked(fs.readFileSync).mockImplementation((filePath) => {
|
|
91
|
+
if (filePath === path.join("/test/project", "package.json")) {
|
|
92
|
+
return JSON.stringify({
|
|
93
|
+
dependencies: {},
|
|
94
|
+
devDependencies: {},
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
throw new Error(`Unexpected file read: ${String(filePath)}`);
|
|
98
|
+
});
|
|
99
|
+
// Mock fs.existsSync to return true for test paths
|
|
100
|
+
vi.spyOn(fs, "existsSync").mockImplementation((p) => {
|
|
101
|
+
const validPaths = [
|
|
102
|
+
"/test/project",
|
|
103
|
+
"/user/powerhouse/monorepo",
|
|
104
|
+
"/test/project/package.json",
|
|
105
|
+
path.join("/test/project", "package.json"),
|
|
106
|
+
path.join("/test/project", "pnpm-lock.yaml"),
|
|
107
|
+
];
|
|
108
|
+
return validPaths.includes(p);
|
|
109
|
+
});
|
|
110
|
+
const cmd = program.commands.find((c) => c.name() === "update");
|
|
111
|
+
await cmd?.parseAsync(["node", "test", "--force", "prod"]);
|
|
112
|
+
// When using --force, it should call installDependency with the latest versions
|
|
113
|
+
expect(installDependency).toHaveBeenCalledWith("pnpm", [
|
|
114
|
+
"@powerhousedao/common@latest",
|
|
115
|
+
"@powerhousedao/design-system@latest",
|
|
116
|
+
"@powerhousedao/reactor-browser@latest",
|
|
117
|
+
"@powerhousedao/builder-tools@latest",
|
|
118
|
+
"@powerhousedao/codegen@latest",
|
|
119
|
+
"@powerhousedao/reactor-api@latest",
|
|
120
|
+
"@powerhousedao/reactor-local@latest",
|
|
121
|
+
"@powerhousedao/scalars@latest",
|
|
122
|
+
"@powerhousedao/ph-cli@latest",
|
|
123
|
+
], "/test/project");
|
|
124
|
+
});
|
|
125
|
+
it("should handle debug flag", async () => {
|
|
126
|
+
const consoleSpy = vi.spyOn(console, "log");
|
|
127
|
+
const cmd = program.commands.find((c) => c.name() === "update");
|
|
128
|
+
await cmd?.parseAsync(["node", "test", "--debug"]);
|
|
129
|
+
expect(consoleSpy).toHaveBeenCalledWith(">>> options", expect.any(Object));
|
|
130
|
+
});
|
|
131
|
+
it("should execute update command without local dependencies", async () => {
|
|
132
|
+
// Mock fs.readFileSync to return package.json without local dependencies
|
|
133
|
+
vi.mocked(fs.readFileSync).mockImplementation((filePath) => {
|
|
134
|
+
if (filePath === path.join("/test/project", "package.json")) {
|
|
135
|
+
return JSON.stringify({
|
|
136
|
+
dependencies: {
|
|
137
|
+
"@powerhousedao/builder-tools": "^0.40.0",
|
|
138
|
+
"@powerhousedao/common": "^0.40.0",
|
|
139
|
+
},
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
throw new Error(`Unexpected file read: ${String(filePath)}`);
|
|
143
|
+
});
|
|
144
|
+
const cmd = program.commands.find((c) => c.name() === "update");
|
|
145
|
+
await cmd?.parseAsync(["node", "test"]);
|
|
146
|
+
// Should call execSync with pnpm update for all dependencies
|
|
147
|
+
expect(childProcess.execSync).toHaveBeenCalledWith("pnpm update @powerhousedao/common @powerhousedao/design-system @powerhousedao/reactor-browser @powerhousedao/builder-tools @powerhousedao/codegen @powerhousedao/reactor-api @powerhousedao/reactor-local @powerhousedao/scalars @powerhousedao/ph-cli", expect.objectContaining({
|
|
148
|
+
stdio: "inherit",
|
|
149
|
+
cwd: "/test/project",
|
|
150
|
+
}));
|
|
151
|
+
});
|
|
152
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use.test.d.ts","sourceRoot":"","sources":["../../../../src/commands/__tests__/use.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { Command } from "commander";
|
|
2
|
+
import * as fs from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
5
|
+
import { getPackageManagerFromLockfile, getProjectInfo, } from "../../utils.js";
|
|
6
|
+
import { useCommand } from "../use.js";
|
|
7
|
+
// Mock dependencies
|
|
8
|
+
vi.mock("node:fs");
|
|
9
|
+
vi.mock("../install.js", () => ({
|
|
10
|
+
installDependency: vi.fn(),
|
|
11
|
+
}));
|
|
12
|
+
// Import installDependency after mocking
|
|
13
|
+
import { installDependency } from "../install.js";
|
|
14
|
+
vi.mock("../../utils.js", () => ({
|
|
15
|
+
packageManagers: {
|
|
16
|
+
pnpm: {
|
|
17
|
+
buildAffected: "pnpm run build:affected",
|
|
18
|
+
updateCommand: "pnpm update {{dependency}}",
|
|
19
|
+
installCommand: "pnpm install {{dependency}}",
|
|
20
|
+
workspaceOption: "--workspace-root",
|
|
21
|
+
lockfile: "pnpm-lock.yaml",
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
getPackageManagerFromLockfile: vi.fn(),
|
|
25
|
+
getProjectInfo: vi.fn(),
|
|
26
|
+
}));
|
|
27
|
+
describe("useCommand", () => {
|
|
28
|
+
let program;
|
|
29
|
+
beforeEach(() => {
|
|
30
|
+
vi.clearAllMocks();
|
|
31
|
+
vi.restoreAllMocks();
|
|
32
|
+
program = new Command();
|
|
33
|
+
useCommand(program);
|
|
34
|
+
// Mock utils functions
|
|
35
|
+
vi.mocked(getPackageManagerFromLockfile).mockReturnValue("pnpm");
|
|
36
|
+
vi.mocked(getProjectInfo).mockReturnValue({
|
|
37
|
+
path: "/test/project",
|
|
38
|
+
});
|
|
39
|
+
// Mock fs.existsSync to return true for test paths
|
|
40
|
+
vi.spyOn(fs, "existsSync").mockImplementation((p) => {
|
|
41
|
+
const validPaths = [
|
|
42
|
+
"/test/project",
|
|
43
|
+
"/test/project/package.json",
|
|
44
|
+
path.join("/test/project", "package.json"),
|
|
45
|
+
path.join("/test/project", "pnpm-lock.yaml"),
|
|
46
|
+
];
|
|
47
|
+
return validPaths.includes(p);
|
|
48
|
+
});
|
|
49
|
+
// Mock installDependency
|
|
50
|
+
vi.mocked(installDependency).mockImplementation(() => { });
|
|
51
|
+
});
|
|
52
|
+
it("should register the use command with correct options", () => {
|
|
53
|
+
const cmd = program.commands.find((c) => c.name() === "use");
|
|
54
|
+
expect(cmd).toBeDefined();
|
|
55
|
+
expect(cmd?.description()).toContain("change your environment");
|
|
56
|
+
const options = cmd?.options.map((opt) => opt.attributeName());
|
|
57
|
+
expect(options).toContain("dev");
|
|
58
|
+
expect(options).toContain("prod");
|
|
59
|
+
expect(options).toContain("latest");
|
|
60
|
+
expect(options).toContain("local");
|
|
61
|
+
expect(options).toContain("packageManager");
|
|
62
|
+
expect(options).toContain("debug");
|
|
63
|
+
});
|
|
64
|
+
it("should execute use command with dev environment", async () => {
|
|
65
|
+
const cmd = program.commands.find((c) => c.name() === "use");
|
|
66
|
+
await cmd?.parseAsync(["node", "test", "--dev"]);
|
|
67
|
+
expect(installDependency).toHaveBeenCalledWith("pnpm", [
|
|
68
|
+
"@powerhousedao/common@dev",
|
|
69
|
+
"@powerhousedao/design-system@dev",
|
|
70
|
+
"@powerhousedao/reactor-browser@dev",
|
|
71
|
+
"@powerhousedao/builder-tools@dev",
|
|
72
|
+
"@powerhousedao/codegen@dev",
|
|
73
|
+
"@powerhousedao/reactor-api@dev",
|
|
74
|
+
"@powerhousedao/reactor-local@dev",
|
|
75
|
+
"@powerhousedao/scalars@dev",
|
|
76
|
+
"@powerhousedao/ph-cli@dev",
|
|
77
|
+
], "/test/project");
|
|
78
|
+
});
|
|
79
|
+
it("should execute use command with prod environment", async () => {
|
|
80
|
+
const cmd = program.commands.find((c) => c.name() === "use");
|
|
81
|
+
await cmd?.parseAsync(["node", "test", "--prod"]);
|
|
82
|
+
expect(installDependency).toHaveBeenCalledWith("pnpm", [
|
|
83
|
+
"@powerhousedao/common@latest",
|
|
84
|
+
"@powerhousedao/design-system@latest",
|
|
85
|
+
"@powerhousedao/reactor-browser@latest",
|
|
86
|
+
"@powerhousedao/builder-tools@latest",
|
|
87
|
+
"@powerhousedao/codegen@latest",
|
|
88
|
+
"@powerhousedao/reactor-api@latest",
|
|
89
|
+
"@powerhousedao/reactor-local@latest",
|
|
90
|
+
"@powerhousedao/scalars@latest",
|
|
91
|
+
"@powerhousedao/ph-cli@latest",
|
|
92
|
+
], "/test/project");
|
|
93
|
+
});
|
|
94
|
+
it("should execute use command with local environment", async () => {
|
|
95
|
+
const cmd = program.commands.find((c) => c.name() === "use");
|
|
96
|
+
await cmd?.parseAsync(["node", "test", "--local", "/path/to/local"]);
|
|
97
|
+
expect(installDependency).toHaveBeenCalledWith("pnpm", [
|
|
98
|
+
"/path/to/local/packages/common",
|
|
99
|
+
"/path/to/local/packages/design-system",
|
|
100
|
+
"/path/to/local/packages/reactor-browser",
|
|
101
|
+
"/path/to/local/packages/builder-tools",
|
|
102
|
+
"/path/to/local/packages/codegen",
|
|
103
|
+
"/path/to/local/packages/reactor-api",
|
|
104
|
+
"/path/to/local/packages/reactor-local",
|
|
105
|
+
"/path/to/local/packages/scalars",
|
|
106
|
+
"/path/to/local/clis/ph-cli",
|
|
107
|
+
], "/test/project");
|
|
108
|
+
});
|
|
109
|
+
it("should handle debug flag", async () => {
|
|
110
|
+
const consoleSpy = vi.spyOn(console, "log");
|
|
111
|
+
const cmd = program.commands.find((c) => c.name() === "use");
|
|
112
|
+
await cmd?.parseAsync(["node", "test", "--dev", "--debug"]);
|
|
113
|
+
expect(consoleSpy).toHaveBeenCalledWith(">>> options", expect.any(Object));
|
|
114
|
+
});
|
|
115
|
+
it("should throw error when no environment is specified", async () => {
|
|
116
|
+
const cmd = program.commands.find((c) => c.name() === "use");
|
|
117
|
+
await expect(cmd?.parseAsync(["node", "test"])).rejects.toThrow("❌ Please specify an environment");
|
|
118
|
+
});
|
|
119
|
+
it("should use specified package manager", async () => {
|
|
120
|
+
const cmd = program.commands.find((c) => c.name() === "use");
|
|
121
|
+
await cmd?.parseAsync([
|
|
122
|
+
"node",
|
|
123
|
+
"test",
|
|
124
|
+
"--dev",
|
|
125
|
+
"--package-manager",
|
|
126
|
+
"npm",
|
|
127
|
+
]);
|
|
128
|
+
expect(installDependency).toHaveBeenCalledWith("npm", expect.any(Array), "/test/project");
|
|
129
|
+
});
|
|
130
|
+
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connect.d.ts","sourceRoot":"","sources":["../../../src/commands/connect.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,OAAO,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAC7D,OAAO,EAAE,KAAK,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAQrD,eAAO,MAAM,OAAO,EAAE,iBAAiB,CACrC;IAAC,cAAc;CAAC,EAChB,OAAO,CAAC,IAAI,CAAC,CAGd,CAAC;AAEF,wBAAgB,cAAc,CAAC,OAAO,EAAE,OAAO,
|
|
1
|
+
{"version":3,"file":"connect.d.ts","sourceRoot":"","sources":["../../../src/commands/connect.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,OAAO,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAC7D,OAAO,EAAE,KAAK,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAQrD,eAAO,MAAM,OAAO,EAAE,iBAAiB,CACrC;IAAC,cAAc;CAAC,EAChB,OAAO,CAAC,IAAI,CAAC,CAGd,CAAC;AAEF,wBAAgB,cAAc,CAAC,OAAO,EAAE,OAAO,QAe9C"}
|
|
@@ -15,8 +15,6 @@ export function connectCommand(program) {
|
|
|
15
15
|
.option("--https", "Enable HTTPS")
|
|
16
16
|
.option("--open", "Open the browser")
|
|
17
17
|
.option("--config-file <configFile>", "Path to the powerhouse.config.js file")
|
|
18
|
-
.option("-le, --local-editors <localEditors>", "Link local document editors path")
|
|
19
|
-
.option("-ld, --local-documents <localDocuments>", "Link local documents path")
|
|
20
18
|
.action(async (...args) => {
|
|
21
19
|
await connect(...args);
|
|
22
20
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/commands/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,OAAO,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/commands/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,OAAO,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAc9C,eAAO,MAAM,QAAQ,2BAcpB,CAAC;AAEF,MAAM,CAAC,OAAO,UAAU,gBAAgB,CAAC,OAAO,EAAE,OAAO,QAExD"}
|
|
@@ -8,6 +8,8 @@ import { listCommand } from "./list.js";
|
|
|
8
8
|
import { serviceCommand } from "./service.js";
|
|
9
9
|
import { reactorCommand } from "./switchboard.js";
|
|
10
10
|
import { uninstallCommand } from "./uninstall.js";
|
|
11
|
+
import { updateCommand } from "./update.js";
|
|
12
|
+
import { useCommand } from "./use.js";
|
|
11
13
|
import { versionCommand } from "./version.js";
|
|
12
14
|
export const commands = [
|
|
13
15
|
// devCommand,
|
|
@@ -21,6 +23,8 @@ export const commands = [
|
|
|
21
23
|
listCommand,
|
|
22
24
|
inspectCommand,
|
|
23
25
|
versionCommand,
|
|
26
|
+
useCommand,
|
|
27
|
+
updateCommand,
|
|
24
28
|
];
|
|
25
29
|
export default function registerCommands(program) {
|
|
26
30
|
commands.forEach((command) => command(program));
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
import { type Command } from "commander";
|
|
2
2
|
import { type InspectOptions } from "../services/inspect.js";
|
|
3
3
|
import { type CommandActionType } from "../types.js";
|
|
4
|
-
export declare const inspect: CommandActionType<[
|
|
5
|
-
string,
|
|
6
|
-
InspectOptions
|
|
7
|
-
]>;
|
|
4
|
+
export declare const inspect: CommandActionType<[string, InspectOptions]>;
|
|
8
5
|
export declare function inspectCommand(program: Command): void;
|
|
9
6
|
//# sourceMappingURL=inspect.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"inspect.d.ts","sourceRoot":"","sources":["../../../src/commands/inspect.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,OAAO,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAC7D,OAAO,EAAE,KAAK,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAQrD,eAAO,MAAM,OAAO,EAAE,iBAAiB,
|
|
1
|
+
{"version":3,"file":"inspect.d.ts","sourceRoot":"","sources":["../../../src/commands/inspect.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,OAAO,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAC7D,OAAO,EAAE,KAAK,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAQrD,eAAO,MAAM,OAAO,EAAE,iBAAiB,CAAC,CAAC,MAAM,EAAE,cAAc,CAAC,CAK/D,CAAC;AAEF,wBAAgB,cAAc,CAAC,OAAO,EAAE,OAAO,QAQ9C"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type Command } from "commander";
|
|
2
|
+
import { type CommandActionType } from "../types.js";
|
|
3
|
+
export declare const update: CommandActionType<[
|
|
4
|
+
{
|
|
5
|
+
force?: string;
|
|
6
|
+
debug?: boolean;
|
|
7
|
+
packageManager?: string;
|
|
8
|
+
}
|
|
9
|
+
]>;
|
|
10
|
+
export declare function updateCommand(program: Command): void;
|
|
11
|
+
//# sourceMappingURL=update.d.ts.map
|
|
@@ -0,0 +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;AAqErD,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,CAqDF,CAAC;AAEF,wBAAgB,aAAa,CAAC,OAAO,EAAE,OAAO,QA4B7C"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { execSync } from "node:child_process";
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { findContainerDirectory, getPackageManagerFromLockfile, getProjectInfo, packageManagers, } from "../utils.js";
|
|
5
|
+
import { ENV_MAP, PH_PROJECT_DEPENDENCIES, updatePackageJson, } from "./use.js";
|
|
6
|
+
const FILE_PROTOCOL = "file:";
|
|
7
|
+
const LINK_PROTOCOL = "link:";
|
|
8
|
+
const MONOREPO_FILE = "pnpm-workspace.yaml";
|
|
9
|
+
const buildLocalDependencies = (localDependencyPath, pkgManagerName) => {
|
|
10
|
+
const monorepoPath = findContainerDirectory(localDependencyPath, MONOREPO_FILE);
|
|
11
|
+
if (!monorepoPath) {
|
|
12
|
+
throw new Error("Monorepo root directory not found");
|
|
13
|
+
}
|
|
14
|
+
const pkgManager = packageManagers[pkgManagerName];
|
|
15
|
+
console.log("⚙️ Building local dependencies...");
|
|
16
|
+
execSync(pkgManager.buildAffected, {
|
|
17
|
+
stdio: "inherit",
|
|
18
|
+
cwd: monorepoPath,
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
const getLocalDependencyPath = (projectPath) => {
|
|
22
|
+
// read package json from projectInfo.path
|
|
23
|
+
const packageJson = JSON.parse(fs.readFileSync(path.join(projectPath, "package.json"), "utf-8"));
|
|
24
|
+
// filter dependencies
|
|
25
|
+
const filteredDependencies = Object.entries({
|
|
26
|
+
...packageJson.dependencies,
|
|
27
|
+
...packageJson.devDependencies,
|
|
28
|
+
}).filter(([name]) => PH_PROJECT_DEPENDENCIES.includes(name));
|
|
29
|
+
const [_, localDependencyPath] = filteredDependencies.find(([_, version]) => version.startsWith(FILE_PROTOCOL) || version.startsWith(LINK_PROTOCOL)) || [null, null];
|
|
30
|
+
if (!localDependencyPath)
|
|
31
|
+
return null;
|
|
32
|
+
return localDependencyPath
|
|
33
|
+
.replace(FILE_PROTOCOL, "")
|
|
34
|
+
.replace(LINK_PROTOCOL, "");
|
|
35
|
+
};
|
|
36
|
+
export const update = (options) => {
|
|
37
|
+
const { force, packageManager, debug } = options;
|
|
38
|
+
if (debug) {
|
|
39
|
+
console.log(">>> options", options);
|
|
40
|
+
}
|
|
41
|
+
const projectInfo = getProjectInfo();
|
|
42
|
+
const pkgManagerName = (packageManager ||
|
|
43
|
+
getPackageManagerFromLockfile(projectInfo.path));
|
|
44
|
+
const localDependencyPath = getLocalDependencyPath(projectInfo.path);
|
|
45
|
+
if (debug) {
|
|
46
|
+
console.log(">>> projectInfo", projectInfo);
|
|
47
|
+
console.log(">>> pkgManagerName", pkgManagerName);
|
|
48
|
+
console.log(">>> localDependencyPath", localDependencyPath);
|
|
49
|
+
}
|
|
50
|
+
if (localDependencyPath) {
|
|
51
|
+
buildLocalDependencies(localDependencyPath, pkgManagerName);
|
|
52
|
+
}
|
|
53
|
+
if (force) {
|
|
54
|
+
const supportedEnvs = Object.keys(ENV_MAP);
|
|
55
|
+
if (!supportedEnvs.includes(force)) {
|
|
56
|
+
throw new Error(`Invalid environment: ${force}, supported envs: ${supportedEnvs.join(", ")}`);
|
|
57
|
+
}
|
|
58
|
+
const env = force;
|
|
59
|
+
updatePackageJson(env, undefined, pkgManagerName, debug);
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
const pkgManager = packageManagers[pkgManagerName];
|
|
63
|
+
const deps = PH_PROJECT_DEPENDENCIES.join(" ");
|
|
64
|
+
const updateCommand = pkgManager.updateCommand.replace("{{dependency}}", deps);
|
|
65
|
+
console.log(updateCommand);
|
|
66
|
+
const commandOptions = { cwd: projectInfo.path };
|
|
67
|
+
execSync(updateCommand, {
|
|
68
|
+
stdio: "inherit",
|
|
69
|
+
...commandOptions,
|
|
70
|
+
});
|
|
71
|
+
};
|
|
72
|
+
export function updateCommand(program) {
|
|
73
|
+
program
|
|
74
|
+
.command("update")
|
|
75
|
+
.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.")
|
|
76
|
+
.option("--force <env>", "Force update to latest available version for the environment specified (dev, prod, latest)")
|
|
77
|
+
.option("--package-manager <packageManager>", "force package manager to use")
|
|
78
|
+
.option("--debug", "Show additional logs")
|
|
79
|
+
.addHelpText("after", `
|
|
80
|
+
Examples:
|
|
81
|
+
$ ph-cli update # Update dependencies based on package.json ranges
|
|
82
|
+
$ ph-cli update --force dev # Force update to latest dev version available
|
|
83
|
+
$ ph-cli update --force prod # Force update to latest stable version available (same as latest)
|
|
84
|
+
$ ph-cli update --force latest # Force update to latest stable version available (same as prod)
|
|
85
|
+
$ ph-cli update --package-manager pnpm # Specify package manager to use
|
|
86
|
+
$ ph-cli update --debug # Show debug information during update
|
|
87
|
+
`)
|
|
88
|
+
.action(update);
|
|
89
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { type Command } from "commander";
|
|
2
|
+
import { type CommandActionType } from "../types.js";
|
|
3
|
+
import { type PackageManager } from "../utils.js";
|
|
4
|
+
export declare const ORG = "@powerhousedao";
|
|
5
|
+
export declare const CLIS: string[];
|
|
6
|
+
export declare const PACKAGES: string[];
|
|
7
|
+
export declare const PH_PROJECT_DEPENDENCIES: string[];
|
|
8
|
+
export declare const PH_PROJECT_LOCAL_DEPENDENCIES: string[];
|
|
9
|
+
export declare const ENV_MAP: {
|
|
10
|
+
dev: string;
|
|
11
|
+
prod: string;
|
|
12
|
+
latest: string;
|
|
13
|
+
};
|
|
14
|
+
export type Environment = keyof typeof ENV_MAP;
|
|
15
|
+
export declare const updatePackageJson: (env: Environment, localPath?: string, packageManager?: PackageManager, debug?: boolean) => void;
|
|
16
|
+
export declare const use: CommandActionType<[
|
|
17
|
+
{
|
|
18
|
+
dev?: boolean;
|
|
19
|
+
prod?: boolean;
|
|
20
|
+
local?: string;
|
|
21
|
+
debug?: boolean;
|
|
22
|
+
latest?: boolean;
|
|
23
|
+
packageManager?: string;
|
|
24
|
+
}
|
|
25
|
+
]>;
|
|
26
|
+
export declare function useCommand(program: Command): void;
|
|
27
|
+
//# sourceMappingURL=use.d.ts.map
|
|
@@ -0,0 +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;AAEzC,OAAO,EAAE,KAAK,iBAAiB,EAAE,MAAM,aAAa,CAAC;AACrD,OAAO,EAGL,KAAK,cAAc,EACpB,MAAM,aAAa,CAAC;AAGrB,eAAO,MAAM,GAAG,mBAAmB,CAAC;AACpC,eAAO,MAAM,IAAI,UAAa,CAAC;AAC/B,eAAO,MAAM,QAAQ,UASpB,CAAC;AAEF,eAAO,MAAM,uBAAuB,UAGnC,CAAC;AAEF,eAAO,MAAM,6BAA6B,UAGzC,CAAC;AAEF,eAAO,MAAM,OAAO;;;;CAInB,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,SAuChB,CAAC;AAEF,eAAO,MAAM,GAAG,EAAE,iBAAiB,CACjC;IACE;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,cAAc,CAAC,EAAE,MAAM,CAAC;KACzB;CACF,CAwBF,CAAC;AAEF,wBAAgB,UAAU,CAAC,OAAO,EAAE,OAAO,QAmB1C"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { getPackageManagerFromLockfile, getProjectInfo, } from "../utils.js";
|
|
3
|
+
import { installDependency } from "./install.js";
|
|
4
|
+
export const ORG = "@powerhousedao";
|
|
5
|
+
export const CLIS = ["ph-cli"];
|
|
6
|
+
export const PACKAGES = [
|
|
7
|
+
"common",
|
|
8
|
+
"design-system",
|
|
9
|
+
"reactor-browser",
|
|
10
|
+
"builder-tools",
|
|
11
|
+
"codegen",
|
|
12
|
+
"reactor-api",
|
|
13
|
+
"reactor-local",
|
|
14
|
+
"scalars",
|
|
15
|
+
];
|
|
16
|
+
export const PH_PROJECT_DEPENDENCIES = [
|
|
17
|
+
...PACKAGES.map((dependency) => `${ORG}/${dependency}`),
|
|
18
|
+
...CLIS.map((dependency) => `${ORG}/${dependency}`),
|
|
19
|
+
];
|
|
20
|
+
export const PH_PROJECT_LOCAL_DEPENDENCIES = [
|
|
21
|
+
...PACKAGES.map((dependency) => path.join("packages", dependency)),
|
|
22
|
+
...CLIS.map((dependency) => path.join("clis", dependency)),
|
|
23
|
+
];
|
|
24
|
+
export const ENV_MAP = {
|
|
25
|
+
dev: "dev",
|
|
26
|
+
prod: "latest",
|
|
27
|
+
latest: "latest",
|
|
28
|
+
};
|
|
29
|
+
export const updatePackageJson = (env, localPath, packageManager, debug) => {
|
|
30
|
+
const dependencies = [];
|
|
31
|
+
const projectInfo = getProjectInfo();
|
|
32
|
+
const pkgManager = packageManager || getPackageManagerFromLockfile(projectInfo.path);
|
|
33
|
+
if (debug) {
|
|
34
|
+
console.log(">>> projectInfo", projectInfo);
|
|
35
|
+
console.log(">>> pkgManager", pkgManager);
|
|
36
|
+
}
|
|
37
|
+
if (localPath) {
|
|
38
|
+
const localPathDependencies = PH_PROJECT_LOCAL_DEPENDENCIES.map((dependency) => path.join(localPath, dependency));
|
|
39
|
+
dependencies.push(...localPathDependencies);
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
dependencies.push(...PH_PROJECT_DEPENDENCIES.map((dependency) => `${dependency}@${ENV_MAP[env]}`));
|
|
43
|
+
}
|
|
44
|
+
if (debug) {
|
|
45
|
+
console.log(">>> dependencies", dependencies);
|
|
46
|
+
}
|
|
47
|
+
try {
|
|
48
|
+
console.log("⚙️ Updating dependencies...");
|
|
49
|
+
installDependency(pkgManager, dependencies, projectInfo.path);
|
|
50
|
+
console.log("✅ Dependencies updated successfully");
|
|
51
|
+
}
|
|
52
|
+
catch (error) {
|
|
53
|
+
console.error("❌ Failed to update dependencies");
|
|
54
|
+
throw error;
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
export const use = (options) => {
|
|
58
|
+
const { dev, prod, latest, local, packageManager, debug } = options;
|
|
59
|
+
const develop = dev ? "dev" : null;
|
|
60
|
+
const production = prod ? "prod" : null;
|
|
61
|
+
const latestEnv = latest ? "latest" : null;
|
|
62
|
+
const env = develop || production || latestEnv;
|
|
63
|
+
if (debug) {
|
|
64
|
+
console.log(">>> options", options);
|
|
65
|
+
}
|
|
66
|
+
if (!env && !local) {
|
|
67
|
+
throw new Error("❌ Please specify an environment");
|
|
68
|
+
}
|
|
69
|
+
updatePackageJson(env || "dev", local, packageManager, debug);
|
|
70
|
+
};
|
|
71
|
+
export function useCommand(program) {
|
|
72
|
+
program
|
|
73
|
+
.command("use")
|
|
74
|
+
.description("Allows you to change your environment (latest, development, production, local)")
|
|
75
|
+
.option("-d, --dev", "Use development environment")
|
|
76
|
+
.option("-p, --prod", "Use production environment")
|
|
77
|
+
.option("--latest", "Use latest environment")
|
|
78
|
+
.option("-l, --local <localPath>", "Use local environment (you have to specify the path to the local environment)")
|
|
79
|
+
.option("--package-manager <packageManager>", "force package manager to use")
|
|
80
|
+
.option("--debug", "Show additional logs")
|
|
81
|
+
.action(use);
|
|
82
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connect.d.ts","sourceRoot":"","sources":["../../../src/services/connect.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,oBAAoB,EAE1B,MAAM,6CAA6C,CAAC;AAKrD,MAAM,MAAM,cAAc,GAAG,oBAAoB,CAAC;AAElD,wBAAsB,YAAY,CAAC,cAAc,EAAE,cAAc,
|
|
1
|
+
{"version":3,"file":"connect.d.ts","sourceRoot":"","sources":["../../../src/services/connect.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,oBAAoB,EAE1B,MAAM,6CAA6C,CAAC;AAKrD,MAAM,MAAM,cAAc,GAAG,oBAAoB,CAAC;AAElD,wBAAsB,YAAY,CAAC,cAAc,EAAE,cAAc,6BAUhE"}
|
|
@@ -3,13 +3,11 @@ import { getConfig } from "@powerhousedao/config/powerhouse";
|
|
|
3
3
|
import packageJson from "../../package.json" with { type: "json" };
|
|
4
4
|
const version = packageJson.version;
|
|
5
5
|
export async function startConnect(connectOptions) {
|
|
6
|
-
const {
|
|
6
|
+
const { packages, studio, logLevel } = getConfig(connectOptions.configFile);
|
|
7
7
|
return await startConnectStudio({
|
|
8
8
|
port: studio?.port?.toString() || undefined,
|
|
9
9
|
packages,
|
|
10
10
|
phCliVersion: typeof version === "string" ? version : undefined,
|
|
11
|
-
localDocuments: documentModelsDir || undefined,
|
|
12
|
-
localEditors: editorsDir || undefined,
|
|
13
11
|
open: studio?.openBrowser,
|
|
14
12
|
logLevel: logLevel,
|
|
15
13
|
...connectOptions,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dev.d.ts","sourceRoot":"","sources":["../../../src/services/dev.ts"],"names":[],"mappings":"AAcA,MAAM,MAAM,UAAU,GAAG;IACvB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB,CAAC;
|
|
1
|
+
{"version":3,"file":"dev.d.ts","sourceRoot":"","sources":["../../../src/services/dev.ts"],"names":[],"mappings":"AAcA,MAAM,MAAM,UAAU,GAAG;IACvB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB,CAAC;AA0EF,wBAAsB,QAAQ,CAAC,EAC7B,QAAQ,EACR,KAAK,EACL,eAAgD,EAChD,UAAU,GACX,EAAE,UAAU,iBAcZ"}
|
package/dist/src/services/dev.js
CHANGED
|
@@ -40,8 +40,6 @@ async function spawnConnect(options, localReactorUrl) {
|
|
|
40
40
|
env: {
|
|
41
41
|
...process.env,
|
|
42
42
|
// TODO add studio variables?
|
|
43
|
-
LOCAL_DOCUMENT_MODELS: options?.localDocuments,
|
|
44
|
-
LOCAL_DOCUMENT_EDITORS: options?.localEditors,
|
|
45
43
|
PH_CONNECT_DEFAULT_DRIVES_URL: localReactorUrl,
|
|
46
44
|
},
|
|
47
45
|
});
|