@ethlete/cli 2.1.0-next.4 → 2.1.0-next.6
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/CHANGELOG.md +45 -0
- package/README.md +49 -8
- package/package.json +1 -1
- package/src/index.js +52 -8
- package/src/index.js.map +1 -1
- package/src/lib/api/api-command.d.ts +3 -2
- package/src/lib/api/api-command.js +2 -2
- package/src/lib/api/api-command.js.map +1 -1
- package/src/lib/api/auth-hint.d.ts +11 -0
- package/src/lib/api/auth-hint.js +47 -0
- package/src/lib/api/auth-hint.js.map +1 -0
- package/src/lib/api/clear.d.ts +36 -0
- package/src/lib/api/clear.js +121 -0
- package/src/lib/api/clear.js.map +1 -0
- package/src/lib/api/clone.d.ts +12 -0
- package/src/lib/api/clone.js +24 -0
- package/src/lib/api/clone.js.map +1 -0
- package/src/lib/api/compose.d.ts +29 -0
- package/src/lib/api/compose.js +44 -1
- package/src/lib/api/compose.js.map +1 -1
- package/src/lib/api/definition.d.ts +11 -2
- package/src/lib/api/definition.js +29 -3
- package/src/lib/api/definition.js.map +1 -1
- package/src/lib/api/git.d.ts +25 -0
- package/src/lib/api/git.js +71 -0
- package/src/lib/api/git.js.map +1 -0
- package/src/lib/api/help.d.ts +11 -0
- package/src/lib/api/help.js +72 -0
- package/src/lib/api/help.js.map +1 -0
- package/src/lib/api/index.d.ts +10 -0
- package/src/lib/api/index.js +10 -0
- package/src/lib/api/index.js.map +1 -1
- package/src/lib/api/ports.d.ts +13 -0
- package/src/lib/api/ports.js +98 -0
- package/src/lib/api/ports.js.map +1 -0
- package/src/lib/api/resolve-checkout.d.ts +45 -0
- package/src/lib/api/resolve-checkout.js +91 -0
- package/src/lib/api/resolve-checkout.js.map +1 -0
- package/src/lib/api/run.d.ts +1 -1
- package/src/lib/api/run.js +268 -55
- package/src/lib/api/run.js.map +1 -1
- package/src/lib/api/setup.d.ts +15 -0
- package/src/lib/api/setup.js +41 -0
- package/src/lib/api/setup.js.map +1 -0
- package/src/lib/api/state.d.ts +20 -0
- package/src/lib/api/state.js +33 -0
- package/src/lib/api/state.js.map +1 -0
- package/src/lib/api/suggest.d.ts +7 -0
- package/src/lib/api/suggest.js +35 -0
- package/src/lib/api/suggest.js.map +1 -0
- package/src/lib/auth/auth-command.d.ts +11 -0
- package/src/lib/auth/auth-command.js +137 -0
- package/src/lib/auth/auth-command.js.map +1 -0
- package/src/lib/auth/composer-auth.d.ts +25 -0
- package/src/lib/auth/composer-auth.js +63 -0
- package/src/lib/auth/composer-auth.js.map +1 -0
- package/src/lib/auth/composer-repositories.d.ts +5 -0
- package/src/lib/auth/composer-repositories.js +33 -0
- package/src/lib/auth/composer-repositories.js.map +1 -0
- package/src/lib/auth/gitlab-token.d.ts +43 -0
- package/src/lib/auth/gitlab-token.js +72 -0
- package/src/lib/auth/gitlab-token.js.map +1 -0
- package/src/lib/auth/index.d.ts +4 -0
- package/src/lib/auth/index.js +8 -0
- package/src/lib/auth/index.js.map +1 -0
- package/src/lib/config/diagnose.d.ts +7 -0
- package/src/lib/config/diagnose.js +103 -0
- package/src/lib/config/diagnose.js.map +1 -0
- package/src/lib/config/index.d.ts +1 -0
- package/src/lib/config/index.js +1 -0
- package/src/lib/config/index.js.map +1 -1
- package/src/lib/config/local-config.d.ts +13 -0
- package/src/lib/config/local-config.js +13 -6
- package/src/lib/config/local-config.js.map +1 -1
- package/src/lib/doctor/doctor-command.d.ts +5 -0
- package/src/lib/doctor/doctor-command.js +62 -0
- package/src/lib/doctor/doctor-command.js.map +1 -0
- package/src/lib/doctor/index.d.ts +1 -0
- package/src/lib/doctor/index.js +5 -0
- package/src/lib/doctor/index.js.map +1 -0
- package/src/lib/index.d.ts +3 -0
- package/src/lib/index.js +3 -0
- package/src/lib/index.js.map +1 -1
- package/src/lib/invocation.d.ts +9 -0
- package/src/lib/invocation.js +47 -0
- package/src/lib/invocation.js.map +1 -0
- package/src/lib/utils.d.ts +14 -0
- package/src/lib/utils.js +14 -1
- package/src/lib/utils.js.map +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,50 @@
|
|
|
1
1
|
# @ethlete/cli
|
|
2
2
|
|
|
3
|
+
## 2.1.0-next.6
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [`a1c489e`](https://github.com/ethlete-io/ethdk/commit/a1c489e0a1da4b479fd6e47743dec4c1bad0152f) Thanks [@TomTomB](https://github.com/TomTomB)! - `et api up` now refuses a port another program holds and prints a per-service state table instead of
|
|
8
|
+
the engine's output. New `et api clear` removes a managed checkout, and offers to take its containers down first.
|
|
9
|
+
|
|
10
|
+
- [`12dcd51`](https://github.com/ethlete-io/ethdk/commit/12dcd5118ca8d2089cc3e9379efe4e9d0502a0f6) Thanks [@TomTomB](https://github.com/TomTomB)! - Every `et api` command now takes a comma-separated list of names, so `et api up hub,platform` starts
|
|
11
|
+
both APIs.
|
|
12
|
+
|
|
13
|
+
- [`0e060b2`](https://github.com/ethlete-io/ethdk/commit/0e060b28436e9444726a35a93264a046242e348e) Thanks [@TomTomB](https://github.com/TomTomB)! - `et api help <name>` now answers for one API: the commands it accepts, what each one runs, its url
|
|
14
|
+
and services, and the state of its checkout. `--help` after a known API name prints the same text.
|
|
15
|
+
|
|
16
|
+
- [`0e060b2`](https://github.com/ethlete-io/ethdk/commit/0e060b28436e9444726a35a93264a046242e348e) Thanks [@TomTomB](https://github.com/TomTomB)! - `et api` now runs an API's `setupCommand` itself: `et api setup <name>` on its own, or as an offer
|
|
17
|
+
when a command finds the `envFile` missing. `--setup` accepts that offer without the question.
|
|
18
|
+
|
|
19
|
+
- [`c3dd7c3`](https://github.com/ethlete-io/ethdk/commit/c3dd7c3d7e0e2a060e081c7fe820f9774537418b) Thanks [@TomTomB](https://github.com/TomTomB)! - `et auth <token>` writes a GitLab token into composer's `auth.json`, which the API containers mount. It asks the host whether the token can download code before it writes anything.
|
|
20
|
+
|
|
21
|
+
### Patch Changes
|
|
22
|
+
|
|
23
|
+
- [`0e060b2`](https://github.com/ethlete-io/ethdk/commit/0e060b28436e9444726a35a93264a046242e348e) Thanks [@TomTomB](https://github.com/TomTomB)! - An unknown API name in `et api` now names the closest match and the APIs there are, in place of the
|
|
24
|
+
whole help text. An unknown command suggests the closest command the same way.
|
|
25
|
+
|
|
26
|
+
- [`c3dd7c3`](https://github.com/ethlete-io/ethdk/commit/c3dd7c3d7e0e2a060e081c7fe820f9774537418b) Thanks [@TomTomB](https://github.com/TomTomB)! - A failing `et api` exec command no longer always blames a private dependency. That hint is kept for a command that installs dependencies; any other one suggests running the install command first.
|
|
27
|
+
|
|
28
|
+
- [`0e060b2`](https://github.com/ethlete-io/ethdk/commit/0e060b28436e9444726a35a93264a046242e348e) Thanks [@TomTomB](https://github.com/TomTomB)! - `et api setup` keeps the setup command's own output back and prints one line for the result. The output is only shown when the command fails, so a checkout's advice about its Makefile no longer competes with the CLI.
|
|
29
|
+
|
|
30
|
+
- [`0e060b2`](https://github.com/ethlete-io/ethdk/commit/0e060b28436e9444726a35a93264a046242e348e) Thanks [@TomTomB](https://github.com/TomTomB)! - Every `et` message now names a command the reader can type, for example `yarn api` or `npx et api`,
|
|
31
|
+
in place of a bare `et`. `et doctor` names the `et api` command that fixes each problem.
|
|
32
|
+
|
|
33
|
+
## 2.1.0-next.5
|
|
34
|
+
|
|
35
|
+
### Minor Changes
|
|
36
|
+
|
|
37
|
+
- [`612d735`](https://github.com/ethlete-io/ethdk/commit/612d73563e1689bbfcf948d26ebe7c59d2420781) Thanks [@TomTomB](https://github.com/TomTomB)! - `et api` now clones a missing API checkout from a `repoUrl` in `ethlete.apis.js`, making
|
|
38
|
+
`apiRepoPaths` optional. `runApiCommand` is async as a result.
|
|
39
|
+
|
|
40
|
+
- [#3072](https://github.com/ethlete-io/ethdk/pull/3072) [`4bbbb51`](https://github.com/ethlete-io/ethdk/commit/4bbbb5167989a1c3ef2ffeba09fcfd18ba953fba) Thanks [@github-actions](https://github.com/apps/github-actions)! - Add `et doctor` to check this machine's config, container engine and API checkouts, `et api
|
|
41
|
+
checkout` and `et api pull` (with `--force`) to move an API checkout to the branch it should be on,
|
|
42
|
+
and `et api --help`.
|
|
43
|
+
|
|
44
|
+
### Patch Changes
|
|
45
|
+
|
|
46
|
+
- [#3072](https://github.com/ethlete-io/ethdk/pull/3072) [`0fd8ba3`](https://github.com/ethlete-io/ethdk/commit/0fd8ba3dd61cc78409c397c8180f0a675282642f) Thanks [@github-actions](https://github.com/apps/github-actions)! - `et doctor` now says when a directory has neither config file rather than reporting no problems.
|
|
47
|
+
|
|
3
48
|
## 2.1.0-next.4
|
|
4
49
|
|
|
5
50
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -16,22 +16,61 @@ yarn et release
|
|
|
16
16
|
|
|
17
17
|
Turns pending changesets into a tagged, pushed release commit (version → tag → commit → push).
|
|
18
18
|
|
|
19
|
+
## `et auth`
|
|
20
|
+
|
|
21
|
+
Writes a GitLab token into composer's `auth.json`, so a private PHP dependency can be downloaded.
|
|
22
|
+
The compose file of each API mounts `$HOME/.composer` into its container, so this is the token the
|
|
23
|
+
composer inside the container reads.
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
yarn et auth glpat-xxxxxxxxxxxxxxxxxxxx # the host comes from ethlete.apis.js
|
|
27
|
+
yarn et auth gitlab.example.com glpat-xxxxxxxxxxxxxxxxxxxx # name it when more than one is in use
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
The token is checked against the host first: once for the token itself, and once by downloading one
|
|
31
|
+
byte of a project archive. A token that can read the API but not fetch code answers `403` there, and
|
|
32
|
+
nothing is written. `--force` writes it anyway.
|
|
33
|
+
|
|
19
34
|
## `et api`
|
|
20
35
|
|
|
21
36
|
Runs the API an app in this repo talks to, from a checkout on your own machine.
|
|
22
37
|
|
|
23
38
|
```bash
|
|
24
|
-
yarn et api
|
|
25
|
-
yarn et api
|
|
26
|
-
yarn et api
|
|
27
|
-
yarn et api
|
|
28
|
-
yarn et api
|
|
29
|
-
yarn et api
|
|
39
|
+
yarn et api --help # the commands, the APIs and what each one accepts
|
|
40
|
+
yarn et api help hub # what hub accepts, and where its checkout is
|
|
41
|
+
yarn et api up hub # start the containers
|
|
42
|
+
yarn et api up hub,platform # the same, for both APIs
|
|
43
|
+
yarn et api down hub # stop them
|
|
44
|
+
yarn et api logs hub # follow the API's log
|
|
45
|
+
yarn et api shell hub # a shell in the API container
|
|
46
|
+
yarn et api install hub # an entry from that API's own "exec" map
|
|
47
|
+
yarn et api up hub --host # also print the address other devices can reach
|
|
48
|
+
yarn et api checkout hub # switch the checkout to the branch apiRepoBranches names
|
|
49
|
+
yarn et api pull hub # fetch and fast-forward the checked-out branch
|
|
50
|
+
yarn et api pull hub --force # the same, discarding local commits and tracked changes
|
|
51
|
+
yarn et api clone hub # clone the API into .ethlete/hub
|
|
52
|
+
yarn et api setup hub # run the API's own setupCommand, which writes its .env
|
|
30
53
|
```
|
|
31
54
|
|
|
55
|
+
Every command takes a comma-separated list of names, and acts on each API in turn.
|
|
56
|
+
|
|
57
|
+
`checkout`, `pull` and `setup` act on the checkout itself, so they work before the API has an `.env`
|
|
58
|
+
and need no container engine. `pull` refuses to run on a checkout with uncommitted changes unless you pass
|
|
59
|
+
`--force`. `--force` resets the branch to its remote and throws away local commits and tracked
|
|
60
|
+
changes; it never touches untracked or ignored files, so a `vendor/` directory or a `.env` survives.
|
|
61
|
+
|
|
32
62
|
The first container tool that answers is used, in this order: `docker compose`,
|
|
33
63
|
`container compose`, `podman-compose`, `podman compose`.
|
|
34
64
|
|
|
65
|
+
## `et doctor`
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
yarn et doctor
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
Checks `ethlete.config.local.json`, reports the container engine it would use, and resolves every
|
|
72
|
+
API declared in `ethlete.apis.js`. It exits non-zero when it finds a problem, so CI can run it.
|
|
73
|
+
|
|
35
74
|
### Declaring the APIs
|
|
36
75
|
|
|
37
76
|
`ethlete.apis.js` at the repo root describes each API's compose setup. It is a module rather
|
|
@@ -64,8 +103,10 @@ Adding an API is an entry in this map. Nothing else changes.
|
|
|
64
103
|
|
|
65
104
|
### Where the checkouts live
|
|
66
105
|
|
|
67
|
-
|
|
68
|
-
|
|
106
|
+
Give an API a `repoUrl` and `et api` clones it into a gitignored `.ethlete/<name>` when you have no
|
|
107
|
+
checkout of your own, asking first (or use `--clone`). To point at a checkout you already have - which
|
|
108
|
+
you want whenever you work in the backend, since compose mounts it into the container - set
|
|
109
|
+
`apiRepoPaths` in a gitignored `ethlete.config.local.json` at the repo root. `@ethlete/agent-rules` reads the same file, so its skills and `et` agree on where a
|
|
69
110
|
checkout is:
|
|
70
111
|
|
|
71
112
|
```json
|
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -2,12 +2,40 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
4
|
const lib_1 = require("./lib");
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
5
|
+
const USAGE_ROWS = [
|
|
6
|
+
{ subcommand: 'release', args: '', lines: ['Turn pending changesets into a tagged, pushed release commit'] },
|
|
7
|
+
{
|
|
8
|
+
subcommand: 'api',
|
|
9
|
+
args: ' <cmd> <api>',
|
|
10
|
+
lines: [
|
|
11
|
+
"Run an API from this repo's ethlete.apis.js locally",
|
|
12
|
+
"(up, down, logs, shell, setup, plus that API's own exec entries)",
|
|
13
|
+
],
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
subcommand: 'auth',
|
|
17
|
+
args: ' [host] <token>',
|
|
18
|
+
lines: [
|
|
19
|
+
"Write a GitLab token into composer's auth.json, which the",
|
|
20
|
+
'API containers mount, after checking it can download code',
|
|
21
|
+
],
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
subcommand: 'doctor',
|
|
25
|
+
args: '',
|
|
26
|
+
lines: ["Check this machine's ethlete.config.local.json, container engine", 'and every API checkout'],
|
|
27
|
+
},
|
|
28
|
+
];
|
|
29
|
+
const usage = (root) => {
|
|
30
|
+
const rows = USAGE_ROWS.map((row) => (Object.assign(Object.assign({}, row), { command: `${(0, lib_1.repoInvocation)({ root, subcommand: row.subcommand })}${row.args}` })));
|
|
31
|
+
const width = Math.max(...rows.map((row) => row.command.length));
|
|
32
|
+
return [
|
|
33
|
+
'et — Ethlete repo tooling',
|
|
34
|
+
'',
|
|
35
|
+
...rows.flatMap((row) => row.lines.map((line, index) => ` ${(index === 0 ? row.command : '').padEnd(width)} ${line}`)),
|
|
36
|
+
'',
|
|
37
|
+
].join('\n');
|
|
38
|
+
};
|
|
11
39
|
const cli = (args) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
12
40
|
switch (args[0]) {
|
|
13
41
|
case 'release':
|
|
@@ -16,9 +44,25 @@ const cli = (args) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
|
16
44
|
yield (0, lib_1.release)(args.join('=').split('='));
|
|
17
45
|
return 0;
|
|
18
46
|
case 'api':
|
|
19
|
-
return (0, lib_1.apiCommand)({
|
|
47
|
+
return (0, lib_1.apiCommand)({
|
|
48
|
+
root: process.cwd(),
|
|
49
|
+
argv: args.slice(1),
|
|
50
|
+
invocation: (0, lib_1.repoInvocation)({ root: process.cwd(), subcommand: 'api' }),
|
|
51
|
+
});
|
|
52
|
+
case 'auth':
|
|
53
|
+
return (0, lib_1.authCommand)({
|
|
54
|
+
root: process.cwd(),
|
|
55
|
+
argv: args.slice(1),
|
|
56
|
+
invocation: (0, lib_1.repoInvocation)({ root: process.cwd(), subcommand: 'auth' }),
|
|
57
|
+
});
|
|
58
|
+
case 'doctor':
|
|
59
|
+
// Every fix it names is an `et api` command, so it needs that script rather than its own.
|
|
60
|
+
return (0, lib_1.doctorCommand)({
|
|
61
|
+
root: process.cwd(),
|
|
62
|
+
apiInvocation: (0, lib_1.repoInvocation)({ root: process.cwd(), subcommand: 'api' }),
|
|
63
|
+
});
|
|
20
64
|
default:
|
|
21
|
-
console.log(
|
|
65
|
+
console.log(usage(process.cwd()));
|
|
22
66
|
return args[0] === undefined || args[0] === '--help' || args[0] === '-h' ? 0 : 1;
|
|
23
67
|
}
|
|
24
68
|
});
|
package/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../libs/cli/src/index.ts"],"names":[],"mappings":";;;AAAA,+
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../libs/cli/src/index.ts"],"names":[],"mappings":";;;AAAA,+BAAwF;AAExF,MAAM,UAAU,GAAG;IACjB,EAAE,UAAU,EAAE,SAAS,EAAE,IAAI,EAAE,EAAE,EAAE,KAAK,EAAE,CAAC,8DAA8D,CAAC,EAAE;IAC5G;QACE,UAAU,EAAE,KAAK;QACjB,IAAI,EAAE,cAAc;QACpB,KAAK,EAAE;YACL,qDAAqD;YACrD,kEAAkE;SACnE;KACF;IACD;QACE,UAAU,EAAE,MAAM;QAClB,IAAI,EAAE,iBAAiB;QACvB,KAAK,EAAE;YACL,2DAA2D;YAC3D,2DAA2D;SAC5D;KACF;IACD;QACE,UAAU,EAAE,QAAQ;QACpB,IAAI,EAAE,EAAE;QACR,KAAK,EAAE,CAAC,kEAAkE,EAAE,wBAAwB,CAAC;KACtG;CACF,CAAC;AAEF,MAAM,KAAK,GAAG,CAAC,IAAY,EAAE,EAAE;IAC7B,MAAM,IAAI,GAAG,UAAU,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,iCAChC,GAAG,KACN,OAAO,EAAE,GAAG,IAAA,oBAAc,EAAC,EAAE,IAAI,EAAE,UAAU,EAAE,GAAG,CAAC,UAAU,EAAE,CAAC,GAAG,GAAG,CAAC,IAAI,EAAE,IAC7E,CAAC,CAAC;IACJ,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,IAA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|
|
|
3
3
|
exports.apiCommand = void 0;
|
|
4
4
|
const load_definitions_1 = require("./load-definitions");
|
|
5
5
|
const run_1 = require("./run");
|
|
6
|
-
const apiCommand = ({ root, argv }) => {
|
|
6
|
+
const apiCommand = ({ root, argv, invocation }) => {
|
|
7
7
|
const { found, apis } = (0, load_definitions_1.loadApiDefinitions)(root);
|
|
8
8
|
if (!found) {
|
|
9
9
|
console.error(`No API definitions found. Create ${load_definitions_1.API_DEFINITIONS_FILE_NAMES[0]} in the repo root:\n\n` +
|
|
@@ -21,7 +21,7 @@ const apiCommand = ({ root, argv }) => {
|
|
|
21
21
|
` };`);
|
|
22
22
|
return 1;
|
|
23
23
|
}
|
|
24
|
-
return (0, run_1.runApiCommand)({ apis, argv, root });
|
|
24
|
+
return (0, run_1.runApiCommand)({ apis, argv, root, invocation });
|
|
25
25
|
};
|
|
26
26
|
exports.apiCommand = apiCommand;
|
|
27
27
|
//# sourceMappingURL=api-command.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api-command.js","sourceRoot":"","sources":["../../../../../../libs/cli/src/lib/api/api-command.ts"],"names":[],"mappings":";;;AAAA,yDAAoF;AACpF,+BAAsC;AAE/B,MAAM,UAAU,GAAG,CAAC,EAAE,IAAI,EAAE,IAAI,
|
|
1
|
+
{"version":3,"file":"api-command.js","sourceRoot":"","sources":["../../../../../../libs/cli/src/lib/api/api-command.ts"],"names":[],"mappings":";;;AAAA,yDAAoF;AACpF,+BAAsC;AAE/B,MAAM,UAAU,GAAG,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,UAAU,EAAyD,EAAE,EAAE;IAC9G,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,IAAA,qCAAkB,EAAC,IAAI,CAAC,CAAC;IAEjD,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,OAAO,CAAC,KAAK,CACX,oCAAoC,6CAA0B,CAAC,CAAC,CAAC,wBAAwB;YACvF,uDAAuD;YACvD,wBAAwB;YACxB,cAAc;YACd,oCAAoC;YACpC,wCAAwC;YACxC,6BAA6B;YAC7B,qBAAqB;YACrB,0BAA0B;YAC1B,qCAAqC;YACrC,qDAAqD;YACrD,UAAU;YACV,MAAM,CACT,CAAC;QAEF,OAAO,CAAC,CAAC;IACX,CAAC;IAED,OAAO,IAAA,mBAAa,EAAC,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,UAAU,EAAE,CAAC,CAAC;AACzD,CAAC,CAAC;AAxBW,QAAA,UAAU,cAwBrB"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A private dependency that will not download is the most common way these commands fail, and git
|
|
3
|
+
* and the package managers report it as a bare 403 or a public-key error. This says what to check.
|
|
4
|
+
*/
|
|
5
|
+
export declare const printPrivateDependencyHint: (options: {
|
|
6
|
+
repoHost?: string;
|
|
7
|
+
}) => void;
|
|
8
|
+
/** The host of a git url, for naming it in the hint. Undefined when the url has no host. */
|
|
9
|
+
export declare const gitUrlHost: (repoUrl: string) => string | undefined;
|
|
10
|
+
/** The `group/project` part of a git url, for addressing the project in a host's own API. */
|
|
11
|
+
export declare const gitUrlProjectPath: (repoUrl: string) => string | undefined;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.gitUrlProjectPath = exports.gitUrlHost = exports.printPrivateDependencyHint = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* A private dependency that will not download is the most common way these commands fail, and git
|
|
6
|
+
* and the package managers report it as a bare 403 or a public-key error. This says what to check.
|
|
7
|
+
*/
|
|
8
|
+
const printPrivateDependencyHint = (options) => {
|
|
9
|
+
var _a;
|
|
10
|
+
const host = (_a = options.repoHost) !== null && _a !== void 0 ? _a : 'your git host';
|
|
11
|
+
console.error(`\nThat command may have failed because a private dependency could not be downloaded.\n` +
|
|
12
|
+
`Three things are worth checking:\n\n` +
|
|
13
|
+
` 1. A personal access token for ${host} with permission to DOWNLOAD code.\n` +
|
|
14
|
+
` Read access is not enough for a clone, and the server reports the difference as 403.\n` +
|
|
15
|
+
` 2. An SSH key this machine offers to ${host}, when the dependency is fetched over SSH.\n` +
|
|
16
|
+
` 3. That the token is where the package manager looks for it, not only in your shell.\n` +
|
|
17
|
+
` Composer, for example, reads ~/.composer/auth.json rather than the environment.`);
|
|
18
|
+
};
|
|
19
|
+
exports.printPrivateDependencyHint = printPrivateDependencyHint;
|
|
20
|
+
/** The host of a git url, for naming it in the hint. Undefined when the url has no host. */
|
|
21
|
+
const gitUrlHost = (repoUrl) => {
|
|
22
|
+
const scpLike = /^[^/]+@([^:]+):/.exec(repoUrl);
|
|
23
|
+
if (scpLike)
|
|
24
|
+
return scpLike[1];
|
|
25
|
+
try {
|
|
26
|
+
return new URL(repoUrl).hostname || undefined;
|
|
27
|
+
}
|
|
28
|
+
catch (_a) {
|
|
29
|
+
return undefined;
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
exports.gitUrlHost = gitUrlHost;
|
|
33
|
+
/** The `group/project` part of a git url, for addressing the project in a host's own API. */
|
|
34
|
+
const gitUrlProjectPath = (repoUrl) => {
|
|
35
|
+
var _a;
|
|
36
|
+
const scpLike = /^[^/]+@[^:]+:(.+)$/.exec(repoUrl);
|
|
37
|
+
if (scpLike)
|
|
38
|
+
return ((_a = scpLike[1]) !== null && _a !== void 0 ? _a : '').replace(/\.git$/, '') || undefined;
|
|
39
|
+
try {
|
|
40
|
+
return new URL(repoUrl).pathname.replace(/^\/+/, '').replace(/\.git$/, '') || undefined;
|
|
41
|
+
}
|
|
42
|
+
catch (_b) {
|
|
43
|
+
return undefined;
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
exports.gitUrlProjectPath = gitUrlProjectPath;
|
|
47
|
+
//# sourceMappingURL=auth-hint.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth-hint.js","sourceRoot":"","sources":["../../../../../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IAAI,SAAS,CAAC;IAC1F,CAAC;IAAC,WAAM,CAAC;QACP,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC,CAAC;AAVW,QAAA,iBAAiB,qBAU5B"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { ApiDefinitions } from './definition';
|
|
2
|
+
export type ApiClearTarget = {
|
|
3
|
+
name: string;
|
|
4
|
+
/** Absolute path that would be removed. */
|
|
5
|
+
repoPath: string;
|
|
6
|
+
/** Directory that holds the compose file. */
|
|
7
|
+
composePath: string;
|
|
8
|
+
/** Whether any container of its compose project still exists. Those are taken down before the removal. */
|
|
9
|
+
hasContainers: boolean;
|
|
10
|
+
/** Why it must stay. Empty when it can be removed. */
|
|
11
|
+
blockers: string[];
|
|
12
|
+
};
|
|
13
|
+
export type ApiClearPlanOptions = {
|
|
14
|
+
apis: ApiDefinitions;
|
|
15
|
+
names: string[];
|
|
16
|
+
root: string;
|
|
17
|
+
invocation: string;
|
|
18
|
+
/** Skips the checks on uncommitted changes and unpushed commits. */
|
|
19
|
+
force: boolean;
|
|
20
|
+
/** Whether any container of the API's compose project exists. */
|
|
21
|
+
hasContainers: (composePath: string) => boolean;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* What `clear` would do to each named API: the path it would remove, and every reason it must stay.
|
|
25
|
+
* An API without a managed checkout is left out, because there is nothing of ours to remove.
|
|
26
|
+
*/
|
|
27
|
+
export declare const planApiClear: (options: ApiClearPlanOptions) => ApiClearTarget[];
|
|
28
|
+
export type ApiClearOptions = ApiClearPlanOptions & {
|
|
29
|
+
/** Takes the containers of one compose project down. False when the compose command failed. */
|
|
30
|
+
takeDown: (composePath: string) => boolean;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Removes the managed checkout of each named API, after one question that defaults to no. It offers to
|
|
34
|
+
* take down the containers that still exist, and refuses an API with work only this checkout holds.
|
|
35
|
+
*/
|
|
36
|
+
export declare const clearApiCheckouts: (options: ApiClearOptions) => Promise<number>;
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.clearApiCheckouts = exports.planApiClear = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const fs_1 = require("fs");
|
|
6
|
+
const utils_1 = require("../utils");
|
|
7
|
+
const git_1 = require("./git");
|
|
8
|
+
const resolve_checkout_1 = require("./resolve-checkout");
|
|
9
|
+
const MAX_LISTED = 5;
|
|
10
|
+
/** The first few lines of a git listing, so a refusal shows what stands in the way. */
|
|
11
|
+
const listed = (lines) => [
|
|
12
|
+
...lines.slice(0, MAX_LISTED).map((line) => ` ${line}`),
|
|
13
|
+
...(lines.length > MAX_LISTED ? [` and ${lines.length - MAX_LISTED} more`] : []),
|
|
14
|
+
].join('\n');
|
|
15
|
+
/**
|
|
16
|
+
* What `clear` would do to each named API: the path it would remove, and every reason it must stay.
|
|
17
|
+
* An API without a managed checkout is left out, because there is nothing of ours to remove.
|
|
18
|
+
*/
|
|
19
|
+
const planApiClear = (options) => {
|
|
20
|
+
const { apis, names, root, invocation, force, hasContainers } = options;
|
|
21
|
+
return names.flatMap((name) => {
|
|
22
|
+
const api = apis[name];
|
|
23
|
+
if (!api)
|
|
24
|
+
return [];
|
|
25
|
+
const checkout = (0, resolve_checkout_1.resolveApiCheckout)({ root, name, api, needs: 'repo' });
|
|
26
|
+
if (!checkout.ok)
|
|
27
|
+
return [];
|
|
28
|
+
const { repoPath, composePath } = checkout.checkout;
|
|
29
|
+
const managed = (0, resolve_checkout_1.managedCheckoutPath)(root, name);
|
|
30
|
+
if (repoPath !== managed) {
|
|
31
|
+
return [
|
|
32
|
+
{
|
|
33
|
+
name,
|
|
34
|
+
repoPath,
|
|
35
|
+
composePath,
|
|
36
|
+
hasContainers: false,
|
|
37
|
+
blockers: [
|
|
38
|
+
`${repoPath} is your own checkout, not the one ${invocation} manages. ` +
|
|
39
|
+
`Remove it yourself, or drop apiRepoPaths.${name} first.`,
|
|
40
|
+
],
|
|
41
|
+
},
|
|
42
|
+
];
|
|
43
|
+
}
|
|
44
|
+
const changes = (0, git_1.uncommittedChanges)(repoPath);
|
|
45
|
+
const unpushed = (0, git_1.unpushedCommits)(repoPath);
|
|
46
|
+
return [
|
|
47
|
+
{
|
|
48
|
+
name,
|
|
49
|
+
repoPath,
|
|
50
|
+
composePath,
|
|
51
|
+
hasContainers: hasContainers(composePath),
|
|
52
|
+
blockers: [
|
|
53
|
+
...(!force && changes.length > 0
|
|
54
|
+
? [
|
|
55
|
+
`${repoPath} has uncommitted changes:\n\n${listed(changes)}\n\n` +
|
|
56
|
+
'Commit them, or pass --force to lose them.',
|
|
57
|
+
]
|
|
58
|
+
: []),
|
|
59
|
+
...(!force && unpushed.length > 0
|
|
60
|
+
? [
|
|
61
|
+
`${repoPath} has commits no remote holds:\n\n${listed(unpushed)}\n\n` +
|
|
62
|
+
'Push them, or pass --force to lose them.',
|
|
63
|
+
]
|
|
64
|
+
: []),
|
|
65
|
+
],
|
|
66
|
+
},
|
|
67
|
+
];
|
|
68
|
+
});
|
|
69
|
+
};
|
|
70
|
+
exports.planApiClear = planApiClear;
|
|
71
|
+
/**
|
|
72
|
+
* Removes the managed checkout of each named API, after one question that defaults to no. It offers to
|
|
73
|
+
* take down the containers that still exist, and refuses an API with work only this checkout holds.
|
|
74
|
+
*/
|
|
75
|
+
const clearApiCheckouts = (options) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
76
|
+
const { names, invocation, takeDown } = options;
|
|
77
|
+
const targets = (0, exports.planApiClear)(options);
|
|
78
|
+
const blocked = targets.filter(({ blockers }) => blockers.length > 0);
|
|
79
|
+
const removable = targets.filter(({ blockers }) => blockers.length === 0);
|
|
80
|
+
for (const { blockers } of blocked) {
|
|
81
|
+
console.error(blockers.join('\n\n'));
|
|
82
|
+
}
|
|
83
|
+
if (blocked.length > 0)
|
|
84
|
+
console.error('');
|
|
85
|
+
if (removable.length === 0) {
|
|
86
|
+
if (blocked.length === 0) {
|
|
87
|
+
console.log(`Nothing to remove. ${names.join(', ')} has no checkout ${invocation} manages.`);
|
|
88
|
+
}
|
|
89
|
+
return blocked.length > 0 ? 1 : 0;
|
|
90
|
+
}
|
|
91
|
+
const paths = removable.map(({ repoPath }) => ` ${repoPath}`).join('\n');
|
|
92
|
+
const running = removable.filter(({ hasContainers }) => hasContainers).map(({ name }) => name);
|
|
93
|
+
const stopped = running.join(', ');
|
|
94
|
+
const checkouts = removable.length === 1 ? 'the checkout' : 'the checkouts';
|
|
95
|
+
const accepted = yield (0, utils_1.confirm)({
|
|
96
|
+
problem: running.length > 0 ? `This takes ${stopped} down, then removes:\n\n${paths}` : `This removes:\n\n${paths}`,
|
|
97
|
+
question: running.length > 0
|
|
98
|
+
? `Take ${stopped} down and remove ${checkouts}?`
|
|
99
|
+
: `Remove ${removable.map(({ name }) => name).join(', ')}?`,
|
|
100
|
+
hint: running.length > 0
|
|
101
|
+
? `Re-run in a terminal to answer the question, or run "${invocation} down ${stopped}" and remove the ` +
|
|
102
|
+
'directories yourself.'
|
|
103
|
+
: 'Re-run in a terminal to answer the question, or remove the directories yourself.',
|
|
104
|
+
defaultsToYes: false,
|
|
105
|
+
});
|
|
106
|
+
if (!accepted)
|
|
107
|
+
return 1;
|
|
108
|
+
let failed = 0;
|
|
109
|
+
for (const { name, repoPath, composePath, hasContainers } of removable) {
|
|
110
|
+
if (hasContainers && !takeDown(composePath)) {
|
|
111
|
+
console.error(`Could not take ${name} down, so ${repoPath} stays.`);
|
|
112
|
+
failed += 1;
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
(0, fs_1.rmSync)(repoPath, { recursive: true, force: true });
|
|
116
|
+
console.log(`Removed ${repoPath}. Run "${invocation} clone ${name}" to get it back.`);
|
|
117
|
+
}
|
|
118
|
+
return blocked.length > 0 || failed > 0 ? 1 : 0;
|
|
119
|
+
});
|
|
120
|
+
exports.clearApiCheckouts = clearApi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I,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;QACnD,OAAO,CAAC,GAAG,CAAC,WAAW,QAAQ,UAAU,UAAU,UAAU,IAAI,mBAAmB,CAAC,CAAC;IACxF,CAAC;IAED,OAAO,OAAO,CAAC,MAAM,GAAG,CAAC,IAAI,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAClD,CAAC,CAAA,CAAC;AAvDW,QAAA,iBAAiB,qBAuD5B"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare const DEFAULT_CHECKOUT_DIR = ".ethlete";
|
|
2
|
+
/** True when git would ignore the path, so a cloned checkout cannot be committed by accident. */
|
|
3
|
+
export declare const isGitIgnored: (root: string, path: string) => boolean;
|
|
4
|
+
export type CloneRequest = {
|
|
5
|
+
repoUrl: string;
|
|
6
|
+
/** Absolute path to clone into. */
|
|
7
|
+
into: string;
|
|
8
|
+
/** Branch to check out, from `apiRepoBranches`. */
|
|
9
|
+
branch?: string;
|
|
10
|
+
};
|
|
11
|
+
/** Clones an API repo into its managed directory. Git's own output and failures are passed through. */
|
|
12
|
+
export declare const cloneApiRepo: ({ repoUrl, into, branch }: CloneRequest) => number;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.cloneApiRepo = exports.isGitIgnored = exports.DEFAULT_CHECKOUT_DIR = void 0;
|
|
4
|
+
const child_process_1 = require("child_process");
|
|
5
|
+
const fs_1 = require("fs");
|
|
6
|
+
const path_1 = require("path");
|
|
7
|
+
const fs_2 = require("fs");
|
|
8
|
+
exports.DEFAULT_CHECKOUT_DIR = '.ethlete';
|
|
9
|
+
/** True when git would ignore the path, so a cloned checkout cannot be committed by accident. */
|
|
10
|
+
const isGitIgnored = (root, path) => (0, child_process_1.spawnSync)('git', ['check-ignore', '-q', path], { cwd: root }).status === 0;
|
|
11
|
+
exports.isGitIgnored = isGitIgnored;
|
|
12
|
+
/** Clones an API repo into its managed directory. Git's own output and failures are passed through. */
|
|
13
|
+
const cloneApiRepo = ({ repoUrl, into, branch }) => {
|
|
14
|
+
var _a;
|
|
15
|
+
if ((0, fs_1.existsSync)(into)) {
|
|
16
|
+
console.error(`${into} already exists.`);
|
|
17
|
+
return 1;
|
|
18
|
+
}
|
|
19
|
+
(0, fs_2.mkdirSync)((0, path_1.dirname)(into), { recursive: true });
|
|
20
|
+
const args = ['clone', ...(branch ? ['--branch', branch] : []), '--', repoUrl, into];
|
|
21
|
+
return (_a = (0, child_process_1.spawnSync)('git', args, { stdio: 'inherit' }).status) !== null && _a !== void 0 ? _a : 1;
|
|
22
|
+
};
|
|
23
|
+
exports.cloneApiRepo = cloneApiRepo;
|
|
24
|
+
//# sourceMappingURL=clone.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clone.js","sourceRoot":"","sources":["../../../../../../libs/cli/src/lib/api/clone.ts"],"names":[],"mappings":";;;AAAA,iDAA0C;AAC1C,2BAAgC;AAChC,+BAA+B;AAC/B,2BAA+B;AAElB,QAAA,oBAAoB,GAAG,UAAU,CAAC;AAE/C,iGAAiG;AAC1F,MAAM,YAAY,GAAG,CAAC,IAAY,EAAE,IAAY,EAAE,EAAE,CACzD,IAAA,yBAAS,EAAC,KAAK,EAAE,CAAC,cAAc,EAAE,IAAI,EAAE,IAAI,CAAC,EAAE,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC;AADhE,QAAA,YAAY,gBACoD;AAU7E,uGAAuG;AAChG,MAAM,YAAY,GAAG,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAgB,EAAE,EAAE;;IACtE,IAAI,IAAA,eAAU,EAAC,IAAI,CAAC,EAAE,CAAC;QACrB,OAAO,CAAC,KAAK,CAAC,GAAG,IAAI,kBAAkB,CAAC,CAAC;QAEzC,OAAO,CAAC,CAAC;IACX,CAAC;IAED,IAAA,cAAS,EAAC,IAAA,cAAO,EAAC,IAAI,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAE9C,MAAM,IAAI,GAAG,CAAC,OAAO,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,CAAC,CAAC;IAErF,OAAO,MAAA,IAAA,yBAAS,EAAC,KAAK,EAAE,IAAI,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC,CAAC,MAAM,mCAAI,CAAC,CAAC;AAClE,CAAC,CAAC;AAZW,QAAA,YAAY,gBAYvB"}
|
package/src/lib/api/compose.d.ts
CHANGED
|
@@ -15,3 +15,32 @@ export declare const engineEnv: (engine: string) => {
|
|
|
15
15
|
export declare const lanAddress: () => string | undefined;
|
|
16
16
|
/** Path of this machine's SSH key, for a compose file that mounts one into the API container. */
|
|
17
17
|
export declare const sshKeyPath: () => string | undefined;
|
|
18
|
+
export type ComposeCall = {
|
|
19
|
+
tool: ComposeTool;
|
|
20
|
+
/** Directory that holds the compose file. */
|
|
21
|
+
cwd: string;
|
|
22
|
+
env?: NodeJS.ProcessEnv;
|
|
23
|
+
};
|
|
24
|
+
/** Runs a compose command and captures its stdout. `undefined` when the tool itself failed. */
|
|
25
|
+
export declare const composeOutput: (options: ComposeCall & {
|
|
26
|
+
args: string[];
|
|
27
|
+
}) => string | undefined;
|
|
28
|
+
/** Container ids of a compose project, or `undefined` when the tool could not answer. */
|
|
29
|
+
export declare const composeContainerIds: (call: ComposeCall) => string[] | undefined;
|
|
30
|
+
export type PortMapping = {
|
|
31
|
+
host: number;
|
|
32
|
+
container: number;
|
|
33
|
+
};
|
|
34
|
+
export type ContainerState = {
|
|
35
|
+
id: string;
|
|
36
|
+
name: string;
|
|
37
|
+
/** Compose service, empty for a container compose did not start. */
|
|
38
|
+
service: string;
|
|
39
|
+
/** The engine's own words, for example `Up 42 minutes` or `Exited (1) 3 seconds ago`. */
|
|
40
|
+
status: string;
|
|
41
|
+
ports: PortMapping[];
|
|
42
|
+
};
|
|
43
|
+
/** True for a status the engine prints while the container runs. */
|
|
44
|
+
export declare const isRunningStatus: (status: string) => boolean;
|
|
45
|
+
/** Every container the engine knows, with its compose service and published ports. */
|
|
46
|
+
export declare const containerStates: (engine: string) => ContainerState[];
|
package/src/lib/api/compose.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.sshKeyPath = exports.lanAddress = exports.engineEnv = exports.composeToolNames = exports.resolveComposeTool = exports.composeBinary = void 0;
|
|
3
|
+
exports.containerStates = exports.isRunningStatus = exports.composeContainerIds = exports.composeOutput = exports.sshKeyPath = exports.lanAddress = exports.engineEnv = exports.composeToolNames = exports.resolveComposeTool = exports.composeBinary = void 0;
|
|
4
4
|
const child_process_1 = require("child_process");
|
|
5
5
|
const fs_1 = require("fs");
|
|
6
6
|
const os_1 = require("os");
|
|
@@ -55,4 +55,47 @@ exports.lanAddress = lanAddress;
|
|
|
55
55
|
/** Path of this machine's SSH key, for a compose file that mounts one into the API container. */
|
|
56
56
|
const sshKeyPath = () => [(0, path_1.join)((0, os_1.homedir)(), '.ssh/id_ed25519'), (0, path_1.join)((0, os_1.homedir)(), '.ssh/id_rsa')].find((path) => (0, fs_1.existsSync)(path));
|
|
57
57
|
exports.sshKeyPath = sshKeyPath;
|
|
58
|
+
/** Runs a compose command and captures its stdout. `undefined` when the tool itself failed. */
|
|
59
|
+
const composeOutput = (options) => {
|
|
60
|
+
var _a;
|
|
61
|
+
const { tool, cwd, env, args } = options;
|
|
62
|
+
const [binary, ...prefix] = tool.compose;
|
|
63
|
+
const result = (0, child_process_1.spawnSync)(binary, [...prefix, ...args], { cwd, env, encoding: 'utf8' });
|
|
64
|
+
return result.error || result.status !== 0 ? undefined : ((_a = result.stdout) !== null && _a !== void 0 ? _a : '');
|
|
65
|
+
};
|
|
66
|
+
exports.composeOutput = composeOutput;
|
|
67
|
+
/** Container ids of a compose project, or `undefined` when the tool could not answer. */
|
|
68
|
+
const composeContainerIds = (call) => {
|
|
69
|
+
const stdout = (0, exports.composeOutput)(Object.assign(Object.assign({}, call), { args: ['ps', '-q'] }));
|
|
70
|
+
return stdout === undefined ? undefined : stdout.split('\n').filter((id) => id.trim() !== '');
|
|
71
|
+
};
|
|
72
|
+
exports.composeContainerIds = composeContainerIds;
|
|
73
|
+
const PUBLISHED_MAPPING = /(\d+)->(\d+)/g;
|
|
74
|
+
const parsePortMappings = (ports) => [...ports.matchAll(PUBLISHED_MAPPING)].map(([, host, container]) => ({
|
|
75
|
+
host: Number(host),
|
|
76
|
+
container: Number(container),
|
|
77
|
+
}));
|
|
78
|
+
const PS_FORMAT = '{{.ID}}\t{{.Names}}\t{{.Label "com.docker.compose.service"}}\t{{.Status}}\t{{.Ports}}';
|
|
79
|
+
/** True for a status the engine prints while the container runs. */
|
|
80
|
+
const isRunningStatus = (status) => /^up\b/i.test(status);
|
|
81
|
+
exports.isRunningStatus = isRunningStatus;
|
|
82
|
+
/** Every container the engine knows, with its compose service and published ports. */
|
|
83
|
+
const containerStates = (engine) => {
|
|
84
|
+
var _a;
|
|
85
|
+
const result = (0, child_process_1.spawnSync)(engine, ['ps', '-a', '--format', PS_FORMAT], { encoding: 'utf8' });
|
|
86
|
+
if (result.error || result.status !== 0)
|
|
87
|
+
return [];
|
|
88
|
+
return ((_a = result.stdout) !== null && _a !== void 0 ? _a : '')
|
|
89
|
+
.split('\n')
|
|
90
|
+
.map((line) => line.split('\t'))
|
|
91
|
+
.filter((columns) => columns.length >= 5 && columns[0])
|
|
92
|
+
.map(([id, name, service, status, ports]) => ({
|
|
93
|
+
id: id !== null && id !== void 0 ? id : '',
|
|
94
|
+
name: name !== null && name !== void 0 ? name : '',
|
|
95
|
+
service: service !== null && service !== void 0 ? service : '',
|
|
96
|
+
status: status !== null && status !== void 0 ? status : '',
|
|
97
|
+
ports: parsePortMappings(ports !== null && ports !== void 0 ? ports : ''),
|
|
98
|
+
}));
|
|
99
|
+
};
|
|
100
|
+
exports.containerStates = containerStates;
|
|
58
101
|
//# sourceMappingURL=compose.js.map
|