Skip to content

Commit 0280b5a

Browse files
authored
Merge pull request #30 from reynaldichernando/puter-site-deploy
Add non interactive puter site deploy
2 parents fbdda11 + 9f38f68 commit 0280b5a

File tree

4 files changed

+40
-26
lines changed

4 files changed

+40
-26
lines changed

bin/index.js

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { startShell } from '../src/commands/shell.js';
77
import { PROJECT_NAME, getLatestVersion } from '../src/commons.js';
88
import { createApp } from '../src/commands/apps.js';
99
import { deploy } from '../src/commands/deploy.js';
10+
import inquirer from 'inquirer';
1011

1112
async function main() {
1213
const version = await getLatestVersion(PROJECT_NAME);
@@ -63,21 +64,42 @@ async function main() {
6364
process.exit(0);
6465
});
6566

66-
/*/ Deploy command
67-
program
68-
.command('site:deploy')
67+
const site = program
68+
.command('site')
69+
.description('Site management commands');
70+
71+
site
72+
.command('deploy')
6973
.description('Deploy a local web project to Puter')
70-
.argument('[remoteDir]', 'Remote directory path')
71-
.option('--subdomain <subdomain>', 'Subdomain for the site')
72-
.action(async (name, remoteDir, options) => {
73-
try {
74-
await deploy([name, remoteDir, `--subdomain=${options.subdomain}`].filter(Boolean));
75-
} catch (error) {
76-
console.error(chalk.red(error.message));
77-
}
78-
process.exit(0);
74+
.argument('[local_dir]', 'Local directory path')
75+
.argument('[subdomain]', 'Deployment subdomain (<subdomain>.puter.site)')
76+
.action(async (local_dir, subdomain) => {
77+
if (!local_dir) {
78+
const answer = await inquirer.prompt([
79+
{
80+
type: 'input',
81+
name: 'local_dir',
82+
message: 'Local directory path:',
83+
default: '.'
84+
}
85+
]);
86+
local_dir = answer.local_dir;
87+
}
88+
89+
if (!subdomain) {
90+
const answer = await inquirer.prompt([
91+
{
92+
type: 'input',
93+
name: 'subdomain',
94+
message: 'Deployment subdomain (leave empty for random):',
95+
}
96+
]);
97+
subdomain = answer.subdomain;
98+
}
99+
100+
await startShell(`site:deploy ${local_dir}${subdomain ? ` --subdomain=${subdomain}`: ''}`)
101+
process.exit(0);
79102
});
80-
*/
81103

82104
if (process.argv.length === 2) {
83105
startShell();

src/commands/deploy.js

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,28 +25,20 @@ export async function deploy(args = []) {
2525

2626
const remoteDir = `deployments/site-${crypto.randomUUID()}`;
2727

28-
console.log(chalk.cyan(`Deploying '${appName}' from local '${sourceDir}' to remote '${remoteDir}' at '${subdomain}.puter.site'...`));
28+
console.log(chalk.cyan(`Deploying '${sourceDir}' to '${subdomain}.puter.site'...`));
2929

3030
try {
3131
// 1. Upload files
32-
console.log(chalk.cyan(`Uploading files from '${sourceDir}' to '${remoteDir}'...`));
3332
await syncDirectory([sourceDir, remoteDir, '--delete', '-r', '--overwrite']);
3433

3534
// 2. Create the site
36-
console.log(chalk.cyan(`Creating site...`));
3735
const site = await createSite([appName, remoteDir, `--subdomain=${subdomain}`]);
3836

3937
if (site) {
4038
console.log(chalk.green('Deployment successful!'));
4139
} else {
4240
console.log(chalk.yellow('Deployment successfuly updated!'));
4341
}
44-
if (subdomain){
45-
console.log(chalk.cyan('Your site is live at:'));
46-
console.log(chalk.green(`https://${subdomain}.puter.site`));
47-
} else {
48-
console.log(chalk.red('Deployment failed. Subdomain cannot be reserved!'));
49-
}
5042
} catch (error) {
5143
console.error(chalk.red(`Deployment failed: ${error.message}`));
5244
}

src/commands/sites.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,14 +176,14 @@ export async function infoSite(args = []) {
176176
console.log(chalk.cyan(`New generated subdomain: "${subdomain}" will be used if its not already in use.`));
177177

178178
// Step 3: Host the current directory under the subdomain
179-
console.log(chalk.cyan(`Hosting app "${appName}" under subdomain "${subdomain}"...`));
179+
console.log(chalk.cyan(`Hosting site "${appName}" under subdomain "${subdomain}"...`));
180180
const site = await createSubdomain(subdomain, remoteDir);
181181
if (!site){
182182
console.error(chalk.red(`Failed to create subdomain: "${chalk.red(subdomain)}"`));
183183
return;
184184
}
185185

186-
console.log(chalk.green(`App ${chalk.dim(appName)} created successfully and accessible at:`));
186+
console.log(chalk.green(`Site ${chalk.dim(appName)} created successfully and accessible at:`));
187187
console.log(chalk.cyan(`https://${site.subdomain}.puter.site`));
188188
return site;
189189
} catch (error) {

src/commons.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export function getHeaders(contentType = 'application/json') {
4545
* @see: [randName](https://github.com/HeyPuter/puter/blob/06a67a3b223a6cbd7ec2e16853b6d2304f621a88/src/puter-js/src/index.js#L389)
4646
*/
4747
export function generateAppName(separateWith = '-'){
48-
console.log(chalk.cyan('Generating random app name...'));
48+
console.log(chalk.cyan('Generating random name...'));
4949
try {
5050
const first_adj = ['helpful','sensible', 'loyal', 'honest', 'clever', 'capable','calm', 'smart', 'genius', 'bright', 'charming', 'creative', 'diligent', 'elegant', 'fancy',
5151
'colorful', 'avid', 'active', 'gentle', 'happy', 'intelligent', 'jolly', 'kind', 'lively', 'merry', 'nice', 'optimistic', 'polite',
@@ -63,7 +63,7 @@ export function generateAppName(separateWith = '-'){
6363
// return a random combination of first_adj + noun + number (between 0 and 9999)
6464
// e.g. clever-idea-123
6565
const appName = first_adj[Math.floor(Math.random() * first_adj.length)] + separateWith + nouns[Math.floor(Math.random() * nouns.length)] + separateWith + Math.floor(Math.random() * 10000);
66-
console.log(chalk.green(`AppName: "${appName}"`));
66+
console.log(chalk.green(`Name: "${appName}"`));
6767
return appName;
6868
} catch (error) {
6969
console.error(`Error: ${error.message}`);

0 commit comments

Comments
 (0)