@zuplo/cli 6.23.0 → 6.25.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.
@@ -14,9 +14,6 @@ export declare class NoGitCommits extends Error {
14
14
  export declare class NotOnAGitBranch extends Error {
15
15
  constructor();
16
16
  }
17
- export declare class MissingGitRemote extends Error {
18
- constructor();
19
- }
20
17
  export declare class GitVersionControlValidator implements ValidationRule<{
21
18
  dir: string;
22
19
  }> {
@@ -38,13 +35,6 @@ export declare class GitBranchValidator implements ValidationRule<{
38
35
  dir: string;
39
36
  }): Promise<Result>;
40
37
  }
41
- export declare class GitRemoteValidator implements ValidationRule<{
42
- dir: string;
43
- }> {
44
- validate(option: {
45
- dir: string;
46
- }): Promise<Result>;
47
- }
48
38
  export declare class ZuploProjectValidator implements ValidationRule<{
49
39
  dir: string;
50
40
  }> {
@@ -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,gBAAiB,SAAQ,KAAK;;CAO1C;AAED,qBAAa,0BACX,YAAW,cAAc,CAAC;IAAE,GAAG,EAAE,MAAM,CAAA;CAAE,CAAC;IAEpC,QAAQ,CAAC,MAAM,EAAE;QAAE,GAAG,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,MAAM,CAAC;CAazD;AAED,qBAAa,kBAAmB,YAAW,cAAc,CAAC;IAAE,GAAG,EAAE,MAAM,CAAA;CAAE,CA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OnAGitBranch.prototype);
36
36
  }
37
37
  }
