-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.js
More file actions
167 lines (151 loc) · 3.15 KB
/
gulpfile.js
File metadata and controls
167 lines (151 loc) · 3.15 KB
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
const fs = require('fs')
const path = require('path')
const gulp = require('gulp')
const ts = require('gulp-typescript')
const watch = require('gulp-watch')
const mocha = require('gulp-mocha')
const cp = require('child_process')
const ncp = require('ncp').ncp
const archiver = require('archiver')
const rimraf = require('rimraf')
const plugin = require('./plugins/plugin')
const tsProd = ts.createProject('tsconfig.json')
const ROOT_DIR = path.join(__dirname)
const PLUGINS_DIR = path.join(ROOT_DIR, 'plugins')
const TS_DIR = path.join(__dirname, 'src')
const JS_DIR = path.join(__dirname, 'dist')
const TEST_FILES = [
JS_DIR + '/test/**/*.test.js',
'plugins/test.js'
]
function deleteRecursive(src){
return new Promise(function(resolve, reject){
console.log('Deleting dir: %s', src)
rimraf(src, e => {
if(e) return reject(e)
else return resolve()
})
})
}
function tsc(){
return gulp.src(TS_DIR + '/**/*.ts')
.pipe(tsProd())
.pipe(gulp.dest(JS_DIR))
}
function run(cb){
cp.exec('npm start', function(err, stdout, stderr){
if(err){
console.error(err)
process.exit(1)
cb(err)
}
console.log(stdout)
console.error(stderr)
cb()
})
}
function test(){
return gulp.src(TEST_FILES)
.pipe(mocha())
}
async function backup(cb){
try{
await deleteRecursive(path.join(ROOT_DIR, 'backups'))
await plugin.backup()
cb()
} catch(e){
cb(e)
}
}
async function forceBackup(cb){
try{
await deleteRecursive(path.join(ROOT_DIR, 'backups'))
await plugin.backup()
cb()
} catch(e){
cb(e)
}
}
async function restore(cb){
try{
await plugin.restore()
cb()
} catch(e){
cb(e)
}
}
async function restoreConfig(cb){
try{
await plugin.restoreConfig()
cb()
} catch(e){
cb(e)
}
}
async function refresh(cb){
try{
await plugin.init()
await plugin.uninstall()
cb()
} catch(e){
cb(e)
}
}
async function pluginInit(cb){
try{
await plugin.init()
cb()
} catch(e){
cb(e)
}
}
function createEmptyPlugin(cb){
try{
const p = path.join('newPlugin')
plugin.createEmptyPlugin(p)
cb()
} catch(e){
cb(e)
}
}
function testPluginSetup(cb){
let pluginDir = path.join(__dirname, 'plugins', 'helloworld-example')
let targetDir = path.join(__dirname, 'plugins', 'helloworld')
ncp(pluginDir, targetDir, e => {
if(e)
return cb(e)
try{
let zipPath = path.join(__dirname, 'plugins', 'helloworld.zip')
let zipWriteStream = fs.createWriteStream(zipPath)
.on('close', () => {
console.log('successfully zipped %s to %s',
targetDir,
zipPath
)
rimraf(targetDir, e => cb(e))
})
.on('error', e => {
console.error(e)
rimraf(targetDir, e => cb(e))
})
let zip = archiver('zip')
zip.pipe(zipWriteStream)
zip.directory(targetDir, false)
zip.finalize()
} catch(e){
return cb(e)
}
})
}
exports.tsc = tsc
exports.mocha = exports.test
exports.refresh = refresh
exports.backup = backup
exports.forceBackup = forceBackup
exports.restore = restore
exports.restoreConfig = restoreConfig
exports.pluginInit = pluginInit
exports.testPluginSetup = testPluginSetup
exports.createEmptyPlugin = createEmptyPlugin
exports.test = gulp.series(tsc, test)
exports.run = gulp.series(tsc, run)