@velastack/patterns 0.13.1 → 0.13.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/dist/chunks/app-d-ts-h33RrYIv.js +198 -0
- package/dist/chunks/app-d-ts-h33RrYIv.js.map +1 -0
- package/dist/chunks/app-layout.svelte-CZ0hw-pi.js +51 -0
- package/dist/chunks/app-layout.svelte-CZ0hw-pi.js.map +1 -0
- package/dist/chunks/{generate.runtime-DHJqOJTr.js → generate.runtime-Bv_16lWi.js} +2 -2
- package/dist/chunks/{generate.runtime-DHJqOJTr.js.map → generate.runtime-Bv_16lWi.js.map} +1 -1
- package/dist/chunks/{generate.runtime-DvTbN-no.js → generate.runtime-CZKIKP3B.js} +213 -175
- package/dist/chunks/generate.runtime-CZKIKP3B.js.map +1 -0
- package/dist/chunks/{generate.runtime-BEmSIAop.js → generate.runtime-C_SdcnRs.js} +2 -2
- package/dist/chunks/{generate.runtime-BEmSIAop.js.map → generate.runtime-C_SdcnRs.js.map} +1 -1
- package/dist/chunks/{generate.runtime-DGnXHELM.js → generate.runtime-CsP4c8GY.js} +78 -77
- package/dist/chunks/generate.runtime-CsP4c8GY.js.map +1 -0
- package/dist/chunks/{generate.runtime-DWHoDisZ.js → generate.runtime-CzYArKUA.js} +2 -2
- package/dist/chunks/{generate.runtime-DWHoDisZ.js.map → generate.runtime-CzYArKUA.js.map} +1 -1
- package/dist/chunks/generate.runtime-DZUPtJVF.js +429 -0
- package/dist/chunks/generate.runtime-DZUPtJVF.js.map +1 -0
- package/dist/chunks/{generate.runtime-Cgam_XCc.js → generate.runtime-DaPA2NNL.js} +2 -2
- package/dist/chunks/{generate.runtime-Cgam_XCc.js.map → generate.runtime-DaPA2NNL.js.map} +1 -1
- package/dist/chunks/{generate.runtime-i3tMIA1A.js → generate.runtime-pbIrEsa7.js} +45 -45
- package/dist/chunks/generate.runtime-pbIrEsa7.js.map +1 -0
- package/dist/chunks/i18n-BHCytiiO.js +28 -0
- package/dist/chunks/i18n-BHCytiiO.js.map +1 -0
- package/dist/chunks/test-setup-cZj1tqaf.js +176 -0
- package/dist/chunks/test-setup-cZj1tqaf.js.map +1 -0
- package/dist/chunks/translations-CiJnl574.js +189 -0
- package/dist/chunks/translations-CiJnl574.js.map +1 -0
- package/dist/chunks/{ui-Ct6YQuPw.js → ui-IkdkLwmB.js} +2 -2
- package/dist/chunks/{ui-Ct6YQuPw.js.map → ui-IkdkLwmB.js.map} +1 -1
- package/dist/chunks/write-result-C1GYInL8.js +499 -0
- package/dist/chunks/write-result-C1GYInL8.js.map +1 -0
- package/dist/index.js +735 -725
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/chunks/_layout-Dju9EYqa.js +0 -60
- package/dist/chunks/_layout-Dju9EYqa.js.map +0 -1
- package/dist/chunks/generate.runtime-DGnXHELM.js.map +0 -1
- package/dist/chunks/generate.runtime-Dtf3tF3-.js +0 -316
- package/dist/chunks/generate.runtime-Dtf3tF3-.js.map +0 -1
- package/dist/chunks/generate.runtime-DvTbN-no.js.map +0 -1
- package/dist/chunks/generate.runtime-i3tMIA1A.js.map +0 -1
- package/dist/chunks/test-setup-CbwhAJT4.js +0 -176
- package/dist/chunks/test-setup-CbwhAJT4.js.map +0 -1
- package/dist/chunks/write-result-B5KFCqxw.js +0 -487
- package/dist/chunks/write-result-B5KFCqxw.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate.runtime-CZKIKP3B.js","names":["FAILURE_HINT","NOT_FOUND_HINT","FAILURE_HINT","FAILURE_HINT","FAILURE_HINT","NOT_FOUND_HINT","NOT_FOUND_HINT","getLogger","modifyOutcomeToFile","probeFirstExisting","VITE_CONFIG_CANDIDATES","withInMemoryScript","ensureNamedImport","formatLikeSource","ensureImports","modifyLayoutServerLocale","ensureRootLayoutI18n","modifyPrettierignore","modifyAppDts","modifyPackageImportsI18n","dedent","addHandle","SvelteFile","APP_LAYOUT_PATH","modifyAppLayoutLanguageSelect","withTranslations","translateCatalog","entriesInProject","AUTH_TRANSLATIONS","withWuchaleJsFiles","TRANSLATED_LIB_FILES","fs","path","FAILURE_HINT$4","NOT_FOUND_HINT$3","modifyViteConfig","viteConfigPath","sourceFile","Project","QuoteKind","changed","failed","d","configArg","SyntaxKind","ce","configObj","pluginsProp","pluginsInit","arr","el","I18N_HANDLE","HANDLE_BODY","types","indent","text","line","IMPORTS","STARTUP","UNTYPED_HANDLE","FAILURE_HINT$3","HOOKS_SERVER_SNIPPET","ensureNamespaceImport","moduleSpecifier","ns","modifyHooksServerI18n","hooksServerPath","original","composed","handleStmt","DELOCALIZE_HELPER","HOOKS_SNIPPET","FAILURE_HINT$2","NEGOTIATE_ONLY_REROUTE","hasOtherReroute","n","ensureDeLocalizeImports","modifyHooksI18n","hooksPath","rerouteDecl","init","target","s","FAILURE_HINT$1","NOT_FOUND_HINT$2","modifyAppHtml","appHtmlPath","updated","match","NOT_FOUND_HINT$1","modifyGitignore","gitignorePath","block","LANGUAGE_SELECT_SNIPPET","PLAIN_LANGUAGE_SELECT_SNIPPET","IMPORT_SNIPPET","FAILURE_HINT","NOT_FOUND_HINT","PLAIN_FAILURE_HINT","PLAIN_NOT_FOUND_HINT","addImport","out","source","sf","modifyRootLayoutLanguageSelect","plain","ui","layoutPath","file","PAGE_PATH","CATALOG_PATH","WELCOME_PAGE","PAGE_ENTRIES","PLAIN_SELECT_ENTRY","HEADER","normalize","welcomePageCatalog","root","pagePath","entry","withLibraryTexts","present","creates","edited","generate","logger","options","modifies","pushResult","imports","appDtsPath","layoutServerPath","rootLayoutCandidates","resolveUi","rootLayoutPath","p","appLayoutPath","prettierignorePath","catalog","shipped","content","translated"],"sources":["../../src/patterns/enable/i18n/modifies/vite-config.ts","../../src/patterns/enable/i18n/modifies/hooks.server.ts","../../src/patterns/enable/i18n/modifies/hooks.ts","../../src/patterns/enable/i18n/modifies/app-html.ts","../../src/patterns/enable/i18n/modifies/gitignore.ts","../../src/patterns/enable/i18n/modifies/root-layout.svelte.ts","../../src/patterns/enable/i18n/welcome-catalog.ts","../../src/patterns/enable/i18n/generate.runtime.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport { Project, QuoteKind, SyntaxKind } from \"ts-morph\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\nimport { formatLikeSource } from \"../../../../runtime/ts-morph-helpers\";\n\nconst FAILURE_HINT = [\n \"Add the wuchale plugin to your Vite config:\",\n \"\",\n \"import { wuchale } from 'wuchale/vite';\",\n \"\",\n \"export default defineConfig({\",\n \" plugins: [wuchale(), /* ...existing plugins */],\",\n \"});\",\n].join(\"\\n\");\n\nconst NOT_FOUND_HINT = [\n \"Create a Vite config with the wuchale plugin:\",\n \"\",\n \"import { defineConfig } from 'vite';\",\n \"import { wuchale } from 'wuchale/vite';\",\n \"\",\n \"export default defineConfig({\",\n \" plugins: [wuchale()],\",\n \"});\",\n].join(\"\\n\");\n\nexport function modifyViteConfig(viteConfigPath: string): ModifyOutcome {\n if (!fs.existsSync(viteConfigPath)) {\n return { status: \"not-found\", message: NOT_FOUND_HINT };\n }\n\n const project = new Project({\n compilerOptions: { allowJs: true },\n manipulationSettings: { quoteKind: QuoteKind.Single },\n });\n const sourceFile = project.addSourceFileAtPath(viteConfigPath);\n\n let changed = false;\n let failed = false;\n\n const hasImport = sourceFile\n .getImportDeclarations()\n .some((d) => d.getModuleSpecifierValue() === \"wuchale/vite\");\n\n if (!hasImport) {\n sourceFile.insertImportDeclaration(0, {\n namedImports: [\"wuchale\"],\n moduleSpecifier: \"wuchale/vite\",\n });\n changed = true;\n }\n\n const defineConfigCall = sourceFile\n .getDescendantsOfKind(SyntaxKind.CallExpression)\n .find((ce) => ce.getExpression().getText() === \"defineConfig\");\n\n const configArg = defineConfigCall?.getArguments()?.[0];\n const configObj =\n configArg?.getKind() === SyntaxKind.ObjectLiteralExpression\n ? (configArg as import(\"ts-morph\").ObjectLiteralExpression)\n : null;\n\n if (!configObj) {\n failed = true;\n } else {\n const pluginsProp = configObj.getProperty(\"plugins\");\n if (!pluginsProp) {\n configObj.addPropertyAssignment({\n name: \"plugins\",\n initializer: \"[wuchale()]\",\n });\n changed = true;\n } else if (pluginsProp.getKind() !== SyntaxKind.PropertyAssignment) {\n failed = true;\n } else {\n const pluginsInit = (\n pluginsProp as import(\"ts-morph\").PropertyAssignment\n ).getInitializer();\n\n if (!pluginsInit) {\n (pluginsProp as import(\"ts-morph\").PropertyAssignment).setInitializer(\n \"[wuchale()]\",\n );\n changed = true;\n } else if (pluginsInit.getKind() !== SyntaxKind.ArrayLiteralExpression) {\n failed = true;\n } else {\n const arr = pluginsInit as import(\"ts-morph\").ArrayLiteralExpression;\n const hasWuchale = arr\n .getElements()\n .some((el) => el.getText().replace(/\\s/g, \"\") === \"wuchale()\");\n\n if (!hasWuchale) {\n arr.insertElement(0, \"wuchale()\");\n changed = true;\n }\n }\n }\n }\n\n if (changed) {\n formatLikeSource(sourceFile);\n sourceFile.saveSync();\n }\n\n if (failed) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n return { status: \"success\", changed };\n}\n","import fs from \"node:fs\";\nimport path from \"node:path\";\nimport dedent from \"dedent\";\nimport { Project, QuoteKind } from \"ts-morph\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\nimport { addHandle } from \"../../../../runtime/compose-handle\";\nimport {\n ensureNamedImport,\n formatLikeSource,\n} from \"../../../../runtime/ts-morph-helpers\";\n\nconst I18N_HANDLE = \"handleWuchale\";\n\n/**\n * The handle's body: which language the request is in (the URL on a public\n * page, the visitor's preference elsewhere: see `src/lib/locale.ts`), and the\n * cookie that remembers the last public page opened.\n */\nconst HANDLE_BODY = (types: { locale: string; html: string }) => dedent`\n const urlLocale = deLocalizeDefault(event.url.pathname, locales)[1] as Locale | null;\n const localizedUrl = hasLocalizedUrl(event.url.pathname);\n const cookie${types.locale} = event.cookies.get(LOCALE_COOKIE);\n const locale = pickLocale({\n urlLocale,\n localizedUrl,\n cookie,\n acceptLanguage: event.request.headers.get('accept-language'),\n locales,\n defaultLocale\n });\n event.locals.locale = locale;\n\n const response${types.html ? \": Response\" : \"\"} = await runWithLocale(locale, () =>\n resolve(event, {\n transformPageChunk: ({ html }${types.html}) => html.replace('%sveltekit.lang%', locale)\n })\n );\n\n // Opening a public page sets the language of the pages that have no\n // language in their URL. Only when the page itself is opened: a preload\n // (hovering a link) must not change it.\n if (localizedUrl && cookie !== locale && event.request.method === 'GET' && !event.isDataRequest) {\n try {\n response.headers.append('set-cookie', localeCookie(locale));\n } catch {\n // a response with immutable headers (a proxied file): nothing to remember\n }\n }\n return response;\n`;\n\nconst indent = (text: string) =>\n text\n .split(\"\\n\")\n .map((line) => (line ? ` ${line}` : line))\n .join(\"\\n\");\n\nconst IMPORTS = dedent`\n import { runWithLocale, loadLocales } from 'wuchale/load-utils/server';\n import { deLocalizeDefault } from 'wuchale/url';\n import { locales, type Locale } from '#locales/data.js';\n import { defaultLocale, hasLocalizedUrl } from '#lib/url.js';\n import { LOCALE_COOKIE, localeCookie, pickLocale } from '#lib/locale.js';\n import * as main from '#locales/main.loader.server.svelte.js';\n import * as js from '#locales/js.loader.server.js';\n`;\n\nconst STARTUP = dedent`\n loadLocales(main.key, main.loadCount, main.loadCatalog, locales);\n loadLocales(js.key, js.loadCount, js.loadCatalog, locales);\n`;\n\n/** The handle as it is added to a file whose own handle is typed loosely. */\nconst UNTYPED_HANDLE = [\n `const ${I18N_HANDLE} = async ({ event, resolve }: any) => {`,\n indent(\n HANDLE_BODY({ locale: \": string | undefined\", html: \": { html: string }\" }),\n ),\n \"};\",\n].join(\"\\n\");\n\nconst FAILURE_HINT = [\n \"Wrap your exported handle with the wuchale i18n handler:\",\n \"\",\n \"import { sequence } from '@sveltejs/kit/hooks';\",\n IMPORTS,\n \"\",\n STARTUP,\n \"\",\n UNTYPED_HANDLE,\n \"\",\n \"export const handle = sequence(handleWuchale, /* your existing handle */);\",\n].join(\"\\n\");\n\n/**\n * The whole file, for a project that had no server hooks: a fresh `sv create`\n * app or a static site. `disable-i18n` deletes it again once the i18n handle\n * is all that is left.\n */\nexport const HOOKS_SERVER_SNIPPET = [\n \"import type { Handle } from '@sveltejs/kit/hooks';\",\n IMPORTS,\n \"\",\n STARTUP,\n \"\",\n `const ${I18N_HANDLE}: Handle = async ({ event, resolve }) => {`,\n indent(HANDLE_BODY({ locale: \"\", html: \"\" })),\n \"};\",\n \"\",\n `export const handle = ${I18N_HANDLE};`,\n].join(\"\\n\");\n\nfunction ensureNamespaceImport(\n sourceFile: import(\"ts-morph\").SourceFile,\n moduleSpecifier: string,\n ns: string,\n) {\n const existing = sourceFile\n .getImportDeclarations()\n .find((d) => d.getModuleSpecifierValue() === moduleSpecifier);\n if (existing) return;\n sourceFile.addImportDeclaration({ namespaceImport: ns, moduleSpecifier });\n}\n\nexport function modifyHooksServerI18n(hooksServerPath: string): ModifyOutcome {\n if (!fs.existsSync(hooksServerPath)) {\n // SvelteKit loads the first `hooks.server.*` it finds, and `.js` sorts\n // first, so a new `.ts` beside it would never run.\n if (fs.existsSync(hooksServerPath.replace(/\\.ts$/, \".js\"))) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n fs.mkdirSync(path.dirname(hooksServerPath), { recursive: true });\n fs.writeFileSync(hooksServerPath, HOOKS_SERVER_SNIPPET + \"\\n\");\n return { status: \"success\", changed: true };\n }\n\n const original = fs.readFileSync(hooksServerPath, \"utf8\");\n if (original.includes(\"runWithLocale\") || original.includes(\"loadLocales(\")) {\n return { status: \"success\", changed: false };\n }\n\n const project = new Project({\n compilerOptions: { allowJs: true },\n manipulationSettings: { quoteKind: QuoteKind.Single },\n });\n const sourceFile = project.addSourceFileAtPath(hooksServerPath);\n\n // Composed first: an unsupported handle leaves the file untouched.\n const composed = addHandle(sourceFile, { expression: I18N_HANDLE });\n if (composed.status === \"unsupported\" || !composed.statement) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n const handleStmt = composed.statement;\n\n ensureNamedImport(sourceFile, \"wuchale/load-utils/server\", \"runWithLocale\");\n ensureNamedImport(sourceFile, \"wuchale/load-utils/server\", \"loadLocales\");\n ensureNamedImport(sourceFile, \"wuchale/url\", \"deLocalizeDefault\");\n ensureNamedImport(sourceFile, \"#locales/data.js\", \"locales\");\n ensureNamedImport(sourceFile, \"#locales/data.js\", \"Locale\", true);\n ensureNamedImport(sourceFile, \"#lib/url.js\", \"defaultLocale\");\n ensureNamedImport(sourceFile, \"#lib/url.js\", \"hasLocalizedUrl\");\n ensureNamedImport(sourceFile, \"#lib/locale.js\", \"LOCALE_COOKIE\");\n ensureNamedImport(sourceFile, \"#lib/locale.js\", \"localeCookie\");\n ensureNamedImport(sourceFile, \"#lib/locale.js\", \"pickLocale\");\n ensureNamespaceImport(\n sourceFile,\n \"#locales/main.loader.server.svelte.js\",\n \"main\",\n );\n ensureNamespaceImport(sourceFile, \"#locales/js.loader.server.js\", \"js\");\n\n // Above the handle and its JSDoc, so `handleWuchale` is declared before\n // the handle reads it.\n sourceFile.insertText(\n handleStmt.getStart(true),\n `${STARTUP}\\n\\n${UNTYPED_HANDLE}\\n\\n`,\n );\n\n formatLikeSource(sourceFile);\n sourceFile.saveSync();\n return { status: \"success\", changed: true };\n}\n","import fs from \"node:fs\";\nimport path from \"node:path\";\nimport dedent from \"dedent\";\nimport { Project, QuoteKind, SyntaxKind, type SourceFile } from \"ts-morph\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\nimport {\n ensureNamedImport,\n formatLikeSource,\n} from \"../../../../runtime/ts-morph-helpers\";\n\nconst DELOCALIZE_HELPER = dedent`\n const rerouteDeLocalize = (url: string) => {\n const [upath, locale] = deLocalizeDefault(url, locales);\n const { path } = matchUrl(upath, locale);\n return path ?? url;\n };\n`;\n\n/**\n * The whole file, for a project that had no universal hooks. `disable-i18n`\n * deletes it again once the de-localizing reroute is all that is left.\n */\nexport const HOOKS_SNIPPET = dedent`\n import { deLocalizeDefault } from 'wuchale/url';\n import { matchUrl } from '#locales/main.url.js';\n import { locales } from '#locales/data.js';\n\n const rerouteDeLocalize = (url: string) => {\n const [upath, locale] = deLocalizeDefault(url, locales);\n const { path } = matchUrl(upath, locale);\n return path ?? url;\n };\n\n export const reroute = ({ url }) => rerouteDeLocalize(url.pathname);\n`;\n\nconst FAILURE_HINT = dedent`\n Compose your existing reroute in src/hooks.ts with the wuchale de-localizer:\n\n import { deLocalizeDefault } from 'wuchale/url';\n import { matchUrl } from '#locales/main.url.js';\n import { locales } from '#locales/data.js';\n\n const rerouteDeLocalize = (url: string) => {\n const [upath, locale] = deLocalizeDefault(url, locales);\n const { path } = matchUrl(upath, locale);\n return path ?? url;\n };\n\n export const reroute = ({ url }) => rerouteDeLocalize(existingReroute(url.pathname));\n`;\n\n/** What `enable-content-negotiation` leaves behind, to the whitespace. */\nconst NEGOTIATE_ONLY_REROUTE =\n /^\\(\\s*\\{\\s*url\\s*\\}\\s*\\)\\s*=>\\s*negotiateReroute\\(\\s*url\\.pathname\\s*\\)$/;\n\n/** A `reroute` this modifier cannot compose with: not a variable declaration. */\nfunction hasOtherReroute(sourceFile: SourceFile): boolean {\n if (sourceFile.getFunction(\"reroute\")) return true;\n return sourceFile\n .getExportDeclarations()\n .some((d) =>\n d\n .getNamedExports()\n .some(\n (n) => (n.getAliasNode()?.getText() ?? n.getName()) === \"reroute\",\n ),\n );\n}\n\nfunction ensureDeLocalizeImports(sourceFile: SourceFile) {\n ensureNamedImport(sourceFile, \"wuchale/url\", \"deLocalizeDefault\");\n ensureNamedImport(sourceFile, \"#locales/main.url.js\", \"matchUrl\");\n ensureNamedImport(sourceFile, \"#locales/data.js\", \"locales\");\n}\n\n/**\n * Add the de-localizing reroute to `src/hooks.ts`, composing with the one\n * `enable-content-negotiation` wrote rather than replacing the file: either\n * pattern may be enabled first, and negotiation's `modifyHooksNegotiate`\n * composes the other way round.\n */\nexport function modifyHooksI18n(hooksPath: string): ModifyOutcome {\n if (!fs.existsSync(hooksPath)) {\n fs.mkdirSync(path.dirname(hooksPath), { recursive: true });\n fs.writeFileSync(hooksPath, HOOKS_SNIPPET + \"\\n\");\n return { status: \"success\", changed: true };\n }\n\n const original = fs.readFileSync(hooksPath, \"utf8\");\n if (original.includes(\"rerouteDeLocalize\")) {\n return { status: \"success\", changed: false };\n }\n\n const project = new Project({\n compilerOptions: { allowJs: true },\n manipulationSettings: { quoteKind: QuoteKind.Single },\n });\n const sourceFile = project.addSourceFileAtPath(hooksPath);\n\n const rerouteDecl = sourceFile.getVariableDeclaration(\"reroute\");\n\n if (!rerouteDecl) {\n // A reroute in a shape ts-morph cannot rewrite (a function declaration,\n // a re-export) would collide with the one added below.\n if (hasOtherReroute(sourceFile)) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n ensureDeLocalizeImports(sourceFile);\n sourceFile.addStatements(\n `\\n${DELOCALIZE_HELPER}\\n\\nexport const reroute = ({ url }) => rerouteDeLocalize(url.pathname);\\n`,\n );\n formatLikeSource(sourceFile);\n sourceFile.saveSync();\n return { status: \"success\", changed: true };\n }\n\n const rerouteStmt = rerouteDecl.getFirstAncestorByKind(\n SyntaxKind.VariableStatement,\n );\n if (!rerouteStmt?.hasExportKeyword()) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n const init = rerouteDecl.getInitializer();\n if (!init || !NEGOTIATE_ONLY_REROUTE.test(init.getText())) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n ensureDeLocalizeImports(sourceFile);\n rerouteDecl.setInitializer(\n \"({ url }) => rerouteDeLocalize(negotiateReroute(url.pathname))\",\n );\n\n // Last: inserting text forgets the nodes above, and the helper has to be\n // declared before the reroute that reads it.\n const target = sourceFile\n .getVariableStatements()\n .find((s) => s.getDeclarations().some((d) => d.getName() === \"reroute\"))!;\n sourceFile.insertText(target.getStart(true), `${DELOCALIZE_HELPER}\\n\\n`);\n\n formatLikeSource(sourceFile);\n sourceFile.saveSync();\n return { status: \"success\", changed: true };\n}\n","import fs from \"node:fs\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\nconst FAILURE_HINT = [\n \"Add the sveltekit lang placeholder to the <html> tag:\",\n \"\",\n '<html lang=\"%sveltekit.lang%\">',\n].join(\"\\n\");\n\nconst NOT_FOUND_HINT = [\n \"Create src/app.html with a lang placeholder:\",\n \"\",\n \"<!doctype html>\",\n '<html lang=\"%sveltekit.lang%\">',\n \" <head>\",\n ' <meta charset=\"utf-8\" />',\n \" %sveltekit.head%\",\n \" </head>\",\n ' <body data-sveltekit-preload-data=\"hover\">',\n ' <div style=\"display: contents\">%sveltekit.body%</div>',\n \" </body>\",\n \"</html>\",\n].join(\"\\n\");\n\nexport function modifyAppHtml(appHtmlPath: string): ModifyOutcome {\n if (!fs.existsSync(appHtmlPath)) {\n return { status: \"not-found\", message: NOT_FOUND_HINT };\n }\n\n const original = fs.readFileSync(appHtmlPath, \"utf8\");\n if (\n original.includes('lang=\"%sveltekit.lang%\"') ||\n original.includes(\"lang='%sveltekit.lang%'\")\n ) {\n return { status: \"success\", changed: false };\n }\n\n const updated = original.replace(/<html(\\s[^>]*?)?>/i, (match) => {\n // A static lang (the templates ship lang=\"en\") is replaced by the\n // placeholder so the server hook can fill in the negotiated locale.\n if (/\\slang\\s*=/i.test(match)) {\n return match.replace(\n /\\slang\\s*=\\s*(?:\"[^\"]*\"|'[^']*'|[^\\s>]+)/i,\n ' lang=\"%sveltekit.lang%\"',\n );\n }\n return match.replace(/<html/i, '<html lang=\"%sveltekit.lang%\"');\n });\n\n if (updated === original) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n fs.writeFileSync(appHtmlPath, updated);\n return { status: \"success\", changed: true };\n}\n","import fs from \"node:fs\";\nimport dedent from \"dedent\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\nconst NOT_FOUND_HINT = [\n \"Create a .gitignore with the wuchale cache ignored:\",\n \"\",\n \"# Wuchale\",\n \"src/locales/.wuchale\",\n].join(\"\\n\");\n\nexport function modifyGitignore(gitignorePath: string): ModifyOutcome {\n if (!fs.existsSync(gitignorePath)) {\n return { status: \"not-found\", message: NOT_FOUND_HINT };\n }\n\n const original = fs.readFileSync(gitignorePath, \"utf8\");\n if (original.includes(\"src/locales/.wuchale\")) {\n return { status: \"success\", changed: false };\n }\n\n const block = dedent`\n # Wuchale\n src/locales/.wuchale\n `;\n\n const needsNewline = original.length > 0 && !original.endsWith(\"\\n\");\n const updated = original + (needsNewline ? \"\\n\" : \"\") + \"\\n\" + block + \"\\n\";\n fs.writeFileSync(gitignorePath, updated);\n return { status: \"success\", changed: true };\n}\n","import fs from \"node:fs\";\nimport dedent from \"dedent\";\nimport { SvelteFile } from \"../../../../runtime/svelte-file\";\nimport {\n ensureImports,\n withInMemoryScript,\n} from \"../../../../runtime/ts-morph-helpers\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\nimport type { Ui } from \"../../../../core/field/ui\";\n\nconst LANGUAGE_SELECT_SNIPPET = `<Navbar.Item>\n\t\t\t\t<LanguageSelect />\n\t\t\t</Navbar.Item>\n\t\t\t`;\n\nconst PLAIN_LANGUAGE_SELECT_SNIPPET = \"<LanguageSelect />\";\n\nconst IMPORT_SNIPPET = dedent`\n import LanguageSelect from '#lib/components/language-select.svelte';\n`;\n\nconst FAILURE_HINT = [\n \"Add the language select inside your <Navbar.List> in the root layout.\",\n \"\",\n \"Import to add to the <script> tag:\",\n \"\",\n IMPORT_SNIPPET,\n \"\",\n \"Markup to add at the end of <Navbar.List>:\",\n LANGUAGE_SELECT_SNIPPET,\n].join(\"\\n\");\n\nconst NOT_FOUND_HINT = [\n \"Create a root layout that includes a language select inside <Navbar.List>.\",\n \"\",\n \"Import for the <script> tag:\",\n \"\",\n IMPORT_SNIPPET,\n \"\",\n \"Markup at the end of <Navbar.List>:\",\n LANGUAGE_SELECT_SNIPPET,\n].join(\"\\n\");\n\nconst PLAIN_FAILURE_HINT = [\n \"Add the language select to your root layout.\",\n \"\",\n \"Import to add to the <script> tag:\",\n \"\",\n IMPORT_SNIPPET,\n \"\",\n \"Markup to add wherever it should render, e.g. above {@render children()}:\",\n \"\",\n PLAIN_LANGUAGE_SELECT_SNIPPET,\n].join(\"\\n\");\n\nconst PLAIN_NOT_FOUND_HINT = [\n \"Create a root layout that includes the language select.\",\n \"\",\n \"Import for the <script> tag:\",\n \"\",\n IMPORT_SNIPPET,\n \"\",\n \"Markup above {@render children()}:\",\n \"\",\n PLAIN_LANGUAGE_SELECT_SNIPPET,\n].join(\"\\n\");\n\nfunction addImport(file: SvelteFile): void {\n file.modifyScript((source) => {\n const { source: out } = withInMemoryScript(source, (sf) => {\n ensureImports(sf, [\n {\n defaultImport: \"LanguageSelect\",\n moduleSpecifier: \"#lib/components/language-select.svelte\",\n },\n ]);\n });\n return out;\n });\n}\n\n/**\n * A vela layout gets the select as the last `<Navbar.List>` item. A plain one\n * (a project vela did not create) has no navbar, so the select goes above the\n * layout's children.\n */\nexport function modifyRootLayoutLanguageSelect(\n layoutPath: string,\n ui: Ui = \"shadcn\",\n): ModifyOutcome {\n const plain = ui === \"plain\";\n if (!fs.existsSync(layoutPath)) {\n return {\n status: \"not-found\",\n message: plain ? PLAIN_NOT_FOUND_HINT : NOT_FOUND_HINT,\n };\n }\n\n const file = SvelteFile.fromPath(layoutPath);\n if (file.hasElement(\"LanguageSelect\")) {\n return { status: \"success\", changed: false };\n }\n\n if (plain) {\n // Without a <script> the import has nowhere to go, and the markup alone\n // would not compile.\n if (!file.getScript()) {\n return { status: \"failed\", message: PLAIN_FAILURE_HINT };\n }\n if (!file.insertBeforeChildren(PLAIN_LANGUAGE_SELECT_SNIPPET)) {\n return { status: \"failed\", message: PLAIN_FAILURE_HINT };\n }\n addImport(file);\n file.writeTo(layoutPath);\n return { status: \"success\", changed: file.hasChanged() };\n }\n\n if (!file.hasElement(\"Navbar.List\")) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n addImport(file);\n file.insertBeforeClosingTag(\"Navbar.List\", LANGUAGE_SELECT_SNIPPET);\n file.writeTo(layoutPath);\n return { status: \"success\", changed: file.hasChanged() };\n}\n","import fs from \"node:fs\";\nimport path from \"node:path\";\nimport type { File } from \"../../../core/types\";\nimport type { Ui } from \"../../../core/field/ui\";\n\nconst PAGE_PATH = \"src/routes/+page.svelte\";\nconst CATALOG_PATH = \"src/locales/es.po\";\n\n/** `src/routes/+page.svelte` as `sv create` writes it. */\nconst WELCOME_PAGE = [\n \"<h1>Welcome to SvelteKit</h1>\",\n '<p>Visit <a href=\"https://svelte.dev/docs/kit\">svelte.dev/docs/kit</a> to read the documentation</p>',\n].join(\"\\n\");\n\ninterface Entry {\n reference: string;\n msgid: string;\n msgstr: string;\n}\n\nconst PAGE_ENTRIES: Entry[] = [\n {\n reference: PAGE_PATH,\n msgid: \"Welcome to SvelteKit\",\n msgstr: \"Bienvenido a SvelteKit\",\n },\n {\n reference: PAGE_PATH,\n msgid: \"Visit <0>svelte.dev/docs/kit</0> to read the documentation\",\n msgstr: \"Visita <0>svelte.dev/docs/kit</0> para leer la documentación\",\n },\n];\n\n// The native <select>'s aria-label. The shadcn select has no text of its own:\n// locale names come from Intl.DisplayNames.\nconst PLAIN_SELECT_ENTRY: Entry = {\n reference: \"src/lib/components/language-select.svelte\",\n msgid: \"Language\",\n msgstr: \"Idioma\",\n};\n\n// What wuchale writes for `es`. It rewrites the file on the first extraction,\n// keeping these translations and adding the source locale's catalog.\nconst HEADER = [\n 'msgid \"\"',\n 'msgstr \"\"',\n '\"Source-Language: en\\\\n\"',\n '\"Language: es\\\\n\"',\n '\"MIME-Version: 1.0\\\\n\"',\n '\"Content-Type: text/plain; charset=utf-8\\\\n\"',\n '\"Content-Transfer-Encoding: 8bit\\\\n\"',\n '\"Plural-Forms: nplurals=3\\\\n\"',\n '\"X-Plurals-Order: one, many, other\\\\n\"',\n].join(\"\\n\");\n\n// Whitespace is ignored so a page prettier has rewrapped still counts.\nconst normalize = (source: string) => source.replace(/\\s+/g, \"\");\n\n/**\n * A Spanish catalog for the `sv create` welcome page, so the language select\n * visibly does something on a fresh project. Anything else in the project is\n * left for the user to translate. Null unless the page is untouched, and never\n * over an existing catalog.\n */\nexport function welcomePageCatalog(root: string, ui: Ui): File | null {\n if (fs.existsSync(path.join(root, CATALOG_PATH))) return null;\n\n const pagePath = path.join(root, PAGE_PATH);\n if (!fs.existsSync(pagePath)) return null;\n const page = fs.readFileSync(pagePath, \"utf8\");\n if (normalize(page) !== normalize(WELCOME_PAGE)) return null;\n\n const entries =\n ui === \"plain\" ? [...PAGE_ENTRIES, PLAIN_SELECT_ENTRY] : PAGE_ENTRIES;\n const blocks = entries.map((entry) =>\n [\n `#: ${entry.reference}`,\n `msgid \"${entry.msgid}\"`,\n `msgstr \"${entry.msgstr}\"`,\n ].join(\"\\n\"),\n );\n\n return {\n path: CATALOG_PATH,\n language: \"text\",\n content: [HEADER, ...blocks].join(\"\\n\\n\") + \"\\n\",\n status: \"success\",\n };\n}\n","import fs from \"node:fs\";\nimport path from \"node:path\";\nimport type { File, Options, Result } from \"../../../core/types\";\nimport { getLogger } from \"../../../core/logger\";\nimport { resolveUi } from \"../../../core/field/ui\";\nimport { modifyOutcomeToFile } from \"../../../runtime/modify-file\";\nimport {\n probeFirstExisting,\n VITE_CONFIG_CANDIDATES,\n} from \"../../../runtime/config-target\";\nimport { modifyViteConfig } from \"./modifies/vite-config\";\nimport { modifyPackageImportsI18n } from \"./modifies/package-imports\";\nimport { modifyHooksServerI18n } from \"./modifies/hooks.server\";\nimport { modifyHooksI18n } from \"./modifies/hooks\";\nimport { modifyAppHtml } from \"./modifies/app-html\";\nimport { modifyGitignore } from \"./modifies/gitignore\";\nimport { modifyPrettierignore } from \"./modifies/prettierignore\";\nimport { ensureRootLayoutI18n } from \"./modifies/+layout\";\nimport { modifyRootLayoutLanguageSelect } from \"./modifies/root-layout.svelte\";\nimport { modifyLayoutServerLocale } from \"./modifies/layout.server\";\nimport { modifyAppDts } from \"./modifies/app-d-ts\";\nimport {\n APP_LAYOUT_PATH,\n modifyAppLayoutLanguageSelect,\n} from \"./modifies/app-layout.svelte\";\nimport { welcomePageCatalog } from \"./welcome-catalog\";\nimport {\n entriesInProject,\n translateCatalog,\n withTranslations,\n} from \"../../../runtime/wuchale-catalog\";\nimport { AUTH_TRANSLATIONS } from \"../auth/translations\";\nimport {\n TRANSLATED_LIB_FILES,\n withWuchaleJsFiles,\n} from \"../../../runtime/wuchale-config\";\n\n/**\n * The `wuchale.config.js` create, with the library modules that carry\n * visitor-facing text and already exist in the project (the WhatsApp order\n * message, say) listed for the js adapter. A pattern enabled later adds its\n * own module to the written config.\n */\nexport function withLibraryTexts(root: string, creates: File[]): File[] {\n const present = TRANSLATED_LIB_FILES.filter((file) =>\n fs.existsSync(path.join(root, file)),\n );\n if (present.length === 0) return creates;\n return creates.map((file) => {\n if (!file.path.endsWith(\"wuchale.config.js\")) return file;\n const edited = withWuchaleJsFiles(file.content, present);\n return edited?.changed ? { ...file, content: edited.source } : file;\n });\n}\n\nexport async function generate(options: Options) {\n const logger = getLogger(options);\n const modifies: File[] = [];\n\n const pushResult = (file: File | null) => {\n if (file) modifies.push(file);\n };\n\n logger.info(\"Modifying vite.config\");\n const viteConfigPath =\n probeFirstExisting(options.root, VITE_CONFIG_CANDIDATES) ??\n path.join(options.root, VITE_CONFIG_CANDIDATES[0]);\n pushResult(\n modifyOutcomeToFile(viteConfigPath, modifyViteConfig(viteConfigPath)),\n );\n\n logger.info(\"Adding #locales to package.json imports\");\n const imports = modifyPackageImportsI18n(options.root);\n pushResult(modifyOutcomeToFile(imports.filePath, imports.outcome));\n\n logger.info(\"Modifying hooks.server.ts\");\n const hooksServerPath = path.join(options.root, \"src\", \"hooks.server.ts\");\n pushResult(\n modifyOutcomeToFile(\n hooksServerPath,\n modifyHooksServerI18n(hooksServerPath),\n ),\n );\n\n logger.info(\"Modifying hooks.ts\");\n const hooksPath = path.join(options.root, \"src\", \"hooks.ts\");\n pushResult(modifyOutcomeToFile(hooksPath, modifyHooksI18n(hooksPath)));\n\n logger.info(\"Modifying app.html\");\n const appHtmlPath = path.join(options.root, \"src\", \"app.html\");\n pushResult(modifyOutcomeToFile(appHtmlPath, modifyAppHtml(appHtmlPath)));\n\n logger.info(\"Declaring the request's language in app.d.ts\");\n const appDtsPath = path.join(options.root, \"src\", \"app.d.ts\");\n pushResult(modifyOutcomeToFile(appDtsPath, modifyAppDts(appDtsPath)));\n\n logger.info(\"Modifying root +layout.server.ts\");\n const layoutServerPath = path.join(\n options.root,\n \"src\",\n \"routes\",\n \"+layout.server.ts\",\n );\n pushResult(\n modifyOutcomeToFile(\n layoutServerPath,\n modifyLayoutServerLocale(layoutServerPath),\n ),\n );\n\n logger.info(\"Modifying root +layout.ts\");\n const layoutPath = path.join(options.root, \"src\", \"routes\", \"+layout.ts\");\n pushResult(modifyOutcomeToFile(layoutPath, ensureRootLayoutI18n(layoutPath)));\n\n logger.info(\"Modifying root layout language select\");\n const rootLayoutCandidates = [\n path.join(options.root, \"src\", \"routes\", \"(public)\", \"root-layout.svelte\"),\n path.join(options.root, \"src\", \"routes\", \"root-layout.svelte\"),\n path.join(options.root, \"src\", \"routes\", \"(public)\", \"+layout.svelte\"),\n path.join(options.root, \"src\", \"routes\", \"+layout.svelte\"),\n ];\n const ui = resolveUi(options);\n // With no layout at all, a plain project's not-found hint names the\n // +layout.svelte it would have rather than vela's root-layout.svelte.\n const rootLayoutPath =\n rootLayoutCandidates.find((p) => fs.existsSync(p)) ??\n (ui === \"plain\" ? rootLayoutCandidates[3] : rootLayoutCandidates[0]);\n pushResult(\n modifyOutcomeToFile(\n rootLayoutPath,\n modifyRootLayoutLanguageSelect(rootLayoutPath, ui),\n ),\n );\n\n // Signed-in pages have one URL for every language; the select is how a\n // visitor changes it there.\n const appLayoutPath = path.join(options.root, APP_LAYOUT_PATH);\n if (fs.existsSync(appLayoutPath)) {\n logger.info(\"Adding the language select to the signed-in layout\");\n pushResult(\n modifyOutcomeToFile(\n appLayoutPath,\n modifyAppLayoutLanguageSelect(appLayoutPath),\n ),\n );\n }\n\n logger.info(\"Updating .gitignore\");\n const gitignorePath = path.join(options.root, \".gitignore\");\n pushResult(\n modifyOutcomeToFile(gitignorePath, modifyGitignore(gitignorePath)),\n );\n\n logger.info(\"Updating .prettierignore\");\n const prettierignorePath = path.join(options.root, \".prettierignore\");\n pushResult(\n modifyOutcomeToFile(\n prettierignorePath,\n modifyPrettierignore(prettierignorePath),\n ),\n );\n\n const catalog = welcomePageCatalog(options.root, ui);\n if (catalog) logger.info(\"Translating the welcome page into Spanish\");\n\n // Spanish for the pages other patterns wrote before this one: without it\n // they stay in English, and nothing says so.\n const shipped = entriesInProject(options.root, AUTH_TRANSLATIONS);\n if (shipped.length > 0)\n logger.info(\"Translating the sign-in pages into Spanish\");\n const creates: File[] = [];\n if (catalog) {\n const content = withTranslations(catalog.content, shipped).source;\n creates.push({ ...catalog, content });\n } else {\n const translated = translateCatalog(options.root, shipped);\n if (translated.create) creates.push(translated.create);\n pushResult(translated.modify);\n }\n\n return {\n creates,\n modifies,\n deletes: [],\n components: [],\n packages: [],\n collections: [],\n collectionPatches: [],\n collectionDrops: [],\n } satisfies Result;\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAKA,IAAMA,IAAe,oLAUfC,IAAiB;AAWvB,SAAgBkC,GAAiB,GAAuC;CACtE,IAAI,CAACJ,EAAG,WAAWK,CAAc,GAC/B,OAAO;EAAE,QAAQ;EAAa,SAASnC;CAAe;CAOxD,IAAMoC,IAAa,IAJCC,EAAQ;EAC1B,iBAAiB,EAAE,SAAS,GAAK;EACjC,sBAAsB,EAAE,WAAWC,EAAU,OAAO;CACtD,CACmB,CAAA,CAAQ,oBAAoBH,CAAc,GAEzDI,IAAU,IACVC,IAAS;CAMb,AAJkBJ,EACf,sBAAsB,CAAC,CACvB,MAAM,MAAMK,EAAE,wBAAwB,MAAM,cAE1C,MACHL,EAAW,wBAAwB,GAAG;EACpC,cAAc,CAAC,SAAS;EACxB,iBAAiB;CACnB,CAAC,GACD,IAAU;CAOZ,IAAMM,IAJmBN,EACtB,qBAAqBO,EAAW,cAAc,CAAC,CAC/C,MAAM,MAAOC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H,GAAqBwH,CAAkB,CACzC,CACF;CAEA,IAAMC,IAAUtB,GAAmBU,EAAQ,MAAMpB,CAAE;CACnD,AAAIgC,KAASb,EAAO,KAAK,2CAA2C;CAIpE,IAAMc,IAAUhH,GAAiBmG,EAAQ,MAAMlG,CAAiB;CAChE,AAAI+G,EAAQ,SAAS,KACnBd,EAAO,KAAK,4CAA4C;CAC1D,IAAMH,IAAkB,CAAC;CACzB,IAAIgB,GAAS;EACX,IAAME,IAAUnH,GAAiBiH,EAAQ,SAASC,CAAO,CAAC,CAAC;EAC3D,EAAQ,KAAK;GAAE,GAAGD;GAAS;EAAQ,CAAC;CACtC,OAAO;EACL,IAAMG,IAAanH,GAAiBoG,EAAQ,MAAMa,CAAO;EAEzD,AADIE,EAAW,UAAQnB,EAAQ,KAAKmB,EAAW,MAAM,GACrDb,EAAWa,EAAW,MAAM;CAC9B;CAEA,OAAO;EACL;EACA;EACA,SAAS,CAAC;EACV,YAAY,CAAC;EACb,UAAU,CAAC;EACX,aAAa,CAAC;EACd,mBAAmB,CAAC;EACpB,iBAAiB,CAAC;CACpB;AACF"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { n as e } from "./logger-t1HxmpG2.js";
|
|
2
2
|
import { r as t } from "./modify-file-CRZ_gMg0.js";
|
|
3
|
-
import { c as n, i as r, n as i, o as a, r as o, t as s } from "./test-setup-
|
|
3
|
+
import { c as n, i as r, n as i, o as a, r as o, t as s } from "./test-setup-cZj1tqaf.js";
|
|
4
4
|
import { a as c } from "./util-ILWdjRAd.js";
|
|
5
5
|
import { t as l } from "./dedent-CCUOcPFW.js";
|
|
6
6
|
import { r as u } from "./compose-handle-Da7m6lV_.js";
|
|
@@ -158,4 +158,4 @@ async function k(l) {
|
|
|
158
158
|
}
|
|
159
159
|
export { k as generate };
|
|
160
160
|
|
|
161
|
-
//# sourceMappingURL=generate.runtime-
|
|
161
|
+
//# sourceMappingURL=generate.runtime-C_SdcnRs.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate.runtime-BEmSIAop.js","names":["getLogger","modifyOutcomeToFile","modifySvelteConfig","modifyTestSetup","WITH_BACKEND","modifyGitignore","hasVitestConfig","VITEST_CONFIG","languageFromPath","dedent","replaceHandle","pruneUnusedImports","ensureNamedImport","ensureBlankLineAfterImports","formatLikeSource","BACKEND_ENV_VARS","fs","path","POCKETBASE_TYPES","VITEST_CONFIGS","ext","modifyTsconfigBackend","filePath","root","original","vitestConfig","name","wanted","config","entry","include","normalize","has","existing","next","insertAfter","index","after","i","indent","POCKETBASE_ENV_NAMES","POCKETBASE_HANDLE","FAILURE_HINT","modifyHooksServerBackend","hooksServerPath","sourceFile","Project","QuoteKind","composed","statement","Node","doc","generate","logger","options","modifies","creates","create","adapter","svelteConfigFile","hooksServerFile","envVars","modifyEnvVarsFiles","gitignorePath","gitignoreFile","testSetupPath","testSetupFile","tsconfigPath","tsconfigFile"],"sources":["../../src/patterns/enable/backend/modifies/tsconfig.ts","../../src/patterns/enable/backend/modifies/hooks.server.ts","../../src/patterns/enable/backend/generate.runtime.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport path from \"node:path\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\n/** Where `vela sync` writes PocketBase's generated types (`Schemas`, the typed client). */\nexport const POCKETBASE_TYPES = \".svelte-kit/types/pocketbase/*.d.ts\";\n\nconst VITEST_CONFIGS = [\"ts\", \"mts\", \"js\", \"mjs\"].map(\n (ext) => `vitest.config.${ext}`,\n);\n\n/**\n * SvelteKit 3's `$app/tsconfig` lists no files: the project's own `include`\n * decides what is type-checked, and `sv create` writes `[\"src\",\n * \"vite.config.ts\"]`. A backend adds three things that have to be in it, as\n * they are in vela's minimal template: `test` (the server-test context that\n * every `server.test.ts` reads), the vitest config, and PocketBase's generated\n * types, without which `Schemas` is missing from `@velastack/pocketbase`.\n *\n * Entries already there stay, in their order. A tsconfig with no `include`\n * checks everything already; one that is not plain JSON (comments) is left\n * alone with the entries to add.\n */\nexport function modifyTsconfigBackend(root: string): ModifyOutcome {\n const filePath = path.join(root, \"tsconfig.json\");\n if (!fs.existsSync(filePath)) {\n return { status: \"success\", changed: false };\n }\n const original = fs.readFileSync(filePath, \"utf8\");\n const vitestConfig =\n VITEST_CONFIGS.find((name) => fs.existsSync(path.join(root, name))) ??\n \"vitest.config.ts\";\n const wanted = [\"test\", vitestConfig, POCKETBASE_TYPES];\n\n let config: Record<string, unknown>;\n try {\n config = JSON.parse(original) as Record<string, unknown>;\n } catch {\n return {\n status: \"failed\",\n message: `Add these to the \"include\" array of tsconfig.json: ${wanted\n .map((entry) => JSON.stringify(entry))\n .join(\", \")}`,\n };\n }\n const include = config.include;\n if (include === undefined) {\n return { status: \"success\", changed: false };\n }\n if (!Array.isArray(include)) {\n return {\n status: \"failed\",\n message: `tsconfig.json \"include\" is not an array; it needs ${wanted.join(\", \")}`,\n };\n }\n\n const normalize = (entry: unknown) =>\n typeof entry === \"string\" ? entry.replace(/^\\.\\//, \"\") : entry;\n const has = (entry: string) =>\n include.some((existing) => normalize(existing) === entry);\n const next = [...include] as unknown[];\n const insertAfter = (entry: string, after: (e: unknown) => boolean) => {\n if (has(entry)) return;\n let index = -1;\n next.forEach((e, i) => {\n if (after(e)) index = i;\n });\n next.splice(index === -1 ? next.length : index + 1, 0, entry);\n };\n insertAfter(\"test\", (e) => normalize(e) === \"src\");\n insertAfter(vitestConfig, (e) =>\n /^vite\\.config\\.[cm]?[jt]s$/.test(String(normalize(e))),\n );\n insertAfter(POCKETBASE_TYPES, () => false);\n\n if (next.length === include.length) {\n return { status: \"success\", changed: false };\n }\n config.include = next;\n const indent = original.match(/^\\{\\s*\\n([\\t ]+)/)?.[1] ?? \"\\t\";\n fs.writeFileSync(filePath, `${JSON.stringify(config, null, indent)}\\n`);\n return { status: \"success\", changed: true };\n}\n","import fs from \"node:fs\";\nimport dedent from \"dedent\";\nimport { Node, Project, QuoteKind } from \"ts-morph\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\nimport { replaceHandle } from \"../../../../runtime/compose-handle\";\nimport {\n ensureBlankLineAfterImports,\n ensureNamedImport,\n pruneUnusedImports,\n formatLikeSource,\n} from \"../../../../runtime/ts-morph-helpers\";\n\n/** The variables the handle reads, imported from `$app/env/private`. */\nexport const POCKETBASE_ENV_NAMES = [\n \"POCKETBASE_URL\",\n \"POCKETBASE_SUPERUSER_EMAIL\",\n \"POCKETBASE_SUPERUSER_PASSWORD\",\n] as const;\n\n/** The handle `creates/src/hooks.server.ts` exports, for a file that already exists. */\nexport const POCKETBASE_HANDLE = dedent`\n handlePocketbase({\n \tpocketbaseUrl: POCKETBASE_URL,\n \tsuperuserEmail: POCKETBASE_SUPERUSER_EMAIL,\n \tsuperuserPassword: POCKETBASE_SUPERUSER_PASSWORD\n })\n`;\n\nconst FAILURE_HINT = dedent`\n Add the PocketBase handle to the exported handle in src/hooks.server.ts:\n\n import { sequence } from '@sveltejs/kit/hooks';\n import {\n \tPOCKETBASE_URL,\n \tPOCKETBASE_SUPERUSER_EMAIL,\n \tPOCKETBASE_SUPERUSER_PASSWORD\n } from '$app/env/private';\n import { handlePocketbase } from '@velastack/pocketbase';\n\n export const handle = sequence(\n \t/* your existing handle */,\n \t${POCKETBASE_HANDLE.replace(/\\n/g, \"\\n\\t\")}\n );\n`;\n\n/**\n * Compose the PocketBase handle into a `hooks.server.ts` the project already\n * has, instead of the create overwriting it: a static site's, or one i18n or\n * content negotiation wrote. It takes `handleStatic()`'s place, since\n * `handlePocketbase` does what that did and more; otherwise it goes last, so\n * the handles already there keep running first.\n */\nexport function modifyHooksServerBackend(\n hooksServerPath: string,\n): ModifyOutcome {\n if (!fs.existsSync(hooksServerPath)) {\n // The create writes it.\n return { status: \"success\", changed: false };\n }\n\n const original = fs.readFileSync(hooksServerPath, \"utf8\");\n const project = new Project({\n compilerOptions: { allowJs: true },\n manipulationSettings: { quoteKind: QuoteKind.Single },\n });\n const sourceFile = project.addSourceFileAtPath(hooksServerPath);\n\n const composed = replaceHandle(sourceFile, \"handleStatic\", {\n expression: POCKETBASE_HANDLE,\n name: \"handlePocketbase\",\n position: \"last\",\n });\n if (composed.status === \"unsupported\") {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n if (composed.status === \"unchanged\") {\n return { status: \"success\", changed: false };\n }\n\n // The static template's comment explains handleStatic(). Where that was the\n // whole handle, replaceHandle already dropped it; in a sequence (i18n or\n // negotiation composed in since) it is still there, describing a handle\n // that is gone.\n const statement = composed.statement;\n if (statement && Node.isJSDocable(statement)) {\n for (const doc of statement.getJsDocs()) {\n if (doc.getText().includes(\"vela legal\")) doc.remove();\n }\n }\n\n pruneUnusedImports(sourceFile, [\"@velastack/kit\"]);\n for (const name of POCKETBASE_ENV_NAMES) {\n ensureNamedImport(sourceFile, \"$app/env/private\", name);\n }\n ensureNamedImport(sourceFile, \"@velastack/pocketbase\", \"handlePocketbase\");\n\n formatLikeSource(sourceFile);\n ensureBlankLineAfterImports(sourceFile);\n sourceFile.saveSync();\n return {\n status: \"success\",\n changed: sourceFile.getFullText() !== original,\n };\n}\n","import fs from \"node:fs\";\nimport path from \"node:path\";\nimport type { File, Options, Result } from \"../../../core/types\";\nimport { getLogger } from \"../../../core/logger\";\nimport { modifyOutcomeToFile } from \"../../../runtime/modify-file\";\nimport { modifySvelteConfig } from \"./modifies/svelte-config\";\nimport { modifyGitignore } from \"./modifies/gitignore\";\nimport { modifyTsconfigBackend } from \"./modifies/tsconfig\";\nimport { languageFromPath } from \"../../../core/util\";\nimport {\n hasVitestConfig,\n modifyTestSetup,\n VITEST_CONFIG,\n WITH_BACKEND,\n} from \"./modifies/test-setup\";\nimport { modifyHooksServerBackend } from \"./modifies/hooks.server\";\nimport { modifyEnvVarsFiles } from \"../../../runtime/env-vars\";\nimport { BACKEND_ENV_VARS } from \"./env-vars\";\n\nexport async function generate(options: Options) {\n const logger = getLogger(options);\n const modifies: File[] = [];\n const creates: File[] = [];\n const create = (filePath: string, content: string) =>\n creates.push({\n path: filePath,\n language: languageFromPath(filePath),\n content,\n status: \"success\",\n });\n\n logger.info(\"Modifying adapter config\");\n const adapter = modifySvelteConfig(options.root);\n const svelteConfigFile = modifyOutcomeToFile(\n adapter.filePath,\n adapter.outcome,\n );\n if (svelteConfigFile) modifies.push(svelteConfigFile);\n\n // A hooks.server.ts the project already has keeps its handles; the create\n // only writes the file where there is none (see `keepMissing` in index.ts).\n const hooksServerPath = path.join(options.root, \"src\", \"hooks.server.ts\");\n const hooksServerFile = modifyOutcomeToFile(\n hooksServerPath,\n modifyHooksServerBackend(hooksServerPath),\n );\n if (hooksServerFile) {\n logger.info(\"Modifying hooks.server.ts\");\n modifies.push(hooksServerFile);\n }\n\n // SvelteKit 3 exposes only declared variables: the handle above reads\n // these three from `$app/env/private`.\n logger.info(\"Declaring the PocketBase variables in src/env.ts\");\n const envVars = modifyEnvVarsFiles(options.root, BACKEND_ENV_VARS);\n if (envVars.create) creates.push(envVars.create);\n if (envVars.modify) modifies.push(envVars.modify);\n\n logger.info(\"Modifying .gitignore\");\n const gitignorePath = path.join(options.root, \".gitignore\");\n const gitignoreFile = modifyOutcomeToFile(\n gitignorePath,\n modifyGitignore(gitignorePath),\n );\n if (gitignoreFile) modifies.push(gitignoreFile);\n\n // A backend brings server tests with it. The static template and a project\n // vela did not create have no harness at all, so what is missing is created:\n // the setup file, and the vitest config that loads it.\n const testSetupPath = path.join(options.root, \"test\", \"setup.ts\");\n if (fs.existsSync(testSetupPath)) {\n logger.info(\"Modifying test/setup.ts\");\n const testSetupFile = modifyOutcomeToFile(\n testSetupPath,\n modifyTestSetup(testSetupPath),\n );\n if (testSetupFile) modifies.push(testSetupFile);\n } else {\n logger.info(\"Creating test/setup.ts\");\n create(\"test/setup.ts\", WITH_BACKEND);\n }\n\n if (!hasVitestConfig(options.root)) {\n logger.info(\"Creating vitest.config.ts\");\n create(\"vitest.config.ts\", VITEST_CONFIG);\n }\n\n // Kit 3's tsconfig lists no files, so the test harness and PocketBase's\n // generated types are type-checked only when the project's include names them.\n const tsconfigPath = path.join(options.root, \"tsconfig.json\");\n const tsconfigFile = modifyOutcomeToFile(\n tsconfigPath,\n modifyTsconfigBackend(options.root),\n );\n if (tsconfigFile) {\n logger.info(\"Modifying tsconfig.json\");\n modifies.push(tsconfigFile);\n }\n\n return {\n creates,\n modifies,\n deletes: [],\n components: [],\n packages: [],\n collections: [],\n collectionPatches: [],\n collectionDrops: [],\n } satisfies Result;\n}\n"],"mappings":";;;;;;;;;;;;;AAKA,IAAakB,IAAmB,uCAE1BC,IAAiB;CAAC;CAAM;CAAO;CAAM;AAAK,CAAC,CAAC,KAC/C,MAAQ,iBAAiBC,GAC5B;AAcA,SAAgBC,EAAsB,GAA6B;CACjE,IAAMC,IAAWL,EAAK,KAAKM,GAAM,eAAe;CAChD,IAAI,CAACP,EAAG,WAAWM,CAAQ,GACzB,OAAO;EAAE,QAAQ;EAAW,SAAS;CAAM;CAE7C,IAAME,IAAWR,EAAG,aAAaM,GAAU,MAAM,GAC3CG,IACJN,EAAe,MAAM,MAASH,EAAG,WAAWC,EAAK,KAAKM,GAAMG,CAAI,CAAC,CAAC,KAClE,oBACIC,IAAS;EAAC;EAAQF;EAAcP;CAAgB,GAElDU;CACJ,IAAI;EACF,IAAS,KAAK,MAAMJ,CAAQ;CAC9B,QAAQ;EACN,OAAO;GACL,QAAQ;GACR,SAAS,sDAAsDG,EAC5D,KAAK,MAAU,KAAK,UAAUE,CAAK,CAAC,CAAC,CACrC,KAAK,IAAI;EACd;CACF;CACA,IAAMC,IAAUF,EAAO;CACvB,IAAIE,MAAY,KAAA,GACd,OAAO;EAAE,QAAQ;EAAW,SAAS;CAAM;CAE7C,IAAI,CAAC,MAAM,QAAQA,CAAO,GACxB,OAAO;EACL,QAAQ;EACR,SAAS,qDAAqDH,EAAO,KAAK,IAAI;CAChF;CAGF,IAAMI,KAAa,MACjB,OAAOF,KAAU,WAAWA,EAAM,QAAQ,SAAS,EAAE,IAAIA,GACrDG,KAAO,MACXF,EAAQ,MAA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Ae,IAK/BP,EAAO,KAAK,kDAAkD;CAC9D,IAAMQ,IAAUC,EAAmBR,EAAQ,MAAMvC,CAAgB;CAIjE,AAHI8C,EAAQ,UAAQL,EAAQ,KAAKK,EAAQ,MAAM,GAC3CA,EAAQ,UAAQN,EAAS,KAAKM,EAAQ,MAAM,GAEhDR,EAAO,KAAK,sBAAsB;CAClC,IAAMU,IAAgB9C,EAAK,KAAKqC,EAAQ,MAAM,YAAY,GACpDU,IAAgB/D,EACpB8D,GACA1D,EAAgB0D,CAAa,CAC/B;CACA,AAAIC,KAAeT,EAAS,KAAKS,CAAa;CAK9C,IAAMC,IAAgBhD,EAAK,KAAKqC,EAAQ,MAAM,QAAQ,UAAU;CAChE,IAAItC,EAAG,WAAWiD,CAAa,GAAG;EAChC,EAAO,KAAK,yBAAyB;EACrC,IAAMC,IAAgBjE,EACpBgE,GACA9D,EAAgB8D,CAAa,CAC/B;EACA,AAAIC,KAAeX,EAAS,KAAKW,CAAa;CAChD,OAEE,AADAb,EAAO,KAAK,wBAAwB,GACpCI,EAAO,iBAAiBrD,CAAY;CAGtC,AAAKE,EAAgBgD,EAAQ,IAAI,MAC/BD,EAAO,KAAK,2BAA2B,GACvCI,EAAO,oBAAoBlD,CAAa;CAK1C,IAAM4D,IAAelD,EAAK,KAAKqC,EAAQ,MAAM,eAAe,GACtDc,IAAenE,EACnBkE,GACA9C,EAAsBiC,EAAQ,IAAI,CACpC;CAMA,OALIc,MACFf,EAAO,KAAK,yBAAyB,GACrCE,EAAS,KAAKa,CAAY,IAGrB;EACL;EACA;EACA,SAAS,CAAC;EACV,YAAY,CAAC;EACb,UAAU,CAAC;EACX,aAAa,CAAC;EACd,mBAAmB,CAAC;EACpB,iBAAiB,CAAC;CACpB;AACF"}
|
|
1
|
+
{"version":3,"file":"generate.runtime-C_SdcnRs.js","names":["getLogger","modifyOutcomeToFile","modifySvelteConfig","modifyTestSetup","WITH_BACKEND","modifyGitignore","hasVitestConfig","VITEST_CONFIG","languageFromPath","dedent","replaceHandle","pruneUnusedImports","ensureNamedImport","ensureBlankLineAfterImports","formatLikeSource","BACKEND_ENV_VARS","fs","path","POCKETBASE_TYPES","VITEST_CONFIGS","ext","modifyTsconfigBackend","filePath","root","original","vitestConfig","name","wanted","config","entry","include","normalize","has","existing","next","insertAfter","index","after","i","indent","POCKETBASE_ENV_NAMES","POCKETBASE_HANDLE","FAILURE_HINT","modifyHooksServerBackend","hooksServerPath","sourceFile","Project","QuoteKind","composed","statement","Node","doc","generate","logger","options","modifies","creates","create","adapter","svelteConfigFile","hooksServerFile","envVars","modifyEnvVarsFiles","gitignorePath","gitignoreFile","testSetupPath","testSetupFile","tsconfigPath","tsconfigFile"],"sources":["../../src/patterns/enable/backend/modifies/tsconfig.ts","../../src/patterns/enable/backend/modifies/hooks.server.ts","../../src/patterns/enable/backend/generate.runtime.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport path from \"node:path\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\n/** Where `vela sync` writes PocketBase's generated types (`Schemas`, the typed client). */\nexport const POCKETBASE_TYPES = \".svelte-kit/types/pocketbase/*.d.ts\";\n\nconst VITEST_CONFIGS = [\"ts\", \"mts\", \"js\", \"mjs\"].map(\n (ext) => `vitest.config.${ext}`,\n);\n\n/**\n * SvelteKit 3's `$app/tsconfig` lists no files: the project's own `include`\n * decides what is type-checked, and `sv create` writes `[\"src\",\n * \"vite.config.ts\"]`. A backend adds three things that have to be in it, as\n * they are in vela's minimal template: `test` (the server-test context that\n * every `server.test.ts` reads), the vitest config, and PocketBase's generated\n * types, without which `Schemas` is missing from `@velastack/pocketbase`.\n *\n * Entries already there stay, in their order. A tsconfig with no `include`\n * checks everything already; one that is not plain JSON (comments) is left\n * alone with the entries to add.\n */\nexport function modifyTsconfigBackend(root: string): ModifyOutcome {\n const filePath = path.join(root, \"tsconfig.json\");\n if (!fs.existsSync(filePath)) {\n return { status: \"success\", changed: false };\n }\n const original = fs.readFileSync(filePath, \"utf8\");\n const vitestConfig =\n VITEST_CONFIGS.find((name) => fs.existsSync(path.join(root, name))) ??\n \"vitest.config.ts\";\n const wanted = [\"test\", vitestConfig, POCKETBASE_TYPES];\n\n let config: Record<string, unknown>;\n try {\n config = JSON.parse(original) as Record<string, unknown>;\n } catch {\n return {\n status: \"failed\",\n message: `Add these to the \"include\" array of tsconfig.json: ${wanted\n .map((entry) => JSON.stringify(entry))\n .join(\", \")}`,\n };\n }\n const include = config.include;\n if (include === undefined) {\n return { status: \"success\", changed: false };\n }\n if (!Array.isArray(include)) {\n return {\n status: \"failed\",\n message: `tsconfig.json \"include\" is not an array; it needs ${wanted.join(\", \")}`,\n };\n }\n\n const normalize = (entry: unknown) =>\n typeof entry === \"string\" ? entry.replace(/^\\.\\//, \"\") : entry;\n const has = (entry: string) =>\n include.some((existing) => normalize(existing) === entry);\n const next = [...include] as unknown[];\n const insertAfter = (entry: string, after: (e: unknown) => boolean) => {\n if (has(entry)) return;\n let index = -1;\n next.forEach((e, i) => {\n if (after(e)) index = i;\n });\n next.splice(index === -1 ? next.length : index + 1, 0, entry);\n };\n insertAfter(\"test\", (e) => normalize(e) === \"src\");\n insertAfter(vitestConfig, (e) =>\n /^vite\\.config\\.[cm]?[jt]s$/.test(String(normalize(e))),\n );\n insertAfter(POCKETBASE_TYPES, () => false);\n\n if (next.length === include.length) {\n return { status: \"success\", changed: false };\n }\n config.include = next;\n const indent = original.match(/^\\{\\s*\\n([\\t ]+)/)?.[1] ?? \"\\t\";\n fs.writeFileSync(filePath, `${JSON.stringify(config, null, indent)}\\n`);\n return { status: \"success\", changed: true };\n}\n","import fs from \"node:fs\";\nimport dedent from \"dedent\";\nimport { Node, Project, QuoteKind } from \"ts-morph\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\nimport { replaceHandle } from \"../../../../runtime/compose-handle\";\nimport {\n ensureBlankLineAfterImports,\n ensureNamedImport,\n pruneUnusedImports,\n formatLikeSource,\n} from \"../../../../runtime/ts-morph-helpers\";\n\n/** The variables the handle reads, imported from `$app/env/private`. */\nexport const POCKETBASE_ENV_NAMES = [\n \"POCKETBASE_URL\",\n \"POCKETBASE_SUPERUSER_EMAIL\",\n \"POCKETBASE_SUPERUSER_PASSWORD\",\n] as const;\n\n/** The handle `creates/src/hooks.server.ts` exports, for a file that already exists. */\nexport const POCKETBASE_HANDLE = dedent`\n handlePocketbase({\n \tpocketbaseUrl: POCKETBASE_URL,\n \tsuperuserEmail: POCKETBASE_SUPERUSER_EMAIL,\n \tsuperuserPassword: POCKETBASE_SUPERUSER_PASSWORD\n })\n`;\n\nconst FAILURE_HINT = dedent`\n Add the PocketBase handle to the exported handle in src/hooks.server.ts:\n\n import { sequence } from '@sveltejs/kit/hooks';\n import {\n \tPOCKETBASE_URL,\n \tPOCKETBASE_SUPERUSER_EMAIL,\n \tPOCKETBASE_SUPERUSER_PASSWORD\n } from '$app/env/private';\n import { handlePocketbase } from '@velastack/pocketbase';\n\n export const handle = sequence(\n \t/* your existing handle */,\n \t${POCKETBASE_HANDLE.replace(/\\n/g, \"\\n\\t\")}\n );\n`;\n\n/**\n * Compose the PocketBase handle into a `hooks.server.ts` the project already\n * has, instead of the create overwriting it: a static site's, or one i18n or\n * content negotiation wrote. It takes `handleStatic()`'s place, since\n * `handlePocketbase` does what that did and more; otherwise it goes last, so\n * the handles already there keep running first.\n */\nexport function modifyHooksServerBackend(\n hooksServerPath: string,\n): ModifyOutcome {\n if (!fs.existsSync(hooksServerPath)) {\n // The create writes it.\n return { status: \"success\", changed: false };\n }\n\n const original = fs.readFileSync(hooksServerPath, \"utf8\");\n const project = new Project({\n compilerOptions: { allowJs: true },\n manipulationSettings: { quoteKind: QuoteKind.Single },\n });\n const sourceFile = project.addSourceFileAtPath(hooksServerPath);\n\n const composed = replaceHandle(sourceFile, \"handleStatic\", {\n expression: POCKETBASE_HANDLE,\n name: \"handlePocketbase\",\n position: \"last\",\n });\n if (composed.status === \"unsupported\") {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n if (composed.status === \"unchanged\") {\n return { status: \"success\", changed: false };\n }\n\n // The static template's comment explains handleStatic(). Where that was the\n // whole handle, replaceHandle already dropped it; in a sequence (i18n or\n // negotiation composed in since) it is still there, describing a handle\n // that is gone.\n const statement = composed.statement;\n if (statement && Node.isJSDocable(statement)) {\n for (const doc of statement.getJsDocs()) {\n if (doc.getText().includes(\"vela legal\")) doc.remove();\n }\n }\n\n pruneUnusedImports(sourceFile, [\"@velastack/kit\"]);\n for (const name of POCKETBASE_ENV_NAMES) {\n ensureNamedImport(sourceFile, \"$app/env/private\", name);\n }\n ensureNamedImport(sourceFile, \"@velastack/pocketbase\", \"handlePocketbase\");\n\n formatLikeSource(sourceFile);\n ensureBlankLineAfterImports(sourceFile);\n sourceFile.saveSync();\n return {\n status: \"success\",\n changed: sourceFile.getFullText() !== original,\n };\n}\n","import fs from \"node:fs\";\nimport path from \"node:path\";\nimport type { File, Options, Result } from \"../../../core/types\";\nimport { getLogger } from \"../../../core/logger\";\nimport { modifyOutcomeToFile } from \"../../../runtime/modify-file\";\nimport { modifySvelteConfig } from \"./modifies/svelte-config\";\nimport { modifyGitignore } from \"./modifies/gitignore\";\nimport { modifyTsconfigBackend } from \"./modifies/tsconfig\";\nimport { languageFromPath } from \"../../../core/util\";\nimport {\n hasVitestConfig,\n modifyTestSetup,\n VITEST_CONFIG,\n WITH_BACKEND,\n} from \"./modifies/test-setup\";\nimport { modifyHooksServerBackend } from \"./modifies/hooks.server\";\nimport { modifyEnvVarsFiles } from \"../../../runtime/env-vars\";\nimport { BACKEND_ENV_VARS } from \"./env-vars\";\n\nexport async function generate(options: Options) {\n const logger = getLogger(options);\n const modifies: File[] = [];\n const creates: File[] = [];\n const create = (filePath: string, content: string) =>\n creates.push({\n path: filePath,\n language: languageFromPath(filePath),\n content,\n status: \"success\",\n });\n\n logger.info(\"Modifying adapter config\");\n const adapter = modifySvelteConfig(options.root);\n const svelteConfigFile = modifyOutcomeToFile(\n adapter.filePath,\n adapter.outcome,\n );\n if (svelteConfigFile) modifies.push(svelteConfigFile);\n\n // A hooks.server.ts the project already has keeps its handles; the create\n // only writes the file where there is none (see `keepMissing` in index.ts).\n const hooksServerPath = path.join(options.root, \"src\", \"hooks.server.ts\");\n const hooksServerFile = modifyOutcomeToFile(\n hooksServerPath,\n modifyHooksServerBackend(hooksServerPath),\n );\n if (hooksServerFile) {\n logger.info(\"Modifying hooks.server.ts\");\n modifies.push(hooksServerFile);\n }\n\n // SvelteKit 3 exposes only declared variables: the handle above reads\n // these three from `$app/env/private`.\n logger.info(\"Declaring the PocketBase variables in src/env.ts\");\n const envVars = modifyEnvVarsFiles(options.root, BACKEND_ENV_VARS);\n if (envVars.create) creates.push(envVars.create);\n if (envVars.modify) modifies.push(envVars.modify);\n\n logger.info(\"Modifying .gitignore\");\n const gitignorePath = path.join(options.root, \".gitignore\");\n const gitignoreFile = modifyOutcomeToFile(\n gitignorePath,\n modifyGitignore(gitignorePath),\n );\n if (gitignoreFile) modifies.push(gitignoreFile);\n\n // A backend brings server tests with it. The static template and a project\n // vela did not create have no harness at all, so what is missing is created:\n // the setup file, and the vitest config that loads it.\n const testSetupPath = path.join(options.root, \"test\", \"setup.ts\");\n if (fs.existsSync(testSetupPath)) {\n logger.info(\"Modifying test/setup.ts\");\n const testSetupFile = modifyOutcomeToFile(\n testSetupPath,\n modifyTestSetup(testSetupPath),\n );\n if (testSetupFile) modifies.push(testSetupFile);\n } else {\n logger.info(\"Creating test/setup.ts\");\n create(\"test/setup.ts\", WITH_BACKEND);\n }\n\n if (!hasVitestConfig(options.root)) {\n logger.info(\"Creating vitest.config.ts\");\n create(\"vitest.config.ts\", VITEST_CONFIG);\n }\n\n // Kit 3's tsconfig lists no files, so the test harness and PocketBase's\n // generated types are type-checked only when the project's include names them.\n const tsconfigPath = path.join(options.root, \"tsconfig.json\");\n const tsconfigFile = modifyOutcomeToFile(\n tsconfigPath,\n modifyTsconfigBackend(options.root),\n );\n if (tsconfigFile) {\n logger.info(\"Modifying tsconfig.json\");\n modifies.push(tsconfigFile);\n }\n\n return {\n creates,\n modifies,\n deletes: [],\n components: [],\n packages: [],\n collections: [],\n collectionPatches: [],\n collectionDrops: [],\n } satisfies Result;\n}\n"],"mappings":";;;;;;;;;;;;;AAKA,IAAakB,IAAmB,uCAE1BC,IAAiB;CAAC;CAAM;CAAO;CAAM;AAAK,CAAC,CAAC,KAC/C,MAAQ,iBAAiBC,GAC5B;AAcA,SAAgBC,EAAsB,GAA6B;CACjE,IAAMC,IAAWL,EAAK,KAAKM,GAAM,eAAe;CAChD,IAAI,CAACP,EAAG,WAAWM,CAAQ,GACzB,OAAO;EAAE,QAAQ;EAAW,SAAS;CAAM;CAE7C,IAAME,IAAWR,EAAG,aAAaM,GAAU,MAAM,GAC3CG,IACJN,EAAe,MAAM,MAASH,EAAG,WAAWC,EAAK,KAAKM,GAAMG,CAAI,CAAC,CAAC,KAClE,oBACIC,IAAS;EAAC;EAAQF;EAAcP;CAAgB,GAElDU;CACJ,IAAI;EACF,IAAS,KAAK,MAAMJ,CAAQ;CAC9B,QAAQ;EACN,OAAO;GACL,QAAQ;GACR,SAAS,sDAAsDG,EAC5D,KAAK,MAAU,KAAK,UAAUE,CAAK,CAAC,CAAC,CACrC,KAAK,IAAI;EACd;CACF;CACA,IAAMC,IAAUF,EAAO;CACvB,IAAIE,MAAY,KAAA,GACd,OAAO;EAAE,QAAQ;EAAW,SAAS;CAAM;CAE7C,IAAI,CAAC,MAAM,QAAQA,CAAO,GACxB,OAAO;EACL,QAAQ;EACR,SAAS,qDAAqDH,EAAO,KAAK,IAAI;CAChF;CAGF,IAAMI,KAAa,MACjB,OAAOF,KAAU,WAAWA,EAAM,QAAQ,SAAS,EAAE,IAAIA,GACrDG,KAAO,MACXF,EAAQ,MAAM,MAAaC,EAAUE,CAAQ,MAAMJ,CAAK,GACpDK,IAAO,CAAC,GAAGJ,CAAO,GAClBK,KAAe,GAAe,MAAmC;EACrE,IAAIH,EAAIH,CAAK,GAAG;EAChB,IAAIO,IAAQ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CA,EAAQ,UAAQN,EAAS,KAAKM,EAAQ,MAAM,GAEhDR,EAAO,KAAK,sBAAsB;CAClC,IAAMU,IAAgB9C,EAAK,KAAKqC,EAAQ,MAAM,YAAY,GACpDU,IAAgB/D,EACpB8D,GACA1D,EAAgB0D,CAAa,CAC/B;CACA,AAAIC,KAAeT,EAAS,KAAKS,CAAa;CAK9C,IAAMC,IAAgBhD,EAAK,KAAKqC,EAAQ,MAAM,QAAQ,UAAU;CAChE,IAAItC,EAAG,WAAWiD,CAAa,GAAG;EAChC,EAAO,KAAK,yBAAyB;EACrC,IAAMC,IAAgBjE,EACpBgE,GACA9D,EAAgB8D,CAAa,CAC/B;EACA,AAAIC,KAAeX,EAAS,KAAKW,CAAa;CAChD,OAEE,AADAb,EAAO,KAAK,wBAAwB,GACpCI,EAAO,iBAAiBrD,CAAY;CAGtC,AAAKE,EAAgBgD,EAAQ,IAAI,MAC/BD,EAAO,KAAK,2BAA2B,GACvCI,EAAO,oBAAoBlD,CAAa;CAK1C,IAAM4D,IAAelD,EAAK,KAAKqC,EAAQ,MAAM,eAAe,GACtDc,IAAenE,EACnBkE,GACA9C,EAAsBiC,EAAQ,IAAI,CACpC;CAMA,OALIc,MACFf,EAAO,KAAK,yBAAyB,GACrCE,EAAS,KAAKa,CAAY,IAGrB;EACL;EACA;EACA,SAAS,CAAC;EACV,YAAY,CAAC;EACb,UAAU,CAAC;EACX,aAAa,CAAC;EACd,mBAAmB,CAAC;EACpB,iBAAiB,CAAC;CACpB;AACF"}
|
|
@@ -5,38 +5,39 @@ import { n as a } from "./site-B9hDxucR.js";
|
|
|
5
5
|
import { t as o } from "./dedent-CCUOcPFW.js";
|
|
6
6
|
import { _ as s, a as c, o as l, r as u } from "./ts-morph-helpers-B4KZXP44.js";
|
|
7
7
|
import { t as d } from "./svelte-file-DfplF3BU.js";
|
|
8
|
-
import f from "
|
|
9
|
-
import p from "node:
|
|
10
|
-
import
|
|
8
|
+
import { localizeAuthPages as f } from "./i18n-BHCytiiO.js";
|
|
9
|
+
import p from "node:fs";
|
|
10
|
+
import m from "node:path";
|
|
11
|
+
import { Project as h, SyntaxKind as g } from "ts-morph";
|
|
11
12
|
// src/patterns/enable/auth/modifies/+layout.server.ts
|
|
12
|
-
function
|
|
13
|
-
if (!
|
|
13
|
+
function _(e) {
|
|
14
|
+
if (!p.existsSync(e)) {
|
|
14
15
|
let t = o`
|
|
15
16
|
export const load = async ({ locals }) => {
|
|
16
17
|
return { user: locals.pb.authStore.record };
|
|
17
18
|
};
|
|
18
19
|
`;
|
|
19
|
-
return
|
|
20
|
+
return p.writeFileSync(e, t), {
|
|
20
21
|
status: "success",
|
|
21
22
|
changed: !0
|
|
22
23
|
};
|
|
23
24
|
}
|
|
24
|
-
let t =
|
|
25
|
+
let t = p.readFileSync(e, "utf8"), n = new h().addSourceFileAtPath(e), r = (e) => {
|
|
25
26
|
e.getProperty("user") || e.addPropertyAssignment({
|
|
26
27
|
name: "user",
|
|
27
28
|
initializer: "locals.pb.authStore.record"
|
|
28
29
|
});
|
|
29
30
|
}, i, a, s = n.getVariableDeclaration("load");
|
|
30
|
-
if (s && s.getFirstAncestorByKind(
|
|
31
|
-
let e = s.getInitializerIfKind(
|
|
31
|
+
if (s && s.getFirstAncestorByKind(g.VariableStatement)?.hasExportKeyword()) {
|
|
32
|
+
let e = s.getInitializerIfKind(g.ArrowFunction);
|
|
32
33
|
if (e) i = e;
|
|
33
34
|
else {
|
|
34
35
|
let e = s.getInitializer();
|
|
35
36
|
if (e) {
|
|
36
|
-
let t = e.getFirstDescendantByKind(
|
|
37
|
+
let t = e.getFirstDescendantByKind(g.ArrowFunction);
|
|
37
38
|
if (t) i = t;
|
|
38
39
|
else {
|
|
39
|
-
let t = e.getFirstDescendantByKind(
|
|
40
|
+
let t = e.getFirstDescendantByKind(g.FunctionExpression);
|
|
40
41
|
t && (a = t);
|
|
41
42
|
}
|
|
42
43
|
}
|
|
@@ -60,7 +61,7 @@ function g(e) {
|
|
|
60
61
|
if (u.length === 0) c.insertParameter(0, { name: "{ locals }" });
|
|
61
62
|
else {
|
|
62
63
|
let e = u[0], t = e.getStructure(), n = e.getNameNode();
|
|
63
|
-
if (n.getKind() ===
|
|
64
|
+
if (n.getKind() === g.ObjectBindingPattern) {
|
|
64
65
|
let r = n;
|
|
65
66
|
if (!r.getElements().some((e) => e.getName() === "locals")) {
|
|
66
67
|
let n = r.getElements().map((e) => e.getText()).filter(Boolean), i = n.length > 0 ? ", " + n.join(", ") : "";
|
|
@@ -81,32 +82,32 @@ function g(e) {
|
|
|
81
82
|
}
|
|
82
83
|
if (i) {
|
|
83
84
|
let e = i.getBody();
|
|
84
|
-
if (e.getKind() ===
|
|
85
|
+
if (e.getKind() === g.Block) e.getDescendantsOfKind(g.ReturnStatement).forEach((e) => {
|
|
85
86
|
let t = e.getExpression();
|
|
86
87
|
if (t) {
|
|
87
|
-
if (t.getKind() ===
|
|
88
|
-
else if (t.getKind() ===
|
|
88
|
+
if (t.getKind() === g.ObjectLiteralExpression) r(t);
|
|
89
|
+
else if (t.getKind() === g.ParenthesizedExpression) {
|
|
89
90
|
let e = t.getExpression();
|
|
90
|
-
e.getKind() ===
|
|
91
|
+
e.getKind() === g.ObjectLiteralExpression && r(e);
|
|
91
92
|
}
|
|
92
93
|
}
|
|
93
94
|
});
|
|
94
95
|
else {
|
|
95
96
|
let t = e;
|
|
96
|
-
if (t.getKind() ===
|
|
97
|
+
if (t.getKind() === g.ParenthesizedExpression) {
|
|
97
98
|
let e = t.getExpression();
|
|
98
|
-
e.getKind() ===
|
|
99
|
-
} else t.getKind() ===
|
|
99
|
+
e.getKind() === g.ObjectLiteralExpression && r(e);
|
|
100
|
+
} else t.getKind() === g.ObjectLiteralExpression && r(t);
|
|
100
101
|
}
|
|
101
102
|
} else if (a) {
|
|
102
103
|
let e = a.getBody();
|
|
103
|
-
e && e.getDescendantsOfKind(
|
|
104
|
+
e && e.getDescendantsOfKind(g.ReturnStatement).forEach((e) => {
|
|
104
105
|
let t = e.getExpression();
|
|
105
106
|
if (t) {
|
|
106
|
-
if (t.getKind() ===
|
|
107
|
-
else if (t.getKind() ===
|
|
107
|
+
if (t.getKind() === g.ObjectLiteralExpression) r(t);
|
|
108
|
+
else if (t.getKind() === g.ParenthesizedExpression) {
|
|
108
109
|
let e = t.getExpression();
|
|
109
|
-
e.getKind() ===
|
|
110
|
+
e.getKind() === g.ObjectLiteralExpression && r(e);
|
|
110
111
|
}
|
|
111
112
|
}
|
|
112
113
|
});
|
|
@@ -117,32 +118,32 @@ function g(e) {
|
|
|
117
118
|
};
|
|
118
119
|
}
|
|
119
120
|
// src/patterns/enable/auth/modifies/root-layout.svelte.ts
|
|
120
|
-
var
|
|
121
|
+
var v = "\n <Navbar.Item\n class=\"flex flex-col md:flex-row items-center space-y-2 md:space-y-0 md:space-x-4\"\n >\n <AuthMenu.Root>\n {#snippet user()}\n <AuthMenu.Trigger>\n <UserAvatar user={data.user} />\n </AuthMenu.Trigger>\n\n <AuthMenu.Content align=\"end\">\n <AuthMenu.Item href=\"/dashboard\">Dashboard</AuthMenu.Item>\n <AuthMenu.Group>\n <AuthMenu.Item href=\"/settings\">Settings</AuthMenu.Item>\n <AuthMenu.Item>\n <form action=\"/logout\" method=\"post\">\n <button type=\"submit\" class=\"contents\">Logout</button>\n </form>\n </AuthMenu.Item>\n </AuthMenu.Group>\n </AuthMenu.Content>\n {/snippet}\n\n {#snippet guest()}\n <Button\n class=\"w-full justify-start md:justify-center md:w-auto\"\n variant=\"ghost\"\n href=\"/login\">Login</Button\n >\n <Button\n class=\"w-full justify-start md:justify-center md:w-auto\"\n variant=\"outline\"\n href=\"/signup\">Sign up</Button\n >\n {/snippet}\n </AuthMenu.Root>\n </Navbar.Item>\n ", y = o`
|
|
121
122
|
import * as AuthMenu from '#lib/components/ui/auth-menu/index.js';
|
|
122
123
|
import UserAvatar from '#lib/components/user-avatar.svelte';
|
|
123
|
-
`,
|
|
124
|
+
`, b = [
|
|
124
125
|
"Add the auth menu inside your <Navbar.List> in the root layout.",
|
|
125
126
|
"",
|
|
126
127
|
"Imports to add to the <script> tag:",
|
|
127
128
|
"",
|
|
128
|
-
|
|
129
|
+
y,
|
|
129
130
|
"",
|
|
130
131
|
"Markup to add inside <Navbar.List>:",
|
|
131
|
-
|
|
132
|
-
].join("\n"),
|
|
132
|
+
v
|
|
133
|
+
].join("\n"), x = [
|
|
133
134
|
"Create a root layout that includes an auth menu inside <Navbar.List>.",
|
|
134
135
|
"",
|
|
135
136
|
"Imports for the <script> tag:",
|
|
136
137
|
"",
|
|
137
|
-
|
|
138
|
+
y,
|
|
138
139
|
"",
|
|
139
140
|
"Markup inside <Navbar.List>:",
|
|
140
|
-
|
|
141
|
+
v
|
|
141
142
|
].join("\n");
|
|
142
|
-
function
|
|
143
|
-
if (!
|
|
143
|
+
function S(e) {
|
|
144
|
+
if (!p.existsSync(e)) return {
|
|
144
145
|
status: "not-found",
|
|
145
|
-
message:
|
|
146
|
+
message: x
|
|
146
147
|
};
|
|
147
148
|
let t = d.fromPath(e);
|
|
148
149
|
return t.hasElement("Navbar.List") ? t.hasElement("AuthMenu.Root") ? {
|
|
@@ -159,22 +160,22 @@ function x(e) {
|
|
|
159
160
|
}]), c(e, "data");
|
|
160
161
|
});
|
|
161
162
|
return t;
|
|
162
|
-
}), t.insertBeforeClosingTag("Navbar.List",
|
|
163
|
+
}), t.insertBeforeClosingTag("Navbar.List", v), t.writeTo(e), {
|
|
163
164
|
status: "success",
|
|
164
165
|
changed: t.hasChanged()
|
|
165
166
|
}) : {
|
|
166
167
|
status: "failed",
|
|
167
|
-
message:
|
|
168
|
+
message: b
|
|
168
169
|
};
|
|
169
170
|
}
|
|
170
171
|
// src/patterns/enable/auth/modifies/hooks.server.ts
|
|
171
|
-
var
|
|
172
|
+
var C = o`
|
|
172
173
|
Configure handlePocketbase() with the auth option in hooks.server.ts:
|
|
173
174
|
|
|
174
175
|
handlePocketbase({
|
|
175
176
|
auth: { protectedRoutes: ['/(app)'] },
|
|
176
177
|
});
|
|
177
|
-
`,
|
|
178
|
+
`, w = o`
|
|
178
179
|
Create src/hooks.server.ts with handlePocketbase:
|
|
179
180
|
|
|
180
181
|
import { handlePocketbase } from '@velastack/pocketbase';
|
|
@@ -183,15 +184,15 @@ var S = o`
|
|
|
183
184
|
auth: { protectedRoutes: ['/(app)'] },
|
|
184
185
|
});
|
|
185
186
|
`;
|
|
186
|
-
function
|
|
187
|
-
if (!
|
|
187
|
+
function T(e) {
|
|
188
|
+
if (!p.existsSync(e)) return {
|
|
188
189
|
status: "not-found",
|
|
189
|
-
message:
|
|
190
|
+
message: w
|
|
190
191
|
};
|
|
191
|
-
let t =
|
|
192
|
+
let t = p.readFileSync(e, "utf8"), n = new h().addSourceFileAtPath(e), r = n.getDescendantsOfKind(g.CallExpression).find((e) => e.getExpression().getText() === "handlePocketbase");
|
|
192
193
|
if (!r) return {
|
|
193
194
|
status: "failed",
|
|
194
|
-
message:
|
|
195
|
+
message: C
|
|
195
196
|
};
|
|
196
197
|
let i = r.getArguments();
|
|
197
198
|
if (i.length === 0) return r.addArgument("{ auth: { protectedRoutes: ['/(app)'] } }"), l(n), n.saveSync(), {
|
|
@@ -199,11 +200,11 @@ function w(e) {
|
|
|
199
200
|
changed: !0
|
|
200
201
|
};
|
|
201
202
|
let a = i[0];
|
|
202
|
-
if (a.getKind() !==
|
|
203
|
+
if (a.getKind() !== g.ObjectLiteralExpression) return r.insertArgument(0, "{ auth: { protectedRoutes: ['/(app)'] } }"), l(n), n.saveSync(), {
|
|
203
204
|
status: "success",
|
|
204
205
|
changed: !0
|
|
205
206
|
};
|
|
206
|
-
let o = a.asKindOrThrow(
|
|
207
|
+
let o = a.asKindOrThrow(g.ObjectLiteralExpression), s = o.getProperty("auth");
|
|
207
208
|
if (!s) return o.addPropertyAssignment({
|
|
208
209
|
name: "auth",
|
|
209
210
|
initializer: "{ protectedRoutes: ['/(app)'] }"
|
|
@@ -211,17 +212,17 @@ function w(e) {
|
|
|
211
212
|
status: "success",
|
|
212
213
|
changed: !0
|
|
213
214
|
};
|
|
214
|
-
if (s.getKind() ===
|
|
215
|
+
if (s.getKind() === g.PropertyAssignment) {
|
|
215
216
|
let e = s.getInitializer();
|
|
216
|
-
if (e && e.getKind() ===
|
|
217
|
+
if (e && e.getKind() === g.ObjectLiteralExpression) {
|
|
217
218
|
let t = e, n = t.getProperty("protectedRoutes");
|
|
218
219
|
if (!n) t.addPropertyAssignment({
|
|
219
220
|
name: "protectedRoutes",
|
|
220
221
|
initializer: "['/(app)']"
|
|
221
222
|
});
|
|
222
|
-
else if (n.getKind() ===
|
|
223
|
+
else if (n.getKind() === g.PropertyAssignment) {
|
|
223
224
|
let e = n.getInitializer();
|
|
224
|
-
if (e && e.getKind() ===
|
|
225
|
+
if (e && e.getKind() === g.ArrayLiteralExpression) {
|
|
225
226
|
let t = e;
|
|
226
227
|
t.getElements().some((e) => e.getText().replace(/['"`]/g, "") === "/(app)") || t.addElement("'/(app)'");
|
|
227
228
|
} else n.setInitializer("['/(app)']");
|
|
@@ -234,39 +235,39 @@ function w(e) {
|
|
|
234
235
|
};
|
|
235
236
|
}
|
|
236
237
|
// src/patterns/enable/auth/modifies/sidebar-menu-button.svelte.ts
|
|
237
|
-
var
|
|
238
|
+
var E = [{
|
|
238
239
|
from: "'data-active': isActive,",
|
|
239
240
|
to: "'data-active': isActive ? true : undefined,"
|
|
240
241
|
}, {
|
|
241
242
|
from: "\"data-active\": isActive,",
|
|
242
243
|
to: "\"data-active\": isActive ? true : undefined,"
|
|
243
|
-
}],
|
|
244
|
+
}], D = o`
|
|
244
245
|
The shadcn-svelte sidebar component was not installed at the expected path.
|
|
245
246
|
Run: vela enable auth (or install the 'sidebar' shadcn-svelte component).
|
|
246
247
|
`;
|
|
247
|
-
function
|
|
248
|
-
if (!
|
|
248
|
+
function O(e) {
|
|
249
|
+
if (!p.existsSync(e)) return {
|
|
249
250
|
status: "not-found",
|
|
250
|
-
message:
|
|
251
|
+
message: D
|
|
251
252
|
};
|
|
252
|
-
let t =
|
|
253
|
-
if (
|
|
253
|
+
let t = p.readFileSync(e, "utf8");
|
|
254
|
+
if (E.some(({ to: e }) => t.includes(e))) return {
|
|
254
255
|
status: "success",
|
|
255
256
|
changed: !1
|
|
256
257
|
};
|
|
257
|
-
let n =
|
|
258
|
+
let n = E.find(({ from: e }) => t.includes(e));
|
|
258
259
|
if (!n) return {
|
|
259
260
|
status: "success",
|
|
260
261
|
changed: !1
|
|
261
262
|
};
|
|
262
263
|
let r = t.replace(n.from, n.to);
|
|
263
|
-
return
|
|
264
|
+
return p.writeFileSync(e, r, "utf8"), {
|
|
264
265
|
status: "success",
|
|
265
266
|
changed: !0
|
|
266
267
|
};
|
|
267
268
|
}
|
|
268
269
|
// src/patterns/enable/auth/generate.runtime.ts
|
|
269
|
-
async function
|
|
270
|
+
async function k(o) {
|
|
270
271
|
let { input: s } = o, c = e(o), l = [];
|
|
271
272
|
await t(o.root, async (e) => {
|
|
272
273
|
c.info("Updating PocketBase mail settings"), await e.settings.update({ meta: {
|
|
@@ -290,7 +291,7 @@ async function O(o) {
|
|
|
290
291
|
d && l.push({
|
|
291
292
|
path: d,
|
|
292
293
|
language: "ts",
|
|
293
|
-
content:
|
|
294
|
+
content: p.readFileSync(d, "utf8"),
|
|
294
295
|
status: "success"
|
|
295
296
|
});
|
|
296
297
|
});
|
|
@@ -298,22 +299,22 @@ async function O(o) {
|
|
|
298
299
|
e && u.push(e);
|
|
299
300
|
};
|
|
300
301
|
c.info("Modifying +layout.server.ts");
|
|
301
|
-
let
|
|
302
|
-
d(i(
|
|
303
|
-
let
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
],
|
|
309
|
-
d(i(
|
|
310
|
-
let
|
|
311
|
-
d(i(
|
|
312
|
-
let
|
|
313
|
-
d(i(
|
|
314
|
-
let
|
|
315
|
-
return {
|
|
316
|
-
creates:
|
|
302
|
+
let h = m.join(o.root, "src", "routes", "+layout.server.ts");
|
|
303
|
+
d(i(h, _(h))), c.info("Modifying root layout");
|
|
304
|
+
let g = [
|
|
305
|
+
m.join(o.root, "src", "routes", "(public)", "root-layout.svelte"),
|
|
306
|
+
m.join(o.root, "src", "routes", "root-layout.svelte"),
|
|
307
|
+
m.join(o.root, "src", "routes", "(public)", "+layout.svelte"),
|
|
308
|
+
m.join(o.root, "src", "routes", "+layout.svelte")
|
|
309
|
+
], v = g.find((e) => p.existsSync(e)) ?? g[0];
|
|
310
|
+
d(i(v, S(v))), c.info("Modifying hooks.server.ts");
|
|
311
|
+
let y = m.join(o.root, "src", "hooks.server.ts");
|
|
312
|
+
d(i(y, T(y))), c.info("Modifying sidebar-menu-button.svelte");
|
|
313
|
+
let b = m.join(o.root, "src", "lib", "components", "ui", "sidebar", "sidebar-menu-button.svelte");
|
|
314
|
+
d(i(b, O(b)));
|
|
315
|
+
let x = await a(o), C = x ? [...l, x] : [...l], w = f(o);
|
|
316
|
+
return C.push(...w.creates), u.push(...w.modifies), {
|
|
317
|
+
creates: C,
|
|
317
318
|
modifies: u,
|
|
318
319
|
deletes: [],
|
|
319
320
|
components: [],
|
|
@@ -323,6 +324,6 @@ async function O(o) {
|
|
|
323
324
|
collectionDrops: []
|
|
324
325
|
};
|
|
325
326
|
}
|
|
326
|
-
export {
|
|
327
|
+
export { k as generate };
|
|
327
328
|
|
|
328
|
-
//# sourceMappingURL=generate.runtime-
|
|
329
|
+
//# sourceMappingURL=generate.runtime-CsP4c8GY.js.map
|