-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgulpfile.ts
129 lines (108 loc) · 3.2 KB
/
gulpfile.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
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
/// <reference path='typings/node/node.d.ts' />
var gulp = require('gulp');
var tsc = require('gulp-tsc');
var shell = require('gulp-shell');
var runseq = require('run-sequence');
var spawn = require('child_process').spawn
var less = require('gulp-less');
var paths = {
tscripts : {
src : [
'./app.ts',
'./lib/*.ts',
'public/javascripts/*.ts',
],
dest : './'
}
};
function getArg(key) : any {
var index = process.argv.indexOf(key);
var next = process.argv[index + 1];
return (index < 0) ? null : (!next || next[0] === "-") ? '' : next;
}
var server = null;
function runNode(restartOnError) {
console.log('Called runNode');
if (server) {
server.kill('SIGKILL');
server = null;
}
server = spawn('node', ['app.js']);;
server.stdout.setEncoding('utf8');
server.stderr.setEncoding('utf8');
server.stdout.on('data',function (data) {
console.log(data.trim());
});
server.stderr.on('error',function (data) {
console.error(data.trim());
});
server.on('close', function (code) {
console.log('Close server - ' + code);
console.log('restartOnError', restartOnError);
if (code && restartOnError) {
runNode(restartOnError);
}
});
}
gulp.task('default', ['buildrun']);
gulp.task('server-restart', function () {
runNode(true);
});
gulp.task('compile-restart', function (cb) {
runseq('compile:typescript', 'server-restart', cb );
});
gulp.task('server', function () {
runNode(true);
gulp.watch('public/javascripts/*.ts', ['compile:typescript']);
gulp.watch('public/stylesheets/*.less', ['build-less']);
gulp.watch(['*.ts', 'lib/*.ts', 'routes/*.ts'], ['compile-restart']);
});
gulp.task('createAdmin', function () {
var db = require('./lib/db');
var requiredLine = 'RUN: gulp createAdmin --email EMAIL --password PASSWORD'
var email : string = getArg('--email');
var password : string = getArg('--password');
if (!email || email.length === 0) {
console.error('NO EMAIL - ' + requiredLine)
return;
}
if (!password || password.length === 0) {
console.error('NO PASSWORD - ' + requiredLine)
return;
}
db.initDb(err => {
if (err) {
console.error('Err connecting check your local settings `cp config-default.json config-local.json; vim config-loca.json`')
console.error(err);
return;
}
db.createUserIfNotExists(email, password, 'admin', err => {
if (err) {
console.error('Err ', err)
}
console.log('Usuario creado o ya existente.');
db.destroy();
});
})
});
gulp.task('buildrun', (cb) => {
runseq('build', 'server', cb);
});
gulp.task('build-less', function(){
return gulp.src('public/stylesheets/*.less')
.pipe(less())
.pipe(gulp.dest('public/stylesheets/'));
});
gulp.task('build', ['compile:typescript', 'build-less']);
gulp.task('compile:typescript', () => {
return gulp
.src(paths.tscripts.src)
.pipe(tsc({
module: "CommonJS",
sourcemap: false,
emitError: false,
target: 'ES5',
tmpDir:'tmp'
}))
.pipe(gulp.dest(paths.tscripts.dest));
});