@grayspar/cli 0.0.0-stage → 0.0.1
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/LICENSE +202 -0
- package/README.md +76 -2
- package/dist/commands/access.js +103 -0
- package/dist/commands/deploy/archive.js +67 -0
- package/dist/commands/deploy/deploy-flags.js +54 -0
- package/dist/commands/deploy/deploy.js +366 -0
- package/dist/commands/deploy/env-files.js +63 -0
- package/dist/commands/deploy/git-state.js +22 -0
- package/dist/commands/deploy/project-name.js +13 -0
- package/dist/commands/deploy/variables-to-send.js +69 -0
- package/dist/commands/env.js +70 -0
- package/dist/commands/link.js +27 -0
- package/dist/commands/login/challenge.js +5 -0
- package/dist/commands/login/login.js +56 -0
- package/dist/commands/login/open-browser.js +15 -0
- package/dist/commands/login/sign-in-callback.js +36 -0
- package/dist/commands/logout.js +30 -0
- package/dist/commands/logs.js +84 -0
- package/dist/commands/open-path.js +45 -0
- package/dist/commands/project.js +22 -0
- package/dist/commands/restart.js +19 -0
- package/dist/commands/service.js +72 -0
- package/dist/commands/status.js +15 -0
- package/dist/commands/volume.js +73 -0
- package/dist/commands/whoami.js +16 -0
- package/dist/index.js +53 -0
- package/dist/lib/client.js +45 -0
- package/dist/lib/command-helpers.js +25 -0
- package/dist/lib/credentials.js +38 -0
- package/dist/lib/errors.js +12 -0
- package/dist/lib/follow-deployment.js +99 -0
- package/dist/lib/listening.js +24 -0
- package/dist/lib/output.js +36 -0
- package/dist/lib/project-link.js +45 -0
- package/dist/lib/prompt.js +65 -0
- package/dist/lib/resolve-project.js +56 -0
- package/dist/lib/resolve-service.js +29 -0
- package/dist/lib/resolve-team.js +31 -0
- package/dist/lib/services-table.js +28 -0
- package/dist/lib/ui.js +58 -0
- package/dist/lib/version.js +12 -0
- package/package.json +47 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,77 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Grayspar CLI
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The cloud for small software. Deploy your applications with one command, and share them with exactly the people you choose.
|
|
4
|
+
|
|
5
|
+
Grayspar builds your app, gives it its own address, and keeps it private to you until you share it. The people you share it with sign in with Google, GitHub or a code sent to their email, and the app opens. Your app needs no login code of its own.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
npm install -g @grayspar/cli
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
It needs Node 22 or newer. To run it once with nothing installed, use `npx @grayspar/cli deploy`.
|
|
14
|
+
|
|
15
|
+
## Deploy
|
|
16
|
+
|
|
17
|
+
```sh
|
|
18
|
+
grayspar login
|
|
19
|
+
grayspar deploy
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Run `grayspar deploy` in your app's directory. The first deploy asks for the project's name, which is also its address. Grayspar finds the services in it, a web front end and an API for example, builds each one and answers with the address where it runs.
|
|
23
|
+
|
|
24
|
+
A service's files reset on every deploy. To keep a folder, name it when you deploy:
|
|
25
|
+
|
|
26
|
+
```sh
|
|
27
|
+
grayspar deploy --volume app=/app/data
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
A service at the root of your directory is called `app`, and one in a subfolder takes that folder's name.
|
|
31
|
+
|
|
32
|
+
## Share
|
|
33
|
+
|
|
34
|
+
```sh
|
|
35
|
+
grayspar access add alice@company.com
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Alice gets an email with the link. Name people one by one, or a whole company at once with `@company.com`.
|
|
39
|
+
|
|
40
|
+
## For scripts and agents
|
|
41
|
+
|
|
42
|
+
Every command answers in JSON with `--json`, and `--yes` accepts what the CLI would otherwise ask. A command that needs an answer it cannot ask for refuses and names the flag that supplies it, so a script or an AI agent can run Grayspar without a terminal.
|
|
43
|
+
|
|
44
|
+
## Commands
|
|
45
|
+
|
|
46
|
+
| Command | What it does |
|
|
47
|
+
| ----------- | ------------------------------------------------------------------------------- |
|
|
48
|
+
| `login` | sign in to Grayspar from this machine |
|
|
49
|
+
| `logout` | forget the saved sign-in on this machine |
|
|
50
|
+
| `whoami` | show who this machine is signed in as |
|
|
51
|
+
| `deploy` | build a project folder and put it online |
|
|
52
|
+
| `project` | work with your projects |
|
|
53
|
+
| `access` | control who can open a project |
|
|
54
|
+
| `open-path` | paths anyone can reach without signing in, such as webhooks |
|
|
55
|
+
| `env` | set a project's environment variables |
|
|
56
|
+
| `volume` | keep a folder across deploys |
|
|
57
|
+
| `service` | change where a service answers and how it is built |
|
|
58
|
+
| `link` | bind this folder to a project |
|
|
59
|
+
| `unlink` | unbind this folder from its project |
|
|
60
|
+
| `status` | show what a project is doing |
|
|
61
|
+
| `logs` | show what a service printed while running, or with `--build` the last build log |
|
|
62
|
+
| `restart` | run a service again in place, keeping its volumes |
|
|
63
|
+
|
|
64
|
+
`grayspar <command> --help` shows each command's options.
|
|
65
|
+
|
|
66
|
+
## Versions
|
|
67
|
+
|
|
68
|
+
The CLI has a version of its own. It moves when the CLI itself changes, so a new Grayspar feature often reaches you with no update at all.
|
|
69
|
+
|
|
70
|
+
## Links
|
|
71
|
+
|
|
72
|
+
- [grayspar.com](https://grayspar.com)
|
|
73
|
+
- [Privacy Policy](https://grayspar.com/privacy/)
|
|
74
|
+
- [Terms of Service](https://grayspar.com/terms/)
|
|
75
|
+
- Support: support@grayspar.com
|
|
76
|
+
|
|
77
|
+
Licensed under the Apache License 2.0.
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/* A target starting with @ is a company and anything else is an address, so one command adds both,
|
|
2
|
+
the way one box on the dashboard does. */
|
|
3
|
+
import { Command, Option } from 'commander';
|
|
4
|
+
import { dataOrThrow, signedInClient } from '../lib/client.js';
|
|
5
|
+
import { commandAction } from '../lib/command-helpers.js';
|
|
6
|
+
import { CliError } from '../lib/errors.js';
|
|
7
|
+
import { printResult } from '../lib/output.js';
|
|
8
|
+
import { resolveProject } from '../lib/resolve-project.js';
|
|
9
|
+
import { receipt, tableOrEmptyNote, warning } from '../lib/ui.js';
|
|
10
|
+
function targetOf(value) {
|
|
11
|
+
return value.startsWith('@')
|
|
12
|
+
? { kind: 'domain', domain: value.slice(1) }
|
|
13
|
+
: { kind: 'email', email: value };
|
|
14
|
+
}
|
|
15
|
+
function labelOf(entry) {
|
|
16
|
+
return entry.kind === 'email' ? entry.email : `@${entry.domain}`;
|
|
17
|
+
}
|
|
18
|
+
function accessSentence(mode, name) {
|
|
19
|
+
return mode === 'open'
|
|
20
|
+
? `Anyone with the link can open ${name}, without signing in.`
|
|
21
|
+
: `Only the team and the people and companies on its list can open ${name}.`;
|
|
22
|
+
}
|
|
23
|
+
function addedReceipt(added, name) {
|
|
24
|
+
if (added.entry.kind === 'domain')
|
|
25
|
+
return receipt(`Added @${added.entry.domain} to ${name}`);
|
|
26
|
+
return added.told === true
|
|
27
|
+
? receipt(`Added ${added.entry.email} to ${name} and emailed the link`)
|
|
28
|
+
: warning(`Added ${added.entry.email} to ${name}, but the email did not send.`);
|
|
29
|
+
}
|
|
30
|
+
async function setGeneralAccess(mode, format) {
|
|
31
|
+
const api = await signedInClient();
|
|
32
|
+
const project = await resolveProject(api);
|
|
33
|
+
const access = await dataOrThrow(api.PUT('/api/projects/{id}/general-access', {
|
|
34
|
+
params: { path: { id: project.id } },
|
|
35
|
+
body: { mode },
|
|
36
|
+
}));
|
|
37
|
+
printResult(format, access, () => `${receipt(`Set access of ${project.name} to ${access.mode}`)}\n${accessSentence(access.mode, project.name)}`);
|
|
38
|
+
}
|
|
39
|
+
async function addAccess(targets, format) {
|
|
40
|
+
const api = await signedInClient();
|
|
41
|
+
const project = await resolveProject(api);
|
|
42
|
+
const results = [];
|
|
43
|
+
for (const target of targets) {
|
|
44
|
+
results.push(await dataOrThrow(api.POST('/api/projects/{id}/access', {
|
|
45
|
+
params: { path: { id: project.id } },
|
|
46
|
+
body: targetOf(target),
|
|
47
|
+
})));
|
|
48
|
+
}
|
|
49
|
+
printResult(format, results, () => results.map((added) => addedReceipt(added, project.name)).join('\n'));
|
|
50
|
+
}
|
|
51
|
+
async function listAccess(format) {
|
|
52
|
+
const api = await signedInClient();
|
|
53
|
+
const project = await resolveProject(api);
|
|
54
|
+
const rows = await dataOrThrow(api.GET('/api/projects/{id}/access', { params: { path: { id: project.id } } }));
|
|
55
|
+
printResult(format, rows, () => [
|
|
56
|
+
accessSentence(project.generalAccess.mode, project.name),
|
|
57
|
+
'',
|
|
58
|
+
tableOrEmptyNote(['PERSON OR COMPANY', 'STATUS'], rows.map((row) => [
|
|
59
|
+
labelOf(row),
|
|
60
|
+
row.kind === 'domain'
|
|
61
|
+
? 'anyone at this company'
|
|
62
|
+
: row.firstOpenedAt === null
|
|
63
|
+
? 'not opened yet'
|
|
64
|
+
: 'opened it',
|
|
65
|
+
]), `Nobody is named on ${project.name} yet.`),
|
|
66
|
+
].join('\n'));
|
|
67
|
+
}
|
|
68
|
+
async function removeAccess(target, format) {
|
|
69
|
+
const api = await signedInClient();
|
|
70
|
+
const project = await resolveProject(api);
|
|
71
|
+
const rows = await dataOrThrow(api.GET('/api/projects/{id}/access', { params: { path: { id: project.id } } }));
|
|
72
|
+
const wanted = target.toLowerCase();
|
|
73
|
+
const row = rows.find((candidate) => labelOf(candidate) === wanted);
|
|
74
|
+
if (row === undefined) {
|
|
75
|
+
throw new CliError('not_shared', `${target} is not on the list for ${project.name}.`);
|
|
76
|
+
}
|
|
77
|
+
await dataOrThrow(api.DELETE('/api/projects/{id}/access/{accessId}', {
|
|
78
|
+
params: { path: { id: project.id, accessId: row.id } },
|
|
79
|
+
}));
|
|
80
|
+
printResult(format, { status: 'ok', removed: labelOf(row) }, () => receipt(`Removed ${labelOf(row)} from ${project.name}`));
|
|
81
|
+
}
|
|
82
|
+
export const accessCommand = new Command('access').description('control who can open a project');
|
|
83
|
+
accessCommand
|
|
84
|
+
.command('list', { isDefault: true })
|
|
85
|
+
.description('show who can open a project')
|
|
86
|
+
.action(commandAction((format) => listAccess(format)));
|
|
87
|
+
accessCommand
|
|
88
|
+
.command('add')
|
|
89
|
+
.argument('<targets...>', 'email addresses, or @company.com for everyone at a company')
|
|
90
|
+
.description('let named people or a whole company open a project')
|
|
91
|
+
.action(commandAction((format, _command, targets) => addAccess(targets, format)));
|
|
92
|
+
accessCommand
|
|
93
|
+
.command('remove')
|
|
94
|
+
.argument('<target>', 'an email address, or @company.com')
|
|
95
|
+
.description('take someone or a company off a project')
|
|
96
|
+
.action(commandAction((format, _command, target) => removeAccess(target, format)));
|
|
97
|
+
accessCommand
|
|
98
|
+
.command('set')
|
|
99
|
+
.addOption(new Option('--mode <mode>', 'restricted lets in the people and companies on the list, open lets in anyone with the link')
|
|
100
|
+
.choices(['restricted', 'open'])
|
|
101
|
+
.makeOptionMandatory())
|
|
102
|
+
.description('choose whether the list decides who can open a project')
|
|
103
|
+
.action(commandAction((format, command) => setGeneralAccess(command.opts().mode, format)));
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/* What git ignores stays home, matched by git's own rules in every folder's .gitignore, and a .env never goes in
|
|
2
|
+
the archive, because a value landing in an image layer would sit there for as long as the image exists. */
|
|
3
|
+
import { readFileSync } from 'node:fs';
|
|
4
|
+
import { join } from 'node:path';
|
|
5
|
+
import ignore, {} from 'ignore';
|
|
6
|
+
import { create } from 'tar';
|
|
7
|
+
const ALWAYS_SKIPPED = [
|
|
8
|
+
'node_modules',
|
|
9
|
+
'.git',
|
|
10
|
+
'dist',
|
|
11
|
+
'build',
|
|
12
|
+
'out',
|
|
13
|
+
'target',
|
|
14
|
+
'vendor',
|
|
15
|
+
'.venv',
|
|
16
|
+
'.next',
|
|
17
|
+
'.turbo',
|
|
18
|
+
'coverage',
|
|
19
|
+
];
|
|
20
|
+
const ENV_FILE_PATTERN = /(^|\/)\.env(\..+)?$/;
|
|
21
|
+
function readOrEmpty(path) {
|
|
22
|
+
try {
|
|
23
|
+
return readFileSync(path, 'utf8');
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
return '';
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
function ignoredBy(root) {
|
|
30
|
+
const rootRules = ignore()
|
|
31
|
+
.add(ALWAYS_SKIPPED)
|
|
32
|
+
.add(readOrEmpty(join(root, '.gitignore')))
|
|
33
|
+
.add(readOrEmpty(join(root, '.dockerignore')));
|
|
34
|
+
const nested = new Map();
|
|
35
|
+
function rulesIn(folder) {
|
|
36
|
+
if (!nested.has(folder)) {
|
|
37
|
+
const raw = readOrEmpty(join(root, folder, '.gitignore'));
|
|
38
|
+
nested.set(folder, raw === '' ? null : ignore().add(raw));
|
|
39
|
+
}
|
|
40
|
+
return nested.get(folder) ?? null;
|
|
41
|
+
}
|
|
42
|
+
return (path, isDirectory) => {
|
|
43
|
+
const asked = isDirectory ? `${path}/` : path;
|
|
44
|
+
if (ENV_FILE_PATTERN.test(path) || rootRules.ignores(asked))
|
|
45
|
+
return true;
|
|
46
|
+
const folders = path.split('/').slice(0, -1);
|
|
47
|
+
return folders.some((_, index) => {
|
|
48
|
+
const folder = folders.slice(0, index + 1).join('/');
|
|
49
|
+
return rulesIn(folder)?.ignores(asked.slice(folder.length + 1)) === true;
|
|
50
|
+
});
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
export async function archiveOf(root) {
|
|
54
|
+
const ignored = ignoredBy(root);
|
|
55
|
+
const chunks = [];
|
|
56
|
+
const stream = create({
|
|
57
|
+
cwd: root,
|
|
58
|
+
gzip: true,
|
|
59
|
+
filter: (path, entry) => {
|
|
60
|
+
const relative = path.replace(/^\.\/?/, '');
|
|
61
|
+
return relative === '' || !ignored(relative, 'isDirectory' in entry && entry.isDirectory());
|
|
62
|
+
},
|
|
63
|
+
}, ['.']);
|
|
64
|
+
for await (const chunk of stream)
|
|
65
|
+
chunks.push(Buffer.from(chunk));
|
|
66
|
+
return Buffer.concat(chunks);
|
|
67
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { CliError } from '../../lib/errors.js';
|
|
2
|
+
const EXAMPLE_VALUE = {
|
|
3
|
+
'--path': '/api',
|
|
4
|
+
'--dockerfile': 'docker/Dockerfile',
|
|
5
|
+
'--volume': '/app/data',
|
|
6
|
+
};
|
|
7
|
+
function servicePairs(values, flag, onlyServices) {
|
|
8
|
+
return values.map((value) => {
|
|
9
|
+
const separatorIndex = value.indexOf('=');
|
|
10
|
+
if (separatorIndex < 1) {
|
|
11
|
+
throw new CliError('bad_flag', `Write ${flag} as a service and a value, like ${flag} backend=${EXAMPLE_VALUE[flag]}.`, flag);
|
|
12
|
+
}
|
|
13
|
+
const name = value.slice(0, separatorIndex);
|
|
14
|
+
if (onlyServices.length > 0 && !onlyServices.includes(name)) {
|
|
15
|
+
throw new CliError('bad_flag', `${flag} ${value} is for ${name}, which --service leaves out. Add --service ${name}.`, '--service');
|
|
16
|
+
}
|
|
17
|
+
return [name, value.slice(separatorIndex + 1)];
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
export function parseDeployFlags(flags) {
|
|
21
|
+
const volumes = new Map();
|
|
22
|
+
for (const [name, path] of servicePairs(flags.volumes, '--volume', flags.services)) {
|
|
23
|
+
volumes.set(name, [...(volumes.get(name) ?? []), path]);
|
|
24
|
+
}
|
|
25
|
+
return {
|
|
26
|
+
onlyServices: flags.services,
|
|
27
|
+
paths: new Map(servicePairs(flags.paths, '--path', flags.services)),
|
|
28
|
+
dockerfiles: new Map(servicePairs(flags.dockerfiles, '--dockerfile', flags.services)),
|
|
29
|
+
volumes,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
export function servicesToSend(found, serviceFlags) {
|
|
33
|
+
const deploying = serviceFlags.onlyServices.length > 0
|
|
34
|
+
? serviceFlags.onlyServices
|
|
35
|
+
: [
|
|
36
|
+
...new Set([
|
|
37
|
+
...found,
|
|
38
|
+
...serviceFlags.paths.keys(),
|
|
39
|
+
...serviceFlags.dockerfiles.keys(),
|
|
40
|
+
...serviceFlags.volumes.keys(),
|
|
41
|
+
]),
|
|
42
|
+
];
|
|
43
|
+
return deploying.map((name) => {
|
|
44
|
+
const pathPrefix = serviceFlags.paths.get(name);
|
|
45
|
+
const dockerfile = serviceFlags.dockerfiles.get(name);
|
|
46
|
+
const volumes = serviceFlags.volumes.get(name);
|
|
47
|
+
return {
|
|
48
|
+
name,
|
|
49
|
+
...(pathPrefix === undefined ? {} : { pathPrefix }),
|
|
50
|
+
...(dockerfile === undefined ? {} : { dockerfile }),
|
|
51
|
+
...(volumes === undefined ? {} : { volumes }),
|
|
52
|
+
};
|
|
53
|
+
});
|
|
54
|
+
}
|