@murumets-ee/create 0.5.1 → 0.6.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/dist/cli.mjs +1 -56
- package/dist/index.d.mts +9 -2
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +1 -56
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -2
- package/templates/template-demo.tar.gz +0 -0
package/dist/cli.mjs
CHANGED
|
@@ -1,58 +1,3 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import*as e from"@clack/prompts";import t from"picocolors";import{existsSync as n,readFileSync as r}from"node:fs";import{readFile as i,readdir as a,rm as o,writeFile as s}from"node:fs/promises";import{dirname as c,join as l}from"node:path";import{fileURLToPath as u}from"node:url";import{extract as d}from"tar";import{execSync as f}from"node:child_process";function p(e){let t={},n=e.slice(2);for(let e=0;e<n.length;e++){let r=n[e];if(r===`--
|
|
3
|
-
// See https://github.com/murumets-ee/lumi-cms for documentation.
|
|
4
|
-
|
|
5
|
-
export const projectEntities = [] as const
|
|
6
|
-
export const projectTaxonomies = [] as const
|
|
7
|
-
`,`utf-8`)}let r=l(e,`seeds`);if(n(r)){let e=await a(r);for(let t of e)t!==`index.ts`&&await o(l(r,t),{force:!0});await s(l(r,`index.ts`),`import type { AdminSeeder } from '@murumets-ee/admin-ui/pages'
|
|
8
|
-
|
|
9
|
-
export const projectSeeders: AdminSeeder[] = []
|
|
10
|
-
`,`utf-8`)}await o(l(e,`app`,`[locale]`,`(shell)`,`demos`),{recursive:!0,force:!0});let c=l(e,`app`,`admin-layout.tsx`);if(n(c)){let e=await i(c,`utf-8`);e=e.replace(/\n\s*\/\/.*demo.*[\s\S]*?const demosGroup[\s\S]*?\}\n/i,`
|
|
11
|
-
`),e=e.replace(`, demosGroup`,``),e=e.replace(/\s*GalleryHorizontalEnd,\n/,`
|
|
12
|
-
`),e=e.replace(/\s*HardDrive,\n/,`
|
|
13
|
-
`),e=e.replace(/\s*Palette,\n/,`
|
|
14
|
-
`),await s(c,e,`utf-8`)}let u=l(e,`toolkit.config.ts`);if(n(u)){let e=await i(u,`utf-8`);e=e.replace(/import \{[^}]+\} from '\.\/entities'/,`import { projectEntities } from './entities'`),e=e.replace(/entities: \[[^\]]+\]/,`entities: [...projectEntities]`),await s(u,e,`utf-8`)}let d=l(e,`lib`,`admin-config.ts`);n(d)&&await s(d,`/**
|
|
15
|
-
* Shared admin configuration — entities + route resource metadata.
|
|
16
|
-
*
|
|
17
|
-
* Add your own entities to the arrays below after defining them in entities/.
|
|
18
|
-
*/
|
|
19
|
-
|
|
20
|
-
import { Media } from '@murumets-ee/media'
|
|
21
|
-
import {
|
|
22
|
-
Ticket,
|
|
23
|
-
TicketMessage,
|
|
24
|
-
TicketAttachment,
|
|
25
|
-
Department,
|
|
26
|
-
TicketTag,
|
|
27
|
-
} from '@murumets-ee/ticketing'
|
|
28
|
-
|
|
29
|
-
/** All content entities registered in the admin API. */
|
|
30
|
-
export const allEntities = [
|
|
31
|
-
Media,
|
|
32
|
-
Ticket, TicketMessage, TicketAttachment, Department, TicketTag,
|
|
33
|
-
]
|
|
34
|
-
|
|
35
|
-
/** Taxonomy vocabularies. */
|
|
36
|
-
export const taxonomyVocabularies = {}
|
|
37
|
-
|
|
38
|
-
/** Entities exposed via generic CRUD handler (subset of allEntities). */
|
|
39
|
-
export const crudEntities = [
|
|
40
|
-
Media,
|
|
41
|
-
Ticket, TicketMessage, TicketAttachment,
|
|
42
|
-
]
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Plugin route resource declarations.
|
|
46
|
-
*/
|
|
47
|
-
export const pluginResources: { resource: string; actions: readonly string[] }[] = [
|
|
48
|
-
{ resource: 'storage', actions: ['view', 'create', 'update', 'delete'] },
|
|
49
|
-
{ resource: 'settings', actions: ['view', 'update'] },
|
|
50
|
-
{ resource: 'audit-logs', actions: ['view'] },
|
|
51
|
-
{ resource: 'permissions', actions: ['view', 'create', 'update', 'delete'] },
|
|
52
|
-
{ resource: 'ticketing', actions: ['view', 'create', 'update', 'delete'] },
|
|
53
|
-
]
|
|
54
|
-
`,`utf-8`);let f=l(e,`app`,`api`,`content`,`[...path]`,`route.ts`);if(n(f)){let e=await i(f,`utf-8`);e=e.replace(/import \{[^}]+\} from '@\/entities'\n/,``),e=e.replace(/entities: \[[^\]]+\]/,`entities: []`),await s(f,e,`utf-8`)}let p=l(e,`app`,`[locale]`,`(shell)`,`admin`,`page.tsx`);n(p)&&await s(p,`import { pages } from '@/lib/admin-pages'
|
|
55
|
-
|
|
56
|
-
export default pages.DashboardPage
|
|
57
|
-
`,`utf-8`)}async function E(e,t){let n=A(t);for await(let r of O(e)){if(!k(r))continue;let e=await i(r,`utf-8`);!e.includes(y)&&!e.includes(b)||await s(r,e.split(b).join(n).split(y).join(t),`utf-8`)}}const D=new Set([`node_modules`,`dist`,`build`,`coverage`,`out`]);async function*O(e){let t=await a(e,{withFileTypes:!0});for(let n of t){let t=l(e,n.name);if(n.isDirectory()){if(D.has(n.name)||n.name.startsWith(`.`))continue;yield*O(t)}else n.isFile()&&(yield t)}}function k(e){let t=e.lastIndexOf(`/`),n=t>=0?e.slice(t+1):e;if(v.has(n))return!0;let r=n.lastIndexOf(`.`);if(r<0)return!1;let i=n.slice(r);return _.has(i)}function A(e){return e.split(/[-_\s]+/).filter(Boolean).map(e=>e[0]?.toUpperCase()+e.slice(1)).join(` `)}async function j(){let n=process.argv[2],r=await m(n);if(!r)return;let i=e.spinner();try{i.start(`Creating Next.js app...`),await x(r,e=>{i.stop(`${t.green(`✓`)} Done`),i.start(e)}),i.stop(`${t.green(`✓`)} Done`);let n=[`cd ${r.name}`,`cp .env.example .env`,`# Edit .env — set DATABASE_URL and BETTER_AUTH_SECRET`,`docker compose up -d`,`pnpm db:migrate`,`pnpm dev`,`# Sign up at /auth/sign-up — first user is auto-promoted to admin`];e.note(n.join(`
|
|
2
|
+
import*as e from"@clack/prompts";import t from"picocolors";import{existsSync as n,readFileSync as r}from"node:fs";import{readFile as i,readdir as a,rm as o,writeFile as s}from"node:fs/promises";import{dirname as c,join as l}from"node:path";import{fileURLToPath as u}from"node:url";import{extract as d}from"tar";import{execSync as f}from"node:child_process";function p(e){let t={},n=e.slice(2);for(let e=0;e<n.length;e++){let r=n[e];if(r===`--full`)t.preset=`demo`;else if(r===`--preset`&&n[e+1]){let r=n[++e];(r===`minimal`||r===`demo`)&&(t.preset=r)}else if(r.startsWith(`--preset=`)){let e=r.slice(9);(e===`minimal`||e===`demo`)&&(t.preset=e)}else r===`--install`?t.install=!0:r===`--no-install`?t.install=!1:!r.startsWith(`-`)&&!t.name&&(t.name=r)}return t}async function m(t){let n=p(process.argv),r=n.name??t;if(n.preset===`demo`&&n.install===!1)return e.intro(`@murumets-ee/create`),e.cancel("Preset `demo` installs plugins via `lumi add` after deps resolve, so --install must be true (or pick `minimal`)."),null;if(r&&n.install!==void 0&&n.preset!==void 0)return{name:r,installDeps:n.install,preset:n.preset};e.intro(`@murumets-ee/create`);let i=r??await e.text({message:`Project name:`,placeholder:`my-project`,validate:e=>{if(!e)return`Project name is required`;if(!/^[a-z0-9-]+$/.test(e))return`Use lowercase letters, numbers, and hyphens only`}});if(e.isCancel(i))return e.cancel(`Cancelled.`),null;let a=n.preset??await e.select({message:`Preset:`,options:[{value:`demo`,label:`Demo`,hint:`auth + media + ticketing (recommended for first-time setup)`},{value:`minimal`,label:`Minimal`,hint:"auth + infrastructure only — add plugins with `lumi add`"}],initialValue:`demo`});if(e.isCancel(a))return e.cancel(`Cancelled.`),null;let o=n.install??await e.confirm({message:`Install dependencies?`,initialValue:!0});return e.isCancel(o)?(e.cancel(`Cancelled.`),null):a===`demo`&&!o?(e.cancel("Preset `demo` installs plugins via `lumi add` after deps resolve, so --install must be true (or pick `minimal`)."),null):{name:i,installDeps:o,preset:a}}async function h(e,t){for(let n of t)await o(l(e,n),{force:!0,recursive:!0})}function g(e,t){return t?.inherit?(f(e,{cwd:t.cwd,stdio:`inherit`}),``):f(e,{cwd:t?.cwd,stdio:`pipe`,encoding:`utf-8`})}const _=new Set([`.ts`,`.tsx`,`.mts`,`.json`,`.md`,`.yml`,`.yaml`,`.css`,`.html`]),v=new Set([`.env.example`,`Dockerfile`,`.gitignore`]),y=`__PROJECT_NAME__`,b=`__PROJECT_NAME_TITLE__`;async function x(e,t){await S(e,t)}async function S(e,t){let n=l(process.cwd(),e.name);if(t?.(`Creating Next.js app...`),g(`pnpm create next-app@16 ${e.name} --typescript --tailwind --no-eslint --app --no-src-dir --turbopack --react-compiler --skip-install --import-alias "@/*"`),await h(n,[`app/page.tsx`,`app/page.module.css`,`app/fonts`,`app/globals.css`,`README.md`]),t?.(`Extracting template...`),await w(n),t?.(`Personalizing template...`),await E(n,e.name),e.installDeps&&(t?.(`Installing dependencies...`),g(`pnpm install`,{cwd:n})),e.preset===`demo`){if(!e.installDeps)throw Error("Preset `demo` requires --install because the `lumi add` step runs from the scaffolded project. Re-run without --no-install, or pass --preset=minimal.");for(let e of C)t?.(`Adding ${e} plugin...`),g(`pnpm exec lumi add ${e}`,{cwd:n,inherit:!0})}}const C=[`media`,`ticketing`];async function w(e){let t=T();if(!n(t))throw Error(`Template tarball missing: ${t}\nRun \`pnpm --filter @murumets-ee/create build:templates\` first.`);await d({file:t,cwd:e})}function T(){let e=c(u(import.meta.url)),t=e;for(let e=0;e<5;e++){let e=l(t,`package.json`);if(n(e))try{if(JSON.parse(r(e,`utf-8`)).name===`@murumets-ee/create`)return l(t,`templates`,`template-demo.tar.gz`)}catch{}let i=c(t);if(i===t)break;t=i}throw Error(`Could not find @murumets-ee/create package root above ${e}. template-demo.tar.gz cannot be located.`)}async function E(e,t){let n=A(t);for await(let r of O(e)){if(!k(r))continue;let e=await i(r,`utf-8`);!e.includes(y)&&!e.includes(b)||await s(r,e.split(b).join(n).split(y).join(t),`utf-8`)}}const D=new Set([`node_modules`,`dist`,`build`,`coverage`,`out`]);async function*O(e){let t=await a(e,{withFileTypes:!0});for(let n of t){let t=l(e,n.name);if(n.isDirectory()){if(D.has(n.name)||n.name.startsWith(`.`))continue;yield*O(t)}else n.isFile()&&(yield t)}}function k(e){let t=e.lastIndexOf(`/`),n=t>=0?e.slice(t+1):e;if(v.has(n))return!0;let r=n.lastIndexOf(`.`);if(r<0)return!1;let i=n.slice(r);return _.has(i)}function A(e){return e.split(/[-_\s]+/).filter(Boolean).map(e=>e[0]?.toUpperCase()+e.slice(1)).join(` `)}async function j(){let n=process.argv[2],r=await m(n);if(!r)return;let i=e.spinner();try{i.start(`Creating Next.js app...`),await x(r,e=>{i.stop(`${t.green(`✓`)} Done`),i.start(e)}),i.stop(`${t.green(`✓`)} Done`);let n=[`cd ${r.name}`,`cp .env.example .env`,`# Edit .env — set DATABASE_URL and BETTER_AUTH_SECRET`,`docker compose up -d`,`pnpm db:migrate`,`pnpm dev`,`# Sign up at /auth/sign-up — first user is auto-promoted to admin`];e.note(n.join(`
|
|
58
3
|
`),`Next steps`),e.outro(`${t.green(`Success!`)} Your project is ready.`)}catch(n){i.stop(t.red(`Failed.`)),e.log.error(n instanceof Error?n.message:String(n)),process.exit(1)}}j();export{};
|
package/dist/index.d.mts
CHANGED
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
//#region src/types.d.ts
|
|
2
|
-
|
|
2
|
+
/**
|
|
3
|
+
* `minimal` — admin-starter skeleton only (auth + infrastructure). Users
|
|
4
|
+
* run `lumi add <plugin>` post-scaffold to layer on optional plugins.
|
|
5
|
+
* `demo` — minimal + every optional plugin in the CLI catalog (media,
|
|
6
|
+
* ticketing, …), installed via `pnpm exec lumi add` after deps resolve.
|
|
7
|
+
* Requires `installDeps: true`.
|
|
8
|
+
*/
|
|
9
|
+
type Preset = 'minimal' | 'demo';
|
|
3
10
|
interface ProjectOptions {
|
|
4
11
|
name: string;
|
|
5
|
-
template: Template;
|
|
6
12
|
installDeps: boolean;
|
|
13
|
+
preset: Preset;
|
|
7
14
|
}
|
|
8
15
|
//#endregion
|
|
9
16
|
//#region src/scaffold.d.ts
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/types.ts","../src/scaffold.ts"],"mappings":";
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/types.ts","../src/scaffold.ts"],"mappings":";;AAOA;;;;;AAEA;KAFY,MAAA;AAAA,UAEK,cAAA;EACf,IAAA;EACA,WAAA;EACA,MAAA,EAAQ,MAAA;AAAA;;;KCAE,gBAAA,IAAoB,OAAA;AAAA,iBAoBV,QAAA,CACpB,OAAA,EAAS,cAAA,EACT,UAAA,GAAa,gBAAA,GACZ,OAAA"}
|
package/dist/index.mjs
CHANGED
|
@@ -1,57 +1,2 @@
|
|
|
1
|
-
import{existsSync as e,readFileSync as t}from"node:fs";import{readFile as n,readdir as r,rm as i,writeFile as a}from"node:fs/promises";import{dirname as o,join as s}from"node:path";import{fileURLToPath as c}from"node:url";import{extract as l}from"tar";import{execSync as u}from"node:child_process";async function d(e,t){for(let n of t)await i(s(e,n),{force:!0,recursive:!0})}function f(e,t){return u(e,{cwd:t?.cwd,stdio:`pipe`,encoding:`utf-8`})}const p=new Set([`.ts`,`.tsx`,`.mts`,`.json`,`.md`,`.yml`,`.yaml`,`.css`,`.html`]),m=new Set([`.env.example`,`Dockerfile`,`.gitignore`]),h=`__PROJECT_NAME__`,g=`__PROJECT_NAME_TITLE__`;async function _(e,t){await v(e,t)}async function v(e,t){let n=s(process.cwd(),e.name);t?.(`Creating Next.js app...`),f(`pnpm create next-app@16 ${e.name} --typescript --tailwind --no-eslint --app --no-src-dir --turbopack --react-compiler --skip-install --import-alias "@/*"`),await d(n,[`app/page.tsx`,`app/page.module.css`,`app/fonts`,`app/globals.css`,`README.md`]),t?.(`Extracting template...`),await
|
|
2
|
-
// See https://github.com/murumets-ee/lumi-cms for documentation.
|
|
3
|
-
|
|
4
|
-
export const projectEntities = [] as const
|
|
5
|
-
export const projectTaxonomies = [] as const
|
|
6
|
-
`,`utf-8`)}let c=s(t,`seeds`);if(e(c)){let e=await r(c);for(let t of e)t!==`index.ts`&&await i(s(c,t),{force:!0});await a(s(c,`index.ts`),`import type { AdminSeeder } from '@murumets-ee/admin-ui/pages'
|
|
7
|
-
|
|
8
|
-
export const projectSeeders: AdminSeeder[] = []
|
|
9
|
-
`,`utf-8`)}await i(s(t,`app`,`[locale]`,`(shell)`,`demos`),{recursive:!0,force:!0});let l=s(t,`app`,`admin-layout.tsx`);if(e(l)){let e=await n(l,`utf-8`);e=e.replace(/\n\s*\/\/.*demo.*[\s\S]*?const demosGroup[\s\S]*?\}\n/i,`
|
|
10
|
-
`),e=e.replace(`, demosGroup`,``),e=e.replace(/\s*GalleryHorizontalEnd,\n/,`
|
|
11
|
-
`),e=e.replace(/\s*HardDrive,\n/,`
|
|
12
|
-
`),e=e.replace(/\s*Palette,\n/,`
|
|
13
|
-
`),await a(l,e,`utf-8`)}let u=s(t,`toolkit.config.ts`);if(e(u)){let e=await n(u,`utf-8`);e=e.replace(/import \{[^}]+\} from '\.\/entities'/,`import { projectEntities } from './entities'`),e=e.replace(/entities: \[[^\]]+\]/,`entities: [...projectEntities]`),await a(u,e,`utf-8`)}let d=s(t,`lib`,`admin-config.ts`);e(d)&&await a(d,`/**
|
|
14
|
-
* Shared admin configuration — entities + route resource metadata.
|
|
15
|
-
*
|
|
16
|
-
* Add your own entities to the arrays below after defining them in entities/.
|
|
17
|
-
*/
|
|
18
|
-
|
|
19
|
-
import { Media } from '@murumets-ee/media'
|
|
20
|
-
import {
|
|
21
|
-
Ticket,
|
|
22
|
-
TicketMessage,
|
|
23
|
-
TicketAttachment,
|
|
24
|
-
Department,
|
|
25
|
-
TicketTag,
|
|
26
|
-
} from '@murumets-ee/ticketing'
|
|
27
|
-
|
|
28
|
-
/** All content entities registered in the admin API. */
|
|
29
|
-
export const allEntities = [
|
|
30
|
-
Media,
|
|
31
|
-
Ticket, TicketMessage, TicketAttachment, Department, TicketTag,
|
|
32
|
-
]
|
|
33
|
-
|
|
34
|
-
/** Taxonomy vocabularies. */
|
|
35
|
-
export const taxonomyVocabularies = {}
|
|
36
|
-
|
|
37
|
-
/** Entities exposed via generic CRUD handler (subset of allEntities). */
|
|
38
|
-
export const crudEntities = [
|
|
39
|
-
Media,
|
|
40
|
-
Ticket, TicketMessage, TicketAttachment,
|
|
41
|
-
]
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Plugin route resource declarations.
|
|
45
|
-
*/
|
|
46
|
-
export const pluginResources: { resource: string; actions: readonly string[] }[] = [
|
|
47
|
-
{ resource: 'storage', actions: ['view', 'create', 'update', 'delete'] },
|
|
48
|
-
{ resource: 'settings', actions: ['view', 'update'] },
|
|
49
|
-
{ resource: 'audit-logs', actions: ['view'] },
|
|
50
|
-
{ resource: 'permissions', actions: ['view', 'create', 'update', 'delete'] },
|
|
51
|
-
{ resource: 'ticketing', actions: ['view', 'create', 'update', 'delete'] },
|
|
52
|
-
]
|
|
53
|
-
`,`utf-8`);let f=s(t,`app`,`api`,`content`,`[...path]`,`route.ts`);if(e(f)){let e=await n(f,`utf-8`);e=e.replace(/import \{[^}]+\} from '@\/entities'\n/,``),e=e.replace(/entities: \[[^\]]+\]/,`entities: []`),await a(f,e,`utf-8`)}let p=s(t,`app`,`[locale]`,`(shell)`,`admin`,`page.tsx`);e(p)&&await a(p,`import { pages } from '@/lib/admin-pages'
|
|
54
|
-
|
|
55
|
-
export default pages.DashboardPage
|
|
56
|
-
`,`utf-8`)}async function S(e,t){let r=E(t);for await(let i of w(e)){if(!T(i))continue;let e=await n(i,`utf-8`);!e.includes(h)&&!e.includes(g)||await a(i,e.split(g).join(r).split(h).join(t),`utf-8`)}}const C=new Set([`node_modules`,`dist`,`build`,`coverage`,`out`]);async function*w(e){let t=await r(e,{withFileTypes:!0});for(let n of t){let t=s(e,n.name);if(n.isDirectory()){if(C.has(n.name)||n.name.startsWith(`.`))continue;yield*w(t)}else n.isFile()&&(yield t)}}function T(e){let t=e.lastIndexOf(`/`),n=t>=0?e.slice(t+1):e;if(m.has(n))return!0;let r=n.lastIndexOf(`.`);if(r<0)return!1;let i=n.slice(r);return p.has(i)}function E(e){return e.split(/[-_\s]+/).filter(Boolean).map(e=>e[0]?.toUpperCase()+e.slice(1)).join(` `)}export{_ as scaffold};
|
|
1
|
+
import{existsSync as e,readFileSync as t}from"node:fs";import{readFile as n,readdir as r,rm as i,writeFile as a}from"node:fs/promises";import{dirname as o,join as s}from"node:path";import{fileURLToPath as c}from"node:url";import{extract as l}from"tar";import{execSync as u}from"node:child_process";async function d(e,t){for(let n of t)await i(s(e,n),{force:!0,recursive:!0})}function f(e,t){return t?.inherit?(u(e,{cwd:t.cwd,stdio:`inherit`}),``):u(e,{cwd:t?.cwd,stdio:`pipe`,encoding:`utf-8`})}const p=new Set([`.ts`,`.tsx`,`.mts`,`.json`,`.md`,`.yml`,`.yaml`,`.css`,`.html`]),m=new Set([`.env.example`,`Dockerfile`,`.gitignore`]),h=`__PROJECT_NAME__`,g=`__PROJECT_NAME_TITLE__`;async function _(e,t){await v(e,t)}async function v(e,t){let n=s(process.cwd(),e.name);if(t?.(`Creating Next.js app...`),f(`pnpm create next-app@16 ${e.name} --typescript --tailwind --no-eslint --app --no-src-dir --turbopack --react-compiler --skip-install --import-alias "@/*"`),await d(n,[`app/page.tsx`,`app/page.module.css`,`app/fonts`,`app/globals.css`,`README.md`]),t?.(`Extracting template...`),await b(n),t?.(`Personalizing template...`),await S(n,e.name),e.installDeps&&(t?.(`Installing dependencies...`),f(`pnpm install`,{cwd:n})),e.preset===`demo`){if(!e.installDeps)throw Error("Preset `demo` requires --install because the `lumi add` step runs from the scaffolded project. Re-run without --no-install, or pass --preset=minimal.");for(let e of y)t?.(`Adding ${e} plugin...`),f(`pnpm exec lumi add ${e}`,{cwd:n,inherit:!0})}}const y=[`media`,`ticketing`];async function b(t){let n=x();if(!e(n))throw Error(`Template tarball missing: ${n}\nRun \`pnpm --filter @murumets-ee/create build:templates\` first.`);await l({file:n,cwd:t})}function x(){let n=o(c(import.meta.url)),r=n;for(let n=0;n<5;n++){let n=s(r,`package.json`);if(e(n))try{if(JSON.parse(t(n,`utf-8`)).name===`@murumets-ee/create`)return s(r,`templates`,`template-demo.tar.gz`)}catch{}let i=o(r);if(i===r)break;r=i}throw Error(`Could not find @murumets-ee/create package root above ${n}. template-demo.tar.gz cannot be located.`)}async function S(e,t){let r=E(t);for await(let i of w(e)){if(!T(i))continue;let e=await n(i,`utf-8`);!e.includes(h)&&!e.includes(g)||await a(i,e.split(g).join(r).split(h).join(t),`utf-8`)}}const C=new Set([`node_modules`,`dist`,`build`,`coverage`,`out`]);async function*w(e){let t=await r(e,{withFileTypes:!0});for(let n of t){let t=s(e,n.name);if(n.isDirectory()){if(C.has(n.name)||n.name.startsWith(`.`))continue;yield*w(t)}else n.isFile()&&(yield t)}}function T(e){let t=e.lastIndexOf(`/`),n=t>=0?e.slice(t+1):e;if(m.has(n))return!0;let r=n.lastIndexOf(`.`);if(r<0)return!1;let i=n.slice(r);return p.has(i)}function E(e){return e.split(/[-_\s]+/).filter(Boolean).map(e=>e[0]?.toUpperCase()+e.slice(1)).join(` `)}export{_ as scaffold};
|
|
57
2
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":["tarExtract"],"sources":["../src/utils.ts","../src/scaffold.ts"],"sourcesContent":["import { execSync } from 'node:child_process'\nimport { appendFile, writeFile as fsWriteFile, mkdir, readFile, rm } from 'node:fs/promises'\nimport { dirname, join } from 'node:path'\n\n/** Write a file, creating parent directories as needed */\nexport async function writeFile(filePath: string, content: string): Promise<void> {\n await mkdir(dirname(filePath), { recursive: true })\n await fsWriteFile(filePath, content, 'utf-8')\n}\n\n/** Read and parse package.json, merge in new deps/scripts, write back */\nexport async function mergePackageJson(\n pkgPath: string,\n merge: {\n type?: string\n dependencies?: Record<string, string>\n devDependencies?: Record<string, string>\n scripts?: Record<string, string>\n },\n): Promise<void> {\n const raw = await readFile(pkgPath, 'utf-8')\n const pkg = JSON.parse(raw)\n\n if (merge.type) {\n pkg.type = merge.type\n }\n if (merge.dependencies) {\n pkg.dependencies = { ...pkg.dependencies, ...merge.dependencies }\n }\n if (merge.devDependencies) {\n pkg.devDependencies = { ...pkg.devDependencies, ...merge.devDependencies }\n }\n if (merge.scripts) {\n pkg.scripts = { ...pkg.scripts, ...merge.scripts }\n }\n\n await fsWriteFile(pkgPath, `${JSON.stringify(pkg, null, 2)}\\n`, 'utf-8')\n}\n\n/** Delete files (silently ignores missing) */\nexport async function deleteFiles(basePath: string, files: string[]): Promise<void> {\n for (const file of files) {\n await rm(join(basePath, file), { force: true, recursive: true })\n }\n}\n\n/** Run a shell command synchronously */\nexport function runCommand(cmd: string, options?: { cwd?: string }): string {\n return execSync(cmd, {\n cwd: options?.cwd,\n stdio: 'pipe',\n encoding: 'utf-8',\n })\n}\n\n/** Append content to a file */\nexport async function appendToFile(filePath: string, content: string): Promise<void> {\n await appendFile(filePath, content, 'utf-8')\n}\n","import { existsSync, readFileSync } from 'node:fs'\nimport { readdir, readFile, rm, writeFile } from 'node:fs/promises'\nimport { dirname, join } from 'node:path'\nimport { fileURLToPath } from 'node:url'\nimport { extract as tarExtract } from 'tar'\nimport type { ProjectOptions } from './types'\nimport { deleteFiles, runCommand } from './utils'\n\n// Major Next.js version passed to `pnpm create next-app@<ver>`.\n// Bumped when the toolkit as a whole moves to a new Next major.\nconst CREATE_NEXT_APP_VERSION = '16'\n\nexport type ProgressCallback = (message: string) => void\n\n// File extensions eligible for token replacement during scaffolding.\nconst TOKENIZABLE_EXTENSIONS = new Set<string>([\n '.ts',\n '.tsx',\n '.mts',\n '.json',\n '.md',\n '.yml',\n '.yaml',\n '.css',\n '.html',\n])\n\nconst TOKENIZABLE_BASENAMES = new Set<string>(['.env.example', 'Dockerfile', '.gitignore'])\n\nconst TOKEN_PROJECT_NAME = '__PROJECT_NAME__'\nconst TOKEN_PROJECT_NAME_TITLE = '__PROJECT_NAME_TITLE__'\n\nexport async function scaffold(\n options: ProjectOptions,\n onProgress?: ProgressCallback,\n): Promise<void> {\n await scaffoldSingle(options, onProgress)\n}\n\n// ---------------------------------------------------------------------------\n// scaffoldSingle — extract a prebuilt tarball, then tokenize.\n// ---------------------------------------------------------------------------\n\nasync function scaffoldSingle(\n options: ProjectOptions,\n onProgress?: ProgressCallback,\n): Promise<void> {\n const projectDir = join(process.cwd(), options.name)\n\n // 1. Run create-next-app to get an authoritative Next.js skeleton\n // (lockfile, ESLint config, default tsconfig, etc.)\n onProgress?.('Creating Next.js app...')\n runCommand(\n `pnpm create next-app@${CREATE_NEXT_APP_VERSION} ${options.name} ` +\n '--typescript --tailwind --no-eslint --app --no-src-dir --turbopack --react-compiler --skip-install --import-alias \"@/*\"',\n )\n\n // 2. Cleanup default Next.js artifacts that the template will replace\n await deleteFiles(projectDir, [\n 'app/page.tsx',\n 'app/page.module.css',\n 'app/fonts',\n 'app/globals.css',\n 'README.md',\n ])\n\n // 3. Extract the prebuilt template tarball over the project directory.\n // Both demo and blank use the same tarball — blank strips content after.\n onProgress?.('Extracting template...')\n await extractTemplate(projectDir)\n\n // 4. For blank template: remove demo entities, seeds, and demo routes\n if (options.template === 'blank') {\n onProgress?.('Stripping demo content for blank template...')\n await stripForBlank(projectDir)\n }\n\n // 5. Replace tokens in tokenizable files\n onProgress?.('Personalizing template...')\n await tokenizeProject(projectDir, options.name)\n\n // 6. Install deps\n if (options.installDeps) {\n onProgress?.('Installing dependencies...')\n runCommand('pnpm install', { cwd: projectDir })\n }\n}\n\n// ---------------------------------------------------------------------------\n// Tarball extraction\n// ---------------------------------------------------------------------------\n\nasync function extractTemplate(destDir: string): Promise<void> {\n const tarball = resolveTemplateTarball()\n if (!existsSync(tarball)) {\n throw new Error(\n `Template tarball missing: ${tarball}\\n` +\n `Run \\`pnpm --filter @murumets-ee/create build:templates\\` first.`,\n )\n }\n await tarExtract({ file: tarball, cwd: destDir })\n}\n\n/**\n * Locate the template tarball relative to the published `@murumets-ee/create`\n * package root.\n *\n * Anchors on the package's own `package.json` (matched by `name`) so a parent\n * project that happens to have a `templates/` directory at a higher path\n * can't hijack the resolution. This is a defense-in-depth measure against\n * template-substitution attacks where `create-lumi` is invoked from inside\n * a malicious project layout.\n */\nfunction resolveTemplateTarball(): string {\n const here = dirname(fileURLToPath(import.meta.url))\n let dir = here\n for (let i = 0; i < 5; i++) {\n const pkgJsonPath = join(dir, 'package.json')\n if (existsSync(pkgJsonPath)) {\n try {\n const pkg = JSON.parse(readFileSync(pkgJsonPath, 'utf-8')) as { name?: string }\n if (pkg.name === '@murumets-ee/create') {\n return join(dir, 'templates', 'template-demo.tar.gz')\n }\n } catch {\n // Malformed package.json — keep walking.\n }\n }\n const parent = dirname(dir)\n if (parent === dir) break // hit filesystem root\n dir = parent\n }\n throw new Error(\n `Could not find @murumets-ee/create package root above ${here}. ` +\n `template-demo.tar.gz cannot be located.`,\n )\n}\n\n// ---------------------------------------------------------------------------\n// Blank template: post-extract cleanup\n// ---------------------------------------------------------------------------\n\n/** admin-config.ts for blank template — plugin entities only, no project entities. */\nconst BLANK_ADMIN_CONFIG = `/**\n * Shared admin configuration — entities + route resource metadata.\n *\n * Add your own entities to the arrays below after defining them in entities/.\n */\n\nimport { Media } from '@murumets-ee/media'\nimport {\n Ticket,\n TicketMessage,\n TicketAttachment,\n Department,\n TicketTag,\n} from '@murumets-ee/ticketing'\n\n/** All content entities registered in the admin API. */\nexport const allEntities = [\n Media,\n Ticket, TicketMessage, TicketAttachment, Department, TicketTag,\n]\n\n/** Taxonomy vocabularies. */\nexport const taxonomyVocabularies = {}\n\n/** Entities exposed via generic CRUD handler (subset of allEntities). */\nexport const crudEntities = [\n Media,\n Ticket, TicketMessage, TicketAttachment,\n]\n\n/**\n * Plugin route resource declarations.\n */\nexport const pluginResources: { resource: string; actions: readonly string[] }[] = [\n { resource: 'storage', actions: ['view', 'create', 'update', 'delete'] },\n { resource: 'settings', actions: ['view', 'update'] },\n { resource: 'audit-logs', actions: ['view'] },\n { resource: 'permissions', actions: ['view', 'create', 'update', 'delete'] },\n { resource: 'ticketing', actions: ['view', 'create', 'update', 'delete'] },\n]\n`\n\n/**\n * Strip demo content from a freshly extracted template to produce the\n * \"blank\" variant:\n *\n * 1. Delete entity files (keep `entities/index.ts` with empty exports)\n * 2. Delete seed files (keep `seeds/index.ts` with empty array)\n * 3. Delete `app/[locale]/(shell)/demos/` entirely\n * 4. Remove the demosGroup from `app/admin-layout.tsx`\n * 5. Rewrite toolkit.config.ts, admin-config.ts, content API route,\n * and admin dashboard to not reference project entities\n */\nasync function stripForBlank(projectDir: string): Promise<void> {\n // 1. Entities — delete all .ts files except index.ts, rewrite index to empty\n const entitiesDir = join(projectDir, 'entities')\n if (existsSync(entitiesDir)) {\n const files = await readdir(entitiesDir)\n for (const f of files) {\n if (f !== 'index.ts') await rm(join(entitiesDir, f), { force: true })\n }\n await writeFile(\n join(entitiesDir, 'index.ts'),\n '// Add your entities here and export them.\\n' +\n '// See https://github.com/murumets-ee/lumi-cms for documentation.\\n' +\n '\\n' +\n 'export const projectEntities = [] as const\\n' +\n 'export const projectTaxonomies = [] as const\\n',\n 'utf-8',\n )\n }\n\n // 2. Seeds — delete all .ts files except index.ts, rewrite index to empty\n const seedsDir = join(projectDir, 'seeds')\n if (existsSync(seedsDir)) {\n const files = await readdir(seedsDir)\n for (const f of files) {\n if (f !== 'index.ts') await rm(join(seedsDir, f), { force: true })\n }\n await writeFile(\n join(seedsDir, 'index.ts'),\n \"import type { AdminSeeder } from '@murumets-ee/admin-ui/pages'\\n\\n\" +\n 'export const projectSeeders: AdminSeeder[] = []\\n',\n 'utf-8',\n )\n }\n\n // 3. Demo routes\n const demosDir = join(projectDir, 'app', '[locale]', '(shell)', 'demos')\n await rm(demosDir, { recursive: true, force: true })\n\n // 4. Remove demosGroup from admin-layout.tsx (case-insensitive — comment says \"demo\")\n const layoutPath = join(projectDir, 'app', 'admin-layout.tsx')\n if (existsSync(layoutPath)) {\n let content = await readFile(layoutPath, 'utf-8')\n content = content.replace(\n /\\n\\s*\\/\\/.*demo.*[\\s\\S]*?const demosGroup[\\s\\S]*?\\}\\n/i,\n '\\n',\n )\n content = content.replace(', demosGroup', '')\n // Remove icon imports only used by demosGroup\n content = content.replace(/\\s*GalleryHorizontalEnd,\\n/, '\\n')\n content = content.replace(/\\s*HardDrive,\\n/, '\\n')\n content = content.replace(/\\s*Palette,\\n/, '\\n')\n await writeFile(layoutPath, content, 'utf-8')\n }\n\n // 5. Rewrite toolkit.config.ts — use projectEntities instead of named imports\n const configPath = join(projectDir, 'toolkit.config.ts')\n if (existsSync(configPath)) {\n let content = await readFile(configPath, 'utf-8')\n content = content.replace(\n /import \\{[^}]+\\} from '\\.\\/entities'/,\n \"import { projectEntities } from './entities'\",\n )\n content = content.replace(\n /entities: \\[[^\\]]+\\]/,\n 'entities: [...projectEntities]',\n )\n await writeFile(configPath, content, 'utf-8')\n }\n\n // 6. Rewrite lib/admin-config.ts — no project entities, only plugin entities\n const adminConfigPath = join(projectDir, 'lib', 'admin-config.ts')\n if (existsSync(adminConfigPath)) {\n await writeFile(\n adminConfigPath,\n BLANK_ADMIN_CONFIG,\n 'utf-8',\n )\n }\n\n // 7. Rewrite content API route — empty entity whitelist\n const contentRoutePath = join(projectDir, 'app', 'api', 'content', '[...path]', 'route.ts')\n if (existsSync(contentRoutePath)) {\n let content = await readFile(contentRoutePath, 'utf-8')\n content = content.replace(/import \\{[^}]+\\} from '@\\/entities'\\n/, '')\n content = content.replace(/entities: \\[[^\\]]+\\]/, 'entities: []')\n await writeFile(contentRoutePath, content, 'utf-8')\n }\n\n // 8. Replace admin dashboard page with auto-admin DashboardPage\n const dashboardPath = join(projectDir, 'app', '[locale]', '(shell)', 'admin', 'page.tsx')\n if (existsSync(dashboardPath)) {\n await writeFile(\n dashboardPath,\n \"import { pages } from '@/lib/admin-pages'\\n\\nexport default pages.DashboardPage\\n\",\n 'utf-8',\n )\n }\n}\n\n// ---------------------------------------------------------------------------\n// Token replacement\n// ---------------------------------------------------------------------------\n\n/**\n * Walk the project directory and replace `__PROJECT_NAME__` /\n * `__PROJECT_NAME_TITLE__` tokens in eligible text files.\n *\n * Binary files (images, fonts) and `node_modules` / `.next` are skipped\n * to avoid corruption and pointless work.\n */\nasync function tokenizeProject(projectDir: string, projectName: string): Promise<void> {\n const titleName = toTitleCase(projectName)\n for await (const filePath of walkFiles(projectDir)) {\n if (!isTokenizable(filePath)) continue\n const original = await readFile(filePath, 'utf-8')\n if (!original.includes(TOKEN_PROJECT_NAME) && !original.includes(TOKEN_PROJECT_NAME_TITLE)) {\n continue\n }\n const replaced = original\n .split(TOKEN_PROJECT_NAME_TITLE)\n .join(titleName)\n .split(TOKEN_PROJECT_NAME)\n .join(projectName)\n await writeFile(filePath, replaced, 'utf-8')\n }\n}\n\n/**\n * Directories the tokenizer must skip.\n */\nconst SKIP_DIRS = new Set<string>([\n 'node_modules',\n 'dist',\n 'build',\n 'coverage',\n 'out',\n])\n\nasync function* walkFiles(root: string): AsyncGenerator<string> {\n const entries = await readdir(root, { withFileTypes: true })\n for (const entry of entries) {\n const full = join(root, entry.name)\n if (entry.isDirectory()) {\n if (SKIP_DIRS.has(entry.name) || entry.name.startsWith('.')) continue\n yield* walkFiles(full)\n } else if (entry.isFile()) {\n yield full\n }\n }\n}\n\nfunction isTokenizable(filePath: string): boolean {\n const slash = filePath.lastIndexOf('/')\n const basename = slash >= 0 ? filePath.slice(slash + 1) : filePath\n if (TOKENIZABLE_BASENAMES.has(basename)) return true\n const dot = basename.lastIndexOf('.')\n if (dot < 0) return false\n const ext = basename.slice(dot)\n return TOKENIZABLE_EXTENSIONS.has(ext)\n}\n\nfunction toTitleCase(name: string): string {\n return name\n .split(/[-_\\s]+/)\n .filter(Boolean)\n .map((part) => part[0]?.toUpperCase() + part.slice(1))\n .join(' ')\n}\n"],"mappings":"0SAwCA,eAAsB,EAAY,EAAkB,EAAg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ACD,CAAC,CAEF,eAAgB,EAAU,EAAsC,CAC9D,IAAM,EAAU,MAAM,EAAQ,EAAM,CAAE,cAAe,GAAM,CAAC,CAC5D,IAAK,IAAM,KAAS,EAAS,CAC3B,IAAM,EAAO,EAAK,EAAM,EAAM,KAAK,CACnC,GAAI,EAAM,aAAa,CAAE,CACvB,GAAI,EAAU,IAAI,EAAM,KAAK,EAAI,EAAM,KAAK,WAAW,IAAI,CAAE,SAC7D,MAAO,EAAU,EAAK,MACb,EAAM,QAAQ,GACvB,MAAM,IAKZ,SAAS,EAAc,EAA2B,CAChD,IAAM,EAAQ,EAAS,YAAY,IAAI,CACjC,EAAW,GAAS,EAAI,EAAS,MAAM,EAAQ,EAAE,CAAG,EAC1D,GAAI,EAAsB,IAAI,EAAS,CAAE,MAAO,GAChD,IAAM,EAAM,EAAS,YAAY,IAAI,CACrC,GAAI,EAAM,EAAG,MAAO,GACpB,IAAM,EAAM,EAAS,MAAM,EAAI,CAC/B,OAAO,EAAuB,IAAI,EAAI,CAGxC,SAAS,EAAY,EAAsB,CACzC,OAAO,EACJ,MAAM,UAAU,CAChB,OAAO,QAAQ,CACf,IAAK,GAAS,EAAK,IAAI,aAAa,CAAG,EAAK,MAAM,EAAE,CAAC,CACrD,KAAK,IAAI"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["tarExtract"],"sources":["../src/utils.ts","../src/scaffold.ts"],"sourcesContent":["import { execSync } from 'node:child_process'\nimport { appendFile, writeFile as fsWriteFile, mkdir, readFile, rm } from 'node:fs/promises'\nimport { dirname, join } from 'node:path'\n\n/** Write a file, creating parent directories as needed */\nexport async function writeFile(filePath: string, content: string): Promise<void> {\n await mkdir(dirname(filePath), { recursive: true })\n await fsWriteFile(filePath, content, 'utf-8')\n}\n\n/** Read and parse package.json, merge in new deps/scripts, write back */\nexport async function mergePackageJson(\n pkgPath: string,\n merge: {\n type?: string\n dependencies?: Record<string, string>\n devDependencies?: Record<string, string>\n scripts?: Record<string, string>\n },\n): Promise<void> {\n const raw = await readFile(pkgPath, 'utf-8')\n const pkg = JSON.parse(raw)\n\n if (merge.type) {\n pkg.type = merge.type\n }\n if (merge.dependencies) {\n pkg.dependencies = { ...pkg.dependencies, ...merge.dependencies }\n }\n if (merge.devDependencies) {\n pkg.devDependencies = { ...pkg.devDependencies, ...merge.devDependencies }\n }\n if (merge.scripts) {\n pkg.scripts = { ...pkg.scripts, ...merge.scripts }\n }\n\n await fsWriteFile(pkgPath, `${JSON.stringify(pkg, null, 2)}\\n`, 'utf-8')\n}\n\n/** Delete files (silently ignores missing) */\nexport async function deleteFiles(basePath: string, files: string[]): Promise<void> {\n for (const file of files) {\n await rm(join(basePath, file), { force: true, recursive: true })\n }\n}\n\n/**\n * Run a shell command synchronously.\n *\n * `stdio: 'pipe'` by default so return-value-style callers get the\n * captured stdout. Pass `inherit: true` for commands whose output the\n * user should see in real time (and where the buffered error-on-fail\n * behavior of pipe would hide diagnostics — e.g. `pnpm exec lumi add`\n * in the demo-preset post-install loop).\n */\nexport function runCommand(\n cmd: string,\n options?: { cwd?: string; inherit?: boolean },\n): string {\n if (options?.inherit) {\n execSync(cmd, { cwd: options.cwd, stdio: 'inherit' })\n return ''\n }\n return execSync(cmd, {\n cwd: options?.cwd,\n stdio: 'pipe',\n encoding: 'utf-8',\n })\n}\n\n/** Append content to a file */\nexport async function appendToFile(filePath: string, content: string): Promise<void> {\n await appendFile(filePath, content, 'utf-8')\n}\n","import { existsSync, readFileSync } from 'node:fs'\nimport { readdir, readFile, writeFile } from 'node:fs/promises'\nimport { dirname, join } from 'node:path'\nimport { fileURLToPath } from 'node:url'\nimport { extract as tarExtract } from 'tar'\nimport type { ProjectOptions } from './types'\nimport { deleteFiles, runCommand } from './utils'\n\n// Major Next.js version passed to `pnpm create next-app@<ver>`.\n// Bumped when the toolkit as a whole moves to a new Next major.\nconst CREATE_NEXT_APP_VERSION = '16'\n\nexport type ProgressCallback = (message: string) => void\n\n// File extensions eligible for token replacement during scaffolding.\nconst TOKENIZABLE_EXTENSIONS = new Set<string>([\n '.ts',\n '.tsx',\n '.mts',\n '.json',\n '.md',\n '.yml',\n '.yaml',\n '.css',\n '.html',\n])\n\nconst TOKENIZABLE_BASENAMES = new Set<string>(['.env.example', 'Dockerfile', '.gitignore'])\n\nconst TOKEN_PROJECT_NAME = '__PROJECT_NAME__'\nconst TOKEN_PROJECT_NAME_TITLE = '__PROJECT_NAME_TITLE__'\n\nexport async function scaffold(\n options: ProjectOptions,\n onProgress?: ProgressCallback,\n): Promise<void> {\n await scaffoldSingle(options, onProgress)\n}\n\n// ---------------------------------------------------------------------------\n// scaffoldSingle — extract a prebuilt tarball, then tokenize.\n// ---------------------------------------------------------------------------\n\nasync function scaffoldSingle(\n options: ProjectOptions,\n onProgress?: ProgressCallback,\n): Promise<void> {\n const projectDir = join(process.cwd(), options.name)\n\n // 1. Run create-next-app to get an authoritative Next.js skeleton\n // (lockfile, ESLint config, default tsconfig, etc.)\n onProgress?.('Creating Next.js app...')\n runCommand(\n `pnpm create next-app@${CREATE_NEXT_APP_VERSION} ${options.name} ` +\n '--typescript --tailwind --no-eslint --app --no-src-dir --turbopack --react-compiler --skip-install --import-alias \"@/*\"',\n )\n\n // 2. Cleanup default Next.js artifacts that the template will replace\n await deleteFiles(projectDir, [\n 'app/page.tsx',\n 'app/page.module.css',\n 'app/fonts',\n 'app/globals.css',\n 'README.md',\n ])\n\n // 3. Extract the prebuilt template tarball over the project directory.\n // The template is the minimal Lumi skeleton — run `lumi add <plugin>`\n // after scaffolding to layer in plugins (auth is preinstalled).\n onProgress?.('Extracting template...')\n await extractTemplate(projectDir)\n\n // 4. Replace tokens in tokenizable files\n onProgress?.('Personalizing template...')\n await tokenizeProject(projectDir, options.name)\n\n // 5. Install deps\n if (options.installDeps) {\n onProgress?.('Installing dependencies...')\n runCommand('pnpm install', { cwd: projectDir })\n }\n\n // 6. Layer on demo-preset plugins via `lumi add`. Skipped for the minimal\n // preset — user runs `lumi add <plugin>` themselves. Requires the deps\n // step above, because `pnpm exec lumi` resolves the bin from\n // `node_modules/.bin/`.\n if (options.preset === 'demo') {\n if (!options.installDeps) {\n throw new Error(\n 'Preset `demo` requires --install because the `lumi add` step runs ' +\n 'from the scaffolded project. Re-run without --no-install, or pass ' +\n '--preset=minimal.',\n )\n }\n for (const plugin of DEMO_PRESET_PLUGINS) {\n onProgress?.(`Adding ${plugin} plugin...`)\n // stdio=inherit so the user sees `lumi add`'s own step-by-step\n // output + any error messages (otherwise they get buffered on\n // failure and surfaced as a generic execSync error).\n runCommand(`pnpm exec lumi add ${plugin}`, { cwd: projectDir, inherit: true })\n }\n }\n}\n\n/**\n * Optional plugins layered on top of the baseline skeleton for the demo\n * preset. Must stay in sync with `CATALOG` in `@murumets-ee/cli` minus\n * `auth` (which is preinstalled in the baseline `lumi.config.ts`). The\n * `preset-parity.test.ts` test reads `CATALOG` at test time and asserts\n * `[...DEMO_PRESET_PLUGINS, 'auth'].sort()` equals\n * `Object.keys(CATALOG).sort()` — rename or add an entry here whenever\n * the CLI catalog grows.\n */\nconst DEMO_PRESET_PLUGINS = ['media', 'ticketing'] as const\n\n// ---------------------------------------------------------------------------\n// Tarball extraction\n// ---------------------------------------------------------------------------\n\nasync function extractTemplate(destDir: string): Promise<void> {\n const tarball = resolveTemplateTarball()\n if (!existsSync(tarball)) {\n throw new Error(\n `Template tarball missing: ${tarball}\\n` +\n `Run \\`pnpm --filter @murumets-ee/create build:templates\\` first.`,\n )\n }\n await tarExtract({ file: tarball, cwd: destDir })\n}\n\n/**\n * Locate the template tarball relative to the published `@murumets-ee/create`\n * package root.\n *\n * Anchors on the package's own `package.json` (matched by `name`) so a parent\n * project that happens to have a `templates/` directory at a higher path\n * can't hijack the resolution. This is a defense-in-depth measure against\n * template-substitution attacks where `create-lumi` is invoked from inside\n * a malicious project layout.\n */\nfunction resolveTemplateTarball(): string {\n const here = dirname(fileURLToPath(import.meta.url))\n let dir = here\n for (let i = 0; i < 5; i++) {\n const pkgJsonPath = join(dir, 'package.json')\n if (existsSync(pkgJsonPath)) {\n try {\n const pkg = JSON.parse(readFileSync(pkgJsonPath, 'utf-8')) as { name?: string }\n if (pkg.name === '@murumets-ee/create') {\n return join(dir, 'templates', 'template-demo.tar.gz')\n }\n } catch {\n // Malformed package.json — keep walking.\n }\n }\n const parent = dirname(dir)\n if (parent === dir) break // hit filesystem root\n dir = parent\n }\n throw new Error(\n `Could not find @murumets-ee/create package root above ${here}. ` +\n `template-demo.tar.gz cannot be located.`,\n )\n}\n\n\n// ---------------------------------------------------------------------------\n// Token replacement\n// ---------------------------------------------------------------------------\n\n/**\n * Walk the project directory and replace `__PROJECT_NAME__` /\n * `__PROJECT_NAME_TITLE__` tokens in eligible text files.\n *\n * Binary files (images, fonts) and `node_modules` / `.next` are skipped\n * to avoid corruption and pointless work.\n */\nasync function tokenizeProject(projectDir: string, projectName: string): Promise<void> {\n const titleName = toTitleCase(projectName)\n for await (const filePath of walkFiles(projectDir)) {\n if (!isTokenizable(filePath)) continue\n const original = await readFile(filePath, 'utf-8')\n if (!original.includes(TOKEN_PROJECT_NAME) && !original.includes(TOKEN_PROJECT_NAME_TITLE)) {\n continue\n }\n const replaced = original\n .split(TOKEN_PROJECT_NAME_TITLE)\n .join(titleName)\n .split(TOKEN_PROJECT_NAME)\n .join(projectName)\n await writeFile(filePath, replaced, 'utf-8')\n }\n}\n\n/**\n * Directories the tokenizer must skip.\n */\nconst SKIP_DIRS = new Set<string>([\n 'node_modules',\n 'dist',\n 'build',\n 'coverage',\n 'out',\n])\n\nasync function* walkFiles(root: string): AsyncGenerator<string> {\n const entries = await readdir(root, { withFileTypes: true })\n for (const entry of entries) {\n const full = join(root, entry.name)\n if (entry.isDirectory()) {\n if (SKIP_DIRS.has(entry.name) || entry.name.startsWith('.')) continue\n yield* walkFiles(full)\n } else if (entry.isFile()) {\n yield full\n }\n }\n}\n\nfunction isTokenizable(filePath: string): boolean {\n const slash = filePath.lastIndexOf('/')\n const basename = slash >= 0 ? filePath.slice(slash + 1) : filePath\n if (TOKENIZABLE_BASENAMES.has(basename)) return true\n const dot = basename.lastIndexOf('.')\n if (dot < 0) return false\n const ext = basename.slice(dot)\n return TOKENIZABLE_EXTENSIONS.has(ext)\n}\n\nfunction toTitleCase(name: string): string {\n return name\n .split(/[-_\\s]+/)\n .filter(Boolean)\n .map((part) => part[0]?.toUpperCase() + part.slice(1))\n .join(' ')\n}\n"],"mappings":"0SAwCA,eAAsB,EAAY,EAAkB,EAAgC,CAClF,IAAK,IAAM,KAAQ,EACjB,MAAM,EAAG,EAAK,EAAU,EAAK,CAAE,CAAE,MAAO,GAAM,UAAW,GAAM,CAAC,CAapE,SAAgB,EACd,EACA,EACQ,CAKR,OAJI,GAAS,SACX,EAAS,EAAK,CAAE,IAAK,EAAQ,IAAK,MAAO,UAAW,CAAC,CAC9C,IAEF,EAAS,EAAK,CACnB,IAAK,GAAS,IACd,MAAO,OACP,SAAU,QACX,CAAC,CCzDJ,MAKM,EAAyB,IAAI,IAAY,CAC7C,MACA,OACA,OACA,QACA,MACA,OACA,QACA,OACA,QACD,CAAC,CAEI,EAAwB,IAAI,IAAY,CAAC,eAAgB,aAAc,aAAa,CAAC,CAErF,EAAqB,mBACrB,EAA2B,yBAEjC,eAAsB,EACpB,EACA,EACe,CACf,MAAM,EAAe,EAAS,EAAW,CAO3C,eAAe,EACb,EACA,EACe,CACf,IAAM,EAAa,EAAK,QAAQ,KAAK,CAAE,EAAQ,KAAK,CAuCpD,GAnCA,IAAa,0BAA0B,CACvC,EACE,2BAAmD,EAAQ,KAAK,0HAEjE,CAGD,MAAM,EAAY,EAAY,CAC5B,eACA,sBACA,YACA,kBACA,YACD,CAAC,CAKF,IAAa,yBAAyB,CACtC,MAAM,EAAgB,EAAW,CAGjC,IAAa,4BAA4B,CACzC,MAAM,EAAgB,EAAY,EAAQ,KAAK,CAG3C,EAAQ,cACV,IAAa,6BAA6B,CAC1C,EAAW,eAAgB,CAAE,IAAK,EAAY,CAAC,EAO7C,EAAQ,SAAW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WACA,MACD,CAAC,CAEF,eAAgB,EAAU,EAAsC,CAC9D,IAAM,EAAU,MAAM,EAAQ,EAAM,CAAE,cAAe,GAAM,CAAC,CAC5D,IAAK,IAAM,KAAS,EAAS,CAC3B,IAAM,EAAO,EAAK,EAAM,EAAM,KAAK,CACnC,GAAI,EAAM,aAAa,CAAE,CACvB,GAAI,EAAU,IAAI,EAAM,KAAK,EAAI,EAAM,KAAK,WAAW,IAAI,CAAE,SAC7D,MAAO,EAAU,EAAK,MACb,EAAM,QAAQ,GACvB,MAAM,IAKZ,SAAS,EAAc,EAA2B,CAChD,IAAM,EAAQ,EAAS,YAAY,IAAI,CACjC,EAAW,GAAS,EAAI,EAAS,MAAM,EAAQ,EAAE,CAAG,EAC1D,GAAI,EAAsB,IAAI,EAAS,CAAE,MAAO,GAChD,IAAM,EAAM,EAAS,YAAY,IAAI,CACrC,GAAI,EAAM,EAAG,MAAO,GACpB,IAAM,EAAM,EAAS,MAAM,EAAI,CAC/B,OAAO,EAAuB,IAAI,EAAI,CAGxC,SAAS,EAAY,EAAsB,CACzC,OAAO,EACJ,MAAM,UAAU,CAChB,OAAO,QAAQ,CACf,IAAK,GAAS,EAAK,IAAI,aAAa,CAAG,EAAK,MAAM,EAAE,CAAC,CACrD,KAAK,IAAI"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@murumets-ee/create",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"license": "Elastic-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -26,7 +26,8 @@
|
|
|
26
26
|
"@types/tar": "^6.1.13",
|
|
27
27
|
"tsdown": "^0.21.7",
|
|
28
28
|
"tsx": "^4.21.0",
|
|
29
|
-
"typescript": "^5.7.3"
|
|
29
|
+
"typescript": "^5.7.3",
|
|
30
|
+
"@murumets-ee/cli": "^0.6.0"
|
|
30
31
|
},
|
|
31
32
|
"scripts": {
|
|
32
33
|
"build": "node ../../scripts/verify-catalog-sync.mjs && tsdown && tsx scripts/build-templates.ts",
|
|
Binary file
|