@solution-lib/space 0.0.4 → 0.0.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/main.js CHANGED
@@ -1,15 +1,15 @@
1
1
  #!/usr/bin/env bun
2
- import {cli}from'@je-es/cli';import*as u from'fs';import*as T from'path';import {input,select,confirm}from'@inquirer/prompts';import {spawnSync}from'child_process';var U=Object.defineProperty;var q=(h=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(h,{get:(t,e)=>(typeof require<"u"?require:t)[e]}):h)(function(h){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+h+'" is not supported')});var B=(h,t)=>()=>(h&&(t=h(h=0)),t);var J=(h,t)=>{for(var e in t)U(h,e,{get:t[e],enumerable:true});};var N={};J(N,{TemplateRegistry:()=>S});var S,D=B(()=>{S=class{static{this.TEMPLATES={lib:{type:"lib",defaultTemplate:"clean",templates:[{name:"clean",label:"Clean Library",description:"Zero dependencies - just TypeScript and build tools",repo:"lib-clean",requiresSetup:false,ready:true}]},cli:{type:"cli",defaultTemplate:"clean",templates:[{name:"clean",label:"Clean CLI",description:"Comes with @je-es/cli library for quick CLI development",repo:"cli-clean",deps:["@je-es/cli"],requiresSetup:true,ready:true}]},server:{type:"server",defaultTemplate:"clean",templates:[{name:"clean",label:"Clean Server",description:"Comes with @je-es/server library for quick server development",repo:"server-clean",deps:["@je-es/server"],requiresSetup:true,ready:true}]}};}static getTemplatesForType(t,e=false){let r=this.TEMPLATES[t]?.templates||[];return e?r:r.filter(s=>s.ready)}static getReadyTemplatesForType(t){return this.getTemplatesForType(t,false)}static getDefaultTemplate(t){let e=this.TEMPLATES[t];if(!e)return "clean";let r=e.templates.find(a=>a.name===e.defaultTemplate&&a.ready);return r?r.name:e.templates.find(a=>a.ready)?.name||e.defaultTemplate}static getTemplate(t,e){let r=this.TEMPLATES[t];return r?r.templates.find(s=>s.name===e):null}static isTemplateReady(t,e){return this.getTemplate(t,e)?.ready||false}static isValidTemplate(t,e){return this.getTemplatesForType(t).some(s=>s.name===e)}static getRepoName(t,e){return this.getTemplate(t,e)?.repo||"ready-lib"}static getSpaceTypes(){return Object.keys(this.TEMPLATES)}};});D();var I=["name","version","description","keywords","license","homepage","bugs","author","repository","type","main","types","bin","files","exports","scripts","engines","peerDependencies","dependencies","devDependencies"],L=["type","template","pm","repo","author","createdAt"];var P=class{static format(t,e={}){let r=e.indent||" ",s=e.alignColons!==false,a=e.sortKeys||false,i=e.tabWidth||4,n=e.keyOrder||[],p=s?this.calculateGlobalMaxKeyLength(t):0,m=this.calculateMaxDepth(t)*(r===" "?i:r.length);return this.formatValue(t,0,r,s,a,p,m,i,n)}static formatFile(t,e={}){let r=q("fs"),s=r.readFileSync(t,"utf-8"),a=JSON.parse(s),i=this.format(a,e);r.writeFileSync(t,i+`
2
+ import {cli}from'@je-es/cli';import*as u from'fs';import*as T from'path';import {input,select,confirm}from'@inquirer/prompts';import {spawnSync}from'child_process';var U=Object.defineProperty;var q=(h=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(h,{get:(t,e)=>(typeof require<"u"?require:t)[e]}):h)(function(h){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+h+'" is not supported')});var B=(h,t)=>()=>(h&&(t=h(h=0)),t);var J=(h,t)=>{for(var e in t)U(h,e,{get:t[e],enumerable:true});};var N={};J(N,{TemplateRegistry:()=>w});var w,D=B(()=>{w=class{static{this.TEMPLATES={lib:{type:"lib",defaultTemplate:"clean",templates:[{name:"clean",label:"Clean Library",description:"Zero dependencies - just TypeScript and build tools",repo:"lib",requiresSetup:false,ready:true}]},cli:{type:"cli",defaultTemplate:"clean",templates:[{name:"clean",label:"Clean CLI",description:"Comes with @je-es/cli library for quick CLI development",repo:"cli",deps:["@je-es/cli"],requiresSetup:true,ready:true}]},server:{type:"server",defaultTemplate:"clean",templates:[{name:"clean",label:"Clean Server",description:"Comes with @je-es/server library for quick server development",repo:"server",deps:["@je-es/server"],requiresSetup:true,ready:true}]},web:{type:"web",defaultTemplate:"clean",templates:[{name:"clean",label:"Clean Web App",description:"Comes with @je-es/server and @je-es/client libs for quick web development",repo:"web",deps:["@je-es/server","@je-es/client"],requiresSetup:true,ready:true}]}};}static getTemplatesForType(t,e=false){let r=this.TEMPLATES[t]?.templates||[];return e?r:r.filter(s=>s.ready)}static getReadyTemplatesForType(t){return this.getTemplatesForType(t,false)}static getDefaultTemplate(t){let e=this.TEMPLATES[t];if(!e)return "clean";let r=e.templates.find(a=>a.name===e.defaultTemplate&&a.ready);return r?r.name:e.templates.find(a=>a.ready)?.name||e.defaultTemplate}static getTemplate(t,e){let r=this.TEMPLATES[t];return r?r.templates.find(s=>s.name===e):null}static isTemplateReady(t,e){return this.getTemplate(t,e)?.ready||false}static isValidTemplate(t,e){return this.getTemplatesForType(t).some(s=>s.name===e)}static getRepoName(t,e){return this.getTemplate(t,e)?.repo||"ready-lib"}static getSpaceTypes(){return Object.keys(this.TEMPLATES)}};});D();var j=["name","version","description","keywords","license","homepage","bugs","author","repository","type","main","types","bin","files","exports","scripts","engines","peerDependencies","dependencies","devDependencies"],L=["type","template","pm","repo","author","createdAt"];var P=class{static format(t,e={}){let r=e.indent||" ",s=e.alignColons!==false,a=e.sortKeys||false,i=e.tabWidth||4,n=e.keyOrder||[],p=s?this.calculateGlobalMaxKeyLength(t):0,m=this.calculateMaxDepth(t)*(r===" "?i:r.length);return this.formatValue(t,0,r,s,a,p,m,i,n)}static formatFile(t,e={}){let r=q("fs"),s=r.readFileSync(t,"utf-8"),a=JSON.parse(s),i=this.format(a,e);r.writeFileSync(t,i+`
3
3
  `,"utf-8");}static calculateMaxDepth(t,e=0){if(!t||typeof t!="object")return e;let r=e;return Array.isArray(t)?t.forEach(s=>{let a=this.calculateMaxDepth(s,e+1);a>r&&(r=a);}):Object.values(t).forEach(s=>{let a=this.calculateMaxDepth(s,e+1);a>r&&(r=a);}),r}static sortKeys(t,e,r){if(e.length===0)return r?t.sort():t;let s=[],a=[];return t.forEach(i=>{e.includes(i)?s.push(i):a.push(i);}),s.sort((i,n)=>e.indexOf(i)-e.indexOf(n)),r&&a.sort(),[...s,...a]}static calculateGlobalMaxKeyLength(t){let e=0,r=s=>{if(!s||typeof s!="object")return;if(Array.isArray(s)){s.forEach(i=>r(i));return}Object.keys(s).forEach(i=>{let n=JSON.stringify(i).length;n>e&&(e=n),r(s[i]);});};return r(t),e}static formatValue(t,e,r,s,a,i,n,p,d){if(t===null)return "null";if(t===void 0)return "undefined";let m=typeof t;return m==="string"?JSON.stringify(t):m==="number"||m==="boolean"?String(t):Array.isArray(t)?this.formatArray(t,e,r,s,a,i,n,p,d):m==="object"?this.formatObject(t,e,r,s,a,i,n,p,d):JSON.stringify(t)}static formatArray(t,e,r,s,a,i,n,p,d){if(t.length===0)return "[]";if(t.every(l=>typeof l=="string"||typeof l=="number"||typeof l=="boolean"||l===null)&&t.length<=3)return "["+t.map(l=>this.formatValue(l,e,r,s,a,i,n,p,d)).join(", ")+"]";let f=r.repeat(e+1);return `[
4
4
  `+t.map(l=>f+this.formatValue(l,e+1,r,s,a,i,n,p,d)).join(`,
5
5
  `)+`
6
6
  `+r.repeat(e)+"]"}static formatObject(t,e,r,s,a,i,n,p,d){if(Object.keys(t).length===0)return "{}";let m=Object.keys(t);m=this.sortKeys(m,d,a);let f=r.repeat(e+1),k=(e+1)*(r===" "?p:r.length);return `{
7
- `+m.map(y=>{let g=JSON.stringify(y),b=this.formatValue(t[y],e+1,r,s,a,i,n,p,d);if(s){let c=n-k,E=i-g.length,_=" ".repeat(c+E);return `${f}${g}${_} : ${b}`}else return `${f}${g} : ${b}`}).join(`,
7
+ `+m.map(b=>{let g=JSON.stringify(b),y=this.formatValue(t[b],e+1,r,s,a,i,n,p,d);if(s){let c=n-k,E=i-g.length,_=" ".repeat(c+E);return `${f}${g}${_} : ${y}`}else return `${f}${g} : ${y}`}).join(`,
8
8
  `)+`
9
- `+r.repeat(e)+"}"}};var j=class{constructor(t=process.cwd()){this.basePath=t;}async createSpace(t,e){let r=e||T.join(this.basePath,t.repo.name);if(u.existsSync(r))throw new Error(`Space path "${r}" already exists!`);let s=false;try{u.existsSync(r)||(u.mkdirSync(r,{recursive:!0}),s=!0),await this.cloneTemplate(t.type,r,t,t.template),this.createSpaceConfig(r,t);}catch(a){if(s&&u.existsSync(r))try{await this.safeDeleteDirectory(r);}catch{console.warn(`Warning: Could not clean up directory at "${r}"`);}throw a}}loadSpaceConfig(t){let e=t||this.basePath,r=T.join(e,".space");if(!u.existsSync(r))return null;let s=u.readFileSync(r,"utf-8");return JSON.parse(s)}isSpace(t){let e=t||this.basePath;return u.existsSync(T.join(e,".space"))}async cloneTemplate(t,e,r,s){let i=`https://github.com/solution-dist/${S.getRepoName(t,s)}.git`;try{let{execSync:n}=await import('child_process');n(`git clone --quiet --depth 1 ${i} "${e}"`,{stdio:"pipe"});let p=T.join(e,".git");u.existsSync(p)&&await this.safeDeleteDirectory(p),await this.updateTemplateFiles(e,r);}catch(n){throw n.message&&n.message.includes("Repository not found")?new Error(`Template repository not found: ${i}
10
- This template is not yet available. Please mark it as ready: false in templateRegistry.ts`):new Error(`Failed to clone template from ${i}: ${n.message||n}`)}}async updateTemplateFiles(t,e){let r=e.repo.org&&e.repo.org.trim()!=="",s=e.author.id&&e.author.id.trim()!=="",a=r?e.repo.org:s?e.author.id:"",i=a?`git+https://github.com/${a}/${e.repo.name}.git`:"",n=a?`https://github.com/${a}/${e.repo.name}#readme`:"",p=a?`https://github.com/${a}/${e.repo.name}/issues`:"",d=r?`@${e.repo.org}/${e.repo.name}`:e.repo.name,m="\u{1F525}-";r?m+=`@${(e.repo.org.replace(/-/g,"--")+"/"+e.repo.name.replace(/-/g,"--")).replace(/ /g,"_")}`:e.author.name?m+=(e.author.name.replace(/-/g,"--")+"/"+e.repo.name.replace(/-/g,"--")).replace(/ /g,"_"):m+=e.repo.name.replace(/-/g,"--").replace(/ /g,"_");let f=s?`https://github.com/${e.author.id}`:e.author.url||"",k=e.repo.kw&&e.repo.kw.length>0?JSON.stringify(e.repo.kw):"[]",l=this.getAllFiles(t);for(let y of l)if(!(y.includes("node_modules")||y.includes(".git")))try{let g=u.readFileSync(y,"utf-8"),b=!1;if(g.includes("{{")&&(b=!0,g=g.replace(/\{\{tag\}\}/g,d).replace(/\{\{tag-badge\}\}/g,m).replace(/\{\{name\}\}/g,e.repo.name).replace(/\{\{repo\}\}/g,e.repo.name).replace(/\{\{org\}\}/g,e.repo.org||"").replace(/\{\{desc\}\}/g,e.repo.desc||`A ${e.type} space`).replace(/\{\{description\}\}/g,e.repo.desc||`A ${e.type} space`).replace(/\{\{version\}\}/g,e.repo.version).replace(/\{\{license\}\}/g,e.repo.license||"MIT").replace(/\{\{kw\}\}/g,k).replace(/\{\{keywords\}\}/g,k).replace(/\{\{url\}\}/g,i).replace(/\{\{repo_url\}\}/g,i).replace(/\{\{git_url\}\}/g,i).replace(/\{\{homepage\}\}/g,n).replace(/\{\{issues\}\}/g,p).replace(/\{\{type\}\}/g,e.type).replace(/\{\{template\}\}/g,e.template||"clean").replace(/\{\{pm\}\}/g,e.pm).replace(/\{\{author\}\}/g,e.author.name||"").replace(/\{\{author_name\}\}/g,e.author.name||"").replace(/\{\{author_id\}\}/g,e.author.id||"").replace(/\{\{author_email\}\}/g,e.author.email||"").replace(/\{\{author_url\}\}/g,f),u.writeFileSync(y,g,"utf-8")),y.endsWith("package.json")){let c=JSON.parse(g);if(c.name=d,c.version=e.repo.version,c.description=e.repo.desc||`A ${e.type} space`,c.license=e.repo.license||"MIT",e.repo.kw&&e.repo.kw.length>0?c.keywords=e.repo.kw:c.keywords=[],n&&(c.homepage=n),p&&(c.bugs||(c.bugs={}),c.bugs.url=p),e.author.name&&(e.author.email?c.author={name:e.author.name,email:e.author.email,url:f||void 0}:c.author={name:e.author.name,url:f||void 0}),i&&(c.repository={type:"git",url:i}),e.type==="cli"&&c.bin){let E=Object.keys(c.bin)[0],_=c.bin[E];delete c.bin[E],c.bin[e.repo.name]=_;}c.engines||(c.engines={}),c.engines.bun||(c.engines.bun=">=1.0.0"),g=P.format(c,{keyOrder:I}),u.writeFileSync(y,g+`
9
+ `+r.repeat(e)+"}"}};var I=class{constructor(t=process.cwd()){this.basePath=t;}async createSpace(t,e){let r=e||T.join(this.basePath,t.repo.name);if(u.existsSync(r))throw new Error(`Space path "${r}" already exists!`);let s=false;try{u.existsSync(r)||(u.mkdirSync(r,{recursive:!0}),s=!0),await this.cloneTemplate(t.type,r,t,t.template),this.createSpaceConfig(r,t);}catch(a){if(s&&u.existsSync(r))try{await this.safeDeleteDirectory(r);}catch{console.warn(`Warning: Could not clean up directory at "${r}"`);}throw a}}loadSpaceConfig(t){let e=t||this.basePath,r=T.join(e,".space");if(!u.existsSync(r))return null;let s=u.readFileSync(r,"utf-8");return JSON.parse(s)}isSpace(t){let e=t||this.basePath;return u.existsSync(T.join(e,".space"))}async cloneTemplate(t,e,r,s){let i=`https://github.com/solution-dist/${w.getRepoName(t,s)}.git`;try{let{execSync:n}=await import('child_process');n(`git clone --quiet --depth 1 ${i} "${e}"`,{stdio:"pipe"});let p=T.join(e,".git");u.existsSync(p)&&await this.safeDeleteDirectory(p),await this.updateTemplateFiles(e,r);}catch(n){throw n.message&&n.message.includes("Repository not found")?new Error(`Template repository not found: ${i}
10
+ This template is not yet available. Please mark it as ready: false in templateRegistry.ts`):new Error(`Failed to clone template from ${i}: ${n.message||n}`)}}async updateTemplateFiles(t,e){let r=e.repo.org&&e.repo.org.trim()!=="",s=e.author.id&&e.author.id.trim()!=="",a=r?e.repo.org:s?e.author.id:"",i=a?`git+https://github.com/${a}/${e.repo.name}.git`:"",n=a?`https://github.com/${a}/${e.repo.name}#readme`:"",p=a?`https://github.com/${a}/${e.repo.name}/issues`:"",d=r?`@${e.repo.org}/${e.repo.name}`:e.repo.name,m="\u{1F525}-";r?m+=`@${(e.repo.org.replace(/-/g,"--")+"/"+e.repo.name.replace(/-/g,"--")).replace(/ /g,"_")}`:e.author.name?m+=(e.author.name.replace(/-/g,"--")+"/"+e.repo.name.replace(/-/g,"--")).replace(/ /g,"_"):m+=e.repo.name.replace(/-/g,"--").replace(/ /g,"_");let f=s?`https://github.com/${e.author.id}`:e.author.url||"",k=e.repo.kw&&e.repo.kw.length>0?JSON.stringify(e.repo.kw):"[]",l=this.getAllFiles(t);for(let b of l)if(!(b.includes("node_modules")||b.includes(".git")))try{let g=u.readFileSync(b,"utf-8"),y=!1;if(g.includes("{{")&&(y=!0,g=g.replace(/\{\{tag\}\}/g,d).replace(/\{\{tag-badge\}\}/g,m).replace(/\{\{name\}\}/g,e.repo.name).replace(/\{\{repo\}\}/g,e.repo.name).replace(/\{\{org\}\}/g,e.repo.org||"").replace(/\{\{desc\}\}/g,e.repo.desc||`A ${e.type} space`).replace(/\{\{description\}\}/g,e.repo.desc||`A ${e.type} space`).replace(/\{\{version\}\}/g,e.repo.version).replace(/\{\{license\}\}/g,e.repo.license||"MIT").replace(/\{\{kw\}\}/g,k).replace(/\{\{keywords\}\}/g,k).replace(/\{\{url\}\}/g,i).replace(/\{\{repo_url\}\}/g,i).replace(/\{\{git_url\}\}/g,i).replace(/\{\{homepage\}\}/g,n).replace(/\{\{issues\}\}/g,p).replace(/\{\{type\}\}/g,e.type).replace(/\{\{template\}\}/g,e.template||"clean").replace(/\{\{pm\}\}/g,e.pm).replace(/\{\{author\}\}/g,e.author.name||"").replace(/\{\{author_name\}\}/g,e.author.name||"").replace(/\{\{author_id\}\}/g,e.author.id||"").replace(/\{\{author_email\}\}/g,e.author.email||"").replace(/\{\{author_url\}\}/g,f),u.writeFileSync(b,g,"utf-8")),b.endsWith("package.json")){let c=JSON.parse(g);if(c.name=d,c.version=e.repo.version,c.description=e.repo.desc||`A ${e.type} space`,c.license=e.repo.license||"MIT",e.repo.kw&&e.repo.kw.length>0?c.keywords=e.repo.kw:c.keywords=[],n&&(c.homepage=n),p&&(c.bugs||(c.bugs={}),c.bugs.url=p),e.author.name&&(e.author.email?c.author={name:e.author.name,email:e.author.email,url:f||void 0}:c.author={name:e.author.name,url:f||void 0}),i&&(c.repository={type:"git",url:i}),e.type==="cli"&&c.bin){let E=Object.keys(c.bin)[0],_=c.bin[E];delete c.bin[E],c.bin[e.repo.name]=_;}c.engines||(c.engines={}),c.engines.bun||(c.engines.bun=">=1.0.0"),g=P.format(c,{keyOrder:j}),u.writeFileSync(b,g+`
11
11
  `,"utf-8");continue}}catch{continue}}getAllFiles(t,e=[]){return u.readdirSync(t).forEach(s=>{let a=T.join(t,s);u.statSync(a).isDirectory()?e=this.getAllFiles(a,e):e.push(a);}),e}createSpaceConfig(t,e){let r=T.join(t,".space"),s=e.repo.org&&e.repo.org.trim()!=="",a=e.author.id&&e.author.id.trim()!=="",i=s?e.repo.org:a?e.author.id:"",n=i?`git+https://github.com/${i}/${e.repo.name}.git`:"",p=i?`https://github.com/${i}/${e.repo.name}#readme`:"",d=i?`https://github.com/${i}/${e.repo.name}/issues`:"",m=a?`https://github.com/${e.author.id}`:e.author.url||"",f={type:e.type,template:e.template||"clean",pm:e.pm,repo:{org:e.repo.org||"",name:e.repo.name,version:e.repo.version,desc:e.repo.desc||`A ${e.type} space`,kw:e.repo.kw||[],license:e.repo.license||"MIT",issues:d,homepage:p,git_url:n},author:{id:e.author.id||"",name:e.author.name||"",email:e.author.email||"",url:m},createdAt:new Date().toISOString()},k=P.format(f,{keyOrder:L});u.writeFileSync(r,k+`
12
- `,"utf-8");}async safeDeleteDirectory(t,e=3){for(let r=0;r<e;r++)try{if(u.rmSync(t,{recursive:!0,force:!0,maxRetries:3,retryDelay:100}),!u.existsSync(t))return}catch(s){if(r===e-1)throw s;await new Promise(a=>setTimeout(a,300*(r+1)));}}};var O=class{constructor(){this.pm="bun";this.DEFAULT_SCRIPTS={build:"tsup",test:"test"};}install(t,e){let r=[];e?.global?(r.push("install","--global"),t&&t.length>0?r.push(...t):(console.error("\u2718 Please specify packages to install globally"),process.exit(1))):(r.push("install"),t&&t.length>0&&r.push(...t),e?.dev&&r.push("--dev")),console.log(`\u2192 Installing${t?` ${t.join(", ")}`:" dependencies"}${e?.global?" globally":""}...`),this.execute(r),e?.global||this.format();}remove(t,e){let r=["remove"];e?.global&&r.push("--global"),r.push(...t),console.log(`\u{1F5D1}\uFE0F Removing ${t.join(", ")}${e?.global?" globally":""}...`),this.execute(r),e?.global||this.format();}link(t){t?(console.log(`\u{1F517} Linking global package "${t}" to current project...`),this.execute(["link",t])):(console.log("\u{1F517} Linking current package globally..."),this.execute(["link"]));}unlink(t){t?(console.log(`\u{1F513} Unlinking global package "${t}" from current project...`),this.execute(["unlink",t])):(console.log("\u{1F513} Unlinking current package globally..."),this.execute(["unlink"]));}run(t,e){let r=this.getScriptCommand(t);if(r||(console.error(`\u2718 Script "${t}" not found in package.json and no default available`),process.exit(1)),this.isUsingDefaultScript(t)){let a=[...r.split(" ")];e&&e.length>0&&a.push(...e),this.execute(a);}else {let s=["run",t];e&&e.length>0&&s.push("--",...e),this.execute(s);}}runSilent(t,e){let r=this.getScriptCommand(t);if(!r)throw new Error(`Script "${t}" not found in package.json and no default available`);if(this.isUsingDefaultScript(t)){let a=[...r.split(" ")];e&&e.length>0&&a.push(...e),this.executeSilent(a);}else {let s=["run",t];e&&e.length>0&&s.push("--",...e),this.executeSilent(s);}}update(t){console.log(`\u{1F504} Updating${t?` ${t.join(", ")}`:" all packages"}...`);let e=["update"];t&&t.length>0&&e.push(...t),this.execute(e),this.format();}list(t){let e=["pm","ls"];t?.global&&e.push("--global"),this.execute(e);}init(){console.log("\u{1F4DD} Initializing package.json..."),this.execute(["init","-y"]),this.format();}publish(t,e){let r=["publish"];t?.tag&&r.push("--tag",t.tag);let s=t?.access||"public";r.push("--access",s);let a=Bun.spawnSync(["bun",...r],{stdout:"pipe",stderr:"pipe"});if(a.exitCode===0){let n=new TextDecoder().decode(a.stdout).match(/\+ (.+@[\d.]+)/);e?n?e.stop(`\u2714 Published ${n[1]} successfully!`):e.stop("\u2714 Published successfully!"):console.log(n?`\u2714 Published ${n[1]} successfully!`:"\u2714 Published successfully!");}else {let i=new TextDecoder().decode(a.stderr);e?e.stopWithError("Publish failed!"):console.error("Publish failed!"),i&&console.error(i),process.exit(1);}}execute(t){Bun.spawnSync(["bun",...t],{stdout:"inherit",stderr:"inherit"}).exitCode!==0&&(console.error(`\u2718 Command failed: bun ${t.join(" ")}`),process.exit(1));}executeSilent(t){let e=Bun.spawnSync(["bun",...t],{stdout:"pipe",stderr:"pipe"});if(e.exitCode!==0){let r=new TextDecoder().decode(e.stderr);console.error(`\u2718 Command failed: bun ${t.join(" ")}`),r&&console.error(r),process.exit(1);}}getName(){return "bun"}getEmoji(){return "\u{1F95F}"}format(){try{let t=T.join(process.cwd(),"package.json");u.existsSync(t)&&P.formatFile(t,{keyOrder:I});}catch{}}getScriptCommand(t){let e=T.join(process.cwd(),"package.json");if(u.existsSync(e))try{let r=JSON.parse(u.readFileSync(e,"utf-8"));if(r.scripts&&r.scripts[t])return r.scripts[t]}catch{}return t in this.DEFAULT_SCRIPTS?this.DEFAULT_SCRIPTS[t]:null}isUsingDefaultScript(t){let e=T.join(process.cwd(),"package.json");if(u.existsSync(e))try{let r=JSON.parse(u.readFileSync(e,"utf-8"));if(r.scripts&&r.scripts[t])return !1}catch{}return t in this.DEFAULT_SCRIPTS}};D();var o=class{static async promptInit(t){let e=t.name,r=t.type,s=t.template,a=t.desc,i="";if((!e||e==="my-space")&&(e=await input({message:"name:",default:"my-space",validate:l=>{if(!l||l.trim()==="")return "Space name is required";let y=/^@([a-z0-9-_]+)\/([a-z0-9-_]+)$/,g=/^[a-z0-9-_]+$/;return !y.test(l)&&!g.test(l)?'Name must be either "package-name" or "@org/package-name" (lowercase, numbers, hyphens, underscores only)':true}})),!r){let l=S.getTemplatesForType("lib",false).length>0,y=S.getTemplatesForType("cli",false).length>0,g=S.getTemplatesForType("server",false).length>0;r=await select({message:"type:",choices:[{name:`\u2192 Library - TypeScript library for npm${l?"":" (Coming Soon)"}`,value:"lib",disabled:l?false:"No templates ready yet"},{name:`\u2192 CLI - Command-line tool${y?"":" (Coming Soon)"}`,value:"cli",disabled:y?false:"No templates ready yet"},{name:`\u2192 Server - Backend server application${g?"":" (Coming Soon)"}`,value:"server",disabled:g?false:"No templates ready yet"}]});}if(!s){let l=S.getTemplatesForType(r,true);if(l.filter(b=>b.ready).length===0)throw new Error(`No templates are ready yet for "${r}" spaces. This space type is coming soon!`);let g=l.map(b=>{let c=b.ready?"\u2714":"\u{1F6A7}",E=b.ready?"":" (Coming Soon)";return {name:`${c} ${b.label}${E} - ${b.description}`,value:b.name,short:b.label,disabled:b.ready?false:"Not ready yet"}});s=await select({message:"template:",choices:g,default:S.getDefaultTemplate(r)});}a||(a=await input({message:"desc:",default:r==="lib"?"A TypeScript library":r==="cli"?"A command-line tool":"A backend server"}));let n="bun";i=await input({message:"author name:",default:""});let p=await input({message:"author email:",default:"",validate:l=>l&&!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(l)?"Please enter a valid email address or leave empty":true}),d=await input({message:"github username:",default:"",validate:l=>l&&!/^[a-z0-9]([a-z0-9-]*[a-z0-9])?$/i.test(l)?"Please enter a valid GitHub username or leave empty":true}),m=await input({message:"keywords (comma-separated):",default:""}),f=m?m.split(",").map(l=>l.trim()).filter(l=>l):[],k=await input({message:"license:",default:"MIT"});return {name:e,type:r,template:s,description:a,packageManager:n,author:i,authorEmail:p,githubId:d,keywords:f,license:k}}static async promptPublish(t){if(!await confirm({message:`Are you sure you want to publish "${t}" to npm?`,default:false}))return {confirm:false};let r=await input({message:"Publish with a tag (e.g., beta, next) or leave empty for latest:",default:""}),s=await select({message:"\u{1F510} Access level:",choices:[{name:"Public - Anyone can install",value:"public"},{name:"Restricted - Requires authentication",value:"restricted"}],default:"public"});return {confirm:true,tag:r||void 0,access:s}}static async promptRemove(t){let e=await confirm({message:`Remove ${t.join(", ")}?`,default:true});return {packages:t,confirm:e}}static async promptConfirm(t,e=false){let s=(await import('readline')).createInterface({input:process.stdin,output:process.stdout}),a=e?" (Y/n)":" (y/N)";return new Promise(i=>{s.question(`${t}${a} `,n=>{s.close(),n.trim()===""?i(e):i(n.trim().toLowerCase()==="y"||n.trim().toLowerCase()==="yes");});})}static async promptInstall(t){let e=await input({message:"Enter package names (space-separated):",default:t||"",validate:s=>!s||s.trim()===""?"Please enter at least one package name":true}),r=await confirm({message:"\u{1F6E0}\uFE0F Install as dev dependency?",default:false});return {packages:e.split(" ").filter(s=>s.trim()),isDev:r}}static async promptUpdate(){return await select({message:"What do you want to update?",choices:[{name:"All packages",value:"all"},{name:"Specific packages",value:"specific"}]})==="all"?{updateAll:true}:{updateAll:false,packages:(await input({message:"\u{1F4E6} Enter package names (space-separated):",validate:r=>!r||r.trim()===""?"Please enter at least one package name":true})).split(" ").filter(r=>r.trim())}}static async promptUseCurrentDir(t){return await confirm({message:`Use current directory "${t}" as the space root?`,default:true})}static async promptDeleteExistingDir(t){return await confirm({message:`\u26A0\uFE0F Directory already exists at "${t}". Delete and recreate?`,default:false})}static showSuccess(t,e){console.log(""),e.forEach((r,s)=>{console.log(`\u2192 ${r}`);}),console.log("");}static showError(t,e){console.log(`
12
+ `,"utf-8");}async safeDeleteDirectory(t,e=3){for(let r=0;r<e;r++)try{if(u.rmSync(t,{recursive:!0,force:!0,maxRetries:3,retryDelay:100}),!u.existsSync(t))return}catch(s){if(r===e-1)throw s;await new Promise(a=>setTimeout(a,300*(r+1)));}}};var O=class{constructor(){this.pm="bun";this.DEFAULT_SCRIPTS={build:"tsup",test:"test"};}install(t,e){let r=[];e?.global?(r.push("install","--global"),t&&t.length>0?r.push(...t):(console.error("\u2718 Please specify packages to install globally"),process.exit(1))):(r.push("install"),t&&t.length>0&&r.push(...t),e?.dev&&r.push("--dev")),console.log(`\u2192 Installing${t?` ${t.join(", ")}`:" dependencies"}${e?.global?" globally":""}...`),this.execute(r),e?.global||this.format();}remove(t,e){let r=["remove"];e?.global&&r.push("--global"),r.push(...t),console.log(`\u{1F5D1}\uFE0F Removing ${t.join(", ")}${e?.global?" globally":""}...`),this.execute(r),e?.global||this.format();}link(t){t?(console.log(`\u{1F517} Linking global package "${t}" to current project...`),this.execute(["link",t])):(console.log("\u{1F517} Linking current package globally..."),this.execute(["link"]));}unlink(t){t?(console.log(`\u{1F513} Unlinking global package "${t}" from current project...`),this.execute(["unlink",t])):(console.log("\u{1F513} Unlinking current package globally..."),this.execute(["unlink"]));}run(t,e){let r=this.getScriptCommand(t);if(r||(console.error(`\u2718 Script "${t}" not found in package.json and no default available`),process.exit(1)),this.isUsingDefaultScript(t)){let a=[...r.split(" ")];e&&e.length>0&&a.push(...e),this.execute(a);}else {let s=["run",t];e&&e.length>0&&s.push("--",...e),this.execute(s);}}runSilent(t,e){let r=this.getScriptCommand(t);if(!r)throw new Error(`Script "${t}" not found in package.json and no default available`);if(this.isUsingDefaultScript(t)){let a=[...r.split(" ")];e&&e.length>0&&a.push(...e),this.executeSilent(a);}else {let s=["run",t];e&&e.length>0&&s.push("--",...e),this.executeSilent(s);}}update(t){console.log(`\u{1F504} Updating${t?` ${t.join(", ")}`:" all packages"}...`);let e=["update"];t&&t.length>0&&e.push(...t),this.execute(e),this.format();}list(t){let e=["pm","ls"];t?.global&&e.push("--global"),this.execute(e);}init(){console.log("\u{1F4DD} Initializing package.json..."),this.execute(["init","-y"]),this.format();}publish(t,e){let r=["publish"];t?.tag&&r.push("--tag",t.tag);let s=t?.access||"public";r.push("--access",s);let a=Bun.spawnSync(["bun",...r],{stdout:"pipe",stderr:"pipe"});if(a.exitCode===0){let n=new TextDecoder().decode(a.stdout).match(/\+ (.+@[\d.]+)/);e?n?e.stop(`\u2714 Published ${n[1]} successfully!`):e.stop("\u2714 Published successfully!"):console.log(n?`\u2714 Published ${n[1]} successfully!`:"\u2714 Published successfully!");}else {let i=new TextDecoder().decode(a.stderr);e?e.stopWithError("Publish failed!"):console.error("Publish failed!"),i&&console.error(i),process.exit(1);}}execute(t){Bun.spawnSync(["bun",...t],{stdout:"inherit",stderr:"inherit"}).exitCode!==0&&(console.error(`\u2718 Command failed: bun ${t.join(" ")}`),process.exit(1));}executeSilent(t){let e=Bun.spawnSync(["bun",...t],{stdout:"pipe",stderr:"pipe"});if(e.exitCode!==0){let r=new TextDecoder().decode(e.stderr);console.error(`\u2718 Command failed: bun ${t.join(" ")}`),r&&console.error(r),process.exit(1);}}getName(){return "bun"}getEmoji(){return "\u{1F95F}"}format(){try{let t=T.join(process.cwd(),"package.json");u.existsSync(t)&&P.formatFile(t,{keyOrder:j});}catch{}}getScriptCommand(t){let e=T.join(process.cwd(),"package.json");if(u.existsSync(e))try{let r=JSON.parse(u.readFileSync(e,"utf-8"));if(r.scripts&&r.scripts[t])return r.scripts[t]}catch{}return t in this.DEFAULT_SCRIPTS?this.DEFAULT_SCRIPTS[t]:null}isUsingDefaultScript(t){let e=T.join(process.cwd(),"package.json");if(u.existsSync(e))try{let r=JSON.parse(u.readFileSync(e,"utf-8"));if(r.scripts&&r.scripts[t])return !1}catch{}return t in this.DEFAULT_SCRIPTS}};D();var o=class{static async promptInit(t){let e=t.name,r=t.type,s=t.template,a=t.desc,i="";if((!e||e==="my-space")&&(e=await input({message:"name:",default:"my-space",validate:l=>{if(!l||l.trim()==="")return "Space name is required";let b=/^@([a-z0-9-_]+)\/([a-z0-9-_]+)$/,g=/^[a-z0-9-_]+$/;return !b.test(l)&&!g.test(l)?'Name must be either "package-name" or "@org/package-name" (lowercase, numbers, hyphens, underscores only)':true}})),!r){let l=w.getTemplatesForType("lib",false).length>0,b=w.getTemplatesForType("cli",false).length>0,g=w.getTemplatesForType("server",false).length>0,y=w.getTemplatesForType("web",false).length>0;r=await select({message:"type:",choices:[{name:`\u2192 Library - TypeScript library for npm${l?"":" (Coming Soon)"}`,value:"lib",disabled:l?false:"No templates ready yet"},{name:`\u2192 CLI - Command-line tool${b?"":" (Coming Soon)"}`,value:"cli",disabled:b?false:"No templates ready yet"},{name:`\u2192 Server - Backend server application${g?"":" (Coming Soon)"}`,value:"server",disabled:g?false:"No templates ready yet"},{name:`\u2192 Web App - Full-stack web application${y?"":" (Coming Soon)"}`,value:"web",disabled:y?false:"No templates ready yet"}]});}if(!s){let l=w.getTemplatesForType(r,true);if(l.filter(y=>y.ready).length===0)throw new Error(`No templates are ready yet for "${r}" spaces. This space type is coming soon!`);let g=l.map(y=>{let c=y.ready?"\u2714":"\u{1F6A7}",E=y.ready?"":" (Coming Soon)";return {name:`${c} ${y.label}${E} - ${y.description}`,value:y.name,short:y.label,disabled:y.ready?false:"Not ready yet"}});s=await select({message:"template:",choices:g,default:w.getDefaultTemplate(r)});}a||(a=await input({message:"desc:",default:r==="lib"?"A TypeScript library":r==="cli"?"A command-line tool":"A backend server"}));let n="bun";i=await input({message:"author name:",default:""});let p=await input({message:"author email:",default:"",validate:l=>l&&!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(l)?"Please enter a valid email address or leave empty":true}),d=await input({message:"github username:",default:"",validate:l=>l&&!/^[a-z0-9]([a-z0-9-]*[a-z0-9])?$/i.test(l)?"Please enter a valid GitHub username or leave empty":true}),m=await input({message:"keywords (comma-separated):",default:""}),f=m?m.split(",").map(l=>l.trim()).filter(l=>l):[],k=await input({message:"license:",default:"MIT"});return {name:e,type:r,template:s,description:a,packageManager:n,author:i,authorEmail:p,githubId:d,keywords:f,license:k}}static async promptPublish(t){if(!await confirm({message:`Are you sure you want to publish "${t}" to npm?`,default:false}))return {confirm:false};let r=await input({message:"Publish with a tag (e.g., beta, next) or leave empty for latest:",default:""}),s=await select({message:"\u{1F510} Access level:",choices:[{name:"Public - Anyone can install",value:"public"},{name:"Restricted - Requires authentication",value:"restricted"}],default:"public"});return {confirm:true,tag:r||void 0,access:s}}static async promptRemove(t){let e=await confirm({message:`Remove ${t.join(", ")}?`,default:true});return {packages:t,confirm:e}}static async promptConfirm(t,e=false){let s=(await import('readline')).createInterface({input:process.stdin,output:process.stdout}),a=e?" (Y/n)":" (y/N)";return new Promise(i=>{s.question(`${t}${a} `,n=>{s.close(),n.trim()===""?i(e):i(n.trim().toLowerCase()==="y"||n.trim().toLowerCase()==="yes");});})}static async promptInstall(t){let e=await input({message:"Enter package names (space-separated):",default:t||"",validate:s=>!s||s.trim()===""?"Please enter at least one package name":true}),r=await confirm({message:"\u{1F6E0}\uFE0F Install as dev dependency?",default:false});return {packages:e.split(" ").filter(s=>s.trim()),isDev:r}}static async promptUpdate(){return await select({message:"What do you want to update?",choices:[{name:"All packages",value:"all"},{name:"Specific packages",value:"specific"}]})==="all"?{updateAll:true}:{updateAll:false,packages:(await input({message:"\u{1F4E6} Enter package names (space-separated):",validate:r=>!r||r.trim()===""?"Please enter at least one package name":true})).split(" ").filter(r=>r.trim())}}static async promptUseCurrentDir(t){return await confirm({message:`Use current directory "${t}" as the space root?`,default:true})}static async promptDeleteExistingDir(t){return await confirm({message:`\u26A0\uFE0F Directory already exists at "${t}". Delete and recreate?`,default:false})}static showSuccess(t,e){console.log(""),e.forEach((r,s)=>{console.log(`\u2192 ${r}`);}),console.log("");}static showError(t,e){console.log(`
13
13
  \u2718 Error:`,t),e&&e.message&&console.log(` ${e.message}`),console.log("");}static showWarning(t){console.log(`
14
14
  \u26A0\uFE0F Warning:`,t),console.log("");}static showInfo(t){console.log(`
15
15
  \u2139\uFE0F `,t),console.log("");}};var $=class{constructor(){this.frames=["\u280B","\u2819","\u2839","\u2838","\u283C","\u2834","\u2826","\u2827","\u2807","\u280F"];this.currentFrame=0;this.interval=null;}start(t){process.stdout.write(`
@@ -17,7 +17,7 @@ ${t}`),this.interval=setInterval(()=>{process.stdout.write(`\r${this.frames[this
17
17
 
18
18
  `);}stopWithError(t){this.interval&&(clearInterval(this.interval),this.interval=null),process.stdout.write(`\r\u2718 ${t}
19
19
 
20
- `);}},M=class h{constructor(t){this.config=t;this.pm=null;this.spaceManager=new j,this.initPackageManager();}static create(t){return new h(t)}run(){cli(this.config.name,this.config.version).description(this.config.desc).command({name:"init",description:"Create a new space (lib or cli)",args:[{name:"name",required:false,default:"my-space",description:"Name of the space (supports @org/name format)"}],options:[{name:"type",flag:"--type",type:"string",required:false,description:"Type of space (lib or cli)"},{name:"description",flag:"--desc",type:"string",required:false,description:"Description of the space"}],action:t=>this.createNewSpaceOnGroundViaCLI(t)}).command({name:"info",description:"Show current space information",action:()=>this.showSpaceInfo()}).command({name:"install",aliases:["i"],description:"Install packages",args:[{name:"packages",required:false,description:"Packages to install (space-separated)"}],options:[{name:"dev",flag:"--dev",type:"boolean",required:false,description:"Install as dev dependency"},{name:"global",flag:"--global",type:"boolean",required:false,description:"Install globally"}],action:t=>this.installPackages(t)}).command({name:"remove",aliases:["r"],description:"Remove packages",args:[{name:"packages",required:true,description:"Packages to remove (space-separated)"}],options:[{name:"global",flag:"--global",type:"boolean",required:false,description:"Remove globally"}],action:t=>this.removePackages(t)}).command({name:"update",aliases:["up"],description:"Update packages",args:[{name:"packages",required:false,description:"Packages to update (space-separated, or all if empty)"}],action:t=>this.updatePackages(t)}).command({name:"link",description:"Link package globally (no args) or link global package to project (with package name)",args:[{name:"package",required:false,description:"Package name to link from global (optional)"}],action:t=>this.linkPackage(t)}).command({name:"unlink",description:"Unlink package globally (no args) or unlink global package from project (with package name)",args:[{name:"package",required:false,description:"Package name to unlink from global (optional)"}],action:t=>this.unlinkPackage(t)}).command({name:"list",aliases:["ls"],description:"List installed packages",options:[{name:"global",flag:"--global",type:"boolean",required:false,description:"List global packages"}],action:t=>this.listPackages(t)}).command({name:"build",description:"Build the current space",action:()=>this.buildSpace()}).command({name:"test",description:"Run tests for the current space",args:[{name:"path",required:false,description:"Specific test file or folder (optional)"}],action:t=>this.runTests(t)}).command({name:"run",description:"Run any script from package.json",args:[{name:"script",required:true,description:"Script name from package.json"}],allowDynamicArgs:true,allowDynamicOptions:true,action:t=>this.runScript(t)}).command({name:"clean",description:"Clean build artifacts",action:()=>this.clean()}).command({name:"start",description:"Start the main file",allowDynamicArgs:true,allowDynamicOptions:true,action:t=>this.startMain(t)}).command({name:"publish",description:"Publish space to npm registry",options:[{name:"tag",flag:"--tag",type:"string",required:false,description:"Publish with tag (e.g., beta, next)"},{name:"access",flag:"--access",type:"string",required:false,description:"Access level (public or restricted)"}],action:t=>this.publish(t)}).build().run();}static defaultConfig(){return {name:"Space",version:"0.0.1",desc:"Build flexible spaces for any platform"}}initPackageManager(){this.spaceManager.isSpace()&&(this.pm=new O);}ensureSpace(){return this.spaceManager.isSpace()?true:(console.error('\u2718 Not a space directory. Run "space init <name> --type lib|cli" first.'),false)}parsePackageName(t){let e=/^@([a-z0-9-_]+)\/([a-z0-9-_]+)$/i,r=t.match(e);return r?{org:r[1],name:r[2]}:{org:"",name:t}}async deleteDirectoryWithRetry(t,e=3){for(let r=0;r<e;r++)try{if(u.rmSync(t,{recursive:!0,force:!0,maxRetries:3,retryDelay:100}),!u.existsSync(t))return}catch(s){if(r===e-1)throw s;await new Promise(a=>setTimeout(a,500*(r+1)));}throw new Error("Failed to delete directory after multiple attempts")}async createNewSpaceOnGroundViaCLI(t){try{let e=await o.promptInit({type:t.options.type,template:t.options.template,org:"",name:t.args.name,desc:t.options.desc}),{org:r,name:s}=this.parsePackageName(e.name);["lib","cli","server"].includes(e.type)||(o.showError("Invalid space type. Must be lib, cli or server."),process.exit(1));let{TemplateRegistry:a}=await Promise.resolve().then(()=>(D(),N));a.isValidTemplate(e.type,e.template)||(o.showError("Invalid template for this space type."),process.exit(1)),a.isTemplateReady(e.type,e.template)||(o.showError("This template is not ready yet. Please choose another template."),process.exit(1));let i,n=T.basename(process.cwd());if(!s||s.trim()===""?await o.promptUseCurrentDir(n)?i=process.cwd():(o.showError("Space name is required when not using current directory"),process.exit(1)):n===s&&await o.promptUseCurrentDir(s)&&(i=process.cwd()),i||(i=T.join(process.cwd(),s)),u.existsSync(i)){u.statSync(i).isDirectory()||(o.showError(`Path "${i}" exists but is not a directory`),process.exit(1)),await o.promptDeleteExistingDir(i)||(o.showInfo("Space creation cancelled"),process.exit(0));try{await this.deleteDirectoryWithRetry(i);}catch(f){f.message&&(f.message.includes("EBUSY")||f.message.includes("EPERM")||f.message.includes("resource busy"))?o.showError(`Cannot delete directory - it's being used by another program.
20
+ `);}},M=class h{constructor(t){this.config=t;this.pm=null;this.spaceManager=new I,this.initPackageManager();}static create(t){return new h(t)}run(){cli(this.config.name,this.config.version).description(this.config.desc).command({name:"init",description:"Create a new space (lib or cli)",args:[{name:"name",required:false,default:"my-space",description:"Name of the space (supports @org/name format)"}],options:[{name:"type",flag:"--type",type:"string",required:false,description:"Type of space (lib or cli)"},{name:"description",flag:"--desc",type:"string",required:false,description:"Description of the space"}],action:t=>this.createNewSpaceOnGroundViaCLI(t)}).command({name:"info",description:"Show current space information",action:()=>this.showSpaceInfo()}).command({name:"install",aliases:["i"],description:"Install packages",args:[{name:"packages",required:false,description:"Packages to install (space-separated)"}],options:[{name:"dev",flag:"--dev",type:"boolean",required:false,description:"Install as dev dependency"},{name:"global",flag:"--global",type:"boolean",required:false,description:"Install globally"}],action:t=>this.installPackages(t)}).command({name:"remove",aliases:["r"],description:"Remove packages",args:[{name:"packages",required:true,description:"Packages to remove (space-separated)"}],options:[{name:"global",flag:"--global",type:"boolean",required:false,description:"Remove globally"}],action:t=>this.removePackages(t)}).command({name:"update",aliases:["up"],description:"Update packages",args:[{name:"packages",required:false,description:"Packages to update (space-separated, or all if empty)"}],action:t=>this.updatePackages(t)}).command({name:"link",description:"Link package globally (no args) or link global package to project (with package name)",args:[{name:"package",required:false,description:"Package name to link from global (optional)"}],action:t=>this.linkPackage(t)}).command({name:"unlink",description:"Unlink package globally (no args) or unlink global package from project (with package name)",args:[{name:"package",required:false,description:"Package name to unlink from global (optional)"}],action:t=>this.unlinkPackage(t)}).command({name:"list",aliases:["ls"],description:"List installed packages",options:[{name:"global",flag:"--global",type:"boolean",required:false,description:"List global packages"}],action:t=>this.listPackages(t)}).command({name:"build",description:"Build the current space",action:()=>this.buildSpace()}).command({name:"test",description:"Run tests for the current space",args:[{name:"path",required:false,description:"Specific test file or folder (optional)"}],action:t=>this.runTests(t)}).command({name:"run",description:"Run any script from package.json",args:[{name:"script",required:true,description:"Script name from package.json"}],allowDynamicArgs:true,allowDynamicOptions:true,action:t=>this.runScript(t)}).command({name:"clean",description:"Clean build artifacts",action:()=>this.clean()}).command({name:"start",description:"Start the main file",allowDynamicArgs:true,allowDynamicOptions:true,action:t=>this.startMain(t)}).command({name:"publish",description:"Publish space to npm registry",options:[{name:"tag",flag:"--tag",type:"string",required:false,description:"Publish with tag (e.g., beta, next)"},{name:"access",flag:"--access",type:"string",required:false,description:"Access level (public or restricted)"}],action:t=>this.publish(t)}).build().run();}static defaultConfig(){return {name:"Space",version:"0.0.1",desc:"Build flexible spaces for any platform"}}initPackageManager(){this.spaceManager.isSpace()&&(this.pm=new O);}ensureSpace(){return this.spaceManager.isSpace()?true:(console.error('\u2718 Not a space directory. Run "space init <name> --type lib|cli" first.'),false)}parsePackageName(t){let e=/^@([a-z0-9-_]+)\/([a-z0-9-_]+)$/i,r=t.match(e);return r?{org:r[1],name:r[2]}:{org:"",name:t}}async deleteDirectoryWithRetry(t,e=3){for(let r=0;r<e;r++)try{if(u.rmSync(t,{recursive:!0,force:!0,maxRetries:3,retryDelay:100}),!u.existsSync(t))return}catch(s){if(r===e-1)throw s;await new Promise(a=>setTimeout(a,500*(r+1)));}throw new Error("Failed to delete directory after multiple attempts")}async createNewSpaceOnGroundViaCLI(t){try{let e=await o.promptInit({type:t.options.type,template:t.options.template,org:"",name:t.args.name,desc:t.options.desc}),{org:r,name:s}=this.parsePackageName(e.name);["lib","cli","server"].includes(e.type)||(o.showError("Invalid space type. Must be lib, cli or server."),process.exit(1));let{TemplateRegistry:a}=await Promise.resolve().then(()=>(D(),N));a.isValidTemplate(e.type,e.template)||(o.showError("Invalid template for this space type."),process.exit(1)),a.isTemplateReady(e.type,e.template)||(o.showError("This template is not ready yet. Please choose another template."),process.exit(1));let i,n=T.basename(process.cwd());if(!s||s.trim()===""?await o.promptUseCurrentDir(n)?i=process.cwd():(o.showError("Space name is required when not using current directory"),process.exit(1)):n===s&&await o.promptUseCurrentDir(s)&&(i=process.cwd()),i||(i=T.join(process.cwd(),s)),u.existsSync(i)){u.statSync(i).isDirectory()||(o.showError(`Path "${i}" exists but is not a directory`),process.exit(1)),await o.promptDeleteExistingDir(i)||(o.showInfo("Space creation cancelled"),process.exit(0));try{await this.deleteDirectoryWithRetry(i);}catch(f){f.message&&(f.message.includes("EBUSY")||f.message.includes("EPERM")||f.message.includes("resource busy"))?o.showError(`Cannot delete directory - it's being used by another program.
21
21
 
22
22
  Please try:
23
23
  1. Close any terminals/editors with "${i}" open