@sugarcube-org/cli 0.0.0-alpha.3 → 0.0.0-alpha.5
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/index.mjs +2 -2
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -40,11 +40,11 @@ To fix this:
|
|
|
40
40
|
3. Or mark some files as theme files
|
|
41
41
|
See ${v.info("https://docs.sugarcube.sh")} to learn more.`)}}return t.data}p(_,"validateAndLoadConfig");async function ae(e){const n={$schema:"https://sugarcube.style/schema.json",...e};try{const t=JSON.stringify(n,null,2);await M("sugarcube.config.json",t)}catch(t){const o=t instanceof Error?`: ${t.message}`:"";throw new d(`Failed to write config file${o}`)}}p(ae,"writeConfig");function Ke(e){const n=e.split("/"),t=n.findIndex(s=>s==="variables");if(t===-1||t===n.length-1)return"default";const o=n[t+1];return!o||o.endsWith(".css")?"default":o}p(Ke,"getCollectionFromPath");function be(e,n){if(e.includes("/variables/")){const t=Ke(e),o=n.variables.get(t)??[];o.push(e),n.variables.set(t,o)}else e.startsWith("global/")?n.global.push(e):e.startsWith("compositions/")?n.compositions.push(e):e.startsWith("utilities/")&&n.utilities.push(e)}p(be,"groupFile");async function Ye(e,n,t="merge"){const o={variables:new Map,global:[],compositions:[],utilities:[]},s=h.join(n,"index.css");t==="merge"&&D(s)&&(await le(s,"utf-8")).split(`
|
|
42
42
|
`).filter(f=>f.trim().startsWith("@import")).map(f=>f.match(/'([^']+)'/)?.[1]).filter(f=>f!==void 0).forEach(f=>be(f,o)),e.filter(r=>r.endsWith(".css")).forEach(r=>{const u=h.relative(n,r).replace(/\\/g,"/");be(u,o)});const i=["reset.css","fonts.css","global-styles.css"];o.global.sort((r,u)=>{const f=i.findIndex(w=>r.endsWith(w)),m=i.findIndex(w=>u.endsWith(w));return f-m});const c=Array.from(o.variables.entries()).sort(([r,u],[f,m])=>r==="default"?-1:f==="default"?1:r.localeCompare(f)).flatMap(([r,u])=>u.sort((f,m)=>f.endsWith("tokens.variables.css")?-1:m.endsWith("tokens.variables.css")?1:f.localeCompare(m))),a=[...new Set([...c,...o.global,...o.compositions.sort(),...o.utilities.sort()])].map(r=>`@import '${r}';`);return await M(s,a.join(`
|
|
43
|
-
`)),s}p(Ye,"generateIndexFile");const Ze=p(()=>{B(g.inverse(" Welcome to sugarcube. The toolkit for seriously sweet front ends "))},"welcome");async function He(e,{withFallback:n=!1}={}){const t=await De({programmatic:!0,cwd:e});if(
|
|
43
|
+
`)),s}p(Ye,"generateIndexFile");const Ze=p(()=>{B(g.inverse(" Welcome to sugarcube. The toolkit for seriously sweet front ends "))},"welcome");async function He(e,{withFallback:n=!1}={}){const t=await De({programmatic:!0,cwd:e});if(t?.startsWith("yarn@"))return"yarn";if(t?.startsWith("pnpm@"))return"pnpm";if(t==="bun")return"bun";if(!n)return t?.split("@")[0]??"npm";const o=process.env.npm_config_user_agent||"";return o.startsWith("yarn")?"yarn":o.startsWith("pnpm")?"pnpm":o.startsWith("bun")?"bun":"npm"}p(He,"getPackageManager");async function Qe(e,n){const t=await He(n,{withFallback:!0});console.log("[install-dependencies] packageManager:",t),console.log("[install-dependencies] targetDir:",n),console.log("[install-dependencies] dependencies:",e);const o=t==="npm"?"install":"add";console.log("[install-dependencies] command:",`${t} ${o}`);try{await Ie(t,[o,...e],{cwd:n})}catch(s){throw console.log("[install-dependencies] error:",s),s}}p(Qe,"installDependencies");async function ve({registryIndex:e,selectedComponents:n,componentType:t,componentsOutputDirectory:o,cssOutputDirectory:s}){const i=[],c=new Set;await P(o,{recursive:!0});const a=h.join(s,"global","variables");await P(h.join(s,"global"),{recursive:!0}),await P(a,{recursive:!0});const r=await _e(e,n,t);for(const u of r){const f=await Z({type:"component",name:u.name,framework:t});for(const w of f.files)if(w)try{if(w.path.endsWith(".variables.css")){const y=h.join(a,`${u.name}.variables.css`);await M(y,w.content),i.push(y)}else{const y=h.join(o,u.name);await P(y,{recursive:!0});const $=h.join(y,h.basename(w.path));await M($,w.content),i.push($)}}catch(y){const $=y instanceof Error?`: ${y.message}`:"";throw new d(`Failed to write component file for "${u.name}"${$}`)}(u.dependencies?.[t]||[]).forEach(w=>c.add(w))}if(c.size>0)try{await Qe(Array.from(c),process.cwd())}catch(u){const f=u instanceof Error?`: ${u.message}`:"";throw new d(`Failed to install component dependencies${f}`)}return{createdFiles:i,npmDependencies:c}}p(ve,"installComponents");async function Xe(e){const n=[],t=h.resolve(process.cwd(),e);await P(t,{recursive:!0});const s=(await W()).filter(i=>i.type==="cube").map(i=>i.name);for(const i of s){const c=await Z({type:"cube",name:i});for(const a of c.files){if(!a)continue;const r=a.path.replace(/^styles\//,""),u=h.join(t,r),f=h.dirname(u);try{await P(f,{recursive:!0}),await M(u,a.content),n.push(u)}catch(m){const w=m instanceof Error?`: ${m.message}`:"";throw new d(`Failed to write CUBE module "${i}"${w}`)}}}return n}p(Xe,"installCUBE");function et(e){switch(e){case"react":return"tsx";case"astro":return"astro";case"nunjucks":return"njk";default:return"tsx"}}p(et,"getExtension");function Se({components:e,componentType:n,componentsOutputDirectory:t}){return e.filter(o=>{const s=h.join(t,o,`${o}.${et(n)}`);return D(s)})}p(Se,"checkComponentExists");async function H({mode:e,cssOutputDirectory:n,files:t,config:o}){if(!o.output.css.manageIndex)return;const s=t.filter(a=>a.endsWith(".css"));if(s.length===0)return;const i=h.join(n,"index.css"),c=D(i);if(!(e==="create"&&c&&(k.warn(g.yellow(`The following file will be overwritten:
|
|
44
44
|
${g.dim(" - index.css")}`)),!await K("Continue?",!1))))try{return await Ye(s,n,e)}catch(a){const r=a instanceof Error?`: ${a.message}`:"";throw new d(`Failed to ${e} CSS index file${r}`)}}p(H,"manageCSSIndex");function J(e){if(S.break(),e instanceof d){const n=e.message.split(`
|
|
45
45
|
`);n.length>1?(S.error(n[0]),S.break(),n.slice(1).forEach(t=>{S.error(` ${t.trim()}`)})):S.error(e.message),process.env.DEBUG&&e.cause&&S.info(`
|
|
46
46
|
Caused by:`,e.cause)}else S.error(`An unexpected error occurred: ${e instanceof Error?e.message:String(e)}
|
|
47
47
|
If this issue persists, please report it: ${g.cyanBright("https://github.com/sugarcube-org/sugarcube/issues")}`),process.env.DEBUG&&S.info(`
|
|
48
48
|
Error details:`,e);S.break(),process.exit(0)}p(J,"handleError");const tt=new O().name("init").description("Initialize a new project").action(async()=>{try{Ze(),(await Ve()).shouldProceed||process.exit(0),V("Step 1. Set up tokens");const n=await Ae();let t;switch(n){case"starter":const r=await Me(),u=await fe(),f=await Oe();try{t=await Je(r,u,f),t.config=Le(t.config||{},u,f,r)}catch(m){ne(`Failed to initialize starter kit: ${m instanceof Error?m.message:"Unknown error"}`),process.exit(1)}break;case"existing":t=await qe({});break}V("Step 2. Add style system");const o=await We();V("Step 3. Add components");const s=await de();let i=[];if(s!=="skip"){const r=await W();r||(ne("Failed to fetch component list"),process.exit(1));const u=await ge(r,s),f=await me(),m=await Se({components:u,componentType:s,componentsOutputDirectory:f});if(m.length>0){const w=m.join(", ");await K(`The following components already exist and will be overwritten: ${w}. Continue?`,!1)}if(u.length>0){const w=te();w.start("Installing components...");try{const{createdFiles:y,npmDependencies:$}=await ve({registryIndex:r,selectedComponents:u,componentType:s,componentsOutputDirectory:f,cssOutputDirectory:t.config.output.directories.css});i=y,w.stop("Components installed successfully")}catch(y){throw w.stop("Installation failed"),y}}}V("Step 4. Generating files");try{if(await se.mkdir(t.tokensDir,{recursive:!0}),await se.mkdir(t.config.output.directories.css,{recursive:!0}),n==="starter"){if(!t.tokenContent)throw new d("Failed to generate token content for starter kit");await se.writeFile(t.tokenPath,t.tokenContent)}}catch(r){const u=r instanceof Error?`: ${r.message}`:"";throw new d(`Failed to create project files${u}`)}let c=[];c=await we(t.trees,t.resolved,t.config);let a=[];o&&(a=await Xe(t.config.output.directories.css)),await H({mode:"create",cssOutputDirectory:t.config.output.directories.css,files:[...c.map(r=>r.name),...i.filter(r=>r.endsWith(".css")),...a],config:t.config}),await ae(t.config),Y({config:"sugarcube.config.json",tokens:n==="starter"?t.tokens:[],generated:[...c.map(r=>r.name),...a,...i,...t.config.output.css.manageIndex?["index.css"]:[]]}),L(g.greenBright("Success! Project initialized \u2728"))}catch(e){J(e)}}),nt=new O().name("generate").description("Generate CSS from your design tokens").option("--force","Skip confirmation when deleting stale files").action(async e=>{try{if(B(g.inverse(" Generate CSS variables from your design tokens ")),!D("sugarcube.config.json"))throw new d("This command requires a sugarcube project. Run 'npx make-sugarcube init' first.");const n=await _(),{trees:t,resolved:o}=await G(n),s=await we(t,o,n);n.output.css.manageIndex&&await H({mode:"merge",cssOutputDirectory:n.output.directories.css,files:s.map(i=>i.name),config:n}),Y({generated:[...s.map(i=>i.name),...n.output.css.manageIndex?["index.css"]:[]]}),L(g.greenBright("Success! CSS variables generated successfully. \u2728"))}catch(n){J(n)}}),st=new O().name("validate").description("Validate design token files").argument("[paths...]","Token files or directories to validate (e.g., tokens.json or ./tokens)").action(async e=>{try{if(B(g.inverse(" Validate design tokens ")),D("sugarcube.config.json")&&!e.length){const s=await _();await G(s),L(g.greenBright("All tokens are valid \u2728"));return}if(!e.length)throw new d("No paths specified. Please provide files/directories to validate, or run this in a Sugarcube project directory.");const n=e.map(s=>h.normalize(s));for(const s of n)if(!D(s))throw new d(`Path not found: ${s}
|
|
49
49
|
Please check that the specified files or directories exist`);const t=await ue(n.map(s=>s.endsWith(".json")?s:h.join(s,"**/*.json")));if(t.length===0)throw new d(`No JSON files found in the specified paths
|
|
50
|
-
Please ensure the paths contain .json files`);const o=D("sugarcube.config.json")?await _():{output:{directories:{tokens:".",css:"."},css:{separate:!1}}};await G({...o,tokens:{type:"custom",source:t.map(s=>h.relative(process.cwd(),s))}}),L(g.greenBright("All tokens are valid \u2728"))}catch(n){J(n)}}),ot=new O().name("components").description("Add components to your project").argument("[components...]","Components to add (e.g., button card)").option("-f, --framework <type>","Framework to use (react, astro, nunjucks)").option("-s, --silent","Suppress logs and prompts").action(async(e,n)=>{try{if(n.silent||B(g.inverse(" Add components ")),!D("sugarcube.config.json"))throw new d("This command requires a sugarcube project. Run 'npx make-sugarcube init' first.");let t=await _(),o,s=[],i;if(e.length>0){if(!n.framework)throw new d("Framework must be specified in non-interactive mode (--framework)");const r=["react","astro","nunjucks"];if(!r.includes(n.framework))throw new d(`Invalid framework. Must be one of: ${r.join(", ")}`);if(i=n.framework,s=e,!t.output.directories.components)throw new d("Components directory must be configured in non-interactive mode. Please run without arguments first.");o=h.resolve(process.cwd(),t.output.directories.components)}else{i=await de(!1);const r=await W();if(r||(ne("Failed to fetch component list"),process.exit(1)),s=await ge(r,i),t.output.directories.components)o=h.resolve(process.cwd(),t.output.directories.components);else{const u=await me();o=h.resolve(process.cwd(),u),t.output.directories.components=h.relative(process.cwd(),o),await ae(t)}}const c=await Se({components:s,componentType:i,componentsOutputDirectory:o});if(c.length>0&&!n.silent){const r=c.join(", ");await K(`The following components already exist and will be overwritten: ${r}. Continue?`,!1)}let a;n.silent||(a=te(),a.start("Installing components..."));try{const r=await W(),{createdFiles:u,npmDependencies:f}=await ve({registryIndex:r,selectedComponents:s,componentType:i,componentsOutputDirectory:o,cssOutputDirectory:t.output.directories.css});await H({mode:"merge",cssOutputDirectory:t.output.directories.css,files:u,config:t}),n.silent||(a?.stop("Components installed successfully"),Y({generated:u}),L(g.greenBright("Success! Components installed \u2728")))}catch(r){throw n.silent||a?.stop("Installation failed"),r}}catch(t){J(t)}}),rt=new O().name("cube").description("Add CUBE CSS to your project").option("-s, --silent","Suppress logs and prompts").action(async e=>{const n=[];try{if(!D("sugarcube.config.json"))throw new d("This command requires a sugarcube project. Run 'npx make-sugarcube init' first.");e.silent||B(g.inverse(" Add CUBE CSS "));const t=await _(),o=h.resolve(process.cwd(),t.output.directories.css);try{await P(o,{recursive:!0})}catch(c){const a=c instanceof Error?`: ${c.message}`:"";throw new d(`Failed to create output directory${a}`)}const i=(await W()).filter(c=>c.type==="cube").map(c=>c.name);for(const c of i){const a=await Z({type:"cube",name:c});for(const r of a.files){if(!r)continue;const u=r.path.replace(/^styles\//,""),f=h.join(o,u),m=h.dirname(f);try{await P(m,{recursive:!0}),await M(f,r.content),n.push(f)}catch(w){const y=w instanceof Error?`: ${w.message}`:"";throw new d(`Failed to write CUBE CSS file ${f}${y}`)}}}await H({mode:"merge",cssOutputDirectory:o,files:n,config:t}),await ae(t),!e.silent&&n.length>0&&(Y({generated:n}),L(g.greenBright("Success! CUBE CSS added successfully. \u2728")))}catch(t){J(t)}});var it="@sugarcube-org/cli",at="0.0.0-alpha.
|
|
50
|
+
Please ensure the paths contain .json files`);const o=D("sugarcube.config.json")?await _():{output:{directories:{tokens:".",css:"."},css:{separate:!1}}};await G({...o,tokens:{type:"custom",source:t.map(s=>h.relative(process.cwd(),s))}}),L(g.greenBright("All tokens are valid \u2728"))}catch(n){J(n)}}),ot=new O().name("components").description("Add components to your project").argument("[components...]","Components to add (e.g., button card)").option("-f, --framework <type>","Framework to use (react, astro, nunjucks)").option("-s, --silent","Suppress logs and prompts").action(async(e,n)=>{try{if(n.silent||B(g.inverse(" Add components ")),!D("sugarcube.config.json"))throw new d("This command requires a sugarcube project. Run 'npx make-sugarcube init' first.");let t=await _(),o,s=[],i;if(e.length>0){if(!n.framework)throw new d("Framework must be specified in non-interactive mode (--framework)");const r=["react","astro","nunjucks"];if(!r.includes(n.framework))throw new d(`Invalid framework. Must be one of: ${r.join(", ")}`);if(i=n.framework,s=e,!t.output.directories.components)throw new d("Components directory must be configured in non-interactive mode. Please run without arguments first.");o=h.resolve(process.cwd(),t.output.directories.components)}else{i=await de(!1);const r=await W();if(r||(ne("Failed to fetch component list"),process.exit(1)),s=await ge(r,i),t.output.directories.components)o=h.resolve(process.cwd(),t.output.directories.components);else{const u=await me();o=h.resolve(process.cwd(),u),t.output.directories.components=h.relative(process.cwd(),o),await ae(t)}}const c=await Se({components:s,componentType:i,componentsOutputDirectory:o});if(c.length>0&&!n.silent){const r=c.join(", ");await K(`The following components already exist and will be overwritten: ${r}. Continue?`,!1)}let a;n.silent||(a=te(),a.start("Installing components..."));try{console.log("[components] Starting installation"),console.log("[components] cwd:",process.cwd());const r=await W(),{createdFiles:u,npmDependencies:f}=await ve({registryIndex:r,selectedComponents:s,componentType:i,componentsOutputDirectory:o,cssOutputDirectory:t.output.directories.css});await H({mode:"merge",cssOutputDirectory:t.output.directories.css,files:u,config:t}),n.silent||(a?.stop("Components installed successfully"),Y({generated:u}),L(g.greenBright("Success! Components installed \u2728")))}catch(r){throw n.silent||a?.stop("Installation failed"),r}}catch(t){J(t)}}),rt=new O().name("cube").description("Add CUBE CSS to your project").option("-s, --silent","Suppress logs and prompts").action(async e=>{const n=[];try{if(!D("sugarcube.config.json"))throw new d("This command requires a sugarcube project. Run 'npx make-sugarcube init' first.");e.silent||B(g.inverse(" Add CUBE CSS "));const t=await _(),o=h.resolve(process.cwd(),t.output.directories.css);try{await P(o,{recursive:!0})}catch(c){const a=c instanceof Error?`: ${c.message}`:"";throw new d(`Failed to create output directory${a}`)}const i=(await W()).filter(c=>c.type==="cube").map(c=>c.name);for(const c of i){const a=await Z({type:"cube",name:c});for(const r of a.files){if(!r)continue;const u=r.path.replace(/^styles\//,""),f=h.join(o,u),m=h.dirname(f);try{await P(m,{recursive:!0}),await M(f,r.content),n.push(f)}catch(w){const y=w instanceof Error?`: ${w.message}`:"";throw new d(`Failed to write CUBE CSS file ${f}${y}`)}}}await H({mode:"merge",cssOutputDirectory:o,files:n,config:t}),await ae(t),!e.silent&&n.length>0&&(Y({generated:n}),L(g.greenBright("Success! CUBE CSS added successfully. \u2728")))}catch(t){J(t)}});var it="@sugarcube-org/cli",at="0.0.0-alpha.5",ct={access:"restricted"},lt="A CLI for scaffolding sugarcube applications",ut="UNLICENSED",pt="Mark Tomlinson",ft={type:"git",url:"https://github.com/sugarcube-org/sugarcube"},mt={url:"https://github.com/sugarcube-org/sugarcube/issues"},dt=["cli","design-system","components","CUBE CSS","react","sugarcube"],gt=["dist","README.md","LICENSE.md"],ht="module",wt={sugarcube:"./dist/index.mjs"},yt={build:"pkgroll --minify",dev:"cross-env REGISTRY_URL=http://localhost:8787/registry tsx src/index.ts",test:"vitest","type-check":"tsc --noEmit",start:"cross-env REGISTRY_URL=https://sugarcube-registry.mark-tomlinson3.workers.dev/registry tsx src/index.ts",prepublishOnly:"pnpm up @sugarcube-org/core --filter @sugarcube-org/cli && pnpm build"},kt={"@antfu/ni":"^23.3.0","@clack/prompts":"^0.9.1","@sugarcube-org/core":"workspace:*",commander:"^12.1.0","cross-env":"^7.0.3",execa:"^9.5.2","fast-glob":"^3.3.2","fs-extra":"^11.2.0","lucide-react":"^0.468.0","node-fetch":"^3.3.0",picocolors:"^1.1.1",prompts:"^2.4.2",zod:"^3.23.8"},bt={"@types/fs-extra":"^11.0.4","@types/prompts":"^2.4.9",pkgroll:"^2.5.1",tsx:"^4.19.2"},vt={name:it,version:at,publishConfig:ct,description:lt,license:ut,author:pt,repository:ft,bugs:mt,keywords:dt,files:gt,type:ht,bin:wt,scripts:yt,dependencies:kt,devDependencies:bt};process.on("SIGINT",()=>process.exit(0)),process.on("SIGTERM",()=>process.exit(0));async function St(){const e=new O().name("sugarcube").description("CLI for scaffolding sugarcube applications").version(vt.version,"-v, --version","display the version number");e.addCommand(tt).addCommand(nt).addCommand(st).addCommand(ot).addCommand(rt),e.parse()}p(St,"main"),St();
|