-
-
Notifications
You must be signed in to change notification settings - Fork 794
/
index.ts
61 lines (51 loc) · 1.45 KB
/
index.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
import prompts from 'prompts'
import list, { ListOptions } from './list'
import { file, http, config, exec, Ware, Middleware } from './core'
import { Options, Context, Template } from './types'
import confirm from './confirm'
import resolve from './resolve'
import load from './load'
import inquire from './inquire'
import setup from './setup'
import prepare from './prepare'
import rename from './rename'
import render from './render'
import emit from './emit'
import install from './install'
import init from './init'
import complete from './complete'
// export inject for test
const { inject } = prompts
const creator = new Ware<Context>()
creator.use(confirm)
creator.use(resolve)
creator.use(load)
creator.use(inquire)
creator.use(setup)
creator.use(prepare)
creator.use(rename)
creator.use(render)
creator.use(emit)
creator.use(install)
creator.use(init)
creator.use(complete)
export default async (template: string, project: string = '.', options: Options = {}): Promise<void> => {
// required arguments
if (template == null || template === '') {
throw new Error('Missing required argument: `template`.')
}
// create context
const context = {
template,
project,
options,
src: '',
dest: '',
config: Object.create(null),
answers: Object.create(null),
files: []
}
// running creator
await creator.run(context)
}
export { inject, file, http, config, exec, Ware, list, Middleware, Options, Context, Template, ListOptions }