|
1
|
import ora, { Ora } from "ora" |
|
2
|
import path from "path" |
|
3
|
import createAbortController from "../create-abort-controller.js" |
|
4
|
import { FactBoxOptions } from "../facts.js" |
|
5
|
import ProcessManager from "../process-manager.js" |
|
6
|
import PackageManager from "../package-manager.js" |
|
7
|
|
|
8
|
export interface ProjectOptions { |
|
9
|
repoUrl?: string |
|
10
|
seed?: boolean |
|
11
|
skipDb?: boolean |
|
12
|
dbUrl?: string |
|
13
|
browser?: boolean |
|
14
|
migrations?: boolean |
|
15
|
directoryPath?: string |
|
16
|
withNextjsStarter?: boolean |
|
17
|
verbose?: boolean |
|
18
|
plugin?: boolean |
|
19
|
version?: string |
|
20
|
useNpm?: boolean |
|
21
|
usePnpm?: boolean |
|
22
|
useYarn?: boolean |
|
23
|
} |
|
24
|
|
|
25
|
export interface ProjectCreator { |
|
26
|
create({ verbose }: { verbose?: boolean }): Promise<void> |
|
27
|
} |
|
28
|
|
|
29
|
// Base class for common project functionality |
|
30
|
export abstract class BaseProjectCreator { |
|
31
|
protected spinner: Ora |
|
32
|
protected processManager: ProcessManager |
|
33
|
protected packageManager: PackageManager |
|
34
|
protected abortController: AbortController |
|
35
|
protected factBoxOptions: FactBoxOptions |
|
36
|
protected projectName: string |
|
37
|
protected projectPath: string |
|
38
|
protected isProjectCreated: boolean = false |
|
39
|
protected printedMessage: boolean = false |
|
40
|
|
|
41
|
constructor( |
|
42
|
projectName: string, |
|
43
|
protected options: ProjectOptions, |
|
44
|
protected args: string[] |
|
45
|
) { |
|
46
|
this.spinner = ora() |
|
47
|
this.processManager = new ProcessManager() |
|
48
|
this.packageManager = new PackageManager(this.processManager, { |
|
49
|
verbose: options.verbose, |
|
50
|
useNpm: options.useNpm, |
|
51
|
usePnpm: options.usePnpm, |
|
52
|
useYarn: options.useYarn, |
|
53
|
}) |
|
54
|
this.abortController = createAbortController(this.processManager) |
|
55
|
this.projectName = projectName |
|
56
|
const basePath = |
|
57
|
typeof options.directoryPath === "string" ? options.directoryPath : "" |
|
58
|
this.projectPath = path.join(basePath, projectName) |
|
59
|
|
|
60
|
this.factBoxOptions = { |
|
61
|
interval: null, |
|
62
|
spinner: this.spinner, |
|
63
|
processManager: this.processManager, |
|
64
|
message: "", |
|
65
|
title: "", |
|
66
|
verbose: options.verbose || false, |
|
67
|
} |
|
68
|
} |
|
69
|
|
|
70
|
protected getProjectPath(projectName: string): string { |
|
71
|
return path.join(this.options.directoryPath ?? "", projectName) |
|
72
|
} |
|
73
|
|
|
74
|
protected abstract showSuccessMessage(): void |
|
75
|
|
|
76
|
protected abstract setupProcessManager(): void |
|
77
|
} |