create-shopnex 0.16.1 → 0.17.0

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.
Files changed (3) hide show
  1. package/README.md +19 -14
  2. package/dist/main.mjs +63 -14
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -56,24 +56,29 @@ npx fetches it into its cache the first time. The same works from the folder abo
56
56
 
57
57
  ## Options
58
58
 
59
- | Option | What it does |
60
- | ----------------------- | --------------------------------------------------------------------------------------------------------- |
61
- | `[name]` | The shop's folder, created if needed. `shopnex` when left out; the same folder is the same shop |
62
- | `--port <n>` | Admin, API and checkout. Default `3000` |
63
- | `--storefront-port <n>` | Storefront. Default `4321` |
64
- | `--no-open` | Do not open the browser |
65
- | `--with <apps>` | Also start optional apps next to the shop: `stripe`, `cj`, `shippo` (comma separated, or repeat the flag) |
66
- | `--app <name>` | What to start. Only `shop` today; a picker appears once there is more than one |
67
- | `--verbose` | Show the servers' output while they start (otherwise only if one fails) |
68
- | `--dry-run` | Show what would run, and exit |
69
-
70
- ## Apps: Stripe, CJ Dropshipping and Shippo
59
+ | Option | What it does |
60
+ | ----------------------- | ------------------------------------------------------------------------------------------------------------------------------------------- |
61
+ | `[name]` | The shop's folder, created if needed. `shopnex` when left out; the same folder is the same shop |
62
+ | `--port <n>` | Admin, API and checkout. Default `3000` |
63
+ | `--storefront-port <n>` | Storefront. Default `4321` |
64
+ | `--no-open` | Do not open the browser |
65
+ | `--with <apps>` | Start only these apps: `stripe`, `cj`, `shippo`, `reviews` (comma separated, or repeat the flag). All four start by default |
66
+ | `--no-apps` | Start the shop alone, without the bundled apps |
67
+ | `--from <store>` | Bring a Shopify or WooCommerce store across: products, collections, pages and the look. It starts after you create the owner in the browser |
68
+ | `--app <name>` | What to start. Only `shop` today; a picker appears once there is more than one |
69
+ | `--verbose` | Show the servers' output while they start (otherwise only if one fails) |
70
+ | `--dry-run` | Show what would run, and exit |
71
+
72
+ ## Apps: Stripe, CJ Dropshipping, Shippo and Reviews
73
+
74
+ All the bundled apps start by default. Pick some, or none:
71
75
 
72
76
  ```sh
73
- npx create-shopnex@latest --with stripe,cj,shippo
77
+ npx create-shopnex@latest --with stripe,reviews # only these
78
+ npx create-shopnex@latest --no-apps # the shop alone
74
79
  ```
75
80
 
76
- Each app runs as its own small server on this machine only (Stripe on port 4600, CJ Dropshipping on 4700, Shippo on 4900) and keeps
81
+ Each app runs as its own small server on this machine only (Stripe on port 4600, CJ Dropshipping on 4700, Shippo on 4900, Reviews on 5100) and keeps
77
82
  its data in `<shop folder>/apps/`. The admin finds them by itself; install them from the admin like any app and enter
78
83
  your keys there. Stripe cannot reach a `localhost` address, so card payments need a public address for the app or
79
84
  `stripe listen`: see the Stripe app's settings page.
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.16.1", engines: { node: ">=22.22.0" } };
43
+ define_PKG_default = { version: "0.17.0", engines: { node: ">=22.22.0" } };
44
44
  }
45
45
  });
46
46
 