38
- export class MissingGitRemote extends Error {
39
- constructor() {
40
- super("Invalid Git state: You do not have a remote origin configured. Run `git remote add origin <url>` to add the url of Git repository matching your project on Zuplo.");
41
- Object.setPrototypeOf(this, MissingGitRemote.prototype);
42
- }
43
- }
44
38
  export class GitVersionControlValidator {
45
39
  async validate(option) {
46
40
  const { dir } = option;
@@ -92,21 +86,6 @@ export class GitBranchValidator {
92
86
  return { ok: true };
93
87
  }
94
88
  }
95
- export class GitRemoteValidator {
96
- async validate(option) {
97
- const { dir } = option;
98
- const git = simpleGit({ baseDir: dir });
99
- const remotes = await git.getRemotes(true);
100
- const origin = remotes.find((r) => r.name === "origin");
101
- if (!origin) {
102
- return {
103
- ok: false,
104
- error: new MissingGitRemote(),
105
- };
106
- }
107
- return { ok: true };
108
- }
109
- }
110
89
  export class ZuploProjectValidator {
111
90
  async validate(options) {
112
91
  const { dir } = options;
@@ -153,6 +132,6 @@ export class ZuploProjectHasTestsValidator {
153
132
  }
154
133
  }
155
134
  }
156
- export const validDeployDirectoryValidator = new CompositeValidator(new ZuploProjectValidator(), new GitVersionControlValidator(), new GitCommitValidator(), new GitBranchValidator(), new GitRemoteValidator(), new ProjectIsSetValidator());
135
+ export const validDeployDirectoryValidator = new CompositeValidator(new ZuploProjectValidator(), new GitVersionControlValidator(), new GitCommitValidator(), new GitBranchValidator(), new ProjectIsSetValidator());
157
136
  export const validTestDirectoryValidator = new CompositeValidator(new ZuploProjectValidator(), new ZuploProjectHasTestsValidator());
158
137
  //# sourceMappingURL=file-system-validator.js.map
@@ -1 +1 @@
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,OA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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 MissingGitRemote extends Error {\n constructor() {\n super(\n \"Invalid Git state: You do not have a remote origin configured. Run `git remote add origin <url>` to add the url of Git repository matching your project on Zuplo.\"\n );\n Object.setPrototypeOf(this, MissingGitRemote.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 GitRemoteValidator implements ValidationRule<{ dir: string }> {\n async validate(option: { dir: string }): Promise<Result> {\n const { dir } = option;\n const git = simpleGit({ baseDir: dir });\n const remotes = await git.getRemotes(true);\n const origin = remotes.find((r) => r.name === \"origin\");\n if (!origin) {\n return {\n ok: false,\n error: new MissingGitRemote(),\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 GitRemoteValidator(),\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,gBAAiB,SAAQ,KAAK;IACzC;QACE,KAAK,CAAC,mEAAmE,CAAC,CAAC;QAC3E,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,gBAAgB,CAAC,SAAS,CAAC,CAAC;IAC1D,CAAC;CACF;AAED,MAAM,OAAO,gBAAiB,SAAQ,KAAK;IACzC;QACE,KAAK,CACH,8EAA8E,CAC/E,CAAC;QACF,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,gBAAgB,CAAC,SAAS,CAAC,CAAC;IAC1D,CAAC;CACF;AAED,MAAM,OAAO,wBAAyB,SAAQ,KAAK;I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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"]}
@@ -4,14 +4,14 @@ export declare function archive(argv: Arguments): Promise<{
4
4
  tarball: string;
5
5
  metadata: {
6
6
  branch: string;
7
- repoUrl: string;
7
+ repoUrl: string | undefined;
8
8
  sha: string;
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
- repoUrl: string;
14
+ repoUrl: string | undefined;
15
15
  sha: string;
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;;;;GAoDrD"}
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;;;;GA8DrD"}
@@ -112,9 +112,19 @@ export async function generateMetadata(argv) {
112
112
  }
113
113
  }
114
114
  const sha = (await git.revparse(["HEAD"])).trim();
115
- const repoUrl = argv["override-repo-url"]
116
- ? argv["override-repo-url"]
117
- : (await git.listRemote(["--get-url"])).trim();
115
+ let repoUrl;
116
+ if (argv["override-repo-url"]) {
117
+ repoUrl = argv["override-repo-url"];
118
+ }
119
+ else {
120
+ try {
121
+ repoUrl = (await git.listRemote(["--get-url"])).trim();
122
+ }
123
+ catch (err) {
124
+ logger.debug("Failed to get the remote URL from the git repository. This can happen if there is no remote configured.");
125
+ repoUrl = undefined;
126
+ }
127
+ }
118
128
  return {
119
129
  branch,
120
130
  repoUrl,
@@ -1 +1 @@
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,EACL,UAAU,EACV,SAAS,EACT,YAAY,EAEZ,aAAa,GACd,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAChD,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,KAAK,GAAG,MAAM,KAAK,CAAC;AAC3B,OAAO,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAC;AAChE,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAG7C,MAAM,CAAC,MAAM,iBAAiB,GAAG,SAAS,CAAC;AAE3C,SAAS,wBAAwB,CAAC,MAAM,GAAG,iBAAiB;IAC1D,MAAM,OAAO,GAAG,MAAM,EAAE,CAAC;IACzB,MAAM,UAAU,GAAG,WAAW,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IACnD,MAAM,YAAY,GAAG,IAAI,CAAC,OAAO,EAAE,GAAG,UAAU,GAAG,MAAM,EAAE,CAAC,CAAC;IAC7D,OAAO,YAAY,CAAC;AACtB,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,OAAO,CAAC,IAAe;IAC3C,MAAM,OAAO,GAAG,wBAAwB,EAAE,CAAC;IAC3C,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC;IACrB,MAAM,QAAQ,GA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,iBAAiB,GAAG,YAAY,CAAC,OAAO,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;gBAChE,IAAI,CAAC,iBAAiB,EAAE,CAAC;oBACvB,MAAM,IAAI,KAAK,CACb,qDAAqD,CACtD,CAAC;gBACJ,CAAC;gBACD,MAAM,GAAG,iBAAiB,CAAC,IAAI,EAAE,CAAC;YACpC,CAAC;QACH,CAAC;IACH,CAAC;IAGD,MAAM,GAAG,GAAG,CAAC,MAAM,GAAG,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;IAElD,MAAM,OAAO,GAAG,IAAI,CAAC,mBAAmB,CAAC;QACvC,CAAC,CAAC,IAAI,CAAC,mBAAmB,CAAC;QAC3B,CAAC,CAAC,CAAC,MAAM,GAAG,CAAC,UAAU,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;IAEjD,OAAO;QACL,MAAM;QACN,OAAO;QACP,GAAG;KACJ,CAAC;AACJ,CAAC;AAED,KAAK,UAAU,sBAAsB,CAAC,GAAW,EAAE,QAA0B;IAC3E,IAAI,CAAC;QACH,SAAS,CAAC,GAAG,GAAG,SAAS,CAAC,CAAC;IAC7B,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,IAAI,GAAG,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;QAE5B,CAAC;aAAM,CAAC;YACN,MAAM,GAAG,CAAC;QACZ,CAAC;IACH,CAAC;IACD,MAAM,aAAa,CACjB,GAAG,GAAG,WAAW,sBAAsB,EAAE,EACzC,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC,EACjC;QACE,IAAI,EAAE,GAAG;KACV,CACF,CAAC;AACJ,CAAC","sourcesContent":["import ignore from \"ignore\";\nimport { minimatch } from \"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;\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 const repoUrl = argv[\"override-repo-url\"]\n ? argv[\"override-repo-url\"]\n : (await git.listRemote([\"--get-url\"])).trim();\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,EACL,UAAU,EACV,SAAS,EACT,YAAY,EAEZ,aAAa,GACd,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAChD,OAAO,EAAE,SAAS,EAAE,M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AO,GAAG,CAAC,MAAM,GAAG,CAAC,UAAU,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;QACzD,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,MAAM,CAAC,KAAK,CACV,yGAAyG,CAC1G,CAAC;YACF,OAAO,GAAG,SAAS,CAAC;QACtB,CAAC;IACH,CAAC;IAED,OAAO;QACL,MAAM;QACN,OAAO;QACP,GAAG;KACJ,CAAC;AACJ,CAAC;AAED,KAAK,UAAU,sBAAsB,CAAC,GAAW,EAAE,QAA0B;IAC3E,IAAI,CAAC;QACH,SAAS,CAAC,GAAG,GAAG,SAAS,CAAC,CAAC;IAC7B,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,IAAI,GAAG,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;QAE5B,CAAC;aAAM,CAAC;YACN,MAAM,GAAG,CAAC;QACZ,CAAC;IACH,CAAC;IACD,MAAM,aAAa,CACjB,GAAG,GAAG,WAAW,sBAAsB,EAAE,EACzC,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC,EACjC;QACE,IAAI,EAAE,GAAG;KACV,CACF,CAAC;AACJ,CAAC","sourcesContent":["import ignore from \"ignore\";\nimport { minimatch } from \"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"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zuplo/cli",
3
- "version": "6.23.0",
3
+ "version": "6.25.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": "^7.119.2",
31
31
  "@swc/core": "1.7.22",
32
- "@zuplo/core": "^6.23.0",
33
- "@zuplo/runtime": "^6.23.0",
32
+ "@zuplo/core": "^6.25.0",
33
+ "@zuplo/runtime": "^6.25.0",
34
34
  "as-table": "^1.0.55",
35
35
  "chalk": "^5.3.0",
36
36
  "chokidar": "^3.5.3",