@zuplo/cli 1.118.0 → 1.120.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/cmds/link.js +22 -3
- package/dist/common/api/lib.js +2 -2
- package/dist/common/validators/file-system-validator.js +4 -4
- package/dist/common/validators/login-state-validator.js +11 -8
- package/dist/compile/handler.js +15 -10
- package/dist/dev/handler.js +16 -9
- package/dist/link/handler.js +123 -60
- package/dist/link/populate.js +25 -22
- package/package.json +3 -3
package/dist/cmds/link.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
|
|
2
|
-
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="
|
|
2
|
+
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="6247c8c4-d880-5d58-a70d-da8c9cd6a68a")}catch(e){}}();
|
|
3
3
|
import { captureEvent } from "../common/analytics/lib.js";
|
|
4
|
+
import { configure } from "../common/middleware/user-configuration.js";
|
|
4
5
|
import { identify } from "../common/middleware/user-identification.js";
|
|
5
6
|
import setBlocking from "../common/output.js";
|
|
6
7
|
import { validLinkDirectoryValidator } from "../common/validators/file-system-validator.js";
|
|
@@ -18,7 +19,25 @@ export default {
|
|
|
18
19
|
normalize: true,
|
|
19
20
|
hidden: true,
|
|
20
21
|
})
|
|
21
|
-
.
|
|
22
|
+
.option("api-key", {
|
|
23
|
+
type: "string",
|
|
24
|
+
describe: "The API Key from Zuplo",
|
|
25
|
+
envVar: "API_KEY",
|
|
26
|
+
})
|
|
27
|
+
.option("account", {
|
|
28
|
+
type: "string",
|
|
29
|
+
describe: "The account name",
|
|
30
|
+
})
|
|
31
|
+
.option("project", {
|
|
32
|
+
type: "string",
|
|
33
|
+
describe: "The project name",
|
|
34
|
+
})
|
|
35
|
+
.option("environment", {
|
|
36
|
+
type: "string",
|
|
37
|
+
describe: "The environment name",
|
|
38
|
+
})
|
|
39
|
+
.demandOption(["api-key"])
|
|
40
|
+
.middleware([setBlocking, configure, identify])
|
|
22
41
|
.check(async (argv) => {
|
|
23
42
|
return await new YargsChecker(validLinkDirectoryValidator).check(argv);
|
|
24
43
|
});
|
|
@@ -29,4 +48,4 @@ export default {
|
|
|
29
48
|
},
|
|
30
49
|
};
|
|
31
50
|
//# sourceMappingURL=link.js.map
|
|
32
|
-
//# debugId=
|
|
51
|
+
//# debugId=6247c8c4-d880-5d58-a70d-da8c9cd6a68a
|
package/dist/common/api/lib.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="
|
|
2
|
+
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="be0ac435-2dd7-5dd2-8b70-531169e83b20")}catch(e){}}();
|
|
3
3
|
export {};
|
|
4
4
|
//# sourceMappingURL=lib.js.map
|
|
5
|
-
//# debugId=
|
|
5
|
+
//# debugId=be0ac435-2dd7-5dd2-8b70-531169e83b20
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
|
|
2
|
-
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="
|
|
2
|
+
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="ec896cd1-5086-5370-b8b3-2b5276946dee")}catch(e){}}();
|
|
3
3
|
import fg from "fast-glob";
|
|
4
4
|
import { existsSync, readdirSync } from "node:fs";
|
|
5
5
|
import { join } from "node:path";
|
|
6
6
|
import { simpleGit } from "simple-git";
|
|
7
7
|
import { TEST_IN_FOLDER } from "../constants.js";
|
|
8
8
|
import { CompositeValidator } from "./lib.js";
|
|
9
|
-
import {
|
|
9
|
+
import { IsZupLinkInvocableValidator } from "./login-state-validator.js";
|
|
10
10
|
import { ProjectIsSetValidator } from "./project-name-validator.js";
|
|
11
11
|
export class NotAGitRepoError extends Error {
|
|
12
12
|
constructor() {
|
|
@@ -161,6 +161,6 @@ export class ZuploProjectHasTestsValidator {
|
|
|
161
161
|
}
|
|
162
162
|
export const validDeployDirectoryValidator = new CompositeValidator(new ZuploProjectValidator(), new GitVersionControlValidator(), new GitCommitValidator(), new GitBranchValidator(), new GitRemoteValidator(), new ProjectIsSetValidator());
|
|
163
163
|
export const validTestDirectoryValidator = new CompositeValidator(new ZuploProjectValidator(), new ZuploProjectHasTestsValidator());
|
|
164
|
-
export const validLinkDirectoryValidator = new CompositeValidator(new ZuploProjectValidator(), new
|
|
164
|
+
export const validLinkDirectoryValidator = new CompositeValidator(new ZuploProjectValidator(), new IsZupLinkInvocableValidator());
|
|
165
165
|
//# sourceMappingURL=file-system-validator.js.map
|
|
166
|
-
//# debugId=
|
|
166
|
+
//# debugId=ec896cd1-5086-5370-b8b3-2b5276946dee
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="
|
|
2
|
+
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="b9d015db-7e92-5ad9-a0e8-514350db203a")}catch(e){}}();
|
|
3
3
|
import { existsSync } from "node:fs";
|
|
4
4
|
import { readFile } from "node:fs/promises";
|
|
5
5
|
import { join } from "node:path";
|
|
@@ -7,16 +7,19 @@ import { ZUPLO_AUTH_FILE_NAME } from "../constants.js";
|
|
|
7
7
|
import { logger } from "../logger.js";
|
|
8
8
|
import settings from "../settings.js";
|
|
9
9
|
import { ZUPLO_XDG_STATE_HOME } from "../xdg/lib.js";
|
|
10
|
-
export class
|
|
10
|
+
export class CannotInvokeZupLink extends Error {
|
|
11
11
|
constructor() {
|
|
12
12
|
super(`You are not logged in (or your credentials have expired). Please run \`zup login\` to log in.`);
|
|
13
|
-
Object.setPrototypeOf(this,
|
|
13
|
+
Object.setPrototypeOf(this, CannotInvokeZupLink.prototype);
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
|
-
export class
|
|
17
|
-
async validate(
|
|
16
|
+
export class IsZupLinkInvocableValidator {
|
|
17
|
+
async validate(options) {
|
|
18
|
+
if (options.environment) {
|
|
19
|
+
return { ok: true };
|
|
20
|
+
}
|
|
18
21
|
if (!existsSync(join(ZUPLO_XDG_STATE_HOME, ZUPLO_AUTH_FILE_NAME))) {
|
|
19
|
-
return { ok: false, error: new
|
|
22
|
+
return { ok: false, error: new CannotInvokeZupLink() };
|
|
20
23
|
}
|
|
21
24
|
const rawAuth = await readFile(join(ZUPLO_XDG_STATE_HOME, ZUPLO_AUTH_FILE_NAME), "utf-8");
|
|
22
25
|
const authJson = JSON.parse(rawAuth);
|
|
@@ -30,10 +33,10 @@ export class UserIsLoggedInValidator {
|
|
|
30
33
|
status: accountResponse.status,
|
|
31
34
|
statusText: accountResponse.statusText,
|
|
32
35
|
}, "Failed to connect to Zuplo API during verification. Assuming user is not logged in.");
|
|
33
|
-
return { ok: false, error: new
|
|
36
|
+
return { ok: false, error: new CannotInvokeZupLink() };
|
|
34
37
|
}
|
|
35
38
|
return { ok: true };
|
|
36
39
|
}
|
|
37
40
|
}
|
|
38
41
|
//# sourceMappingURL=login-state-validator.js.map
|
|
39
|
-
//# debugId=
|
|
42
|
+
//# debugId=b9d015db-7e92-5ad9-a0e8-514350db203a
|
package/dist/compile/handler.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
|
|
2
|
-
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="
|
|
3
|
-
import
|
|
2
|
+
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="925b9d73-a4de-58c0-8f9c-d757c8155db7")}catch(e){}}();
|
|
3
|
+
import dotenv from "dotenv";
|
|
4
|
+
import { cpSync, existsSync, readFileSync } from "node:fs";
|
|
4
5
|
import { join, relative, resolve } from "node:path";
|
|
5
6
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
6
7
|
import { printDiagnosticsToConsole } from "../common/output.js";
|
|
@@ -14,14 +15,11 @@ export async function compile(argv) {
|
|
|
14
15
|
});
|
|
15
16
|
}
|
|
16
17
|
process.env.GLOBAL_MODULE_LOCATION = fileURLToPath(new URL("../../node_modules", import.meta.url));
|
|
17
|
-
|
|
18
|
-
const envFile = join(sourceDirectory, ".env");
|
|
19
|
-
if (existsSync(envFile)) {
|
|
20
|
-
loadedEnvFiles.push(".env");
|
|
21
|
-
}
|
|
18
|
+
let envZuplo = {};
|
|
22
19
|
const envZuploFile = join(sourceDirectory, ".env.zuplo");
|
|
23
20
|
if (existsSync(envZuploFile)) {
|
|
24
|
-
|
|
21
|
+
const contents = readFileSync(envZuploFile);
|
|
22
|
+
envZuplo = dotenv.parse(contents);
|
|
25
23
|
}
|
|
26
24
|
const config = {
|
|
27
25
|
build_assets_url: pathToFileURL(sourceDirectory),
|
|
@@ -33,10 +31,17 @@ export async function compile(argv) {
|
|
|
33
31
|
sourceDirectory,
|
|
34
32
|
port: zupPort,
|
|
35
33
|
binaryName: argv["binary-name"],
|
|
36
|
-
|
|
34
|
+
publicZuploEnvironmentVariables: envZuplo
|
|
35
|
+
? {
|
|
36
|
+
ZUPLO_ACCOUNT_NAME: envZuplo.ZUPLO_ACCOUNT_NAME,
|
|
37
|
+
ZUPLO_PROJECT_NAME: envZuplo.ZUPLO_PROJECT_NAME,
|
|
38
|
+
ZUPLO_ENVIRONMENT_TYPE: envZuplo.ZUPLO_ENVIRONMENT_TYPE,
|
|
39
|
+
}
|
|
40
|
+
:
|
|
41
|
+
undefined,
|
|
37
42
|
});
|
|
38
43
|
printDiagnosticsToConsole("📦 Compiled a self-contained zup binary");
|
|
39
44
|
printDiagnosticsToConsole(`The binary is available at ${sourceDirectory}/dist/${argv["binary-name"]}`);
|
|
40
45
|
}
|
|
41
46
|
//# sourceMappingURL=handler.js.map
|
|
42
|
-
//# debugId=
|
|
47
|
+
//# debugId=925b9d73-a4de-58c0-8f9c-d757c8155db7
|
package/dist/dev/handler.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
|
|
2
|
-
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="
|
|
3
|
-
import
|
|
2
|
+
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="249e5ca0-cf2e-5cef-a5c8-0d053825f965")}catch(e){}}();
|
|
3
|
+
import dotenv from "dotenv";
|
|
4
|
+
import { cpSync, existsSync, readFileSync } from "node:fs";
|
|
4
5
|
import { join, relative, resolve } from "node:path";
|
|
5
6
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
6
7
|
import { logger } from "../common/logger.js";
|
|
@@ -22,14 +23,18 @@ export async function dev(argv) {
|
|
|
22
23
|
if (existsSync(envFile)) {
|
|
23
24
|
loadedEnvFiles.push(".env");
|
|
24
25
|
}
|
|
26
|
+
let envZuplo;
|
|
25
27
|
const envZuploFile = join(sourceDirectory, ".env.zuplo");
|
|
26
28
|
if (existsSync(envZuploFile)) {
|
|
29
|
+
const contents = readFileSync(envZuploFile);
|
|
30
|
+
envZuplo = dotenv.parse(contents);
|
|
27
31
|
loadedEnvFiles.push(".env.zuplo");
|
|
28
32
|
}
|
|
29
33
|
const config = {
|
|
30
34
|
build_assets_url: pathToFileURL(sourceDirectory),
|
|
31
35
|
};
|
|
32
36
|
process.env.__ZUPLO_CONFIG = btoa(JSON.stringify(config));
|
|
37
|
+
process.env.ZUPLO_IS_LOCAL_DEVELOPMENT = "true";
|
|
33
38
|
const core = await import("@zuplo/core");
|
|
34
39
|
const zupPort = argv.port;
|
|
35
40
|
const zupEditorPort = argv.editorPort;
|
|
@@ -52,12 +57,14 @@ export async function dev(argv) {
|
|
|
52
57
|
sourceDirectory,
|
|
53
58
|
port: zupPort,
|
|
54
59
|
debugPort: argv.debugPort ?? undefined,
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
60
|
+
publicZuploEnvironmentVariables: envZuplo
|
|
61
|
+
? {
|
|
62
|
+
ZUPLO_ACCOUNT_NAME: envZuplo.ZUPLO_ACCOUNT_NAME,
|
|
63
|
+
ZUPLO_PROJECT_NAME: envZuplo.ZUPLO_PROJECT_NAME,
|
|
64
|
+
ZUPLO_ENVIRONMENT_TYPE: envZuplo.ZUPLO_ENVIRONMENT_TYPE,
|
|
65
|
+
}
|
|
66
|
+
:
|
|
67
|
+
undefined,
|
|
61
68
|
});
|
|
62
69
|
let editor;
|
|
63
70
|
if (argv["start-editor"]) {
|
|
@@ -95,4 +102,4 @@ export async function dev(argv) {
|
|
|
95
102
|
});
|
|
96
103
|
}
|
|
97
104
|
//# sourceMappingURL=handler.js.map
|
|
98
|
-
//# debugId=
|
|
105
|
+
//# debugId=249e5ca0-cf2e-5cef-a5c8-0d053825f965
|
package/dist/link/handler.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="
|
|
2
|
+
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="90968db1-f5e4-5d8c-bbaa-d4b1a87e94fa")}catch(e){}}();
|
|
3
3
|
import { select } from "@inquirer/prompts";
|
|
4
4
|
import { readFile } from "node:fs/promises";
|
|
5
5
|
import { join } from "node:path";
|
|
@@ -9,75 +9,138 @@ import { printCriticalFailureToConsoleAndExit, printResultToConsoleAndExitGracef
|
|
|
9
9
|
import settings from "../common/settings.js";
|
|
10
10
|
import { ZUPLO_XDG_STATE_HOME } from "../common/xdg/lib.js";
|
|
11
11
|
import { pullSystemConfig, safeMergeConfig } from "./populate.js";
|
|
12
|
+
function prettyPrintEnvironmentPrompt(env) {
|
|
13
|
+
const name = env.name;
|
|
14
|
+
let environmentType = env.environmentType.toLowerCase();
|
|
15
|
+
let branchName = env.branchName;
|
|
16
|
+
switch (environmentType) {
|
|
17
|
+
case "working-copy":
|
|
18
|
+
case "working_copy":
|
|
19
|
+
environmentType = "development";
|
|
20
|
+
branchName = "(via portal.zuplo.com)";
|
|
21
|
+
break;
|
|
22
|
+
}
|
|
23
|
+
return `${env.name} (${environmentType}, ${branchName})`;
|
|
24
|
+
}
|
|
12
25
|
export async function link(argv) {
|
|
13
26
|
const rawAuth = await readFile(join(ZUPLO_XDG_STATE_HOME, ZUPLO_AUTH_FILE_NAME), "utf-8");
|
|
14
27
|
const authJson = JSON.parse(rawAuth);
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
status: accountResponse.status,
|
|
23
|
-
statusText: accountResponse.statusText,
|
|
24
|
-
response: textOrJson(await accountResponse.text()),
|
|
25
|
-
}, "Failed to list accounts.");
|
|
26
|
-
await printCriticalFailureToConsoleAndExit("Error: Failed to list your accounts. Try again later.");
|
|
27
|
-
}
|
|
28
|
-
const accountJson = (await accountResponse.json());
|
|
29
|
-
let account;
|
|
30
|
-
if (accountJson.length === 1) {
|
|
31
|
-
account = accountJson[0].name;
|
|
32
|
-
}
|
|
33
|
-
else {
|
|
34
|
-
account = await select({
|
|
35
|
-
message: "Select the account to work with",
|
|
36
|
-
choices: accountJson.map((acc) => {
|
|
37
|
-
return {
|
|
38
|
-
name: acc.name,
|
|
39
|
-
value: acc.name,
|
|
40
|
-
};
|
|
41
|
-
}),
|
|
28
|
+
let environment = argv.environment;
|
|
29
|
+
let account = argv.account;
|
|
30
|
+
if (!environment && !account) {
|
|
31
|
+
const accountResponse = await fetch(`${settings.ZUPLO_API_ENDPOINT}/v1/accounts`, {
|
|
32
|
+
headers: {
|
|
33
|
+
authorization: `Bearer ${authJson.access_token}`,
|
|
34
|
+
},
|
|
42
35
|
});
|
|
36
|
+
if (!accountResponse.ok) {
|
|
37
|
+
logger.error({
|
|
38
|
+
status: accountResponse.status,
|
|
39
|
+
statusText: accountResponse.statusText,
|
|
40
|
+
response: textOrJson(await accountResponse.text()),
|
|
41
|
+
}, "Failed to list accounts.");
|
|
42
|
+
await printCriticalFailureToConsoleAndExit("Error: Failed to list your accounts. Try again later.");
|
|
43
|
+
}
|
|
44
|
+
const accountJson = (await accountResponse.json());
|
|
45
|
+
if (accountJson.length === 1) {
|
|
46
|
+
account = accountJson[0].name;
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
account = await select({
|
|
50
|
+
message: "Select the account to work with",
|
|
51
|
+
choices: accountJson.map((acc) => {
|
|
52
|
+
return {
|
|
53
|
+
name: acc.name,
|
|
54
|
+
value: acc.name,
|
|
55
|
+
};
|
|
56
|
+
}),
|
|
57
|
+
});
|
|
58
|
+
}
|
|
43
59
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
60
|
+
let project = argv.project;
|
|
61
|
+
if (!environment && !project) {
|
|
62
|
+
const projectResponse = await fetch(`${settings.ZUPLO_API_ENDPOINT}/v1/accounts/${account}/projects`, {
|
|
63
|
+
headers: {
|
|
64
|
+
authorization: `Bearer ${authJson.access_token}`,
|
|
65
|
+
},
|
|
66
|
+
});
|
|
67
|
+
if (!projectResponse.ok) {
|
|
68
|
+
logger.error({
|
|
69
|
+
status: projectResponse.status,
|
|
70
|
+
statusText: projectResponse.statusText,
|
|
71
|
+
response: textOrJson(await projectResponse.text()),
|
|
72
|
+
}, "Failed to list projects.");
|
|
73
|
+
await printCriticalFailureToConsoleAndExit("Error: Failed to list your projects. Try again later.");
|
|
74
|
+
}
|
|
75
|
+
const projectJson = (await projectResponse.json());
|
|
76
|
+
if (projectJson.data.length === 1) {
|
|
77
|
+
project = projectJson.data[0].name;
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
project = await select({
|
|
81
|
+
message: "Select the project to work with",
|
|
82
|
+
choices: projectJson.data.map((prj) => {
|
|
83
|
+
return {
|
|
84
|
+
name: prj.name,
|
|
85
|
+
value: prj.name,
|
|
86
|
+
};
|
|
87
|
+
}),
|
|
88
|
+
});
|
|
89
|
+
}
|
|
61
90
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
name: prj.name,
|
|
68
|
-
value: prj.name,
|
|
69
|
-
};
|
|
70
|
-
}),
|
|
91
|
+
if (!environment) {
|
|
92
|
+
const environmentResponseFromZuploAPI = await fetch(`${settings.ZUPLO_API_ENDPOINT}/v1/accounts/${account}/projects/${project}/deployments`, {
|
|
93
|
+
headers: {
|
|
94
|
+
authorization: `Bearer ${authJson.access_token}`,
|
|
95
|
+
},
|
|
71
96
|
});
|
|
97
|
+
const environmentJsonFromZuploAPI = (await environmentResponseFromZuploAPI.json());
|
|
98
|
+
const environmentResponseFromDeveloperAPI = await fetch(`${settings.ZUPLO_DEVELOPER_API_ENDPOINT}/v1/accounts/${account}/projects/${project}/deployments`, {
|
|
99
|
+
headers: {
|
|
100
|
+
authorization: `Bearer ${argv["api-key"]}`,
|
|
101
|
+
},
|
|
102
|
+
});
|
|
103
|
+
const environmentJsonFromDeveloperAPI = (await environmentResponseFromDeveloperAPI.json());
|
|
104
|
+
const environments = Object.assign({}, environmentJsonFromZuploAPI.data
|
|
105
|
+
.map((env) => {
|
|
106
|
+
return {
|
|
107
|
+
[prettyPrintEnvironmentPrompt(env)]: env.name,
|
|
108
|
+
};
|
|
109
|
+
})
|
|
110
|
+
.reduce((acc, curr) => {
|
|
111
|
+
return { ...acc, ...curr };
|
|
112
|
+
}), environmentJsonFromDeveloperAPI.data
|
|
113
|
+
.map((env) => {
|
|
114
|
+
return {
|
|
115
|
+
[prettyPrintEnvironmentPrompt(env)]: env.name,
|
|
116
|
+
};
|
|
117
|
+
})
|
|
118
|
+
.reduce((acc, curr) => {
|
|
119
|
+
return { ...acc, ...curr };
|
|
120
|
+
}));
|
|
121
|
+
if (Object.values(environments).length === 1) {
|
|
122
|
+
environment = Object.values(environments)[0];
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
environment = await select({
|
|
126
|
+
message: "Select the environment to work with",
|
|
127
|
+
choices: Object.entries(environments).map(([key, value]) => {
|
|
128
|
+
return {
|
|
129
|
+
name: key,
|
|
130
|
+
value,
|
|
131
|
+
};
|
|
132
|
+
}),
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
argv.environment = environment;
|
|
137
|
+
if (project) {
|
|
138
|
+
await safeMergeConfig(argv.dir, project);
|
|
72
139
|
}
|
|
73
|
-
await
|
|
74
|
-
await pullSystemConfig(argv.dir, {
|
|
75
|
-
account: accountJson.find((acc) => acc.name === account),
|
|
76
|
-
project: projectJson.data.find((prj) => prj.name === project),
|
|
77
|
-
});
|
|
140
|
+
await pullSystemConfig(argv);
|
|
78
141
|
await printResultToConsoleAndExitGracefully(`
|
|
79
142
|
Successfully linked your local directory to the ${project} project in the ${account} account.
|
|
80
143
|
.env.zuplo and zuplo.jsonc have been updated with the new values.`);
|
|
81
144
|
}
|
|
82
145
|
//# sourceMappingURL=handler.js.map
|
|
83
|
-
//# debugId=
|
|
146
|
+
//# debugId=90968db1-f5e4-5d8c-bbaa-d4b1a87e94fa
|
package/dist/link/populate.js
CHANGED
|
@@ -1,25 +1,22 @@
|
|
|
1
1
|
|
|
2
|
-
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="
|
|
2
|
+
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="6b8807e2-ae71-5c69-b1b0-2b87dae3cfdb")}catch(e){}}();
|
|
3
3
|
import { applyEdits, modify } from "jsonc-parser";
|
|
4
4
|
import { existsSync } from "node:fs";
|
|
5
5
|
import { readFile, writeFile } from "node:fs/promises";
|
|
6
6
|
import { join, relative } from "node:path";
|
|
7
7
|
import prettier from "prettier";
|
|
8
8
|
import { ZUPLO_FALLBACK_JSON_FILE, ZUPLO_PREFERRED_JSON_FILE, ZUPLO_SYSTEM_ENV_VAR, } from "../common/constants.js";
|
|
9
|
-
|
|
9
|
+
import settings from "../common/settings.js";
|
|
10
|
+
export async function safeMergeConfig(dir, project) {
|
|
10
11
|
const normalizedDir = join(relative(process.cwd(), dir));
|
|
11
12
|
const zuploPreferredConfigFile = join(normalizedDir, ZUPLO_PREFERRED_JSON_FILE);
|
|
12
13
|
const zuploFallbackConfigFile = join(normalizedDir, ZUPLO_FALLBACK_JSON_FILE);
|
|
13
14
|
if (existsSync(zuploPreferredConfigFile)) {
|
|
14
15
|
const originalContents = await readFile(zuploPreferredConfigFile, "utf-8");
|
|
15
|
-
const
|
|
16
|
-
getInsertionIndex: () => 1,
|
|
17
|
-
});
|
|
18
|
-
const contentsPostAccount = applyEdits(originalContents, modifyAccountEdit);
|
|
19
|
-
const modifyProjectEdit = modify(contentsPostAccount, ["project"], options.project, {
|
|
16
|
+
const modifyProjectEdit = modify(originalContents, ["project"], project, {
|
|
20
17
|
getInsertionIndex: () => 2,
|
|
21
18
|
});
|
|
22
|
-
const contentsPostProject = applyEdits(
|
|
19
|
+
const contentsPostProject = applyEdits(originalContents, modifyProjectEdit);
|
|
23
20
|
const formatted = prettier.format(contentsPostProject, {
|
|
24
21
|
parser: "json",
|
|
25
22
|
quoteProps: "as-needed",
|
|
@@ -30,8 +27,7 @@ export async function safeMergeConfig(dir, options) {
|
|
|
30
27
|
const config = JSON.parse(await readFile(zuploFallbackConfigFile, "utf-8"));
|
|
31
28
|
const formatted = prettier.format(JSON.stringify({
|
|
32
29
|
version: 1,
|
|
33
|
-
|
|
34
|
-
project: options.project,
|
|
30
|
+
project: project,
|
|
35
31
|
compatibilityDate: config.compatibilityDate,
|
|
36
32
|
}), {
|
|
37
33
|
parser: "json",
|
|
@@ -42,8 +38,7 @@ export async function safeMergeConfig(dir, options) {
|
|
|
42
38
|
else {
|
|
43
39
|
const formatted = prettier.format(JSON.stringify({
|
|
44
40
|
version: 1,
|
|
45
|
-
|
|
46
|
-
project: options.project,
|
|
41
|
+
project: project,
|
|
47
42
|
compatibilityDate: "2023-03-14",
|
|
48
43
|
}), {
|
|
49
44
|
parser: "json",
|
|
@@ -52,18 +47,26 @@ export async function safeMergeConfig(dir, options) {
|
|
|
52
47
|
await writeFile(zuploPreferredConfigFile, formatted);
|
|
53
48
|
}
|
|
54
49
|
}
|
|
55
|
-
export async function pullSystemConfig(
|
|
56
|
-
const normalizedDir = join(relative(process.cwd(), dir));
|
|
50
|
+
export async function pullSystemConfig(argv) {
|
|
51
|
+
const normalizedDir = join(relative(process.cwd(), argv.dir));
|
|
57
52
|
const zuploPreferredConfigFile = join(normalizedDir, ZUPLO_SYSTEM_ENV_VAR);
|
|
53
|
+
const environmentResponseFromDeveloperAPI = await fetch(`${settings.ZUPLO_DEVELOPER_API_ENDPOINT}/v1/environments/${argv.environment}/configurations`, {
|
|
54
|
+
headers: {
|
|
55
|
+
authorization: `Bearer ${argv["api-key"]}`,
|
|
56
|
+
},
|
|
57
|
+
});
|
|
58
|
+
const payload = await environmentResponseFromDeveloperAPI.json();
|
|
58
59
|
const content = `
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
60
|
+
# This file is auto-generated from zup link. Please do not edit it manually.
|
|
61
|
+
# It will be auto-generated afresh the next time you run zup link.
|
|
62
|
+
# If you wish to add your own environment variables, create a separate .env file.
|
|
63
|
+
|
|
64
|
+
ZUPLO_ACCOUNT_NAME=${payload.accountName}
|
|
65
|
+
ZUPLO_PROJECT_NAME=${payload.projectName}
|
|
66
|
+
ZUPLO_ENVIRONMENT_TYPE=${payload.environmentType}
|
|
67
|
+
ZUPLO_SYSTEM_CONFIGURATIONS=${payload["systemConfigurations"]}
|
|
68
|
+
`;
|
|
66
69
|
await writeFile(zuploPreferredConfigFile, content);
|
|
67
70
|
}
|
|
68
71
|
//# sourceMappingURL=populate.js.map
|
|
69
|
-
//# debugId=
|
|
72
|
+
//# debugId=6b8807e2-ae71-5c69-b1b0-2b87dae3cfdb
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zuplo/cli",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.120.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"repository": "https://github.com/zuplo/cli",
|
|
6
6
|
"description": "The command-line interface for Zuplo",
|
|
@@ -64,10 +64,10 @@
|
|
|
64
64
|
"@opentelemetry/api": "^1.8.0",
|
|
65
65
|
"@sentry/node": "7.69.0",
|
|
66
66
|
"@swc/core": "1.3.78",
|
|
67
|
-
"@zuplo/core": "5.
|
|
67
|
+
"@zuplo/core": "5.2251.0",
|
|
68
68
|
"@zuplo/deno-bin": "1.37.1",
|
|
69
69
|
"@zuplo/pino-pretty-configurations": "^1.5.0",
|
|
70
|
-
"@zuplo/runtime": "5.
|
|
70
|
+
"@zuplo/runtime": "5.2251.0",
|
|
71
71
|
"chalk": "^5.1.2",
|
|
72
72
|
"chokidar": "^3.5.3",
|
|
73
73
|
"dotenv": "^16.3.1",
|