@@ -692,7 +692,9 @@ var options = {
692
692
  port: { type: "string" },
693
693
  "storefront-port": { type: "string" },
694
694
  app: { type: "string" },
695
+ from: { type: "string" },
695
696
  with: { type: "string", multiple: true },
697
+ "no-apps": { type: "boolean" },
696
698
  verbose: { type: "boolean" },
697
699
  "no-open": { type: "boolean" },
698
700
  "dry-run": { type: "boolean" },
@@ -721,12 +723,19 @@ Run create-shopnex --help for the options.`);
721
723
  const port = toPort("port", values.port, DEFAULT_PORT);
722
724
  const storefrontPort = toPort("storefront-port", values["storefront-port"], DEFAULT_STOREFRONT_PORT);
723
725
  if (port === storefrontPort) throw new UsageError("--port and --storefront-port must be different");
726
+ if (values["no-apps"] && values.with?.length) throw new UsageError("--no-apps and --with cannot be used together");
727
+ const from = values.from?.trim();
728
+ if (values.from !== void 0 && !from)
729
+ throw new UsageError("--from needs a store address, e.g. --from my-store.myshopify.com");
730
+ if (from && from.length > 300) throw new UsageError("--from is too long: give the store address, not a page");
724
731
  return {
725
732
  name: positionals[0],
726
733
  port,
727
734
  storefrontPort,
728
735
  app: values.app,
736
+ from,
729
737
  with: values.with ?? [],
738
+ noApps: Boolean(values["no-apps"]),
730
739
  verbose: Boolean(values.verbose),
731
740
  open: !values["no-open"],
732
741
  dryRun: Boolean(values["dry-run"]),
@@ -807,7 +816,8 @@ function planFromBundle(input) {
807
816
  APP_DATABASE_URL: databaseUrl.startsWith("pglite:") ? `pglite:${join(shopDir, "apps", extra.dir, ".pglite")}` : databaseUrl
808
817
  }
809
818
  },
810
- readyUrl: `http://127.0.0.1:${extra.port}/shopnex/app.js`
819
+ readyUrl: `http://127.0.0.1:${extra.port}/shopnex/app.js`,
820
+ optional: true
811
821
  }))
812
822
  ]
813
823
  };
@@ -890,6 +900,11 @@ var extras = [
890
900
  database: true
891
901
  }
892
902
  ];
903
+ function selectExtras(options2, list = extras) {
904
+ if (options2.noApps) return [];
905
+ const picked = pickExtras(options2.with, list);
906
+ return picked.length ? picked : list;
907
+ }
893
908
  function pickExtras(values, list = extras) {
894
909
  const names = (values ?? []).flatMap((value) => value.split(",")).map((name) => name.trim().toLowerCase());
895
910
  const picked = [];
@@ -1194,6 +1209,9 @@ async function isUp(url) {
1194
1209
  return false;
1195
1210
  }
1196
1211
  }
1212
+ function adminEntry(appUrl, from) {
1213
+ return from ? `${appUrl}/admin/signup?import=${encodeURIComponent(from)}` : `${appUrl}/admin`;
1214
+ }
1197
1215
  function openBrowser(url) {
1198
1216
  const [command, args] = process.platform === "darwin" ? ["open", [url]] : process.platform === "win32" ? ["cmd", ["/c", "start", "", url]] : ["xdg-open", [url]];
1199
1217
  const child = spawn(command, args, { stdio: "ignore", detached: true });
@@ -1201,12 +1219,13 @@ function openBrowser(url) {
1201
1219
  });
1202
1220
  child.unref();
1203
1221
  }
