-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.es6.js
150 lines (120 loc) · 4 KB
/
gulpfile.es6.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
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
'use strict';
// What files to monitor - when to rebuild and reload emulator?
var watchedFiles = [
'app/src/*.{js,xml,css}',
'app/src/**/*.{js,xml,css}'
];
// Where are your ES6 files which are going to be translated?
// These are also the files which will be linted by eslint
var babelSrc = [
'app/src/**/*.js'
];
// Where are your resource files which are just being
// moved without any translation.
var resources = [
'app/src/*.{xml,css}',
'app/src/**/*.{xml,css}'
];
// These folders are cleaned every time a build is done.
// This pattern should be all the folders you have in /app/src/
var generatedSources = [
'./app/{shared,test,views}'
];
// Which emulator to run?
// Valid emulators are
// iPhone-4s, iPhone-5, iPhone-5s, iPhone-6-Plus, iPhone-6,
// iPad-2, iPad-Retina, iPad-Air, Resizable-iPhone, Resizable-iPa
var emulator = 'iPhone-5';
var gulp = require('gulp');
var chalk = require('chalk');
var spawn = require('child_process').spawn;
var babel = require('gulp-babel');
var mocha = require('gulp-mocha');
var mergeStream = require('merge-stream');
var del = require('del');
var runSequence = require('run-sequence');
var eslint = require('gulp-eslint');
gulp.task('_emulate', function(cb) {
var child = spawn('tns', ['emulate', 'ios', '--device', emulator], {cwd: process.cwd()});
var stdout = '';
var stderr = '';
child.stdout.setEncoding('utf8');
child.stdout.on('data', function (data) {
stdout += data;
console.log(data);
});
child.stderr.setEncoding('utf8');
child.stderr.on('data', function (data) {
stderr += data;
console.log(chalk.red(data));
});
child.on('close', function(code) {
console.log('Done with exit code', code);
});
cb();
});
gulp.task('_clean', function(cb) {
del(generatedSources, cb);
});
gulp.task('_compile', function() {
var js = gulp.src(babelSrc)
.pipe(babel({
stage: 1
}))
.pipe(gulp.dest('app'));
var res = gulp.src(resources)
.pipe(gulp.dest('app'));
return mergeStream(js, res);
});
gulp.task('_test', function() {
return gulp.src(['app/test/*.js'], { read: false })
.pipe(mocha({
reporter: 'spec'
}));
});
gulp.task('test', function(callback) {
runSequence(
'_clean',
'_compile',
'_test',
callback);
});
gulp.task('lint', function () {
return gulp.src(babelSrc)
.pipe(eslint())
.pipe(eslint.format());
});
gulp.task('watch', function(callback) {
console.log();
console.log(chalk.blue('Watcher started, will restart emulator ') + chalk.yellow(emulator) + chalk.blue(' when files change'));
console.log('Tip: Run "gulp help" to show help');
console.log();
gulp.watch(watchedFiles, function () {
runSequence(
'_clean',
'_compile',
'_emulate',
callback);
}
);
});
gulp.task('default', function() {
console.log();
console.log(chalk.magenta(' Main tasks'));
console.log();
console.log(' ' + chalk.blue('gulp watch') + ' - Start watching files, recompile Javascript and restart');
console.log(' emulator (set to: ' + emulator + ') when files change.');
console.log();
console.log(' ' + chalk.blue('gulp test') + ' - Clean, compile and run tests in /app/tests');
console.log();
console.log(' ' + chalk.blue('gulp lint') + ' - Run eslint');
console.log();
console.log(chalk.magenta(' Sub-tasks') + ' (primarily run by main tasks)');
console.log();
console.log(' ' + chalk.blue('gulp _clean') + ' - Clean target folders (' + generatedSources.join(', ') + ')');
console.log();
console.log(' ' + chalk.blue('gulp _compile') + ' - Compile Javascript');
console.log();
console.log(' ' + chalk.blue('gulp _test') + ' - Run emulator (set to: ' + emulator + ')');
console.log();
});