@@ -5,11 +5,16 @@ import { login, logout } from '../src/commands/auth.js';
55import { init } from '../src/commands/init.js' ;
66import { startShell } from '../src/commands/shell.js' ;
77import { PROJECT_NAME , getLatestVersion } from '../src/commons.js' ;
8- import { createApp } from '../src/commands/apps.js' ;
9- import { deploy } from '../src/commands/deploy.js' ;
8+ import { appInfo , createApp , listApps , deleteApp , updateApp } from '../src/commands/apps.js' ;
109import inquirer from 'inquirer' ;
10+ import { initProfileModule } from '../src/modules/ProfileModule.js' ;
11+ import { initPuterModule } from '../src/modules/PuterModule.js' ;
12+ import { createSite , infoSite , listSites , deleteSite } from '../src/commands/sites.js' ;
1113
1214async function main ( ) {
15+ initProfileModule ( ) ;
16+ initPuterModule ( ) ;
17+
1318 const version = await getLatestVersion ( PROJECT_NAME ) ;
1419
1520 const program = new Command ( ) ;
@@ -22,14 +27,18 @@ async function main() {
2227 . command ( 'login' )
2328 . description ( 'Login to Puter account' )
2429 . option ( '-s, --save' , 'Save authentication token in .env file' , '' )
25- . action ( ( ) => {
26- startShell ( 'login' ) ;
30+ . action ( async ( ) => {
31+ await login ( ) ;
32+ process . exit ( 0 ) ;
2733 } ) ;
2834
2935 program
3036 . command ( 'logout' )
3137 . description ( 'Logout from Puter account' )
32- . action ( logout ) ;
38+ . action ( async ( ) => {
39+ await logout ( ) ;
40+ process . exit ( 0 ) ;
41+ } ) ;
3342
3443 program
3544 . command ( 'init' )
@@ -44,29 +53,121 @@ async function main() {
4453
4554 // App commands
4655 program
47- . command ( 'app:create' )
48- . description ( 'Create a new Puter application' )
56+ . command ( 'apps' )
57+ . description ( 'List all your apps' )
58+ . argument ( '[period]' , 'period: today, yesterday, 7d, 30d, this_month, last_month' )
59+ . action ( async ( period ) => {
60+ await listApps ( {
61+ statsPeriod : period || 'all'
62+ } ) ;
63+ process . exit ( 0 ) ;
64+ } ) ;
65+
66+ const app = program
67+ . command ( 'app' )
68+ . description ( 'App management commands' ) ;
69+
70+ app
71+ . command ( 'info' )
72+ . description ( 'Get application information' )
73+ . argument ( '<app_name>' , 'Name of the application' )
74+ . action ( async ( app_name ) => {
75+ await appInfo ( [ app_name ] ) ;
76+ process . exit ( 0 ) ;
77+ } ) ;
78+
79+ app
80+ . command ( 'create' )
81+ . description ( 'Create a new app' )
4982 . argument ( '<name>' , 'Name of the application' )
50- . argument ( '[remoteDir]' , 'Remote directory path' )
51- . option ( '-d, --description [description]' , 'Application description' , '' )
52- . option ( '-u, --url <url>' , 'Application URL' , 'https://dev-center.puter.com/coming-soon.html' )
53- . action ( async ( name , remoteDir , options ) => {
83+ . argument ( '<remote_dir>' , 'Remote directory URL' )
84+ . action ( async ( name , remote_dir ) => {
5485 try {
5586 await createApp ( {
56- name,
57- directory : remoteDir || '' ,
58- description : options . description || '' ,
59- url : options . url
87+ name : name ,
88+ directory : remote_dir || '' ,
89+ description : '' ,
90+ url : 'https://dev-center.puter.com/coming-soon.html'
6091 } ) ;
6192 } catch ( error ) {
6293 console . error ( chalk . red ( error . message ) ) ;
6394 }
6495 process . exit ( 0 ) ;
6596 } ) ;
6697
98+ app
99+ . command ( 'update' )
100+ . description ( 'Update an app' )
101+ . argument ( '<name>' , 'Name of the application' )
102+ . argument ( '[dir]' , 'Directory path' , '.' )
103+ . action ( async ( name , dir ) => {
104+ await updateApp ( [ name , dir ] ) ;
105+ process . exit ( 0 ) ;
106+ } ) ;
107+
108+ app
109+ . command ( 'delete' )
110+ . description ( 'Delete an app' )
111+ . argument ( '<name>' , 'Name of the application' )
112+ . option ( '-f, --force' , 'Force deletion without confirmation' )
113+ . action ( async ( name , options ) => {
114+ let shouldDelete = options . force ;
115+
116+ if ( ! shouldDelete ) {
117+ const answer = await inquirer . prompt ( [
118+ {
119+ type : 'confirm' ,
120+ name : 'confirm' ,
121+ message : `Are you sure you want to delete the app "${ name } "?` ,
122+ default : false
123+ }
124+ ] ) ;
125+ shouldDelete = answer . confirm ;
126+ }
127+
128+ if ( shouldDelete ) {
129+ await deleteApp ( name ) ;
130+ } else {
131+ console . log ( chalk . yellow ( 'App deletion cancelled.' ) ) ;
132+ }
133+ process . exit ( 0 ) ;
134+ } ) ;
135+
136+ program
137+ . command ( 'sites' )
138+ . description ( 'List sites and subdomains' )
139+ . action ( async ( ) => {
140+ await listSites ( ) ;
141+ process . exit ( 0 ) ;
142+ } ) ;
143+
67144 const site = program
68- . command ( 'site' )
69- . description ( 'Site management commands' ) ;
145+ . command ( 'site' )
146+ . description ( 'Site management commands' ) ;
147+
148+ site
149+ . command ( 'info' )
150+ . description ( 'Get site information by UID' )
151+ . argument ( '<site_uid>' , 'Site UID' )
152+ . action ( async ( site_uid ) => {
153+ await infoSite ( [ site_uid ] ) ;
154+ process . exit ( 0 ) ;
155+ } ) ;
156+
157+ site
158+ . command ( 'create' )
159+ . description ( 'Create a static website from directory' )
160+ . argument ( '<app_name>' , 'Application name' )
161+ . argument ( '[dir]' , 'Directory path' )
162+ . option ( '--subdomain <name>' , 'Subdomain name' )
163+ . action ( async ( app_name , dir , options ) => {
164+ const args = [ app_name ] ;
165+ if ( dir ) args . push ( dir ) ;
166+ if ( options . subdomain ) args . push ( `--subdomain=${ options . subdomain } ` )
167+
168+ await createSite ( args )
169+ process . exit ( 0 ) ;
170+ } ) ;
70171
71172 site
72173 . command ( 'deploy' )
@@ -97,7 +198,35 @@ async function main() {
97198 subdomain = answer . subdomain ;
98199 }
99200
100- await startShell ( `site:deploy ${ local_dir } ${ subdomain ? ` --subdomain=${ subdomain } ` : '' } ` )
201+ await startShell ( `site:deploy ${ local_dir } ${ subdomain ? ` --subdomain=${ subdomain } ` : '' } ` )
202+ process . exit ( 0 ) ;
203+ } ) ;
204+
205+ site
206+ . command ( 'delete' )
207+ . description ( 'Delete a site by UID' )
208+ . argument ( '<uid>' , 'Site UID' )
209+ . option ( '-f, --force' , 'Force deletion without confirmation' )
210+ . action ( async ( uid , options ) => {
211+ let shouldDelete = options . force ;
212+
213+ if ( ! shouldDelete ) {
214+ const answer = await inquirer . prompt ( [
215+ {
216+ type : 'confirm' ,
217+ name : 'confirm' ,
218+ message : `Are you sure you want to delete the site with UID "${ uid } "?` ,
219+ default : false
220+ }
221+ ] ) ;
222+ shouldDelete = answer . confirm ;
223+ }
224+
225+ if ( shouldDelete ) {
226+ await deleteSite ( [ uid ] ) ;
227+ } else {
228+ console . log ( chalk . yellow ( 'Site deletion cancelled.' ) ) ;
229+ }
101230 process . exit ( 0 ) ;
102231 } ) ;
103232
0 commit comments