zappie 0.1.1 → 0.1.3
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 +12 -0
- package/README.md +29 -9
- package/dist/cli.js +369 -78
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# zappie
|
|
2
2
|
|
|
3
|
+
## 0.1.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- b74e9a9: Verify can run on a build worker. `zappie verify` takes `--only` with check IDs or the `quick` set (V01 to V07, V09, V10 and V13), `--no-build` to serve the existing build, `--port` for the local preview, `--artifacts` for screenshots and the trace, and `--runner` for the report. `@zappie/verify` launches the Chromium named by `browserExecutablePath` or `ZAPPIE_VERIFY_CHROMIUM` instead of Playwright's own, exports `CHECK_SETS`, and refuses an `only` entry that names no check.
|
|
8
|
+
|
|
9
|
+
## 0.1.2
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- 5e6a0a4: Create a React Router storefront with `zappie init` in a new or empty folder. The starter download uses published dependencies and checks its archive hash before writing your files.
|
|
14
|
+
|
|
3
15
|
## 0.1.1
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -11,18 +11,18 @@ npx zappie add cart-drawer
|
|
|
11
11
|
|
|
12
12
|
## Commands
|
|
13
13
|
|
|
14
|
-
| Command | What it does
|
|
15
|
-
| ---------------------- |
|
|
16
|
-
| `zappie add <name...>` | Add components from the registry. `--dry-run` shows the plan, `--overwrite` replaces files you've changed, and `--no-install` skips npm installs.
|
|
17
|
-
| `zappie list` | Show the components in the registry. `--installed` shows the ones in your project.
|
|
18
|
-
| `zappie diff [name]` | Compare your components with the registry. `--apply` merges updates into files you've changed.
|
|
19
|
-
| `zappie doctor` | Check your project, its `zappie.json` and its installed components.
|
|
20
|
-
| `zappie check [dir]` | Run the storefront checks from `@zappie/check` in your project.
|
|
21
|
-
| `zappie verify [url]` | Test a storefront through customer journeys with `@zappie/verify`.
|
|
14
|
+
| Command | What it does |
|
|
15
|
+
| ---------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
16
|
+
| `zappie add <name...>` | Add components from the registry. `--dry-run` shows the plan, `--overwrite` replaces files you've changed, and `--no-install` skips npm installs. |
|
|
17
|
+
| `zappie list` | Show the components in the registry. `--installed` shows the ones in your project. |
|
|
18
|
+
| `zappie diff [name]` | Compare your components with the registry. `--apply` merges updates into files you've changed. |
|
|
19
|
+
| `zappie doctor` | Check your project, its `zappie.json` and its installed components. |
|
|
20
|
+
| `zappie check [dir]` | Run the storefront checks from `@zappie/check` in your project. |
|
|
21
|
+
| `zappie verify [url]` | Test a storefront through customer journeys with `@zappie/verify`. `--only quick` runs the quick set, and `--no-build` verifies the existing build. |
|
|
22
22
|
|
|
23
23
|
Add `--json` to any command for machine-readable output, including errors. Components come from `https://registry.zappie.ai/v1` unless you pass `--registry <url|dir>` or set `registry` in `zappie.json`.
|
|
24
24
|
|
|
25
|
-
`zappie check` and `zappie verify` run `@zappie/check` and `@zappie/verify` from your project. Install whichever you use as a dev dependency. `@zappie/verify` also needs `@playwright/test` and its Chromium browser.
|
|
25
|
+
`zappie check` and `zappie verify` run `@zappie/check` and `@zappie/verify` from your project. Install whichever you use as a dev dependency. `@zappie/verify` also needs `@playwright/test` and its Chromium browser, or `ZAPPIE_VERIFY_CHROMIUM` set to another Chromium's executable.
|
|
26
26
|
|
|
27
27
|
Run `zappie --help` for every option.
|
|
28
28
|
|
|
@@ -39,3 +39,23 @@ The CLI is at `0.x`. Commands and options can change in a minor release while it
|
|
|
39
39
|
## License
|
|
40
40
|
|
|
41
41
|
MIT
|
|
42
|
+
|
|
43
|
+
## Start a storefront
|
|
44
|
+
|
|
45
|
+
```sh
|
|
46
|
+
npx zappie init my-storefront --store my-store --key pk_test_YOUR_KEY --yes
|
|
47
|
+
cd my-storefront
|
|
48
|
+
npm install
|
|
49
|
+
npm run dev
|
|
50
|
+
npm run check
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
Choose a new or empty folder. Existing-project init is not available yet.
|
|
54
|
+
The React Router starter comes from `https://registry.zappie.ai/v1`.
|
|
55
|
+
Use `--registry <url|dir>` to choose another registry, or `--json` for a
|
|
56
|
+
machine-readable result. Init checks the archive hash before writing files.
|
|
57
|
+
|
|
58
|
+
Without `--yes`, init asks for missing values in a terminal. Pass `--store`
|
|
59
|
+
when using `--yes` or `--json`. If you leave out the key, set your test
|
|
60
|
+
publishable key in `.dev.vars` before starting. Init refuses live and secret
|
|
61
|
+
keys. It never installs dependencies for you.
|
package/dist/cli.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
// src/cli.ts
|
|
4
|
-
import
|
|
4
|
+
import path16 from "path";
|
|
5
5
|
|
|
6
6
|
// src/args.ts
|
|
7
7
|
import { parseArgs } from "util";
|
|
@@ -67,9 +67,41 @@ function registrySource(flag, configured) {
|
|
|
67
67
|
|
|
68
68
|
// src/args.ts
|
|
69
69
|
var registryFlag = "--registry <url|dir>";
|
|
70
|
+
var verifyRunners = ["cli", "ci", "build-worker", "sandbox"];
|
|
71
|
+
var verifyCheckSets = {
|
|
72
|
+
quick: ["V01", "V02", "V03", "V04", "V05", "V06", "V07", "V09", "V10", "V13"]
|
|
73
|
+
};
|
|
74
|
+
function parseOnly(value) {
|
|
75
|
+
const entries = value.split(",").map((entry) => entry.trim()).filter(Boolean);
|
|
76
|
+
if (entries.length === 0) {
|
|
77
|
+
throw new CliError("Name at least one check or check set for --only.");
|
|
78
|
+
}
|
|
79
|
+
const ids = /* @__PURE__ */ new Set();
|
|
80
|
+
for (const entry of entries) {
|
|
81
|
+
const set = verifyCheckSets[entry.toLowerCase()];
|
|
82
|
+
if (set) {
|
|
83
|
+
set.forEach((id) => ids.add(id));
|
|
84
|
+
} else if (/^[VE]\d{2}$/i.test(entry)) {
|
|
85
|
+
ids.add(entry.toUpperCase());
|
|
86
|
+
} else {
|
|
87
|
+
throw new CliError(
|
|
88
|
+
`"${entry}" is not a check ID or set for --only. Pass IDs such as V01,V02 or one of: ${Object.keys(verifyCheckSets).join(", ")}.`
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return [...ids];
|
|
93
|
+
}
|
|
94
|
+
function parsePort(value) {
|
|
95
|
+
const port = Number(value);
|
|
96
|
+
if (!/^\d+$/.test(value) || port < 1 || port > 65535) {
|
|
97
|
+
throw new CliError("Pass a port between 1 and 65535 for --port.");
|
|
98
|
+
}
|
|
99
|
+
return port;
|
|
100
|
+
}
|
|
70
101
|
var usage = `Usage: zappie <command>
|
|
71
102
|
|
|
72
103
|
Commands:
|
|
104
|
+
init [dir] Create a storefront in a new or empty folder
|
|
73
105
|
add <name...> Add components from a registry
|
|
74
106
|
list Show registry or installed components
|
|
75
107
|
diff [name] Compare your installed components with the registry
|
|
@@ -78,13 +110,20 @@ Commands:
|
|
|
78
110
|
verify [url] Test your storefront through customer journeys
|
|
79
111
|
|
|
80
112
|
Options:
|
|
113
|
+
--yes Skip init prompts
|
|
114
|
+
--template <name> Choose the react-router starter
|
|
81
115
|
${registryFlag} Use a registry URL or folder. Default: zappie.json, then ${DEFAULT_REGISTRY}
|
|
82
|
-
--json Print machine-readable output for add, list, diff, doctor, check or verify
|
|
116
|
+
--json Print machine-readable output for init, add, list, diff, doctor, check or verify
|
|
83
117
|
--all Keep running check after a step fails
|
|
84
118
|
--suite <name> Run the standard or extended verify suite
|
|
119
|
+
--only <checks> Run only these verify checks, such as V01,V04 or quick
|
|
85
120
|
--report <file> Save your verification report to a file
|
|
86
|
-
--
|
|
87
|
-
--
|
|
121
|
+
--no-build Verify the project's existing build without building it again
|
|
122
|
+
--port <number> Serve verify's local preview on this port. Default: a free port
|
|
123
|
+
--artifacts <dir> Save verify screenshots and the trace here. Default: verify-artifacts
|
|
124
|
+
--runner <name> Record cli, ci, build-worker or sandbox as the report's runner
|
|
125
|
+
--key <pk_test_...> Use this test publishable key for init or verify
|
|
126
|
+
--store <slug> Choose your store for init or verify
|
|
88
127
|
--overwrite Replace files you changed locally during add
|
|
89
128
|
--dry-run Show an add or diff --apply plan without writing
|
|
90
129
|
--apply Apply registry updates with a 3-way merge
|
|
@@ -105,6 +144,8 @@ function parseCommand(argv) {
|
|
|
105
144
|
args: argv,
|
|
106
145
|
options: {
|
|
107
146
|
registry: { type: "string" },
|
|
147
|
+
yes: { type: "boolean" },
|
|
148
|
+
template: { type: "string" },
|
|
108
149
|
json: { type: "boolean" },
|
|
109
150
|
overwrite: { type: "boolean" },
|
|
110
151
|
"dry-run": { type: "boolean" },
|
|
@@ -116,6 +157,11 @@ function parseCommand(argv) {
|
|
|
116
157
|
report: { type: "string" },
|
|
117
158
|
key: { type: "string" },
|
|
118
159
|
store: { type: "string" },
|
|
160
|
+
only: { type: "string" },
|
|
161
|
+
"no-build": { type: "boolean" },
|
|
162
|
+
port: { type: "string" },
|
|
163
|
+
artifacts: { type: "string" },
|
|
164
|
+
runner: { type: "string" },
|
|
119
165
|
help: { type: "boolean", short: "h" }
|
|
120
166
|
},
|
|
121
167
|
allowPositionals: true,
|
|
@@ -134,6 +180,21 @@ ${usage}`);
|
|
|
134
180
|
if (values.help === true || name2 === void 0 || name2 === "help") {
|
|
135
181
|
return { name: "help" };
|
|
136
182
|
}
|
|
183
|
+
if (name2 === "init") {
|
|
184
|
+
if (rest.length > 1) {
|
|
185
|
+
throw new CliError("Pass init at most one directory.");
|
|
186
|
+
}
|
|
187
|
+
return {
|
|
188
|
+
name: name2,
|
|
189
|
+
directory: rest[0],
|
|
190
|
+
registry,
|
|
191
|
+
json: json4,
|
|
192
|
+
yes: values.yes === true,
|
|
193
|
+
store: typeof values.store === "string" ? values.store : void 0,
|
|
194
|
+
key: typeof values.key === "string" ? values.key : void 0,
|
|
195
|
+
template: typeof values.template === "string" ? values.template : "react-router"
|
|
196
|
+
};
|
|
197
|
+
}
|
|
137
198
|
if (name2 === "add") {
|
|
138
199
|
if (rest.length === 0) {
|
|
139
200
|
throw new CliError(`Name at least one component to add.
|
|
@@ -194,7 +255,20 @@ ${usage}`);
|
|
|
194
255
|
}
|
|
195
256
|
const suite = values.suite ?? "standard";
|
|
196
257
|
if (suite !== "standard" && suite !== "extended") {
|
|
197
|
-
throw new CliError(
|
|
258
|
+
throw new CliError(
|
|
259
|
+
"Choose standard or extended for --suite. To run the quick checks, pass --only quick."
|
|
260
|
+
);
|
|
261
|
+
}
|
|
262
|
+
const runner = values.runner;
|
|
263
|
+
if (typeof runner === "string" && !verifyRunners.includes(runner)) {
|
|
264
|
+
throw new CliError(`Choose ${verifyRunners.join(", ")} for --runner.`);
|
|
265
|
+
}
|
|
266
|
+
const build = values["no-build"] !== true;
|
|
267
|
+
const port = typeof values.port === "string" ? parsePort(values.port) : void 0;
|
|
268
|
+
if (rest[0] && (!build || port !== void 0)) {
|
|
269
|
+
throw new CliError(
|
|
270
|
+
"--no-build and --port apply to the local preview. Drop them, or drop the URL."
|
|
271
|
+
);
|
|
198
272
|
}
|
|
199
273
|
return {
|
|
200
274
|
name: name2,
|
|
@@ -203,6 +277,11 @@ ${usage}`);
|
|
|
203
277
|
report: typeof values.report === "string" ? values.report : void 0,
|
|
204
278
|
key: typeof values.key === "string" ? values.key : void 0,
|
|
205
279
|
store: typeof values.store === "string" ? values.store : void 0,
|
|
280
|
+
only: typeof values.only === "string" ? parseOnly(values.only) : void 0,
|
|
281
|
+
build,
|
|
282
|
+
port,
|
|
283
|
+
artifacts: typeof values.artifacts === "string" ? values.artifacts : void 0,
|
|
284
|
+
runner,
|
|
206
285
|
json: json4
|
|
207
286
|
};
|
|
208
287
|
}
|
|
@@ -828,73 +907,40 @@ async function doctor(options) {
|
|
|
828
907
|
return { ...result, failed: checks.some((entry) => entry.status === "fail") };
|
|
829
908
|
}
|
|
830
909
|
|
|
831
|
-
// src/
|
|
832
|
-
import {
|
|
833
|
-
import
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
);
|
|
843
|
-
}
|
|
844
|
-
const absolute = path8.resolve(cwd, normalized);
|
|
845
|
-
if (absolute !== cwd && !absolute.startsWith(`${cwd}${path8.sep}`)) {
|
|
846
|
-
throw new CliError(
|
|
847
|
-
`Registry target points outside your project root: ${target}`
|
|
848
|
-
);
|
|
849
|
-
}
|
|
850
|
-
return { normalized, absolute };
|
|
851
|
-
}
|
|
852
|
-
function verifySource(item2, file) {
|
|
853
|
-
if (sha256(file.content) !== file.sha256) {
|
|
854
|
-
throw new CliError(`The registry hash does not match ${item2}.`);
|
|
855
|
-
}
|
|
856
|
-
}
|
|
857
|
-
|
|
858
|
-
// src/kit-imports.ts
|
|
910
|
+
// src/init.ts
|
|
911
|
+
import { Buffer as Buffer2 } from "buffer";
|
|
912
|
+
import { createHash as createHash2 } from "crypto";
|
|
913
|
+
import {
|
|
914
|
+
existsSync as existsSync5,
|
|
915
|
+
lstatSync,
|
|
916
|
+
mkdirSync,
|
|
917
|
+
readdirSync,
|
|
918
|
+
readFileSync as readFileSync5,
|
|
919
|
+
writeFileSync as writeFileSync2
|
|
920
|
+
} from "fs";
|
|
859
921
|
import path9 from "path";
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
const value = path9.posix.relative(path9.posix.dirname(from), to);
|
|
863
|
-
return value.startsWith(".") ? value : `./${value}`;
|
|
864
|
-
}
|
|
865
|
-
function rewriteKitImports(content, target, componentsDir, alias) {
|
|
866
|
-
return content.replace(
|
|
867
|
-
IMPORT,
|
|
868
|
-
(match, keyword, quote, specifier, sibling) => {
|
|
869
|
-
const replacement = alias ? `${alias.replace(/\/$/, "")}/${sibling}` : posixRelative(target, `${componentsDir}/${sibling}`);
|
|
870
|
-
return `${keyword}${quote}${replacement}${quote}`;
|
|
871
|
-
}
|
|
872
|
-
);
|
|
873
|
-
}
|
|
874
|
-
function installTarget(target, componentsDir) {
|
|
875
|
-
const normalized = target.replaceAll("\\", "/");
|
|
876
|
-
return normalized.startsWith("components/zappie/") ? `${componentsDir}/${normalized.slice("components/zappie/".length)}` : normalized;
|
|
877
|
-
}
|
|
922
|
+
import { createInterface } from "readline/promises";
|
|
923
|
+
import { fileURLToPath as fileURLToPath2, pathToFileURL as pathToFileURL2, URL as URL2 } from "url";
|
|
878
924
|
|
|
879
925
|
// src/package-manager.ts
|
|
880
926
|
import { spawnSync } from "child_process";
|
|
881
927
|
import { existsSync as existsSync4, readFileSync as readFileSync4 } from "fs";
|
|
882
|
-
import
|
|
928
|
+
import path8 from "path";
|
|
883
929
|
function detectPackageManager(cwd) {
|
|
884
|
-
for (let directory = cwd; ; directory =
|
|
885
|
-
if (existsSync4(
|
|
930
|
+
for (let directory = cwd; ; directory = path8.dirname(directory)) {
|
|
931
|
+
if (existsSync4(path8.join(directory, "pnpm-lock.yaml"))) {
|
|
886
932
|
return "pnpm";
|
|
887
933
|
}
|
|
888
|
-
if (existsSync4(
|
|
934
|
+
if (existsSync4(path8.join(directory, "package-lock.json"))) {
|
|
889
935
|
return "npm";
|
|
890
936
|
}
|
|
891
|
-
if (existsSync4(
|
|
937
|
+
if (existsSync4(path8.join(directory, "yarn.lock"))) {
|
|
892
938
|
return "yarn";
|
|
893
939
|
}
|
|
894
|
-
if (existsSync4(
|
|
940
|
+
if (existsSync4(path8.join(directory, "bun.lock")) || existsSync4(path8.join(directory, "bun.lockb"))) {
|
|
895
941
|
return "bun";
|
|
896
942
|
}
|
|
897
|
-
if (
|
|
943
|
+
if (path8.dirname(directory) === directory) {
|
|
898
944
|
break;
|
|
899
945
|
}
|
|
900
946
|
}
|
|
@@ -902,7 +948,7 @@ function detectPackageManager(cwd) {
|
|
|
902
948
|
}
|
|
903
949
|
function missingDependencies(cwd, requested) {
|
|
904
950
|
const manifest = JSON.parse(
|
|
905
|
-
readFileSync4(
|
|
951
|
+
readFileSync4(path8.join(cwd, "package.json"), "utf8")
|
|
906
952
|
);
|
|
907
953
|
const present = {
|
|
908
954
|
...manifest.dependencies,
|
|
@@ -926,6 +972,237 @@ function installDependencies(cwd, dependencies, quiet = false) {
|
|
|
926
972
|
}
|
|
927
973
|
}
|
|
928
974
|
|
|
975
|
+
// src/starter-archive.ts
|
|
976
|
+
import "buffer";
|
|
977
|
+
import { gunzipSync } from "zlib";
|
|
978
|
+
function readStarterArchive(bytes) {
|
|
979
|
+
const tar = gunzipSync(new Uint8Array(bytes), {
|
|
980
|
+
maxOutputLength: 32 * 1024 * 1024
|
|
981
|
+
});
|
|
982
|
+
const files2 = /* @__PURE__ */ new Map();
|
|
983
|
+
const invalid = () => new CliError("The starter archive is invalid or contains an unsafe path.");
|
|
984
|
+
const text = (start, length) => tar.subarray(start, start + length).toString("utf8").split("\0")[0];
|
|
985
|
+
let offset = 0;
|
|
986
|
+
while (offset + 512 <= tar.length) {
|
|
987
|
+
const header = tar.subarray(offset, offset + 512);
|
|
988
|
+
if (header.every((byte) => byte === 0)) {
|
|
989
|
+
if (tar.length < offset + 1024 || tar.length % 512 !== 0 || tar.subarray(offset).some((byte) => byte !== 0)) {
|
|
990
|
+
throw invalid();
|
|
991
|
+
}
|
|
992
|
+
for (const name3 of files2.keys()) {
|
|
993
|
+
const parts = name3.split("/");
|
|
994
|
+
parts.pop();
|
|
995
|
+
while (parts.length) {
|
|
996
|
+
if (files2.has(parts.join("/"))) {
|
|
997
|
+
throw invalid();
|
|
998
|
+
}
|
|
999
|
+
parts.pop();
|
|
1000
|
+
}
|
|
1001
|
+
}
|
|
1002
|
+
return files2;
|
|
1003
|
+
}
|
|
1004
|
+
const checksum = header.reduce(
|
|
1005
|
+
(sum, byte, index2) => sum + (index2 >= 148 && index2 < 156 ? 32 : byte),
|
|
1006
|
+
0
|
|
1007
|
+
);
|
|
1008
|
+
const stored = text(offset + 148, 8).trim();
|
|
1009
|
+
const sizeText = text(offset + 124, 12).trim();
|
|
1010
|
+
const name2 = text(offset, 100);
|
|
1011
|
+
const kind = text(offset + 156, 1);
|
|
1012
|
+
if (!/^[0-7]+$/.test(stored) || parseInt(stored, 8) !== checksum || !/^[0-7]+$/.test(sizeText) || kind !== "0" || text(offset + 257, 6) !== "ustar" || text(offset + 345, 155) !== "" || /[\\:\x00-\x1f\x7f]/.test(name2) || name2.split("/").some((part) => !part || part === "." || part === "..") || files2.has(name2)) {
|
|
1013
|
+
throw invalid();
|
|
1014
|
+
}
|
|
1015
|
+
const size = parseInt(sizeText, 8);
|
|
1016
|
+
offset += 512;
|
|
1017
|
+
if (!Number.isSafeInteger(size) || offset + size > tar.length) {
|
|
1018
|
+
throw invalid();
|
|
1019
|
+
}
|
|
1020
|
+
files2.set(name2, tar.subarray(offset, offset + size));
|
|
1021
|
+
offset += Math.ceil(size / 512) * 512;
|
|
1022
|
+
}
|
|
1023
|
+
throw invalid();
|
|
1024
|
+
}
|
|
1025
|
+
|
|
1026
|
+
// src/init.ts
|
|
1027
|
+
async function download(url) {
|
|
1028
|
+
if (url.protocol === "file:") {
|
|
1029
|
+
return readFileSync5(fileURLToPath2(url));
|
|
1030
|
+
}
|
|
1031
|
+
const response = await fetch(url.href, {
|
|
1032
|
+
signal: AbortSignal.timeout(3e4)
|
|
1033
|
+
});
|
|
1034
|
+
if (!response.ok) {
|
|
1035
|
+
throw new CliError(`Could not download the starter (${response.status}).`);
|
|
1036
|
+
}
|
|
1037
|
+
return Buffer2.from(await response.arrayBuffer());
|
|
1038
|
+
}
|
|
1039
|
+
async function initProject(command, cwd) {
|
|
1040
|
+
const directory = path9.resolve(cwd, command.directory ?? ".");
|
|
1041
|
+
if (existsSync5(directory) && (!lstatSync(directory).isDirectory() || readdirSync(directory).length > 0)) {
|
|
1042
|
+
throw new CliError(
|
|
1043
|
+
"Choose a new or empty folder. Existing-project init is not available yet."
|
|
1044
|
+
);
|
|
1045
|
+
}
|
|
1046
|
+
if (command.template !== "react-router") {
|
|
1047
|
+
throw new CliError("Choose react-router for --template.");
|
|
1048
|
+
}
|
|
1049
|
+
let { store, key } = command;
|
|
1050
|
+
if (!command.yes && !command.json && process.stdin.isTTY && (!store || !key)) {
|
|
1051
|
+
const prompt = createInterface({
|
|
1052
|
+
input: process.stdin,
|
|
1053
|
+
output: process.stdout
|
|
1054
|
+
});
|
|
1055
|
+
try {
|
|
1056
|
+
store ||= await prompt.question("Store slug: ");
|
|
1057
|
+
key ||= await prompt.question(
|
|
1058
|
+
"Test publishable key (leave blank to set it later): "
|
|
1059
|
+
);
|
|
1060
|
+
} finally {
|
|
1061
|
+
prompt.close();
|
|
1062
|
+
}
|
|
1063
|
+
}
|
|
1064
|
+
if (!store || !/^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(store)) {
|
|
1065
|
+
throw new CliError(
|
|
1066
|
+
"Pass --store with your store slug, using lowercase letters, numbers and hyphens."
|
|
1067
|
+
);
|
|
1068
|
+
}
|
|
1069
|
+
if (key && !/^pk_test_[A-Za-z0-9_-]+$/.test(key)) {
|
|
1070
|
+
throw new CliError(
|
|
1071
|
+
"Use a pk_test_ publishable key. Live and secret keys are not accepted by init."
|
|
1072
|
+
);
|
|
1073
|
+
}
|
|
1074
|
+
const name2 = path9.basename(directory).toLowerCase().replace(/[^a-z0-9-]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 63) || "my-storefront";
|
|
1075
|
+
const source2 = command.registry ?? DEFAULT_REGISTRY;
|
|
1076
|
+
const base = /^[a-z]+:\/\//i.test(source2) ? new URL2(source2.endsWith("/") ? source2 : `${source2}/`) : pathToFileURL2(path9.resolve(cwd, source2) + path9.sep);
|
|
1077
|
+
const manifest = JSON.parse(
|
|
1078
|
+
(await download(new URL2("starters/index.json", base))).toString("utf8")
|
|
1079
|
+
);
|
|
1080
|
+
const template = manifest.templates?.[command.template];
|
|
1081
|
+
const entry = template?.versions?.[template.latest];
|
|
1082
|
+
if (!entry || !/^react-router@\d+\.\d+\.\d+(?:-[\w.-]+)?(?:\+[\w.-]+)?\.tgz$/.test(
|
|
1083
|
+
entry.file
|
|
1084
|
+
) || !/^[a-f0-9]{64}$/.test(entry.sha256) || !Number.isSafeInteger(entry.size) || entry.size <= 0) {
|
|
1085
|
+
throw new CliError("The starter manifest is invalid.");
|
|
1086
|
+
}
|
|
1087
|
+
const bytes = await download(new URL2(`starters/${entry.file}`, base));
|
|
1088
|
+
if (bytes.length !== entry.size || createHash2("sha256").update(new Uint8Array(bytes)).digest("hex") !== entry.sha256) {
|
|
1089
|
+
throw new CliError(
|
|
1090
|
+
"The starter archive does not match its manifest. Nothing was written."
|
|
1091
|
+
);
|
|
1092
|
+
}
|
|
1093
|
+
const files2 = readStarterArchive(bytes);
|
|
1094
|
+
for (const filename of [
|
|
1095
|
+
"package.json",
|
|
1096
|
+
"wrangler.jsonc",
|
|
1097
|
+
"zappie.config.ts",
|
|
1098
|
+
".gitignore"
|
|
1099
|
+
]) {
|
|
1100
|
+
const file = files2.get(filename);
|
|
1101
|
+
if (!file) {
|
|
1102
|
+
throw new CliError(
|
|
1103
|
+
`The starter is missing ${filename}. Nothing was written.`
|
|
1104
|
+
);
|
|
1105
|
+
}
|
|
1106
|
+
files2.set(
|
|
1107
|
+
filename,
|
|
1108
|
+
Buffer2.from(
|
|
1109
|
+
file.toString("utf8").replaceAll("__ZAPPIE_NAME__", name2).replaceAll("__ZAPPIE_STORE__", store)
|
|
1110
|
+
)
|
|
1111
|
+
);
|
|
1112
|
+
}
|
|
1113
|
+
if ([...files2.keys()].some((name3) => name3.startsWith(".dev.vars/"))) {
|
|
1114
|
+
throw new CliError(
|
|
1115
|
+
"The starter archive contains an unsafe path. Nothing was written."
|
|
1116
|
+
);
|
|
1117
|
+
}
|
|
1118
|
+
files2.set(
|
|
1119
|
+
".dev.vars",
|
|
1120
|
+
Buffer2.from(
|
|
1121
|
+
`ZAPPIE_API=https://api.zappie.ai/storefront/v1
|
|
1122
|
+
ZAPPIE_STORE=${store}
|
|
1123
|
+
ZAPPIE_KEY=${key || "pk_test_REPLACE_ME"}
|
|
1124
|
+
`
|
|
1125
|
+
)
|
|
1126
|
+
);
|
|
1127
|
+
mkdirSync(directory, { recursive: true });
|
|
1128
|
+
for (const [filename, contents] of files2) {
|
|
1129
|
+
const destination = path9.join(directory, filename);
|
|
1130
|
+
mkdirSync(path9.dirname(destination), { recursive: true });
|
|
1131
|
+
writeFileSync2(destination, new Uint8Array(contents), { flag: "wx" });
|
|
1132
|
+
}
|
|
1133
|
+
const manager = detectPackageManager(directory);
|
|
1134
|
+
const run = manager === "npm" ? "npm run" : manager;
|
|
1135
|
+
const next = [`${manager} install`, `${run} dev`, `${run} check`];
|
|
1136
|
+
const hint = key ? void 0 : "Set your test publishable key in .dev.vars before starting the storefront.";
|
|
1137
|
+
if (command.json) {
|
|
1138
|
+
console.log(
|
|
1139
|
+
JSON.stringify({
|
|
1140
|
+
command: "init",
|
|
1141
|
+
directory,
|
|
1142
|
+
template: command.template,
|
|
1143
|
+
version: template.latest,
|
|
1144
|
+
next,
|
|
1145
|
+
...hint ? { hint } : {}
|
|
1146
|
+
})
|
|
1147
|
+
);
|
|
1148
|
+
} else {
|
|
1149
|
+
console.log(
|
|
1150
|
+
`Created your storefront in ${directory}.
|
|
1151
|
+
${hint ? `${hint}
|
|
1152
|
+
` : ""}In that folder, run:
|
|
1153
|
+
${next.join("\n")}`
|
|
1154
|
+
);
|
|
1155
|
+
}
|
|
1156
|
+
}
|
|
1157
|
+
|
|
1158
|
+
// src/kit-add.ts
|
|
1159
|
+
import { existsSync as existsSync6, mkdirSync as mkdirSync2, readFileSync as readFileSync6, writeFileSync as writeFileSync3 } from "fs";
|
|
1160
|
+
import path12 from "path";
|
|
1161
|
+
|
|
1162
|
+
// src/kit-files.ts
|
|
1163
|
+
import path10 from "path";
|
|
1164
|
+
function safeTarget(cwd, target) {
|
|
1165
|
+
const normalized = target.replaceAll("\\", "/");
|
|
1166
|
+
if (normalized.startsWith("/") || /^[A-Za-z]:\//.test(normalized) || normalized.split("/").includes("..")) {
|
|
1167
|
+
throw new CliError(
|
|
1168
|
+
`Registry target points outside your project root: ${target}`
|
|
1169
|
+
);
|
|
1170
|
+
}
|
|
1171
|
+
const absolute = path10.resolve(cwd, normalized);
|
|
1172
|
+
if (absolute !== cwd && !absolute.startsWith(`${cwd}${path10.sep}`)) {
|
|
1173
|
+
throw new CliError(
|
|
1174
|
+
`Registry target points outside your project root: ${target}`
|
|
1175
|
+
);
|
|
1176
|
+
}
|
|
1177
|
+
return { normalized, absolute };
|
|
1178
|
+
}
|
|
1179
|
+
function verifySource(item2, file) {
|
|
1180
|
+
if (sha256(file.content) !== file.sha256) {
|
|
1181
|
+
throw new CliError(`The registry hash does not match ${item2}.`);
|
|
1182
|
+
}
|
|
1183
|
+
}
|
|
1184
|
+
|
|
1185
|
+
// src/kit-imports.ts
|
|
1186
|
+
import path11 from "path";
|
|
1187
|
+
var IMPORT = /(\bfrom\s+|\bimport\s*)(["'])(@\/components\/zappie\/([^"']+))\2/g;
|
|
1188
|
+
function posixRelative(from, to) {
|
|
1189
|
+
const value = path11.posix.relative(path11.posix.dirname(from), to);
|
|
1190
|
+
return value.startsWith(".") ? value : `./${value}`;
|
|
1191
|
+
}
|
|
1192
|
+
function rewriteKitImports(content, target, componentsDir, alias) {
|
|
1193
|
+
return content.replace(
|
|
1194
|
+
IMPORT,
|
|
1195
|
+
(match, keyword, quote, specifier, sibling) => {
|
|
1196
|
+
const replacement = alias ? `${alias.replace(/\/$/, "")}/${sibling}` : posixRelative(target, `${componentsDir}/${sibling}`);
|
|
1197
|
+
return `${keyword}${quote}${replacement}${quote}`;
|
|
1198
|
+
}
|
|
1199
|
+
);
|
|
1200
|
+
}
|
|
1201
|
+
function installTarget(target, componentsDir) {
|
|
1202
|
+
const normalized = target.replaceAll("\\", "/");
|
|
1203
|
+
return normalized.startsWith("components/zappie/") ? `${componentsDir}/${normalized.slice("components/zappie/".length)}` : normalized;
|
|
1204
|
+
}
|
|
1205
|
+
|
|
929
1206
|
// src/registry-graph.ts
|
|
930
1207
|
async function batches(values, size, read) {
|
|
931
1208
|
const output = [];
|
|
@@ -1021,8 +1298,8 @@ async function addItems(options) {
|
|
|
1021
1298
|
project2.alias
|
|
1022
1299
|
);
|
|
1023
1300
|
const installedHash = project2.installed[item2.name]?.files[safe.normalized];
|
|
1024
|
-
if (
|
|
1025
|
-
const currentHash = sha256(
|
|
1301
|
+
if (existsSync6(safe.absolute)) {
|
|
1302
|
+
const currentHash = sha256(readFileSync6(safe.absolute, "utf8"));
|
|
1026
1303
|
if (currentHash !== installedHash && !options.overwrite) {
|
|
1027
1304
|
throw new CliError(
|
|
1028
1305
|
`${safe.normalized} has local changes. Pass --overwrite to replace it.`
|
|
@@ -1056,9 +1333,9 @@ async function addItems(options) {
|
|
|
1056
1333
|
installDependencies(options.cwd, dependencies, options.json);
|
|
1057
1334
|
}
|
|
1058
1335
|
for (const file of planned) {
|
|
1059
|
-
const absolute =
|
|
1060
|
-
|
|
1061
|
-
|
|
1336
|
+
const absolute = path12.join(options.cwd, file.target);
|
|
1337
|
+
mkdirSync2(path12.dirname(absolute), { recursive: true });
|
|
1338
|
+
writeFileSync3(absolute, file.content);
|
|
1062
1339
|
}
|
|
1063
1340
|
const installed = { ...project2.installed };
|
|
1064
1341
|
for (const item2 of items) {
|
|
@@ -1089,11 +1366,11 @@ function planText(result) {
|
|
|
1089
1366
|
}
|
|
1090
1367
|
|
|
1091
1368
|
// src/kit-apply.ts
|
|
1092
|
-
import { mkdirSync as
|
|
1093
|
-
import
|
|
1369
|
+
import { mkdirSync as mkdirSync3, rmSync, writeFileSync as writeFileSync4 } from "fs";
|
|
1370
|
+
import path13 from "path";
|
|
1094
1371
|
|
|
1095
1372
|
// src/kit-apply-plan.ts
|
|
1096
|
-
import { existsSync as
|
|
1373
|
+
import { existsSync as existsSync7, readFileSync as readFileSync7 } from "fs";
|
|
1097
1374
|
|
|
1098
1375
|
// src/three-way.ts
|
|
1099
1376
|
import { diff3Merge } from "node-diff3";
|
|
@@ -1159,7 +1436,7 @@ function conflict(file, reason, hunks = []) {
|
|
|
1159
1436
|
}
|
|
1160
1437
|
function planFile(cwd, target, base, theirs, installedHash) {
|
|
1161
1438
|
const absolute = safeTarget(cwd, target).absolute;
|
|
1162
|
-
const ours =
|
|
1439
|
+
const ours = existsSync7(absolute) ? readFileSync7(absolute, "utf8") : void 0;
|
|
1163
1440
|
if (base === void 0 && theirs !== void 0) {
|
|
1164
1441
|
if (ours !== void 0 && ours !== theirs) {
|
|
1165
1442
|
return {
|
|
@@ -1305,8 +1582,8 @@ async function applyDiff(options) {
|
|
|
1305
1582
|
if (action.kind === "delete") {
|
|
1306
1583
|
rmSync(absolute, { force: true });
|
|
1307
1584
|
} else {
|
|
1308
|
-
|
|
1309
|
-
|
|
1585
|
+
mkdirSync3(path13.dirname(absolute), { recursive: true });
|
|
1586
|
+
writeFileSync4(absolute, action.content);
|
|
1310
1587
|
}
|
|
1311
1588
|
}
|
|
1312
1589
|
installed[name2] = planned.next;
|
|
@@ -1346,8 +1623,8 @@ function applyText(items) {
|
|
|
1346
1623
|
}
|
|
1347
1624
|
|
|
1348
1625
|
// src/kit-status.ts
|
|
1349
|
-
import { existsSync as
|
|
1350
|
-
import
|
|
1626
|
+
import { existsSync as existsSync8, readFileSync as readFileSync8 } from "fs";
|
|
1627
|
+
import path14 from "path";
|
|
1351
1628
|
|
|
1352
1629
|
// src/unified-diff.ts
|
|
1353
1630
|
function unifiedDiff(file, before, after) {
|
|
@@ -1375,8 +1652,8 @@ function project(cwd) {
|
|
|
1375
1652
|
}
|
|
1376
1653
|
function modified(cwd, files2) {
|
|
1377
1654
|
return Object.entries(files2).some(([file, installedHash]) => {
|
|
1378
|
-
const target =
|
|
1379
|
-
return !
|
|
1655
|
+
const target = path14.join(cwd, file);
|
|
1656
|
+
return !existsSync8(target) || sha256(readFileSync8(target, "utf8")) !== installedHash;
|
|
1380
1657
|
});
|
|
1381
1658
|
}
|
|
1382
1659
|
function state(local, update) {
|
|
@@ -1478,7 +1755,7 @@ async function upstreamDiffs(registry, name2, installedVersion, latestVersion) {
|
|
|
1478
1755
|
|
|
1479
1756
|
// src/verify-command.ts
|
|
1480
1757
|
import { mkdir, writeFile } from "fs/promises";
|
|
1481
|
-
import
|
|
1758
|
+
import path15 from "path";
|
|
1482
1759
|
async function runProjectVerify(options) {
|
|
1483
1760
|
const key = options.key ?? process.env.ZAPPIE_KEY;
|
|
1484
1761
|
if (key?.startsWith("pk_live_")) {
|
|
@@ -1501,11 +1778,16 @@ async function runProjectVerify(options) {
|
|
|
1501
1778
|
packageManager: options.packageManager,
|
|
1502
1779
|
...options.url ? { url: options.url } : {},
|
|
1503
1780
|
...options.store ? { store: options.store } : {},
|
|
1781
|
+
...options.only ? { only: options.only } : {},
|
|
1782
|
+
...options.build === false ? { build: false } : {},
|
|
1783
|
+
...options.port ? { port: options.port } : {},
|
|
1784
|
+
...options.artifacts ? { artifactsDir: path15.resolve(options.cwd, options.artifacts) } : {},
|
|
1785
|
+
...options.runner ? { runner: options.runner } : {},
|
|
1504
1786
|
...options.signal ? { signal: options.signal } : {}
|
|
1505
1787
|
});
|
|
1506
1788
|
if (options.report) {
|
|
1507
|
-
const file =
|
|
1508
|
-
await mkdir(
|
|
1789
|
+
const file = path15.resolve(options.cwd, options.report);
|
|
1790
|
+
await mkdir(path15.dirname(file), { recursive: true });
|
|
1509
1791
|
await writeFile(file, `${JSON.stringify(result, null, 2)}
|
|
1510
1792
|
`);
|
|
1511
1793
|
}
|
|
@@ -1544,6 +1826,10 @@ async function main(argv) {
|
|
|
1544
1826
|
const command = parseCommand(argv);
|
|
1545
1827
|
const cwd = process.cwd();
|
|
1546
1828
|
switch (command.name) {
|
|
1829
|
+
case "init": {
|
|
1830
|
+
await initProject(command, cwd);
|
|
1831
|
+
return 0;
|
|
1832
|
+
}
|
|
1547
1833
|
case "help": {
|
|
1548
1834
|
console.log(usage);
|
|
1549
1835
|
return 0;
|
|
@@ -1599,7 +1885,7 @@ async function main(argv) {
|
|
|
1599
1885
|
return result.failed ? 1 : 0;
|
|
1600
1886
|
}
|
|
1601
1887
|
case "check": {
|
|
1602
|
-
const directory =
|
|
1888
|
+
const directory = path16.resolve(cwd, command.directory ?? ".");
|
|
1603
1889
|
const controller = new AbortController();
|
|
1604
1890
|
const abort = () => controller.abort(new Error("Check cancelled."));
|
|
1605
1891
|
process.once("SIGINT", abort);
|
|
@@ -1629,6 +1915,11 @@ async function main(argv) {
|
|
|
1629
1915
|
...command.report ? { report: command.report } : {},
|
|
1630
1916
|
...command.key ? { key: command.key } : {},
|
|
1631
1917
|
...command.store ? { store: command.store } : {},
|
|
1918
|
+
...command.only ? { only: command.only } : {},
|
|
1919
|
+
...command.build ? {} : { build: false },
|
|
1920
|
+
...command.port ? { port: command.port } : {},
|
|
1921
|
+
...command.artifacts ? { artifacts: command.artifacts } : {},
|
|
1922
|
+
...command.runner ? { runner: command.runner } : {},
|
|
1632
1923
|
packageManager: detectPackageManager(cwd),
|
|
1633
1924
|
signal: controller.signal
|
|
1634
1925
|
});
|