@govuk-pay/cli 0.0.2-rc.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/bin/cli.js +19 -0
- package/package.json +21 -0
- package/readme.md +30 -0
- package/resources/header.txt +9 -0
- package/resources/usageDetails.txt +11 -0
- package/src/commands/browse.js +95 -0
- package/src/commands/browse.spec.js +81 -0
- package/src/commands/demo.js +11 -0
- package/src/commands/help.js +15 -0
- package/src/commands/legacy.js +70 -0
- package/src/core/commandRouter.js +81 -0
- package/src/core/constants.js +38 -0
- package/src/core/standardContent.js +37 -0
- package/src/util/moduleFunctionWrapper.js +7 -0
- package/src/util/payCliExec.js +88 -0
package/bin/cli.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
+
};
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
const commandRouter_js_1 = __importDefault(require("../src/core/commandRouter.js"));
|
|
8
|
+
(async () => {
|
|
9
|
+
try {
|
|
10
|
+
await (0, commandRouter_js_1.default)();
|
|
11
|
+
}
|
|
12
|
+
catch (e) {
|
|
13
|
+
console.error('Error executing command:');
|
|
14
|
+
console.error(e);
|
|
15
|
+
}
|
|
16
|
+
})()
|
|
17
|
+
.catch((e) => {
|
|
18
|
+
throw e;
|
|
19
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@govuk-pay/cli",
|
|
3
|
+
"version": "0.0.2-rc.0",
|
|
4
|
+
"description": "GOV.UK Pay Command Line Interface",
|
|
5
|
+
"bin": {
|
|
6
|
+
"pay": "bin/cli.js",
|
|
7
|
+
"payx": "bin/cli.js",
|
|
8
|
+
"@govuk-pay/cli": "bin/cli.js"
|
|
9
|
+
},
|
|
10
|
+
"keywords": [],
|
|
11
|
+
"author": "",
|
|
12
|
+
"license": "MIT",
|
|
13
|
+
"dependencies": {
|
|
14
|
+
"openurl": "^1.1.1",
|
|
15
|
+
"ts-standard": "^12.0.2"
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"resources",
|
|
19
|
+
"src"
|
|
20
|
+
]
|
|
21
|
+
}
|
package/readme.md
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# pay-cli
|
|
2
|
+
GOV.UK Pay Command Line Interface
|
|
3
|
+
|
|
4
|
+
## Usage
|
|
5
|
+
|
|
6
|
+
This is published to NPM, you can install it globally using `npm install -g @govuk-pay/cli`,
|
|
7
|
+
once it's installed you can run it using `pay [arguments]` or `payx [arguments]`.
|
|
8
|
+
If you'd rather not install it globally you can run it using `npx @govuk-pay/cli`.
|
|
9
|
+
|
|
10
|
+
We're in the process of porting the existing Ruby CLI into typescript, we've tried to make that process
|
|
11
|
+
transparent to the users of the CLI. Most of the commands rely on the existing ruby implementation therefore
|
|
12
|
+
you'll need `rbenv` installed with `bundler` installed into it. When handing over to ruby we use `zsh` by default,
|
|
13
|
+
if you want a different shell or `rbenv` you can set the following environment variables:
|
|
14
|
+
|
|
15
|
+
- `PAY_CLI_RBENV_COMMAND` - defaults to `rbenv`
|
|
16
|
+
- `PAY_CLI_SHELL_COMMAND` - defaults to `zsh`
|
|
17
|
+
|
|
18
|
+
To see the commands run `pay` without any arguments.
|
|
19
|
+
|
|
20
|
+
If you find that the ported typescript version isn't behaving as expected and you want to use the ruby version you can
|
|
21
|
+
use the command `legacy`, for example:
|
|
22
|
+
|
|
23
|
+
- `pay browse manual` - uses the typescript port to open the team manual
|
|
24
|
+
- `pay legacy browse manual` - uses the original ruby version to open the team manual
|
|
25
|
+
|
|
26
|
+
Please add an issue any time you need to fall back on legacy behaviour so we can improve the typescript implementation.
|
|
27
|
+
|
|
28
|
+
## Vulnerability Disclosure
|
|
29
|
+
|
|
30
|
+
GOV.UK Pay aims to stay secure for everyone. If you are a security researcher and have discovered a security vulnerability in this code, we appreciate your help in disclosing it to us in a responsible manner. Please refer to our [vulnerability disclosure policy](https://www.gov.uk/help/report-vulnerability) and our [security.txt](https://vdp.cabinetoffice.gov.uk/.well-known/security.txt) file for details.
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
Commands:
|
|
2
|
+
pay aws # Interactions with AWS, e.g. fetching STS tokens
|
|
3
|
+
pay browse # Opens web browser link to useful links
|
|
4
|
+
pay deployment_status <env> # Describe what's deployed
|
|
5
|
+
pay doctor # Attempts to initialise or fix the Pay CLI
|
|
6
|
+
pay help [COMMAND] # Describe available commands or one specific ...
|
|
7
|
+
pay local # Sets up local Pay development environment
|
|
8
|
+
pay schema # Generates web based database diagrams and me...
|
|
9
|
+
pay secrets # Manage secrets in and between environments
|
|
10
|
+
pay ssm # Start an SSM session to boxes in environments
|
|
11
|
+
pay tf # Runs Terraform
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.logBrowseCommands = void 0;
|
|
27
|
+
const path = __importStar(require("path"));
|
|
28
|
+
const standardContent_js_1 = require("../core/standardContent.js");
|
|
29
|
+
const constants_js_1 = require("../core/constants.js");
|
|
30
|
+
const moduleFunctionWrapper_js_1 = require("../util/moduleFunctionWrapper.js");
|
|
31
|
+
const requestableItems = new Map();
|
|
32
|
+
requestableItems.set('concourse', {
|
|
33
|
+
name: 'concourse page',
|
|
34
|
+
url: 'https://pay-cd.deploy.payments.service.gov.uk/'
|
|
35
|
+
});
|
|
36
|
+
requestableItems.set('manual', {
|
|
37
|
+
name: 'team manual',
|
|
38
|
+
url: 'https://manual.payments.service.gov.uk/'
|
|
39
|
+
});
|
|
40
|
+
requestableItems.set('repo', {
|
|
41
|
+
name: 'pay-infra github repository',
|
|
42
|
+
url: 'https://github.com/alphagov/pay-infra'
|
|
43
|
+
});
|
|
44
|
+
requestableItems.set('status', {
|
|
45
|
+
name: 'status page',
|
|
46
|
+
url: 'https://payments.statuspage.io/'
|
|
47
|
+
});
|
|
48
|
+
function logBrowseCommands() {
|
|
49
|
+
console.log(`Commands:
|
|
50
|
+
pay browse concourse # browses the concourse page
|
|
51
|
+
pay browse help [COMMAND] # Describe subcommands or one specific subcommand
|
|
52
|
+
pay browse manual # browses the pay team manual
|
|
53
|
+
pay browse repo # browses the pay-infra github repo
|
|
54
|
+
pay browse status # browses the pay status page`);
|
|
55
|
+
}
|
|
56
|
+
exports.logBrowseCommands = logBrowseCommands;
|
|
57
|
+
function logNoCommand(argumentName) {
|
|
58
|
+
console.error(`Could not find command "${argumentName}".`);
|
|
59
|
+
console.log(`The available options are: "${Array.from(requestableItems.keys()).join('", "')}".`);
|
|
60
|
+
}
|
|
61
|
+
async function browseHandler(options) {
|
|
62
|
+
await (0, standardContent_js_1.showHeader)();
|
|
63
|
+
if (options.arguments.length === 0) {
|
|
64
|
+
logBrowseCommands();
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
if (options.arguments[0] === 'help') {
|
|
68
|
+
const argumentName = options.arguments[1];
|
|
69
|
+
if (argumentName === undefined || argumentName.trim() === '') {
|
|
70
|
+
logBrowseCommands();
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
const requestedItem = requestableItems.get(argumentName);
|
|
74
|
+
if (requestedItem != null) {
|
|
75
|
+
console.log('Usage:');
|
|
76
|
+
console.log(` npx --package=${path.resolve(constants_js_1.rootDir)} browse ${argumentName}`);
|
|
77
|
+
console.log(`browses the ${requestedItem.name}`);
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
logNoCommand(argumentName);
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
const requestedItem = requestableItems.get(options.arguments[0]);
|
|
84
|
+
if (requestedItem != null) {
|
|
85
|
+
console.log(`Opening the ${requestedItem.name}`);
|
|
86
|
+
moduleFunctionWrapper_js_1.moduleFunctionWrapper.open(requestedItem.url, (err) => {
|
|
87
|
+
if (err != null) {
|
|
88
|
+
console.log(`Failed to open browser, please visit ${requestedItem.url}`);
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
logNoCommand(options.arguments[0]);
|
|
94
|
+
}
|
|
95
|
+
exports.default = browseHandler;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
// import * as open from 'open'
|
|
7
|
+
const globals_1 = require("@jest/globals");
|
|
8
|
+
const moduleFunctionWrapper_js_1 = require("../util/moduleFunctionWrapper.js");
|
|
9
|
+
const browse_js_1 = __importDefault(require("./browse.js"));
|
|
10
|
+
const commandsText = `Commands:
|
|
11
|
+
pay browse concourse # browses the concourse page
|
|
12
|
+
pay browse help [COMMAND] # Describe subcommands or one specific subcommand
|
|
13
|
+
pay browse manual # browses the pay team manual
|
|
14
|
+
pay browse repo # browses the pay-infra github repo
|
|
15
|
+
pay browse status # browses the pay status page`;
|
|
16
|
+
(0, globals_1.describe)('browse command', () => {
|
|
17
|
+
(0, globals_1.beforeEach)(() => {
|
|
18
|
+
globals_1.jest.spyOn(console, 'log').mockImplementation(() => { });
|
|
19
|
+
globals_1.jest.spyOn(console, 'error').mockImplementation(() => { });
|
|
20
|
+
globals_1.jest.spyOn(moduleFunctionWrapper_js_1.moduleFunctionWrapper, 'open').mockImplementation(() => { });
|
|
21
|
+
});
|
|
22
|
+
(0, globals_1.afterEach)(() => {
|
|
23
|
+
globals_1.jest.restoreAllMocks();
|
|
24
|
+
globals_1.jest.resetModules();
|
|
25
|
+
});
|
|
26
|
+
(0, globals_1.it)('should show usage when no additional params are provided', async () => {
|
|
27
|
+
await (0, browse_js_1.default)({ commandName: 'browse', arguments: [] });
|
|
28
|
+
(0, globals_1.expect)(console.log).toHaveBeenCalledWith(commandsText);
|
|
29
|
+
});
|
|
30
|
+
(0, globals_1.it)('should open the browser when manual is provided as the first param', async () => {
|
|
31
|
+
await (0, browse_js_1.default)({ commandName: 'browse', arguments: ['manual'] });
|
|
32
|
+
(0, globals_1.expect)(moduleFunctionWrapper_js_1.moduleFunctionWrapper.open).toHaveBeenCalledWith('https://manual.payments.service.gov.uk/', globals_1.expect.any(Function));
|
|
33
|
+
(0, globals_1.expect)(console.log).toHaveBeenCalledWith('Opening the team manual');
|
|
34
|
+
(0, globals_1.expect)(console.error).not.toHaveBeenCalled();
|
|
35
|
+
});
|
|
36
|
+
(0, globals_1.it)('should open the browser when concourse is provided as the first param', async () => {
|
|
37
|
+
await (0, browse_js_1.default)({ commandName: 'browse', arguments: ['concourse'] });
|
|
38
|
+
(0, globals_1.expect)(moduleFunctionWrapper_js_1.moduleFunctionWrapper.open).toHaveBeenCalledWith('https://pay-cd.deploy.payments.service.gov.uk/', globals_1.expect.any(Function));
|
|
39
|
+
(0, globals_1.expect)(console.log).toHaveBeenCalledWith('Opening the concourse page');
|
|
40
|
+
(0, globals_1.expect)(console.error).not.toHaveBeenCalled();
|
|
41
|
+
});
|
|
42
|
+
(0, globals_1.it)('should open the browser when repo is provided as the first param', async () => {
|
|
43
|
+
await (0, browse_js_1.default)({ commandName: 'browse', arguments: ['repo'] });
|
|
44
|
+
(0, globals_1.expect)(moduleFunctionWrapper_js_1.moduleFunctionWrapper.open).toHaveBeenCalledWith('https://github.com/alphagov/pay-infra', globals_1.expect.any(Function));
|
|
45
|
+
(0, globals_1.expect)(console.log).toHaveBeenCalledWith('Opening the pay-infra github repository');
|
|
46
|
+
(0, globals_1.expect)(console.error).not.toHaveBeenCalled();
|
|
47
|
+
});
|
|
48
|
+
(0, globals_1.it)('should open the browser when status is provided as the first param', async () => {
|
|
49
|
+
await (0, browse_js_1.default)({ commandName: 'browse', arguments: ['status'] });
|
|
50
|
+
(0, globals_1.expect)(moduleFunctionWrapper_js_1.moduleFunctionWrapper.open).toHaveBeenCalledWith('https://payments.statuspage.io/', globals_1.expect.any(Function));
|
|
51
|
+
(0, globals_1.expect)(console.log).toHaveBeenCalledWith('Opening the status page');
|
|
52
|
+
(0, globals_1.expect)(console.error).not.toHaveBeenCalled();
|
|
53
|
+
});
|
|
54
|
+
(0, globals_1.it)('should show the help page when requested', async () => {
|
|
55
|
+
await (0, browse_js_1.default)({ commandName: 'browse', arguments: ['help'] });
|
|
56
|
+
(0, globals_1.expect)(moduleFunctionWrapper_js_1.moduleFunctionWrapper.open).not.toHaveBeenCalled();
|
|
57
|
+
(0, globals_1.expect)(console.log).toHaveBeenCalledWith(`Commands:
|
|
58
|
+
pay browse concourse # browses the concourse page
|
|
59
|
+
pay browse help [COMMAND] # Describe subcommands or one specific subcommand
|
|
60
|
+
pay browse manual # browses the pay team manual
|
|
61
|
+
pay browse repo # browses the pay-infra github repo
|
|
62
|
+
pay browse status # browses the pay status page`);
|
|
63
|
+
});
|
|
64
|
+
(0, globals_1.it)('should details about a command', async () => {
|
|
65
|
+
await (0, browse_js_1.default)({ commandName: 'browse', arguments: ['help', 'manual'] });
|
|
66
|
+
(0, globals_1.expect)(moduleFunctionWrapper_js_1.moduleFunctionWrapper.open).not.toHaveBeenCalled();
|
|
67
|
+
(0, globals_1.expect)(console.log).toHaveBeenCalledWith('Usage:');
|
|
68
|
+
(0, globals_1.expect)(console.log).toHaveBeenCalledWith('browses the team manual');
|
|
69
|
+
});
|
|
70
|
+
(0, globals_1.it)('should handle an unknown command', async () => {
|
|
71
|
+
await (0, browse_js_1.default)({ commandName: 'browse', arguments: ['abcdef'] });
|
|
72
|
+
(0, globals_1.expect)(moduleFunctionWrapper_js_1.moduleFunctionWrapper.open).not.toHaveBeenCalled();
|
|
73
|
+
(0, globals_1.expect)(console.error).toHaveBeenCalledWith('Could not find command "abcdef".');
|
|
74
|
+
(0, globals_1.expect)(console.log).toHaveBeenCalledWith('The available options are: "concourse", "manual", "repo", "status".');
|
|
75
|
+
});
|
|
76
|
+
(0, globals_1.it)('should handle an unknown command within help', async () => {
|
|
77
|
+
await (0, browse_js_1.default)({ commandName: 'browse', arguments: ['help', 'abcdef'] });
|
|
78
|
+
(0, globals_1.expect)(moduleFunctionWrapper_js_1.moduleFunctionWrapper.open).not.toHaveBeenCalled();
|
|
79
|
+
(0, globals_1.expect)(console.error).toHaveBeenCalledWith('Could not find command "abcdef".');
|
|
80
|
+
});
|
|
81
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
async function demoHandler(options) {
|
|
4
|
+
console.log('This is where you would put your implementation.');
|
|
5
|
+
await new Promise((resolve) => {
|
|
6
|
+
setTimeout(resolve, 10);
|
|
7
|
+
});
|
|
8
|
+
console.log('It can be asynchronous.');
|
|
9
|
+
console.error('You can also write to stderr.');
|
|
10
|
+
}
|
|
11
|
+
exports.default = demoHandler;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const legacy_1 = require("./legacy");
|
|
4
|
+
const standardContent_1 = require("../core/standardContent");
|
|
5
|
+
const browse_1 = require("./browse");
|
|
6
|
+
async function helpHandler(options) {
|
|
7
|
+
if (options.arguments[0] === 'browse') {
|
|
8
|
+
await (0, standardContent_1.showHeader)();
|
|
9
|
+
(0, browse_1.logBrowseCommands)();
|
|
10
|
+
}
|
|
11
|
+
else {
|
|
12
|
+
await (0, legacy_1.proxyHandlerOptionsToLegacyCli)(options);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
exports.default = helpHandler;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.proxyHandlerOptionsToLegacyCli = exports.proxyArrayOfArgumentsToLegacyCli = void 0;
|
|
27
|
+
const payCliExec_1 = __importStar(require("../util/payCliExec"));
|
|
28
|
+
const path = __importStar(require("node:path"));
|
|
29
|
+
const constants_1 = require("../core/constants");
|
|
30
|
+
const standardContent_1 = require("../core/standardContent");
|
|
31
|
+
async function legacyHandler(options) {
|
|
32
|
+
const argsToPassOn = [];
|
|
33
|
+
if (options.commandName !== 'legacy') {
|
|
34
|
+
argsToPassOn.unshift(options.commandName);
|
|
35
|
+
}
|
|
36
|
+
options.arguments.forEach((arg) => {
|
|
37
|
+
argsToPassOn.push(arg);
|
|
38
|
+
});
|
|
39
|
+
await proxyArrayOfArgumentsToLegacyCli(argsToPassOn);
|
|
40
|
+
}
|
|
41
|
+
exports.default = legacyHandler;
|
|
42
|
+
async function proxyArrayOfArgumentsToLegacyCli(argsToPassOn) {
|
|
43
|
+
await (0, standardContent_1.showHeader)();
|
|
44
|
+
const rbenvCommand = process.env.PAY_CLI_RBENV_COMMAND ?? 'rbenv';
|
|
45
|
+
const shellCommand = process.env.PAY_CLI_SHELL_COMMAND ?? 'zsh';
|
|
46
|
+
const whichRbenvResult = await (0, payCliExec_1.execAndReturnIO)(`which ${rbenvCommand}`);
|
|
47
|
+
const whichBundlerResult = await (0, payCliExec_1.execAndReturnIO)(`${rbenvCommand} exec which bundle`);
|
|
48
|
+
if (whichRbenvResult.exitCode !== 0) {
|
|
49
|
+
console.error('You need rbenv installed before you can continue.');
|
|
50
|
+
process.exit(12);
|
|
51
|
+
}
|
|
52
|
+
if (whichBundlerResult.exitCode !== 0) {
|
|
53
|
+
console.error('You need bundler installed and available to rbenv before you can continue.');
|
|
54
|
+
process.exit(12);
|
|
55
|
+
}
|
|
56
|
+
await (0, payCliExec_1.default)(shellCommand, {
|
|
57
|
+
cwd: path.join(constants_1.rootDir, 'legacy-ruby-cli'),
|
|
58
|
+
matchExitCode: true,
|
|
59
|
+
streamStdio: true,
|
|
60
|
+
commandsToWrite: [
|
|
61
|
+
`${rbenvCommand} exec bundle exec bin/pay ${argsToPassOn.join(' ')}`,
|
|
62
|
+
'exit $?'
|
|
63
|
+
]
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
exports.proxyArrayOfArgumentsToLegacyCli = proxyArrayOfArgumentsToLegacyCli;
|
|
67
|
+
async function proxyHandlerOptionsToLegacyCli(options) {
|
|
68
|
+
await proxyArrayOfArgumentsToLegacyCli([options.commandName].concat(options.arguments));
|
|
69
|
+
}
|
|
70
|
+
exports.proxyHandlerOptionsToLegacyCli = proxyHandlerOptionsToLegacyCli;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const standardContent_js_1 = require("./standardContent.js");
|
|
7
|
+
const browse_js_1 = __importDefault(require("../commands/browse.js"));
|
|
8
|
+
const demo_js_1 = __importDefault(require("../commands/demo.js"));
|
|
9
|
+
const legacy_1 = __importDefault(require("../commands/legacy"));
|
|
10
|
+
const help_1 = __importDefault(require("../commands/help"));
|
|
11
|
+
const handlers = new Map();
|
|
12
|
+
handlers.set('browse', {
|
|
13
|
+
handler: browse_js_1.default
|
|
14
|
+
});
|
|
15
|
+
handlers.set('legacy', {
|
|
16
|
+
handler: legacy_1.default
|
|
17
|
+
});
|
|
18
|
+
handlers.set('aws', {
|
|
19
|
+
handler: legacy_1.default
|
|
20
|
+
});
|
|
21
|
+
handlers.set('deployment_status', {
|
|
22
|
+
handler: legacy_1.default
|
|
23
|
+
});
|
|
24
|
+
handlers.set('doctor', {
|
|
25
|
+
handler: legacy_1.default
|
|
26
|
+
});
|
|
27
|
+
handlers.set('help', {
|
|
28
|
+
handler: help_1.default
|
|
29
|
+
});
|
|
30
|
+
handlers.set('local', {
|
|
31
|
+
handler: legacy_1.default
|
|
32
|
+
});
|
|
33
|
+
handlers.set('schema', {
|
|
34
|
+
handler: legacy_1.default
|
|
35
|
+
});
|
|
36
|
+
handlers.set('secrets', {
|
|
37
|
+
handler: legacy_1.default
|
|
38
|
+
});
|
|
39
|
+
handlers.set('ssm', {
|
|
40
|
+
handler: legacy_1.default
|
|
41
|
+
});
|
|
42
|
+
handlers.set('tf', {
|
|
43
|
+
handler: legacy_1.default
|
|
44
|
+
});
|
|
45
|
+
handlers.set('demo', {
|
|
46
|
+
handler: demo_js_1.default
|
|
47
|
+
});
|
|
48
|
+
async function runCommand() {
|
|
49
|
+
const command = process.argv[2];
|
|
50
|
+
await showUsageIfNoCommand(command);
|
|
51
|
+
const commandDetails = await getCommandDetails(command);
|
|
52
|
+
if (commandDetails === undefined) {
|
|
53
|
+
console.error(`No command found for [${command}]`);
|
|
54
|
+
process.exit(10);
|
|
55
|
+
}
|
|
56
|
+
await runHandler(command, commandDetails);
|
|
57
|
+
}
|
|
58
|
+
exports.default = runCommand;
|
|
59
|
+
async function getCommandDetails(commandName) {
|
|
60
|
+
return handlers.get(commandName);
|
|
61
|
+
}
|
|
62
|
+
async function showUsageIfNoCommand(commandName) {
|
|
63
|
+
if (commandName === undefined || commandName.trim() === '') {
|
|
64
|
+
await (0, standardContent_js_1.showHeader)();
|
|
65
|
+
await (0, standardContent_js_1.showUsage)();
|
|
66
|
+
process.exit(2);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
async function runHandler(commandName, commandHandler) {
|
|
70
|
+
try {
|
|
71
|
+
await commandHandler.handler({
|
|
72
|
+
commandName,
|
|
73
|
+
arguments: process.argv.slice(3)
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
catch (e) {
|
|
77
|
+
console.error(`Failed to run command [${commandName}]`);
|
|
78
|
+
console.error(e);
|
|
79
|
+
process.exit(12);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.distDir = exports.rootDir = void 0;
|
|
27
|
+
const path = __importStar(require("path"));
|
|
28
|
+
// import {dirname} from 'path'
|
|
29
|
+
// import {fileURLToPath} from 'url'
|
|
30
|
+
//
|
|
31
|
+
// // @ts-ignore
|
|
32
|
+
// const currentDir = dirname(fileURLToPath(import.meta.url))
|
|
33
|
+
const potentialRootDir = path.resolve(__dirname, '..', '..');
|
|
34
|
+
exports.rootDir = potentialRootDir.endsWith('dist') ? path.resolve(potentialRootDir, '..') : potentialRootDir;
|
|
35
|
+
exports.distDir = path.join(exports.rootDir, 'dist');
|
|
36
|
+
exports.default = {
|
|
37
|
+
rootDir: exports.rootDir
|
|
38
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.showUsage = exports.showHeader = void 0;
|
|
27
|
+
const fsp = __importStar(require("fs/promises"));
|
|
28
|
+
const path = __importStar(require("path"));
|
|
29
|
+
const constants_js_1 = require("./constants.js");
|
|
30
|
+
async function showHeader() {
|
|
31
|
+
console.log(await fsp.readFile(path.join(constants_js_1.rootDir, 'resources/header.txt'), 'utf8'));
|
|
32
|
+
}
|
|
33
|
+
exports.showHeader = showHeader;
|
|
34
|
+
async function showUsage() {
|
|
35
|
+
console.log(await fsp.readFile(path.join(constants_js_1.rootDir, 'resources/usageDetails.txt'), 'utf8'));
|
|
36
|
+
}
|
|
37
|
+
exports.showUsage = showUsage;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.execAndReturnIO = void 0;
|
|
27
|
+
const cp = __importStar(require("child_process"));
|
|
28
|
+
async function payCliExec(fullCommand, options) {
|
|
29
|
+
return await new Promise((resolve) => {
|
|
30
|
+
const commandParts = fullCommand.split(' ');
|
|
31
|
+
const command = commandParts.shift();
|
|
32
|
+
if (command === undefined) {
|
|
33
|
+
throw new Error('Command can\'t be undefined');
|
|
34
|
+
}
|
|
35
|
+
const spawnedThread = cp.spawn(command, commandParts, {
|
|
36
|
+
cwd: options?.cwd,
|
|
37
|
+
env: options?.passThroughEnvironmentVariables === true ? { ...process.env } : undefined
|
|
38
|
+
});
|
|
39
|
+
if ((options?.onStdout) !== undefined) {
|
|
40
|
+
spawnedThread.stdout.on('data', options.onStdout);
|
|
41
|
+
}
|
|
42
|
+
if ((options?.onStderr) !== undefined) {
|
|
43
|
+
spawnedThread.stderr.on('data', options.onStderr);
|
|
44
|
+
}
|
|
45
|
+
if ((options?.onClose) !== undefined) {
|
|
46
|
+
spawnedThread.on('close', options.onClose);
|
|
47
|
+
}
|
|
48
|
+
if (options?.streamStdio === true) {
|
|
49
|
+
spawnedThread.stdout.pipe(process.stdout);
|
|
50
|
+
spawnedThread.stderr.pipe(process.stderr);
|
|
51
|
+
process.stdin.pipe(spawnedThread.stdin);
|
|
52
|
+
}
|
|
53
|
+
if (options?.matchExitCode === true) {
|
|
54
|
+
spawnedThread.once('close', (exitCode) => {
|
|
55
|
+
process.exitCode = exitCode;
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
spawnedThread.once('close', () => {
|
|
59
|
+
resolve();
|
|
60
|
+
});
|
|
61
|
+
if (options?.commandsToWrite !== undefined) {
|
|
62
|
+
spawnedThread.stdin.setDefaultEncoding('utf-8');
|
|
63
|
+
options.commandsToWrite.forEach((value) => {
|
|
64
|
+
spawnedThread.stdin.write(`${value}\n`);
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
exports.default = payCliExec;
|
|
70
|
+
async function execAndReturnIO(command, options = {}) {
|
|
71
|
+
const result = {
|
|
72
|
+
stdout: '',
|
|
73
|
+
stderr: '',
|
|
74
|
+
exitCode: -1
|
|
75
|
+
};
|
|
76
|
+
options.onStdout = (data) => {
|
|
77
|
+
result.stdout = `${result.stdout}${data.toString()}`;
|
|
78
|
+
};
|
|
79
|
+
options.onStderr = (data) => {
|
|
80
|
+
result.stderr = `${result.stderr}${data.toString()}`;
|
|
81
|
+
};
|
|
82
|
+
options.onClose = (statusCode) => {
|
|
83
|
+
result.exitCode = statusCode;
|
|
84
|
+
};
|
|
85
|
+
await payCliExec(command, options);
|
|
86
|
+
return result;
|
|
87
|
+
}
|
|
88
|
+
exports.execAndReturnIO = execAndReturnIO;
|