-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.ts
More file actions
52 lines (43 loc) · 1.9 KB
/
cli.ts
File metadata and controls
52 lines (43 loc) · 1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import * as clack from '@clack/prompts';
import { spawn } from 'node:child_process';
import { basename, resolve } from 'node:path';
import { promptAppExtensions } from './prompts/appExtensions.js';
import { promptDatabase } from './prompts/database.js';
import { promptProjectName } from './prompts/projectName.js';
import { promptWebhooks } from './prompts/webhooks.js';
import { nodeGenerator } from './generators/node/index.js';
async function main(): Promise<void> {
clack.intro('create-pipedrive-app');
const nameOrPath = await promptProjectName(process.argv[2]);
const database = await promptDatabase();
const appExtensions = await promptAppExtensions();
const webhooks = await promptWebhooks();
const outputDir = resolve(process.cwd(), nameOrPath);
const projectName = basename(outputDir);
try {
await nodeGenerator.generate(outputDir, { projectName, database, appExtensions, webhooks });
} catch (error) {
clack.log.error(`Generation failed: ${error instanceof Error ? error.message : String(error)}`);
process.exit(1);
}
clack.outro(`✓ Created ${projectName}`);
const installDeps = await clack.confirm({ message: 'Install dependencies now?' });
if (clack.isCancel(installDeps)) process.exit(0);
if (installDeps) {
const spinner = clack.spinner();
spinner.start('Installing dependencies');
const ok = await new Promise<boolean>((resolve) => {
const child = spawn('npm', ['install'], { cwd: outputDir, stdio: 'ignore' });
child.on('close', (code) => resolve(code === 0));
});
spinner.stop(ok ? 'Dependencies installed' : 'npm install failed — run it manually');
}
const needsDocker = database === 'postgres' || database === 'mysql';
console.log('\nNext steps:');
console.log(` cd ${nameOrPath}`);
console.log(' cp .env.example .env');
if (needsDocker) console.log(' docker-compose up -d');
if (!installDeps) console.log(' npm install');
console.log(' npm run dev');
}
main();