1204
- function runPlan(plan, { open, verbose }) {
1222
+ function runPlan(plan, { open, verbose, from }) {
1205
1223
  return new Promise((resolve3) => {
1206
1224
  const children = [];
1207
1225
  const tails = /* @__PURE__ */ new Map();
1208
1226
  let stopping = false;
1209
1227
  let ready = false;
1228
+ const failed = /* @__PURE__ */ new Set();
1210
1229
  const spinner = de();
1211
1230
  const animate = Boolean(process.stdout.isTTY) && !verbose;
1212
1231
  if (animate) spinner.start("Starting ShopNex (the first start takes a minute)");
@@ -1248,11 +1267,19 @@ function runPlan(plan, { open, verbose }) {
1248
1267
  });
1249
1268
  }
1250
1269
  child.on("error", (error) => {
1270
+ if (stopping) return;
1251
1271
  console.error(`Could not start ${proc.name}: ${error.message}`);
1272
+ if (proc.optional) return void failed.add(proc.name);
1252
1273
  stop(1);
1253
1274
  });
1254
1275
  child.on("exit", (code, signal) => {
1255
1276
  if (stopping) return;
1277
+ if (proc.optional) {
1278
+ failed.add(proc.name);
1279
+ console.error(`${proc.name} stopped (${signal ?? `exit ${code}`}); the shop keeps running without it.`);
1280
+ if (!verbose) for (const line of tails.get(proc.name) ?? []) console.error(import_picocolors3.default.dim(` ${line}`));
1281
+ return;
1282
+ }
1256
1283
  if (animate && !ready) spinner.stop(`${proc.name} stopped`, 1);
1257
1284
  console.error(`${proc.name} stopped (${signal ?? `exit ${code}`}).`);
1258
1285
  if (!verbose) for (const line of tails.get(proc.name) ?? []) console.error(import_picocolors3.default.dim(` ${line}`));
@@ -1263,21 +1290,27 @@ function runPlan(plan, { open, verbose }) {
1263
1290
  process.on("SIGTERM", () => stop(0));
1264
1291
  void (async () => {
1265
1292
  for (let i = 0; i < 180 && !stopping; i++) {
1266
- if ((await Promise.all(plan.processes.map((proc) => isUp(proc.readyUrl)))).every(Boolean)) break;
1293
+ const up = await Promise.all(
1294
+ plan.processes.map(async (proc) => proc.optional && failed.has(proc.name) || await isUp(proc.readyUrl))
1295
+ );
1296
+ if (up.every(Boolean)) break;
1267
1297
  await sleep(1e3);
1268
1298
  }
1269
1299
  if (stopping) return;
1270
1300
  ready = true;
1271
1301
  if (animate) spinner.stop("ShopNex is running");
1302
+ if (failed.size) f2.warn(`Not running: ${[...failed].join(", ")} (see above). The rest of the shop is up.`);
1272
1303
  le(
1273
1304
  [
1274
1305
  `${import_picocolors3.default.bold("Shop ")} ${brand(plan.storefrontUrl)}`,
1275
- `${import_picocolors3.default.bold("Admin")} ${brand(`${plan.appUrl}/admin`)} (the first run opens the setup wizard)`
1306
+ `${import_picocolors3.default.bold("Admin")} ${brand(`${plan.appUrl}/admin`)} (the first run opens the setup wizard)`,
1307
+ ...from ? [`${import_picocolors3.default.bold("Import")} ${from} (starts once you have created the owner)`] : []
1276
1308
  ].join("\n"),
1277
1309
  "Open"
1278
1310
  );
1311
+ f2.message(`${import_picocolors3.default.dim("Like it? Star us on GitHub:")} ${brand("https://github.com/shopnex-ai/shopnex")}`);
1279
1312
  $e("Create the owner account right away. Ctrl+C stops everything.");
1280
- if (open) openBrowser(`${plan.appUrl}/admin`);
1313
+ if (open) openBrowser(adminEntry(plan.appUrl, from));
1281
1314
  })();
1282
1315
  });
1283
1316
  }
@@ -1298,7 +1331,9 @@ Options
1298
1331
  --port <n> admin, API and checkout (default 3000)
1299
1332
  --storefront-port <n> storefront (default 4321)
1300
1333
  --no-open do not open the browser
1301
- --with <apps> also start optional apps: stripe, cj, shippo (comma separated, or repeat the flag)
1334
+ --with <apps> start only these apps: stripe, cj, shippo, reviews (comma separated, or repeat the flag)
1335
+ --no-apps start the shop alone, without the bundled apps (all four start by default)
1336
+ --from <store> bring a Shopify or WooCommerce store across (products, pages, look): its address, e.g. my-store.myshopify.com
1302
1337
  --app <name> what to start (default shop; a picker appears once there is more than one)
1303
1338
  --verbose show the output of the servers while they start
1304
1339
  --dry-run show what would run and exit
@@ -1310,7 +1345,8 @@ function describe({
1310
1345
  database,
1311
1346
  plan,
1312
1347
  source,
1313
- extras: extras2 = []
1348
+ extras: extras2 = [],
1349
+ from
1314
1350
  }) {
1315
1351
  const rows = [
1316
1352
  ["Source", source],
@@ -1318,6 +1354,7 @@ function describe({
1318
1354
  ["Database", redactUrl(database)],
1319
1355
  ["Admin", `${plan.appUrl}/admin`],
1320
1356
  ["Storefront", plan.storefrontUrl],
1357
+ ...from ? [["Import", `${from} (starts after you create the owner)`]] : [],
1321
1358
  ...extras2.map((extra) => [extra.label, `http://localhost:${extra.port} (install it from the admin)`])
1322
1359
  ];
1323
1360
  const width = Math.max(...rows.map(([label]) => label?.length ?? 0)) + 2;
@@ -1333,16 +1370,28 @@ async function run(argv) {
1333
1370
  const interactive = Boolean(process.stdin.isTTY && process.stdout.isTTY);
1334
1371
  const name = options2.name ?? DEFAULT_SHOP_NAME;
1335
1372
  const shopDir = resolveShopDir(name);
1336
- const extras2 = pickExtras(options2.with);
1373
+ let extras2 = selectExtras(options2);
1337
1374
  const shopEnv = loadShopEnv(shopDir, { write: !options2.dryRun });
1338
1375
  const scaffoldWarning = options2.dryRun ? void 0 : await writeScaffold(shopDir, pkg.version);
1339
1376
  if (scaffoldWarning) f2.warn(scaffoldWarning);
1340
1377
  const ports = [
1341
1378
  { port: options2.port, flag: "--port" },
1342
- { port: options2.storefrontPort, flag: "--storefront-port" },
1343
- ...extras2.map((extra) => ({ port: extra.port, flag: `--with (${extra.name} needs it free)` }))
1379
+ { port: options2.storefrontPort, flag: "--storefront-port" }
1344
1380
  ];
1345
- if (!options2.dryRun) await assertPortsFree(ports);
1381
+ if (!options2.dryRun) {
1382
+ await assertPortsFree(ports);
1383
+ if (options2.with.length) {
1384
+ await assertPortsFree(extras2.map((extra) => ({ port: extra.port, flag: `--with (${extra.name} needs it free)` })));
1385
+ } else {
1386
+ const busy = /* @__PURE__ */ new Set();
1387
+ for (const extra of extras2) if (await portInUse(extra.port)) busy.add(extra.name);
1388
+ for (const name2 of busy) {
1389
+ const extra = extras2.find((e2) => e2.name === name2);
1390
+ f2.warn(`Port ${extra?.port} is in use, so ${extra?.label} is not started. --no-apps hides this.`);
1391
+ }
1392
+ extras2 = extras2.filter((extra) => !busy.has(extra.name));
1393
+ }
1394
+ }
1346
1395
  const root = options2.dryRun ? bundleDir(pkg.version) : await resolveBundle({ version: pkg.version });
1347
1396
  const source = isEdge(pkg.version) ? "ShopNex edge (the latest build from main, checked on every run)" : `ShopNex ${pkg.version} ${isInstalled(pkg.version) ? "(downloaded)" : "(downloaded on the first run)"}`;
1348
1397
  const app = await pickApp(options2.app, { interactive });
@@ -1357,10 +1406,10 @@ async function run(argv) {
1357
1406
  secret: shopEnv.secret,
1358
1407
  appKeys: loadAppKeys(shopDir, extras2, { write: !options2.dryRun })
1359
1408
  });
1360
- le(describe({ shopDir, database: shopEnv.databaseUrl, plan, source, extras: extras2 }), app.label);
1409
+ le(describe({ shopDir, database: shopEnv.databaseUrl, plan, source, extras: extras2, from: options2.from }), app.label);
1361
1410
  if (options2.dryRun) return $e("Dry run: nothing was started.");
1362
1411
  f2.warn("This is a trial database: it is not for production.");
1363
- process.exitCode = await runPlan(plan, { open: options2.open, verbose: options2.verbose });
1412
+ process.exitCode = await runPlan(plan, { open: options2.open, verbose: options2.verbose, from: options2.from });
1364
1413
  }
1365
1414
  async function main(argv) {
1366
1415
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-shopnex",
3
- "version": "0.16.1",
3
+ "version": "0.17.0",
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",