-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
156 lines (134 loc) · 4.27 KB
/
gulpfile.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
151
152
153
154
155
156
'use strict';
var gulp = require("gulp");
var ts = require("gulp-typescript");
var browserify = require("browserify");
var source = require('vinyl-source-stream');
var $ = require('gulp-load-plugins')({lazy: true});
var sassLint = require('gulp-sass-lint');
var tsify = require('tsify');
var del = require('del');
var sassImportOnce = require('gulp-sass-import-once');
var settings = require('./gulp.settings/settings');
gulp.task('clean-styles', function (done) {
var files = settings.app.cssStyles + '*.css';
clean(files, done);
});
gulp.task('code-check', function () {
return gulp.src(settings.app.allTSs)
.pipe($.tslint({
formatter: "verbose"
}))
.pipe($.tslint.report());
});
gulp.task('lint-sass', ['clean-styles'], function () {
return gulp.src(settings.app.scssStyles)
.pipe(sassLint(
{
configFile: '.sass-lint.yml'
}
))
.pipe(sassLint.format())
.pipe(sassLint.failOnError())
});
gulp.task('test-run', function (done) {
runTests(done);
});
gulp.task('sass-compile', ['lint-sass'], function () {
msg('Kompilacja plików scss -> css');
return gulp.src(settings.app.scssFile)
.pipe(sassImportOnce())
.pipe($.sass().on('error', $.sass.logError))
.pipe($.autoprefixer({browsers: ['last 3 version', '> 3%']}))
.pipe(gulp.dest(settings.app.cssStyles));
});
gulp.task('browserify-compil', [], function () {
return browserify({
entries: [settings.app.tsFile],
debug: true
}).plugin(tsify)
.bundle()
.pipe(source(settings.app.compiledJS))
.pipe(gulp.dest('./'));
});
gulp.task('browserify-inject-js', ['browserify-compil'], function () {
return gulp.src(settings.app.index)
.pipe($.inject(gulp.src(settings.app.compiledJS, {read: false}), {relative: true}))
.pipe(gulp.dest(settings.app.client));
});
gulp.task('build-prepare', ['browserify-inject-js', 'inject-css'], function () {
});
gulp.task('dist-optimize', ['build-prepare', 'copyToBuild-fonts'], function () {
var cleanCss = require('gulp-clean-css');
return gulp.src(settings.app.index)
.pipe($.plumber())
.pipe($.useref())
.pipe($.if('*.js', $.uglify()))
.pipe($.if('*.css', cleanCss()))
.pipe(gulp.dest(settings.build.path));
});
gulp.task('copyToBuild-fonts', function () {
msg('Kopiowanie fontów');
return gulp.src(settings.app.fontsSrc)
.pipe(gulp.dest(settings.build.fontsPath));
});
gulp.task('run-dist', ['dist-optimize'], function () {
serve(false);
});
gulp.task('run-dev', ['browserify-inject-js', 'inject-css', 'test-run'], function () {
serve(true);
});
gulp.task('help', $.taskListing);
gulp.task('default', ['help']);
gulp.task('sass-watcher', function () {
gulp.watch(settings.app.scssStyles, ['sass-compile', 'inject-css']);
});
gulp.task('inject-css', ['sass-compile'], function () {
return gulp.src(settings.app.index)
.pipe($.inject(gulp.src(settings.app.cssFile, {read: false}), {relative: true}))
.pipe(gulp.dest(settings.app.client));
});
gulp.task('ts-watcher', function () {
gulp.watch(settings.app.allTSs, ['browserify-inject-js']);
});
function serve(isDev) {
var nodeOptions = {
script: settings.server.serverApp,
ext: 'js',
delay: 2500,
env: {
'PORT': settings.server.port,
'NODE_ENV': isDev ? 'dev' : 'build'
},
watch: settings.server.serverFiles
};
return $.nodemon(nodeOptions)
.on('start', function () {
msg('...start servera ...');
})
.on('restart', function () {
msg('...restart servera...');
})
.on('exit', function () {
})
.on('crash', function () {
msg('!!!Wystąpiły bęłdy');
});
}
//--functions
function clean(path, done) {
$.util.log('Czyszczenie folderu:' + $.util.colors.blue(path));
del(path).then(function () {
done();
});
}
function msg(txt) {
$.util.log($.util.colors.blue(txt));
}
function runTests(done) {
var Server = require('karma').Server;
var karmaServer = new Server({
configFile: __dirname + '/karma.conf.js',
}, function (exitCode) {
done();
}).start();
}