shopnex 0.0.0-stage → 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 CHANGED
@@ -1,3 +1,87 @@
1
- # Temporary Holding Version
1
+ # shopnex
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Look after a ShopNex shop that you started with [`create-shopnex`](../create-shopnex), and start new apps for it.
4
+
5
+ | Command | What it does |
6
+ | ----------------------------- | --------------------------------------------------------------- |
7
+ | `shopnex migrate-db` | Moves the shop's data from the embedded database to PostgreSQL. |
8
+ | `shopnex generate app <name>` | Makes a new ShopNex app in the folder `<name>`, ready to run. |
9
+
10
+ Options: `--to <url>` and `--to-env <NAME>` (migrate-db), `--dir <folder>` and `--port <n>` (migrate-db), `-h, --help`
11
+ and `-v, --version`. `npx shopnex@latest --help` prints the same list.
12
+
13
+ ## generate app
14
+
15
+ Run it in the shop folder that `create-shopnex` made:
16
+
17
+ ```sh
18
+ cd my-shop
19
+ npx shopnex@latest generate app my-app # makes apps/my-app
20
+ cd apps/my-app
21
+ cp .env.example .env # fill in SHOPNEX_CLIENT_ID and SHOPNEX_APP_KEY from your app's page
22
+ pnpm install && pnpm dev # npm or yarn work too
23
+ ```
24
+
25
+ It writes a small, self-contained project (the shop can be running):
26
+
27
+ - `src/server.tsx`: the whole app. A page inside the admin, an endpoint that saves a note in the shop's app data, and
28
+ an `order.created` webhook.
29
+ - `package.json` (depends on `@shopnex/app` at this CLI's version), `tsconfig.json`, `.env.example`, `.gitignore` and
30
+ a `README.md` with the steps to run and install it.
31
+
32
+ The app goes to `<shop folder>/apps/<name>` when the folder has a `.env` (use `--dir` for another shop folder), and to
33
+ `./<name>` anywhere else. `<name>` is the folder and the package name: lowercase letters, numbers, `-`, `_` and `.`. The
34
+ folder must not exist yet or must be empty; nothing is overwritten.
35
+
36
+ The admin does not find a generated app by itself: it is its own server (port 4500). Register
37
+ `http://localhost:4500` as the App URL and install the app from the admin.
38
+
39
+ ## migrate-db
40
+
41
+ ```sh
42
+ cd my-shop # the folder create-shopnex made (it has the .env)
43
+ # stop the shop (Ctrl+C where it runs), then:
44
+ npx shopnex@latest migrate-db --to postgres://user:password@host:5432/shopnex
45
+ ```
46
+
47
+ The new database must exist and be empty. To keep the password out of your shell history, put the address in an
48
+ environment variable and give its name: `--to-env SHOPNEX_TARGET`.
49
+
50
+ ### What it does
51
+
52
+ 1. Checks that the shop is stopped (nothing answers on the admin's port, 3000; use `--port` if you started it on
53
+ another) and that its database is at the schema of this version.
54
+ 2. Keeps a copy of `.pglite/` next to it (`.pglite.bak-<date>`).
55
+ 3. Runs `admin/migrate-db.mjs` from the packaged build of the same version: it creates the tables in PostgreSQL,
56
+ copies every table in foreign-key order inside **one transaction**, and checks every table's row count before it
57
+ commits.
58
+ 4. Only then changes `DATABASE_URL` in the `.env`. The old line stays above it as a comment, and `.pglite/` stays
59
+ where it is: going back is one edit.
60
+
61
+ If anything fails, PostgreSQL is left as empty as it was found, the `.env` is not touched, and the extra copy is
62
+ removed. The old data is only ever read.
63
+
64
+ ### What it does not do
65
+
66
+ - **The optional apps' data** (`apps/<name>/.pglite`: Stripe, CJ Dropshipping, Shippo) is not moved. They start empty
67
+ on PostgreSQL, and the command names the ones that had data.
68
+ - It never merges into a database that already has tables.
69
+ - It does not move data back, or between two PostgreSQL servers (use `pg_dump` for that).
70
+
71
+ ### The version rule
72
+
73
+ Like `create-shopnex`, this CLI runs the packaged build of **its own version** (downloaded once into
74
+ `~/.shopnex/app/<version>`, shared with `create-shopnex`). A shop last started by an older version must be started once
75
+ with this one first: it updates the database at start, and `migrate-db` refuses to copy until then. A database from a
76
+ newer version is refused too.
77
+
78
+ ## Development
79
+
80
+ ```sh
81
+ pnpm --filter shopnex dev migrate-db --help # runs src/main.ts
82
+ pnpm --filter shopnex test # the command, against a stub in place of the build's script
83
+ pnpm --filter @shopnex/db test # the copier itself (modules/db/src/move-data.ts) on two PGlite databases
84
+ ```
85
+
86
+ The code that is not about this command (downloading and unpacking the build, the `.env`, ports) is
87
+ [`@shopnex/cli-core`](../cli-core), shared with `create-shopnex`.
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env node
2
+ // The compiled CLI (pnpm --filter shopnex build; it is built before the package is packed). From a checkout,
3
+ // `pnpm --filter shopnex dev -- <options>` runs the TypeScript directly.
4
+ try {
5
+ await import('../dist/main.mjs')
6
+ } catch (error) {
7
+ if (error?.code !== 'ERR_MODULE_NOT_FOUND' || !String(error.message).includes('dist/main.mjs')) throw error
8
+ console.error('shopnex is not built. Run: pnpm --filter shopnex build')
9
+ process.exitCode = 1
10
+ }
package/dist/main.mjs ADDED
@@ -0,0 +1,1025 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __esm = (fn, res, err) => function __init() {
8
+ if (err) throw err[0];
9
+ try {
10
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
11
+ } catch (e2) {
12
+ throw err = [e2], e2;
13
+ }
14
+ };
15
+ var __commonJS = (cb, mod) => function __require() {
16
+ try {
17
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
18
+ } catch (e2) {
19
+ throw mod = 0, e2;
20
+ }
21
+ };
22
+ var __copyProps = (to, from, except, desc) => {
23
+ if (from && typeof from === "object" || typeof from === "function") {
24
+ for (let key of __getOwnPropNames(from))
25
+ if (!__hasOwnProp.call(to, key) && key !== except)
26
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
27
+ }
28
+ return to;
29
+ };
30
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
31
+ // If the importer is in node compatibility mode or this is not an ESM
32
+ // file that has been converted to a CommonJS file using a Babel-
33
+ // compatible transform (i.e. "__esModule" has not been set), then set
34
+ // "default" to the CommonJS "module.exports" for node compatibility.
35
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
36
+ mod
37
+ ));
38
+
39
+ // <define:__APP_STARTER__>
40
+ var define_APP_STARTER_default;
41
+ var init_define_APP_STARTER = __esm({
42
+ "<define:__APP_STARTER__>"() {
43
+ define_APP_STARTER_default = { "src/server.tsx": `// ShopNex app starter: an embedded app with no database and no OAuth code (@shopnex/app does both).
44
+ //
45
+ // GET / The app's page inside the ShopNex admin
46
+ // POST /api/notes Saves a note in the shop's app data (called by the page's form)
47
+ // POST /webhooks order.created deliveries, checked against the shop's published keys
48
+ import { serve } from '@hono/node-server'
49
+ import { Hono } from 'hono'
50
+ import { HTTPException } from 'hono/http-exception'
51
+ import { createShopnexApp, type ShopContext } from '@shopnex/app'
52
+ import { Button, Card, Form, Inline, Page, Stat, Text, TextField } from '@shopnex/app/ui'
53
+
54
+ const APP_URL = (process.env.APP_URL ?? 'http://localhost:4500').replace(/\\/$/, '')
55
+ // Listens on the URL's port unless the platform sets PORT (behind a proxy the public URL has none)
56
+ const PORT = Number(process.env.PORT || new URL(APP_URL).port || 4500)
57
+ const shopnex = createShopnexApp()
58
+
59
+ const app = new Hono()
60
+ app.route('/', shopnex.routes)
61
+
62
+ async function stats(shop: ShopContext) {
63
+ const [products, orders] = await Promise.all([
64
+ shop.admin.get<{ total: number }>('/products?limit=1'),
65
+ shop.admin.get<{ total: number }>('/orders?limit=1'),
66
+ ])
67
+ return { products: products.total, orders: orders.total }
68
+ }
69
+
70
+ app.get('/', async (c) => {
71
+ const { shop, ...ctx } = await shopnex.authenticate(c)
72
+ const [s, note] = await Promise.all([stats(ctx), ctx.data.get<string>('note'), subscribe(ctx)])
73
+ return c.html(
74
+ <Page
75
+ title="App starter"
76
+ subtitle={\`Connected to \${shop.name}\`}
77
+ actions={
78
+ <Button action="/api/ping" reload variant="secondary">
79
+ Refresh
80
+ </Button>
81
+ }
82
+ >
83
+ <Card title="Your shop">
84
+ <Inline gap={8}>
85
+ <Stat label="Products" value={s.products} />
86
+ <Stat label="Orders" value={s.orders} />
87
+ </Inline>
88
+ <Text tone="subdued">New orders are logged by this app's server (order.created webhook).</Text>
89
+ </Card>
90
+ <Card title="Note" description="Kept in the shop's ShopNex (app data): this app stores nothing itself.">
91
+ <Form action="/api/notes" success="Saved">
92
+ <TextField label="Note" name="note" value={note} multiline />
93
+ <div>
94
+ <Button>Save</Button>
95
+ </div>
96
+ </Form>
97
+ </Card>
98
+ </Page>,
99
+ )
100
+ })
101
+
102
+ app.post('/api/ping', async (c) => {
103
+ await shopnex.authenticate(c)
104
+ return c.json({ message: 'Refreshed' })
105
+ })
106
+
107
+ app.post('/api/notes', async (c) => {
108
+ const { data } = await shopnex.authenticate(c)
109
+ const { note } = await c.req.json<{ note?: string }>()
110
+ await data.set('note', note ?? '')
111
+ return c.json({ ok: true })
112
+ })
113
+
114
+ // Subscribe once per shop (the subscription belongs to the app's installation)
115
+ async function subscribe(shop: ShopContext) {
116
+ const url = \`\${APP_URL}/webhooks\`
117
+ const hooks = await shop.admin.get<{ url: string }[]>('/webhooks')
118
+ if (!hooks.some((h) => h.url === url)) await shop.admin.post('/webhooks', { url, topics: ['order.created'] })
119
+ }
120
+
121
+ app.post('/webhooks', async (c) => {
122
+ const { event, shop } = await shopnex.verifyWebhook<{ orderNumber?: number }>(c)
123
+ console.log(\`[webhook] \${shop.instance} shop \${shop.shopId}: \${event.type}\`, event.data.orderNumber ?? '')
124
+ return c.body(null, 204)
125
+ })
126
+
127
+ app.onError((error, c) => {
128
+ if (error instanceof HTTPException) return error.getResponse()
129
+ console.error(error)
130
+ return c.json({ error: error.message }, 500)
131
+ })
132
+
133
+ serve({ fetch: app.fetch, port: PORT }, () => console.log(\`App starter on \${APP_URL}\`))
134
+ `, ".env.example": "# From your app's page in the marketplace developer dashboard (or Admin \u2192 Apps \u2192 Custom apps). Leave the app's\n# Redirect URLs empty: it's a managed app, installed and opened right in the ShopNex admin.\nSHOPNEX_CLIENT_ID=app_\u2026\nSHOPNEX_APP_KEY=snxk_\u2026\n# Marketplace apps: only serve installs the marketplace knows about (anyone can run a ShopNex instance)\nSHOPNEX_MARKETPLACE_URL=http://localhost:3200\n# Where this app runs: register it as the App URL. It listens on this URL's port; set PORT only when the\n# platform assigns one (behind a proxy the public URL has no port)\nAPP_URL=http://localhost:4500\n", ".gitignore": ".env\n" };
135
+ }
136
+ });
137
+
138
+ // <define:__PKG__>
139
+ var define_PKG_default;
140
+ var init_define_PKG = __esm({
141
+ "<define:__PKG__>"() {
142
+ define_PKG_default = { version: "0.16.1", engines: { node: ">=22.22.0" } };
143
+ }
144
+ });
145
+
146
+ // ../../node_modules/.pnpm/sisteransi@1.0.5/node_modules/sisteransi/src/index.js
147
+ var require_src = __commonJS({
148
+ "../../node_modules/.pnpm/sisteransi@1.0.5/node_modules/sisteransi/src/index.js"(exports, module) {
149
+ "use strict";
150
+ init_define_APP_STARTER();
151
+ init_define_PKG();
152
+ var ESC = "\x1B";
153
+ var CSI = `${ESC}[`;
154
+ var beep = "\x07";
155
+ var cursor = {
156
+ to(x2, y) {
157
+ if (!y) return `${CSI}${x2 + 1}G`;
158
+ return `${CSI}${y + 1};${x2 + 1}H`;
159
+ },
160
+ move(x2, y) {
161
+ let ret = "";
162
+ if (x2 < 0) ret += `${CSI}${-x2}D`;
163
+ else if (x2 > 0) ret += `${CSI}${x2}C`;
164
+ if (y < 0) ret += `${CSI}${-y}A`;
165
+ else if (y > 0) ret += `${CSI}${y}B`;
166
+ return ret;
167
+ },
168
+ up: (count = 1) => `${CSI}${count}A`,
169
+ down: (count = 1) => `${CSI}${count}B`,
170
+ forward: (count = 1) => `${CSI}${count}C`,
171
+ backward: (count = 1) => `${CSI}${count}D`,
172
+ nextLine: (count = 1) => `${CSI}E`.repeat(count),
173
+ prevLine: (count = 1) => `${CSI}F`.repeat(count),
174
+ left: `${CSI}G`,
175
+ hide: `${CSI}?25l`,
176
+ show: `${CSI}?25h`,
177
+ save: `${ESC}7`,
178
+ restore: `${ESC}8`
179
+ };
180
+ var scroll = {
181
+ up: (count = 1) => `${CSI}S`.repeat(count),
182
+ down: (count = 1) => `${CSI}T`.repeat(count)
183
+ };
184
+ var erase = {
185
+ screen: `${CSI}2J`,
186
+ up: (count = 1) => `${CSI}1J`.repeat(count),
187
+ down: (count = 1) => `${CSI}J`.repeat(count),
188
+ line: `${CSI}2K`,
189
+ lineEnd: `${CSI}K`,
190
+ lineStart: `${CSI}1K`,
191
+ lines(count) {
192
+ let clear = "";
193
+ for (let i = 0; i < count; i++)
194
+ clear += this.line + (i < count - 1 ? cursor.up() : "");
195
+ if (count)
196
+ clear += cursor.left;
197
+ return clear;
198
+ }
199
+ };
200
+ module.exports = { cursor, scroll, erase, beep };
201
+ }
202
+ });
203
+
204
+ // ../../node_modules/.pnpm/picocolors@1.1.1/node_modules/picocolors/picocolors.js
205
+ var require_picocolors = __commonJS({
206
+ "../../node_modules/.pnpm/picocolors@1.1.1/node_modules/picocolors/picocolors.js"(exports, module) {
207
+ init_define_APP_STARTER();
208
+ init_define_PKG();
209
+ var p = process || {};
210
+ var argv = p.argv || [];
211
+ var env = p.env || {};
212
+ var isColorSupported = !(!!env.NO_COLOR || argv.includes("--no-color")) && (!!env.FORCE_COLOR || argv.includes("--color") || p.platform === "win32" || (p.stdout || {}).isTTY && env.TERM !== "dumb" || !!env.CI);
213
+ var formatter = (open, close, replace = open) => (input) => {
214
+ let string = "" + input, index = string.indexOf(close, open.length);
215
+ return ~index ? open + replaceClose(string, close, replace, index) + close : open + string + close;
216
+ };
217
+ var replaceClose = (string, close, replace, index) => {
218
+ let result = "", cursor = 0;
219
+ do {
220
+ result += string.substring(cursor, index) + replace;
221
+ cursor = index + close.length;
222
+ index = string.indexOf(close, cursor);
223
+ } while (~index);
224
+ return result + string.substring(cursor);
225
+ };
226
+ var createColors = (enabled = isColorSupported) => {
227
+ let f3 = enabled ? formatter : () => String;
228
+ return {
229
+ isColorSupported: enabled,
230
+ reset: f3("\x1B[0m", "\x1B[0m"),
231
+ bold: f3("\x1B[1m", "\x1B[22m", "\x1B[22m\x1B[1m"),
232
+ dim: f3("\x1B[2m", "\x1B[22m", "\x1B[22m\x1B[2m"),
233
+ italic: f3("\x1B[3m", "\x1B[23m"),
234
+ underline: f3("\x1B[4m", "\x1B[24m"),
235
+ inverse: f3("\x1B[7m", "\x1B[27m"),
236
+ hidden: f3("\x1B[8m", "\x1B[28m"),
237
+ strikethrough: f3("\x1B[9m", "\x1B[29m"),
238
+ black: f3("\x1B[30m", "\x1B[39m"),
239
+ red: f3("\x1B[31m", "\x1B[39m"),
240
+ green: f3("\x1B[32m", "\x1B[39m"),
241
+ yellow: f3("\x1B[33m", "\x1B[39m"),
242
+ blue: f3("\x1B[34m", "\x1B[39m"),
243
+ magenta: f3("\x1B[35m", "\x1B[39m"),
244
+ cyan: f3("\x1B[36m", "\x1B[39m"),
245
+ white: f3("\x1B[37m", "\x1B[39m"),
246
+ gray: f3("\x1B[90m", "\x1B[39m"),
247
+ bgBlack: f3("\x1B[40m", "\x1B[49m"),
248
+ bgRed: f3("\x1B[41m", "\x1B[49m"),
249
+ bgGreen: f3("\x1B[42m", "\x1B[49m"),
250
+ bgYellow: f3("\x1B[43m", "\x1B[49m"),
251
+ bgBlue: f3("\x1B[44m", "\x1B[49m"),
252
+ bgMagenta: f3("\x1B[45m", "\x1B[49m"),
253
+ bgCyan: f3("\x1B[46m", "\x1B[49m"),
254
+ bgWhite: f3("\x1B[47m", "\x1B[49m"),
255
+ blackBright: f3("\x1B[90m", "\x1B[39m"),
256
+ redBright: f3("\x1B[91m", "\x1B[39m"),
257
+ greenBright: f3("\x1B[92m", "\x1B[39m"),
258
+ yellowBright: f3("\x1B[93m", "\x1B[39m"),
259
+ blueBright: f3("\x1B[94m", "\x1B[39m"),
260
+ magentaBright: f3("\x1B[95m", "\x1B[39m"),
261
+ cyanBright: f3("\x1B[96m", "\x1B[39m"),
262
+ whiteBright: f3("\x1B[97m", "\x1B[39m"),
263
+ bgBlackBright: f3("\x1B[100m", "\x1B[49m"),
264
+ bgRedBright: f3("\x1B[101m", "\x1B[49m"),
265
+ bgGreenBright: f3("\x1B[102m", "\x1B[49m"),
266
+ bgYellowBright: f3("\x1B[103m", "\x1B[49m"),
267
+ bgBlueBright: f3("\x1B[104m", "\x1B[49m"),
268
+ bgMagentaBright: f3("\x1B[105m", "\x1B[49m"),
269
+ bgCyanBright: f3("\x1B[106m", "\x1B[49m"),
270
+ bgWhiteBright: f3("\x1B[107m", "\x1B[49m")
271
+ };
272
+ };
273
+ module.exports = createColors();
274
+ module.exports.createColors = createColors;
275
+ }
276
+ });
277
+
278
+ // src/main.ts
279
+ init_define_APP_STARTER();
280
+ init_define_PKG();
281
+
282
+ // src/cli.ts
283
+ init_define_APP_STARTER();
284
+ init_define_PKG();
285
+ import { readFileSync as readFileSync4 } from "node:fs";
286
+ import { relative, resolve as resolve5 } from "node:path";
287
+
288
+ // ../../node_modules/.pnpm/@clack+prompts@0.7.0/node_modules/@clack/prompts/dist/index.mjs
289
+ init_define_APP_STARTER();
290
+ init_define_PKG();
291
+
292
+ // ../../node_modules/.pnpm/@clack+core@0.3.5/node_modules/@clack/core/dist/index.mjs
293
+ init_define_APP_STARTER();
294
+ init_define_PKG();
295
+ var import_sisteransi = __toESM(require_src(), 1);
296
+ import { stdin as $, stdout as k } from "node:process";
297
+ import * as f from "node:readline";
298
+ function q({ onlyFirst: e2 = false } = {}) {
299
+ const F = ["[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?(?:\\u0007|\\u001B\\u005C|\\u009C))", "(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]))"].join("|");
300
+ return new RegExp(F, e2 ? void 0 : "g");
301
+ }
302
+ var J = q();
303
+ function T(e2) {
304
+ return e2 && e2.__esModule && Object.prototype.hasOwnProperty.call(e2, "default") ? e2.default : e2;
305
+ }
306
+ var j = { exports: {} };
307
+ (function(e2) {
308
+ var u = {};
309
+ e2.exports = u, u.eastAsianWidth = function(t) {
310
+ var s = t.charCodeAt(0), C2 = t.length == 2 ? t.charCodeAt(1) : 0, D = s;
311
+ return 55296 <= s && s <= 56319 && 56320 <= C2 && C2 <= 57343 && (s &= 1023, C2 &= 1023, D = s << 10 | C2, D += 65536), D == 12288 || 65281 <= D && D <= 65376 || 65504 <= D && D <= 65510 ? "F" : D == 8361 || 65377 <= D && D <= 65470 || 65474 <= D && D <= 65479 || 65482 <= D && D <= 65487 || 65490 <= D && D <= 65495 || 65498 <= D && D <= 65500 || 65512 <= D && D <= 65518 ? "H" : 4352 <= D && D <= 4447 || 4515 <= D && D <= 4519 || 4602 <= D && D <= 4607 || 9001 <= D && D <= 9002 || 11904 <= D && D <= 11929 || 11931 <= D && D <= 12019 || 12032 <= D && D <= 12245 || 12272 <= D && D <= 12283 || 12289 <= D && D <= 12350 || 12353 <= D && D <= 12438 || 12441 <= D && D <= 12543 || 12549 <= D && D <= 12589 || 12593 <= D && D <= 12686 || 12688 <= D && D <= 12730 || 12736 <= D && D <= 12771 || 12784 <= D && D <= 12830 || 12832 <= D && D <= 12871 || 12880 <= D && D <= 13054 || 13056 <= D && D <= 19903 || 19968 <= D && D <= 42124 || 42128 <= D && D <= 42182 || 43360 <= D && D <= 43388 || 44032 <= D && D <= 55203 || 55216 <= D && D <= 55238 || 55243 <= D && D <= 55291 || 63744 <= D && D <= 64255 || 65040 <= D && D <= 65049 || 65072 <= D && D <= 65106 || 65108 <= D && D <= 65126 || 65128 <= D && D <= 65131 || 110592 <= D && D <= 110593 || 127488 <= D && D <= 127490 || 127504 <= D && D <= 127546 || 127552 <= D && D <= 127560 || 127568 <= D && D <= 127569 || 131072 <= D && D <= 194367 || 177984 <= D && D <= 196605 || 196608 <= D && D <= 262141 ? "W" : 32 <= D && D <= 126 || 162 <= D && D <= 163 || 165 <= D && D <= 166 || D == 172 || D == 175 || 10214 <= D && D <= 10221 || 10629 <= D && D <= 10630 ? "Na" : D == 161 || D == 164 || 167 <= D && D <= 168 || D == 170 || 173 <= D && D <= 174 || 176 <= D && D <= 180 || 182 <= D && D <= 186 || 188 <= D && D <= 191 || D == 198 || D == 208 || 215 <= D && D <= 216 || 222 <= D && D <= 225 || D == 230 || 232 <= D && D <= 234 || 236 <= D && D <= 237 || D == 240 || 242 <= D && D <= 243 || 247 <= D && D <= 250 || D == 252 || D == 254 || D == 257 || D == 273 || D == 275 || D == 283 || 294 <= D && D <= 295 || D == 299 || 305 <= D && D <= 307 || D == 312 || 319 <= D && D <= 322 || D == 324 || 328 <= D && D <= 331 || D == 333 || 338 <= D && D <= 339 || 358 <= D && D <= 359 || D == 363 || D == 462 || D == 464 || D == 466 || D == 468 || D == 470 || D == 472 || D == 474 || D == 476 || D == 593 || D == 609 || D == 708 || D == 711 || 713 <= D && D <= 715 || D == 717 || D == 720 || 728 <= D && D <= 731 || D == 733 || D == 735 || 768 <= D && D <= 879 || 913 <= D && D <= 929 || 931 <= D && D <= 937 || 945 <= D && D <= 961 || 963 <= D && D <= 969 || D == 1025 || 1040 <= D && D <= 1103 || D == 1105 || D == 8208 || 8211 <= D && D <= 8214 || 8216 <= D && D <= 8217 || 8220 <= D && D <= 8221 || 8224 <= D && D <= 8226 || 8228 <= D && D <= 8231 || D == 8240 || 8242 <= D && D <= 8243 || D == 8245 || D == 8251 || D == 8254 || D == 8308 || D == 8319 || 8321 <= D && D <= 8324 || D == 8364 || D == 8451 || D == 8453 || D == 8457 || D == 8467 || D == 8470 || 8481 <= D && D <= 8482 || D == 8486 || D == 8491 || 8531 <= D && D <= 8532 || 8539 <= D && D <= 8542 || 8544 <= D && D <= 8555 || 8560 <= D && D <= 8569 || D == 8585 || 8592 <= D && D <= 8601 || 8632 <= D && D <= 8633 || D == 8658 || D == 8660 || D == 8679 || D == 8704 || 8706 <= D && D <= 8707 || 8711 <= D && D <= 8712 || D == 8715 || D == 8719 || D == 8721 || D == 8725 || D == 8730 || 8733 <= D && D <= 8736 || D == 8739 || D == 8741 || 8743 <= D && D <= 8748 || D == 8750 || 8756 <= D && D <= 8759 || 8764 <= D && D <= 8765 || D == 8776 || D == 8780 || D == 8786 || 8800 <= D && D <= 8801 || 8804 <= D && D <= 8807 || 8810 <= D && D <= 8811 || 8814 <= D && D <= 8815 || 8834 <= D && D <= 8835 || 8838 <= D && D <= 8839 || D == 8853 || D == 8857 || D == 8869 || D == 8895 || D == 8978 || 9312 <= D && D <= 9449 || 9451 <= D && D <= 9547 || 9552 <= D && D <= 9587 || 9600 <= D && D <= 9615 || 9618 <= D && D <= 9621 || 9632 <= D && D <= 9633 || 9635 <= D && D <= 9641 || 9650 <= D && D <= 9651 || 9654 <= D && D <= 9655 || 9660 <= D && D <= 9661 || 9664 <= D && D <= 9665 || 9670 <= D && D <= 9672 || D == 9675 || 9678 <= D && D <= 9681 || 9698 <= D && D <= 9701 || D == 9711 || 9733 <= D && D <= 9734 || D == 9737 || 9742 <= D && D <= 9743 || 9748 <= D && D <= 9749 || D == 9756 || D == 9758 || D == 9792 || D == 9794 || 9824 <= D && D <= 9825 || 9827 <= D && D <= 9829 || 9831 <= D && D <= 9834 || 9836 <= D && D <= 9837 || D == 9839 || 9886 <= D && D <= 9887 || 9918 <= D && D <= 9919 || 9924 <= D && D <= 9933 || 9935 <= D && D <= 9953 || D == 9955 || 9960 <= D && D <= 9983 || D == 10045 || D == 10071 || 10102 <= D && D <= 10111 || 11093 <= D && D <= 11097 || 12872 <= D && D <= 12879 || 57344 <= D && D <= 63743 || 65024 <= D && D <= 65039 || D == 65533 || 127232 <= D && D <= 127242 || 127248 <= D && D <= 127277 || 127280 <= D && D <= 127337 || 127344 <= D && D <= 127386 || 917760 <= D && D <= 917999 || 983040 <= D && D <= 1048573 || 1048576 <= D && D <= 1114109 ? "A" : "N";
312
+ }, u.characterLength = function(t) {
313
+ var s = this.eastAsianWidth(t);
314
+ return s == "F" || s == "W" || s == "A" ? 2 : 1;
315
+ };
316
+ function F(t) {
317
+ return t.match(/[\uD800-\uDBFF][\uDC00-\uDFFF]|[^\uD800-\uDFFF]/g) || [];
318
+ }
319
+ u.length = function(t) {
320
+ for (var s = F(t), C2 = 0, D = 0; D < s.length; D++) C2 = C2 + this.characterLength(s[D]);
321
+ return C2;
322
+ }, u.slice = function(t, s, C2) {
323
+ textLen = u.length(t), s = s || 0, C2 = C2 || 1, s < 0 && (s = textLen + s), C2 < 0 && (C2 = textLen + C2);
324
+ for (var D = "", i = 0, n = F(t), E2 = 0; E2 < n.length; E2++) {
325
+ var h2 = n[E2], o2 = u.length(h2);
326
+ if (i >= s - (o2 == 2 ? 1 : 0)) if (i + o2 <= C2) D += h2;
327
+ else break;
328
+ i += o2;
329
+ }
330
+ return D;
331
+ };
332
+ })(j);
333
+ var Q = j.exports;
334
+ var X = T(Q);
335
+ var DD = function() {
336
+ return /\uD83C\uDFF4\uDB40\uDC67\uDB40\uDC62(?:\uDB40\uDC77\uDB40\uDC6C\uDB40\uDC73|\uDB40\uDC73\uDB40\uDC63\uDB40\uDC74|\uDB40\uDC65\uDB40\uDC6E\uDB40\uDC67)\uDB40\uDC7F|(?:\uD83E\uDDD1\uD83C\uDFFF\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFF\u200D\uD83E\uDD1D\u200D(?:\uD83D[\uDC68\uDC69]))(?:\uD83C[\uDFFB-\uDFFE])|(?:\uD83E\uDDD1\uD83C\uDFFE\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFE\u200D\uD83E\uDD1D\u200D(?:\uD83D[\uDC68\uDC69]))(?:\uD83C[\uDFFB-\uDFFD\uDFFF])|(?:\uD83E\uDDD1\uD83C\uDFFD\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFD\u200D\uD83E\uDD1D\u200D(?:\uD83D[\uDC68\uDC69]))(?:\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF])|(?:\uD83E\uDDD1\uD83C\uDFFC\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFC\u200D\uD83E\uDD1D\u200D(?:\uD83D[\uDC68\uDC69]))(?:\uD83C[\uDFFB\uDFFD-\uDFFF])|(?:\uD83E\uDDD1\uD83C\uDFFB\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFB\u200D\uD83E\uDD1D\u200D(?:\uD83D[\uDC68\uDC69]))(?:\uD83C[\uDFFC-\uDFFF])|\uD83D\uDC68(?:\uD83C\uDFFB(?:\u200D(?:\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFF])|\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFF]))|\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFC-\uDFFF])|[\u2695\u2696\u2708]\uFE0F|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD]))?|(?:\uD83C[\uDFFC-\uDFFF])\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFF])|\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFF]))|\u200D(?:\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D)?\uD83D\uDC68|(?:\uD83D[\uDC68\uDC69])\u200D(?:\uD83D\uDC66\u200D\uD83D\uDC66|\uD83D\uDC67\u200D(?:\uD83D[\uDC66\uDC67]))|\uD83D\uDC66\u200D\uD83D\uDC66|\uD83D\uDC67\u200D(?:\uD83D[\uDC66\uDC67])|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFF\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFE])|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFE\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFD\uDFFF])|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFD\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF])|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFC\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB\uDFFD-\uDFFF])|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|(?:\uD83C\uDFFF\u200D[\u2695\u2696\u2708]|\uD83C\uDFFE\u200D[\u2695\u2696\u2708]|\uD83C\uDFFD\u200D[\u2695\u2696\u2708]|\uD83C\uDFFC\u200D[\u2695\u2696\u2708]|\u200D[\u2695\u2696\u2708])\uFE0F|\u200D(?:(?:\uD83D[\uDC68\uDC69])\u200D(?:\uD83D[\uDC66\uDC67])|\uD83D[\uDC66\uDC67])|\uD83C\uDFFF|\uD83C\uDFFE|\uD83C\uDFFD|\uD83C\uDFFC)?|(?:\uD83D\uDC69(?:\uD83C\uDFFB\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D(?:\uD83D[\uDC68\uDC69])|\uD83D[\uDC68\uDC69])|(?:\uD83C[\uDFFC-\uDFFF])\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D(?:\uD83D[\uDC68\uDC69])|\uD83D[\uDC68\uDC69]))|\uD83E\uDDD1(?:\uD83C[\uDFFB-\uDFFF])\u200D\uD83E\uDD1D\u200D\uD83E\uDDD1)(?:\uD83C[\uDFFB-\uDFFF])|\uD83D\uDC69\u200D\uD83D\uDC69\u200D(?:\uD83D\uDC66\u200D\uD83D\uDC66|\uD83D\uDC67\u200D(?:\uD83D[\uDC66\uDC67]))|\uD83D\uDC69(?:\u200D(?:\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D(?:\uD83D[\uDC68\uDC69])|\uD83D[\uDC68\uDC69])|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFF\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFE\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFD\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFC\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFB\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD]))|\uD83E\uDDD1(?:\u200D(?:\uD83E\uDD1D\u200D\uD83E\uDDD1|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFF\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFE\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFD\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFC\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFB\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD]))|\uD83D\uDC69\u200D\uD83D\uDC66\u200D\uD83D\uDC66|\uD83D\uDC69\u200D\uD83D\uDC69\u200D(?:\uD83D[\uDC66\uDC67])|\uD83D\uDC69\u200D\uD83D\uDC67\u200D(?:\uD83D[\uDC66\uDC67])|(?:\uD83D\uDC41\uFE0F\u200D\uD83D\uDDE8|\uD83E\uDDD1(?:\uD83C\uDFFF\u200D[\u2695\u2696\u2708]|\uD83C\uDFFE\u200D[\u2695\u2696\u2708]|\uD83C\uDFFD\u200D[\u2695\u2696\u2708]|\uD83C\uDFFC\u200D[\u2695\u2696\u2708]|\uD83C\uDFFB\u200D[\u2695\u2696\u2708]|\u200D[\u2695\u2696\u2708])|\uD83D\uDC69(?:\uD83C\uDFFF\u200D[\u2695\u2696\u2708]|\uD83C\uDFFE\u200D[\u2695\u2696\u2708]|\uD83C\uDFFD\u200D[\u2695\u2696\u2708]|\uD83C\uDFFC\u200D[\u2695\u2696\u2708]|\uD83C\uDFFB\u200D[\u2695\u2696\u2708]|\u200D[\u2695\u2696\u2708])|\uD83D\uDE36\u200D\uD83C\uDF2B|\uD83C\uDFF3\uFE0F\u200D\u26A7|\uD83D\uDC3B\u200D\u2744|(?:(?:\uD83C[\uDFC3\uDFC4\uDFCA]|\uD83D[\uDC6E\uDC70\uDC71\uDC73\uDC77\uDC81\uDC82\uDC86\uDC87\uDE45-\uDE47\uDE4B\uDE4D\uDE4E\uDEA3\uDEB4-\uDEB6]|\uD83E[\uDD26\uDD35\uDD37-\uDD39\uDD3D\uDD3E\uDDB8\uDDB9\uDDCD-\uDDCF\uDDD4\uDDD6-\uDDDD])(?:\uD83C[\uDFFB-\uDFFF])|\uD83D\uDC6F|\uD83E[\uDD3C\uDDDE\uDDDF])\u200D[\u2640\u2642]|(?:\u26F9|\uD83C[\uDFCB\uDFCC]|\uD83D\uDD75)(?:\uFE0F|\uD83C[\uDFFB-\uDFFF])\u200D[\u2640\u2642]|\uD83C\uDFF4\u200D\u2620|(?:\uD83C[\uDFC3\uDFC4\uDFCA]|\uD83D[\uDC6E\uDC70\uDC71\uDC73\uDC77\uDC81\uDC82\uDC86\uDC87\uDE45-\uDE47\uDE4B\uDE4D\uDE4E\uDEA3\uDEB4-\uDEB6]|\uD83E[\uDD26\uDD35\uDD37-\uDD39\uDD3D\uDD3E\uDDB8\uDDB9\uDDCD-\uDDCF\uDDD4\uDDD6-\uDDDD])\u200D[\u2640\u2642]|[\xA9\xAE\u203C\u2049\u2122\u2139\u2194-\u2199\u21A9\u21AA\u2328\u23CF\u23ED-\u23EF\u23F1\u23F2\u23F8-\u23FA\u24C2\u25AA\u25AB\u25B6\u25C0\u25FB\u25FC\u2600-\u2604\u260E\u2611\u2618\u2620\u2622\u2623\u2626\u262A\u262E\u262F\u2638-\u263A\u2640\u2642\u265F\u2660\u2663\u2665\u2666\u2668\u267B\u267E\u2692\u2694-\u2697\u2699\u269B\u269C\u26A0\u26A7\u26B0\u26B1\u26C8\u26CF\u26D1\u26D3\u26E9\u26F0\u26F1\u26F4\u26F7\u26F8\u2702\u2708\u2709\u270F\u2712\u2714\u2716\u271D\u2721\u2733\u2734\u2744\u2747\u2763\u27A1\u2934\u2935\u2B05-\u2B07\u3030\u303D\u3297\u3299]|\uD83C[\uDD70\uDD71\uDD7E\uDD7F\uDE02\uDE37\uDF21\uDF24-\uDF2C\uDF36\uDF7D\uDF96\uDF97\uDF99-\uDF9B\uDF9E\uDF9F\uDFCD\uDFCE\uDFD4-\uDFDF\uDFF5\uDFF7]|\uD83D[\uDC3F\uDCFD\uDD49\uDD4A\uDD6F\uDD70\uDD73\uDD76-\uDD79\uDD87\uDD8A-\uDD8D\uDDA5\uDDA8\uDDB1\uDDB2\uDDBC\uDDC2-\uDDC4\uDDD1-\uDDD3\uDDDC-\uDDDE\uDDE1\uDDE3\uDDE8\uDDEF\uDDF3\uDDFA\uDECB\uDECD-\uDECF\uDEE0-\uDEE5\uDEE9\uDEF0\uDEF3])\uFE0F|\uD83C\uDFF3\uFE0F\u200D\uD83C\uDF08|\uD83D\uDC69\u200D\uD83D\uDC67|\uD83D\uDC69\u200D\uD83D\uDC66|\uD83D\uDE35\u200D\uD83D\uDCAB|\uD83D\uDE2E\u200D\uD83D\uDCA8|\uD83D\uDC15\u200D\uD83E\uDDBA|\uD83E\uDDD1(?:\uD83C\uDFFF|\uD83C\uDFFE|\uD83C\uDFFD|\uD83C\uDFFC|\uD83C\uDFFB)?|\uD83D\uDC69(?:\uD83C\uDFFF|\uD83C\uDFFE|\uD83C\uDFFD|\uD83C\uDFFC|\uD83C\uDFFB)?|\uD83C\uDDFD\uD83C\uDDF0|\uD83C\uDDF6\uD83C\uDDE6|\uD83C\uDDF4\uD83C\uDDF2|\uD83D\uDC08\u200D\u2B1B|\u2764\uFE0F\u200D(?:\uD83D\uDD25|\uD83E\uDE79)|\uD83D\uDC41\uFE0F|\uD83C\uDFF3\uFE0F|\uD83C\uDDFF(?:\uD83C[\uDDE6\uDDF2\uDDFC])|\uD83C\uDDFE(?:\uD83C[\uDDEA\uDDF9])|\uD83C\uDDFC(?:\uD83C[\uDDEB\uDDF8])|\uD83C\uDDFB(?:\uD83C[\uDDE6\uDDE8\uDDEA\uDDEC\uDDEE\uDDF3\uDDFA])|\uD83C\uDDFA(?:\uD83C[\uDDE6\uDDEC\uDDF2\uDDF3\uDDF8\uDDFE\uDDFF])|\uD83C\uDDF9(?:\uD83C[\uDDE6\uDDE8\uDDE9\uDDEB-\uDDED\uDDEF-\uDDF4\uDDF7\uDDF9\uDDFB\uDDFC\uDDFF])|\uD83C\uDDF8(?:\uD83C[\uDDE6-\uDDEA\uDDEC-\uDDF4\uDDF7-\uDDF9\uDDFB\uDDFD-\uDDFF])|\uD83C\uDDF7(?:\uD83C[\uDDEA\uDDF4\uDDF8\uDDFA\uDDFC])|\uD83C\uDDF5(?:\uD83C[\uDDE6\uDDEA-\uDDED\uDDF0-\uDDF3\uDDF7-\uDDF9\uDDFC\uDDFE])|\uD83C\uDDF3(?:\uD83C[\uDDE6\uDDE8\uDDEA-\uDDEC\uDDEE\uDDF1\uDDF4\uDDF5\uDDF7\uDDFA\uDDFF])|\uD83C\uDDF2(?:\uD83C[\uDDE6\uDDE8-\uDDED\uDDF0-\uDDFF])|\uD83C\uDDF1(?:\uD83C[\uDDE6-\uDDE8\uDDEE\uDDF0\uDDF7-\uDDFB\uDDFE])|\uD83C\uDDF0(?:\uD83C[\uDDEA\uDDEC-\uDDEE\uDDF2\uDDF3\uDDF5\uDDF7\uDDFC\uDDFE\uDDFF])|\uD83C\uDDEF(?:\uD83C[\uDDEA\uDDF2\uDDF4\uDDF5])|\uD83C\uDDEE(?:\uD83C[\uDDE8-\uDDEA\uDDF1-\uDDF4\uDDF6-\uDDF9])|\uD83C\uDDED(?:\uD83C[\uDDF0\uDDF2\uDDF3\uDDF7\uDDF9\uDDFA])|\uD83C\uDDEC(?:\uD83C[\uDDE6\uDDE7\uDDE9-\uDDEE\uDDF1-\uDDF3\uDDF5-\uDDFA\uDDFC\uDDFE])|\uD83C\uDDEB(?:\uD83C[\uDDEE-\uDDF0\uDDF2\uDDF4\uDDF7])|\uD83C\uDDEA(?:\uD83C[\uDDE6\uDDE8\uDDEA\uDDEC\uDDED\uDDF7-\uDDFA])|\uD83C\uDDE9(?:\uD83C[\uDDEA\uDDEC\uDDEF\uDDF0\uDDF2\uDDF4\uDDFF])|\uD83C\uDDE8(?:\uD83C[\uDDE6\uDDE8\uDDE9\uDDEB-\uDDEE\uDDF0-\uDDF5\uDDF7\uDDFA-\uDDFF])|\uD83C\uDDE7(?:\uD83C[\uDDE6\uDDE7\uDDE9-\uDDEF\uDDF1-\uDDF4\uDDF6-\uDDF9\uDDFB\uDDFC\uDDFE\uDDFF])|\uD83C\uDDE6(?:\uD83C[\uDDE8-\uDDEC\uDDEE\uDDF1\uDDF2\uDDF4\uDDF6-\uDDFA\uDDFC\uDDFD\uDDFF])|[#\*0-9]\uFE0F\u20E3|\u2764\uFE0F|(?:\uD83C[\uDFC3\uDFC4\uDFCA]|\uD83D[\uDC6E\uDC70\uDC71\uDC73\uDC77\uDC81\uDC82\uDC86\uDC87\uDE45-\uDE47\uDE4B\uDE4D\uDE4E\uDEA3\uDEB4-\uDEB6]|\uD83E[\uDD26\uDD35\uDD37-\uDD39\uDD3D\uDD3E\uDDB8\uDDB9\uDDCD-\uDDCF\uDDD4\uDDD6-\uDDDD])(?:\uD83C[\uDFFB-\uDFFF])|(?:\u26F9|\uD83C[\uDFCB\uDFCC]|\uD83D\uDD75)(?:\uFE0F|\uD83C[\uDFFB-\uDFFF])|\uD83C\uDFF4|(?:[\u270A\u270B]|\uD83C[\uDF85\uDFC2\uDFC7]|\uD83D[\uDC42\uDC43\uDC46-\uDC50\uDC66\uDC67\uDC6B-\uDC6D\uDC72\uDC74-\uDC76\uDC78\uDC7C\uDC83\uDC85\uDC8F\uDC91\uDCAA\uDD7A\uDD95\uDD96\uDE4C\uDE4F\uDEC0\uDECC]|\uD83E[\uDD0C\uDD0F\uDD18-\uDD1C\uDD1E\uDD1F\uDD30-\uDD34\uDD36\uDD77\uDDB5\uDDB6\uDDBB\uDDD2\uDDD3\uDDD5])(?:\uD83C[\uDFFB-\uDFFF])|(?:[\u261D\u270C\u270D]|\uD83D[\uDD74\uDD90])(?:\uFE0F|\uD83C[\uDFFB-\uDFFF])|[\u270A\u270B]|\uD83C[\uDF85\uDFC2\uDFC7]|\uD83D[\uDC08\uDC15\uDC3B\uDC42\uDC43\uDC46-\uDC50\uDC66\uDC67\uDC6B-\uDC6D\uDC72\uDC74-\uDC76\uDC78\uDC7C\uDC83\uDC85\uDC8F\uDC91\uDCAA\uDD7A\uDD95\uDD96\uDE2E\uDE35\uDE36\uDE4C\uDE4F\uDEC0\uDECC]|\uD83E[\uDD0C\uDD0F\uDD18-\uDD1C\uDD1E\uDD1F\uDD30-\uDD34\uDD36\uDD77\uDDB5\uDDB6\uDDBB\uDDD2\uDDD3\uDDD5]|\uD83C[\uDFC3\uDFC4\uDFCA]|\uD83D[\uDC6E\uDC70\uDC71\uDC73\uDC77\uDC81\uDC82\uDC86\uDC87\uDE45-\uDE47\uDE4B\uDE4D\uDE4E\uDEA3\uDEB4-\uDEB6]|\uD83E[\uDD26\uDD35\uDD37-\uDD39\uDD3D\uDD3E\uDDB8\uDDB9\uDDCD-\uDDCF\uDDD4\uDDD6-\uDDDD]|\uD83D\uDC6F|\uD83E[\uDD3C\uDDDE\uDDDF]|[\u231A\u231B\u23E9-\u23EC\u23F0\u23F3\u25FD\u25FE\u2614\u2615\u2648-\u2653\u267F\u2693\u26A1\u26AA\u26AB\u26BD\u26BE\u26C4\u26C5\u26CE\u26D4\u26EA\u26F2\u26F3\u26F5\u26FA\u26FD\u2705\u2728\u274C\u274E\u2753-\u2755\u2757\u2795-\u2797\u27B0\u27BF\u2B1B\u2B1C\u2B50\u2B55]|\uD83C[\uDC04\uDCCF\uDD8E\uDD91-\uDD9A\uDE01\uDE1A\uDE2F\uDE32-\uDE36\uDE38-\uDE3A\uDE50\uDE51\uDF00-\uDF20\uDF2D-\uDF35\uDF37-\uDF7C\uDF7E-\uDF84\uDF86-\uDF93\uDFA0-\uDFC1\uDFC5\uDFC6\uDFC8\uDFC9\uDFCF-\uDFD3\uDFE0-\uDFF0\uDFF8-\uDFFF]|\uD83D[\uDC00-\uDC07\uDC09-\uDC14\uDC16-\uDC3A\uDC3C-\uDC3E\uDC40\uDC44\uDC45\uDC51-\uDC65\uDC6A\uDC79-\uDC7B\uDC7D-\uDC80\uDC84\uDC88-\uDC8E\uDC90\uDC92-\uDCA9\uDCAB-\uDCFC\uDCFF-\uDD3D\uDD4B-\uDD4E\uDD50-\uDD67\uDDA4\uDDFB-\uDE2D\uDE2F-\uDE34\uDE37-\uDE44\uDE48-\uDE4A\uDE80-\uDEA2\uDEA4-\uDEB3\uDEB7-\uDEBF\uDEC1-\uDEC5\uDED0-\uDED2\uDED5-\uDED7\uDEEB\uDEEC\uDEF4-\uDEFC\uDFE0-\uDFEB]|\uD83E[\uDD0D\uDD0E\uDD10-\uDD17\uDD1D\uDD20-\uDD25\uDD27-\uDD2F\uDD3A\uDD3F-\uDD45\uDD47-\uDD76\uDD78\uDD7A-\uDDB4\uDDB7\uDDBA\uDDBC-\uDDCB\uDDD0\uDDE0-\uDDFF\uDE70-\uDE74\uDE78-\uDE7A\uDE80-\uDE86\uDE90-\uDEA8\uDEB0-\uDEB6\uDEC0-\uDEC2\uDED0-\uDED6]|(?:[\u231A\u231B\u23E9-\u23EC\u23F0\u23F3\u25FD\u25FE\u2614\u2615\u2648-\u2653\u267F\u2693\u26A1\u26AA\u26AB\u26BD\u26BE\u26C4\u26C5\u26CE\u26D4\u26EA\u26F2\u26F3\u26F5\u26FA\u26FD\u2705\u270A\u270B\u2728\u274C\u274E\u2753-\u2755\u2757\u2795-\u2797\u27B0\u27BF\u2B1B\u2B1C\u2B50\u2B55]|\uD83C[\uDC04\uDCCF\uDD8E\uDD91-\uDD9A\uDDE6-\uDDFF\uDE01\uDE1A\uDE2F\uDE32-\uDE36\uDE38-\uDE3A\uDE50\uDE51\uDF00-\uDF20\uDF2D-\uDF35\uDF37-\uDF7C\uDF7E-\uDF93\uDFA0-\uDFCA\uDFCF-\uDFD3\uDFE0-\uDFF0\uDFF4\uDFF8-\uDFFF]|\uD83D[\uDC00-\uDC3E\uDC40\uDC42-\uDCFC\uDCFF-\uDD3D\uDD4B-\uDD4E\uDD50-\uDD67\uDD7A\uDD95\uDD96\uDDA4\uDDFB-\uDE4F\uDE80-\uDEC5\uDECC\uDED0-\uDED2\uDED5-\uDED7\uDEEB\uDEEC\uDEF4-\uDEFC\uDFE0-\uDFEB]|\uD83E[\uDD0C-\uDD3A\uDD3C-\uDD45\uDD47-\uDD78\uDD7A-\uDDCB\uDDCD-\uDDFF\uDE70-\uDE74\uDE78-\uDE7A\uDE80-\uDE86\uDE90-\uDEA8\uDEB0-\uDEB6\uDEC0-\uDEC2\uDED0-\uDED6])|(?:[#\*0-9\xA9\xAE\u203C\u2049\u2122\u2139\u2194-\u2199\u21A9\u21AA\u231A\u231B\u2328\u23CF\u23E9-\u23F3\u23F8-\u23FA\u24C2\u25AA\u25AB\u25B6\u25C0\u25FB-\u25FE\u2600-\u2604\u260E\u2611\u2614\u2615\u2618\u261D\u2620\u2622\u2623\u2626\u262A\u262E\u262F\u2638-\u263A\u2640\u2642\u2648-\u2653\u265F\u2660\u2663\u2665\u2666\u2668\u267B\u267E\u267F\u2692-\u2697\u2699\u269B\u269C\u26A0\u26A1\u26A7\u26AA\u26AB\u26B0\u26B1\u26BD\u26BE\u26C4\u26C5\u26C8\u26CE\u26CF\u26D1\u26D3\u26D4\u26E9\u26EA\u26F0-\u26F5\u26F7-\u26FA\u26FD\u2702\u2705\u2708-\u270D\u270F\u2712\u2714\u2716\u271D\u2721\u2728\u2733\u2734\u2744\u2747\u274C\u274E\u2753-\u2755\u2757\u2763\u2764\u2795-\u2797\u27A1\u27B0\u27BF\u2934\u2935\u2B05-\u2B07\u2B1B\u2B1C\u2B50\u2B55\u3030\u303D\u3297\u3299]|\uD83C[\uDC04\uDCCF\uDD70\uDD71\uDD7E\uDD7F\uDD8E\uDD91-\uDD9A\uDDE6-\uDDFF\uDE01\uDE02\uDE1A\uDE2F\uDE32-\uDE3A\uDE50\uDE51\uDF00-\uDF21\uDF24-\uDF93\uDF96\uDF97\uDF99-\uDF9B\uDF9E-\uDFF0\uDFF3-\uDFF5\uDFF7-\uDFFF]|\uD83D[\uDC00-\uDCFD\uDCFF-\uDD3D\uDD49-\uDD4E\uDD50-\uDD67\uDD6F\uDD70\uDD73-\uDD7A\uDD87\uDD8A-\uDD8D\uDD90\uDD95\uDD96\uDDA4\uDDA5\uDDA8\uDDB1\uDDB2\uDDBC\uDDC2-\uDDC4\uDDD1-\uDDD3\uDDDC-\uDDDE\uDDE1\uDDE3\uDDE8\uDDEF\uDDF3\uDDFA-\uDE4F\uDE80-\uDEC5\uDECB-\uDED2\uDED5-\uDED7\uDEE0-\uDEE5\uDEE9\uDEEB\uDEEC\uDEF0\uDEF3-\uDEFC\uDFE0-\uDFEB]|\uD83E[\uDD0C-\uDD3A\uDD3C-\uDD45\uDD47-\uDD78\uDD7A-\uDDCB\uDDCD-\uDDFF\uDE70-\uDE74\uDE78-\uDE7A\uDE80-\uDE86\uDE90-\uDEA8\uDEB0-\uDEB6\uDEC0-\uDEC2\uDED0-\uDED6])\uFE0F|(?:[\u261D\u26F9\u270A-\u270D]|\uD83C[\uDF85\uDFC2-\uDFC4\uDFC7\uDFCA-\uDFCC]|\uD83D[\uDC42\uDC43\uDC46-\uDC50\uDC66-\uDC78\uDC7C\uDC81-\uDC83\uDC85-\uDC87\uDC8F\uDC91\uDCAA\uDD74\uDD75\uDD7A\uDD90\uDD95\uDD96\uDE45-\uDE47\uDE4B-\uDE4F\uDEA3\uDEB4-\uDEB6\uDEC0\uDECC]|\uD83E[\uDD0C\uDD0F\uDD18-\uDD1F\uDD26\uDD30-\uDD39\uDD3C-\uDD3E\uDD77\uDDB5\uDDB6\uDDB8\uDDB9\uDDBB\uDDCD-\uDDCF\uDDD1-\uDDDD])/g;
337
+ };
338
+ var uD = T(DD);
339
+ var d = 10;
340
+ var M = (e2 = 0) => (u) => `\x1B[${u + e2}m`;
341
+ var P = (e2 = 0) => (u) => `\x1B[${38 + e2};5;${u}m`;
342
+ var W = (e2 = 0) => (u, F, t) => `\x1B[${38 + e2};2;${u};${F};${t}m`;
343
+ var r = { modifier: { reset: [0, 0], bold: [1, 22], dim: [2, 22], italic: [3, 23], underline: [4, 24], overline: [53, 55], inverse: [7, 27], hidden: [8, 28], strikethrough: [9, 29] }, color: { black: [30, 39], red: [31, 39], green: [32, 39], yellow: [33, 39], blue: [34, 39], magenta: [35, 39], cyan: [36, 39], white: [37, 39], blackBright: [90, 39], gray: [90, 39], grey: [90, 39], redBright: [91, 39], greenBright: [92, 39], yellowBright: [93, 39], blueBright: [94, 39], magentaBright: [95, 39], cyanBright: [96, 39], whiteBright: [97, 39] }, bgColor: { bgBlack: [40, 49], bgRed: [41, 49], bgGreen: [42, 49], bgYellow: [43, 49], bgBlue: [44, 49], bgMagenta: [45, 49], bgCyan: [46, 49], bgWhite: [47, 49], bgBlackBright: [100, 49], bgGray: [100, 49], bgGrey: [100, 49], bgRedBright: [101, 49], bgGreenBright: [102, 49], bgYellowBright: [103, 49], bgBlueBright: [104, 49], bgMagentaBright: [105, 49], bgCyanBright: [106, 49], bgWhiteBright: [107, 49] } };
344
+ Object.keys(r.modifier);
345
+ var FD = Object.keys(r.color);
346
+ var eD = Object.keys(r.bgColor);
347
+ [...FD, ...eD];
348
+ function tD() {
349
+ const e2 = /* @__PURE__ */ new Map();
350
+ for (const [u, F] of Object.entries(r)) {
351
+ for (const [t, s] of Object.entries(F)) r[t] = { open: `\x1B[${s[0]}m`, close: `\x1B[${s[1]}m` }, F[t] = r[t], e2.set(s[0], s[1]);
352
+ Object.defineProperty(r, u, { value: F, enumerable: false });
353
+ }
354
+ return Object.defineProperty(r, "codes", { value: e2, enumerable: false }), r.color.close = "\x1B[39m", r.bgColor.close = "\x1B[49m", r.color.ansi = M(), r.color.ansi256 = P(), r.color.ansi16m = W(), r.bgColor.ansi = M(d), r.bgColor.ansi256 = P(d), r.bgColor.ansi16m = W(d), Object.defineProperties(r, { rgbToAnsi256: { value: (u, F, t) => u === F && F === t ? u < 8 ? 16 : u > 248 ? 231 : Math.round((u - 8) / 247 * 24) + 232 : 16 + 36 * Math.round(u / 255 * 5) + 6 * Math.round(F / 255 * 5) + Math.round(t / 255 * 5), enumerable: false }, hexToRgb: { value: (u) => {
355
+ const F = /[a-f\d]{6}|[a-f\d]{3}/i.exec(u.toString(16));
356
+ if (!F) return [0, 0, 0];
357
+ let [t] = F;
358
+ t.length === 3 && (t = [...t].map((C2) => C2 + C2).join(""));
359
+ const s = Number.parseInt(t, 16);
360
+ return [s >> 16 & 255, s >> 8 & 255, s & 255];
361
+ }, enumerable: false }, hexToAnsi256: { value: (u) => r.rgbToAnsi256(...r.hexToRgb(u)), enumerable: false }, ansi256ToAnsi: { value: (u) => {
362
+ if (u < 8) return 30 + u;
363
+ if (u < 16) return 90 + (u - 8);
364
+ let F, t, s;
365
+ if (u >= 232) F = ((u - 232) * 10 + 8) / 255, t = F, s = F;
366
+ else {
367
+ u -= 16;
368
+ const i = u % 36;
369
+ F = Math.floor(u / 36) / 5, t = Math.floor(i / 6) / 5, s = i % 6 / 5;
370
+ }
371
+ const C2 = Math.max(F, t, s) * 2;
372
+ if (C2 === 0) return 30;
373
+ let D = 30 + (Math.round(s) << 2 | Math.round(t) << 1 | Math.round(F));
374
+ return C2 === 2 && (D += 60), D;
375
+ }, enumerable: false }, rgbToAnsi: { value: (u, F, t) => r.ansi256ToAnsi(r.rgbToAnsi256(u, F, t)), enumerable: false }, hexToAnsi: { value: (u) => r.ansi256ToAnsi(r.hexToAnsi256(u)), enumerable: false } }), r;
376
+ }
377
+ var sD = tD();
378
+ var iD = "]";
379
+ var w = `${iD}8;;`;
380
+ var WD = globalThis.process.platform.startsWith("win");
381
+ function OD({ input: e2 = $, output: u = k, overwrite: F = true, hideCursor: t = true } = {}) {
382
+ const s = f.createInterface({ input: e2, output: u, prompt: "", tabSize: 1 });
383
+ f.emitKeypressEvents(e2, s), e2.isTTY && e2.setRawMode(true);
384
+ const C2 = (D, { name: i }) => {
385
+ if (String(D) === "") {
386
+ t && u.write(import_sisteransi.cursor.show), process.exit(0);
387
+ return;
388
+ }
389
+ if (!F) return;
390
+ let n = i === "return" ? 0 : -1, E2 = i === "return" ? -1 : 0;
391
+ f.moveCursor(u, n, E2, () => {
392
+ f.clearLine(u, 1, () => {
393
+ e2.once("keypress", C2);
394
+ });
395
+ });
396
+ };
397
+ return t && u.write(import_sisteransi.cursor.hide), e2.once("keypress", C2), () => {
398
+ e2.off("keypress", C2), t && u.write(import_sisteransi.cursor.show), e2.isTTY && !WD && e2.setRawMode(false), s.terminal = false, s.close();
399
+ };
400
+ }
401
+
402
+ // ../../node_modules/.pnpm/@clack+prompts@0.7.0/node_modules/@clack/prompts/dist/index.mjs
403
+ var import_picocolors = __toESM(require_picocolors(), 1);
404
+ var import_sisteransi2 = __toESM(require_src(), 1);
405
+ import h from "node:process";
406
+ function q2() {
407
+ return h.platform !== "win32" ? h.env.TERM !== "linux" : Boolean(h.env.CI) || Boolean(h.env.WT_SESSION) || Boolean(h.env.TERMINUS_SUBLIME) || h.env.ConEmuTask === "{cmd::Cmder}" || h.env.TERM_PROGRAM === "Terminus-Sublime" || h.env.TERM_PROGRAM === "vscode" || h.env.TERM === "xterm-256color" || h.env.TERM === "alacritty" || h.env.TERMINAL_EMULATOR === "JetBrains-JediTerm";
408
+ }
409
+ var _ = q2();
410
+ var o = (r2, n) => _ ? r2 : n;
411
+ var H = o("\u25C6", "*");
412
+ var I = o("\u25A0", "x");
413
+ var x = o("\u25B2", "x");
414
+ var S = o("\u25C7", "o");
415
+ var K = o("\u250C", "T");
416
+ var a = o("\u2502", "|");
417
+ var d2 = o("\u2514", "\u2014");
418
+ var b = o("\u25CF", ">");
419
+ var E = o("\u25CB", " ");
420
+ var C = o("\u25FB", "[\u2022]");
421
+ var w2 = o("\u25FC", "[+]");
422
+ var M2 = o("\u25FB", "[ ]");
423
+ var U = o("\u25AA", "\u2022");
424
+ var B = o("\u2500", "-");
425
+ var Z = o("\u256E", "+");
426
+ var z = o("\u251C", "+");
427
+ var X2 = o("\u256F", "+");
428
+ var J2 = o("\u25CF", "\u2022");
429
+ var Y = o("\u25C6", "*");
430
+ var Q2 = o("\u25B2", "!");
431
+ var ee = o("\u25A0", "x");
432
+ var oe = (r2 = "") => {
433
+ process.stdout.write(`${import_picocolors.default.gray(K)} ${r2}
434
+ `);
435
+ };
436
+ var $e = (r2 = "") => {
437
+ process.stdout.write(`${import_picocolors.default.gray(a)}
438
+ ${import_picocolors.default.gray(d2)} ${r2}
439
+
440
+ `);
441
+ };
442
+ var f2 = { message: (r2 = "", { symbol: n = import_picocolors.default.gray(a) } = {}) => {
443
+ const i = [`${import_picocolors.default.gray(a)}`];
444
+ if (r2) {
445
+ const [t, ...s] = r2.split(`
446
+ `);
447
+ i.push(`${n} ${t}`, ...s.map((c) => `${import_picocolors.default.gray(a)} ${c}`));
448
+ }
449
+ process.stdout.write(`${i.join(`
450
+ `)}
451
+ `);
452
+ }, info: (r2) => {
453
+ f2.message(r2, { symbol: import_picocolors.default.blue(J2) });
454
+ }, success: (r2) => {
455
+ f2.message(r2, { symbol: import_picocolors.default.green(Y) });
456
+ }, step: (r2) => {
457
+ f2.message(r2, { symbol: import_picocolors.default.green(S) });
458
+ }, warn: (r2) => {
459
+ f2.message(r2, { symbol: import_picocolors.default.yellow(Q2) });
460
+ }, warning: (r2) => {
461
+ f2.warn(r2);
462
+ }, error: (r2) => {
463
+ f2.message(r2, { symbol: import_picocolors.default.red(ee) });
464
+ } };
465
+ var de = () => {
466
+ const r2 = _ ? ["\u25D2", "\u25D0", "\u25D3", "\u25D1"] : ["\u2022", "o", "O", "0"], n = _ ? 80 : 120;
467
+ let i, t, s = false, c = "";
468
+ const l2 = (v = "") => {
469
+ s = true, i = OD(), c = v.replace(/\.+$/, ""), process.stdout.write(`${import_picocolors.default.gray(a)}
470
+ `);
471
+ let g = 0, p = 0;
472
+ t = setInterval(() => {
473
+ const O = import_picocolors.default.magenta(r2[g]), P2 = ".".repeat(Math.floor(p)).slice(0, 3);
474
+ process.stdout.write(import_sisteransi2.cursor.move(-999, 0)), process.stdout.write(import_sisteransi2.erase.down(1)), process.stdout.write(`${O} ${c}${P2}`), g = g + 1 < r2.length ? g + 1 : 0, p = p < r2.length ? p + 0.125 : 0;
475
+ }, n);
476
+ }, u = (v = "", g = 0) => {
477
+ c = v ?? c, s = false, clearInterval(t);
478
+ const p = g === 0 ? import_picocolors.default.green(S) : g === 1 ? import_picocolors.default.red(I) : import_picocolors.default.red(x);
479
+ process.stdout.write(import_sisteransi2.cursor.move(-999, 0)), process.stdout.write(import_sisteransi2.erase.down(1)), process.stdout.write(`${p} ${c}
480
+ `), i();
481
+ }, m2 = (v = "") => {
482
+ c = v ?? c;
483
+ }, $2 = (v) => {
484
+ const g = v > 1 ? "Something went wrong" : "Canceled";
485
+ s && u(g, v);
486
+ };
487
+ return process.on("uncaughtExceptionMonitor", () => $2(2)), process.on("unhandledRejection", () => $2(2)), process.on("SIGINT", () => $2(1)), process.on("SIGTERM", () => $2(1)), process.on("exit", $2), { start: l2, stop: u, message: m2 };
488
+ };
489
+
490
+ // ../cli-core/src/errors.ts
491
+ init_define_APP_STARTER();
492
+ init_define_PKG();
493
+ var UsageError = class extends Error {
494
+ };
495
+ var UnavailableError = class extends Error {
496
+ };
497
+
498
+ // ../cli-core/src/node-version.ts
499
+ init_define_APP_STARTER();
500
+ init_define_PKG();
501
+ var atLeast = (version, minimum) => version.replace(/^v/, "").localeCompare(minimum, void 0, { numeric: true }) >= 0;
502
+ function assertNode(version, enginesRange) {
503
+ const minimum = enginesRange.replace(/^>=/, "");
504
+ if (!atLeast(version, minimum)) {
505
+ throw new UsageError(
506
+ `ShopNex needs Node ${minimum} or newer, this is ${version}. Install a newer Node (https://nodejs.org) and run it again.`
507
+ );
508
+ }
509
+ }
510
+
511
+ // ../cli-core/src/theme.ts
512
+ init_define_APP_STARTER();
513
+ init_define_PKG();
514
+ var import_picocolors2 = __toESM(require_picocolors(), 1);
515
+ var BRAND = [67, 192, 122];
516
+ var ON_BRAND = [6, 21, 12];
517
+ var truecolor = import_picocolors2.default.isColorSupported && /^(truecolor|24bit)$/i.test(process.env.COLORTERM ?? "");
518
+ 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));
519
+
520
+ // src/args.ts
521
+ init_define_APP_STARTER();
522
+ init_define_PKG();
523
+ import { parseArgs } from "node:util";
524
+ var DEFAULT_PORT = 3e3;
525
+ var COMMANDS = ["migrate-db", "generate"];
526
+ var options = {
527
+ to: { type: "string" },
528
+ "to-env": { type: "string" },
529
+ dir: { type: "string" },
530
+ port: { type: "string" },
531
+ help: { type: "boolean", short: "h" },
532
+ version: { type: "boolean", short: "v" }
533
+ };
534
+ function parse(argv) {
535
+ let values;
536
+ let positionals;
537
+ try {
538
+ ;
539
+ ({ values, positionals } = parseArgs({ args: argv, options, allowPositionals: true }));
540
+ } catch (error) {
541
+ throw new UsageError(`${error.message}
542
+ Run shopnex --help for the options.`);
543
+ }
544
+ if (positionals[0] !== "generate" && positionals.length > 1)
545
+ throw new UsageError(`Give one command, got: ${positionals.join(" ")}`);
546
+ const port = values.port === void 0 ? DEFAULT_PORT : Number(values.port);
547
+ if (!Number.isInteger(port) || port < 1 || port > 65535) {
548
+ throw new UsageError(`--port must be a port number (1-65535), got "${values.port}"`);
549
+ }
550
+ return {
551
+ command: positionals[0],
552
+ rest: positionals.slice(1),
553
+ to: values.to,
554
+ toEnv: values["to-env"],
555
+ dir: values.dir ?? ".",
556
+ port,
557
+ help: Boolean(values.help),
558
+ version: Boolean(values.version)
559
+ };
560
+ }
561
+
562
+ // src/generate.ts
563
+ init_define_APP_STARTER();
564
+ init_define_PKG();
565
+ import { existsSync, mkdirSync, readFileSync, readdirSync, writeFileSync } from "node:fs";
566
+ import { basename, dirname, join, resolve } from "node:path";
567
+ var KINDS = ["app"];
568
+ var STARTER_FILES = ["src/server.tsx", ".env.example", ".gitignore"];
569
+ var starterFile = (path) => typeof define_APP_STARTER_default !== "undefined" ? define_APP_STARTER_default[path] ?? "" : readFileSync(new URL(`../../../templates/app-starter/${path}`, import.meta.url), "utf8");
570
+ function checkName(name) {
571
+ if (!name) throw new UsageError("Give the app a name: shopnex generate app <name>");
572
+ if (!/^[a-z0-9][a-z0-9._-]*$/.test(basename(name))) {
573
+ throw new UsageError(`"${name}" is not a usable app name: use lowercase letters, numbers, - and _.`);
574
+ }
575
+ }
576
+ var title = (name) => {
577
+ const words = basename(name).replace(/[-_.]+/g, " ");
578
+ return words.charAt(0).toUpperCase() + words.slice(1);
579
+ };
580
+ function appFiles(name, version) {
581
+ const id = basename(name);
582
+ const files = {};
583
+ for (const path of STARTER_FILES) files[path] = starterFile(path);
584
+ files["src/server.tsx"] = files["src/server.tsx"].replaceAll("App starter", title(name));
585
+ files["package.json"] = JSON.stringify(
586
+ {
587
+ name: id,
588
+ private: true,
589
+ type: "module",
590
+ scripts: {
591
+ dev: "tsx watch --env-file-if-exists=.env src/server.tsx",
592
+ start: "tsx --env-file-if-exists=.env src/server.tsx",
593
+ typecheck: "tsc"
594
+ },
595
+ dependencies: { "@hono/node-server": "^2.1.6", "@shopnex/app": `^${version}`, hono: "^4.13.17" },
596
+ devDependencies: { "@types/node": "^22.20.5", tsx: "^4.23.15", typescript: "5.9.3" }
597
+ },
598
+ null,
599
+ 2
600
+ ) + "\n";
601
+ files["tsconfig.json"] = JSON.stringify(
602
+ {
603
+ compilerOptions: {
604
+ target: "ES2022",
605
+ lib: ["ES2022", "DOM"],
606
+ module: "ESNext",
607
+ moduleResolution: "Bundler",
608
+ strict: true,
609
+ noUncheckedIndexedAccess: true,
610
+ esModuleInterop: true,
611
+ skipLibCheck: true,
612
+ isolatedModules: true,
613
+ noEmit: true,
614
+ jsx: "react-jsx",
615
+ jsxImportSource: "hono/jsx",
616
+ types: ["node"]
617
+ },
618
+ include: ["src"]
619
+ },
620
+ null,
621
+ 2
622
+ ) + "\n";
623
+ files["README.md"] = `# ${title(name)}
624
+
625
+ A ShopNex app, made with \`npx shopnex generate app ${id}\`.
626
+
627
+ ## Run it
628
+
629
+ 1. \`cp .env.example .env\`, then fill in \`SHOPNEX_CLIENT_ID\` and \`SHOPNEX_APP_KEY\` from your app's page in the
630
+ marketplace developer dashboard (or Admin \u2192 Apps \u2192 Custom apps).
631
+ 2. \`pnpm install\` (or npm, yarn), then \`pnpm dev\`.
632
+ 3. Register \`http://localhost:4500\` as the App URL, install the app from the admin, and open it there.
633
+
634
+ \`src/server.tsx\` is the whole app: a page inside the admin, an endpoint that saves a note in the shop's app data,
635
+ and an \`order.created\` webhook.
636
+ `;
637
+ return files;
638
+ }
639
+ function generateApp({ name, dir, version }) {
640
+ checkName(name);
641
+ const folder = resolve(existsSync(join(dir, ".env")) ? join(dir, "apps") : dir, name);
642
+ if (existsSync(folder) && readdirSync(folder).length > 0) {
643
+ throw new UsageError(`${folder} is not empty. Pick another name, or empty the folder.`);
644
+ }
645
+ for (const [path, content] of Object.entries(appFiles(name, version))) {
646
+ const file = join(folder, path);
647
+ mkdirSync(dirname(file), { recursive: true });
648
+ writeFileSync(file, content);
649
+ }
650
+ return folder;
651
+ }
652
+
653
+ // src/migrate-db.ts
654
+ init_define_APP_STARTER();
655
+ init_define_PKG();
656
+ import { cpSync, existsSync as existsSync4, readdirSync as readdirSync3, rmSync as rmSync2 } from "node:fs";
657
+ import { join as join5, resolve as resolve4 } from "node:path";
658
+
659
+ // ../cli-core/src/bundle.ts
660
+ init_define_APP_STARTER();
661
+ init_define_PKG();
662
+ import { createHash } from "node:crypto";
663
+ import {
664
+ createWriteStream,
665
+ existsSync as existsSync2,
666
+ mkdirSync as mkdirSync2,
667
+ mkdtempSync,
668
+ readdirSync as readdirSync2,
669
+ readFileSync as readFileSync2,
670
+ renameSync,
671
+ rmSync
672
+ } from "node:fs";
673
+ import { join as join3 } from "node:path";
674
+ import { spawnSync } from "node:child_process";
675
+ import { Readable, Transform } from "node:stream";
676
+ import { pipeline } from "node:stream/promises";
677
+
678
+ // ../cli-core/src/paths.ts
679
+ init_define_APP_STARTER();
680
+ init_define_PKG();
681
+ import { homedir } from "node:os";
682
+ import { join as join2, resolve as resolve2 } from "node:path";
683
+ var appCacheDir = () => process.env.SHOPNEX_APP_DIR ?? join2(homedir(), ".shopnex", "app");
684
+
685
+ // ../cli-core/src/bundle.ts
686
+ var isEdge = (version) => /-edge\./.test(version);
687
+ var bundleName = (version) => `shopnex-v${version}-node.tgz`;
688
+ 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)}`);
689
+ var bundleDir = (key) => join3(appCacheDir(), key);
690
+ var isInstalled = (key) => existsSync2(join3(bundleDir(key), "manifest.json"));
691
+ var installedEdges = () => existsSync2(appCacheDir()) ? readdirSync2(appCacheDir()).filter((name) => /^edge-[0-9a-f]{12}$/.test(name)) : [];
692
+ async function get(url, what, version, cli) {
693
+ let response;
694
+ try {
695
+ response = await fetch(url);
696
+ } catch (error) {
697
+ const reason = error.cause?.message ?? error.message;
698
+ throw new UnavailableError(`Could not download ${what} (${reason}).
699
+ Check your connection and try again.`);
700
+ }
701
+ if (response.status === 404) {
702
+ throw new UnavailableError(
703
+ `ShopNex ${version} has no packaged build to download (404 for ${url}).
704
+ Use a released version of ${cli}.`
705
+ );
706
+ }
707
+ if (!response.ok) {
708
+ throw new UnavailableError(`Could not download ${what}: ${url} answered ${response.status}.`);
709
+ }
710
+ return response;
711
+ }
712
+ var parseChecksum = (text) => text.trim().split(/\s+/)[0]?.toLowerCase() ?? "";
713
+ async function download(response, file, onProgress) {
714
+ const hash = createHash("sha256");
715
+ let bytes = 0;
716
+ const measure = new Transform({
717
+ transform(chunk, _encoding, done) {
718
+ hash.update(chunk);
719
+ bytes += chunk.length;
720
+ onProgress(bytes);
721
+ done(null, chunk);
722
+ }
723
+ });
724
+ await pipeline(
725
+ Readable.fromWeb(response.body),
726
+ measure,
727
+ createWriteStream(file)
728
+ );
729
+ return hash.digest("hex");
730
+ }
731
+ async function resolveBundle({ version, cli = "create-shopnex" }) {
732
+ const edge = isEdge(version);
733
+ if (!edge && isInstalled(version)) return bundleDir(version);
734
+ mkdirSync2(appCacheDir(), { recursive: true });
735
+ const spinner = de();
736
+ const animate = Boolean(process.stdout.isTTY);
737
+ const say = (message) => animate ? spinner.message(message) : void 0;
738
+ const start = edge ? "Checking for a newer edge build" : `Downloading ShopNex ${version} (once, about 15 MB)`;
739
+ if (animate) spinner.start(start);
740
+ else f2.step(start);
741
+ let work;
742
+ try {
743
+ const url = bundleUrl(version);
744
+ const expected = parseChecksum(await (await get(`${url}.sha256`, "the checksum", version, cli)).text());
745
+ if (!/^[0-9a-f]{64}$/.test(expected)) throw new UnavailableError(`${url}.sha256 does not hold a SHA-256 checksum.`);
746
+ const key = edge ? `edge-${expected.slice(0, 12)}` : version;
747
+ const dir = bundleDir(key);
748
+ if (isInstalled(key)) {
749
+ if (animate) spinner.stop("ShopNex edge is up to date");
750
+ return dir;
751
+ }
752
+ const label = edge ? "the latest edge build" : `ShopNex ${version}`;
753
+ say(`Downloading ${label}`);
754
+ work = mkdtempSync(join3(appCacheDir(), `${key}.tmp-`));
755
+ const file = join3(work, "bundle.tgz");
756
+ const actual = await download(
757
+ await get(url, "ShopNex", version, cli),
758
+ file,
759
+ (bytes) => say(`Downloading ${label}: ${(bytes / 1e6).toFixed(1)} MB`)
760
+ );
761
+ if (actual !== expected) {
762
+ throw new UnavailableError(
763
+ `The download is damaged: its SHA-256 is ${actual}, expected ${expected}. Nothing was installed; try again.`
764
+ );
765
+ }
766
+ say("Unpacking");
767
+ const unpacked = join3(work, "app");
768
+ mkdirSync2(unpacked);
769
+ const tar = spawnSync("tar", ["-xzf", file, "-C", unpacked], { encoding: "utf8" });
770
+ if (tar.error || tar.status !== 0) {
771
+ throw new UnavailableError(`Could not unpack the download with tar: ${tar.error?.message ?? tar.stderr.trim()}`);
772
+ }
773
+ const manifestFile = join3(unpacked, "manifest.json");
774
+ const manifest = existsSync2(manifestFile) ? JSON.parse(readFileSync2(manifestFile, "utf8")) : void 0;
775
+ if (edge ? !manifest : manifest?.version !== version) {
776
+ throw new UnavailableError(
777
+ `The download is not ShopNex ${version} (its manifest says ${manifest?.version ?? "nothing"}).`
778
+ );
779
+ }
780
+ rmSync(dir, { recursive: true, force: true });
781
+ renameSync(unpacked, dir);
782
+ for (const old of installedEdges()) if (old !== key) rmSync(bundleDir(old), { recursive: true, force: true });
783
+ if (animate) spinner.stop(`${label} downloaded`);
784
+ else f2.success(`${label} downloaded`);
785
+ return dir;
786
+ } catch (error) {
787
+ if (animate) spinner.stop("Download failed", 1);
788
+ throw error;
789
+ } finally {
790
+ if (work) rmSync(work, { recursive: true, force: true });
791
+ }
792
+ }
793
+
794
+ // ../cli-core/src/env.ts
795
+ init_define_APP_STARTER();
796
+ init_define_PKG();
797
+ import { randomBytes } from "node:crypto";
798
+ import { existsSync as existsSync3, mkdirSync as mkdirSync3, readFileSync as readFileSync3, appendFileSync, writeFileSync as writeFileSync2 } from "node:fs";
799
+ import { isAbsolute, join as join4, resolve as resolve3 } from "node:path";
800
+ import { parseEnv } from "node:util";
801
+ var DEFAULT_DATABASE_URL = "pglite:./.pglite";
802
+ var template = (secret) => `# ShopNex: the settings of this shop. Edit, then start it again.
803
+ #
804
+ # Where the data lives. The default is an embedded database in ./.pglite (PGlite): one process owns it, for trying
805
+ # ShopNex out. For a real database use PostgreSQL, for example:
806
+ # DATABASE_URL=postgres://user:password@localhost:5432/shopnex
807
+ # (docker-compose.yml runs ShopNex and PostgreSQL in Docker)
808
+ DATABASE_URL=${DEFAULT_DATABASE_URL}
809
+
810
+ # Encrypts the provider keys saved in the admin and signs sessions. Keep it: a new one logs everyone out and makes the
811
+ # saved keys unreadable. Do not share this file.
812
+ SHOPNEX_SECRET=${secret}
813
+ `;
814
+ var resolveDatabaseUrl = (url, shopDir) => {
815
+ if (!url.startsWith("pglite:")) return url;
816
+ const path = url.slice("pglite:".length);
817
+ return isAbsolute(path) ? url : `pglite:${resolve3(shopDir, path)}`;
818
+ };
819
+ var redactUrl = (url) => url.replace(/\/\/([^:@/]+):[^@/]*@/, "//$1:***@");
820
+ function loadShopEnv(shopDir, { write }) {
821
+ const file = join4(shopDir, ".env");
822
+ const exists = existsSync3(file);
823
+ const { DATABASE_URL, SHOPNEX_SECRET, ...rest } = exists ? parseEnv(readFileSync3(file, "utf8")) : {};
824
+ const secret = SHOPNEX_SECRET?.trim() || (write ? randomBytes(32).toString("hex") : "");
825
+ const databaseUrl = DATABASE_URL?.trim() || DEFAULT_DATABASE_URL;
826
+ if (write) {
827
+ if (!exists) {
828
+ mkdirSync3(shopDir, { recursive: true });
829
+ writeFileSync2(file, template(secret), { mode: 384 });
830
+ } else {
831
+ const missing = [
832
+ DATABASE_URL?.trim() ? "" : `DATABASE_URL=${DEFAULT_DATABASE_URL}`,
833
+ SHOPNEX_SECRET?.trim() ? "" : `SHOPNEX_SECRET=${secret}`
834
+ ].filter(Boolean);
835
+ if (missing.length)
836
+ appendFileSync(file, `${readFileSync3(file, "utf8").endsWith("\n") ? "" : "\n"}${missing.join("\n")}
837
+ `);
838
+ }
839
+ }
840
+ return { databaseUrl: resolveDatabaseUrl(databaseUrl, shopDir), secret, rest, file };
841
+ }
842
+ function switchDatabaseUrl(file, url, now = /* @__PURE__ */ new Date()) {
843
+ if (/[\s#"'`]/.test(url)) {
844
+ throw new UsageError(
845
+ "The database address has a space, #, quote or backtick in it: percent-encode those characters."
846
+ );
847
+ }
848
+ const text = readFileSync3(file, "utf8");
849
+ const line = /^[ \t]*DATABASE_URL[ \t]*=.*$/m;
850
+ const old = line.exec(text)?.[0].trim();
851
+ const stamp2 = now.toISOString().slice(0, 10);
852
+ const replacement = `${old ? `# ${redactUrl(old)} (before shopnex migrate-db, ${stamp2})
853
+ ` : ""}DATABASE_URL=${url}`;
854
+ writeFileSync2(
855
+ file,
856
+ old ? text.replace(line, () => replacement) : `${text}${text.endsWith("\n") ? "" : "\n"}${replacement}
857
+ `
858
+ );
859
+ }
860
+
861
+ // ../cli-core/src/ports.ts
862
+ init_define_APP_STARTER();
863
+ init_define_PKG();
864
+ import { connect } from "node:net";
865
+ function portInUse(port) {
866
+ const tryHost = (host) => new Promise((resolve6) => {
867
+ const socket = connect({ port, host });
868
+ socket.setTimeout(500);
869
+ socket.once("connect", () => (socket.destroy(), resolve6(true)));
870
+ socket.once("timeout", () => (socket.destroy(), resolve6(false)));
871
+ socket.once("error", () => resolve6(false));
872
+ });
873
+ return Promise.all([tryHost("127.0.0.1"), tryHost("::1")]).then((used) => used.some(Boolean));
874
+ }
875
+
876
+ // src/run-once.ts
877
+ init_define_APP_STARTER();
878
+ init_define_PKG();
879
+ import { spawn } from "node:child_process";
880
+ function runOnce({ script, cwd, env }) {
881
+ return new Promise((resolve6) => {
882
+ const child = spawn(process.execPath, [script], { cwd, env: { ...process.env, ...env }, stdio: "inherit" });
883
+ child.on("error", (error) => {
884
+ console.error(`Could not start ${script}: ${error.message}`);
885
+ resolve6(1);
886
+ });
887
+ child.on("exit", (code, signal) => resolve6(code ?? (signal ? 1 : 0)));
888
+ });
889
+ }
890
+
891
+ // src/migrate-db.ts
892
+ function targetUrl({ to, toEnv }) {
893
+ if (to === void 0 === (toEnv === void 0)) {
894
+ throw new UsageError("Give where to move the data: --to postgres://\u2026 or --to-env NAME (a variable that holds it).");
895
+ }
896
+ const url = to ?? process.env[toEnv]?.trim();
897
+ if (!url) throw new UsageError(`${toEnv} is not set.`);
898
+ if (!/^postgres(ql)?:\/\/\S+$/.test(url)) {
899
+ throw new UsageError(`The new database must be a postgres:// address, got "${redactUrl(url)}".`);
900
+ }
901
+ return url;
902
+ }
903
+ var stamp = (now) => now.toISOString().replace(/[-:]/g, "").replace("T", "-").slice(0, 15);
904
+ var appsWithData = (shopDir) => {
905
+ const apps = join5(shopDir, "apps");
906
+ if (!existsSync4(apps)) return [];
907
+ return readdirSync3(apps).filter((name) => existsSync4(join5(apps, name, ".pglite")));
908
+ };
909
+ async function migrateDb(options2) {
910
+ const target = targetUrl(options2);
911
+ const shopDir = resolve4(process.cwd(), options2.dir);
912
+ if (!existsSync4(join5(shopDir, ".env"))) {
913
+ throw new UsageError(
914
+ `${shopDir} is not a ShopNex shop (there is no .env in it). Go into the shop's folder, or give it with --dir.`
915
+ );
916
+ }
917
+ const env = loadShopEnv(shopDir, { write: false });
918
+ if (!env.databaseUrl.startsWith("pglite:")) {
919
+ throw new UsageError(`This shop already uses PostgreSQL (${redactUrl(env.databaseUrl)}): nothing to move.`);
920
+ }
921
+ const data = env.databaseUrl.slice("pglite:".length);
922
+ if (data === "memory" || !existsSync4(data)) {
923
+ throw new UsageError(`There is no data to move: ${data} does not exist. Start the shop once first.`);
924
+ }
925
+ if (await portInUse(options2.port)) {
926
+ throw new UsageError(
927
+ `Something answers on port ${options2.port}: stop the shop first (Ctrl+C where it runs). If it runs on another port, give it with --port.`
928
+ );
929
+ }
930
+ const root = await resolveBundle({ version: options2.version, cli: "shopnex" });
931
+ const script = join5(root, "admin", "migrate-db.mjs");
932
+ if (!existsSync4(script)) {
933
+ throw new UnavailableError(`ShopNex ${options2.version} cannot move a database yet (its build has no migrate-db).`);
934
+ }
935
+ const backup = `${data}.bak-${stamp(/* @__PURE__ */ new Date())}`;
936
+ cpSync(data, backup, { recursive: true });
937
+ f2.info(`A copy of the current data is kept in ${backup} until the move has worked`);
938
+ const code = await runOnce({
939
+ script,
940
+ cwd: join5(root, "admin"),
941
+ env: {
942
+ SOURCE_DATABASE_URL: env.databaseUrl,
943
+ TARGET_DATABASE_URL: target,
944
+ SHOPNEX_MIGRATIONS_DIR: join5(root, "migrations")
945
+ }
946
+ });
947
+ if (code !== 0) {
948
+ rmSync2(backup, { recursive: true, force: true });
949
+ throw new UnavailableError(`Nothing was changed: the shop still uses ${data}.`);
950
+ }
951
+ switchDatabaseUrl(env.file, target);
952
+ const left = appsWithData(shopDir);
953
+ if (left.length) {
954
+ f2.warn(
955
+ `The data of ${left.map((name) => `apps/${name}`).join(", ")} was not moved: those apps start empty on PostgreSQL. Their old files stay in apps/.`
956
+ );
957
+ }
958
+ $e(
959
+ `The shop now uses ${redactUrl(target)}. Start it again as before; the old data stays in ${data} as a fallback.`
960
+ );
961
+ }
962
+
963
+ // src/cli.ts
964
+ var pkg = typeof define_PKG_default !== "undefined" ? define_PKG_default : JSON.parse(readFileSync4(new URL("../package.json", import.meta.url), "utf8"));
965
+ var HELP = `shopnex ${pkg.version}: look after a ShopNex shop made with create-shopnex.
966
+
967
+ Usage
968
+ shopnex <command> [options]
969
+
970
+ Commands
971
+ migrate-db move the shop's data from the embedded database to PostgreSQL
972
+ generate app <name>
973
+ make a new ShopNex app in apps/<name> of the shop folder (or ./<name> outside one)
974
+
975
+ Options
976
+ --to <url> migrate-db: the PostgreSQL address, an empty database (postgres://user:password@host:5432/shopnex)
977
+ --to-env <NAME> migrate-db: read that address from the environment variable NAME, so the password stays out of
978
+ the shell history
979
+ --dir <folder> the shop's folder (default: the current folder)
980
+ --port <n> the admin's port, to check the shop is stopped (default 3000)
981
+ -h, --help this text
982
+ -v, --version the version
983
+
984
+ Run it in the shop's folder, with the shop stopped. A copy of the old data is kept next to it.
985
+ `;
986
+ async function run(argv) {
987
+ const options2 = parse(argv);
988
+ if (options2.version) return void console.log(pkg.version);
989
+ if (options2.help || !options2.command) return void console.log(HELP);
990
+ if (!COMMANDS.includes(options2.command)) {
991
+ throw new UsageError(`Unknown command "${options2.command}". Run shopnex --help.`);
992
+ }
993
+ assertNode(process.versions.node, pkg.engines.node);
994
+ oe(brandBadge(` shopnex ${options2.command} ${pkg.version} `));
995
+ if (options2.command === "generate") {
996
+ const [kind, name, ...extra] = options2.rest;
997
+ if (!KINDS.includes(kind) || extra.length > 0) {
998
+ throw new UsageError(`Usage: shopnex generate app <name> (kinds: ${KINDS.join(", ")}).`);
999
+ }
1000
+ const folder = generateApp({ name, dir: resolve5(options2.dir), version: pkg.version });
1001
+ return void $e(
1002
+ `Made ${folder}
1003
+ Next: cd ${relative(process.cwd(), folder) || "."}, copy .env.example to .env, then pnpm install and pnpm dev.`
1004
+ );
1005
+ }
1006
+ await migrateDb({ ...options2, version: pkg.version });
1007
+ }
1008
+ async function main(argv) {
1009
+ try {
1010
+ await run(argv);
1011
+ } catch (error) {
1012
+ if (error instanceof UsageError) {
1013
+ console.error(error.message);
1014
+ process.exitCode = 2;
1015
+ } else if (error instanceof UnavailableError) {
1016
+ console.error(error.message);
1017
+ process.exitCode = 1;
1018
+ } else {
1019
+ throw error;
1020
+ }
1021
+ }
1022
+ }
1023
+
1024
+ // src/main.ts
1025
+ await main(process.argv.slice(2));
package/package.json CHANGED
@@ -1,6 +1,46 @@
1
1
  {
2
2
  "name": "shopnex",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.16.1",
4
+ "description": "Look after a ShopNex shop made with create-shopnex: npx shopnex migrate-db moves the embedded database to PostgreSQL",
5
+ "license": "MIT",
6
+ "homepage": "https://shopnex.ai",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/shopnex-ai/shopnex.git",
10
+ "directory": "packages/cli"
11
+ },
12
+ "keywords": [
13
+ "shopnex",
14
+ "ecommerce",
15
+ "cli"
16
+ ],
17
+ "publishConfig": {
18
+ "access": "public"
19
+ },
20
+ "type": "module",
21
+ "bin": {
22
+ "shopnex": "./bin/shopnex.mjs"
23
+ },
24
+ "files": [
25
+ "bin",
26
+ "dist"
27
+ ],
28
+ "engines": {
29
+ "node": ">=22.22.0"
30
+ },
31
+ "scripts": {
32
+ "build": "node scripts/build.mjs",
33
+ "prepack": "node scripts/build.mjs",
34
+ "dev": "tsx src/main.ts",
35
+ "typecheck": "tsc",
36
+ "test": "tsx --test \"tests/**/*.test.ts\""
37
+ },
38
+ "devDependencies": {
39
+ "@clack/prompts": "^0.7.0",
40
+ "@shopnex/cli-core": "workspace:*",
41
+ "@types/node": "catalog:",
42
+ "esbuild": "0.28.2",
43
+ "picocolors": "^1.1.1",
44
+ "tsx": "^4.23.15"
45
+ }
46
+ }