@zuplo/cli 6.25.18 → 6.26.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/common/middleware/user-configuration.d.ts.map +1 -1
- package/dist/common/middleware/user-configuration.js +6 -5
- package/dist/common/middleware/user-configuration.js.map +1 -1
- package/dist/common/validators/file-system-validator.d.ts +12 -0
- package/dist/common/validators/file-system-validator.d.ts.map +1 -1
- package/dist/common/validators/file-system-validator.js +39 -5
- package/dist/common/validators/file-system-validator.js.map +1 -1
- package/dist/deploy/archive.d.ts +2 -2
- package/dist/deploy/archive.d.ts.map +1 -1
- package/dist/deploy/archive.js +8 -3
- package/dist/deploy/archive.js.map +1 -1
- package/package.json +3 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"user-configuration.d.ts","sourceRoot":"","sources":["../../../src/common/middleware/user-configuration.ts"],"names":[],"mappings":"AA0BA,wBAAsB,SAAS,CAAC,IAAI,EAAE;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CAAE,
|
|
1
|
+
{"version":3,"file":"user-configuration.d.ts","sourceRoot":"","sources":["../../../src/common/middleware/user-configuration.ts"],"names":[],"mappings":"AA0BA,wBAAsB,SAAS,CAAC,IAAI,EAAE;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CAAE,iBA8C/D"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { parse } from "jsonc-parser";
|
|
2
2
|
import { existsSync } from "node:fs";
|
|
3
3
|
import { readFile } from "node:fs/promises";
|
|
4
|
-
import {
|
|
4
|
+
import { join, relative } from "node:path";
|
|
5
5
|
import { ZUPLO_FALLBACK_JSON_FILE, ZUPLO_PREFERRED_JSON_FILE, } from "../constants.js";
|
|
6
6
|
import { logger } from "../logger.js";
|
|
7
7
|
import { printCriticalFailureToConsoleAndExit } from "../output.js";
|
|
@@ -17,7 +17,7 @@ export async function configure(argv) {
|
|
|
17
17
|
if (whoAmIResponse.ok) {
|
|
18
18
|
const apiKeyMetadata = await whoAmIResponse.json();
|
|
19
19
|
Object.assign(argv, omitNull(apiKeyMetadata));
|
|
20
|
-
const { project: zuploJsoncProject } = await processZuploConfigurationFile();
|
|
20
|
+
const { project: zuploJsoncProject } = await processZuploConfigurationFile(argv.dir);
|
|
21
21
|
if (zuploJsoncProject) {
|
|
22
22
|
argv.project = zuploJsoncProject;
|
|
23
23
|
}
|
|
@@ -28,9 +28,10 @@ export async function configure(argv) {
|
|
|
28
28
|
await printCriticalFailureToConsoleAndExit("Error: Failed to validate the API key. Check your API key.");
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
|
-
async function processZuploConfigurationFile() {
|
|
32
|
-
const
|
|
33
|
-
const
|
|
31
|
+
async function processZuploConfigurationFile(sourceDirectory) {
|
|
32
|
+
const normalizedDir = join(relative(process.cwd(), sourceDirectory ?? "."));
|
|
33
|
+
const preferredPath = join(normalizedDir, ZUPLO_PREFERRED_JSON_FILE);
|
|
34
|
+
const fallbackPath = join(normalizedDir, ZUPLO_FALLBACK_JSON_FILE);
|
|
34
35
|
let fileContents = "{}";
|
|
35
36
|
if (existsSync(preferredPath)) {
|
|
36
37
|
fileContents = await readFile(preferredPath, "utf-8");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"user-configuration.js","sourceRoot":"","sources":["../../../src/common/middleware/user-configuration.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,KAAK,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"user-configuration.js","sourceRoot":"","sources":["../../../src/common/middleware/user-configuration.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,KAAK,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,EAAE,UAAU,EAAE,MAAM,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,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC;SAC9B,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,OAAO,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IACjC,OAAO,GAAG,CAAC;AACb,CAAC,CAAC","sourcesContent":["import { ParseError, parse } from \"jsonc-parser\";\nimport { existsSync } from \"node:fs\";\nimport { readFile } from \"node:fs/promises\";\nimport { join, relative } from \"node:path\";\nimport {\n ZUPLO_FALLBACK_JSON_FILE,\n ZUPLO_PREFERRED_JSON_FILE,\n} from \"../constants.js\";\nimport { logger } from \"../logger.js\";\nimport { printCriticalFailureToConsoleAndExit } from \"../output.js\";\nimport settings from \"../settings.js\";\n\n/**\n * This is the middleware to set the context for the CLI calls.\n *\n * It can be used to set sensible configurations such as account and project that are gotten from the API, zuplo.jsonc, --parameters\n *\n * The order of setting a configuration is\n * 1. API key\n * 2. zuplo.jsonc\n * 3. --parameters from the CLI invocation\n *\n * Note that --parameters objects can also come from .env file because of https://yargs.js.org/docs/#api-reference-envprefix\n *\n * @param argv - The yargs object\n */\nexport async function configure(argv: { [key: string]: unknown }) {\n // Clone the original value (for merging at the end)\n // The original is the most specific since it can only contain things from --parameters\n // It will always be applied last to override anything from zuplo.jsonc or the API key\n const cliParametersConfiguration = { ...argv };\n\n // Make a call to the API key\n const whoAmIResponse = await fetch(\n `${settings.ZUPLO_DEVELOPER_API_ENDPOINT}/v1/who-am-i`,\n {\n method: \"GET\",\n headers: {\n Authorization: `Bearer ${argv[\"api-key\"]}`,\n },\n }\n );\n\n if (whoAmIResponse.ok) {\n // Note that the algorithms below are based on \"addition\"\n // You cannot unset/remove a value from the configuration by setting it to null/undefined\n // Do be mindful of parameters that might be the same value since things might be overridden\n\n // Merge any non-null values from the API key\n const apiKeyMetadata = await whoAmIResponse.json();\n Object.assign(argv, omitNull(apiKeyMetadata));\n\n // Merge any non-null values from zuplo.jsonc\n // For now, only merge project since zuplo.jsonc could have many keys that might conflict\n const { project: zuploJsoncProject } = await processZuploConfigurationFile(\n argv.dir as string | undefined\n );\n if (zuploJsoncProject) {\n argv.project = zuploJsoncProject;\n }\n\n // Merge any non-null values from --parameters\n Object.assign(argv, cliParametersConfiguration);\n } else {\n logger.trace(\n { status: whoAmIResponse.status, statusText: whoAmIResponse.statusText },\n \"Failed to determine who-am-i\"\n );\n await printCriticalFailureToConsoleAndExit(\n \"Error: Failed to validate the API key. Check your API key.\"\n );\n }\n}\n\nasync function processZuploConfigurationFile(\n sourceDirectory: string | undefined\n) {\n const normalizedDir = join(relative(process.cwd(), sourceDirectory ?? \".\"));\n const preferredPath = join(normalizedDir, ZUPLO_PREFERRED_JSON_FILE);\n const fallbackPath = join(normalizedDir, ZUPLO_FALLBACK_JSON_FILE);\n let fileContents = \"{}\";\n if (existsSync(preferredPath)) {\n fileContents = await readFile(preferredPath, \"utf-8\");\n } else if (existsSync(fallbackPath)) {\n fileContents = await readFile(fallbackPath, \"utf-8\");\n } else {\n logger.trace(\"No zuplo.jsonc file found\");\n return {};\n }\n\n // If we get here, we have a zuplo.jsonc (or, zuplo.json) file\n // That means we should report any issues with it.\n const errors: ParseError[] = [];\n const data = parse(fileContents, errors, { allowTrailingComma: true });\n if (errors.length > 0) {\n logger.trace(errors[0], \"Failed to parse zuplo.jsonc\");\n await printCriticalFailureToConsoleAndExit(\n \"Error: Failed to parse the values from zuplo.jsonc. Check your zuplo.jsonc file.\"\n );\n }\n return data;\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nconst omitNull = (obj: any) => {\n Object.keys(obj)\n .filter((k) => obj[k] === null)\n .forEach((k) => delete obj[k]);\n return obj;\n};\n"]}
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import { CompositeValidator, Result, ValidationRule } from "./lib.js";
|
|
2
|
+
export declare class GitBranchOrEnvironmentRequiredError extends Error {
|
|
3
|
+
constructor();
|
|
4
|
+
}
|
|
2
5
|
export declare class NotAGitRepoError extends Error {
|
|
3
6
|
constructor();
|
|
4
7
|
}
|
|
@@ -21,6 +24,14 @@ export declare class GitVersionControlValidator implements ValidationRule<{
|
|
|
21
24
|
dir: string;
|
|
22
25
|
}): Promise<Result>;
|
|
23
26
|
}
|
|
27
|
+
export declare class GitBranchOrEnvironmentValidator implements ValidationRule<{
|
|
28
|
+
dir: string;
|
|
29
|
+
}> {
|
|
30
|
+
validate(option: {
|
|
31
|
+
dir: string;
|
|
32
|
+
environment: string | undefined;
|
|
33
|
+
}): Promise<Result>;
|
|
34
|
+
}
|
|
24
35
|
export declare class GitCommitValidator implements ValidationRule<{
|
|
25
36
|
dir: string;
|
|
26
37
|
}> {
|
|
@@ -52,6 +63,7 @@ export declare class ZuploProjectHasTestsValidator implements ValidationRule<{
|
|
|
52
63
|
export declare const validDeployDirectoryValidator: CompositeValidator<{
|
|
53
64
|
dir: string;
|
|
54
65
|
project: string | undefined;
|
|
66
|
+
environment: string | undefined;
|
|
55
67
|
}>;
|
|
56
68
|
export declare const validTestDirectoryValidator: CompositeValidator<{
|
|
57
69
|
dir: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"file-system-validator.d.ts","sourceRoot":"","sources":["../../../src/common/validators/file-system-validator.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,kBAAkB,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAGtE,qBAAa,gBAAiB,SAAQ,KAAK;;CAK1C;AAED,qBAAa,gBAAiB,SAAQ,KAAK;;CAO1C;AAED,qBAAa,wBAAyB,SAAQ,KAAK;;CAOlD;AAED,qBAAa,YAAa,SAAQ,KAAK;;CAOtC;AAED,qBAAa,eAAgB,SAAQ,KAAK;;CAOzC;AAED,qBAAa,0BACX,YAAW,cAAc,CAAC;IAAE,GAAG,EAAE,MAAM,CAAA;CAAE,CAAC;IAEpC,QAAQ,CAAC,MAAM,EAAE;QAAE,GAAG,EAAE,MAAM,CAAA;KAAE,GA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SAAS;iBACd,MAAM,GAAG,SAAS;EAKhC,CAAC;AAEF,eAAO,MAAM,2BAA2B;SACjC,MAAM;EACuD,CAAC"}
|
|
@@ -5,27 +5,33 @@ import { simpleGit } from "simple-git";
|
|
|
5
5
|
import { TEST_IN_FOLDER } from "../constants.js";
|
|
6
6
|
import { CompositeValidator } from "./lib.js";
|
|
7
7
|
import { ProjectIsSetValidator } from "./project-name-validator.js";
|
|
8
|
+
export class GitBranchOrEnvironmentRequiredError extends Error {
|
|
9
|
+
constructor() {
|
|
10
|
+
super("Invalid arguments: The project directory is not a Git repository, you must specify the `environment` argument.");
|
|
11
|
+
Object.setPrototypeOf(this, NotAGitRepoError.prototype);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
8
14
|
export class NotAGitRepoError extends Error {
|
|
9
15
|
constructor() {
|
|
10
|
-
super("Invalid directory: The
|
|
16
|
+
super("Invalid directory: The project directory is not a Git repository.");
|
|
11
17
|
Object.setPrototypeOf(this, NotAGitRepoError.prototype);
|
|
12
18
|
}
|
|
13
19
|
}
|
|
14
20
|
export class NotAZuploProject extends Error {
|
|
15
21
|
constructor() {
|
|
16
|
-
super("Invalid directory: The
|
|
22
|
+
super("Invalid directory: The project directory is not the root of a Zuplo project.");
|
|
17
23
|
Object.setPrototypeOf(this, NotAZuploProject.prototype);
|
|
18
24
|
}
|
|
19
25
|
}
|
|
20
26
|
export class ZuploProjectMissingTests extends Error {
|
|
21
27
|
constructor() {
|
|
22
|
-
super("Invalid directory: The
|
|
28
|
+
super("Invalid directory: The project directory does not contain any tests (*.test.ts) in the /tests folder. Create a at least one test of the form some-name.test.ts");
|
|
23
29
|
Object.setPrototypeOf(this, ZuploProjectMissingTests.prototype);
|
|
24
30
|
}
|
|
25
31
|
}
|
|
26
32
|
export class NoGitCommits extends Error {
|
|
27
33
|
constructor() {
|
|
28
|
-
super("Invalid Git state: The
|
|
34
|
+
super("Invalid Git state: The project directory does not contain any commits. Make a commit before deploying.");
|
|
29
35
|
Object.setPrototypeOf(this, NoGitCommits.prototype);
|
|
30
36
|
}
|
|
31
37
|
}
|
|
@@ -50,6 +56,34 @@ export class GitVersionControlValidator {
|
|
|
50
56
|
}
|
|
51
57
|
}
|
|
52
58
|
}
|
|
59
|
+
export class GitBranchOrEnvironmentValidator {
|
|
60
|
+
async validate(option) {
|
|
61
|
+
const { dir, environment } = option;
|
|
62
|
+
if (typeof environment === "string") {
|
|
63
|
+
return {
|
|
64
|
+
ok: true,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
try {
|
|
68
|
+
if (await simpleGit({ baseDir: dir }).checkIsRepo()) {
|
|
69
|
+
await simpleGit({ baseDir: dir }).status();
|
|
70
|
+
const git = simpleGit({ baseDir: dir });
|
|
71
|
+
const branch = await git.branch();
|
|
72
|
+
if (branch.current) {
|
|
73
|
+
return {
|
|
74
|
+
ok: true,
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
catch {
|
|
80
|
+
}
|
|
81
|
+
return {
|
|
82
|
+
ok: false,
|
|
83
|
+
error: new GitBranchOrEnvironmentRequiredError(),
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
}
|
|
53
87
|
export class GitCommitValidator {
|
|
54
88
|
async validate(option) {
|
|
55
89
|
const { dir } = option;
|
|
@@ -132,6 +166,6 @@ export class ZuploProjectHasTestsValidator {
|
|
|
132
166
|
}
|
|
133
167
|
}
|
|
134
168
|
}
|
|
135
|
-
export const validDeployDirectoryValidator = new CompositeValidator(new ZuploProjectValidator(), new
|
|
169
|
+
export const validDeployDirectoryValidator = new CompositeValidator(new ZuploProjectValidator(), new ProjectIsSetValidator(), new GitBranchOrEnvironmentValidator());
|
|
136
170
|
export const validTestDirectoryValidator = new CompositeValidator(new ZuploProjectValidator(), new ZuploProjectHasTestsValidator());
|
|
137
171
|
//# sourceMappingURL=file-system-validator.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"file-system-validator.js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;QACvB,IAAI,CAAC;YACH,IAAI,EAAE,CAAC,IAAI,CAAC,GAAG,GAAG,IAAI,cAAc,eAAe,CAAC,CAAC,MAAM,IAAI,CAAC,EAAE,CAAC;gBACjE,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC;YACtB,CAAC;iBAAM,CAAC;gBACN,OAAO;oBACL,EAAE,EAAE,KAAK;oBACT,KAAK,EAAE,IAAI,wBAAwB,EAAE;iBACtC,CAAC;YACJ,CAAC;QACH,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,OAAO;gBACL,EAAE,EAAE,KAAK;gBACT,KAAK,EAAE,GAAG;aACX,CAAC;QACJ,CAAC;IACH,CAAC;CACF;AAED,MAAM,CAAC,MAAM,6BAA6B,GAAG,IAAI,kBAAkB,CAIjE,IAAI,qBAAqB,EAAE,EAC3B,IAAI,0BAA0B,EAAE,EAChC,IAAI,kBAAkB,EAAE,EACxB,IAAI,kBAAkB,EAAE,EACxB,IAAI,qBAAqB,EAAE,CAC5B,CAAC;AAEF,MAAM,CAAC,MAAM,2BAA2B,GAAG,IAAI,kBAAkB,CAE9D,IAAI,qBAAqB,EAAE,EAAE,IAAI,6BAA6B,EAAE,CAAC,CAAC","sourcesContent":["import fg from \"fast-glob\";\nimport { existsSync, readdirSync } from \"node:fs\";\nimport { join } from \"node:path\";\nimport { simpleGit } from \"simple-git\";\nimport { TEST_IN_FOLDER } from \"../constants.js\";\nimport { CompositeValidator, Result, ValidationRule } from \"./lib.js\";\nimport { ProjectIsSetValidator } from \"./project-name-validator.js\";\n\nexport class NotAGitRepoError extends Error {\n constructor() {\n super(\"Invalid directory: The current directory is not a Git repository.\");\n Object.setPrototypeOf(this, NotAGitRepoError.prototype);\n }\n}\n\nexport class NotAZuploProject extends Error {\n constructor() {\n super(\n \"Invalid directory: The current directory is not the root of a Zuplo project.\"\n );\n Object.setPrototypeOf(this, NotAZuploProject.prototype);\n }\n}\n\nexport class ZuploProjectMissingTests extends Error {\n constructor() {\n super(\n \"Invalid directory: The current directory does not contain any tests (*.test.ts) in the /tests folder. Create a at least one test of the form some-name.test.ts\"\n );\n Object.setPrototypeOf(this, ZuploProjectMissingTests.prototype);\n }\n}\n\nexport class NoGitCommits extends Error {\n constructor() {\n super(\n \"Invalid Git state: The current directory does not contain any commits. Make a commit before deploying.\"\n );\n Object.setPrototypeOf(this, NoGitCommits.prototype);\n }\n}\n\nexport class NotOnAGitBranch extends Error {\n constructor() {\n super(\n \"Invalid Git state: You are not on a branch. Run `git checkout -b <branch-name>` to create a new branch.\"\n );\n Object.setPrototypeOf(this, NotOnAGitBranch.prototype);\n }\n}\n\nexport class GitVersionControlValidator\n implements ValidationRule<{ dir: string }>\n{\n async validate(option: { dir: string }): Promise<Result> {\n const { dir } = option;\n try {\n await simpleGit({ baseDir: dir }).status();\n return { ok: true };\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n } catch (_err) {\n return {\n ok: false,\n error: new NotAGitRepoError(),\n };\n }\n }\n}\n\nexport class GitCommitValidator implements ValidationRule<{ dir: string }> {\n async validate(option: { dir: string }): Promise<Result> {\n const { dir } = option;\n try {\n const git = simpleGit({ baseDir: dir });\n const commits = await git.log({ maxCount: 1 });\n if (commits.total === 0) {\n return {\n ok: false,\n error: new NoGitCommits(),\n };\n }\n return { ok: true };\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n } catch (_err) {\n return {\n ok: false,\n error: new NoGitCommits(),\n };\n }\n }\n}\n\nexport class GitBranchValidator implements ValidationRule<{ dir: string }> {\n async validate(option: { dir: string }): Promise<Result> {\n const { dir } = option;\n const git = simpleGit({ baseDir: dir });\n const branch = await git.branch();\n if (!branch.current) {\n return {\n ok: false,\n error: new NotOnAGitBranch(),\n };\n }\n\n return { ok: true };\n }\n}\n\nexport class ZuploProjectValidator implements ValidationRule<{ dir: string }> {\n async validate(options: { dir: string }): Promise<Result> {\n const { dir } = options;\n try {\n if (existsSync(`${dir}/config`)) {\n const files = readdirSync(join(dir, \"config\"));\n const existingOASFiles =\n files.filter((file) => file.endsWith(\".oas.json\")).length >= 1;\n if (existingOASFiles === true) {\n return { ok: true };\n }\n }\n return {\n ok: false,\n error: new NotAZuploProject(),\n };\n } catch (err) {\n return {\n ok: false,\n error: err,\n };\n }\n }\n}\n\nexport class ZuploProjectHasTestsValidator\n implements ValidationRule<{ dir: string }>\n{\n async validate(option: { dir: string }): Promise<Result> {\n const { dir } = option;\n try {\n if (fg.sync(`${dir}/${TEST_IN_FOLDER}/**/*.test.ts`).length >= 1) {\n return { ok: true };\n } else {\n return {\n ok: false,\n error: new ZuploProjectMissingTests(),\n };\n }\n } catch (err) {\n return {\n ok: false,\n error: err,\n };\n }\n }\n}\n\nexport const validDeployDirectoryValidator = new CompositeValidator<{\n dir: string;\n project: string | undefined;\n}>(\n new ZuploProjectValidator(),\n new GitVersionControlValidator(),\n new GitCommitValidator(),\n new GitBranchValidator(),\n new ProjectIsSetValidator()\n);\n\nexport const validTestDirectoryValidator = new CompositeValidator<{\n dir: string;\n}>(new ZuploProjectValidator(), new ZuploProjectHasTestsValidator());\n"]}
|
|
1
|
+
{"version":3,"file":"file-system-validator.js","sourceRoot":"","sources":["../../../src/common/validators/file-system-validator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,WAAW,CAAC;AAC3B,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAClD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAE,kBAAkB,EAA0B,MAAM,UAAU,CAAC;AACtE,OAAO,EAAE,qBAAqB,EAAE,MAAM,6BAA6B,CAAC;AAEpE,MAAM,OAAO,mCAAoC,SAAQ,KAAK;IAC5D;QACE,KAAK,CACH,gHAAgH,CACjH,CAAC;QACF,MAAM,CAAC,cAAc,CAAC,IAAI,EA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s\";\nimport { join } from \"node:path\";\nimport { simpleGit } from \"simple-git\";\nimport { TEST_IN_FOLDER } from \"../constants.js\";\nimport { CompositeValidator, Result, ValidationRule } from \"./lib.js\";\nimport { ProjectIsSetValidator } from \"./project-name-validator.js\";\n\nexport class GitBranchOrEnvironmentRequiredError extends Error {\n constructor() {\n super(\n \"Invalid arguments: The project directory is not a Git repository, you must specify the `environment` argument.\"\n );\n Object.setPrototypeOf(this, NotAGitRepoError.prototype);\n }\n}\n\nexport class NotAGitRepoError extends Error {\n constructor() {\n super(\"Invalid directory: The project directory is not a Git repository.\");\n Object.setPrototypeOf(this, NotAGitRepoError.prototype);\n }\n}\n\nexport class NotAZuploProject extends Error {\n constructor() {\n super(\n \"Invalid directory: The project directory is not the root of a Zuplo project.\"\n );\n Object.setPrototypeOf(this, NotAZuploProject.prototype);\n }\n}\n\nexport class ZuploProjectMissingTests extends Error {\n constructor() {\n super(\n \"Invalid directory: The project directory does not contain any tests (*.test.ts) in the /tests folder. Create a at least one test of the form some-name.test.ts\"\n );\n Object.setPrototypeOf(this, ZuploProjectMissingTests.prototype);\n }\n}\n\nexport class NoGitCommits extends Error {\n constructor() {\n super(\n \"Invalid Git state: The project directory does not contain any commits. Make a commit before deploying.\"\n );\n Object.setPrototypeOf(this, NoGitCommits.prototype);\n }\n}\n\nexport class NotOnAGitBranch extends Error {\n constructor() {\n super(\n \"Invalid Git state: You are not on a branch. Run `git checkout -b <branch-name>` to create a new branch.\"\n );\n Object.setPrototypeOf(this, NotOnAGitBranch.prototype);\n }\n}\n\nexport class GitVersionControlValidator\n implements ValidationRule<{ dir: string }>\n{\n async validate(option: { dir: string }): Promise<Result> {\n const { dir } = option;\n try {\n await simpleGit({ baseDir: dir }).status();\n return { ok: true };\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n } catch (_err) {\n return {\n ok: false,\n error: new NotAGitRepoError(),\n };\n }\n }\n}\n\n/**\n * Checks if either the current branch is set as the environment or if\n * the environment is explicitly set\n */\nexport class GitBranchOrEnvironmentValidator\n implements ValidationRule<{ dir: string }>\n{\n async validate(option: {\n dir: string;\n environment: string | undefined;\n }): Promise<Result> {\n const { dir, environment } = option;\n if (typeof environment === \"string\") {\n return {\n ok: true,\n };\n }\n try {\n if (await simpleGit({ baseDir: dir }).checkIsRepo()) {\n await simpleGit({ baseDir: dir }).status();\n const git = simpleGit({ baseDir: dir });\n const branch = await git.branch();\n if (branch.current) {\n return {\n ok: true,\n };\n }\n }\n } catch {\n // Ignore\n }\n return {\n ok: false,\n error: new GitBranchOrEnvironmentRequiredError(),\n };\n }\n}\n\nexport class GitCommitValidator implements ValidationRule<{ dir: string }> {\n async validate(option: { dir: string }): Promise<Result> {\n const { dir } = option;\n try {\n const git = simpleGit({ baseDir: dir });\n const commits = await git.log({ maxCount: 1 });\n if (commits.total === 0) {\n return {\n ok: false,\n error: new NoGitCommits(),\n };\n }\n return { ok: true };\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n } catch (_err) {\n return {\n ok: false,\n error: new NoGitCommits(),\n };\n }\n }\n}\n\nexport class GitBranchValidator implements ValidationRule<{ dir: string }> {\n async validate(option: { dir: string }): Promise<Result> {\n const { dir } = option;\n const git = simpleGit({ baseDir: dir });\n const branch = await git.branch();\n if (!branch.current) {\n return {\n ok: false,\n error: new NotOnAGitBranch(),\n };\n }\n\n return { ok: true };\n }\n}\n\nexport class ZuploProjectValidator implements ValidationRule<{ dir: string }> {\n async validate(options: { dir: string }): Promise<Result> {\n const { dir } = options;\n try {\n if (existsSync(`${dir}/config`)) {\n const files = readdirSync(join(dir, \"config\"));\n const existingOASFiles =\n files.filter((file) => file.endsWith(\".oas.json\")).length >= 1;\n if (existingOASFiles === true) {\n return { ok: true };\n }\n }\n return {\n ok: false,\n error: new NotAZuploProject(),\n };\n } catch (err) {\n return {\n ok: false,\n error: err,\n };\n }\n }\n}\n\nexport class ZuploProjectHasTestsValidator\n implements ValidationRule<{ dir: string }>\n{\n async validate(option: { dir: string }): Promise<Result> {\n const { dir } = option;\n try {\n if (fg.sync(`${dir}/${TEST_IN_FOLDER}/**/*.test.ts`).length >= 1) {\n return { ok: true };\n } else {\n return {\n ok: false,\n error: new ZuploProjectMissingTests(),\n };\n }\n } catch (err) {\n return {\n ok: false,\n error: err,\n };\n }\n }\n}\n\nexport const validDeployDirectoryValidator = new CompositeValidator<{\n dir: string;\n project: string | undefined;\n environment: string | undefined;\n}>(\n new ZuploProjectValidator(),\n new ProjectIsSetValidator(),\n new GitBranchOrEnvironmentValidator()\n);\n\nexport const validTestDirectoryValidator = new CompositeValidator<{\n dir: string;\n}>(new ZuploProjectValidator(), new ZuploProjectHasTestsValidator());\n"]}
|
package/dist/deploy/archive.d.ts
CHANGED
|
@@ -5,13 +5,13 @@ export declare function archive(argv: Arguments): Promise<{
|
|
|
5
5
|
metadata: {
|
|
6
6
|
branch: string;
|
|
7
7
|
repoUrl: string | undefined;
|
|
8
|
-
sha: string;
|
|
8
|
+
sha: string | undefined;
|
|
9
9
|
};
|
|
10
10
|
}>;
|
|
11
11
|
export declare function createIgnoreFunction(normalizedDir: string): any;
|
|
12
12
|
export declare function generateMetadata(argv: Arguments): Promise<{
|
|
13
13
|
branch: string;
|
|
14
14
|
repoUrl: string | undefined;
|
|
15
|
-
sha: string;
|
|
15
|
+
sha: string | undefined;
|
|
16
16
|
}>;
|
|
17
17
|
//# sourceMappingURL=archive.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"archive.d.ts","sourceRoot":"","sources":["../../src/deploy/archive.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC,eAAO,MAAM,iBAAiB,YAAY,CAAC;AAS3C,wBAAsB,OAAO,CAAC,IAAI,EAAE,SAAS;;;;;;;GA6D5C;AAID,wBAAgB,oBAAoB,CAAC,aAAa,EAAE,MAAM,OA2BzD;AAeD,wBAAsB,gBAAgB,CAAC,IAAI,EAAE,SAAS;;;;
|
|
1
|
+
{"version":3,"file":"archive.d.ts","sourceRoot":"","sources":["../../src/deploy/archive.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC,eAAO,MAAM,iBAAiB,YAAY,CAAC;AAS3C,wBAAsB,OAAO,CAAC,IAAI,EAAE,SAAS;;;;;;;GA6D5C;AAID,wBAAgB,oBAAoB,CAAC,aAAa,EAAE,MAAM,OA2BzD;AAeD,wBAAsB,gBAAgB,CAAC,IAAI,EAAE,SAAS;;;;GAmErD"}
|
package/dist/deploy/archive.js
CHANGED
|
@@ -83,11 +83,12 @@ async function prepareDeployerMetadata(argv) {
|
|
|
83
83
|
export async function generateMetadata(argv) {
|
|
84
84
|
const dir = argv.dir;
|
|
85
85
|
const git = simpleGit({ baseDir: dir });
|
|
86
|
+
const isRepo = await git.checkIsRepo();
|
|
86
87
|
let branch;
|
|
87
88
|
if (argv.environment) {
|
|
88
89
|
branch = argv.environment;
|
|
89
90
|
}
|
|
90
|
-
else {
|
|
91
|
+
else if (isRepo) {
|
|
91
92
|
const status = await git.status();
|
|
92
93
|
if (!status.current) {
|
|
93
94
|
throw new Error("Invalid state: Directory is in detached head state.");
|
|
@@ -111,12 +112,16 @@ export async function generateMetadata(argv) {
|
|
|
111
112
|
}
|
|
112
113
|
}
|
|
113
114
|
}
|
|
114
|
-
|
|
115
|
+
else {
|
|
116
|
+
throw new Error("The argument `environment` is required when not in a git repository.");
|
|
117
|
+
}
|
|
118
|
+
let sha;
|
|
115
119
|
let repoUrl;
|
|
116
120
|
if (argv["override-repo-url"]) {
|
|
117
121
|
repoUrl = argv["override-repo-url"];
|
|
118
122
|
}
|
|
119
|
-
else {
|
|
123
|
+
else if (isRepo) {
|
|
124
|
+
sha = (await git.revparse(["HEAD"])).trim();
|
|
120
125
|
try {
|
|
121
126
|
repoUrl = (await git.listRemote(["--get-url"])).trim();
|
|
122
127
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"archive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\"minimatch\";\nimport { randomBytes } from \"node:crypto\";\nimport {\n existsSync,\n mkdirSync,\n readFileSync,\n Stats,\n writeFileSync,\n} from \"node:fs\";\nimport { tmpdir } from \"node:os\";\nimport { join, relative, sep } from \"node:path\";\nimport { simpleGit } from \"simple-git\";\nimport * as tar from \"tar\";\nimport { DEPLOYER_METADATA_FILE } from \"../common/constants.js\";\nimport { logger } from \"../common/logger.js\";\nimport { Arguments } from \"./handler.js\";\n\nexport const ARCHIVE_EXTENSION = \".tar.gz\";\n\nfunction createTempFileWithSuffix(suffix = ARCHIVE_EXTENSION) {\n const tempDir = tmpdir();\n const randomName = randomBytes(16).toString(\"hex\");\n const tempFilePath = join(tempDir, `${randomName}${suffix}`);\n return tempFilePath;\n}\n\nexport async function archive(argv: Arguments) {\n const tarball = createTempFileWithSuffix();\n const dir = argv.dir;\n const ignoreFn = createIgnoreFunction(dir);\n const normalizedDir = join(relative(process.cwd(), dir));\n\n const metadata = await prepareDeployerMetadata(argv);\n\n await tar.create(\n {\n gzip: true,\n file: tarball,\n filter: (path, stat) => {\n const stats = stat as unknown as Stats;\n const normalizedPath = stats.isDirectory()\n ? join(relative(process.cwd(), path), sep) // add / to help the ignore module determine that this is a folder\n : join(relative(process.cwd(), path));\n\n // special case to allow for processing of the root by tar (./)\n if (minimatch(normalizedPath, \"/\", { windowsPathsNoEscape: true })) {\n return true;\n }\n\n if (\n minimatch(normalizedPath, \".zuplo/\", { windowsPathsNoEscape: true })\n ) {\n // Need to return true to allow this to process the entries of the directory\n return true;\n }\n\n if (\n minimatch(normalizedPath, `.zuplo/${DEPLOYER_METADATA_FILE}`, {\n windowsPathsNoEscape: true,\n })\n ) {\n // Now on the second round when it enters the .zuplo folder, we specifically look for this file\n return true;\n }\n\n // We special case the .env files to allow for the self-hosted endpoint to be passed in\n if (normalizedPath === \".env\" || normalizedPath === \".env.zuplo\") {\n if (argv[\"self-hosted-endpoint\"]) {\n return true;\n }\n }\n\n const result = ignoreFn.ignores(normalizedPath);\n logger.trace(`${normalizedPath} ignored: ${result}`);\n\n // The way `tar` interprets true|false is \"opposite\" from ignore\n // When ignore returns true, it means that the .ignore file doesn't want it.\n // When tar return true, it means that we want it.\n return !result;\n },\n },\n [normalizedDir]\n );\n return {\n tarball,\n metadata,\n };\n}\n\n// Note that we do not recursively create an ignore function for each dir\n// We only create one for the top-level of the directory\nexport function createIgnoreFunction(normalizedDir: string) {\n // Most ignore files forget to ignore the .git directory\n\n // Need to do this conversion because of some weird confusion with the d.ts for ignore package in esm\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const baseIgnore = (ignore as any)().add(\".git/\");\n\n if (existsSync(`${normalizedDir}/.zupignore`)) {\n const zupignorePath = `${normalizedDir}/.zupignore`;\n logger.debug(`Using ${zupignorePath} to filter out files`);\n return baseIgnore.add(readFileSync(zupignorePath).toString());\n } else if (existsSync(`${normalizedDir}/.gitignore`)) {\n const gitignorePath = `${normalizedDir}/.gitignore`;\n logger.debug(`Using ${gitignorePath} to filter out files`);\n const gitIgnoreContent = readFileSync(gitignorePath).toString();\n // @NOTE - we should always include the .zuplo folder\n const gitIgnoreContentDotZuploRemoved = gitIgnoreContent.replace(\n /\\.zuplo[/]/,\n \"\"\n );\n return baseIgnore.add(gitIgnoreContentDotZuploRemoved);\n } else {\n logger.debug(\n \"Didn't find a .gitignore or .zupignore file. Defaulting to ignoring .git and node_modules.\"\n );\n return baseIgnore.add(\"node_modules/\");\n }\n}\n\ninterface DeployerMetadata {\n branch: string;\n repoUrl: string | undefined;\n sha: string;\n}\n\nasync function prepareDeployerMetadata(argv: Arguments) {\n const dir = argv.dir;\n const metadata = await generateMetadata(argv);\n await writeGeneratedMetadata(dir, metadata);\n return metadata;\n}\n\nexport async function generateMetadata(argv: Arguments) {\n const dir = argv.dir;\n const git = simpleGit({ baseDir: dir });\n\n let branch: string;\n if (argv.environment) {\n branch = argv.environment;\n } else {\n // Get the current branch from Git\n const status = await git.status();\n if (!status.current) {\n throw new Error(\"Invalid state: Directory is in detached head state.\");\n }\n branch = status.current.trim();\n\n // @NOTE - gitlab returns HEAD as the current branch when running git.status()\n // https://forum.gitlab.com/t/why-i-cant-get-the-branch-name/72462/6\n if (branch === \"HEAD\") {\n // Fetch remote branches to ensure the latest information\n await git.fetch([\"--all\"]);\n\n const branchCommit = await git.branch([\"-a\"]);\n const brancheRef = await git.branch([\n \"-r\",\n \"--contains\",\n branchCommit.current,\n ]);\n if (brancheRef && brancheRef.all && brancheRef.all[0]) {\n const originBranch = brancheRef.all[0];\n const cleanOriginBranch = originBranch.replace(/^origin\\//, \"\");\n if (!cleanOriginBranch) {\n throw new Error(\n \"Invalid state: Directory is in detached head state.\"\n );\n }\n branch = cleanOriginBranch.trim();\n }\n }\n }\n\n // Get the current sha\n const sha = (await git.revparse([\"HEAD\"])).trim();\n\n let repoUrl: string | undefined;\n if (argv[\"override-repo-url\"]) {\n repoUrl = argv[\"override-repo-url\"];\n } else {\n try {\n repoUrl = (await git.listRemote([\"--get-url\"])).trim();\n } catch (err) {\n logger.debug(\n \"Failed to get the remote URL from the git repository. This can happen if there is no remote configured.\"\n );\n repoUrl = undefined;\n }\n }\n\n return {\n branch,\n repoUrl,\n sha,\n };\n}\n\nasync function writeGeneratedMetadata(dir: string, metadata: DeployerMetadata) {\n try {\n mkdirSync(`${dir}/.zuplo`);\n } catch (err) {\n if (err.code === \"EEXIST\") {\n // this is fine, which means that we don't create it and move on\n } else {\n throw err;\n }\n }\n await writeFileSync(\n `${dir}/.zuplo/${DEPLOYER_METADATA_FILE}`,\n JSON.stringify(metadata, null, 2),\n {\n flag: \"w\",\n }\n );\n}\n"]}
|
|
1
|
+
{"version":3,"file":"archive.js","sourceRoot":"","sources":["../../src/deploy/archive.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAC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\nimport { randomBytes } from \"node:crypto\";\nimport {\n existsSync,\n mkdirSync,\n readFileSync,\n Stats,\n writeFileSync,\n} from \"node:fs\";\nimport { tmpdir } from \"node:os\";\nimport { join, relative, sep } from \"node:path\";\nimport { simpleGit } from \"simple-git\";\nimport * as tar from \"tar\";\nimport { DEPLOYER_METADATA_FILE } from \"../common/constants.js\";\nimport { logger } from \"../common/logger.js\";\nimport { Arguments } from \"./handler.js\";\n\nexport const ARCHIVE_EXTENSION = \".tar.gz\";\n\nfunction createTempFileWithSuffix(suffix = ARCHIVE_EXTENSION) {\n const tempDir = tmpdir();\n const randomName = randomBytes(16).toString(\"hex\");\n const tempFilePath = join(tempDir, `${randomName}${suffix}`);\n return tempFilePath;\n}\n\nexport async function archive(argv: Arguments) {\n const tarball = createTempFileWithSuffix();\n const dir = argv.dir;\n const ignoreFn = createIgnoreFunction(dir);\n const normalizedDir = join(relative(process.cwd(), dir));\n\n const metadata = await prepareDeployerMetadata(argv);\n\n await tar.create(\n {\n gzip: true,\n file: tarball,\n filter: (path, stat) => {\n const stats = stat as unknown as Stats;\n const normalizedPath = stats.isDirectory()\n ? join(relative(process.cwd(), path), sep) // add / to help the ignore module determine that this is a folder\n : join(relative(process.cwd(), path));\n\n // special case to allow for processing of the root by tar (./)\n if (minimatch(normalizedPath, \"/\", { windowsPathsNoEscape: true })) {\n return true;\n }\n\n if (\n minimatch(normalizedPath, \".zuplo/\", { windowsPathsNoEscape: true })\n ) {\n // Need to return true to allow this to process the entries of the directory\n return true;\n }\n\n if (\n minimatch(normalizedPath, `.zuplo/${DEPLOYER_METADATA_FILE}`, {\n windowsPathsNoEscape: true,\n })\n ) {\n // Now on the second round when it enters the .zuplo folder, we specifically look for this file\n return true;\n }\n\n // We special case the .env files to allow for the self-hosted endpoint to be passed in\n if (normalizedPath === \".env\" || normalizedPath === \".env.zuplo\") {\n if (argv[\"self-hosted-endpoint\"]) {\n return true;\n }\n }\n\n const result = ignoreFn.ignores(normalizedPath);\n logger.trace(`${normalizedPath} ignored: ${result}`);\n\n // The way `tar` interprets true|false is \"opposite\" from ignore\n // When ignore returns true, it means that the .ignore file doesn't want it.\n // When tar return true, it means that we want it.\n return !result;\n },\n },\n [normalizedDir]\n );\n return {\n tarball,\n metadata,\n };\n}\n\n// Note that we do not recursively create an ignore function for each dir\n// We only create one for the top-level of the directory\nexport function createIgnoreFunction(normalizedDir: string) {\n // Most ignore files forget to ignore the .git directory\n\n // Need to do this conversion because of some weird confusion with the d.ts for ignore package in esm\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const baseIgnore = (ignore as any)().add(\".git/\");\n\n if (existsSync(`${normalizedDir}/.zupignore`)) {\n const zupignorePath = `${normalizedDir}/.zupignore`;\n logger.debug(`Using ${zupignorePath} to filter out files`);\n return baseIgnore.add(readFileSync(zupignorePath).toString());\n } else if (existsSync(`${normalizedDir}/.gitignore`)) {\n const gitignorePath = `${normalizedDir}/.gitignore`;\n logger.debug(`Using ${gitignorePath} to filter out files`);\n const gitIgnoreContent = readFileSync(gitignorePath).toString();\n // @NOTE - we should always include the .zuplo folder\n const gitIgnoreContentDotZuploRemoved = gitIgnoreContent.replace(\n /\\.zuplo[/]/,\n \"\"\n );\n return baseIgnore.add(gitIgnoreContentDotZuploRemoved);\n } else {\n logger.debug(\n \"Didn't find a .gitignore or .zupignore file. Defaulting to ignoring .git and node_modules.\"\n );\n return baseIgnore.add(\"node_modules/\");\n }\n}\n\ninterface DeployerMetadata {\n branch: string;\n repoUrl: string | undefined;\n sha: string | undefined;\n}\n\nasync function prepareDeployerMetadata(argv: Arguments) {\n const dir = argv.dir;\n const metadata = await generateMetadata(argv);\n await writeGeneratedMetadata(dir, metadata);\n return metadata;\n}\n\nexport async function generateMetadata(argv: Arguments) {\n const dir = argv.dir;\n const git = simpleGit({ baseDir: dir });\n\n const isRepo = await git.checkIsRepo();\n let branch: string;\n if (argv.environment) {\n branch = argv.environment;\n } else if (isRepo) {\n // Get the current branch from Git\n const status = await git.status();\n if (!status.current) {\n throw new Error(\"Invalid state: Directory is in detached head state.\");\n }\n branch = status.current.trim();\n\n // @NOTE - gitlab returns HEAD as the current branch when running git.status()\n // https://forum.gitlab.com/t/why-i-cant-get-the-branch-name/72462/6\n if (branch === \"HEAD\") {\n // Fetch remote branches to ensure the latest information\n await git.fetch([\"--all\"]);\n\n const branchCommit = await git.branch([\"-a\"]);\n const brancheRef = await git.branch([\n \"-r\",\n \"--contains\",\n branchCommit.current,\n ]);\n if (brancheRef && brancheRef.all && brancheRef.all[0]) {\n const originBranch = brancheRef.all[0];\n const cleanOriginBranch = originBranch.replace(/^origin\\//, \"\");\n if (!cleanOriginBranch) {\n throw new Error(\n \"Invalid state: Directory is in detached head state.\"\n );\n }\n branch = cleanOriginBranch.trim();\n }\n }\n } else {\n throw new Error(\n \"The argument `environment` is required when not in a git repository.\"\n );\n }\n\n // Get the current sha\n let sha: string | undefined;\n let repoUrl: string | undefined;\n if (argv[\"override-repo-url\"]) {\n repoUrl = argv[\"override-repo-url\"];\n } else if (isRepo) {\n sha = (await git.revparse([\"HEAD\"])).trim();\n try {\n repoUrl = (await git.listRemote([\"--get-url\"])).trim();\n } catch (err) {\n logger.debug(\n \"Failed to get the remote URL from the git repository. This can happen if there is no remote configured.\"\n );\n repoUrl = undefined;\n }\n }\n\n return {\n branch,\n repoUrl,\n sha,\n };\n}\n\nasync function writeGeneratedMetadata(dir: string, metadata: DeployerMetadata) {\n try {\n mkdirSync(`${dir}/.zuplo`);\n } catch (err) {\n if (err.code === \"EEXIST\") {\n // this is fine, which means that we don't create it and move on\n } else {\n throw err;\n }\n }\n await writeFileSync(\n `${dir}/.zuplo/${DEPLOYER_METADATA_FILE}`,\n JSON.stringify(metadata, null, 2),\n {\n flag: \"w\",\n }\n );\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zuplo/cli",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.26.0",
|
|
4
4
|
"repository": "https://github.com/zuplo/zuplo",
|
|
5
5
|
"author": "Zuplo, Inc.",
|
|
6
6
|
"type": "module",
|
|
@@ -29,8 +29,8 @@
|
|
|
29
29
|
"@opentelemetry/api": "^1.8.0",
|
|
30
30
|
"@sentry/node": "^8.47.0",
|
|
31
31
|
"@swc/core": "1.7.22",
|
|
32
|
-
"@zuplo/core": "^6.
|
|
33
|
-
"@zuplo/runtime": "^6.
|
|
32
|
+
"@zuplo/core": "^6.26.0",
|
|
33
|
+
"@zuplo/runtime": "^6.26.0",
|
|
34
34
|
"as-table": "^1.0.55",
|
|
35
35
|
"chalk": "^5.3.0",
|
|
36
36
|
"chokidar": "^3.5.3",
|