-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgulpfile.js
109 lines (96 loc) · 2.35 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
/* tslint:disable:no-console */
const del = require('del');
const log = require('fancy-log');
const gulp = require('gulp');
const gulpTslint = require('gulp-tslint');
const gulpTs = require('gulp-typescript');
const gulpRunSequence = require('run-sequence');
const tslint = require('tslint');
const prettierPlugin = require('gulp-prettier-plugin');
function pipeErrHandler(err) {
log(err);
process.exit(1);
}
const PRETTIER_SRC = ['src/**/*.*', 'typings/**/*.*', 'test/**/*.*'];
const PRETTIER_IGNORE = [
'!**/package.json',
'!**/dist/**/*.*',
'!**/node_modules/**/*.*',
'!**/*.yaml',
'!**/*.yml',
'!**/*.sh',
'!**/*.html',
'!**/*.lock',
'!**/*.ejs',
'!**/*.*-',
'!**/*.sql',
'!**/*.txt',
];
const PRETTIER_CONFIG = {
trailingComma: "all",
useTabs: false,
singleQuote: true,
quoteProps: "consistent",
tabWidth: 2,
semi: true,
printWidth: 200
};
// copy assets files from src to dist
gulp.task('copy-assets', () => {
return gulp
.src([
// 'package.json',
// 'package-lock.json',
// 'yarn.lock',
'src/**/*',
'!src/**/*.ts',
'!**/node_modules/**/*',
])
.pipe(gulp.dest('dist/src/'))
});
gulp.task('clean-build', () => {
return new Promise(resolve => {
const result = del.sync(['dist/**/*', 'dist/**/.*']);
resolve(result);
});
});
// build process
gulp.task('prettier-noFix', () => {
return gulp
.src([...PRETTIER_SRC, ...PRETTIER_IGNORE])
.pipe(prettierPlugin(PRETTIER_CONFIG, { filter: true, validate: true }))
.on('error', pipeErrHandler);
});
gulp.task('tslint-noFix', () => {
const lintProgram = tslint.Linter.createProgram('./tsconfig.json');
/**
* this pipe is exit code ready
*/
return gulp
.src(['src/**/*.ts', 'tests/**/*.ts', ...PRETTIER_IGNORE])
.pipe(
gulpTslint({
program: lintProgram,
}),
)
.pipe(gulpTslint.report());
});
gulp.task('compile-code', () => {
const appCodeTsProject = gulpTs.createProject('tsconfig.json');
return appCodeTsProject
.src()
.pipe(appCodeTsProject())
.on('error', pipeErrHandler)
.pipe(gulp.dest(appCodeTsProject.options.outDir));
});
gulp.task('lint-noFix', gulp.series(
['prettier-noFix', 'tslint-noFix'],
done => done(),
));
gulp.task('build', gulp.series(
'clean-build',
['prettier-noFix', 'tslint-noFix'],
'compile-code',
'copy-assets',
done => done(),
));