@shopify/oxygen-cli 1.6.0 → 1.7.0
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/commands/oxygen/deploy.js +0 -1
- package/dist/deploy/build-project.js +9 -13
- package/dist/deploy/build-project.test.js +20 -13
- package/dist/deploy/index.js +6 -1
- package/dist/deploy/types.d.ts +2 -5
- package/dist/utils/test-helper.js +0 -1
- package/oclif.manifest.json +1 -1
- package/package.json +3 -3
@@ -107,7 +107,6 @@ class Deploy extends Command {
|
|
107
107
|
const config = {
|
108
108
|
assetsDir: normalizePath(flags.assetsFolder),
|
109
109
|
buildCommand: flags.buildCommand,
|
110
|
-
buildOutput: true,
|
111
110
|
deploymentToken: parseToken(flags.token),
|
112
111
|
environmentTag: flags.environmentTag,
|
113
112
|
deploymentUrl,
|
@@ -2,12 +2,19 @@ import { spawn } from 'child_process';
|
|
2
2
|
|
3
3
|
async function buildProject(options) {
|
4
4
|
const { config, assetPath, hooks } = options;
|
5
|
-
hooks?.
|
5
|
+
if (hooks?.buildFunction) {
|
6
|
+
try {
|
7
|
+
await hooks.buildFunction(assetPath);
|
8
|
+
} catch (error) {
|
9
|
+
throw new Error(`Build function failed with error: ${error}`);
|
10
|
+
}
|
11
|
+
return;
|
12
|
+
}
|
6
13
|
const assetPathEnvironment = assetPath ? { HYDROGEN_ASSET_BASE_URL: assetPath } : {};
|
7
14
|
try {
|
8
15
|
await new Promise((resolve, reject) => {
|
9
16
|
const buildCommand = spawn(config.buildCommand, [], {
|
10
|
-
stdio:
|
17
|
+
stdio: ["inherit", process.stderr, "inherit"],
|
11
18
|
env: {
|
12
19
|
// eslint-disable-next-line no-process-env
|
13
20
|
...process.env,
|
@@ -16,22 +23,11 @@ async function buildProject(options) {
|
|
16
23
|
cwd: config.rootPath,
|
17
24
|
shell: true
|
18
25
|
});
|
19
|
-
let stderrOutput = "";
|
20
|
-
if (buildCommand.stderr) {
|
21
|
-
buildCommand.stderr.on("data", (data) => {
|
22
|
-
stderrOutput += data;
|
23
|
-
});
|
24
|
-
}
|
25
|
-
if (config.buildOutput && buildCommand.stdout) {
|
26
|
-
buildCommand.stdout.pipe(process.stderr);
|
27
|
-
}
|
28
26
|
buildCommand.on("close", (code) => {
|
29
27
|
if (code !== 0) {
|
30
|
-
hooks?.onBuildError?.(new Error(stderrOutput));
|
31
28
|
reject(code);
|
32
29
|
return;
|
33
30
|
}
|
34
|
-
hooks?.onBuildComplete?.();
|
35
31
|
resolve(code);
|
36
32
|
});
|
37
33
|
});
|
@@ -30,32 +30,39 @@ test("BuildProject builds the project successfully", async () => {
|
|
30
30
|
buildCommand: "npm run build"
|
31
31
|
};
|
32
32
|
const assetPath = "https://example.com/assets";
|
33
|
-
|
34
|
-
onBuildStart: vi.fn(),
|
35
|
-
onBuildComplete: vi.fn()
|
36
|
-
};
|
37
|
-
await buildProject({ config, assetPath, hooks });
|
33
|
+
await buildProject({ config, assetPath });
|
38
34
|
expect(spawn).toBeCalledWith("npm run build", [], {
|
39
35
|
cwd: "rootFolder",
|
40
36
|
shell: true,
|
41
|
-
stdio: ["inherit",
|
37
|
+
stdio: ["inherit", process.stderr, "inherit"],
|
42
38
|
env: {
|
43
39
|
// eslint-disable-next-line no-process-env
|
44
40
|
...process.env,
|
45
41
|
HYDROGEN_ASSET_BASE_URL: "https://example.com/assets"
|
46
42
|
}
|
47
43
|
});
|
48
|
-
expect(hooks.onBuildStart).toBeCalled();
|
49
|
-
expect(hooks.onBuildComplete).toBeCalled();
|
50
44
|
});
|
51
45
|
test("should throw error on build command failure", async () => {
|
52
46
|
returnCode = 1;
|
53
|
-
const hooks = {
|
54
|
-
onBuildError: vi.fn()
|
55
|
-
};
|
56
47
|
const assetPath = "https://example.com/assets";
|
57
48
|
await expect(
|
58
|
-
() => buildProject({ config: testConfig, assetPath
|
49
|
+
() => buildProject({ config: testConfig, assetPath })
|
59
50
|
).rejects.toThrow("Build failed with error code: 1");
|
60
|
-
|
51
|
+
});
|
52
|
+
test("should call buildFunction hook if provided", async () => {
|
53
|
+
const buildFunction = vi.fn().mockResolvedValue(void 0);
|
54
|
+
const hooks = { buildFunction };
|
55
|
+
const assetPath = "https://example.com/assets";
|
56
|
+
await buildProject({ config: testConfig, assetPath, hooks });
|
57
|
+
expect(buildFunction).toBeCalledWith(assetPath);
|
58
|
+
});
|
59
|
+
test("should throw error if buildFunction hook fails", async () => {
|
60
|
+
const buildFunction = vi.fn().mockRejectedValue(new Error("Oops! I tripped over a cable."));
|
61
|
+
const hooks = { buildFunction };
|
62
|
+
const assetPath = "https://example.com/assets";
|
63
|
+
await expect(
|
64
|
+
() => buildProject({ config: testConfig, assetPath, hooks })
|
65
|
+
).rejects.toThrow(
|
66
|
+
"Build function failed with error: Error: Oops! I tripped over a cable."
|
67
|
+
);
|
61
68
|
});
|
package/dist/deploy/index.js
CHANGED
@@ -49,7 +49,12 @@ async function createDeploy(options) {
|
|
49
49
|
input: deploymentInitiateInput,
|
50
50
|
logger
|
51
51
|
});
|
52
|
-
await uploadFiles({
|
52
|
+
await uploadFiles({
|
53
|
+
config,
|
54
|
+
targets: deployment.deploymentTargets,
|
55
|
+
hooks,
|
56
|
+
logger
|
57
|
+
});
|
53
58
|
const deploymentCompleteOp = await deploymentComplete(
|
54
59
|
config,
|
55
60
|
deployment.deployment.id
|
package/dist/deploy/types.d.ts
CHANGED
@@ -6,9 +6,7 @@ interface ClientError extends Error {
|
|
6
6
|
statusCode: number;
|
7
7
|
}
|
8
8
|
interface DeploymentHooks {
|
9
|
-
|
10
|
-
onBuildComplete?: () => void;
|
11
|
-
onBuildError?: (error: Error) => void;
|
9
|
+
buildFunction?: (urlPath?: string) => Promise<void>;
|
12
10
|
onHealthCheckStart?: () => void;
|
13
11
|
onHealthCheckComplete?: () => void;
|
14
12
|
onHealthCheckError?: (error: Error) => void;
|
@@ -17,8 +15,7 @@ interface DeploymentHooks {
|
|
17
15
|
}
|
18
16
|
interface DeploymentConfig {
|
19
17
|
assetsDir?: string;
|
20
|
-
buildCommand
|
21
|
-
buildOutput: boolean;
|
18
|
+
buildCommand?: string;
|
22
19
|
deploymentToken: DeploymentToken;
|
23
20
|
deploymentUrl: string;
|
24
21
|
environmentTag?: string;
|
@@ -13,7 +13,6 @@ function createTestConfig(rootFolder) {
|
|
13
13
|
return {
|
14
14
|
assetsDir: "/assets/",
|
15
15
|
buildCommand: String(deployDefaults.buildCommandDefault),
|
16
|
-
buildOutput: true,
|
17
16
|
deploymentToken: testToken,
|
18
17
|
environmentTag: "environment",
|
19
18
|
deploymentUrl: "https://localhost:3000",
|
package/oclif.manifest.json
CHANGED
package/package.json
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
"@shopify:registry": "https://registry.npmjs.org"
|
6
6
|
},
|
7
7
|
"license": "MIT",
|
8
|
-
"version": "1.
|
8
|
+
"version": "1.7.0",
|
9
9
|
"type": "module",
|
10
10
|
"scripts": {
|
11
11
|
"build": "tsup --clean --config ./tsup.config.ts && oclif manifest",
|
@@ -40,14 +40,14 @@
|
|
40
40
|
"@shopify/eslint-plugin": "^42.1.0",
|
41
41
|
"@shopify/prettier-config": "^1.1.2",
|
42
42
|
"@types/async": "^3.2.18",
|
43
|
-
"@types/node": "^20.4.
|
43
|
+
"@types/node": "^20.4.4",
|
44
44
|
"@types/prettier": "^2.7.3",
|
45
45
|
"eslint": "^8.45.0",
|
46
46
|
"node-fetch": "^3.3.1",
|
47
47
|
"oclif": "^3",
|
48
48
|
"tsup": "^7.1.0",
|
49
49
|
"typescript": "^5.1.3",
|
50
|
-
"vite": "^4.4.
|
50
|
+
"vite": "^4.4.6",
|
51
51
|
"vitest": "^0.33.0"
|
52
52
|
},
|
53
53
|
"prettier": "@shopify/prettier-config",
|