@thorprovider/storefront 0.10.0 → 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +22 -11
- package/assets/templates/app/app/globals.css +0 -1
- package/assets/templates/app/lib/__STOREFRONT__/account-session.core.ts +4 -2
- package/assets/templates/app/lib/__STOREFRONT__/account-user.core.ts +2 -1
- package/assets/templates/app/lib/__STOREFRONT__/actions.ts +73 -11
- package/assets/templates/app/lib/__STOREFRONT__/commerce.ts +18 -2
- package/assets/templates/app/lib/__STOREFRONT__/confirmation.core.ts +38 -3
- package/assets/templates/app/lib/__STOREFRONT__/footer-content.ts +203 -0
- package/assets/templates/app/lib/__STOREFRONT__/order-detail-aftersales.ts +55 -0
- package/assets/templates/app/lib/__STOREFRONT__/order-detail-capabilities.ts +79 -0
- package/assets/templates/app/lib/__STOREFRONT__/order-detail-mapper.ts +13 -2
- package/assets/templates/app/lib/__STOREFRONT__/order-detail-money.ts +39 -0
- package/assets/templates/app/lib/__STOREFRONT__/order-detail-reorder.ts +62 -0
- package/assets/templates/app/lib/__STOREFRONT__/registry.tsx +8 -24
- package/assets/templates/app/lib/__STOREFRONT__/schema.ts +5 -3
- package/assets/templates/app/lib/__STOREFRONT__/shell/content.ts +14 -13
- package/assets/templates/app/lib/__STOREFRONT__/shell/props.ts +7 -2
- package/assets/templates/views/account/assembly/index.skeleton.tsx +3 -0
- package/assets/templates/views/account/assembly/registry.skeleton.tsx +115 -4
- package/assets/templates/views/account/content.ts +6 -0
- package/assets/templates/views/account/index.tsx +3 -0
- package/assets/templates/views/account/order-detail-flows.defaults.ts +106 -0
- package/assets/templates/views/account/order-detail-invoice.ts +136 -0
- package/assets/templates/views/account/order-detail-sheet.tsx +100 -0
- package/assets/templates/views/account/order-detail-sheets.tsx +122 -0
- package/assets/templates/views/account/order-detail.client.tsx +401 -1
- package/assets/templates/views/account/registry.tsx +115 -4
- package/assets/templates/views/account/schema.ts +2 -0
- package/assets/templates/views/home/content.ts +3 -1
- package/assets/templates/views/product/data.ts +13 -6
- package/assets/templates/views/product/index.tsx +3 -3
- package/bin/storefront.js +59 -23
- package/package.json +1 -1
- package/scripts/candidate.mjs +8 -4
- package/scripts/file-classes.mjs +3 -0
- package/scripts/mock-capabilities.mjs +22 -0
- package/scripts/reconcile.mjs +5 -2
- package/scripts/render-templates.mjs +126 -43
- package/scripts/scaffold-env.mjs +48 -0
package/bin/storefront.js
CHANGED
|
@@ -52,6 +52,10 @@ import {
|
|
|
52
52
|
writeManifest,
|
|
53
53
|
} from '../scripts/manifest.mjs'
|
|
54
54
|
import { reconcile } from '../scripts/reconcile.mjs'
|
|
55
|
+
import {
|
|
56
|
+
cleanupScaffoldTemp,
|
|
57
|
+
scaffoldTempEnv,
|
|
58
|
+
} from '../scripts/scaffold-env.mjs'
|
|
55
59
|
import { preflightManifest } from '../scripts/preflight.mjs'
|
|
56
60
|
import { scaffoldComposition } from '../scripts/starter.mjs'
|
|
57
61
|
import {
|
|
@@ -96,6 +100,7 @@ import {
|
|
|
96
100
|
} from '../recipes/validate.mjs'
|
|
97
101
|
import { CATALOG_VERSION, loadCatalog } from '../recipes/catalog.mjs'
|
|
98
102
|
import { OPERATION_NAMES, installGateDiagnostics } from '../scripts/operations.mjs'
|
|
103
|
+
import { MOCK_BACKEND_CAPABILITIES } from '../scripts/mock-capabilities.mjs'
|
|
99
104
|
import {
|
|
100
105
|
applyProject,
|
|
101
106
|
executeOperations,
|
|
@@ -790,8 +795,13 @@ async function remainingNonSuiteSkills(opencodeDir) {
|
|
|
790
795
|
// Run Yarn under the pinned Corepack version (`yarn@x.y.z`), so the scaffold
|
|
791
796
|
// and every install use the canonical package manager deterministically rather
|
|
792
797
|
// than whatever "known good release" Corepack would otherwise pick.
|
|
793
|
-
function runYarn(yarnSpec, cmdArgs, cwd) {
|
|
794
|
-
const res = spawnSync('corepack', [yarnSpec, ...cmdArgs], {
|
|
798
|
+
function runYarn(yarnSpec, cmdArgs, cwd, env) {
|
|
799
|
+
const res = spawnSync('corepack', [yarnSpec, ...cmdArgs], {
|
|
800
|
+
cwd,
|
|
801
|
+
stdio: 'inherit',
|
|
802
|
+
shell: false,
|
|
803
|
+
env: env ? { ...process.env, ...env } : process.env,
|
|
804
|
+
})
|
|
795
805
|
return res.status ?? 1
|
|
796
806
|
}
|
|
797
807
|
|
|
@@ -1067,6 +1077,13 @@ async function create(args) {
|
|
|
1067
1077
|
}
|
|
1068
1078
|
if (!(await verifyConsistency())) return 1
|
|
1069
1079
|
|
|
1080
|
+
// 1b. Keep Yarn's staging on the target's device. `yarn dlx` installs into
|
|
1081
|
+
// `os.tmpdir()`; when that is a different filesystem than the global
|
|
1082
|
+
// cache, Yarn downgrades `nmMode` to `hardlinks-local` (YN0074) and copies
|
|
1083
|
+
// files it would otherwise hardlink. The directory is removed on exit.
|
|
1084
|
+
const tmpEnv = scaffoldTempEnv(target)
|
|
1085
|
+
if (tmpEnv.TMPDIR) process.once('exit', () => cleanupScaffoldTemp(tmpEnv))
|
|
1086
|
+
|
|
1070
1087
|
// 2. Next.js base
|
|
1071
1088
|
const hasPackageJson = existsSync(join(target, 'package.json'))
|
|
1072
1089
|
if (!hasPackageJson) {
|
|
@@ -1082,7 +1099,7 @@ async function create(args) {
|
|
|
1082
1099
|
// written in step 3, so network hardening applies to every install. The
|
|
1083
1100
|
// pinned package manager is forced for the bootstrap too (Corepack), so the
|
|
1084
1101
|
// whole scaffold runs under the canonical Yarn, not a floating release.
|
|
1085
|
-
const status = runYarn(plan.packageManager, ['dlx', `create-next-app@${plan.scaffolder.createNextApp}`, '.', '--ts', '--tailwind', '--app', '--import-alias', '@/*', '--no-turbopack', '--use-yarn', '--skip-install'], target)
|
|
1102
|
+
const status = runYarn(plan.packageManager, ['dlx', `create-next-app@${plan.scaffolder.createNextApp}`, '.', '--ts', '--tailwind', '--app', '--import-alias', '@/*', '--no-turbopack', '--use-yarn', '--skip-install'], target, tmpEnv)
|
|
1086
1103
|
if (hadOpenCode) {
|
|
1087
1104
|
await cp(stash, opencodeDir, { recursive: true })
|
|
1088
1105
|
await rm(stash, { recursive: true, force: true })
|
|
@@ -1110,26 +1127,45 @@ async function create(args) {
|
|
|
1110
1127
|
)
|
|
1111
1128
|
await rm(join(target, '.pnp.cjs'), { force: true })
|
|
1112
1129
|
|
|
1113
|
-
//
|
|
1114
|
-
//
|
|
1115
|
-
//
|
|
1116
|
-
//
|
|
1117
|
-
//
|
|
1130
|
+
// 3a. Own Yarn project root. When the target sits inside another Yarn project
|
|
1131
|
+
// (e.g. `projects/consumers/*` in the Thor Commerce monorepo), Yarn walks
|
|
1132
|
+
// up and rejects the first install — `shadcn init` aborts with "the nearest
|
|
1133
|
+
// package directory … doesn't seem to be part of the project". An empty
|
|
1134
|
+
// lockfile claims this directory as its own project; the first install
|
|
1135
|
+
// replaces it with a real one. Harmless for a standalone target, and an
|
|
1136
|
+
// existing lockfile is left untouched so resumed scaffolds keep theirs.
|
|
1137
|
+
const lockPath = join(target, 'yarn.lock')
|
|
1138
|
+
if (!existsSync(lockPath)) await writeFile(lockPath, '', 'utf8')
|
|
1139
|
+
|
|
1140
|
+
// 3b. Pin the package manager (Corepack reads `packageManager`), declare the
|
|
1141
|
+
// curated dependencies, and resolve the local candidate. Yarn `resolutions`
|
|
1142
|
+
// map each local @thorprovider/* package to its packed tarball while the
|
|
1143
|
+
// declared dependency ranges stay honest semver. Everything is written
|
|
1144
|
+
// before the first install so one install covers the curated set and the
|
|
1145
|
+
// set `shadcn init` adds — step 5 then only reconciles the tree.
|
|
1118
1146
|
{
|
|
1119
1147
|
const pkgPath = join(target, 'package.json')
|
|
1120
1148
|
const pkg = JSON.parse(readFileSync(pkgPath, 'utf8'))
|
|
1121
1149
|
pkg.packageManager = plan.packageManager
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1150
|
+
pkg.dependencies = { ...(pkg.dependencies ?? {}), ...plan.dependencies }
|
|
1151
|
+
// `shadcn init` installs the CLI at whatever `latest` resolves to; pin it
|
|
1152
|
+
// through `resolutions` so its own install already lands on the candidate
|
|
1153
|
+
// version and step 4b's exact pin changes nothing in the tree.
|
|
1154
|
+
pkg.resolutions = { shadcn: plan.scaffolder.shadcn, ...plan.resolutions }
|
|
1155
|
+
if (Object.keys(pkg.resolutions).length === 0) delete pkg.resolutions
|
|
1125
1156
|
await writeFile(pkgPath, JSON.stringify(pkg, null, 2) + '\n', 'utf8')
|
|
1126
1157
|
}
|
|
1127
1158
|
|
|
1128
|
-
// 4. shadcn base
|
|
1159
|
+
// 4. shadcn base. `shadcn init` declares the packages it needs and installs
|
|
1160
|
+
// them in one pass — and because the curated dependencies are already in
|
|
1161
|
+
// package.json, that single install covers both sets. Installing again
|
|
1162
|
+
// afterwards would link the same tree a second time for a handful of new
|
|
1163
|
+
// packages.
|
|
1129
1164
|
const shadcnStatus = runYarn(
|
|
1130
1165
|
plan.packageManager,
|
|
1131
1166
|
['dlx', `shadcn@${plan.scaffolder.shadcn}`, 'init', '--template', 'next', '--base', 'base', '--preset', preset, '--no-monorepo', '--no-rtl', '--yes'],
|
|
1132
1167
|
target,
|
|
1168
|
+
tmpEnv,
|
|
1133
1169
|
)
|
|
1134
1170
|
if (shadcnStatus !== 0) {
|
|
1135
1171
|
console.error('shadcn init failed.')
|
|
@@ -1148,13 +1184,13 @@ async function create(args) {
|
|
|
1148
1184
|
await writeFile(pkgPath, JSON.stringify(pkg, null, 2) + '\n', 'utf8')
|
|
1149
1185
|
}
|
|
1150
1186
|
|
|
1151
|
-
// 5.
|
|
1152
|
-
//
|
|
1153
|
-
|
|
1154
|
-
const
|
|
1155
|
-
if (
|
|
1156
|
-
console.error('yarn
|
|
1157
|
-
return
|
|
1187
|
+
// 5. Reconcile — the curated dependencies were declared in 3b and installed by
|
|
1188
|
+
// step 4, and 4b may have tightened the shadcn pin, so this pass normally
|
|
1189
|
+
// links nothing and only records the corrected lockfile entry.
|
|
1190
|
+
const reconcileStatus = runYarn(plan.packageManager, ['install'], target, tmpEnv)
|
|
1191
|
+
if (reconcileStatus !== 0) {
|
|
1192
|
+
console.error('yarn install failed.')
|
|
1193
|
+
return reconcileStatus
|
|
1158
1194
|
}
|
|
1159
1195
|
|
|
1160
1196
|
// 6. Template copy + placeholder substitution, then reconcile to the manifest.
|
|
@@ -1301,10 +1337,10 @@ async function setup(args) {
|
|
|
1301
1337
|
// No publishable key: nothing to connect. Leave the store in mock mode and exit
|
|
1302
1338
|
// successfully so `setup` is safe to run in CI/bootstrap without a key.
|
|
1303
1339
|
if (!publishableKey) {
|
|
1304
|
-
// Mock mode
|
|
1305
|
-
//
|
|
1306
|
-
//
|
|
1307
|
-
recordCapabilities(target, [])
|
|
1340
|
+
// Mock mode has no endpoint to probe, but its provider has a fixed contract:
|
|
1341
|
+
// record what it actually advertises so capability-gated modules (profile,
|
|
1342
|
+
// address book) install on a demo store instead of being refused.
|
|
1343
|
+
recordCapabilities(target, [...MOCK_BACKEND_CAPABILITIES])
|
|
1308
1344
|
console.log('storefront setup: no publishable key — leaving THOR_DATA_SOURCE=mock.')
|
|
1309
1345
|
return 0
|
|
1310
1346
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thorprovider/storefront",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.0",
|
|
4
4
|
"description": "Deterministic storefront scaffolder and installable OpenCode skill suite for Thor Commerce (Next.js, @thorprovider/blocks, @thorprovider/adapters, Medusa)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": "bin/storefront.js",
|
package/scripts/candidate.mjs
CHANGED
|
@@ -37,16 +37,20 @@ export const CANDIDATE_TOOLSET = Object.freeze({
|
|
|
37
37
|
'next-themes': '0.4.6',
|
|
38
38
|
'lucide-react': '1.47.0',
|
|
39
39
|
motion: '13.4.3',
|
|
40
|
+
// The animation utilities the blocks use (`animate-in`, `fade-in-0`, …). The
|
|
41
|
+
// stylesheet imports it only when it is installed, so the dependency must be
|
|
42
|
+
// part of the generated project's set.
|
|
43
|
+
'tw-animate-css': '1.3.3',
|
|
40
44
|
zod: '3.25.76',
|
|
41
45
|
'@json-render/core': '0.21.0',
|
|
42
46
|
'@json-render/react': '0.21.0',
|
|
43
47
|
'@json-render/next': '0.21.0',
|
|
44
48
|
}),
|
|
45
49
|
local: Object.freeze({
|
|
46
|
-
'@thorprovider/blocks': '4.
|
|
47
|
-
'@thorprovider/adapters': '5.
|
|
48
|
-
'@thorprovider/runtime': '0.
|
|
49
|
-
'@thorprovider/types': '7.
|
|
50
|
+
'@thorprovider/blocks': '4.4.0',
|
|
51
|
+
'@thorprovider/adapters': '5.6.0',
|
|
52
|
+
'@thorprovider/runtime': '0.8.0',
|
|
53
|
+
'@thorprovider/types': '7.7.0',
|
|
50
54
|
}),
|
|
51
55
|
})
|
|
52
56
|
|
package/scripts/file-classes.mjs
CHANGED
|
@@ -58,6 +58,9 @@ const RULES = [
|
|
|
58
58
|
'app/lib/*/account-session.core.ts',
|
|
59
59
|
'app/lib/*/account-private.core.ts',
|
|
60
60
|
'app/lib/*/account-user.core.ts',
|
|
61
|
+
// The footer content contract and its neutral defaults are package-owned;
|
|
62
|
+
// a merchant overrides copy through the user-owned shell content seam.
|
|
63
|
+
'app/lib/*/footer-content.ts',
|
|
61
64
|
'app/lib/*/account-lifecycle.client.tsx',
|
|
62
65
|
'app/lib/*/account-boundary.client.tsx',
|
|
63
66
|
'app/lib/*/account-mutation.client.ts',
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// The mock provider's advertised backend capabilities, sorted the same way the
|
|
2
|
+
// live probe reports them.
|
|
3
|
+
//
|
|
4
|
+
// `setup` records this list when the store stays in mock mode. The mock is a
|
|
5
|
+
// real provider with a fixed contract — it supports the customer account
|
|
6
|
+
// surface (profile updates, address book, order history) and refuses the
|
|
7
|
+
// operations it cannot honor — so recording an empty list would hide working
|
|
8
|
+
// modules behind an install gate that assumes nothing works. The adapters
|
|
9
|
+
// package owns the contract (`MOCK_CAPABILITIES`); this list is its enabled
|
|
10
|
+
// flags, and `tests/mock-capabilities.contract.test.ts` fails if they drift.
|
|
11
|
+
export const MOCK_BACKEND_CAPABILITIES = Object.freeze([
|
|
12
|
+
'applyDiscounts',
|
|
13
|
+
'cancelOrder',
|
|
14
|
+
'defaultAddress',
|
|
15
|
+
'fetchOrders',
|
|
16
|
+
'guestCheckout',
|
|
17
|
+
'listPaymentProviders',
|
|
18
|
+
'manageAddresses',
|
|
19
|
+
'regionSpecificPayments',
|
|
20
|
+
'shippingCalculation',
|
|
21
|
+
'updateProfile',
|
|
22
|
+
])
|
package/scripts/reconcile.mjs
CHANGED
|
@@ -103,16 +103,19 @@ async function ensureLayoutAppend(targetDir, name, siteName, mode, dryRun) {
|
|
|
103
103
|
|
|
104
104
|
async function ensureGlobalsAppend(targetDir, name, siteName, dryRun) {
|
|
105
105
|
const globalsPath = path.join(targetDir, 'app', 'globals.css')
|
|
106
|
+
// The animation plugin is imported only when the project actually has it, so a
|
|
107
|
+
// stylesheet never references an uninstalled package (which fails the build).
|
|
108
|
+
const animations = existsSync(path.join(targetDir, 'node_modules', 'tw-animate-css'))
|
|
106
109
|
if (!existsSync(globalsPath)) {
|
|
107
110
|
if (dryRun) return true
|
|
108
111
|
const raw = await readFile(path.join(templatesRoot, 'app', 'app', 'globals.css'), 'utf8')
|
|
109
|
-
const content = injectGlobals(replacePlaceholders(raw, { name, siteName }))
|
|
112
|
+
const content = injectGlobals(replacePlaceholders(raw, { name, siteName }), { animations })
|
|
110
113
|
await mkdir(path.dirname(globalsPath), { recursive: true })
|
|
111
114
|
await writeFile(globalsPath, content)
|
|
112
115
|
return true
|
|
113
116
|
}
|
|
114
117
|
const existing = await readFile(globalsPath, 'utf8')
|
|
115
|
-
const content = injectGlobals(existing)
|
|
118
|
+
const content = injectGlobals(existing, { animations })
|
|
116
119
|
if (content === existing) return false
|
|
117
120
|
if (!dryRun) await writeFile(globalsPath, content)
|
|
118
121
|
return true
|
|
@@ -17,8 +17,8 @@ import {
|
|
|
17
17
|
resolveViewGenerationSelection,
|
|
18
18
|
} from './view-selection.mjs'
|
|
19
19
|
import { getFeature } from '../recipes/validate.mjs'
|
|
20
|
-
import { fillMissingTokens } from './theme/css-theme.mjs'
|
|
21
|
-
import { REQUIRED_CSS_TOKENS, DEFAULT_GLOBALS_TOKENS } from './theme/tokens.mjs'
|
|
20
|
+
import { applyBlockDeclarations, fillMissingTokens, findBlock } from './theme/css-theme.mjs'
|
|
21
|
+
import { REQUIRED_CSS_TOKENS, DEFAULT_GLOBALS_TOKENS, RADIUS_SCALE } from './theme/tokens.mjs'
|
|
22
22
|
|
|
23
23
|
const here = path.dirname(fileURLToPath(import.meta.url))
|
|
24
24
|
const pkgRoot = path.resolve(here, '..')
|
|
@@ -183,22 +183,104 @@ const THEME_MODE_MARKER = "from 'next-themes'"
|
|
|
183
183
|
export const THEME_MODES = ['light', 'dark', 'system']
|
|
184
184
|
export const DEFAULT_THEME_MODE = 'system'
|
|
185
185
|
const GLOBALS_IMPORT = '@import "@thorprovider/blocks/styles.css";'
|
|
186
|
-
|
|
187
|
-
//
|
|
188
|
-
//
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
//
|
|
193
|
-
//
|
|
194
|
-
//
|
|
195
|
-
const
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
186
|
+
|
|
187
|
+
// The `.dark` class next-themes writes on <html> only selects the `.dark` token
|
|
188
|
+
// block when Tailwind knows the variant; without it the storefront renders the
|
|
189
|
+
// light tokens for every visitor regardless of the configured mode.
|
|
190
|
+
const GLOBALS_DARK_VARIANT = '@custom-variant dark (&:is(.dark *));'
|
|
191
|
+
|
|
192
|
+
// The base layer that gives the semantic utilities their meaning: `border`
|
|
193
|
+
// defaults to the border token instead of `currentColor`, and the page adopts
|
|
194
|
+
// the background/foreground tokens and the sans stack.
|
|
195
|
+
const GLOBALS_BASE_LAYER = `@layer base {
|
|
196
|
+
* {
|
|
197
|
+
@apply border-border outline-ring/50;
|
|
198
|
+
}
|
|
199
|
+
body {
|
|
200
|
+
@apply bg-background text-foreground font-sans;
|
|
201
|
+
}
|
|
200
202
|
}`
|
|
201
203
|
|
|
204
|
+
// The animation utilities the blocks use (`animate-in`, `fade-in-0`, …) come from
|
|
205
|
+
// tw-animate-css. The import is added only when the dependency is installed, so a
|
|
206
|
+
// stylesheet never references a package the project does not have.
|
|
207
|
+
const GLOBALS_ANIMATION_IMPORT = '@import "tw-animate-css";'
|
|
208
|
+
|
|
209
|
+
// Insert lines directly after the last `@import` (CSS requires imports first), or
|
|
210
|
+
// at the top when the stylesheet has none yet.
|
|
211
|
+
function insertAfterImports(css, ...inserts) {
|
|
212
|
+
const lines = css.split('\n')
|
|
213
|
+
let lastImport = -1
|
|
214
|
+
for (let i = 0; i < lines.length; i++) {
|
|
215
|
+
if (lines[i].trimStart().startsWith('@import ')) lastImport = i
|
|
216
|
+
}
|
|
217
|
+
lines.splice(lastImport >= 0 ? lastImport + 1 : 0, 0, ...inserts)
|
|
218
|
+
return lines.join('\n')
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
const hasDependency = (targetDir, name) => existsSync(path.join(targetDir, 'node_modules', name))
|
|
222
|
+
|
|
223
|
+
// create-next-app's OS-driven palette override. It is removed because the
|
|
224
|
+
// storefront's mode is a site setting owned by app/globals.css: leaving it in
|
|
225
|
+
// paints the page with the visitor's OS palette and flattens every token.
|
|
226
|
+
const CNA_DARK_MEDIA = '@media (prefers-color-scheme: dark)'
|
|
227
|
+
const CNA_DARK_BODY = ':root{--background:#0a0a0a;--foreground:#ededed;}'
|
|
228
|
+
// create-next-app's hard-coded body font, which would override the base layer's
|
|
229
|
+
// `font-sans` for the whole page.
|
|
230
|
+
const CNA_BODY_FONT = /^[ \t]*font-family:\s*Arial,\s*Helvetica,\s*sans-serif;\s*$/m
|
|
231
|
+
|
|
232
|
+
const normalizeCss = (value) =>
|
|
233
|
+
value.replace(/\/\*[\s\S]*?\*\//g, '').replace(/\s+/g, '').trim()
|
|
234
|
+
|
|
235
|
+
// Drop create-next-app's dark-scheme block and Arial body font, keeping any
|
|
236
|
+
// developer-owned override: a `prefers-color-scheme` block is removed only when
|
|
237
|
+
// its body is exactly create-next-app's, and only the known font declaration is
|
|
238
|
+
// stripped from `body`.
|
|
239
|
+
function stripCreateNextAppOverrides(css) {
|
|
240
|
+
let out = css
|
|
241
|
+
for (;;) {
|
|
242
|
+
const block = findBlock(out, CNA_DARK_MEDIA)
|
|
243
|
+
if (!block || normalizeCss(out.slice(block.bodyStart, block.bodyEnd)) !== CNA_DARK_BODY) break
|
|
244
|
+
out = `${out.slice(0, block.start)}${out.slice(block.end)}`.replace(/\n{3,}/g, '\n\n')
|
|
245
|
+
}
|
|
246
|
+
return out.replace(CNA_BODY_FONT, '')
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
// The `@theme inline` bridge every block utility resolves against: `bg-card`,
|
|
250
|
+
// `border-border`, `text-muted-foreground`, `rounded-lg`, … all need an entry
|
|
251
|
+
// here. A create-next-app stylesheet maps only background/foreground, so the
|
|
252
|
+
// scaffold owns the rest and adds just the mappings that are missing — a preset
|
|
253
|
+
// (or a developer) that already mapped a name keeps its own value.
|
|
254
|
+
function ensureThemeBridge(css) {
|
|
255
|
+
const mapped = new Set()
|
|
256
|
+
for (const match of css.matchAll(/--((?:color|radius)-[\w-]+)\s*:/g)) mapped.add(match[1])
|
|
257
|
+
|
|
258
|
+
const inserts = []
|
|
259
|
+
for (const token of REQUIRED_CSS_TOKENS) {
|
|
260
|
+
if (mapped.has(`color-${token}`)) continue
|
|
261
|
+
inserts.push({ name: `--color-${token}`, value: `var(--${token})` })
|
|
262
|
+
}
|
|
263
|
+
for (const [step, value] of Object.entries(RADIUS_SCALE)) {
|
|
264
|
+
const name = `radius-${step}`
|
|
265
|
+
if (mapped.has(name)) continue
|
|
266
|
+
inserts.push({ name: `--${name}`, value })
|
|
267
|
+
}
|
|
268
|
+
if (inserts.length === 0) return css
|
|
269
|
+
return applyBlockDeclarations(css, '@theme inline', inserts)
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
// `@custom-variant` and `@layer` must follow the imports; both are inserted once
|
|
273
|
+
// and never rewritten, so a preset- or developer-authored variant survives.
|
|
274
|
+
function ensureDarkVariant(css) {
|
|
275
|
+
if (/@custom-variant\s+dark\b/.test(css)) return css
|
|
276
|
+
return insertAfterImports(css, `\n${GLOBALS_DARK_VARIANT}`)
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
function ensureBaseLayer(css) {
|
|
280
|
+
if (/@apply\s+border-border\b/.test(css)) return css
|
|
281
|
+
return `${css.replace(/\s*$/, '')}\n\n${GLOBALS_BASE_LAYER}\n`
|
|
282
|
+
}
|
|
283
|
+
|
|
202
284
|
/**
|
|
203
285
|
* Idempotently inject the storefront provider wiring into an existing
|
|
204
286
|
* app/layout.tsx (the create-next-app default). Adds the provider and registry
|
|
@@ -340,35 +422,32 @@ export function injectThemeMode(content, mode = DEFAULT_THEME_MODE) {
|
|
|
340
422
|
|
|
341
423
|
/**
|
|
342
424
|
* Idempotently complete an existing app/globals.css (produced by create-next-app
|
|
343
|
-
* + shadcn init):
|
|
344
|
-
*
|
|
345
|
-
* `:root` / `.dark
|
|
346
|
-
*
|
|
347
|
-
*
|
|
348
|
-
*
|
|
349
|
-
*
|
|
425
|
+
* + shadcn init): ensure the blocks stylesheet import, the `.dark` variant, the
|
|
426
|
+
* full `@theme inline` bridge and the base layer, then fill every missing
|
|
427
|
+
* required token declaration in `:root` / `.dark`. create-next-app's own OS
|
|
428
|
+
* palette override and Arial body font are removed so the storefront tokens are
|
|
429
|
+
* the only visual source. Existing declarations are never replaced — a
|
|
430
|
+
* developer's customized value always wins — and the result is stable across
|
|
431
|
+
* repeated runs.
|
|
350
432
|
*/
|
|
351
|
-
export function injectGlobals(content) {
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
if (lines[i].trimStart().startsWith('@import ')) lastImport = i
|
|
356
|
-
}
|
|
357
|
-
let out
|
|
358
|
-
if (content.includes(GLOBALS_IMPORT)) {
|
|
359
|
-
out = content
|
|
360
|
-
} else if (lastImport >= 0) {
|
|
361
|
-
lines.splice(lastImport + 1, 0, GLOBALS_IMPORT)
|
|
362
|
-
out = lines.join('\n')
|
|
363
|
-
} else {
|
|
364
|
-
out = `${GLOBALS_IMPORT}\n${content}`
|
|
433
|
+
export function injectGlobals(content, { animations = false } = {}) {
|
|
434
|
+
let out = content.includes(GLOBALS_IMPORT) ? content : insertAfterImports(content, GLOBALS_IMPORT)
|
|
435
|
+
if (animations && !out.includes(GLOBALS_ANIMATION_IMPORT)) {
|
|
436
|
+
out = insertAfterImports(out, GLOBALS_ANIMATION_IMPORT)
|
|
365
437
|
}
|
|
366
438
|
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
439
|
+
out = stripCreateNextAppOverrides(out)
|
|
440
|
+
out = ensureDarkVariant(out)
|
|
441
|
+
out = ensureThemeBridge(out)
|
|
442
|
+
out = ensureBaseLayer(out)
|
|
370
443
|
|
|
371
|
-
|
|
444
|
+
// `--radius` is not a color token, but the radius bridge above resolves
|
|
445
|
+
// against it and a create-next-app stylesheet never declares it.
|
|
446
|
+
const defaults = {
|
|
447
|
+
light: { ...DEFAULT_GLOBALS_TOKENS.light, radius: '0.5rem' },
|
|
448
|
+
dark: DEFAULT_GLOBALS_TOKENS.dark,
|
|
449
|
+
}
|
|
450
|
+
return fillMissingTokens(out, [...REQUIRED_CSS_TOKENS, 'radius'], defaults)
|
|
372
451
|
}
|
|
373
452
|
|
|
374
453
|
/**
|
|
@@ -490,15 +569,19 @@ async function ensureLayoutAppend(targetDir, name, siteName, mode = DEFAULT_THEM
|
|
|
490
569
|
async function ensureGlobalsAppend(targetDir, name, siteName) {
|
|
491
570
|
const globalsPath = path.join(targetDir, 'app', 'globals.css')
|
|
492
571
|
const templatePath = path.join(templatesRoot, 'app', 'app', 'globals.css')
|
|
572
|
+
const animations = hasDependency(targetDir, 'tw-animate-css')
|
|
493
573
|
if (!existsSync(globalsPath)) {
|
|
494
574
|
const raw = await readFile(templatePath, 'utf8')
|
|
495
575
|
// Run the completeness fill on the fallback template too, so a fresh project
|
|
496
576
|
// and a shadcn-generated one end with the same required token set.
|
|
497
|
-
await writeFile(
|
|
577
|
+
await writeFile(
|
|
578
|
+
globalsPath,
|
|
579
|
+
injectGlobals(replacePlaceholders(raw, { name, siteName }), { animations }),
|
|
580
|
+
)
|
|
498
581
|
return
|
|
499
582
|
}
|
|
500
583
|
const existing = await readFile(globalsPath, 'utf8')
|
|
501
|
-
const injected = injectGlobals(existing)
|
|
584
|
+
const injected = injectGlobals(existing, { animations })
|
|
502
585
|
if (injected !== existing) await writeFile(globalsPath, injected)
|
|
503
586
|
}
|
|
504
587
|
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
// Child-process environment for `storefront create`.
|
|
2
|
+
//
|
|
3
|
+
// `yarn dlx` stages its temporary install under `os.tmpdir()`. When that lives
|
|
4
|
+
// on a different device than Yarn's global cache, Yarn downgrades `nmMode` to
|
|
5
|
+
// `hardlinks-local` (warning YN0074) and copies every file it would otherwise
|
|
6
|
+
// hardlink, which turns a cheap scaffold into a burst of disk writes. Pointing
|
|
7
|
+
// `TMPDIR` at a directory beside the target keeps staging and cache on one
|
|
8
|
+
// device, so `hardlinks-global` holds for every install the scaffold runs.
|
|
9
|
+
|
|
10
|
+
import { mkdtempSync, rmSync, statSync } from 'node:fs'
|
|
11
|
+
import { tmpdir } from 'node:os'
|
|
12
|
+
import { dirname, join } from 'node:path'
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Env overrides that keep Yarn staging on the target's device.
|
|
16
|
+
* Returns `{}` when the default temp directory already shares the device, or
|
|
17
|
+
* when the target cannot be inspected.
|
|
18
|
+
*/
|
|
19
|
+
export function scaffoldTempEnv(target) {
|
|
20
|
+
if (process.platform === 'win32') return {}
|
|
21
|
+
let targetDevice
|
|
22
|
+
try {
|
|
23
|
+
targetDevice = statSync(target).dev
|
|
24
|
+
} catch {
|
|
25
|
+
return {}
|
|
26
|
+
}
|
|
27
|
+
try {
|
|
28
|
+
if (statSync(tmpdir()).dev === targetDevice) return {}
|
|
29
|
+
} catch {
|
|
30
|
+
return {}
|
|
31
|
+
}
|
|
32
|
+
try {
|
|
33
|
+
return { TMPDIR: mkdtempSync(join(dirname(target), '.storefront-tmp-')) }
|
|
34
|
+
} catch {
|
|
35
|
+
// A read-only parent is not a reason to fail the scaffold.
|
|
36
|
+
return {}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Remove a directory created by `scaffoldTempEnv`, ignoring failures. */
|
|
41
|
+
export function cleanupScaffoldTemp(env) {
|
|
42
|
+
if (!env?.TMPDIR) return
|
|
43
|
+
try {
|
|
44
|
+
rmSync(env.TMPDIR, { recursive: true, force: true })
|
|
45
|
+
} catch {
|
|
46
|
+
// Best effort: a leftover empty temp directory is not a scaffold failure.
|
|
47
|
+
}
|
|
48
|
+
}
|