@metacall/protocol 0.1.16 → 0.1.17

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metacall/protocol",
3
- "version": "0.1.16",
3
+ "version": "0.1.17",
4
4
  "description": "Tool for deploying into MetaCall FaaS platform.",
5
5
  "exports": {
6
6
  "./*": "./dist/*.js",
@@ -17,7 +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
+ "postinstall": "node -e \"require('fs').existsSync('githooks') && require('./githooks/configure.js').configure()\"",
21
21
  "build": "npm run --silent lint && tsc",
22
22
  "lint": "eslint . --ignore-pattern dist",
23
23
  "fix": "eslint . --ignore-pattern dist --fix",
@@ -78,10 +78,7 @@
78
78
  },
79
79
  "rules": {
80
80
  "tsdoc/syntax": "warn"
81
- },
82
- "ignorePatterns": [
83
- "githooks/common.js"
84
- ]
81
+ }
85
82
  },
86
83
  "dependencies": {
87
84
  "@types/ignore-walk": "^4.0.0",
@@ -1,37 +0,0 @@
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
- };
package/githooks/pre-push DELETED
@@ -1,18 +0,0 @@
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
- }
@@ -1,109 +0,0 @@
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
- }