-
Notifications
You must be signed in to change notification settings - Fork 4
/
scaffold.ts
50 lines (37 loc) · 1.44 KB
/
scaffold.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
import { flags } from '@oclif/command'
import chalk from 'chalk'
import Listr from 'listr'
import { Kommand } from '../../common'
import { execute } from '../../support/execute'
export default class AppScaffold extends Kommand {
static initSdk = false
static description = 'Scaffolds a new Kuzzle application'
static flags = {
help: flags.help(),
flavor: flags.string({
default: 'generic',
description: 'Template flavor ("generic", "iot-platform")'
})
}
static args = [
{ name: 'destination', description: 'Directory to scaffold the app', required: true },
]
async runSafe() {
const destination = this.args.destination
const flavor = this.flags.flavor
const tasks = new Listr([
{
title: 'Creating and rendering application files',
task: async () => this.cloneTemplate(flavor, destination)
},
]);
await tasks.run();
this.log('')
this.logOk(`Scaffolding complete! Use ${chalk.grey(`cd ${destination} && npm run docker npm install`)} install dependencies and then ${chalk.grey(`npm run docker:dev`)} to run your application!`);
}
async cloneTemplate(flavor: string, destination: string) {
await execute('git', 'clone', '--depth=1', 'https://github.com/kuzzleio/project-templates', '--branch', flavor, '--single-branch');
await execute('mv', `project-templates/${flavor}`, `${destination}/`);
await execute('rm', '-rf', 'project-templates/');
}
}