sellwavy-cli 0.1.0 → 0.1.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/bin/sellwavy.mjs +2 -2
- package/lib/commands.mjs +71 -16
- package/lib/guide.mjs +10 -2
- package/lib/mcp.mjs +1 -1
- package/lib/site.mjs +7 -4
- package/lib/version.mjs +1 -1
- package/package.json +1 -1
package/bin/sellwavy.mjs
CHANGED
|
@@ -37,7 +37,7 @@ ${c.bold('Flags')}
|
|
|
37
37
|
Run ${c.bold('sellwavy <command> --help')} for details. Keys: SELLWAVY_TOKEN works in place of login.`
|
|
38
38
|
|
|
39
39
|
const HELPS = {
|
|
40
|
-
login: `sellwavy login [--no-browser] [--name "MacBook"]
|
|
40
|
+
login: `sellwavy login [--no-browser] [--no-wait] [--name "MacBook"]
|
|
41
41
|
Opens Sellwavy in your browser to approve this computer: type the code it shows there.
|
|
42
42
|
sellwavy login --token <key>
|
|
43
43
|
Uses a key made in Account > CLI & AI agents (for servers and CI).`,
|
|
@@ -83,7 +83,7 @@ sellwavy theme set primaryColor=#111111 font=sans darkMode=true ...`,
|
|
|
83
83
|
Other agents: command "npx", args ["-y", "sellwavy-cli", "mcp"].`,
|
|
84
84
|
}
|
|
85
85
|
|
|
86
|
-
const BOOLEAN = new Set(['json', 'force', 'yes', 'dry-run', 'no-browser', 'help', 'version', 'keep-off', 'no-guide', 'all'])
|
|
86
|
+
const BOOLEAN = new Set(['json', 'force', 'yes', 'dry-run', 'no-browser', 'no-wait', 'help', 'version', 'keep-off', 'no-guide', 'all'])
|
|
87
87
|
const SHORT = { h: 'help', v: 'version', y: 'yes', X: 'method', d: 'data', s: 'store' }
|
|
88
88
|
|
|
89
89
|
function parseArgs(argv) {
|
package/lib/commands.mjs
CHANGED
|
@@ -47,21 +47,60 @@ export async function login(ctx) {
|
|
|
47
47
|
}
|
|
48
48
|
if (process.env.SELLWAVY_TOKEN) warn('SELLWAVY_TOKEN is set, so it will be used instead of this login until you unset it.')
|
|
49
49
|
|
|
50
|
+
// A login started with --no-wait and not finished yet carries on with the
|
|
51
|
+
// same key (and so the same code), so "approve, then run login again" works.
|
|
52
|
+
const config = readConfig()
|
|
53
|
+
const pending = config.pending?.host === host && typeof config.pending?.key === 'string' && Date.now() - (config.pending.at ?? 0) < PENDING_MS
|
|
54
|
+
? config.pending
|
|
55
|
+
: null
|
|
56
|
+
|
|
50
57
|
// The key is made here and only its hash goes through the browser, so the
|
|
51
58
|
// key itself never leaves this computer.
|
|
52
|
-
const key = 'sw_' + crypto.randomBytes(32).toString('base64url')
|
|
59
|
+
const key = pending?.key ?? 'sw_' + crypto.randomBytes(32).toString('base64url')
|
|
53
60
|
const hash = crypto.createHash('sha256').update(key).digest('hex')
|
|
54
61
|
const code = `${hash.slice(0, 4)}-${hash.slice(4, 8)}`.toUpperCase()
|
|
55
|
-
const device = String(ctx.flags.name || `CLI on ${os.hostname()}`).slice(0, 60)
|
|
62
|
+
const device = String(ctx.flags.name || pending?.device || `CLI on ${os.hostname()}`).slice(0, 60)
|
|
56
63
|
const url = `${host}/account/cli/authorize?code=${hash}&name=${encodeURIComponent(device)}`
|
|
64
|
+
const api = createApi({ host, token: key })
|
|
65
|
+
|
|
66
|
+
const signedIn = me => {
|
|
67
|
+
const next = { ...readConfig(), host, token: key, email: me.email }
|
|
68
|
+
delete next.pending
|
|
69
|
+
writeConfig(next)
|
|
70
|
+
ok(`Signed in as ${c.bold(me.email)}. ${me.stores.length} store${me.stores.length === 1 ? '' : 's'}.`)
|
|
71
|
+
log(`\nNext: ${c.bold('sellwavy init')} in a folder to link a store and pull its pages.`)
|
|
72
|
+
}
|
|
73
|
+
const check = async () => {
|
|
74
|
+
try {
|
|
75
|
+
return await api.get('/api/cli/me')
|
|
76
|
+
} catch (err) {
|
|
77
|
+
if (!(err instanceof ApiError) || (err.status !== 401 && err.status !== 0)) throw err
|
|
78
|
+
return null
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// Finishing a --no-wait login that was approved meanwhile.
|
|
83
|
+
if (pending && !ctx.flags['no-wait']) {
|
|
84
|
+
const me = await check()
|
|
85
|
+
if (me) return signedIn(me)
|
|
86
|
+
}
|
|
57
87
|
|
|
58
|
-
|
|
88
|
+
if (!pending || ctx.flags['no-wait']) {
|
|
89
|
+
log(`\nTo connect this computer to Sellwavy, approve it in your browser.`)
|
|
90
|
+
}
|
|
59
91
|
log(`Type this code on the page: ${c.bold(code)}`)
|
|
60
92
|
log(`\n ${c.cyan(url)}\n`)
|
|
61
|
-
if (!ctx.flags['no-browser']) openBrowser(url)
|
|
62
|
-
info('Waiting for approval… (Ctrl+C to cancel)')
|
|
93
|
+
if (!pending && !ctx.flags['no-browser']) openBrowser(url)
|
|
63
94
|
|
|
64
|
-
|
|
95
|
+
// --no-wait: print the code and return, for an AI agent that can only read
|
|
96
|
+
// a command's output once it has ended. "sellwavy login" finishes it.
|
|
97
|
+
if (ctx.flags['no-wait']) {
|
|
98
|
+
writeConfig({ ...readConfig(), pending: { host, key, device, at: pending?.at ?? Date.now() } })
|
|
99
|
+
log('When it is approved, run: sellwavy login')
|
|
100
|
+
return
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
info('Waiting for approval… (Ctrl+C to cancel)')
|
|
65
104
|
const deadline = Date.now() + 10 * 60_000
|
|
66
105
|
let me = null
|
|
67
106
|
let offline = 0
|
|
@@ -74,12 +113,17 @@ export async function login(ctx) {
|
|
|
74
113
|
if (err.status === 0 && ++offline > 5) throw err
|
|
75
114
|
}
|
|
76
115
|
}
|
|
77
|
-
if (!me)
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
116
|
+
if (!me) {
|
|
117
|
+
// Kept, so running login again shows this same code rather than a new one.
|
|
118
|
+
writeConfig({ ...readConfig(), pending: { host, key, device, at: pending?.at ?? Date.now() } })
|
|
119
|
+
fail('Timed out waiting for approval. Approve it with the code above, then run sellwavy login again.')
|
|
120
|
+
}
|
|
121
|
+
signedIn(me)
|
|
81
122
|
}
|
|
82
123
|
|
|
124
|
+
/** How long a login started and not finished keeps its code: a day. */
|
|
125
|
+
const PENDING_MS = 24 * 60 * 60_000
|
|
126
|
+
|
|
83
127
|
export async function logout(ctx) {
|
|
84
128
|
const config = readConfig()
|
|
85
129
|
if (!config.token) return info('Not signed in.')
|
|
@@ -218,11 +262,10 @@ export async function sitePull(ctx) {
|
|
|
218
262
|
)
|
|
219
263
|
}
|
|
220
264
|
result = merged.sections
|
|
221
|
-
} else if (unpushed && !remote.sections.length) {
|
|
222
|
-
// Files written before the store had any pages: they are the work.
|
|
223
|
-
result = local
|
|
224
265
|
} else if (unpushed) {
|
|
225
|
-
|
|
266
|
+
// Files this folder never pulled: someone's own project, or the wrong
|
|
267
|
+
// folder. Nothing is rewritten or renamed under them.
|
|
268
|
+
fail(`${path.relative(process.cwd(), dir) || dir}/ already has files that did not come from this store. Use an empty folder, or move them away first.`)
|
|
226
269
|
}
|
|
227
270
|
}
|
|
228
271
|
const d = diffSections(remote.sections, result)
|
|
@@ -237,6 +280,7 @@ export async function sitePull(ctx) {
|
|
|
237
280
|
if (!remote.sections.length) {
|
|
238
281
|
ok(`${store.name} has no AI-built pages yet. ${rel}/ is ready for them.`)
|
|
239
282
|
log(`Write sections in ${rel}/ (see AGENTS.md) and run ${c.bold('sellwavy site push')}, or start with ${c.bold('sellwavy ai "Build my store"')}.`)
|
|
283
|
+
warn('The store shows its standard design until then: the first push (or sellwavy ai) replaces it with these pages on the live store.')
|
|
240
284
|
} else {
|
|
241
285
|
ok(`Pulled ${remote.sections.length} sections into ${rel}/ (${pageCounts(remote.sections)}). ${written.length} file${written.length === 1 ? '' : 's'} updated.`)
|
|
242
286
|
if (keptLocal) info(`Your ${keptLocal} unpushed change${keptLocal === 1 ? ' is' : 's are'} kept on top.`)
|
|
@@ -287,9 +331,16 @@ export async function sitePush(ctx, { quiet = false } = {}) {
|
|
|
287
331
|
}
|
|
288
332
|
|
|
289
333
|
const d = diffSections(remote.sections, next)
|
|
334
|
+
// The store showing its standard design: this push swaps it for the pages
|
|
335
|
+
// here, on every page they cover. Said every time, not only when nothing
|
|
336
|
+
// else changes, as it is the biggest change a push can make.
|
|
337
|
+
const switchesOn = activate && !remote.aiDesign
|
|
290
338
|
if (ctx.flags['dry-run']) {
|
|
291
|
-
if (ctx.flags.json) return json({ ...d, warnings: problems })
|
|
292
|
-
|
|
339
|
+
if (ctx.flags.json) return json({ ...d, switchesOn, warnings: problems })
|
|
340
|
+
printDiff(d, next, 'Would change:')
|
|
341
|
+
if (switchesOn) {
|
|
342
|
+
warn('This push also switches the store to these pages: they replace its current design on the live store. Add --keep-off to save them without showing them.')
|
|
343
|
+
}
|
|
293
344
|
return false
|
|
294
345
|
}
|
|
295
346
|
|
|
@@ -303,6 +354,7 @@ export async function sitePush(ctx, { quiet = false } = {}) {
|
|
|
303
354
|
printDiff(d, saved.sections, quiet ? `${new Date().toLocaleTimeString()} pushed:` : 'Pushed:')
|
|
304
355
|
if (fromStore.length) info(`Kept ${fromStore.length} change${fromStore.length === 1 ? '' : 's'} made on the store since your pull; ${rewritten.length} file${rewritten.length === 1 ? '' : 's'} updated.`)
|
|
305
356
|
if (cleaned.changed.length) warn(`Sellwavy cleaned ${cleaned.changed.map(id => fileOf(saved.sections, id)).join(', ')}: the file now holds what was kept.`)
|
|
357
|
+
if (switchesOn) info('The store now shows these pages in place of its standard design.')
|
|
306
358
|
if (!quiet) {
|
|
307
359
|
ok(`Live at ${c.cyan(store.url)}`)
|
|
308
360
|
log(c.dim(`Edit text, photos and videos in the visual editor: ${store.editorUrl}`))
|
|
@@ -367,6 +419,9 @@ export async function siteWatch(ctx) {
|
|
|
367
419
|
}
|
|
368
420
|
|
|
369
421
|
export async function init(ctx) {
|
|
422
|
+
// init sets up the folder it is run in. A linked folder further up (an
|
|
423
|
+
// earlier init) is left alone rather than relinked and pulled into.
|
|
424
|
+
if (ctx.project && ctx.project.root !== process.cwd()) ctx.project = null
|
|
370
425
|
if (!ctx.project?.storeId || ctx.args[0]) await link(ctx)
|
|
371
426
|
await sitePull(ctx)
|
|
372
427
|
log(`\nReady. Open this folder in Claude Code, Cursor or Codex and ask for changes, or connect the agent directly:`)
|
package/lib/guide.mjs
CHANGED
|
@@ -53,7 +53,15 @@ This folder is linked to a Sellwavy online store${storeUrl ? ` (live at ${storeU
|
|
|
53
53
|
3. \`npx sellwavy-cli site push --dry-run\` shows what would change and warns about code the cleaner removes.
|
|
54
54
|
4. \`npx sellwavy-cli site push\` saves it live. Changes are on the real store immediately.
|
|
55
55
|
|
|
56
|
-
Push
|
|
56
|
+
Push merges changes the owner made in the visual editor since your pull. If the same section changed in both places it refuses: tell the owner which sections, and let them choose. Never use \`--force\` unless the owner asks for it.
|
|
57
|
+
|
|
58
|
+
## Before anything goes live
|
|
59
|
+
|
|
60
|
+
Every change is live at once; there is no draft. So:
|
|
61
|
+
|
|
62
|
+
- Show the owner what \`site push --dry-run\` lists before each push. A line starting with "-" removes a section from the live store (deleting, emptying or renaming a file does that): ask first.
|
|
63
|
+
- If the dry run says the push "also switches the store to these pages", the store is showing its standard design and this push replaces it on every page. Build complete pages first (header, footer and home at least) and get the owner's OK.
|
|
64
|
+
- Ask before deleting anything, changing prices, or marking an order shipped (it emails the customer) or paid.
|
|
57
65
|
|
|
58
66
|
## Files in site/
|
|
59
67
|
|
|
@@ -101,4 +109,4 @@ export const CLAUDE_MD = `@AGENTS.md
|
|
|
101
109
|
`
|
|
102
110
|
|
|
103
111
|
/** Short version for the MCP server's handshake: the full guide is one tool call away. */
|
|
104
|
-
export const MCP_INSTRUCTIONS = `Sellwavy online store tools. Before writing or changing any page section, call sellwavy_guide once: pages are HTML + Tailwind with data-sw-* hooks for live products and cart, and the server removes scripts, forms and fonts. Sections you save go live at once and stay editable in the owner's visual editor. Prices are in the store's currency (19.99), not cents.`
|
|
112
|
+
export const MCP_INSTRUCTIONS = `Sellwavy online store tools. Before writing or changing any page section, call sellwavy_guide once: pages are HTML + Tailwind with data-sw-* hooks for live products and cart, and the server removes scripts, forms and fonts. Sections you save go live at once and stay editable in the owner's visual editor. If get_pages shows aiDesignOn false, the store is on its standard design and your first save replaces it: ask the owner first. Ask before removing sections, changing prices, or shipping orders (that emails the customer). Prices are in the store's currency (19.99), not cents.`
|
package/lib/mcp.mjs
CHANGED
|
@@ -197,7 +197,7 @@ function guideText() {
|
|
|
197
197
|
return [
|
|
198
198
|
'# Building a Sellwavy store',
|
|
199
199
|
`Pages: ${PAGES.map(p => `${p} (${PAGE_NAMES[p]})`).join(', ')}, plus the shared header and footer (page "global", keys "header" and "footer"). Each page is a list of sections; each section is one HTML fragment. Checkout, cart and account pages are Sellwavy’s own.`,
|
|
200
|
-
'Workflow: get_pages to see what is there; save_section for each new or changed section (header and footer first for a new store); upload_media for any photo or video, then use the returned address. Every save is live at once.',
|
|
200
|
+
'Workflow: get_pages to see what is there; save_section for each new or changed section (header and footer first for a new store); upload_media for any photo or video, then use the returned address. Every save is live at once. If get_pages shows aiDesignOn false, the first save switches the store from its standard design to these pages: build header, footer and home first and ask the owner before saving.',
|
|
201
201
|
HOOKS,
|
|
202
202
|
RULES,
|
|
203
203
|
EDITOR,
|
package/lib/site.mjs
CHANGED
|
@@ -16,18 +16,21 @@ import {
|
|
|
16
16
|
export { sectionFiles }
|
|
17
17
|
|
|
18
18
|
/** Every .html file the CLI manages in a site folder. */
|
|
19
|
+
// Only files the CLI itself would write are ever touched: header.html and
|
|
20
|
+
// footer.html at the top, and NN-key.html section files in a page folder.
|
|
21
|
+
// Anything else in site/ (a stray index.html, someone's own project) stays.
|
|
19
22
|
function managedFiles(dir) {
|
|
20
23
|
const found = []
|
|
21
24
|
if (!fs.existsSync(dir)) return found
|
|
22
|
-
for (const
|
|
23
|
-
|
|
24
|
-
if (name.endsWith('.html') && fs.statSync(full).isFile()) found.push(name)
|
|
25
|
+
for (const key of GLOBAL_KEYS) {
|
|
26
|
+
if (fs.existsSync(path.join(dir, `${key}.html`))) found.push(`${key}.html`)
|
|
25
27
|
}
|
|
26
28
|
for (const page of PAGES) {
|
|
27
29
|
const pdir = path.join(dir, page)
|
|
28
30
|
if (!fs.existsSync(pdir)) continue
|
|
29
31
|
for (const name of fs.readdirSync(pdir)) {
|
|
30
|
-
|
|
32
|
+
const key = keyFromFileName(name)
|
|
33
|
+
if (/^\d+-.+\.html$/.test(name) && key && !GLOBAL_KEYS.includes(key)) found.push(`${page}/${name}`)
|
|
31
34
|
}
|
|
32
35
|
}
|
|
33
36
|
return found
|
package/lib/version.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = '0.1.
|
|
1
|
+
export const VERSION = '0.1.1'
|