-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.ts
64 lines (56 loc) · 1.71 KB
/
init.ts
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
import { AbstractCommand } from './abstract-command'
import * as inquirer from 'inquirer'
import { shell } from '../utils/shell'
import logger from '../utils/logger'
const questions: inquirer.QuestionCollection<any> = [
{
type: 'rawlist',
name: 'seedName',
message: 'Select seed type',
choices: [
{
name: 'graphql-server-typed: Typescript server deployed on now',
value: 'graphql-server-typed'
},
{
name: 'apollo-typed-lambda: Typescript server for aws lambda deployment',
value: 'apollo-typed-lambda'
}
]
}
]
export class Init extends AbstractCommand {
public getName(): string {
return 'init <name>'
}
public getDescription(): string {
return 'Create new project'
}
public getAlias(): string {
return 'i'
}
public getAction(): (...args: any[]) => void {
return async (projectName: string) => {
try {
const answer: any = await inquirer.prompt(questions)
await shell(this.getCloneCommand(answer.seedName, projectName))
logger.info('Project cloned, installing dependencies...')
process.chdir(projectName)
await shell(this.getInstallCommand())
logger.info('Dependencies installed successfully')
} catch (err) {
logger.error(`Got error in init command- ${err}`)
}
}
}
private getCloneCommand(seedName: string, projectName: string): string {
const seedUrlToClone = this.getSeedUrlToClone(seedName)
return `git clone ${seedUrlToClone} ${projectName}`
}
private getSeedUrlToClone(seedName: string): string {
return `https://github.com/tomyitav/${seedName}.git`
}
private getInstallCommand(): string {
return `npm install`
}
}