zappie 0.1.0 → 0.1.2
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 +24 -0
- package/README.md +56 -8
- package/dist/cli.js +299 -77
- package/package.json +3 -2
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# zappie
|
|
2
|
+
|
|
3
|
+
## 0.1.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 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.
|
|
8
|
+
|
|
9
|
+
## 0.1.1
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- 1e6f420: Each package now has a README written for people installing it from npm: what it does, how to install and use it, its entry points, and links to docs.zappie.ai. `@zappie/kit` gains its first README.
|
|
14
|
+
|
|
15
|
+
## 0.1.0
|
|
16
|
+
|
|
17
|
+
### Minor Changes
|
|
18
|
+
|
|
19
|
+
- - `@zappie/tokens`: Publish the semantic storefront token contract, CSS aliases, validation and compilation tools.
|
|
20
|
+
- `@zappie/sdk`: Publish the framework-agnostic storefront client and its React, server, checkout, customer, places, visits and URL entries.
|
|
21
|
+
- `@zappie/foundations`: Publish accessible, unstyled React primitives for storefront catalogue, item, fulfilment and cart experiences.
|
|
22
|
+
- `@zappie/theme-base`: Publish the reusable base storefront theme and its catalogue, item and cart surfaces.
|
|
23
|
+
- `@zappie/kit`: Publish the built component registry consumed by the Zappie CLI.
|
|
24
|
+
- `zappie`: Publish the component CLI with `add`, `list` and `diff`.
|
package/README.md
CHANGED
|
@@ -1,13 +1,61 @@
|
|
|
1
|
-
#
|
|
1
|
+
# zappie
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The Zappie command line for building storefronts. Add ready-made components from the kit to your project, keep them up to date, and check your project's setup.
|
|
4
4
|
|
|
5
5
|
```sh
|
|
6
|
-
zappie
|
|
7
|
-
zappie
|
|
8
|
-
zappie diff
|
|
9
|
-
zappie doctor
|
|
10
|
-
zappie check
|
|
6
|
+
npx zappie list
|
|
7
|
+
npx zappie add cart-drawer
|
|
11
8
|
```
|
|
12
9
|
|
|
13
|
-
`zappie
|
|
10
|
+
`zappie add` copies a component's source into your project, along with the components it needs, so you can change it like your own code. It also installs any npm packages the component uses, and records what it added in `zappie.json`.
|
|
11
|
+
|
|
12
|
+
## Commands
|
|
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`. |
|
|
22
|
+
|
|
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
|
+
|
|
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.
|
|
26
|
+
|
|
27
|
+
Run `zappie --help` for every option.
|
|
28
|
+
|
|
29
|
+
## Docs
|
|
30
|
+
|
|
31
|
+
- [CLI reference](https://docs.zappie.ai/cli)
|
|
32
|
+
- [Kit components](https://docs.zappie.ai/kit)
|
|
33
|
+
- [Build a storefront](https://docs.zappie.ai/guides/build-a-storefront)
|
|
34
|
+
|
|
35
|
+
## Status
|
|
36
|
+
|
|
37
|
+
The CLI is at `0.x`. Commands and options can change in a minor release while it settles. Each change is listed in `CHANGELOG.md`.
|
|
38
|
+
|
|
39
|
+
## License
|
|
40
|
+
|
|
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";
|
|
@@ -70,6 +70,7 @@ var registryFlag = "--registry <url|dir>";
|
|
|
70
70
|
var usage = `Usage: zappie <command>
|
|
71
71
|
|
|
72
72
|
Commands:
|
|
73
|
+
init [dir] Create a storefront in a new or empty folder
|
|
73
74
|
add <name...> Add components from a registry
|
|
74
75
|
list Show registry or installed components
|
|
75
76
|
diff [name] Compare your installed components with the registry
|
|
@@ -78,13 +79,15 @@ Commands:
|
|
|
78
79
|
verify [url] Test your storefront through customer journeys
|
|
79
80
|
|
|
80
81
|
Options:
|
|
82
|
+
--yes Skip init prompts
|
|
83
|
+
--template <name> Choose the react-router starter
|
|
81
84
|
${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
|
|
85
|
+
--json Print machine-readable output for init, add, list, diff, doctor, check or verify
|
|
83
86
|
--all Keep running check after a step fails
|
|
84
87
|
--suite <name> Run the standard or extended verify suite
|
|
85
88
|
--report <file> Save your verification report to a file
|
|
86
|
-
--key <pk_test_...> Use this test publishable key for verify
|
|
87
|
-
--store <slug> Choose
|
|
89
|
+
--key <pk_test_...> Use this test publishable key for init or verify
|
|
90
|
+
--store <slug> Choose your store for init or verify
|
|
88
91
|
--overwrite Replace files you changed locally during add
|
|
89
92
|
--dry-run Show an add or diff --apply plan without writing
|
|
90
93
|
--apply Apply registry updates with a 3-way merge
|
|
@@ -105,6 +108,8 @@ function parseCommand(argv) {
|
|
|
105
108
|
args: argv,
|
|
106
109
|
options: {
|
|
107
110
|
registry: { type: "string" },
|
|
111
|
+
yes: { type: "boolean" },
|
|
112
|
+
template: { type: "string" },
|
|
108
113
|
json: { type: "boolean" },
|
|
109
114
|
overwrite: { type: "boolean" },
|
|
110
115
|
"dry-run": { type: "boolean" },
|
|
@@ -134,6 +139,21 @@ ${usage}`);
|
|
|
134
139
|
if (values.help === true || name2 === void 0 || name2 === "help") {
|
|
135
140
|
return { name: "help" };
|
|
136
141
|
}
|
|
142
|
+
if (name2 === "init") {
|
|
143
|
+
if (rest.length > 1) {
|
|
144
|
+
throw new CliError("Pass init at most one directory.");
|
|
145
|
+
}
|
|
146
|
+
return {
|
|
147
|
+
name: name2,
|
|
148
|
+
directory: rest[0],
|
|
149
|
+
registry,
|
|
150
|
+
json: json4,
|
|
151
|
+
yes: values.yes === true,
|
|
152
|
+
store: typeof values.store === "string" ? values.store : void 0,
|
|
153
|
+
key: typeof values.key === "string" ? values.key : void 0,
|
|
154
|
+
template: typeof values.template === "string" ? values.template : "react-router"
|
|
155
|
+
};
|
|
156
|
+
}
|
|
137
157
|
if (name2 === "add") {
|
|
138
158
|
if (rest.length === 0) {
|
|
139
159
|
throw new CliError(`Name at least one component to add.
|
|
@@ -828,73 +848,40 @@ async function doctor(options) {
|
|
|
828
848
|
return { ...result, failed: checks.some((entry) => entry.status === "fail") };
|
|
829
849
|
}
|
|
830
850
|
|
|
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
|
|
851
|
+
// src/init.ts
|
|
852
|
+
import { Buffer as Buffer2 } from "buffer";
|
|
853
|
+
import { createHash as createHash2 } from "crypto";
|
|
854
|
+
import {
|
|
855
|
+
existsSync as existsSync5,
|
|
856
|
+
lstatSync,
|
|
857
|
+
mkdirSync,
|
|
858
|
+
readdirSync,
|
|
859
|
+
readFileSync as readFileSync5,
|
|
860
|
+
writeFileSync as writeFileSync2
|
|
861
|
+
} from "fs";
|
|
859
862
|
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
|
-
}
|
|
863
|
+
import { createInterface } from "readline/promises";
|
|
864
|
+
import { fileURLToPath as fileURLToPath2, pathToFileURL as pathToFileURL2, URL as URL2 } from "url";
|
|
878
865
|
|
|
879
866
|
// src/package-manager.ts
|
|
880
867
|
import { spawnSync } from "child_process";
|
|
881
868
|
import { existsSync as existsSync4, readFileSync as readFileSync4 } from "fs";
|
|
882
|
-
import
|
|
869
|
+
import path8 from "path";
|
|
883
870
|
function detectPackageManager(cwd) {
|
|
884
|
-
for (let directory = cwd; ; directory =
|
|
885
|
-
if (existsSync4(
|
|
871
|
+
for (let directory = cwd; ; directory = path8.dirname(directory)) {
|
|
872
|
+
if (existsSync4(path8.join(directory, "pnpm-lock.yaml"))) {
|
|
886
873
|
return "pnpm";
|
|
887
874
|
}
|
|
888
|
-
if (existsSync4(
|
|
875
|
+
if (existsSync4(path8.join(directory, "package-lock.json"))) {
|
|
889
876
|
return "npm";
|
|
890
877
|
}
|
|
891
|
-
if (existsSync4(
|
|
878
|
+
if (existsSync4(path8.join(directory, "yarn.lock"))) {
|
|
892
879
|
return "yarn";
|
|
893
880
|
}
|
|
894
|
-
if (existsSync4(
|
|
881
|
+
if (existsSync4(path8.join(directory, "bun.lock")) || existsSync4(path8.join(directory, "bun.lockb"))) {
|
|
895
882
|
return "bun";
|
|
896
883
|
}
|
|
897
|
-
if (
|
|
884
|
+
if (path8.dirname(directory) === directory) {
|
|
898
885
|
break;
|
|
899
886
|
}
|
|
900
887
|
}
|
|
@@ -902,7 +889,7 @@ function detectPackageManager(cwd) {
|
|
|
902
889
|
}
|
|
903
890
|
function missingDependencies(cwd, requested) {
|
|
904
891
|
const manifest = JSON.parse(
|
|
905
|
-
readFileSync4(
|
|
892
|
+
readFileSync4(path8.join(cwd, "package.json"), "utf8")
|
|
906
893
|
);
|
|
907
894
|
const present = {
|
|
908
895
|
...manifest.dependencies,
|
|
@@ -926,6 +913,237 @@ function installDependencies(cwd, dependencies, quiet = false) {
|
|
|
926
913
|
}
|
|
927
914
|
}
|
|
928
915
|
|
|
916
|
+
// src/starter-archive.ts
|
|
917
|
+
import "buffer";
|
|
918
|
+
import { gunzipSync } from "zlib";
|
|
919
|
+
function readStarterArchive(bytes) {
|
|
920
|
+
const tar = gunzipSync(new Uint8Array(bytes), {
|
|
921
|
+
maxOutputLength: 32 * 1024 * 1024
|
|
922
|
+
});
|
|
923
|
+
const files2 = /* @__PURE__ */ new Map();
|
|
924
|
+
const invalid = () => new CliError("The starter archive is invalid or contains an unsafe path.");
|
|
925
|
+
const text = (start, length) => tar.subarray(start, start + length).toString("utf8").split("\0")[0];
|
|
926
|
+
let offset = 0;
|
|
927
|
+
while (offset + 512 <= tar.length) {
|
|
928
|
+
const header = tar.subarray(offset, offset + 512);
|
|
929
|
+
if (header.every((byte) => byte === 0)) {
|
|
930
|
+
if (tar.length < offset + 1024 || tar.length % 512 !== 0 || tar.subarray(offset).some((byte) => byte !== 0)) {
|
|
931
|
+
throw invalid();
|
|
932
|
+
}
|
|
933
|
+
for (const name3 of files2.keys()) {
|
|
934
|
+
const parts = name3.split("/");
|
|
935
|
+
parts.pop();
|
|
936
|
+
while (parts.length) {
|
|
937
|
+
if (files2.has(parts.join("/"))) {
|
|
938
|
+
throw invalid();
|
|
939
|
+
}
|
|
940
|
+
parts.pop();
|
|
941
|
+
}
|
|
942
|
+
}
|
|
943
|
+
return files2;
|
|
944
|
+
}
|
|
945
|
+
const checksum = header.reduce(
|
|
946
|
+
(sum, byte, index2) => sum + (index2 >= 148 && index2 < 156 ? 32 : byte),
|
|
947
|
+
0
|
|
948
|
+
);
|
|
949
|
+
const stored = text(offset + 148, 8).trim();
|
|
950
|
+
const sizeText = text(offset + 124, 12).trim();
|
|
951
|
+
const name2 = text(offset, 100);
|
|
952
|
+
const kind = text(offset + 156, 1);
|
|
953
|
+
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)) {
|
|
954
|
+
throw invalid();
|
|
955
|
+
}
|
|
956
|
+
const size = parseInt(sizeText, 8);
|
|
957
|
+
offset += 512;
|
|
958
|
+
if (!Number.isSafeInteger(size) || offset + size > tar.length) {
|
|
959
|
+
throw invalid();
|
|
960
|
+
}
|
|
961
|
+
files2.set(name2, tar.subarray(offset, offset + size));
|
|
962
|
+
offset += Math.ceil(size / 512) * 512;
|
|
963
|
+
}
|
|
964
|
+
throw invalid();
|
|
965
|
+
}
|
|
966
|
+
|
|
967
|
+
// src/init.ts
|
|
968
|
+
async function download(url) {
|
|
969
|
+
if (url.protocol === "file:") {
|
|
970
|
+
return readFileSync5(fileURLToPath2(url));
|
|
971
|
+
}
|
|
972
|
+
const response = await fetch(url.href, {
|
|
973
|
+
signal: AbortSignal.timeout(3e4)
|
|
974
|
+
});
|
|
975
|
+
if (!response.ok) {
|
|
976
|
+
throw new CliError(`Could not download the starter (${response.status}).`);
|
|
977
|
+
}
|
|
978
|
+
return Buffer2.from(await response.arrayBuffer());
|
|
979
|
+
}
|
|
980
|
+
async function initProject(command, cwd) {
|
|
981
|
+
const directory = path9.resolve(cwd, command.directory ?? ".");
|
|
982
|
+
if (existsSync5(directory) && (!lstatSync(directory).isDirectory() || readdirSync(directory).length > 0)) {
|
|
983
|
+
throw new CliError(
|
|
984
|
+
"Choose a new or empty folder. Existing-project init is not available yet."
|
|
985
|
+
);
|
|
986
|
+
}
|
|
987
|
+
if (command.template !== "react-router") {
|
|
988
|
+
throw new CliError("Choose react-router for --template.");
|
|
989
|
+
}
|
|
990
|
+
let { store, key } = command;
|
|
991
|
+
if (!command.yes && !command.json && process.stdin.isTTY && (!store || !key)) {
|
|
992
|
+
const prompt = createInterface({
|
|
993
|
+
input: process.stdin,
|
|
994
|
+
output: process.stdout
|
|
995
|
+
});
|
|
996
|
+
try {
|
|
997
|
+
store ||= await prompt.question("Store slug: ");
|
|
998
|
+
key ||= await prompt.question(
|
|
999
|
+
"Test publishable key (leave blank to set it later): "
|
|
1000
|
+
);
|
|
1001
|
+
} finally {
|
|
1002
|
+
prompt.close();
|
|
1003
|
+
}
|
|
1004
|
+
}
|
|
1005
|
+
if (!store || !/^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(store)) {
|
|
1006
|
+
throw new CliError(
|
|
1007
|
+
"Pass --store with your store slug, using lowercase letters, numbers and hyphens."
|
|
1008
|
+
);
|
|
1009
|
+
}
|
|
1010
|
+
if (key && !/^pk_test_[A-Za-z0-9_-]+$/.test(key)) {
|
|
1011
|
+
throw new CliError(
|
|
1012
|
+
"Use a pk_test_ publishable key. Live and secret keys are not accepted by init."
|
|
1013
|
+
);
|
|
1014
|
+
}
|
|
1015
|
+
const name2 = path9.basename(directory).toLowerCase().replace(/[^a-z0-9-]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 63) || "my-storefront";
|
|
1016
|
+
const source2 = command.registry ?? DEFAULT_REGISTRY;
|
|
1017
|
+
const base = /^[a-z]+:\/\//i.test(source2) ? new URL2(source2.endsWith("/") ? source2 : `${source2}/`) : pathToFileURL2(path9.resolve(cwd, source2) + path9.sep);
|
|
1018
|
+
const manifest = JSON.parse(
|
|
1019
|
+
(await download(new URL2("starters/index.json", base))).toString("utf8")
|
|
1020
|
+
);
|
|
1021
|
+
const template = manifest.templates?.[command.template];
|
|
1022
|
+
const entry = template?.versions?.[template.latest];
|
|
1023
|
+
if (!entry || !/^react-router@\d+\.\d+\.\d+(?:-[\w.-]+)?(?:\+[\w.-]+)?\.tgz$/.test(
|
|
1024
|
+
entry.file
|
|
1025
|
+
) || !/^[a-f0-9]{64}$/.test(entry.sha256) || !Number.isSafeInteger(entry.size) || entry.size <= 0) {
|
|
1026
|
+
throw new CliError("The starter manifest is invalid.");
|
|
1027
|
+
}
|
|
1028
|
+
const bytes = await download(new URL2(`starters/${entry.file}`, base));
|
|
1029
|
+
if (bytes.length !== entry.size || createHash2("sha256").update(new Uint8Array(bytes)).digest("hex") !== entry.sha256) {
|
|
1030
|
+
throw new CliError(
|
|
1031
|
+
"The starter archive does not match its manifest. Nothing was written."
|
|
1032
|
+
);
|
|
1033
|
+
}
|
|
1034
|
+
const files2 = readStarterArchive(bytes);
|
|
1035
|
+
for (const filename of [
|
|
1036
|
+
"package.json",
|
|
1037
|
+
"wrangler.jsonc",
|
|
1038
|
+
"zappie.config.ts",
|
|
1039
|
+
".gitignore"
|
|
1040
|
+
]) {
|
|
1041
|
+
const file = files2.get(filename);
|
|
1042
|
+
if (!file) {
|
|
1043
|
+
throw new CliError(
|
|
1044
|
+
`The starter is missing ${filename}. Nothing was written.`
|
|
1045
|
+
);
|
|
1046
|
+
}
|
|
1047
|
+
files2.set(
|
|
1048
|
+
filename,
|
|
1049
|
+
Buffer2.from(
|
|
1050
|
+
file.toString("utf8").replaceAll("__ZAPPIE_NAME__", name2).replaceAll("__ZAPPIE_STORE__", store)
|
|
1051
|
+
)
|
|
1052
|
+
);
|
|
1053
|
+
}
|
|
1054
|
+
if ([...files2.keys()].some((name3) => name3.startsWith(".dev.vars/"))) {
|
|
1055
|
+
throw new CliError(
|
|
1056
|
+
"The starter archive contains an unsafe path. Nothing was written."
|
|
1057
|
+
);
|
|
1058
|
+
}
|
|
1059
|
+
files2.set(
|
|
1060
|
+
".dev.vars",
|
|
1061
|
+
Buffer2.from(
|
|
1062
|
+
`ZAPPIE_API=https://api.zappie.ai/storefront/v1
|
|
1063
|
+
ZAPPIE_STORE=${store}
|
|
1064
|
+
ZAPPIE_KEY=${key || "pk_test_REPLACE_ME"}
|
|
1065
|
+
`
|
|
1066
|
+
)
|
|
1067
|
+
);
|
|
1068
|
+
mkdirSync(directory, { recursive: true });
|
|
1069
|
+
for (const [filename, contents] of files2) {
|
|
1070
|
+
const destination = path9.join(directory, filename);
|
|
1071
|
+
mkdirSync(path9.dirname(destination), { recursive: true });
|
|
1072
|
+
writeFileSync2(destination, new Uint8Array(contents), { flag: "wx" });
|
|
1073
|
+
}
|
|
1074
|
+
const manager = detectPackageManager(directory);
|
|
1075
|
+
const run = manager === "npm" ? "npm run" : manager;
|
|
1076
|
+
const next = [`${manager} install`, `${run} dev`, `${run} check`];
|
|
1077
|
+
const hint = key ? void 0 : "Set your test publishable key in .dev.vars before starting the storefront.";
|
|
1078
|
+
if (command.json) {
|
|
1079
|
+
console.log(
|
|
1080
|
+
JSON.stringify({
|
|
1081
|
+
command: "init",
|
|
1082
|
+
directory,
|
|
1083
|
+
template: command.template,
|
|
1084
|
+
version: template.latest,
|
|
1085
|
+
next,
|
|
1086
|
+
...hint ? { hint } : {}
|
|
1087
|
+
})
|
|
1088
|
+
);
|
|
1089
|
+
} else {
|
|
1090
|
+
console.log(
|
|
1091
|
+
`Created your storefront in ${directory}.
|
|
1092
|
+
${hint ? `${hint}
|
|
1093
|
+
` : ""}In that folder, run:
|
|
1094
|
+
${next.join("\n")}`
|
|
1095
|
+
);
|
|
1096
|
+
}
|
|
1097
|
+
}
|
|
1098
|
+
|
|
1099
|
+
// src/kit-add.ts
|
|
1100
|
+
import { existsSync as existsSync6, mkdirSync as mkdirSync2, readFileSync as readFileSync6, writeFileSync as writeFileSync3 } from "fs";
|
|
1101
|
+
import path12 from "path";
|
|
1102
|
+
|
|
1103
|
+
// src/kit-files.ts
|
|
1104
|
+
import path10 from "path";
|
|
1105
|
+
function safeTarget(cwd, target) {
|
|
1106
|
+
const normalized = target.replaceAll("\\", "/");
|
|
1107
|
+
if (normalized.startsWith("/") || /^[A-Za-z]:\//.test(normalized) || normalized.split("/").includes("..")) {
|
|
1108
|
+
throw new CliError(
|
|
1109
|
+
`Registry target points outside your project root: ${target}`
|
|
1110
|
+
);
|
|
1111
|
+
}
|
|
1112
|
+
const absolute = path10.resolve(cwd, normalized);
|
|
1113
|
+
if (absolute !== cwd && !absolute.startsWith(`${cwd}${path10.sep}`)) {
|
|
1114
|
+
throw new CliError(
|
|
1115
|
+
`Registry target points outside your project root: ${target}`
|
|
1116
|
+
);
|
|
1117
|
+
}
|
|
1118
|
+
return { normalized, absolute };
|
|
1119
|
+
}
|
|
1120
|
+
function verifySource(item2, file) {
|
|
1121
|
+
if (sha256(file.content) !== file.sha256) {
|
|
1122
|
+
throw new CliError(`The registry hash does not match ${item2}.`);
|
|
1123
|
+
}
|
|
1124
|
+
}
|
|
1125
|
+
|
|
1126
|
+
// src/kit-imports.ts
|
|
1127
|
+
import path11 from "path";
|
|
1128
|
+
var IMPORT = /(\bfrom\s+|\bimport\s*)(["'])(@\/components\/zappie\/([^"']+))\2/g;
|
|
1129
|
+
function posixRelative(from, to) {
|
|
1130
|
+
const value = path11.posix.relative(path11.posix.dirname(from), to);
|
|
1131
|
+
return value.startsWith(".") ? value : `./${value}`;
|
|
1132
|
+
}
|
|
1133
|
+
function rewriteKitImports(content, target, componentsDir, alias) {
|
|
1134
|
+
return content.replace(
|
|
1135
|
+
IMPORT,
|
|
1136
|
+
(match, keyword, quote, specifier, sibling) => {
|
|
1137
|
+
const replacement = alias ? `${alias.replace(/\/$/, "")}/${sibling}` : posixRelative(target, `${componentsDir}/${sibling}`);
|
|
1138
|
+
return `${keyword}${quote}${replacement}${quote}`;
|
|
1139
|
+
}
|
|
1140
|
+
);
|
|
1141
|
+
}
|
|
1142
|
+
function installTarget(target, componentsDir) {
|
|
1143
|
+
const normalized = target.replaceAll("\\", "/");
|
|
1144
|
+
return normalized.startsWith("components/zappie/") ? `${componentsDir}/${normalized.slice("components/zappie/".length)}` : normalized;
|
|
1145
|
+
}
|
|
1146
|
+
|
|
929
1147
|
// src/registry-graph.ts
|
|
930
1148
|
async function batches(values, size, read) {
|
|
931
1149
|
const output = [];
|
|
@@ -1021,8 +1239,8 @@ async function addItems(options) {
|
|
|
1021
1239
|
project2.alias
|
|
1022
1240
|
);
|
|
1023
1241
|
const installedHash = project2.installed[item2.name]?.files[safe.normalized];
|
|
1024
|
-
if (
|
|
1025
|
-
const currentHash = sha256(
|
|
1242
|
+
if (existsSync6(safe.absolute)) {
|
|
1243
|
+
const currentHash = sha256(readFileSync6(safe.absolute, "utf8"));
|
|
1026
1244
|
if (currentHash !== installedHash && !options.overwrite) {
|
|
1027
1245
|
throw new CliError(
|
|
1028
1246
|
`${safe.normalized} has local changes. Pass --overwrite to replace it.`
|
|
@@ -1056,9 +1274,9 @@ async function addItems(options) {
|
|
|
1056
1274
|
installDependencies(options.cwd, dependencies, options.json);
|
|
1057
1275
|
}
|
|
1058
1276
|
for (const file of planned) {
|
|
1059
|
-
const absolute =
|
|
1060
|
-
|
|
1061
|
-
|
|
1277
|
+
const absolute = path12.join(options.cwd, file.target);
|
|
1278
|
+
mkdirSync2(path12.dirname(absolute), { recursive: true });
|
|
1279
|
+
writeFileSync3(absolute, file.content);
|
|
1062
1280
|
}
|
|
1063
1281
|
const installed = { ...project2.installed };
|
|
1064
1282
|
for (const item2 of items) {
|
|
@@ -1089,11 +1307,11 @@ function planText(result) {
|
|
|
1089
1307
|
}
|
|
1090
1308
|
|
|
1091
1309
|
// src/kit-apply.ts
|
|
1092
|
-
import { mkdirSync as
|
|
1093
|
-
import
|
|
1310
|
+
import { mkdirSync as mkdirSync3, rmSync, writeFileSync as writeFileSync4 } from "fs";
|
|
1311
|
+
import path13 from "path";
|
|
1094
1312
|
|
|
1095
1313
|
// src/kit-apply-plan.ts
|
|
1096
|
-
import { existsSync as
|
|
1314
|
+
import { existsSync as existsSync7, readFileSync as readFileSync7 } from "fs";
|
|
1097
1315
|
|
|
1098
1316
|
// src/three-way.ts
|
|
1099
1317
|
import { diff3Merge } from "node-diff3";
|
|
@@ -1159,7 +1377,7 @@ function conflict(file, reason, hunks = []) {
|
|
|
1159
1377
|
}
|
|
1160
1378
|
function planFile(cwd, target, base, theirs, installedHash) {
|
|
1161
1379
|
const absolute = safeTarget(cwd, target).absolute;
|
|
1162
|
-
const ours =
|
|
1380
|
+
const ours = existsSync7(absolute) ? readFileSync7(absolute, "utf8") : void 0;
|
|
1163
1381
|
if (base === void 0 && theirs !== void 0) {
|
|
1164
1382
|
if (ours !== void 0 && ours !== theirs) {
|
|
1165
1383
|
return {
|
|
@@ -1305,8 +1523,8 @@ async function applyDiff(options) {
|
|
|
1305
1523
|
if (action.kind === "delete") {
|
|
1306
1524
|
rmSync(absolute, { force: true });
|
|
1307
1525
|
} else {
|
|
1308
|
-
|
|
1309
|
-
|
|
1526
|
+
mkdirSync3(path13.dirname(absolute), { recursive: true });
|
|
1527
|
+
writeFileSync4(absolute, action.content);
|
|
1310
1528
|
}
|
|
1311
1529
|
}
|
|
1312
1530
|
installed[name2] = planned.next;
|
|
@@ -1346,8 +1564,8 @@ function applyText(items) {
|
|
|
1346
1564
|
}
|
|
1347
1565
|
|
|
1348
1566
|
// src/kit-status.ts
|
|
1349
|
-
import { existsSync as
|
|
1350
|
-
import
|
|
1567
|
+
import { existsSync as existsSync8, readFileSync as readFileSync8 } from "fs";
|
|
1568
|
+
import path14 from "path";
|
|
1351
1569
|
|
|
1352
1570
|
// src/unified-diff.ts
|
|
1353
1571
|
function unifiedDiff(file, before, after) {
|
|
@@ -1375,8 +1593,8 @@ function project(cwd) {
|
|
|
1375
1593
|
}
|
|
1376
1594
|
function modified(cwd, files2) {
|
|
1377
1595
|
return Object.entries(files2).some(([file, installedHash]) => {
|
|
1378
|
-
const target =
|
|
1379
|
-
return !
|
|
1596
|
+
const target = path14.join(cwd, file);
|
|
1597
|
+
return !existsSync8(target) || sha256(readFileSync8(target, "utf8")) !== installedHash;
|
|
1380
1598
|
});
|
|
1381
1599
|
}
|
|
1382
1600
|
function state(local, update) {
|
|
@@ -1478,7 +1696,7 @@ async function upstreamDiffs(registry, name2, installedVersion, latestVersion) {
|
|
|
1478
1696
|
|
|
1479
1697
|
// src/verify-command.ts
|
|
1480
1698
|
import { mkdir, writeFile } from "fs/promises";
|
|
1481
|
-
import
|
|
1699
|
+
import path15 from "path";
|
|
1482
1700
|
async function runProjectVerify(options) {
|
|
1483
1701
|
const key = options.key ?? process.env.ZAPPIE_KEY;
|
|
1484
1702
|
if (key?.startsWith("pk_live_")) {
|
|
@@ -1504,8 +1722,8 @@ async function runProjectVerify(options) {
|
|
|
1504
1722
|
...options.signal ? { signal: options.signal } : {}
|
|
1505
1723
|
});
|
|
1506
1724
|
if (options.report) {
|
|
1507
|
-
const file =
|
|
1508
|
-
await mkdir(
|
|
1725
|
+
const file = path15.resolve(options.cwd, options.report);
|
|
1726
|
+
await mkdir(path15.dirname(file), { recursive: true });
|
|
1509
1727
|
await writeFile(file, `${JSON.stringify(result, null, 2)}
|
|
1510
1728
|
`);
|
|
1511
1729
|
}
|
|
@@ -1544,6 +1762,10 @@ async function main(argv) {
|
|
|
1544
1762
|
const command = parseCommand(argv);
|
|
1545
1763
|
const cwd = process.cwd();
|
|
1546
1764
|
switch (command.name) {
|
|
1765
|
+
case "init": {
|
|
1766
|
+
await initProject(command, cwd);
|
|
1767
|
+
return 0;
|
|
1768
|
+
}
|
|
1547
1769
|
case "help": {
|
|
1548
1770
|
console.log(usage);
|
|
1549
1771
|
return 0;
|
|
@@ -1599,7 +1821,7 @@ async function main(argv) {
|
|
|
1599
1821
|
return result.failed ? 1 : 0;
|
|
1600
1822
|
}
|
|
1601
1823
|
case "check": {
|
|
1602
|
-
const directory =
|
|
1824
|
+
const directory = path16.resolve(cwd, command.directory ?? ".");
|
|
1603
1825
|
const controller = new AbortController();
|
|
1604
1826
|
const abort = () => controller.abort(new Error("Check cancelled."));
|
|
1605
1827
|
process.once("SIGINT", abort);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zappie",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "Install Zappie kit components and check storefront projects.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -8,7 +8,8 @@
|
|
|
8
8
|
},
|
|
9
9
|
"files": [
|
|
10
10
|
"bin",
|
|
11
|
-
"dist"
|
|
11
|
+
"dist",
|
|
12
|
+
"CHANGELOG.md"
|
|
12
13
|
],
|
|
13
14
|
"engines": {
|
|
14
15
|
"node": ">=20"
|