@40rty/ams-cli 0.3.2 → 0.4.3
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 +9 -10
- package/bin/commands/dev.mjs +10 -11
- package/bin/commands/doctor.mjs +4 -5
- package/bin/commands/hosting.mjs +1 -1
- package/bin/lib/agentic.mjs +1 -1
- package/bin/lib/build-copy.mjs +6 -81
- package/bin/lib/build.mjs +47 -19
- package/bin/lib/hosted-build.mjs +7 -9
- package/dist/wire.js +433 -405
- package/package.json +1 -1
- package/templates/package/src/blocks.tsx +3 -3
package/bin/commands/deploy.mjs
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
// `forty deploy` — host this app on AMS, now, whatever its own production
|
|
2
|
-
// target is: a Hydrogen app or a Next.js app.
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
// `basePath`). It builds in a temporary copy (`lib/build-copy.mjs`) with
|
|
2
|
+
// target is: a Hydrogen app or a Next.js app. A hosted space has a site of its
|
|
3
|
+
// own, `<space>.40rty.app`, and the app answers there from `/` exactly as it
|
|
4
|
+
// builds. It builds in a temporary copy (`lib/build-copy.mjs`) with
|
|
6
5
|
// FORTY_AGENTIC=1, as Vercel Build Output, uploads only what the platform has not got, and
|
|
7
6
|
// prints the space's address. Run it again to ship a new build; `forty
|
|
8
7
|
// hosting self` hands the space back to the app's own deployment.
|
|
@@ -13,7 +12,7 @@
|
|
|
13
12
|
//
|
|
14
13
|
// ── The agentic build contract ──────────────────────────────────────────────
|
|
15
14
|
// The agentic webpage is the app itself, built with FORTY_AGENTIC=1: the app's
|
|
16
|
-
// `/` (hosted: `<
|
|
15
|
+
// `/` (hosted: `<space>.40rty.app/`) is the agentic page; every other route (products, collections, cart) is the
|
|
17
16
|
// app's own, so links and the cart keep working. Without the flag the app
|
|
18
17
|
// builds exactly as before. `forty doctor` checks the wiring
|
|
19
18
|
// (`lib/agentic.mjs`).
|
|
@@ -77,13 +76,13 @@ export async function deploy() {
|
|
|
77
76
|
const dotenv = await readDotenv(path.join(cwd, '.env'));
|
|
78
77
|
const { env, withheld } = framework === 'hydrogen' ? pickDeployEnv(dotenv, optIns(args)) : pickDeployEnv(dotenv, optIns(args), []);
|
|
79
78
|
|
|
80
|
-
const buildDir = await prepareBuildCopy(cwd, framework
|
|
81
|
-
console.log(
|
|
79
|
+
const buildDir = await prepareBuildCopy(cwd, framework);
|
|
80
|
+
console.log('building with FORTY_AGENTIC=1 (in a temporary copy; your files are untouched)');
|
|
82
81
|
let files;
|
|
83
82
|
try {
|
|
84
83
|
if (framework === 'hydrogen') {
|
|
85
|
-
buildHydrogen(buildDir
|
|
86
|
-
files = await listOutputFiles(await assembleBuildOutput(cwd, buildDir
|
|
84
|
+
buildHydrogen(buildDir);
|
|
85
|
+
files = await listOutputFiles(await assembleBuildOutput(cwd, buildDir));
|
|
87
86
|
} else {
|
|
88
87
|
files = await listOutputFiles(await buildNext(cwd, buildDir));
|
|
89
88
|
}
|
|
@@ -95,7 +94,7 @@ export async function deploy() {
|
|
|
95
94
|
await rm(buildDir, { recursive: true, force: true });
|
|
96
95
|
}
|
|
97
96
|
const route = `/org/spaces/${encodeURIComponent(config.spaceSlug)}/deployments`;
|
|
98
|
-
const body = { files: files.map(({ file, sha, size }) => ({ file, sha, size })), basePath:
|
|
97
|
+
const body = { files: files.map(({ file, sha, size }) => ({ file, sha, size })), basePath: '/', env };
|
|
99
98
|
|
|
100
99
|
let res = await request(config.apiUrl, 'POST', route, body);
|
|
101
100
|
if (res.status === 409 && Array.isArray(res.body.missing)) {
|
package/bin/commands/dev.mjs
CHANGED
|
@@ -12,20 +12,13 @@
|
|
|
12
12
|
// into its `.env`.
|
|
13
13
|
import { watch } from 'node:fs';
|
|
14
14
|
import path from 'node:path';
|
|
15
|
-
import { cwd,
|
|
16
|
-
import { call
|
|
15
|
+
import { cwd, fail, readConfig, readConfigIfPresent, writeDotenv } from '../lib/context.mjs';
|
|
16
|
+
import { call } from '../lib/credentials.mjs';
|
|
17
17
|
import { init } from './init.mjs';
|
|
18
18
|
import { buildRelease } from './publish.mjs';
|
|
19
19
|
|
|
20
20
|
const SETTLE_MS = 150;
|
|
21
21
|
|
|
22
|
-
/** The console of the deployment this space lives on: `FORTY_CONSOLE_URL`, else the one the api names. */
|
|
23
|
-
async function previewConsole(config) {
|
|
24
|
-
if (process.env.FORTY_CONSOLE_URL) return deployment(config).consoleUrl;
|
|
25
|
-
const me = await request(config.apiUrl, 'GET', '/org/me');
|
|
26
|
-
return me.ok && typeof me.body.consoleUrl === 'string' ? me.body.consoleUrl : deployment(config).consoleUrl;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
22
|
export async function dev() {
|
|
30
23
|
if ((await readConfigIfPresent()) === null) await init();
|
|
31
24
|
const config = await readConfig();
|
|
@@ -40,6 +33,8 @@ export async function dev() {
|
|
|
40
33
|
|
|
41
34
|
// The preview credential, from the first draft that lands. It outlives every later save.
|
|
42
35
|
let token;
|
|
36
|
+
// Where the draft opens: the space's own site, carrying the token.
|
|
37
|
+
let previewUrl;
|
|
43
38
|
let running = false;
|
|
44
39
|
let again = false;
|
|
45
40
|
async function save() {
|
|
@@ -52,7 +47,10 @@ export async function dev() {
|
|
|
52
47
|
try {
|
|
53
48
|
const result = await call(config.apiUrl, 'PUT', `/org/spaces/${config.spaceSlug}/draft`, await buildRelease(config));
|
|
54
49
|
console.log(`${new Date().toLocaleTimeString()} ${result.types.length} types → preview of ${config.spaceSlug} (${Date.now() - started} ms)`);
|
|
55
|
-
if (token === undefined)
|
|
50
|
+
if (token === undefined) {
|
|
51
|
+
token = result.token;
|
|
52
|
+
previewUrl = result.previewUrl;
|
|
53
|
+
}
|
|
56
54
|
} catch (err) {
|
|
57
55
|
// A save that does not build is the normal case here: report it and keep watching.
|
|
58
56
|
console.error(`forty: ${err.message}`);
|
|
@@ -72,7 +70,8 @@ export async function dev() {
|
|
|
72
70
|
await writeDotenv('FORTY_DEV_TOKEN', token);
|
|
73
71
|
console.log('\n wrote FORTY_DEV_TOKEN to .env — your app previews the draft. Keep it out of version control.\n');
|
|
74
72
|
} else {
|
|
75
|
-
|
|
73
|
+
if (typeof previewUrl !== 'string') fail('the platform did not say where the draft opens — update the platform (its API answers `previewUrl`)');
|
|
74
|
+
console.log(`\n ${previewUrl}\n`);
|
|
76
75
|
}
|
|
77
76
|
// `--once`: store the draft and stop — for a script, or an agent, that cannot hold a watcher open.
|
|
78
77
|
if (process.argv.includes('--once')) return;
|
package/bin/commands/doctor.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// `forty doctor [dev-server-url] [--ask "<question>" | --no-ask]` — the integration's definition of done.
|
|
2
2
|
// When 40rty hosts the app (`forty deploy`), the space's own address is
|
|
3
|
-
// checked too:
|
|
3
|
+
// checked too: its own site, `https://<space>.40rty.app<route>`.
|
|
4
4
|
//
|
|
5
5
|
// Every check names what is wrong in the repo's own terms. Exits non-zero when
|
|
6
6
|
// any fail, so it is the same gate in CI as on a laptop.
|
|
@@ -127,7 +127,6 @@ export async function doctor() {
|
|
|
127
127
|
}
|
|
128
128
|
|
|
129
129
|
// ── The platform ──
|
|
130
|
-
let consoleUrl;
|
|
131
130
|
let hostedAt;
|
|
132
131
|
const credential = await findCredential(config.apiUrl);
|
|
133
132
|
check(credential !== null, 'signed in', 'run `forty login`, or set FORTY_API_KEY in CI');
|
|
@@ -135,7 +134,6 @@ export async function doctor() {
|
|
|
135
134
|
const me = await request(config.apiUrl, 'GET', '/org/me');
|
|
136
135
|
check(me.ok, `the credential from ${credential.source} is accepted by ${config.apiUrl}`);
|
|
137
136
|
const space = me.ok ? me.body.spaces.find((candidate) => candidate.slug === config.spaceSlug) : undefined;
|
|
138
|
-
if (me.ok) consoleUrl = me.body.consoleUrl;
|
|
139
137
|
if (space !== undefined && typeof space.hostedAppOrigin === 'string') hostedAt = space.hostedAppOrigin;
|
|
140
138
|
check(space !== undefined, `space "${config.spaceSlug}" belongs to this organization`);
|
|
141
139
|
if (space !== undefined) {
|
|
@@ -191,8 +189,9 @@ export async function doctor() {
|
|
|
191
189
|
|
|
192
190
|
// ── AMS hosts it (`forty deploy`) ──
|
|
193
191
|
if (hostedAt !== undefined) {
|
|
194
|
-
|
|
195
|
-
|
|
192
|
+
const site = `https://${config.spaceSlug}.40rty.app/`;
|
|
193
|
+
console.log(`- AMS hosts this app (${hostedAt}), served at ${site} — \`forty hosting self\` hands it back`);
|
|
194
|
+
await routeChecks(check, config, site);
|
|
196
195
|
}
|
|
197
196
|
}
|
|
198
197
|
|
package/bin/commands/hosting.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// `forty hosting self` — the space's spacefront is the app's OWN deployment
|
|
2
2
|
// again (Oxygen, Vercel, …), not the one `forty deploy` put on 40rty. The
|
|
3
|
-
// console stops serving `<
|
|
3
|
+
// console stops serving `<space>.40rty.app` from 40rty's copy; the copy and
|
|
4
4
|
// its origin stay, so `forty deploy` switches back in one step.
|
|
5
5
|
import { fail, positionals, readConfig } from '../lib/context.mjs';
|
|
6
6
|
import { call } from '../lib/credentials.mjs';
|
package/bin/lib/agentic.mjs
CHANGED
package/bin/lib/build-copy.mjs
CHANGED
|
@@ -1,21 +1,11 @@
|
|
|
1
1
|
// `forty deploy` builds the app in a COPY — never in the developer's tree, whose
|
|
2
2
|
// `dist/` / `.next/` and config stay theirs. The copy is built with
|
|
3
|
-
// `FORTY_AGENTIC=1` (see `deploy.mjs` for the contract that flag switches)
|
|
4
|
-
//
|
|
5
|
-
//
|
|
6
|
-
//
|
|
7
|
-
// Hydrogen React Router's `basename` (the copy's react-router.config.*
|
|
8
|
-
// wraps the original; Hydrogen's preset refuses a basename, see
|
|
9
|
-
// the wrapper), and every built asset URL through
|
|
10
|
-
// HYDROGEN_ASSET_BASE_URL (`ASSET_BASE_ENV`), which `shopify
|
|
11
|
-
// hydrogen build` sets Vite's `base` from.
|
|
12
|
-
// Next.js `basePath` (the copy's next.config wraps the original).
|
|
13
|
-
//
|
|
14
|
-
// A URL the app spells out itself — `<a href="/cart">` — knows nothing of the
|
|
15
|
-
// base; the console follows it back under `/<slug>/` (a same-site Referer redirect).
|
|
3
|
+
// `FORTY_AGENTIC=1` (see `deploy.mjs` for the contract that flag switches),
|
|
4
|
+
// exactly as the app builds itself: a hosted app has its own site
|
|
5
|
+
// (`<slug>.40rty.app`) and answers from `/`, so nothing in its config moves.
|
|
16
6
|
import { spawnSync } from 'node:child_process';
|
|
17
7
|
import { constants } from 'node:fs';
|
|
18
|
-
import { access, cp, mkdir, readdir, readFile, realpath,
|
|
8
|
+
import { access, cp, mkdir, readdir, readFile, realpath, rm, symlink, writeFile } from 'node:fs/promises';
|
|
19
9
|
import path from 'node:path';
|
|
20
10
|
|
|
21
11
|
/** Where each framework's copy lives: inside the output folder the app already ignores. */
|
|
@@ -55,8 +45,7 @@ async function linkDependencies(from, to) {
|
|
|
55
45
|
}
|
|
56
46
|
|
|
57
47
|
/**
|
|
58
|
-
* A copy of the app at `cwd` to build `framework` in
|
|
59
|
-
* `/<slug>/`; returns its directory.
|
|
48
|
+
* A copy of the app at `cwd` to build `framework` in; returns its directory.
|
|
60
49
|
* A Hydrogen copy links the app's packages (nothing installed twice). A
|
|
61
50
|
* Next.js copy needs them inside it — Turbopack refuses a link out of the
|
|
62
51
|
* project root — and flat for its functions (`hoistedPnpmInstall`); an npm or
|
|
@@ -64,7 +53,7 @@ async function linkDependencies(from, to) {
|
|
|
64
53
|
* `.env*`: a build may prerender a page that reads `FORTY_DEV_TOKEN`, and the
|
|
65
54
|
* site is the space's published face, never a developer's preview.
|
|
66
55
|
*/
|
|
67
|
-
export async function prepareBuildCopy(cwd, framework
|
|
56
|
+
export async function prepareBuildCopy(cwd, framework) {
|
|
68
57
|
const dir = path.join(cwd, BUILD_COPY_DIR[framework]);
|
|
69
58
|
await rm(dir, { recursive: true, force: true });
|
|
70
59
|
await mkdir(dir, { recursive: true });
|
|
@@ -83,13 +72,9 @@ export async function prepareBuildCopy(cwd, framework, slug) {
|
|
|
83
72
|
const kept = (await readFile(file, 'utf8')).split('\n').filter((line) => !/^\s*(export\s+)?FORTY_/.test(line));
|
|
84
73
|
await writeFile(file, kept.join('\n'));
|
|
85
74
|
}
|
|
86
|
-
if (framework === 'hydrogen') await wrapConfig(dir, 'react-router.config', routerConfigWrapper(`/${slug}/`, null), (original) => routerConfigWrapper(`/${slug}/`, original));
|
|
87
|
-
else await wrapConfig(dir, 'next.config', nextConfigWrapper(`/${slug}`, null), (original) => nextConfigWrapper(`/${slug}`, original), 'mjs');
|
|
88
75
|
return dir;
|
|
89
76
|
}
|
|
90
77
|
|
|
91
|
-
const EXTENSIONS = ['ts', 'mts', 'js', 'mjs'];
|
|
92
|
-
|
|
93
78
|
/**
|
|
94
79
|
* A pnpm app's packages are links into `.pnpm/`. A Vercel function ships files,
|
|
95
80
|
* not links, and Node resolves a package's own dependencies through those
|
|
@@ -118,63 +103,3 @@ async function hoistedPnpmInstall(modules, dir) {
|
|
|
118
103
|
if (run.error !== undefined || run.status !== 0) throw new Error(`could not lay out a flat node_modules for the build (\`pnpm install --offline\`, nodeLinker hoisted, in ${dir})`);
|
|
119
104
|
return true;
|
|
120
105
|
}
|
|
121
|
-
|
|
122
|
-
/** In `dir`: the config `<stem>.*` renamed aside and wrapped by `wrapper(originalName)`, or `fresh` written when there is none. */
|
|
123
|
-
async function wrapConfig(dir, stem, fresh, wrapper, freshExt = 'ts') {
|
|
124
|
-
for (const ext of EXTENSIONS) {
|
|
125
|
-
const file = `${stem}.${ext}`;
|
|
126
|
-
if (!(await exists(path.join(dir, file)))) continue;
|
|
127
|
-
const original = `${stem}.forty-original.${ext}`;
|
|
128
|
-
await rename(path.join(dir, file), path.join(dir, original));
|
|
129
|
-
await writeFile(path.join(dir, file), wrapper(original));
|
|
130
|
-
return;
|
|
131
|
-
}
|
|
132
|
-
await writeFile(path.join(dir, `${stem}.${freshExt}`), fresh);
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
/**
|
|
136
|
-
* The React Router config that wraps `original` (a file name beside it), or a
|
|
137
|
-
* fresh one when it is `null`.
|
|
138
|
-
*
|
|
139
|
-
* Hydrogen's preset refuses any basename outright ("use a reverse proxy or CDN
|
|
140
|
-
* path rewriting") because ITS dev and preview servers serve from `/`. The
|
|
141
|
-
* console is that reverse proxy, and the build runs nowhere else, so the
|
|
142
|
-
* preset's own checks still run — on the config as it reads without a
|
|
143
|
-
* basename.
|
|
144
|
-
*/
|
|
145
|
-
export function routerConfigWrapper(basename, original) {
|
|
146
|
-
if (original === null) return `export default { basename: ${JSON.stringify(basename)} };\n`;
|
|
147
|
-
return `import config from './${original}';
|
|
148
|
-
const unbased = (preset) => typeof preset.reactRouterConfigResolved !== 'function' ? preset : {
|
|
149
|
-
...preset,
|
|
150
|
-
reactRouterConfigResolved: (args) => preset.reactRouterConfigResolved({ ...args, reactRouterConfig: { ...args.reactRouterConfig, basename: '/' } }),
|
|
151
|
-
};
|
|
152
|
-
export default { ...config, presets: (Array.isArray(config.presets) ? config.presets : []).map(unbased), basename: ${JSON.stringify(basename)} };
|
|
153
|
-
`;
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
/** The environment `shopify hydrogen build` takes the asset base from. */
|
|
157
|
-
export const ASSET_BASE_ENV = 'HYDROGEN_ASSET_BASE_URL';
|
|
158
|
-
|
|
159
|
-
/**
|
|
160
|
-
* The next.config that wraps `original` (a file name beside it, or `null`) with
|
|
161
|
-
* `basePath`. A config may be an object or a function of the build phase.
|
|
162
|
-
*
|
|
163
|
-
* `skipTrailingSlashRedirect`: the console serves a hosted space's subtree at
|
|
164
|
-
* `/<slug>/…` and sends the bare `/<slug>` there; Next's own `/<slug>/` →
|
|
165
|
-
* `/<slug>` redirect would loop against it.
|
|
166
|
-
*/
|
|
167
|
-
export function nextConfigWrapper(basePath, original) {
|
|
168
|
-
const forty = `basePath: ${JSON.stringify(basePath)}, skipTrailingSlashRedirect: true`;
|
|
169
|
-
if (original === null) return `export default { ${forty} };\n`;
|
|
170
|
-
// A TypeScript config is imported without its extension (the app's own
|
|
171
|
-
// tsconfig may refuse `.ts` imports); the wrapper is not the app's code to check.
|
|
172
|
-
const from = original.replace(/\.m?ts$/, '');
|
|
173
|
-
return `// @ts-nocheck
|
|
174
|
-
import config from './${from}';
|
|
175
|
-
export default async function fortyConfig(...args) {
|
|
176
|
-
const resolved = typeof config === 'function' ? await config(...args) : config;
|
|
177
|
-
return { ...resolved, ${forty} };
|
|
178
|
-
}
|
|
179
|
-
`;
|
|
180
|
-
}
|
package/bin/lib/build.mjs
CHANGED
|
@@ -107,7 +107,9 @@ const sharedModulesPlugin = {
|
|
|
107
107
|
* from a PACKAGE (`@40rty/ams-ui/island.css`) is still bundled and appended:
|
|
108
108
|
* the named sheet is a Tailwind build, whose `@import` cannot resolve a
|
|
109
109
|
* package's `exports`. Their own relative CSS is the named sheet's to carry.
|
|
110
|
-
*
|
|
110
|
+
* A font or image the stylesheet points at by a local path ships with it, as
|
|
111
|
+
* `assets/<content hash>.<ext>` beside the stylesheet (`assets`, base64); a
|
|
112
|
+
* remote one stays where its `url()` points.
|
|
111
113
|
*/
|
|
112
114
|
export async function buildBundle(bundle) {
|
|
113
115
|
if (typeof bundle.entry !== 'string') fail('forty.config.json "bundle" needs an "entry"');
|
|
@@ -122,7 +124,8 @@ export async function buildBundle(bundle) {
|
|
|
122
124
|
minify: true,
|
|
123
125
|
jsx: 'automatic',
|
|
124
126
|
define: { 'process.env.NODE_ENV': '"production"' },
|
|
125
|
-
loader: { '.css': 'css' },
|
|
127
|
+
loader: { '.css': 'css', ...ASSET_LOADERS },
|
|
128
|
+
assetNames: ASSET_NAMES,
|
|
126
129
|
external: CSS_EXTERNAL,
|
|
127
130
|
plugins: typeof bundle.css === 'string' ? [ownCssIsNamedPlugin, sharedModulesPlugin] : [sharedModulesPlugin],
|
|
128
131
|
logLevel: 'error',
|
|
@@ -133,26 +136,51 @@ export async function buildBundle(bundle) {
|
|
|
133
136
|
const utilities = typeof bundle.tailwind === 'string' ? await compileTailwind(bundle.tailwind) : '';
|
|
134
137
|
const importedSheet = result.outputFiles.find((file) => file.path.endsWith('.css'));
|
|
135
138
|
const imported = importedSheet === undefined ? '' : importedSheet.text;
|
|
136
|
-
|
|
137
|
-
let css;
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
139
|
+
const outputs = [...result.outputFiles];
|
|
140
|
+
let css = '';
|
|
141
|
+
if (typeof bundle.css === 'string') {
|
|
142
|
+
try {
|
|
143
|
+
const sheet = await build({
|
|
144
|
+
entryPoints: [path.resolve(cwd, bundle.css)],
|
|
145
|
+
bundle: true,
|
|
146
|
+
write: false,
|
|
147
|
+
minify: true,
|
|
148
|
+
outdir: path.join(cwd, 'node_modules', '.forty', 'bundle'),
|
|
149
|
+
loader: ASSET_LOADERS,
|
|
150
|
+
assetNames: ASSET_NAMES,
|
|
151
|
+
external: CSS_EXTERNAL,
|
|
152
|
+
logLevel: 'error',
|
|
153
|
+
});
|
|
154
|
+
const built = sheet.outputFiles.find((file) => file.path.endsWith('.css'));
|
|
155
|
+
if (built === undefined) fail(`${bundle.css} produced no stylesheet`);
|
|
156
|
+
css = built.text;
|
|
157
|
+
outputs.push(...sheet.outputFiles);
|
|
158
|
+
} catch (err) {
|
|
159
|
+
fail(`cannot build the stylesheet ${bundle.css} — ${err.message}`);
|
|
160
|
+
}
|
|
150
161
|
}
|
|
151
|
-
|
|
162
|
+
const out = { js: js.text, css: css + imported + utilities };
|
|
163
|
+
const assets = bundleAssets(outputs);
|
|
164
|
+
if (Object.keys(assets).length > 0) out.assets = assets;
|
|
165
|
+
return out;
|
|
152
166
|
}
|
|
153
167
|
|
|
154
|
-
/** What a stylesheet points at rather than carries. */
|
|
155
|
-
const CSS_EXTERNAL = ['http://*', 'https://*', 'data:*'
|
|
168
|
+
/** What a stylesheet points at rather than carries: only what is already somewhere else. */
|
|
169
|
+
const CSS_EXTERNAL = ['http://*', 'https://*', 'data:*'];
|
|
170
|
+
|
|
171
|
+
/** What a stylesheet carries as a file of its own, under `assets/` beside it. */
|
|
172
|
+
const ASSET_LOADERS = Object.fromEntries(['.woff', '.woff2', '.ttf', '.otf', '.png', '.jpg', '.jpeg', '.svg', '.gif', '.webp'].map((ext) => [ext, 'file']));
|
|
173
|
+
const ASSET_NAMES = 'assets/[hash]';
|
|
174
|
+
|
|
175
|
+
/** The built asset files, base64, by their path beside the stylesheet. */
|
|
176
|
+
function bundleAssets(outputs) {
|
|
177
|
+
const assets = {};
|
|
178
|
+
for (const file of outputs) {
|
|
179
|
+
const rel = path.relative(path.join(cwd, 'node_modules', '.forty', 'bundle'), file.path).split(path.sep).join('/');
|
|
180
|
+
if (rel.startsWith('assets/')) assets[rel] = Buffer.from(file.contents).toString('base64');
|
|
181
|
+
}
|
|
182
|
+
return assets;
|
|
183
|
+
}
|
|
156
184
|
|
|
157
185
|
export async function loadManifests(dir) {
|
|
158
186
|
const root = path.resolve(cwd, dir);
|
package/bin/lib/hosted-build.mjs
CHANGED
|
@@ -8,7 +8,6 @@ import { cp, mkdir, readdir, readFile, rename, rm, writeFile } from 'node:fs/pro
|
|
|
8
8
|
import path from 'node:path';
|
|
9
9
|
import { fail } from './context.mjs';
|
|
10
10
|
import { findCredential } from './credentials.mjs';
|
|
11
|
-
import { ASSET_BASE_ENV } from './build-copy.mjs';
|
|
12
11
|
|
|
13
12
|
/** Inside `dist/`, which a Hydrogen app already ignores — never the developer's own `.vercel/`. */
|
|
14
13
|
const OUTPUT_DIR = path.join('dist', 'forty-output');
|
|
@@ -29,9 +28,9 @@ export default function handler(request, context) {
|
|
|
29
28
|
/** The build env that makes `/` the agentic webpage (the contract in `deploy.mjs`). */
|
|
30
29
|
const AGENTIC = { FORTY_AGENTIC: '1' };
|
|
31
30
|
|
|
32
|
-
/** `shopify hydrogen build` in `cwd` (the app's build copy), agentic,
|
|
33
|
-
export function buildHydrogen(cwd
|
|
34
|
-
const env = { ...process.env, ...AGENTIC
|
|
31
|
+
/** `shopify hydrogen build` in `cwd` (the app's build copy), agentic, with its output on the terminal. */
|
|
32
|
+
export function buildHydrogen(cwd) {
|
|
33
|
+
const env = { ...process.env, ...AGENTIC };
|
|
35
34
|
const run = spawnSync('npx', ['--no-install', 'shopify', 'hydrogen', 'build', '--no-lockfile-check'], { cwd, stdio: 'inherit', env });
|
|
36
35
|
if (run.error !== undefined) fail(`could not run \`shopify hydrogen build\` (${run.error.message})`);
|
|
37
36
|
if (run.status !== 0) fail('`shopify hydrogen build` failed — fix the build, then run `forty deploy` again');
|
|
@@ -86,16 +85,15 @@ const DEPLOYED_OUTPUT = '.vercel/output';
|
|
|
86
85
|
|
|
87
86
|
/**
|
|
88
87
|
* Lay a build's `dist/client` + `dist/server` out as a Build Output under
|
|
89
|
-
* `cwd`'s OUTPUT_DIR
|
|
90
|
-
*
|
|
91
|
-
* function every other path falls through to.
|
|
88
|
+
* `cwd`'s OUTPUT_DIR: its client files served as they are (`static/assets/…`),
|
|
89
|
+
* the worker the one function every other path falls through to.
|
|
92
90
|
*/
|
|
93
|
-
export async function assembleBuildOutput(cwd, buildDir
|
|
91
|
+
export async function assembleBuildOutput(cwd, buildDir) {
|
|
94
92
|
const out = path.join(cwd, OUTPUT_DIR);
|
|
95
93
|
const func = path.join(out, 'functions', 'index.func');
|
|
96
94
|
await rm(out, { recursive: true, force: true });
|
|
97
95
|
await mkdir(func, { recursive: true });
|
|
98
|
-
await cp(path.join(buildDir, 'dist', 'client'), path.join(out, 'static'
|
|
96
|
+
await cp(path.join(buildDir, 'dist', 'client'), path.join(out, 'static'), { recursive: true });
|
|
99
97
|
// The worker and any chunk or wasm it imports — not its source map, metafile or bundle report. Its entry becomes server.js.
|
|
100
98
|
const runtime = (src) => !/\.[a-z]+$/.test(src) || /\.(m?js|wasm)$/.test(src);
|
|
101
99
|
await cp(path.join(buildDir, 'dist', 'server'), func, { recursive: true, filter: runtime });
|