forked from what-crud/vue-crud
-
Notifications
You must be signed in to change notification settings - Fork 0
/
template-loader.js
109 lines (100 loc) · 2.06 KB
/
template-loader.js
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
const fs = require('fs-extra')
const templates = [
'empty',
'simple-crud',
'sandbox',
'crm',
'cms',
]
const resources = [
{
type: 'dir',
sl: 'public',
tl: 'public',
},
{
type: 'dir',
sl: 'locales',
tl: 'src/locales',
},
{
type: 'dir',
sl: 'routes',
tl: 'src/routes',
},
{
type: 'dir',
sl: 'config',
tl: 'src/config',
},
{
type: 'file',
sl: 'main.js',
tl: 'src/main.js',
},
{
type: 'file',
sl: 'router.js',
tl: 'src/router.js',
},
{
type: 'file',
sl: 'registerServiceWorker.js',
tl: 'src/registerServiceWorker.js',
},
]
var args = process.argv.slice(2)
const usage = function () {
const usageText = `
\x1b[46m\x1b[30m HELP \x1b[0m\x1b[36m
Use the wizard to load the appropriate template.
Usage:
load-template <template>
available templates:
empty - empty template for creating applications from scratch
simple-crud - simple CRUD example (with table configuration)
sandbox - Vue CRUD demo (with configuration)
crm - extended example of crm app (with auth, app layout and various CRUD exmples)
cms - extended example of cms app (with auth, app layout and various CRUD exmples)
`
console.log(usageText)
}
function errorLog (error) {
console.log(
`
\x1b[41m\x1b[30m Error \x1b[0m\x1b[31m ${error}
`
)
}
function successLog () {
console.log(
`
\x1b[42m\x1b[30m DONE \x1b[0m\x1b[32m Template has been successfuly loaded.
`
)
}
if (args.length !== 1) {
errorLog(`Only one argument can be passed`)
usage()
} else {
var arg = args[0]
if (arg === '-help' || arg === '-h') {
usage()
} else if (templates.includes(arg)) {
resources.forEach(function (resource) {
var sl = `examples/${arg}/${resource.sl}`
var tl = resource.tl
if (fs.existsSync(tl)) {
fs.removeSync(tl)
}
if (fs.existsSync(sl)) {
fs.copySync(sl, tl)
}
})
successLog()
} else {
errorLog(`Specified template doesn't exist.`)
usage()
}
}
console.log('\x1b[0m')