@metacall/protocol 0.1.12 → 0.1.15

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.
@@ -9,5 +9,5 @@ interface Language {
9
9
  }
10
10
  export declare const Languages: Record<LanguageId, Language>;
11
11
  export declare const DisplayNameToLanguageId: Record<string, LanguageId>;
12
- export declare const runnerDisplayName: (runner: string) => string;
12
+ export declare const RunnerToDisplayName: (runner: string) => string;
13
13
  export {};
package/dist/language.js CHANGED
@@ -6,13 +6,7 @@
6
6
 
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.runnerDisplayName = exports.DisplayNameToLanguageId = exports.Languages = void 0;
10
- const displayNameMap = {
11
- nodejs: 'NPM',
12
- python: 'PIP',
13
- ruby: 'GEM',
14
- csharp: 'NuGet'
15
- };
9
+ exports.RunnerToDisplayName = exports.DisplayNameToLanguageId = exports.Languages = void 0;
16
10
  exports.Languages = {
17
11
  cs: {
18
12
  tag: 'cs',
@@ -82,5 +76,13 @@ exports.Languages = {
82
76
  exports.DisplayNameToLanguageId = Object.keys(exports.Languages).reduce((obj, lang) => Object.assign(obj, {
83
77
  [exports.Languages[lang].displayName]: lang
84
78
  }), {});
85
- const runnerDisplayName = (runner) => displayNameMap[runner] || 'Deploy';
86
- exports.runnerDisplayName = runnerDisplayName;
79
+ const RunnerToDisplayName = (runner) => {
80
+ const displayNameMap = {
81
+ nodejs: 'NPM',
82
+ python: 'Pip',
83
+ ruby: 'Gem',
84
+ csharp: 'NuGet'
85
+ };
86
+ return displayNameMap[runner] || 'Build';
87
+ };
88
+ exports.RunnerToDisplayName = RunnerToDisplayName;
@@ -4,6 +4,12 @@ import { Plans } from './plan';
4
4
  export declare const isProtocolError: (err: unknown) => boolean;
5
5
  export { AxiosError as ProtocolError };
6
6
  declare type SubscriptionMap = Record<string, number>;
7
+ export interface SubscriptionDeploy {
8
+ id: string;
9
+ plan: Plans;
10
+ date: number;
11
+ deploy: string;
12
+ }
7
13
  export declare type ResourceType = 'Package' | 'Repository';
8
14
  export interface AddResponse {
9
15
  id: string;
@@ -16,6 +22,7 @@ interface API {
16
22
  validate(): Promise<boolean>;
17
23
  deployEnabled(): Promise<boolean>;
18
24
  listSubscriptions(): Promise<SubscriptionMap>;
25
+ listSubscriptionsDeploys(): Promise<SubscriptionDeploy[]>;
19
26
  inspect(): Promise<Deployment[]>;
20
27
  upload(name: string, blob: unknown, jsons: MetaCallJSON[], runners: string[]): Promise<string>;
21
28
  add(url: string, branch: string, jsons: MetaCallJSON[]): Promise<AddResponse>;
package/dist/protocol.js CHANGED
@@ -9,11 +9,14 @@
9
9
  validate: validates the auth token
10
10
  deployEnabled: checks if you're able to deploy
11
11
  listSubscriptions: gives you a list of the subscription available
12
+ listSubscriptionsDeploys: gives you a list of the subscription being used in deploys
12
13
  inspect: gives you are deploys with it's endpoints
13
14
  upload: uploads a zip (package) into the faas
14
15
  deploy: deploys the previously uploaded zip into the faas
15
16
  deployDelete: deletes the deploy and the zip
16
-
17
+ logs: retrieve the logs of a deploy by runner or deployment
18
+ branchList: get the branches of a repository
19
+ fileList: get files of a repository by branch
17
20
  */
18
21
  var __importDefault = (this && this.__importDefault) || function (mod) {
19
22
  return (mod && mod.__esModule) ? mod : { "default": mod };
@@ -57,6 +60,11 @@ exports.default = (token, baseURL) => {
57
60
  }
58
61
  return subscriptions;
59
62
  },
63
+ listSubscriptionsDeploys: async () => axios_1.default
64
+ .get(baseURL + '/api/billing/list-subscriptions-deploys', {
65
+ headers: { Authorization: 'jwt ' + token }
66
+ })
67
+ .then(res => res.data),
60
68
  inspect: async () => axios_1.default
61
69
  .get(baseURL + '/api/inspect', {
62
70
  headers: { Authorization: 'jwt ' + token }
@@ -0,0 +1,37 @@
1
+ const { spawn } = require('child_process');
2
+
3
+ const debug = !!process.env.DEBUG_HOOKS;
4
+ const debugLog = debug ? ((...params) => console.log(...params)) : (() => {});
5
+
6
+ const run = (cmd, args = [], config = {}) => new Promise((ok, nope) => {
7
+ const child = spawn(cmd, args, config);
8
+
9
+ let stderr = '';
10
+ let stdout = '';
11
+
12
+ child.stderr.on('data', data => {
13
+ stderr += data
14
+ debugLog('> stderr:', data.toString().trim());
15
+ });
16
+ child.stdout.on('data', data => {
17
+ stdout += data
18
+ debugLog('> stdout:', data.toString().trim());
19
+ });
20
+ child.on('close', (code, signal) => {
21
+ if (code !== 0) {
22
+ console.error('Exited with code', code);
23
+ return nope({
24
+ message: stderr,
25
+ exit: code,
26
+ data: { code, signal, stderr, stdout, child }
27
+ });
28
+ }
29
+ ok({ code, signal, stderr, stdout, child });
30
+ });
31
+ });
32
+
33
+ module.exports = {
34
+ debug,
35
+ debugLog,
36
+ run
37
+ };
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env node
2
+
3
+ const { debugLog } = require('./common');
4
+
5
+ const PREFIX = 'pre-push';
6
+
7
+ const hooks = [
8
+ 'update-version'
9
+ ];
10
+
11
+ if (require.main === module) {
12
+ for (const hook of hooks) {
13
+ const filename = PREFIX + '-' + hook;
14
+ debugLog('Executing hook:', filename);
15
+ const { main } = require('./' + filename);
16
+ main(process.argv.slice(2));
17
+ }
18
+ }
@@ -0,0 +1,109 @@
1
+ #!/usr/bin/env node
2
+
3
+ const path = require('path');
4
+ const fs = require('fs');
5
+
6
+ const { debugLog, run } = require('./common');
7
+
8
+ const main = async (args) => {
9
+ let resp;
10
+ try {
11
+ /*
12
+ // Not needed: https://stackoverflow.com/a/37927943/12547142
13
+
14
+ const cwd = process.cwd();
15
+ debugLog('Current working directory:', cwd);
16
+
17
+ resp = await run('git', ['rev-parse', '--show-toplevel']);
18
+ const root = resp.stdout.trim();
19
+ debugLog('Repository root directory:', root);
20
+
21
+ // Ensuring the current working directory is at the repository root
22
+ // ...
23
+ */
24
+
25
+ const root = process.cwd();
26
+
27
+ debugLog('Inside update-version hook.');
28
+ debugLog('Command-line arguments:', args);
29
+
30
+ const remoteName = args[0];
31
+ debugLog('Remote:', remoteName);
32
+
33
+ debugLog('Fetching tags...');
34
+ await run('git', ['fetch', '--tags', remoteName]);
35
+
36
+ debugLog('Retrieving the latest tag version...');
37
+ resp = await run('git', ['rev-list', '--tags', '--max-count=1']);
38
+ const latestTagCommit = resp.stdout.trim();
39
+ debugLog('Latest tag commit hash:', latestTagCommit);
40
+
41
+ resp = await run('git', ['describe', '--tags', latestTagCommit]);
42
+ const latestTag = resp.stdout.trim();
43
+ debugLog('Latest tag:', latestTag);
44
+ const latestVersion = latestTag.slice(1);
45
+ debugLog('=> Latest version:', latestVersion);
46
+
47
+
48
+ debugLog('Retrieving the version from package.json...');
49
+ const package = require('../package.json');
50
+ const lockfile = require('../package-lock.json');
51
+ const { version: packageVersion } = package;
52
+ const { version: lockfileVersion } = lockfile;
53
+ const { packages: { '': { version: lockfileVersion2 } } } = lockfile;
54
+ debugLog('package.json version:', packageVersion);
55
+ debugLog('package-lock.json version:', lockfileVersion);
56
+ debugLog('package-lock.json version (repeated):', lockfileVersion2);
57
+
58
+ let success = latestVersion === packageVersion && latestVersion === lockfileVersion && latestVersion === lockfileVersion2;
59
+
60
+ if (success) {
61
+ debugLog('Versions match. No update needed.');
62
+ } else {
63
+ await run('git', ['tag', '-d', latestTag]);
64
+ debugLog('Versions donn\'t match. Updating versions.');
65
+ if (packageVersion !== latestVersion) {
66
+ console.log('Updating package.json with version from latest tag...');
67
+ package.version = latestVersion;
68
+ fs.writeFileSync(path.join(root, 'package.json'), JSON.stringify(package, null, '\t'));
69
+ debugLog('Updated package.json.');
70
+ }
71
+ if (lockfileVersion !== latestVersion) {
72
+ console.log('Updating package-lock.json with version from latest tag...');
73
+ lockfile.version = latestVersion;
74
+ fs.writeFileSync(path.join(root, 'package-lock.json'), JSON.stringify(lockfile, null, '\t'));
75
+ debugLog('Updated package-lock.json.');
76
+ }
77
+ if (lockfileVersion2 !== latestVersion) {
78
+ console.log('Updating package-lock.json (repeated) with version from latest tag...');
79
+ lockfile.packages[''].version = latestVersion;
80
+ fs.writeFileSync(path.join(root, 'package-lock.json'), JSON.stringify(lockfile, null, '\t'));
81
+ debugLog('Updated package-lock.json (repeated).');
82
+ }
83
+ debugLog('Updated versions.');
84
+ await run('git', ['add', 'package.json']);
85
+ await run('git', ['add', 'package-lock.json']);
86
+ await run('git', ['commit', '-m', 'Updating version to ' + latestTag]);
87
+ await run('git', ['tag', latestTag]);
88
+
89
+ resp = await run('git', ['rev-parse', '--abbrev-ref', 'HEAD']);
90
+ const currentBranch = resp.stdout.trim();
91
+ debugLog('Current branch:', currentBranch);
92
+
93
+ process.stderr.write('\033[0;31mYour push has been rejected in order to update the versions in package.json and package-lock.json according to the latest tag.\033[0m\n');
94
+ process.stderr.write('\033[0;32mPush again with: \033[0mgit push ' + remoteName + ' ' + currentBranch + ' ' + latestTag + '\n');
95
+ }
96
+ return process.exit(success ? 0 : 1);
97
+ } catch (e) {
98
+ e && e.data && e.data.signal && debugLog('Signal:', e.data.signal);
99
+ e && e.data && e.data.stdout && debugLog('stdout:', '\n----------------------', e.data.stdout, '\n----------------------');
100
+ console.error(e.message);
101
+ process.exit(e.exit);
102
+ }
103
+ };
104
+
105
+ module.exports = { main };
106
+
107
+ if (require.main === module) {
108
+ main(process.argv.slice(2));
109
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metacall/protocol",
3
- "version": "0.1.12",
3
+ "version": "0.1.15",
4
4
  "description": "Tool for deploying into MetaCall FaaS platform.",
5
5
  "exports": {
6
6
  "./*": "./dist/*.js",
@@ -17,6 +17,7 @@
17
17
  "test": "npm run --silent build && mocha dist/test",
18
18
  "unit": "npm run --silent test -- --ignore **/integration**",
19
19
  "prepublishOnly": "npm run --silent build",
20
+ "postinstall": "git config --local core.hooksPath githooks",
20
21
  "build": "npm run --silent lint && tsc",
21
22
  "lint": "eslint . --ignore-pattern dist",
22
23
  "fix": "eslint . --ignore-pattern dist --fix",
@@ -77,7 +78,10 @@
77
78
  },
78
79
  "rules": {
79
80
  "tsdoc/syntax": "warn"
80
- }
81
+ },
82
+ "ignorePatterns": [
83
+ "githooks/common.js"
84
+ ]
81
85
  },
82
86
  "dependencies": {
83
87
  "@types/ignore-walk": "^4.0.0",
package/src/language.ts CHANGED
@@ -16,13 +16,6 @@ interface Language {
16
16
  runnerFilesRegexes: RegExp[]; // Regex for generating the runners list
17
17
  }
18
18
 
19
- const displayNameMap: Record<string, string> = {
20
- nodejs: 'NPM',
21
- python: 'PIP',
22
- ruby: 'GEM',
23
- csharp: 'NuGet'
24
- };
25
-
26
19
  export const Languages: Record<LanguageId, Language> = {
27
20
  cs: {
28
21
  tag: 'cs',
@@ -100,5 +93,13 @@ export const DisplayNameToLanguageId: Record<string, LanguageId> = Object.keys(
100
93
  {}
101
94
  );
102
95
 
103
- export const runnerDisplayName = (runner: string): string =>
104
- displayNameMap[runner] || 'Deploy';
96
+ export const RunnerToDisplayName = (runner: string): string => {
97
+ const displayNameMap: Record<string, string> = {
98
+ nodejs: 'NPM',
99
+ python: 'Pip',
100
+ ruby: 'Gem',
101
+ csharp: 'NuGet'
102
+ };
103
+
104
+ return displayNameMap[runner] || 'Build';
105
+ };
package/src/protocol.ts CHANGED
@@ -8,11 +8,14 @@
8
8
  validate: validates the auth token
9
9
  deployEnabled: checks if you're able to deploy
10
10
  listSubscriptions: gives you a list of the subscription available
11
+ listSubscriptionsDeploys: gives you a list of the subscription being used in deploys
11
12
  inspect: gives you are deploys with it's endpoints
12
13
  upload: uploads a zip (package) into the faas
13
14
  deploy: deploys the previously uploaded zip into the faas
14
15
  deployDelete: deletes the deploy and the zip
15
-
16
+ logs: retrieve the logs of a deploy by runner or deployment
17
+ branchList: get the branches of a repository
18
+ fileList: get files of a repository by branch
16
19
  */
17
20
 
18
21
  import axios, { AxiosError, AxiosResponse } from 'axios';
@@ -27,6 +30,13 @@ export { AxiosError as ProtocolError };
27
30
 
28
31
  type SubscriptionMap = Record<string, number>;
29
32
 
33
+ export interface SubscriptionDeploy {
34
+ id: string;
35
+ plan: Plans;
36
+ date: number;
37
+ deploy: string;
38
+ }
39
+
30
40
  export type ResourceType = 'Package' | 'Repository';
31
41
 
32
42
  export interface AddResponse {
@@ -42,6 +52,7 @@ interface API {
42
52
  validate(): Promise<boolean>;
43
53
  deployEnabled(): Promise<boolean>;
44
54
  listSubscriptions(): Promise<SubscriptionMap>;
55
+ listSubscriptionsDeploys(): Promise<SubscriptionDeploy[]>;
45
56
  inspect(): Promise<Deployment[]>;
46
57
  upload(
47
58
  name: string,
@@ -122,6 +133,16 @@ export default (token: string, baseURL: string): API => {
122
133
  return subscriptions;
123
134
  },
124
135
 
136
+ listSubscriptionsDeploys: async (): Promise<SubscriptionDeploy[]> =>
137
+ axios
138
+ .get<SubscriptionDeploy[]>(
139
+ baseURL + '/api/billing/list-subscriptions-deploys',
140
+ {
141
+ headers: { Authorization: 'jwt ' + token }
142
+ }
143
+ )
144
+ .then(res => res.data),
145
+
125
146
  inspect: async (): Promise<Deployment[]> =>
126
147
  axios
127
148
  .get<Deployment[]>(baseURL + '/api/inspect', {