@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/README.md +12 -55
- package/dist/main.cjs +6 -6
- package/dist/main.cjs.map +1 -1
- package/dist/main.js +6 -6
- package/dist/main.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -3,21 +3,17 @@
|
|
|
3
3
|
<br>
|
|
4
4
|
<div align="center">
|
|
5
5
|
<p>
|
|
6
|
-
<img src="./assets/img/logo.png" alt="logo" style="" height="
|
|
6
|
+
<img src="./assets/img/logo.png" alt="logo" style="" height="80" />
|
|
7
7
|
</p>
|
|
8
8
|
</div>
|
|
9
9
|
|
|
10
10
|
<div align="center">
|
|
11
|
-
<img src="https://img.shields.io/badge/v-0.0.
|
|
11
|
+
<img src="https://img.shields.io/badge/v-0.0.5-black"/>
|
|
12
12
|
<a href="https://github.com/maysara-elshewehy">
|
|
13
13
|
</a>
|
|
14
|
-
<a href="https://github.com/solution-lib"
|
|
15
|
-
</div>
|
|
16
|
-
|
|
17
|
-
<div align="center">
|
|
18
|
-
<img src="./assets/img/line.png" alt="line" style="display: block; margin-top:20px;margin-bottom:20px;width:500px;"/>
|
|
19
|
-
<br>
|
|
14
|
+
<a href="https://github.com/solution-lib"> <img src="https://img.shields.io/badge/@-solution--lib-black"/> </a>
|
|
20
15
|
</div>
|
|
16
|
+
<br>
|
|
21
17
|
|
|
22
18
|
<!-- ╚═════════════════════════════════════════════════════════════════╝ -->
|
|
23
19
|
|
|
@@ -82,57 +78,15 @@
|
|
|
82
78
|
|
|
83
79
|
<div align="center"> <img src="./assets/img/line.png" alt="line" style="display: block; margin-top:20px;margin-bottom:20px;width:500px;"/> <br> </div>
|
|
84
80
|
|
|
85
|
-
- ## Space Types
|
|
86
|
-
|
|
87
|
-
**Library (lib)**
|
|
88
|
-
```
|
|
89
|
-
my-lib/
|
|
90
|
-
┣ src/
|
|
91
|
-
┃ ┣ ...
|
|
92
|
-
┃ ┗ main.ts
|
|
93
|
-
┣ test/
|
|
94
|
-
┣ dist/
|
|
95
|
-
┣ .space
|
|
96
|
-
┗ package.json
|
|
97
|
-
```
|
|
98
|
-
|
|
99
|
-
**CLI Tool (cli)**
|
|
100
|
-
```
|
|
101
|
-
my-cli/
|
|
102
|
-
┣ src/
|
|
103
|
-
┃ ┣ ...
|
|
104
|
-
┃ ┗ main.ts
|
|
105
|
-
┣ test/
|
|
106
|
-
┣ dist/
|
|
107
|
-
┣ .space
|
|
108
|
-
┗ package.json
|
|
109
|
-
```
|
|
81
|
+
- ## Space Types and Examples
|
|
110
82
|
|
|
111
|
-
|
|
83
|
+
> _**[cli](https://github.com/solution-dist/cli)**_
|
|
112
84
|
|
|
113
|
-
-
|
|
85
|
+
> _**[lib](https://github.com/solution-dist/lib)**_
|
|
114
86
|
|
|
115
|
-
**
|
|
116
|
-
```bash
|
|
117
|
-
space init math-utils --type lib --pm bun
|
|
118
|
-
cd math-utils
|
|
119
|
-
space install
|
|
120
|
-
space start # Build and Start
|
|
121
|
-
space test # Run tests
|
|
122
|
-
space build # Build for production
|
|
123
|
-
space link # Test locally
|
|
124
|
-
space publish # Publish to npm
|
|
125
|
-
```
|
|
87
|
+
> _**[server](https://github.com/solution-dist/server)**_
|
|
126
88
|
|
|
127
|
-
**
|
|
128
|
-
```bash
|
|
129
|
-
space init my-tool --type cli
|
|
130
|
-
cd my-tool
|
|
131
|
-
space i chalk inquirer # Add dependencies
|
|
132
|
-
space start # Test your CLI
|
|
133
|
-
space link # Make it global
|
|
134
|
-
my-tool --help # Use it!
|
|
135
|
-
```
|
|
89
|
+
> _**[web app](https://github.com/solution-dist/web)**_
|
|
136
90
|
|
|
137
91
|
<div align="center"> <img src="./assets/img/line.png" alt="line" style="display: block; margin-top:20px;margin-bottom:20px;width:500px;"/> <br> </div>
|
|
138
92
|
|
|
@@ -145,6 +99,7 @@
|
|
|
145
99
|
"type" : "cli",
|
|
146
100
|
"template" : "clean",
|
|
147
101
|
"pm" : "bun",
|
|
102
|
+
|
|
148
103
|
"repo" : {
|
|
149
104
|
"org" : "solution-lib",
|
|
150
105
|
"name" : "space",
|
|
@@ -156,12 +111,14 @@
|
|
|
156
111
|
"homepage" : "https://github.com/solution-lib/space#readme",
|
|
157
112
|
"git_url" : "git+https://github.com/solution-lib/space.git"
|
|
158
113
|
},
|
|
114
|
+
|
|
159
115
|
"author" : {
|
|
160
116
|
"id" : "maysara-elshewehy",
|
|
161
117
|
"name" : "Maysara",
|
|
162
118
|
"email" : "maysara.elshewehy@gmail.com",
|
|
163
119
|
"url" : "https://github.com/maysara-elshewehy"
|
|
164
120
|
},
|
|
121
|
+
|
|
165
122
|
"createdAt" : "2025-11-29T01:22:48.497Z"
|
|
166
123
|
}
|
|
167
124
|
```
|
package/dist/main.cjs
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
|
-
'use strict';var cli=require('@je-es/cli'),u=require('fs'),T=require('path'),prompts=require('@inquirer/prompts'),child_process=require('child_process');function _interopNamespace(e){if(e&&e.__esModule)return e;var n=Object.create(null);if(e){Object.keys(e).forEach(function(k){if(k!=='default'){var d=Object.getOwnPropertyDescriptor(e,k);Object.defineProperty(n,k,d.get?d:{enumerable:true,get:function(){return e[k]}});}})}n.default=e;return Object.freeze(n)}var u__namespace=/*#__PURE__*/_interopNamespace(u);var T__namespace=/*#__PURE__*/_interopNamespace(T);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:()=>
|
|
2
|
+
'use strict';var cli=require('@je-es/cli'),u=require('fs'),T=require('path'),prompts=require('@inquirer/prompts'),child_process=require('child_process');function _interopNamespace(e){if(e&&e.__esModule)return e;var n=Object.create(null);if(e){Object.keys(e).forEach(function(k){if(k!=='default'){var d=Object.getOwnPropertyDescriptor(e,k);Object.defineProperty(n,k,d.get?d:{enumerable:true,get:function(){return e[k]}});}})}n.default=e;return Object.freeze(n)}var u__namespace=/*#__PURE__*/_interopNamespace(u);var T__namespace=/*#__PURE__*/_interopNamespace(T);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(
|
|
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
|
|
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
|
|
9
|
+
`+r.repeat(e)+"}"}};var I=class{constructor(t=process.cwd()){this.basePath=t;}async createSpace(t,e){let r=e||T__namespace.join(this.basePath,t.repo.name);if(u__namespace.existsSync(r))throw new Error(`Space path "${r}" already exists!`);let s=false;try{u__namespace.existsSync(r)||(u__namespace.mkdirSync(r,{recursive:!0}),s=!0),await this.cloneTemplate(t.type,r,t,t.template),this.createSpaceConfig(r,t);}catch(a){if(s&&u__namespace.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__namespace.join(e,".space");if(!u__namespace.existsSync(r))return null;let s=u__namespace.readFileSync(r,"utf-8");return JSON.parse(s)}isSpace(t){let e=t||this.basePath;return u__namespace.existsSync(T__namespace.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__namespace.join(e,".git");u__namespace.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__namespace.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__namespace.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__namespace.writeFileSync(b,g+`
|
|
11
11
|
`,"utf-8");continue}}catch{continue}}getAllFiles(t,e=[]){return u__namespace.readdirSync(t).forEach(s=>{let a=T__namespace.join(t,s);u__namespace.statSync(a).isDirectory()?e=this.getAllFiles(a,e):e.push(a);}),e}createSpaceConfig(t,e){let r=T__namespace.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__namespace.writeFileSync(r,k+`
|
|
12
|
-
`,"utf-8");}async safeDeleteDirectory(t,e=3){for(let r=0;r<e;r++)try{if(u__namespace.rmSync(t,{recursive:!0,force:!0,maxRetries:3,retryDelay:100}),!u__namespace.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__namespace.join(process.cwd(),"package.json");u__namespace.existsSync(t)&&P.formatFile(t,{keyOrder:
|
|
12
|
+
`,"utf-8");}async safeDeleteDirectory(t,e=3){for(let r=0;r<e;r++)try{if(u__namespace.rmSync(t,{recursive:!0,force:!0,maxRetries:3,retryDelay:100}),!u__namespace.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__namespace.join(process.cwd(),"package.json");u__namespace.existsSync(t)&&P.formatFile(t,{keyOrder:j});}catch{}}getScriptCommand(t){let e=T__namespace.join(process.cwd(),"package.json");if(u__namespace.existsSync(e))try{let r=JSON.parse(u__namespace.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__namespace.join(process.cwd(),"package.json");if(u__namespace.existsSync(e))try{let r=JSON.parse(u__namespace.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 prompts.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 prompts.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 prompts.select({message:"template:",choices:g,default:w.getDefaultTemplate(r)});}a||(a=await prompts.input({message:"desc:",default:r==="lib"?"A TypeScript library":r==="cli"?"A command-line tool":"A backend server"}));let n="bun";i=await prompts.input({message:"author name:",default:""});let p=await prompts.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 prompts.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 prompts.input({message:"keywords (comma-separated):",default:""}),f=m?m.split(",").map(l=>l.trim()).filter(l=>l):[],k=await prompts.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 prompts.confirm({message:`Are you sure you want to publish "${t}" to npm?`,default:false}))return {confirm:false};let r=await prompts.input({message:"Publish with a tag (e.g., beta, next) or leave empty for latest:",default:""}),s=await prompts.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 prompts.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 prompts.input({message:"Enter package names (space-separated):",default:t||"",validate:s=>!s||s.trim()===""?"Please enter at least one package name":true}),r=await prompts.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 prompts.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 prompts.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 prompts.confirm({message:`Use current directory "${t}" as the space root?`,default:true})}static async promptDeleteExistingDir(t){return await prompts.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
|
|
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.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__namespace.rmSync(t,{recursive:!0,force:!0,maxRetries:3,retryDelay:100}),!u__namespace.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__namespace.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__namespace.join(process.cwd(),s)),u__namespace.existsSync(i)){u__namespace.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
|