@glash/cli 0.1.1 → 0.1.2
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/bin/glash.mjs +1 -1
- package/commands/deploy.mjs +39 -6
- package/commands/projects.mjs +12 -3
- package/package.json +1 -1
package/bin/glash.mjs
CHANGED
package/commands/deploy.mjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { apiGet, apiPost } from '../lib/api.mjs';
|
|
2
|
-
import { readProjectLink } from '../lib/config.mjs';
|
|
3
|
-
import { ok, fail, info, warn, color } from '../lib/ui.mjs';
|
|
2
|
+
import { readProjectLink, writeProjectLink } from '../lib/config.mjs';
|
|
3
|
+
import { ok, fail, info, warn, color, prompt } from '../lib/ui.mjs';
|
|
4
4
|
import { execSync } from 'node:child_process';
|
|
5
5
|
import { zipDirectory } from '../lib/zip.mjs';
|
|
6
|
-
import { join } from 'node:path';
|
|
6
|
+
import { join, basename } from 'node:path';
|
|
7
7
|
import { tmpdir } from 'node:os';
|
|
8
8
|
import { readFile, rm } from 'node:fs/promises';
|
|
9
9
|
|
|
@@ -28,10 +28,43 @@ async function resolveProjectId(flags) {
|
|
|
28
28
|
return found.id;
|
|
29
29
|
}
|
|
30
30
|
const link = await readProjectLink();
|
|
31
|
-
if (
|
|
32
|
-
|
|
31
|
+
if (link?.projectId) {
|
|
32
|
+
return link.projectId;
|
|
33
33
|
}
|
|
34
|
-
|
|
34
|
+
|
|
35
|
+
// INTERACTIVE PROJECT SETUP (Vercel-style)
|
|
36
|
+
const dirName = basename(process.cwd());
|
|
37
|
+
const setup = await prompt(`Set up and deploy "${dirName}"? [Y/n] `);
|
|
38
|
+
if (setup.toLowerCase() === 'n') {
|
|
39
|
+
throw new Error('Deployment aborted.');
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const existing = await prompt(`Link to existing project? [y/N] `);
|
|
43
|
+
if (existing.toLowerCase() === 'y') {
|
|
44
|
+
const list = await apiGet('/projects');
|
|
45
|
+
if (list.length === 0) {
|
|
46
|
+
info('No existing projects found. Proceeding to create a new one.');
|
|
47
|
+
} else {
|
|
48
|
+
info('\nYour existing projects:');
|
|
49
|
+
list.forEach((p, i) => info(` ${color.dim(i + 1 + '.')} ${color.bold(p.name)} ${color.dim('(' + p.slug + ')')}`));
|
|
50
|
+
const choice = await prompt('\nWhich project do you want to link to? (enter number or slug): ');
|
|
51
|
+
const p = list.find((x, i) => x.slug === choice || String(i + 1) === choice);
|
|
52
|
+
if (!p) throw new Error(`Project "${choice}" not found.`);
|
|
53
|
+
await writeProjectLink({ projectId: p.id, slug: p.slug });
|
|
54
|
+
ok(`Linked to ${p.name} (${p.slug})`);
|
|
55
|
+
return p.id;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// CREATE NEW PROJECT
|
|
60
|
+
const name = (await prompt(`What's your project's name? [${dirName}] `)) || dirName;
|
|
61
|
+
const slug = name.toLowerCase().replace(/[^a-z0-9-]+/g, '-').replace(/^-+|-+$/g, '');
|
|
62
|
+
|
|
63
|
+
info(color.dim(`Creating project "${name}"...`));
|
|
64
|
+
const p = await apiPost('/projects', { name, slug });
|
|
65
|
+
await writeProjectLink({ projectId: p.id, slug: p.slug });
|
|
66
|
+
ok(`Created and linked to ${p.name} (${p.slug})`);
|
|
67
|
+
return p.id;
|
|
35
68
|
}
|
|
36
69
|
|
|
37
70
|
export async function deploy({ flags }) {
|
package/commands/projects.mjs
CHANGED
|
@@ -33,12 +33,21 @@ export async function createProject({ flags, positional }) {
|
|
|
33
33
|
|
|
34
34
|
export async function linkProject({ flags, positional }) {
|
|
35
35
|
let slug = flags.slug || positional[0];
|
|
36
|
+
const all = await apiGet('/projects');
|
|
37
|
+
|
|
36
38
|
if (!slug) {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
+
if (all.length === 0) {
|
|
40
|
+
return fail('No existing projects found. Run `glash projects:new` to create one.');
|
|
41
|
+
}
|
|
42
|
+
info('\nYour existing projects:');
|
|
43
|
+
all.forEach((p, i) => info(` ${color.dim(i + 1 + '.')} ${color.bold(p.name)} ${color.dim('(' + p.slug + ')')}`));
|
|
44
|
+
const choice = await prompt('\nWhich project do you want to link to? (enter number or slug): ');
|
|
45
|
+
const p = all.find((x, i) => x.slug === choice || String(i + 1) === choice);
|
|
46
|
+
if (!p) return fail(`No project found matching "${choice}".`);
|
|
47
|
+
slug = p.slug;
|
|
39
48
|
}
|
|
49
|
+
|
|
40
50
|
try {
|
|
41
|
-
const all = await apiGet('/projects');
|
|
42
51
|
const p = all.find((x) => x.slug === slug || x.id === slug);
|
|
43
52
|
if (!p) return fail(`No project found matching "${slug}". Run \`glash projects\` to list.`);
|
|
44
53
|
await writeProjectLink({ projectId: p.id, slug: p.slug });
|