create-gato-app 0.0.0-stage → 0.1.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 +201 -0
- package/NOTICE +15 -0
- package/README.md +118 -2
- package/dist/args.js +118 -0
- package/dist/cli.js +93 -0
- package/dist/delegate.js +12 -0
- package/dist/gato-bin.js +18 -0
- package/dist/github.js +113 -0
- package/dist/index.js +32 -0
- package/dist/kit-download.js +33 -0
- package/dist/kit-version.js +30 -0
- package/dist/node-version.js +93 -0
- package/dist/process.js +49 -0
- package/dist/project-name.js +8 -0
- package/package.json +65 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2024-2026 Web Amigos
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/NOTICE
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
GatoJS
|
|
2
|
+
Copyright 2026 Web Amigos
|
|
3
|
+
|
|
4
|
+
This product includes software developed by Web Amigos and the GatoJS
|
|
5
|
+
contributors.
|
|
6
|
+
|
|
7
|
+
Licensed under the Apache License, Version 2.0. See the LICENSE file for the
|
|
8
|
+
full terms.
|
|
9
|
+
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
src/components/ui contains components copied from shadcn/ui, which is
|
|
13
|
+
distributed under the MIT License. The notice is in src/components/ui/LICENSE,
|
|
14
|
+
which is copied into every project assembled from the kit together with the
|
|
15
|
+
components.
|
package/README.md
CHANGED
|
@@ -1,3 +1,119 @@
|
|
|
1
|
-
#
|
|
1
|
+
# create-gato-app
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Create a new [GatoJS](https://github.com/webamigos/gatojs) project, the open-source Next.js kit, with one command:
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
npx create-gato-app my-app
|
|
7
|
+
# or
|
|
8
|
+
npm create gato-app@latest my-app
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
You need Node.js 22 or newer and `git` (`gato create` lists the kit files with `git ls-files`).
|
|
12
|
+
|
|
13
|
+
## What it does
|
|
14
|
+
|
|
15
|
+
1. **Checks Node** against the supported range (`>=22`). An unsupported Node stops the command before
|
|
16
|
+
anything is downloaded, with a message saying whether it is too old or too new. `--skip-install` (or `--no-install`)
|
|
17
|
+
turns the refusal into a warning, because nothing is installed then. `--yes` does not bypass the check.
|
|
18
|
+
2. **Picks the kit version:** `--kit-version <x.y.z>`, or the highest `v<x.y.z>` tag of `webamigos/gatojs`
|
|
19
|
+
(GitHub tags API; prerelease and other tags are ignored).
|
|
20
|
+
3. **Downloads the kit** tag tarball into a temporary directory and extracts it with the system `tar`. No clone, no git
|
|
21
|
+
history.
|
|
22
|
+
4. **Runs `gato create`** from the `gato-cli` package that `create-gato-app` depends on at an exact version
|
|
23
|
+
(`node <gato-cli>/dist/gato.mjs create <dir> … --kit <kit>`), with your terminal attached, so its prompts and flags
|
|
24
|
+
work exactly as documented for `gato create`. The exit code is `gato create`'s. The new project gets
|
|
25
|
+
`"gato-cli": "^<that version>"` in `devDependencies`. The kit's own `.wa/bin/wa.mjs` is not used.
|
|
26
|
+
5. **Removes the temporary directory**, also when something fails.
|
|
27
|
+
|
|
28
|
+
## Flags
|
|
29
|
+
|
|
30
|
+
Flags of `create-gato-app` itself:
|
|
31
|
+
|
|
32
|
+
| Flag | Meaning |
|
|
33
|
+
| ----------------------- | ------------------------------------------------------------------------------------------------------------------- |
|
|
34
|
+
| `--kit-version <x.y.z>` | Kit version (tag `v<x.y.z>`). Default: the highest `v<x.y.z>` tag. |
|
|
35
|
+
| `--kit <path>` | Use a local kit checkout instead of downloading one (kit development, CI). Cannot be combined with `--kit-version`. |
|
|
36
|
+
| `--skip-install` | Write files only: passes `--no-install` to `gato create` and turns the Node refusal into a warning. |
|
|
37
|
+
| `--help`, `-h` | Print usage. |
|
|
38
|
+
| `--version`, `-v` | Print the `create-gato-app` version. |
|
|
39
|
+
|
|
40
|
+
Every other argument goes to `gato create` unchanged, for example:
|
|
41
|
+
|
|
42
|
+
| Flag | Meaning |
|
|
43
|
+
| ----------------------- | ------------------------------------------------------------- |
|
|
44
|
+
| `--modules a,b` | Kit modules besides the core (`--modules ""` = core only). |
|
|
45
|
+
| `--locales pl,en` | App locales (`pl` required). |
|
|
46
|
+
| `--title <text>` | Display name. |
|
|
47
|
+
| `--admin-email <email>` | First admin's email. |
|
|
48
|
+
| `--yes` | No questions; defaults for everything not given. |
|
|
49
|
+
| `--setup` | After install: start the database, migrate, create the admin. |
|
|
50
|
+
| `--no-install` | Skip `npm install`. |
|
|
51
|
+
| `--no-git` | Skip `git init` and the first commit. |
|
|
52
|
+
| `--cli-source <tgz>` | The project's `gato-cli` from a packed tarball (`file:`), for CI. |
|
|
53
|
+
|
|
54
|
+
Examples:
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
npx create-gato-app my-app --yes --modules uploads,api-keys
|
|
58
|
+
npx create-gato-app my-app --kit-version 0.1.0 --skip-install
|
|
59
|
+
npx create-gato-app my-app --kit ../gatojs --yes --no-install --no-git
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## GitHub token
|
|
63
|
+
|
|
64
|
+
`webamigos/gatojs` is public, so `create-gato-app` works without a token. Anonymous requests to the GitHub API are
|
|
65
|
+
rate limited (60 per hour); a token raises the limit. `create-gato-app` sends a token from, in order:
|
|
66
|
+
|
|
67
|
+
1. `GITHUB_TOKEN`,
|
|
68
|
+
2. `GH_TOKEN`,
|
|
69
|
+
3. `gh auth token`, when the [GitHub CLI](https://cli.github.com) is installed and logged in.
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
GITHUB_TOKEN=$(gh auth token) npx create-gato-app my-app
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
The token is only sent to `api.github.com`; it is never printed. When GitHub rejects the token (401),
|
|
76
|
+
`create-gato-app` says so and retries once without it. On a 403 or 429 (rate limit), set a token or pass
|
|
77
|
+
`--kit-version`.
|
|
78
|
+
|
|
79
|
+
## Project name
|
|
80
|
+
|
|
81
|
+
The last segment of `<dir>` becomes the project name: lowercase letters, digits and hyphens, starting with a letter,
|
|
82
|
+
2-50 characters. `create-gato-app` checks it before it downloads anything.
|
|
83
|
+
|
|
84
|
+
## Not yet
|
|
85
|
+
|
|
86
|
+
This version installs a project; it is not the full wizard yet. Planned (spec
|
|
87
|
+
`docs/superpowers/specs/2026-11-21-gato-cli-design.md` §5–§7 in the GatoJS repository):
|
|
88
|
+
|
|
89
|
+
- an interactive wizard (`@clack/prompts`) with module descriptions from the chosen kit version, locales, title, admin
|
|
90
|
+
email, and the storage provider for `uploads` (`local`, or `s3` with endpoint and keys);
|
|
91
|
+
- validation and escaping of `--title` and `--admin-email`;
|
|
92
|
+
- generated secrets for every manifest variable with a `generate` field (`secret-32`, `secret-64`);
|
|
93
|
+
- `COMPOSE_PROJECT_NAME=<slug>-<6 random characters>` in `.env`, port probing before `docker compose up`, `--skip-docker`;
|
|
94
|
+
- the default kit version from GitHub Releases filtered by `kitFormat`, and the `kitFormat` compatibility check;
|
|
95
|
+
- next steps that list only what the wizard did not do.
|
|
96
|
+
|
|
97
|
+
## Development
|
|
98
|
+
|
|
99
|
+
```bash
|
|
100
|
+
npm ci # in the repository root; this package is a workspace
|
|
101
|
+
npm run verify --prefix packages/create-gato-app # lint, typecheck, unit tests, build
|
|
102
|
+
SMOKE_INSTALL=1 bash packages/create-gato-app/scripts/smoke-pack.sh "$PWD"
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
The smoke script packs `gato-cli` and `create-gato-app`, installs both tarballs into an empty prefix, creates projects
|
|
106
|
+
from this checkout (one with `--cli-source <gato-cli tarball>`, one without), and checks versions, the `gato-cli`
|
|
107
|
+
tarball's file list and the exact pin. `SMOKE_INSTALL=1` also runs `npm install` in the project and checks that its
|
|
108
|
+
`gato` is the packed one. CI runs the same script in `.github/workflows/packages.yml`.
|
|
109
|
+
|
|
110
|
+
## Publishing
|
|
111
|
+
|
|
112
|
+
`create-gato-app` depends on `gato-cli` at an exact version, which must equal `packages/gato-cli/package.json`
|
|
113
|
+
(a unit test and CI check it). When both change, publish `gato-cli` first and wait until its staged version is
|
|
114
|
+
approved and live; `publish-packages.yml` refuses to publish `create-gato-app` before that. The runbook is in
|
|
115
|
+
`kit/CLAUDE.md` of the GatoJS repository.
|
|
116
|
+
|
|
117
|
+
## License
|
|
118
|
+
|
|
119
|
+
Apache-2.0
|
package/dist/args.js
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
export const USAGE = [
|
|
2
|
+
"Usage: create-gato-app <dir> [options]",
|
|
3
|
+
"",
|
|
4
|
+
"Creates a GatoJS project: downloads the kit and runs `gato create` from gato-cli.",
|
|
5
|
+
"",
|
|
6
|
+
"Options of create-gato-app:",
|
|
7
|
+
" --kit-version <x.y.z> kit version (tag v<x.y.z>); default: the highest v<x.y.z> tag",
|
|
8
|
+
" --kit <path> use a local kit checkout instead of downloading one",
|
|
9
|
+
" --skip-install write files only (passes --no-install); Node check only warns",
|
|
10
|
+
" -h, --help print this help",
|
|
11
|
+
" -v, --version print the create-gato-app version",
|
|
12
|
+
"",
|
|
13
|
+
"Other options go to `gato create`: --modules a,b --locales pl,en --title <text>",
|
|
14
|
+
" --admin-email <email> --yes --setup --no-install --no-git",
|
|
15
|
+
" --cli-source <tarball> (the project's gato-cli from a packed tarball, for CI)",
|
|
16
|
+
"",
|
|
17
|
+
"Rate limits: set GITHUB_TOKEN or GH_TOKEN, or log in with `gh auth login`.",
|
|
18
|
+
].join("\n");
|
|
19
|
+
const KIT_VERSION_PATTERN = /^v?((?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*))$/;
|
|
20
|
+
const GATO_CREATE_VALUE_OPTIONS = new Set([
|
|
21
|
+
"--modules",
|
|
22
|
+
"--locales",
|
|
23
|
+
"--title",
|
|
24
|
+
"--admin-email",
|
|
25
|
+
"--cli-source",
|
|
26
|
+
]);
|
|
27
|
+
const UNSUPPORTED_FLAGS = new Set(["--skip-docker"]);
|
|
28
|
+
const NO_INSTALL = "--no-install";
|
|
29
|
+
const MISSING_VALUE_MESSAGES = {
|
|
30
|
+
"--kit-version": "--kit-version needs a value, e.g. --kit-version 0.1.0",
|
|
31
|
+
"--kit": "--kit needs a path",
|
|
32
|
+
};
|
|
33
|
+
function ownValueFlagOf(arg) {
|
|
34
|
+
for (const flag of ["--kit-version", "--kit"]) {
|
|
35
|
+
if (arg === flag || arg.startsWith(`${flag}=`)) {
|
|
36
|
+
return flag;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
function parseKitVersion(value) {
|
|
42
|
+
const match = KIT_VERSION_PATTERN.exec(value);
|
|
43
|
+
if (!match) {
|
|
44
|
+
throw new Error(`--kit-version: expected x.y.z, got "${value}"`);
|
|
45
|
+
}
|
|
46
|
+
return match[1];
|
|
47
|
+
}
|
|
48
|
+
export function parseCliArgs(argv) {
|
|
49
|
+
if (argv.includes("--help") || argv.includes("-h")) {
|
|
50
|
+
return { kind: "help" };
|
|
51
|
+
}
|
|
52
|
+
if (argv.includes("--version") || argv.includes("-v")) {
|
|
53
|
+
return { kind: "version" };
|
|
54
|
+
}
|
|
55
|
+
const values = new Map();
|
|
56
|
+
const passthrough = [];
|
|
57
|
+
const positionals = [];
|
|
58
|
+
let install = true;
|
|
59
|
+
for (let index = 0; index < argv.length; index += 1) {
|
|
60
|
+
const arg = argv[index];
|
|
61
|
+
const ownFlag = ownValueFlagOf(arg);
|
|
62
|
+
if (ownFlag !== null) {
|
|
63
|
+
let value;
|
|
64
|
+
if (arg.includes("=")) {
|
|
65
|
+
value = arg.slice(arg.indexOf("=") + 1);
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
value = argv[index + 1];
|
|
69
|
+
if (value !== undefined && !value.startsWith("-")) {
|
|
70
|
+
index += 1;
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
value = undefined;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
if (value === undefined || value === "") {
|
|
77
|
+
throw new Error(MISSING_VALUE_MESSAGES[ownFlag]);
|
|
78
|
+
}
|
|
79
|
+
if (values.has(ownFlag)) {
|
|
80
|
+
throw new Error(`${ownFlag} given more than once`);
|
|
81
|
+
}
|
|
82
|
+
values.set(ownFlag, value);
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
if (UNSUPPORTED_FLAGS.has(arg)) {
|
|
86
|
+
throw new Error(`${arg} is not supported yet`);
|
|
87
|
+
}
|
|
88
|
+
if (arg === "--skip-install" || arg === NO_INSTALL) {
|
|
89
|
+
if (install) {
|
|
90
|
+
passthrough.push(NO_INSTALL);
|
|
91
|
+
}
|
|
92
|
+
install = false;
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
passthrough.push(arg);
|
|
96
|
+
if (GATO_CREATE_VALUE_OPTIONS.has(arg)) {
|
|
97
|
+
const value = argv[index + 1];
|
|
98
|
+
if (value !== undefined) {
|
|
99
|
+
passthrough.push(value);
|
|
100
|
+
index += 1;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
else if (!arg.startsWith("-")) {
|
|
104
|
+
positionals.push(arg);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
const kitVersionValue = values.get("--kit-version");
|
|
108
|
+
const kitPath = values.get("--kit") ?? null;
|
|
109
|
+
if (kitVersionValue !== undefined && kitPath !== null) {
|
|
110
|
+
throw new Error("--kit and --kit-version cannot be used together");
|
|
111
|
+
}
|
|
112
|
+
const kitVersion = kitVersionValue === undefined ? null : parseKitVersion(kitVersionValue);
|
|
113
|
+
const [target] = positionals;
|
|
114
|
+
if (target === undefined || target === "") {
|
|
115
|
+
throw new Error(`Missing project directory.\n${USAGE}`);
|
|
116
|
+
}
|
|
117
|
+
return { kind: "create", target, kitVersion, kitPath, install, passthrough };
|
|
118
|
+
}
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { resolve } from "node:path";
|
|
2
|
+
import { parseCliArgs, USAGE } from "./args.js";
|
|
3
|
+
import { gatoCreateCommand } from "./delegate.js";
|
|
4
|
+
import { GitHubTokenRejectedError, resolveKitVersion, resolveToken, } from "./github.js";
|
|
5
|
+
import { downloadKit } from "./kit-download.js";
|
|
6
|
+
import { checkNodeVersion } from "./node-version.js";
|
|
7
|
+
import { assertProjectName } from "./project-name.js";
|
|
8
|
+
async function delegate(deps, kitDir, passthrough) {
|
|
9
|
+
const { command, args } = gatoCreateCommand({
|
|
10
|
+
nodePath: deps.nodePath,
|
|
11
|
+
gatoBin: deps.gatoBin,
|
|
12
|
+
kitDir,
|
|
13
|
+
passthrough,
|
|
14
|
+
});
|
|
15
|
+
const result = await deps.spawn(command, args, {
|
|
16
|
+
cwd: deps.cwd,
|
|
17
|
+
stdio: "inherit",
|
|
18
|
+
});
|
|
19
|
+
return result.code;
|
|
20
|
+
}
|
|
21
|
+
const TOKEN_RETRY_WARNING = "GitHub rejected the token (401); retrying without it.";
|
|
22
|
+
async function downloadAndDelegate(deps, requested, passthrough, token) {
|
|
23
|
+
const version = await resolveKitVersion({
|
|
24
|
+
requested,
|
|
25
|
+
fetch: deps.fetch,
|
|
26
|
+
token,
|
|
27
|
+
});
|
|
28
|
+
deps.log(`Downloading GatoJS kit v${version}…`);
|
|
29
|
+
const workDir = await deps.makeTempDir();
|
|
30
|
+
try {
|
|
31
|
+
const kitDir = await downloadKit({
|
|
32
|
+
version,
|
|
33
|
+
token,
|
|
34
|
+
fetch: deps.fetch,
|
|
35
|
+
spawn: deps.spawn,
|
|
36
|
+
workDir,
|
|
37
|
+
});
|
|
38
|
+
return await delegate(deps, kitDir, passthrough);
|
|
39
|
+
}
|
|
40
|
+
finally {
|
|
41
|
+
await deps.removeDir(workDir);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
async function createFromDownload(deps, requested, passthrough) {
|
|
45
|
+
const token = await resolveToken({
|
|
46
|
+
env: deps.env,
|
|
47
|
+
ghAuthToken: deps.ghAuthToken,
|
|
48
|
+
});
|
|
49
|
+
try {
|
|
50
|
+
return await downloadAndDelegate(deps, requested, passthrough, token);
|
|
51
|
+
}
|
|
52
|
+
catch (error) {
|
|
53
|
+
if (!(error instanceof GitHubTokenRejectedError)) {
|
|
54
|
+
throw error;
|
|
55
|
+
}
|
|
56
|
+
// WHY: the kit repository is public, so a stale or wrong token should not block the download.
|
|
57
|
+
deps.error(TOKEN_RETRY_WARNING);
|
|
58
|
+
return await downloadAndDelegate(deps, requested, passthrough, null);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
export async function run(argv, deps) {
|
|
62
|
+
try {
|
|
63
|
+
const args = parseCliArgs(argv);
|
|
64
|
+
if (args.kind === "help") {
|
|
65
|
+
deps.log(USAGE);
|
|
66
|
+
return 0;
|
|
67
|
+
}
|
|
68
|
+
if (args.kind === "version") {
|
|
69
|
+
deps.log(deps.packageVersion);
|
|
70
|
+
return 0;
|
|
71
|
+
}
|
|
72
|
+
assertProjectName(deps.cwd, args.target);
|
|
73
|
+
const verdict = checkNodeVersion({
|
|
74
|
+
version: deps.nodeVersion,
|
|
75
|
+
willInstall: args.install,
|
|
76
|
+
});
|
|
77
|
+
if (verdict.kind === "refuse") {
|
|
78
|
+
deps.error(verdict.message);
|
|
79
|
+
return 1;
|
|
80
|
+
}
|
|
81
|
+
if (verdict.kind === "warn") {
|
|
82
|
+
deps.error(verdict.message);
|
|
83
|
+
}
|
|
84
|
+
if (args.kitPath !== null) {
|
|
85
|
+
return await delegate(deps, resolve(deps.cwd, args.kitPath), args.passthrough);
|
|
86
|
+
}
|
|
87
|
+
return await createFromDownload(deps, args.kitVersion, args.passthrough);
|
|
88
|
+
}
|
|
89
|
+
catch (error) {
|
|
90
|
+
deps.error(error instanceof Error ? error.message : String(error));
|
|
91
|
+
return 1;
|
|
92
|
+
}
|
|
93
|
+
}
|
package/dist/delegate.js
ADDED
package/dist/gato-bin.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { dirname, join } from "node:path";
|
|
2
|
+
function gatoEntryOf(packageJson) {
|
|
3
|
+
if (typeof packageJson !== "object" || packageJson === null) {
|
|
4
|
+
return undefined;
|
|
5
|
+
}
|
|
6
|
+
const bin = packageJson.bin;
|
|
7
|
+
if (typeof bin !== "object" || bin === null) {
|
|
8
|
+
return undefined;
|
|
9
|
+
}
|
|
10
|
+
return bin.gato;
|
|
11
|
+
}
|
|
12
|
+
export function gatoBinPath(packageJsonPath, packageJson) {
|
|
13
|
+
const entry = gatoEntryOf(packageJson);
|
|
14
|
+
if (typeof entry !== "string") {
|
|
15
|
+
throw new Error(`gato-cli at ${packageJsonPath} has no "gato" bin; reinstall create-gato-app`);
|
|
16
|
+
}
|
|
17
|
+
return join(dirname(packageJsonPath), entry);
|
|
18
|
+
}
|
package/dist/github.js
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { highestSemverTag } from "./kit-version.js";
|
|
2
|
+
export const KIT_REPO = "webamigos/gatojs";
|
|
3
|
+
const TAGS_PAGE_SIZE = 100;
|
|
4
|
+
export class GitHubTokenRejectedError extends Error {
|
|
5
|
+
name = "GitHubTokenRejectedError";
|
|
6
|
+
}
|
|
7
|
+
export function githubHeaders(token) {
|
|
8
|
+
const headers = {
|
|
9
|
+
"User-Agent": "create-gato-app",
|
|
10
|
+
Accept: "application/vnd.github+json",
|
|
11
|
+
"X-GitHub-Api-Version": "2022-11-28",
|
|
12
|
+
};
|
|
13
|
+
if (token !== null) {
|
|
14
|
+
headers.Authorization = `Bearer ${token}`;
|
|
15
|
+
}
|
|
16
|
+
return headers;
|
|
17
|
+
}
|
|
18
|
+
export function tagsUrl(page) {
|
|
19
|
+
return `https://api.github.com/repos/${KIT_REPO}/tags?per_page=${TAGS_PAGE_SIZE}&page=${page}`;
|
|
20
|
+
}
|
|
21
|
+
export function tarballUrl(version, token) {
|
|
22
|
+
return token === null
|
|
23
|
+
? `https://codeload.github.com/${KIT_REPO}/tar.gz/refs/tags/v${version}`
|
|
24
|
+
: `https://api.github.com/repos/${KIT_REPO}/tarball/refs/tags/v${version}`;
|
|
25
|
+
}
|
|
26
|
+
function nonEmpty(value) {
|
|
27
|
+
const trimmed = value?.trim();
|
|
28
|
+
return trimmed ? trimmed : null;
|
|
29
|
+
}
|
|
30
|
+
export async function resolveToken(input) {
|
|
31
|
+
const fromEnv = nonEmpty(input.env.GITHUB_TOKEN) ?? nonEmpty(input.env.GH_TOKEN);
|
|
32
|
+
if (fromEnv !== null) {
|
|
33
|
+
return fromEnv;
|
|
34
|
+
}
|
|
35
|
+
try {
|
|
36
|
+
return nonEmpty(await input.ghAuthToken());
|
|
37
|
+
}
|
|
38
|
+
catch {
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
function httpErrorMessage(status, what, token) {
|
|
43
|
+
const prefix = `GitHub returned ${status} for ${what}.`;
|
|
44
|
+
if (status === 404 && token === null) {
|
|
45
|
+
return `${prefix} Either it does not exist, or the repository ${KIT_REPO} may be private: set GITHUB_TOKEN (or GH_TOKEN) to a token with access, or log in with "gh auth login".`;
|
|
46
|
+
}
|
|
47
|
+
if (status === 404) {
|
|
48
|
+
return `${prefix} Check that the version exists and that your token can read ${KIT_REPO}.`;
|
|
49
|
+
}
|
|
50
|
+
if (status === 401) {
|
|
51
|
+
return `${prefix} GitHub rejected the token: check GITHUB_TOKEN / GH_TOKEN or "gh auth status".`;
|
|
52
|
+
}
|
|
53
|
+
if (status === 403 || status === 429) {
|
|
54
|
+
return `${prefix} This is a rate limit or missing access: set GITHUB_TOKEN, or pass --kit-version <x.y.z>.`;
|
|
55
|
+
}
|
|
56
|
+
return prefix;
|
|
57
|
+
}
|
|
58
|
+
async function request(fetch, url, token, what) {
|
|
59
|
+
let response;
|
|
60
|
+
try {
|
|
61
|
+
response = await fetch(url, { headers: githubHeaders(token) });
|
|
62
|
+
}
|
|
63
|
+
catch (error) {
|
|
64
|
+
const detail = error instanceof Error ? error.message : String(error);
|
|
65
|
+
throw new Error(`Could not reach GitHub for ${what}: ${detail}`, {
|
|
66
|
+
cause: error,
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
if (response.status === 401 && token !== null) {
|
|
70
|
+
throw new GitHubTokenRejectedError(httpErrorMessage(response.status, what, token));
|
|
71
|
+
}
|
|
72
|
+
if (!response.ok) {
|
|
73
|
+
throw new Error(httpErrorMessage(response.status, what, token));
|
|
74
|
+
}
|
|
75
|
+
return response;
|
|
76
|
+
}
|
|
77
|
+
function tagNamesOf(page) {
|
|
78
|
+
if (!Array.isArray(page)) {
|
|
79
|
+
throw new Error("GitHub returned an unexpected tag list");
|
|
80
|
+
}
|
|
81
|
+
return page.map((tag) => {
|
|
82
|
+
const name = tag?.name;
|
|
83
|
+
if (typeof name !== "string") {
|
|
84
|
+
throw new Error("GitHub returned an unexpected tag list");
|
|
85
|
+
}
|
|
86
|
+
return name;
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
export async function fetchTagNames(input) {
|
|
90
|
+
const names = [];
|
|
91
|
+
for (let page = 1;; page += 1) {
|
|
92
|
+
const response = await request(input.fetch, tagsUrl(page), input.token, "the tag list");
|
|
93
|
+
const pageNames = tagNamesOf(await response.json());
|
|
94
|
+
names.push(...pageNames);
|
|
95
|
+
if (pageNames.length < TAGS_PAGE_SIZE) {
|
|
96
|
+
return names;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
export async function resolveKitVersion(input) {
|
|
101
|
+
if (input.requested !== null) {
|
|
102
|
+
return input.requested;
|
|
103
|
+
}
|
|
104
|
+
const highest = highestSemverTag(await fetchTagNames(input));
|
|
105
|
+
if (highest === null) {
|
|
106
|
+
throw new Error(`No v<x.y.z> tag found in ${KIT_REPO}; pass --kit-version <x.y.z> or --kit <path>.`);
|
|
107
|
+
}
|
|
108
|
+
return highest;
|
|
109
|
+
}
|
|
110
|
+
export async function fetchKitTarball(input) {
|
|
111
|
+
const response = await request(input.fetch, tarballUrl(input.version, input.token), input.token, `kit v${input.version}`);
|
|
112
|
+
return new Uint8Array(await response.arrayBuffer());
|
|
113
|
+
}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { readFileSync } from "node:fs";
|
|
3
|
+
import { createRequire } from "node:module";
|
|
4
|
+
import { mkdtemp, rm } from "node:fs/promises";
|
|
5
|
+
import { tmpdir } from "node:os";
|
|
6
|
+
import { join } from "node:path";
|
|
7
|
+
import { run } from "./cli.js";
|
|
8
|
+
import { gatoBinPath } from "./gato-bin.js";
|
|
9
|
+
import { ghAuthToken, spawnProcess } from "./process.js";
|
|
10
|
+
const packageJson = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8"));
|
|
11
|
+
const gatoPackageJsonPath = createRequire(import.meta.url).resolve("gato-cli/package.json");
|
|
12
|
+
const gatoBin = gatoBinPath(gatoPackageJsonPath, JSON.parse(readFileSync(gatoPackageJsonPath, "utf8")));
|
|
13
|
+
run(process.argv.slice(2), {
|
|
14
|
+
nodeVersion: process.version,
|
|
15
|
+
nodePath: process.execPath,
|
|
16
|
+
gatoBin,
|
|
17
|
+
env: process.env,
|
|
18
|
+
cwd: process.cwd(),
|
|
19
|
+
packageVersion: packageJson.version,
|
|
20
|
+
fetch: (url, init) => fetch(url, init),
|
|
21
|
+
spawn: spawnProcess,
|
|
22
|
+
ghAuthToken,
|
|
23
|
+
makeTempDir: () => mkdtemp(join(tmpdir(), "create-gato-app-")),
|
|
24
|
+
removeDir: (dir) => rm(dir, { recursive: true, force: true }),
|
|
25
|
+
log: (line) => console.log(line),
|
|
26
|
+
error: (line) => console.error(line),
|
|
27
|
+
}).then((code) => {
|
|
28
|
+
process.exitCode = code;
|
|
29
|
+
}, (error) => {
|
|
30
|
+
console.error(error instanceof Error ? error.message : error);
|
|
31
|
+
process.exitCode = 1;
|
|
32
|
+
});
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { mkdir, writeFile } from "node:fs/promises";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { fetchKitTarball } from "./github.js";
|
|
4
|
+
const GIT_REQUIRED = "create-gato-app needs git to read the kit files (`gato create` lists them with git ls-files)";
|
|
5
|
+
async function runGit(spawn, args, cwd) {
|
|
6
|
+
let result;
|
|
7
|
+
try {
|
|
8
|
+
result = await spawn("git", args, { cwd, stdio: "pipe" });
|
|
9
|
+
}
|
|
10
|
+
catch (error) {
|
|
11
|
+
const detail = error instanceof Error ? error.message : String(error);
|
|
12
|
+
throw new Error(`${GIT_REQUIRED}: ${detail}`, { cause: error });
|
|
13
|
+
}
|
|
14
|
+
if (result.code !== 0) {
|
|
15
|
+
throw new Error(`${GIT_REQUIRED}: git ${args.join(" ")} failed: ${result.stderr.trim()}`);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
export async function downloadKit(input) {
|
|
19
|
+
const bytes = await fetchKitTarball(input);
|
|
20
|
+
const tarballPath = join(input.workDir, "kit.tar.gz");
|
|
21
|
+
const kitDir = join(input.workDir, "kit");
|
|
22
|
+
await writeFile(tarballPath, bytes);
|
|
23
|
+
await mkdir(kitDir);
|
|
24
|
+
const extracted = await input.spawn("tar", ["-xzf", tarballPath, "-C", kitDir, "--strip-components=1"], { stdio: "pipe" });
|
|
25
|
+
if (extracted.code !== 0) {
|
|
26
|
+
throw new Error(`Could not extract the kit tarball: ${extracted.stderr.trim()}`);
|
|
27
|
+
}
|
|
28
|
+
// WHY: a tarball has no .git, and `gato create` lists kit files with git ls-files; the tarball holds exactly
|
|
29
|
+
// the tracked files, so -f also keeps files that the kit's .gitignore matches but git tracks.
|
|
30
|
+
await runGit(input.spawn, ["init", "-q"], kitDir);
|
|
31
|
+
await runGit(input.spawn, ["add", "-A", "-f"], kitDir);
|
|
32
|
+
return kitDir;
|
|
33
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
const SEMVER_TAG_PATTERN = /^v(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$/;
|
|
2
|
+
function parseTag(name) {
|
|
3
|
+
const match = SEMVER_TAG_PATTERN.exec(name);
|
|
4
|
+
if (!match) {
|
|
5
|
+
return null;
|
|
6
|
+
}
|
|
7
|
+
return {
|
|
8
|
+
text: name.slice(1),
|
|
9
|
+
parts: [Number(match[1]), Number(match[2]), Number(match[3])],
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
function isGreater(a, b) {
|
|
13
|
+
for (let index = 0; index < 3; index += 1) {
|
|
14
|
+
const difference = a.parts[index] - b.parts[index];
|
|
15
|
+
if (difference !== 0) {
|
|
16
|
+
return difference > 0;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
export function highestSemverTag(tagNames) {
|
|
22
|
+
let highest = null;
|
|
23
|
+
for (const name of tagNames) {
|
|
24
|
+
const version = parseTag(name);
|
|
25
|
+
if (version !== null && (highest === null || isGreater(version, highest))) {
|
|
26
|
+
highest = version;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return highest === null ? null : highest.text;
|
|
30
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
export const SUPPORTED_NODE_RANGES = [{ from: "22.0.0" }];
|
|
2
|
+
const NODE_VERSION_PATTERN = /^v?(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?$/;
|
|
3
|
+
function withoutZeroMinorPatch(version) {
|
|
4
|
+
return version.endsWith(".0.0") ? version.slice(0, -".0.0".length) : version;
|
|
5
|
+
}
|
|
6
|
+
export function enginesRange(ranges) {
|
|
7
|
+
return ranges
|
|
8
|
+
.map((range) => range.belowMajor === undefined
|
|
9
|
+
? `>=${withoutZeroMinorPatch(range.from)}`
|
|
10
|
+
: `^${range.from}`)
|
|
11
|
+
.join(" || ");
|
|
12
|
+
}
|
|
13
|
+
export function parseNodeVersion(version) {
|
|
14
|
+
const match = NODE_VERSION_PATTERN.exec(version);
|
|
15
|
+
if (!match) {
|
|
16
|
+
return undefined;
|
|
17
|
+
}
|
|
18
|
+
const parsed = {
|
|
19
|
+
major: Number(match[1]),
|
|
20
|
+
minor: Number(match[2]),
|
|
21
|
+
patch: Number(match[3]),
|
|
22
|
+
};
|
|
23
|
+
if (match[4] !== undefined) {
|
|
24
|
+
parsed.prerelease = match[4];
|
|
25
|
+
}
|
|
26
|
+
return parsed;
|
|
27
|
+
}
|
|
28
|
+
function compareWithRangeStart(version, start) {
|
|
29
|
+
const numeric = version.major - start.major ||
|
|
30
|
+
version.minor - start.minor ||
|
|
31
|
+
version.patch - start.patch;
|
|
32
|
+
if (numeric !== 0) {
|
|
33
|
+
return numeric;
|
|
34
|
+
}
|
|
35
|
+
return version.prerelease === undefined ? 0 : -1;
|
|
36
|
+
}
|
|
37
|
+
function rangeStart(range) {
|
|
38
|
+
const start = parseNodeVersion(range.from);
|
|
39
|
+
if (start === undefined) {
|
|
40
|
+
throw new Error(`Invalid Node range start: ${range.from}`);
|
|
41
|
+
}
|
|
42
|
+
return start;
|
|
43
|
+
}
|
|
44
|
+
function isInRange(version, range) {
|
|
45
|
+
if (compareWithRangeStart(version, rangeStart(range)) < 0) {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
return range.belowMajor === undefined || version.major < range.belowMajor;
|
|
49
|
+
}
|
|
50
|
+
function format({ major, minor, patch, prerelease }) {
|
|
51
|
+
const base = `${major}.${minor}.${patch}`;
|
|
52
|
+
return prerelease === undefined ? base : `${base}-${prerelease}`;
|
|
53
|
+
}
|
|
54
|
+
function headline(version, ranges) {
|
|
55
|
+
const current = format(version);
|
|
56
|
+
const supported = enginesRange(ranges);
|
|
57
|
+
if (compareWithRangeStart(version, rangeStart(ranges[0])) < 0) {
|
|
58
|
+
return `Node ${current} is too old: GatoJS needs Node ${supported}.`;
|
|
59
|
+
}
|
|
60
|
+
const isAboveAll = ranges.every((range) => range.belowMajor !== undefined && version.major >= range.belowMajor);
|
|
61
|
+
if (isAboveAll) {
|
|
62
|
+
return `Node ${current} is too new: GatoJS supports Node ${supported}.`;
|
|
63
|
+
}
|
|
64
|
+
return `Node ${current} is an unsupported release line: GatoJS supports Node ${supported}.`;
|
|
65
|
+
}
|
|
66
|
+
export function checkNodeVersion(input) {
|
|
67
|
+
const ranges = input.ranges ?? SUPPORTED_NODE_RANGES;
|
|
68
|
+
const version = parseNodeVersion(input.version);
|
|
69
|
+
if (version === undefined ||
|
|
70
|
+
ranges.some((range) => isInRange(version, range))) {
|
|
71
|
+
return { kind: "ok" };
|
|
72
|
+
}
|
|
73
|
+
const summary = headline(version, ranges);
|
|
74
|
+
if (!input.willInstall) {
|
|
75
|
+
return {
|
|
76
|
+
kind: "warn",
|
|
77
|
+
message: `Warning: ${summary} Nothing is installed now (--skip-install), so the files are written anyway; switch Node before running npm install in the new project.`,
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
const recommendedMajor = rangeStart(ranges[0]).major;
|
|
81
|
+
return {
|
|
82
|
+
kind: "refuse",
|
|
83
|
+
message: [
|
|
84
|
+
summary,
|
|
85
|
+
"",
|
|
86
|
+
"Stopping before anything is downloaded: `gato create` runs npm install under this Node.",
|
|
87
|
+
"",
|
|
88
|
+
` nvm install ${recommendedMajor} # or fnm, volta, asdf, …`,
|
|
89
|
+
"",
|
|
90
|
+
"Or pass --skip-install to write the files now and install dependencies yourself on a supported Node.",
|
|
91
|
+
].join("\n"),
|
|
92
|
+
};
|
|
93
|
+
}
|
package/dist/process.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
import { constants } from "node:os";
|
|
3
|
+
const FORWARDED_SIGNALS = ["SIGINT", "SIGTERM", "SIGHUP"];
|
|
4
|
+
function exitCodeOf(code, signal) {
|
|
5
|
+
if (code !== null) {
|
|
6
|
+
return code;
|
|
7
|
+
}
|
|
8
|
+
const signalNumber = signal === null ? undefined : constants.signals[signal];
|
|
9
|
+
return signalNumber === undefined ? 1 : 128 + signalNumber;
|
|
10
|
+
}
|
|
11
|
+
export const spawnProcess = (command, args, options) => new Promise((resolvePromise, reject) => {
|
|
12
|
+
const child = spawn(command, args, {
|
|
13
|
+
cwd: options.cwd,
|
|
14
|
+
stdio: options.stdio === "inherit" ? "inherit" : ["ignore", "pipe", "pipe"],
|
|
15
|
+
});
|
|
16
|
+
let stdout = "";
|
|
17
|
+
let stderr = "";
|
|
18
|
+
child.stdout?.on("data", (chunk) => {
|
|
19
|
+
stdout += chunk.toString();
|
|
20
|
+
});
|
|
21
|
+
child.stderr?.on("data", (chunk) => {
|
|
22
|
+
stderr += chunk.toString();
|
|
23
|
+
});
|
|
24
|
+
// WHY: with an attached terminal, Ctrl+C reaches the child too; ignoring it here lets the child finish
|
|
25
|
+
// (gato create cleans up after itself) and still runs our temp dir cleanup instead of dying first.
|
|
26
|
+
const ignore = () => { };
|
|
27
|
+
if (options.stdio === "inherit") {
|
|
28
|
+
for (const signal of FORWARDED_SIGNALS) {
|
|
29
|
+
process.on(signal, ignore);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
const release = () => {
|
|
33
|
+
for (const signal of FORWARDED_SIGNALS) {
|
|
34
|
+
process.off(signal, ignore);
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
child.on("error", (error) => {
|
|
38
|
+
release();
|
|
39
|
+
reject(error);
|
|
40
|
+
});
|
|
41
|
+
child.on("close", (code, signal) => {
|
|
42
|
+
release();
|
|
43
|
+
resolvePromise({ code: exitCodeOf(code, signal), stdout, stderr });
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
export async function ghAuthToken() {
|
|
47
|
+
const result = await spawnProcess("gh", ["auth", "token"], { stdio: "pipe" });
|
|
48
|
+
return result.code === 0 ? result.stdout : null;
|
|
49
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { basename, resolve } from "node:path";
|
|
2
|
+
const PROJECT_NAME_PATTERN = /^[a-z][a-z0-9-]{1,49}$/;
|
|
3
|
+
export function assertProjectName(cwd, target) {
|
|
4
|
+
const name = basename(resolve(cwd, target));
|
|
5
|
+
if (!PROJECT_NAME_PATTERN.test(name)) {
|
|
6
|
+
throw new Error(`Project name "${name}": use lowercase letters, digits and hyphens, start with a letter, 2-50 characters`);
|
|
7
|
+
}
|
|
8
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,67 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-gato-app",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "Create a GatoJS project (Next.js kit) with one command",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"bin": {
|
|
8
|
+
"create-gato-app": "dist/index.js"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"dist",
|
|
12
|
+
"!dist/**/__tests__",
|
|
13
|
+
"NOTICE"
|
|
14
|
+
],
|
|
15
|
+
"publishConfig": {
|
|
16
|
+
"access": "public"
|
|
17
|
+
},
|
|
18
|
+
"repository": {
|
|
19
|
+
"type": "git",
|
|
20
|
+
"url": "git+https://github.com/webamigos/gatojs.git",
|
|
21
|
+
"directory": "packages/create-gato-app"
|
|
22
|
+
},
|
|
23
|
+
"homepage": "https://github.com/webamigos/gatojs/tree/main/packages/create-gato-app#readme",
|
|
24
|
+
"bugs": {
|
|
25
|
+
"url": "https://github.com/webamigos/gatojs/issues"
|
|
26
|
+
},
|
|
27
|
+
"keywords": [
|
|
28
|
+
"gatojs",
|
|
29
|
+
"create",
|
|
30
|
+
"scaffold",
|
|
31
|
+
"nextjs",
|
|
32
|
+
"starter",
|
|
33
|
+
"cli"
|
|
34
|
+
],
|
|
35
|
+
"engines": {
|
|
36
|
+
"node": ">=22"
|
|
37
|
+
},
|
|
38
|
+
"scripts": {
|
|
39
|
+
"clean": "rm -rf dist",
|
|
40
|
+
"build": "tsc -p tsconfig.build.json && chmod +x dist/index.js",
|
|
41
|
+
"prepack": "cp ../../LICENSE ../../NOTICE . && npm run clean && npm run build",
|
|
42
|
+
"typecheck": "tsc --noEmit -p tsconfig.json",
|
|
43
|
+
"test": "vitest run",
|
|
44
|
+
"lint": "eslint .",
|
|
45
|
+
"verify": "npm run lint && npm run typecheck && npm test && npm run build",
|
|
46
|
+
"test:mutation": "stryker run",
|
|
47
|
+
"test:mutation:task": "stryker run --force --mutate",
|
|
48
|
+
"test:smoke": "bash scripts/smoke-pack.sh"
|
|
49
|
+
},
|
|
50
|
+
"dependencies": {
|
|
51
|
+
"gato-cli": "0.2.2"
|
|
52
|
+
},
|
|
53
|
+
"devDependencies": {
|
|
54
|
+
"@eslint/js": "^9.39.5",
|
|
55
|
+
"@fast-check/vitest": "^0.5.0",
|
|
56
|
+
"@stryker-mutator/core": "^10.1.1",
|
|
57
|
+
"@stryker-mutator/typescript-checker": "^10.1.1",
|
|
58
|
+
"@stryker-mutator/vitest-runner": "^10.1.1",
|
|
59
|
+
"@types/node": "^22",
|
|
60
|
+
"eslint": "^9.39.5",
|
|
61
|
+
"fast-check": "^4.10.3",
|
|
62
|
+
"globals": "^17.14.0",
|
|
63
|
+
"typescript": "^5",
|
|
64
|
+
"typescript-eslint": "^8.73.0",
|
|
65
|
+
"vitest": "^4.1.2"
|
|
66
|
+
}
|
|
67
|
+
}
|