create-shopnex 0.15.0 → 0.16.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/README.md +18 -3
- package/dist/main.mjs +55 -19
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -3,6 +3,9 @@
|
|
|
3
3
|
Try ShopNex on your machine with one command. It starts the admin (with the API and hosted checkout) and the
|
|
4
4
|
storefront on an embedded database ([PGlite](https://pglite.dev)): no PostgreSQL, no Docker, no clone.
|
|
5
5
|
|
|
6
|
+
New here? Read [Getting started](getting-started/README.md) first: a short walk-through from the first command to a
|
|
7
|
+
running shop. This page is the full reference.
|
|
8
|
+
|
|
6
9
|
## Run it
|
|
7
10
|
|
|
8
11
|
```sh
|
|
@@ -23,6 +26,18 @@ The first run downloads ShopNex (one file, about 15 MB) into `~/.shopnex/app/<ve
|
|
|
23
26
|
runs start straight away. It prints where to open the shop and the admin and opens the admin's setup wizard (use
|
|
24
27
|
`--no-open` to skip that). Ctrl+C stops everything. Nothing is installed globally.
|
|
25
28
|
|
|
29
|
+
## Run it again
|
|
30
|
+
|
|
31
|
+
The shop folder has a `package.json`, so from inside it:
|
|
32
|
+
|
|
33
|
+
```sh
|
|
34
|
+
cd shopnex
|
|
35
|
+
npm start # or: npm run dev
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
No `npm install` first: both scripts run `npx --yes create-shopnex@<version> .`, the version that made the folder, and
|
|
39
|
+
npx fetches it into its cache the first time. The same works from the folder above: `npx create-shopnex@latest shopnex`.
|
|
40
|
+
|
|
26
41
|
## What it does, and why you can trust it
|
|
27
42
|
|
|
28
43
|
- **It runs on your machine only.** Both servers listen on `127.0.0.1`, and the data stays in the shop folder (`shopnex/data` by default).
|
|
@@ -73,13 +88,13 @@ SHOPNEX_SECRET=<generated once> # encrypts the provider keys saved in the admi
|
|
|
73
88
|
```
|
|
74
89
|
|
|
75
90
|
- **PostgreSQL:** set `DATABASE_URL=postgres://user:password@host:5432/shopnex` and start again. The migrations are applied
|
|
76
|
-
on start (`SHOPNEX_AUTO_MIGRATE`).
|
|
91
|
+
on start (`SHOPNEX_AUTO_MIGRATE`). To move the data from `.pglite/`, run `npx shopnex migrate-db` (see [Getting started](getting-started/README.md)).
|
|
77
92
|
- **Other settings** in the file (SMTP, and so on) are passed to the admin. The address, the ports and the build's own
|
|
78
93
|
files are set by the CLI and its flags and win over the file.
|
|
79
94
|
- Do not commit or share it. Without `SHOPNEX_SECRET` the saved provider keys cannot be read: a lost one means a new
|
|
80
95
|
shop.
|
|
81
96
|
|
|
82
|
-
The first run also writes a `.gitignore` (keeps `.env`, `.pglite/` and the apps' keys out of git) and the
|
|
97
|
+
The first run also writes a `README.md` (how to run the shop again), a `package.json` (for `npm start`), a `.gitignore` (keeps `.env`, `.pglite/` and the apps' keys out of git) and the
|
|
83
98
|
`docker-compose.yml` (fetched from the repository, the file the [self-hosting docs](https://shopnex.ai/docs/self-hosting/docker) describe: ShopNex, the Stripe
|
|
84
99
|
app and PostgreSQL from prebuilt images), for when the shop should run in Docker instead. Existing files are never
|
|
85
100
|
overwritten.
|
|
@@ -89,7 +104,7 @@ To start over, delete the shop folder.
|
|
|
89
104
|
## Not for production
|
|
90
105
|
|
|
91
106
|
One process owns the data, so nothing else can open the folder, and the servers listen on `127.0.0.1` only. Use
|
|
92
|
-
Docker or PostgreSQL for a real shop
|
|
107
|
+
Docker or PostgreSQL for a real shop, and move the data with `npx shopnex migrate-db`.
|
|
93
108
|
|
|
94
109
|
## Where the build comes from
|
|
95
110
|
|
package/dist/main.mjs
CHANGED
|
@@ -40,7 +40,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
40
40
|
var define_PKG_default;
|
|
41
41
|
var init_define_PKG = __esm({
|
|
42
42
|
"<define:__PKG__>"() {
|
|
43
|
-
define_PKG_default = { version: "0.
|
|
43
|
+
define_PKG_default = { version: "0.16.1", engines: { node: ">=22.22.0" } };
|
|
44
44
|
}
|
|
45
45
|
});
|
|
46
46
|
|
|
@@ -678,7 +678,7 @@ function me() {
|
|
|
678
678
|
init_define_PKG();
|
|
679
679
|
import { parseArgs } from "node:util";
|
|
680
680
|
|
|
681
|
-
// src/errors.ts
|
|
681
|
+
// ../cli-core/src/errors.ts
|
|
682
682
|
init_define_PKG();
|
|
683
683
|
var UsageError = class extends Error {
|
|
684
684
|
};
|
|
@@ -879,7 +879,16 @@ var extras = [
|
|
|
879
879
|
keyEnv: "CJ_DROPSHIPPING_APP_KEY",
|
|
880
880
|
database: true
|
|
881
881
|
},
|
|
882
|
-
{ name: "shippo", label: "Shippo", dir: "shippo", port: 4900, urlEnv: "SHIPPO_APP_URL", keyEnv: "SHIPPO_APP_KEY" }
|
|
882
|
+
{ name: "shippo", label: "Shippo", dir: "shippo", port: 4900, urlEnv: "SHIPPO_APP_URL", keyEnv: "SHIPPO_APP_KEY" },
|
|
883
|
+
{
|
|
884
|
+
name: "reviews",
|
|
885
|
+
label: "Reviews",
|
|
886
|
+
dir: "reviews",
|
|
887
|
+
port: 5100,
|
|
888
|
+
urlEnv: "REVIEWS_APP_URL",
|
|
889
|
+
keyEnv: "REVIEWS_APP_KEY",
|
|
890
|
+
database: true
|
|
891
|
+
}
|
|
883
892
|
];
|
|
884
893
|
function pickExtras(values, list = extras) {
|
|
885
894
|
const names = (values ?? []).flatMap((value) => value.split(",")).map((name) => name.trim().toLowerCase());
|
|
@@ -893,7 +902,7 @@ function pickExtras(values, list = extras) {
|
|
|
893
902
|
return picked;
|
|
894
903
|
}
|
|
895
904
|
|
|
896
|
-
// src/bundle.ts
|
|
905
|
+
// ../cli-core/src/bundle.ts
|
|
897
906
|
init_define_PKG();
|
|
898
907
|
import { createHash } from "node:crypto";
|
|
899
908
|
import {
|
|
@@ -911,7 +920,7 @@ import { spawnSync } from "node:child_process";
|
|
|
911
920
|
import { Readable, Transform } from "node:stream";
|
|
912
921
|
import { pipeline } from "node:stream/promises";
|
|
913
922
|
|
|
914
|
-
// src/paths.ts
|
|
923
|
+
// ../cli-core/src/paths.ts
|
|
915
924
|
init_define_PKG();
|
|
916
925
|
import { homedir } from "node:os";
|
|
917
926
|
import { join as join3, resolve } from "node:path";
|
|
@@ -923,14 +932,14 @@ function resolveShopDir(name, cwd = process.cwd()) {
|
|
|
923
932
|
}
|
|
924
933
|
var appCacheDir = () => process.env.SHOPNEX_APP_DIR ?? join3(homedir(), ".shopnex", "app");
|
|
925
934
|
|
|
926
|
-
// src/bundle.ts
|
|
935
|
+
// ../cli-core/src/bundle.ts
|
|
927
936
|
var isEdge = (version) => /-edge\./.test(version);
|
|
928
937
|
var bundleName = (version) => `shopnex-v${version}-node.tgz`;
|
|
929
938
|
var bundleUrl = (version) => process.env.SHOPNEX_BUNDLE_URL ?? (isEdge(version) ? "https://github.com/shopnex-ai/shopnex/releases/download/edge/shopnex-edge-node.tgz" : `https://github.com/shopnex-ai/shopnex/releases/download/v${version}/${bundleName(version)}`);
|
|
930
939
|
var bundleDir = (key) => join4(appCacheDir(), key);
|
|
931
940
|
var isInstalled = (key) => existsSync2(join4(bundleDir(key), "manifest.json"));
|
|
932
941
|
var installedEdges = () => existsSync2(appCacheDir()) ? readdirSync(appCacheDir()).filter((name) => /^edge-[0-9a-f]{12}$/.test(name)) : [];
|
|
933
|
-
async function get(url, what, version) {
|
|
942
|
+
async function get(url, what, version, cli) {
|
|
934
943
|
let response;
|
|
935
944
|
try {
|
|
936
945
|
response = await fetch(url);
|
|
@@ -942,7 +951,7 @@ Check your connection and try again.`);
|
|
|
942
951
|
if (response.status === 404) {
|
|
943
952
|
throw new UnavailableError(
|
|
944
953
|
`ShopNex ${version} has no packaged build to download (404 for ${url}).
|
|
945
|
-
Use a released version of
|
|
954
|
+
Use a released version of ${cli}.`
|
|
946
955
|
);
|
|
947
956
|
}
|
|
948
957
|
if (!response.ok) {
|
|
@@ -969,7 +978,7 @@ async function download(response, file, onProgress) {
|
|
|
969
978
|
);
|
|
970
979
|
return hash.digest("hex");
|
|
971
980
|
}
|
|
972
|
-
async function resolveBundle({ version }) {
|
|
981
|
+
async function resolveBundle({ version, cli = "create-shopnex" }) {
|
|
973
982
|
const edge = isEdge(version);
|
|
974
983
|
if (!edge && isInstalled(version)) return bundleDir(version);
|
|
975
984
|
mkdirSync2(appCacheDir(), { recursive: true });
|
|
@@ -982,7 +991,7 @@ async function resolveBundle({ version }) {
|
|
|
982
991
|
let work;
|
|
983
992
|
try {
|
|
984
993
|
const url = bundleUrl(version);
|
|
985
|
-
const expected = parseChecksum(await (await get(`${url}.sha256`, "the checksum", version)).text());
|
|
994
|
+
const expected = parseChecksum(await (await get(`${url}.sha256`, "the checksum", version, cli)).text());
|
|
986
995
|
if (!/^[0-9a-f]{64}$/.test(expected)) throw new UnavailableError(`${url}.sha256 does not hold a SHA-256 checksum.`);
|
|
987
996
|
const key = edge ? `edge-${expected.slice(0, 12)}` : version;
|
|
988
997
|
const dir = bundleDir(key);
|
|
@@ -995,7 +1004,7 @@ async function resolveBundle({ version }) {
|
|
|
995
1004
|
work = mkdtempSync(join4(appCacheDir(), `${key}.tmp-`));
|
|
996
1005
|
const file = join4(work, "bundle.tgz");
|
|
997
1006
|
const actual = await download(
|
|
998
|
-
await get(url, "ShopNex", version),
|
|
1007
|
+
await get(url, "ShopNex", version, cli),
|
|
999
1008
|
file,
|
|
1000
1009
|
(bytes) => say(`Downloading ${label}: ${(bytes / 1e6).toFixed(1)} MB`)
|
|
1001
1010
|
);
|
|
@@ -1032,7 +1041,7 @@ async function resolveBundle({ version }) {
|
|
|
1032
1041
|
}
|
|
1033
1042
|
}
|
|
1034
1043
|
|
|
1035
|
-
// src/node-version.ts
|
|
1044
|
+
// ../cli-core/src/node-version.ts
|
|
1036
1045
|
init_define_PKG();
|
|
1037
1046
|
var atLeast = (version, minimum) => version.replace(/^v/, "").localeCompare(minimum, void 0, { numeric: true }) >= 0;
|
|
1038
1047
|
function assertNode(version, enginesRange) {
|
|
@@ -1044,7 +1053,7 @@ function assertNode(version, enginesRange) {
|
|
|
1044
1053
|
}
|
|
1045
1054
|
}
|
|
1046
1055
|
|
|
1047
|
-
// src/env.ts
|
|
1056
|
+
// ../cli-core/src/env.ts
|
|
1048
1057
|
init_define_PKG();
|
|
1049
1058
|
import { randomBytes } from "node:crypto";
|
|
1050
1059
|
import { existsSync as existsSync3, mkdirSync as mkdirSync3, readFileSync as readFileSync3, appendFileSync, writeFileSync as writeFileSync2 } from "node:fs";
|
|
@@ -1095,18 +1104,42 @@ function loadShopEnv(shopDir, { write }) {
|
|
|
1095
1104
|
// src/scaffold.ts
|
|
1096
1105
|
init_define_PKG();
|
|
1097
1106
|
import { existsSync as existsSync4, mkdirSync as mkdirSync4, writeFileSync as writeFileSync3 } from "node:fs";
|
|
1098
|
-
import { join as join6 } from "node:path";
|
|
1107
|
+
import { basename, join as join6 } from "node:path";
|
|
1108
|
+
|
|
1109
|
+
// src/readme.ts
|
|
1110
|
+
init_define_PKG();
|
|
1111
|
+
var template2 = true ? "# Getting started with ShopNex\n\nRun a ShopNex shop on your machine in a few minutes. No PostgreSQL, no Docker, no clone.\n\nWhen it is running you have:\n\n- the **admin** at http://localhost:3000/admin\n- the **storefront** at http://localhost:4321\n- a **database** in the shop folder (embedded, for trying things out)\n\n## You need\n\n- Node.js 22.22 or newer\n- Free ports `3000` (admin, API, checkout) and `4321` (storefront). Other ports: `--port` and `--storefront-port`.\n\n## 1. Start the shop\n\n```sh\nnpx create-shopnex@latest my-shop\n```\n\nThis creates the folder `my-shop`, downloads ShopNex once (about 15 MB, kept in `~/.shopnex/app` and shared by all\nyour shops), starts the admin and the storefront, and opens the admin in your browser. The first start takes a minute.\nLeave the terminal open: Ctrl+C stops the shop.\n\n## 2. Create the owner account\n\nThe admin opens the setup wizard on the first run. Create the owner account right away: until you do, whoever reaches\nthe admin can. Both servers listen on your machine only (`127.0.0.1`).\n\nThen open the storefront at http://localhost:4321 and the admin at http://localhost:3000/admin.\n\n## 3. Run it again\n\n```sh\ncd my-shop\nnpm start\n```\n\n`npm run dev` does the same. Nothing to install first: the script runs `npx --yes create-shopnex@<version> .` with the\nversion that made the folder. The shop's data stays in the folder, so the same folder is the same shop.\n\n## 4. Add your first product\n\nIn the admin, add a product (a name and a price are enough), then reload the storefront: it shows up there. That is the\nwhole loop: you change things in the admin, customers see them in the storefront.\n\nTo try a card payment, start the Stripe app next to the shop (`--with stripe`, see below), install it from the admin and\nenter your Stripe **test** keys; the test card is `4242 4242 4242 4242`. Stripe cannot reach a `localhost` address, so\npayments need a public address for the app or `stripe listen`: the Stripe app's settings page explains it.\n\n## Update\n\n`npm start` runs the version written in the shop's `package.json` (`create-shopnex@<version>`), so it never changes by\nitself. To move to a newer version:\n\n1. Stop the shop and copy the folder somewhere as a backup.\n2. Change the version in the two scripts of `package.json` (or run `npx create-shopnex@latest my-shop` once).\n3. Start it again. The database changes the new version needs are applied on start.\n\n## What is in the folder\n\n| File | What it is |\n| -------------------- | ---------------------------------------------------------------------------------------------------------------- |\n| `.env` | The shop's settings and secrets. Keep it out of git; a lost `SHOPNEX_SECRET` means a new shop |\n| `.pglite/` | The embedded trial database |\n| `docker-compose.yml` | For running the shop in Docker instead: see the [self-hosting docs](https://shopnex.ai/docs/self-hosting/docker) |\n| `README.md` | How to run this shop again |\n\n## Next\n\n- **Payments and shipping:** start the optional apps next to the shop with\n `npx create-shopnex@latest my-shop --with stripe,cj,shippo`, then install them from the admin and enter your keys.\n- **From trying it to a real shop:** the embedded database is for trying ShopNex out (one process owns it), so move to\n PostgreSQL before you rely on the shop. With the shop stopped, run this in its folder with an empty PostgreSQL database:\n\n ```sh\n TARGET=postgres://user:password@host:5432/shopnex npx shopnex migrate-db --to-env TARGET\n ```\n\n It copies the data, keeps a copy of the old data next to it and points the `.env` at PostgreSQL. Then run the shop in\n Docker with the `docker-compose.yml` ([self-hosting docs](https://shopnex.ai/docs/self-hosting/docker)).\n\n- **Every option and how the download is checked:** the [package README](https://github.com/shopnex-ai/shopnex/tree/main/packages/create-shopnex#readme).\n\n## If something goes wrong\n\n- **A port is taken:** the command stops before downloading anything and names the flag to change (`--port`,\n `--storefront-port`).\n- **No connection:** the first run needs the network for the download; later runs do not.\n- **Servers will not start:** run again with `--verbose` to see their output.\n- **Start over:** delete the shop folder.\n" : readFileSync(new URL("../getting-started/README.md", import.meta.url), "utf8");
|
|
1112
|
+
var EXAMPLE_NAME = "my-shop";
|
|
1113
|
+
var readme = (name) => template2.replaceAll(EXAMPLE_NAME, name);
|
|
1114
|
+
|
|
1115
|
+
// src/scaffold.ts
|
|
1099
1116
|
var GITIGNORE = `# ShopNex: secrets and local data stay out of git
|
|
1100
1117
|
.env
|
|
1101
1118
|
.pglite/
|
|
1102
1119
|
apps/*/.pglite/
|
|
1103
1120
|
apps/*/app-key
|
|
1104
1121
|
`;
|
|
1122
|
+
var packageJson = (name, version) => {
|
|
1123
|
+
const run2 = `npx --yes create-shopnex@${version} .`;
|
|
1124
|
+
return JSON.stringify(
|
|
1125
|
+
{
|
|
1126
|
+
name: name.toLowerCase().replace(/[^a-z0-9._-]+/g, "-").replace(/^[._-]+/, "") || "shopnex-shop",
|
|
1127
|
+
private: true,
|
|
1128
|
+
scripts: { start: run2, dev: run2 }
|
|
1129
|
+
},
|
|
1130
|
+
null,
|
|
1131
|
+
2
|
|
1132
|
+
) + "\n";
|
|
1133
|
+
};
|
|
1105
1134
|
var composeUrl = (version) => `https://raw.githubusercontent.com/shopnex-ai/shopnex/${isEdge(version) ? "main" : `v${version}`}/deploy/docker-compose.yml`;
|
|
1106
1135
|
async function writeScaffold(shopDir, version, fetcher = fetch) {
|
|
1107
1136
|
mkdirSync4(shopDir, { recursive: true });
|
|
1108
1137
|
const gitignore = join6(shopDir, ".gitignore");
|
|
1109
1138
|
if (!existsSync4(gitignore)) writeFileSync3(gitignore, GITIGNORE);
|
|
1139
|
+
const pkgFile = join6(shopDir, "package.json");
|
|
1140
|
+
if (!existsSync4(pkgFile)) writeFileSync3(pkgFile, packageJson(basename(shopDir), version));
|
|
1141
|
+
const readmeFile = join6(shopDir, "README.md");
|
|
1142
|
+
if (!existsSync4(readmeFile)) writeFileSync3(readmeFile, readme(basename(shopDir)));
|
|
1110
1143
|
const compose = join6(shopDir, "docker-compose.yml");
|
|
1111
1144
|
if (existsSync4(compose)) return;
|
|
1112
1145
|
const url = composeUrl(version);
|
|
@@ -1119,7 +1152,7 @@ async function writeScaffold(shopDir, version, fetcher = fetch) {
|
|
|
1119
1152
|
}
|
|
1120
1153
|
}
|
|
1121
1154
|
|
|
1122
|
-
// src/theme.ts
|
|
1155
|
+
// ../cli-core/src/theme.ts
|
|
1123
1156
|
init_define_PKG();
|
|
1124
1157
|
var import_picocolors2 = __toESM(require_picocolors(), 1);
|
|
1125
1158
|
var BRAND = [67, 192, 122];
|
|
@@ -1128,12 +1161,9 @@ var truecolor = import_picocolors2.default.isColorSupported && /^(truecolor|24bi
|
|
|
1128
1161
|
var brand = (text) => truecolor ? `\x1B[38;2;${BRAND.join(";")}m${text}\x1B[39m` : import_picocolors2.default.green(text);
|
|
1129
1162
|
var brandBadge = (text) => truecolor ? `\x1B[48;2;${BRAND.join(";")}m\x1B[38;2;${ON_BRAND.join(";")}m${text}\x1B[39m\x1B[49m` : import_picocolors2.default.bgGreen(import_picocolors2.default.black(text));
|
|
1130
1163
|
|
|
1131
|
-
// src/
|
|
1164
|
+
// ../cli-core/src/ports.ts
|
|
1132
1165
|
init_define_PKG();
|
|
1133
|
-
import { spawn } from "node:child_process";
|
|
1134
1166
|
import { connect } from "node:net";
|
|
1135
|
-
var import_picocolors3 = __toESM(require_picocolors(), 1);
|
|
1136
|
-
var sleep = (ms) => new Promise((resolve3) => setTimeout(resolve3, ms));
|
|
1137
1167
|
function portInUse(port) {
|
|
1138
1168
|
const tryHost = (host) => new Promise((resolve3) => {
|
|
1139
1169
|
const socket = connect({ port, host });
|
|
@@ -1151,6 +1181,12 @@ async function assertPortsFree(ports) {
|
|
|
1151
1181
|
}
|
|
1152
1182
|
}
|
|
1153
1183
|
}
|
|
1184
|
+
|
|
1185
|
+
// src/run.ts
|
|
1186
|
+
init_define_PKG();
|
|
1187
|
+
import { spawn } from "node:child_process";
|
|
1188
|
+
var import_picocolors3 = __toESM(require_picocolors(), 1);
|
|
1189
|
+
var sleep = (ms) => new Promise((resolve3) => setTimeout(resolve3, ms));
|
|
1154
1190
|
async function isUp(url) {
|
|
1155
1191
|
try {
|
|
1156
1192
|
return (await fetch(url, { redirect: "manual" })).status < 500;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-shopnex",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.16.1",
|
|
4
4
|
"description": "Try ShopNex with one command: npx create-shopnex starts the admin and the storefront on an embedded database, nothing else to install",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://shopnex.ai",
|
|
@@ -37,6 +37,7 @@
|
|
|
37
37
|
"test": "tsx --test \"tests/**/*.test.ts\""
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
|
+
"@shopnex/cli-core": "workspace:*",
|
|
40
41
|
"@clack/prompts": "^0.7.0",
|
|
41
42
|
"@types/node": "catalog:",
|
|
42
43
|
"esbuild": "0.28.2",
|