-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.ts
More file actions
71 lines (57 loc) · 1.96 KB
/
Copy pathcli.ts
File metadata and controls
71 lines (57 loc) · 1.96 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import * as clack from '@clack/prompts';
import { realpathSync } from 'node:fs';
import { basename, resolve } from 'node:path';
import { fileURLToPath, pathToFileURL } from 'node:url';
import { promptAppExtensions } from './prompts/appExtensions.js';
import { promptDatabase } from './prompts/database.js';
import { promptProjectName } from './prompts/projectName.js';
import { nodeGenerator } from './generators/node/index.js';
interface NextStepOptions {
nameOrPath: string;
}
export function nextStepLines(options: NextStepOptions): string[] {
const steps = [
`cd ${options.nameOrPath}`,
'cp .env.example .env',
'# fill in PIPEDRIVE_CLIENT_ID and PIPEDRIVE_CLIENT_SECRET',
'docker compose up',
];
return ['', 'Next steps:', ...steps.map((s) => ` ${s}`)];
}
function printNextSteps(options: NextStepOptions): void {
for (const line of nextStepLines(options)) {
console.log(line);
}
}
type ResolvePath = (path: string) => string;
export function isCliEntrypoint(
importMetaUrl: string,
argvPath: string | undefined,
resolvePath: ResolvePath = realpathSync,
): boolean {
if (!argvPath) return false;
try {
return resolvePath(fileURLToPath(importMetaUrl)) === resolvePath(argvPath);
} catch {
return importMetaUrl === pathToFileURL(argvPath).href;
}
}
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 outputDir = resolve(process.cwd(), nameOrPath);
const projectName = basename(outputDir);
try {
await nodeGenerator.generate(outputDir, { projectName, database, appExtensions });
} catch (error) {
clack.log.error(`Generation failed: ${error instanceof Error ? error.message : String(error)}`);
process.exit(1);
}
clack.outro(`✓ Created ${projectName}`);
printNextSteps({ nameOrPath });
}
if (isCliEntrypoint(import.meta.url, process.argv[1])) {
void main();
}