@40rty/ams-cli 0.3.1 → 0.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/commands/deploy.mjs +62 -17
- package/bin/commands/dev.mjs +10 -11
- package/bin/commands/doctor.mjs +18 -21
- package/bin/commands/domain.mjs +42 -0
- package/bin/commands/hosting.mjs +1 -1
- package/bin/commands/init.mjs +1 -1
- package/bin/commands/publish.mjs +19 -1
- package/bin/forty.mjs +4 -1
- package/bin/lib/agentic.mjs +48 -0
- package/bin/lib/build-copy.mjs +105 -0
- package/bin/lib/build.mjs +47 -19
- package/bin/lib/hosted-build.mjs +74 -19
- package/dist/wire.js +444 -404
- package/package.json +1 -1
- package/templates/package/src/blocks.tsx +3 -3
- package/bin/lib/base-path-build.mjs +0 -149
package/package.json
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {renderInline,
|
|
1
|
+
import {renderInline, useCommerceActions, useProductCard} from '@40rty/ams-sdk';
|
|
2
2
|
import type {Collection, Product} from '@40rty/ams-sdk';
|
|
3
3
|
import type {ReactNode} from 'react';
|
|
4
4
|
|
|
@@ -45,7 +45,7 @@ export function ProductGrid({title, products}: {title?: string; products?: Array
|
|
|
45
45
|
|
|
46
46
|
/** Collection tiles; a tile opens that collection on the canvas. */
|
|
47
47
|
export function CollectionList({title, collections}: {title?: string; collections?: Array<Collection | string>}) {
|
|
48
|
-
const actions =
|
|
48
|
+
const actions = useCommerceActions();
|
|
49
49
|
return (
|
|
50
50
|
<section className={`grid gap-6 py-8 ${GUTTER}`}>
|
|
51
51
|
{title && <h2 className="text-2xl font-semibold">{title}</h2>}
|
|
@@ -65,7 +65,7 @@ export function CollectionList({title, collections}: {title?: string; collection
|
|
|
65
65
|
|
|
66
66
|
/** A full-width banner over one collection's image. */
|
|
67
67
|
export function Hero({heading, byline, collection}: {heading?: string; byline?: string; collection?: Collection | string}) {
|
|
68
|
-
const actions =
|
|
68
|
+
const actions = useCommerceActions();
|
|
69
69
|
const target = typeof collection === 'object' ? collection : undefined;
|
|
70
70
|
return (
|
|
71
71
|
<button type="button" className="relative block aspect-[2/1] w-full overflow-hidden text-left" onClick={() => target && actions?.showCollection(target.title)}>
|
|
@@ -1,149 +0,0 @@
|
|
|
1
|
-
// `forty deploy` builds the app to answer under `/<slug>/` — the path the
|
|
2
|
-
// console serves a 40rty-hosted space at — WITHOUT touching the developer's
|
|
3
|
-
// files. Two settings, both made outside them:
|
|
4
|
-
//
|
|
5
|
-
// basename '/<slug>/' React Router's. The build runs in a COPY whose
|
|
6
|
-
// react-router.config.* wraps the original (Hydrogen's
|
|
7
|
-
// preset refuses a basename; see the wrapper). Routes,
|
|
8
|
-
// <Link>, <Form>/CartForm actions, redirects and lazy
|
|
9
|
-
// route discovery honour it; an optional `($locale)`
|
|
10
|
-
// segment matches after it.
|
|
11
|
-
// asset base '/<slug>/' Every built asset URL. `shopify hydrogen build` sets
|
|
12
|
-
// Vite's `base` itself, over the app's vite.config, from
|
|
13
|
-
// HYDROGEN_ASSET_BASE_URL (how Oxygen points assets at
|
|
14
|
-
// its CDN) — so that is what is set (`ASSET_BASE_ENV`).
|
|
15
|
-
//
|
|
16
|
-
// A URL the app spells out itself — `<a href="/cart">`, `src="/logo.svg"` —
|
|
17
|
-
// knows nothing of the base; `forty doctor` lists them.
|
|
18
|
-
import { access, cp, mkdir, readdir, readFile, realpath, rename, rm, symlink, writeFile } from 'node:fs/promises';
|
|
19
|
-
import path from 'node:path';
|
|
20
|
-
|
|
21
|
-
/** Inside `dist/`, which a Hydrogen app already ignores. */
|
|
22
|
-
export const BUILD_COPY_DIR = path.join('dist', 'forty-build');
|
|
23
|
-
|
|
24
|
-
const EXTENSIONS = ['ts', 'mts', 'js', 'mjs'];
|
|
25
|
-
/** What the copy leaves behind: dependencies are linked, outputs and VCS state are not the app. */
|
|
26
|
-
const NOT_COPIED = new Set(['node_modules', 'dist', '.git', '.vercel', '.cache', '.turbo']);
|
|
27
|
-
|
|
28
|
-
async function exists(file) {
|
|
29
|
-
try {
|
|
30
|
-
await access(file);
|
|
31
|
-
return true;
|
|
32
|
-
} catch (err) {
|
|
33
|
-
if (err.code === 'ENOENT') return false;
|
|
34
|
-
throw err;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/** Caches a tool writes inside `node_modules`: the copy keeps its own, never the app's. */
|
|
39
|
-
const OWN_CACHES = new Set(['.vite', '.cache']);
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* `to` as a directory of links to what `from` holds, each to its REAL path.
|
|
43
|
-
* Not one link to `from` itself: a pnpm app's packages are relative links
|
|
44
|
-
* (`../../node_modules/.pnpm/…`), and a tool that joins them onto the path it
|
|
45
|
-
* came through — Tailwind's resolver does — lands outside the store from a
|
|
46
|
-
* directory at another depth.
|
|
47
|
-
*/
|
|
48
|
-
async function linkDependencies(from, to) {
|
|
49
|
-
await mkdir(to, { recursive: true });
|
|
50
|
-
for (const entry of await readdir(from)) {
|
|
51
|
-
if (OWN_CACHES.has(entry)) continue;
|
|
52
|
-
const source = path.join(from, entry);
|
|
53
|
-
if (entry.startsWith('@')) await linkDependencies(source, path.join(to, entry));
|
|
54
|
-
else await symlink(await realpath(source), path.join(to, entry));
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/** `react-router.config.ts` → `react-router.config.forty-original.ts` */
|
|
59
|
-
function originalName(file) {
|
|
60
|
-
const ext = path.extname(file);
|
|
61
|
-
return `${path.basename(file, ext)}.forty-original${ext}`;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* The React Router config that wraps `original` (a file name beside it), or a
|
|
66
|
-
* fresh one when the app has none.
|
|
67
|
-
*
|
|
68
|
-
* Hydrogen's preset refuses any basename outright ("use a reverse proxy or CDN
|
|
69
|
-
* path rewriting") because ITS dev and preview servers serve from `/`. The
|
|
70
|
-
* console is that reverse proxy, and the build runs nowhere else, so the
|
|
71
|
-
* preset's own checks still run — on the config as it reads without a
|
|
72
|
-
* basename.
|
|
73
|
-
*/
|
|
74
|
-
export function routerConfigWrapper(basename, original) {
|
|
75
|
-
if (original === null) return `export default { basename: ${JSON.stringify(basename)} };\n`;
|
|
76
|
-
return `import config from './${original}';
|
|
77
|
-
const unbased = (preset) => typeof preset.reactRouterConfigResolved !== 'function' ? preset : {
|
|
78
|
-
...preset,
|
|
79
|
-
reactRouterConfigResolved: (args) => preset.reactRouterConfigResolved({ ...args, reactRouterConfig: { ...args.reactRouterConfig, basename: '/' } }),
|
|
80
|
-
};
|
|
81
|
-
export default { ...config, presets: (Array.isArray(config.presets) ? config.presets : []).map(unbased), basename: ${JSON.stringify(basename)} };
|
|
82
|
-
`;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
/** The environment `shopify hydrogen build` takes the asset base from. */
|
|
86
|
-
export const ASSET_BASE_ENV = 'HYDROGEN_ASSET_BASE_URL';
|
|
87
|
-
|
|
88
|
-
/** The first `<stem>.<ext>` present in `dir`, or `null`. */
|
|
89
|
-
async function find(dir, stem) {
|
|
90
|
-
for (const ext of EXTENSIONS) {
|
|
91
|
-
const file = `${stem}.${ext}`;
|
|
92
|
-
if (await exists(path.join(dir, file))) return file;
|
|
93
|
-
}
|
|
94
|
-
return null;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* A copy of the app at `cwd`, configured to answer under `/<slug>/`. Returns
|
|
99
|
-
* the copy's directory; build it there. Its `node_modules` links to the app's
|
|
100
|
-
* own packages, so nothing is installed twice.
|
|
101
|
-
*/
|
|
102
|
-
export async function prepareBasePathBuild(cwd, slug) {
|
|
103
|
-
const base = `/${slug}/`;
|
|
104
|
-
const dir = path.join(cwd, BUILD_COPY_DIR);
|
|
105
|
-
await rm(dir, { recursive: true, force: true });
|
|
106
|
-
await mkdir(dir, { recursive: true });
|
|
107
|
-
for (const entry of await readdir(cwd)) {
|
|
108
|
-
if (NOT_COPIED.has(entry)) continue;
|
|
109
|
-
await cp(path.join(cwd, entry), path.join(dir, entry), { recursive: true, filter: (src) => !path.relative(cwd, src).split(path.sep).includes('node_modules') });
|
|
110
|
-
}
|
|
111
|
-
if (await exists(path.join(cwd, 'node_modules'))) await linkDependencies(path.join(cwd, 'node_modules'), path.join(dir, 'node_modules'));
|
|
112
|
-
|
|
113
|
-
const router = await find(dir, 'react-router.config');
|
|
114
|
-
if (router === null) {
|
|
115
|
-
await writeFile(path.join(dir, 'react-router.config.ts'), routerConfigWrapper(base, null));
|
|
116
|
-
} else {
|
|
117
|
-
await rename(path.join(dir, router), path.join(dir, originalName(router)));
|
|
118
|
-
await writeFile(path.join(dir, router), routerConfigWrapper(base, originalName(router)));
|
|
119
|
-
}
|
|
120
|
-
return dir;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
/**
|
|
124
|
-
* Root-absolute URLs written into the app's markup — `href="/…"`, `src="/…"`,
|
|
125
|
-
* `action="/…"`, and `href: '/…'` in a `links()` export — as `file:line`. Under `/<slug>/` each points outside the
|
|
126
|
-
* store. `<Link to>` and `<Form action>` through React Router are fine; a
|
|
127
|
-
* plain attribute is not.
|
|
128
|
-
*/
|
|
129
|
-
export async function findRootAbsoluteUrls(cwd, appDir = 'app') {
|
|
130
|
-
const found = [];
|
|
131
|
-
const pattern = /\b(href|src|action)\s*(=\s*\{?|:\s*)["'`]\/(?!\/)/g;
|
|
132
|
-
let entries;
|
|
133
|
-
try {
|
|
134
|
-
entries = await readdir(path.join(cwd, appDir), { recursive: true, withFileTypes: true });
|
|
135
|
-
} catch (err) {
|
|
136
|
-
if (err.code === 'ENOENT') return found;
|
|
137
|
-
throw err;
|
|
138
|
-
}
|
|
139
|
-
for (const entry of entries) {
|
|
140
|
-
if (!entry.isFile() || !/\.(tsx|jsx)$/.test(entry.name)) continue;
|
|
141
|
-
const abs = path.join(entry.parentPath, entry.name);
|
|
142
|
-
const lines = (await readFile(abs, 'utf8')).split('\n');
|
|
143
|
-
lines.forEach((line, i) => {
|
|
144
|
-
if (pattern.test(line)) found.push(`${path.relative(cwd, abs)}:${i + 1}`);
|
|
145
|
-
pattern.lastIndex = 0;
|
|
146
|
-
});
|
|
147
|
-
}
|
|
148
|
-
return found;
|
|
149
|
-
}
|