Skip to content

Commit 9443f9a

Browse files
authored
Merge pull request #51 from reynaldichernando/site-deploy-dir
Make site deployment easily accessible
2 parents a4e1242 + b1de7ce commit 9443f9a

File tree

1 file changed

+19
-10
lines changed

1 file changed

+19
-10
lines changed

src/commands/deploy.js

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
import chalk from 'chalk';
2-
import { generateAppName, isValidAppName } from '../commons.js';
2+
import { generateAppName } from '../commons.js';
33
import { syncDirectory } from './files.js';
44
import { createSite } from './sites.js';
5-
import { getCurrentDirectory } from './auth.js';
6-
import { getSubdomains } from './subdomains.js';
7-
import crypto from '../crypto.js';
5+
import { getPuter } from '../modules/PuterModule.js';
86

97
/**
108
* Deploy a local web project to Puter.
@@ -18,24 +16,35 @@ export async function deploy(args = []) {
1816
console.log(chalk.yellow('Example: site:deploy ./dist --subdomain=my-app-new'));
1917
return;
2018
}
21-
const appName = generateAppName();
19+
const puter = getPuter();
20+
2221
const sourceDirArg = args.find(arg => !arg.startsWith('--'));
2322
const sourceDir = sourceDirArg || '.';
24-
const subdomain = args.find(arg => arg.startsWith('--subdomain='))?.split('=')[1] || appName;
2523

26-
const remoteDir = `deployments/site-${crypto.randomUUID()}`;
24+
let subdomain = args.find(arg => arg.startsWith('--subdomain='))?.split('=')[1];
25+
if (!subdomain) {
26+
subdomain = generateAppName();
27+
}
28+
29+
const remoteDir = `~/sites/${subdomain}/deployment`;
30+
31+
// this will handle the increments
32+
const directory = await puter.fs.mkdir(remoteDir, {
33+
dedupeName: true,
34+
createMissingParents: true
35+
})
2736

2837
console.log(chalk.cyan(`Deploying '${sourceDir}' to '${subdomain}.puter.site'...`));
2938

3039
try {
3140
// 1. Upload files
32-
await syncDirectory([sourceDir, remoteDir, '--delete', '-r', '--overwrite']);
41+
await syncDirectory([sourceDir, directory.path, '--delete', '-r', '--overwrite']);
3342

3443
// 2. Create the site
35-
const site = await createSite([appName, remoteDir, `--subdomain=${subdomain}`]);
44+
const site = await createSite([subdomain, directory.path, `--subdomain=${subdomain}`]);
3645

3746
if (site) {
38-
console.log(chalk.green('Deployment successful!'));
47+
console.log(chalk.green('Deployment successful!'));
3948
} else {
4049
console.log(chalk.yellow('Deployment successfuly updated!'));
4150
}

0 commit comments

Comments
 (0)