forked from VadimDez/ng2-pdf-viewer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
128 lines (112 loc) · 3.3 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
"use strict";
const gulp = require("gulp");
const del = require("del");
const tsc = require("gulp-typescript");
const sourcemaps = require('gulp-sourcemaps');
const tsProject = tsc.createProject("tsconfig.json");
const tslint = require('gulp-tslint');
const Builder = require("systemjs-builder");
const inlineNg2Template = require('gulp-inline-ng2-template');
const exec = require('child_process').exec;
const os = require('os');
/**
* Remove build directory.
*/
gulp.task('clean', (cb) => {
return del(["build"], cb);
});
/**
* Lint all custom TypeScript files.
*/
gulp.task('tslint', () => {
return gulp.src("src/**/*.ts")
.pipe(tslint({
formatter: 'prose'
}))
.pipe(tslint.report());
});
/**
* Compile TypeScript sources and create sourcemaps in build directory.
*/
gulp.task("compile", ["tslint"], cb => {
var cmd = os.platform() === 'win32' ?
'node_modules\\.bin\\ngc -p tsconfig-aot.json' : './node_modules/.bin/ngc -p tsconfig-aot.json';
exec(cmd, function (err, stdout, stderr) {
console.log(stdout);
console.log(stderr);
cb(err);
});
});
/**
* Compile TypeScript sources and create sourcemaps in build directory.
*/
gulp.task('compile-and-inline-html', ['tslint'], () => {
let tsResult = gulp.src(`${ __dirname }/src/**/*.ts`)
.pipe(inlineNg2Template({ base: './src' }))
.pipe(sourcemaps.init())
.pipe(tsProject());
return tsResult.js
.pipe(sourcemaps.write("."))
.pipe(gulp.dest(`${ __dirname }/build`));
});
/**
* Copy all resources that are not TypeScript files into build directory.
*/
gulp.task('resources', () => {
return gulp.src([`${ __dirname }/src/**/*.css`, `${ __dirname }/src/**/*.html`])
.pipe(gulp.dest(`${ __dirname }/build`));
});
/**
* Copy all required libraries into build directory.
*/
gulp.task("libs", () => {
return gulp.src([
'es6-shim/es6-shim.min.js',
'systemjs/dist/system-polyfills.js',
'systemjs/dist/system.src.js',
'reflect-metadata/Reflect.js',
'rxjs/**',
'zone.js/dist/**',
'@angular/**',
'pdfjs-dist/**',
'material-design-lite/**'
], {cwd: "node_modules/**"}) /* Glob required here. */
.pipe(gulp.dest(`${ __dirname }/build/lib`));
});
gulp.task("files", () => {
return gulp.src([
'pdf-test.pdf'
])
.pipe(gulp.dest("build"));
});
/**
* Watch for changes in TypeScript, HTML and CSS files.
*/
gulp.task('watch', function () {
gulp.watch([`${ __dirname }/src/**/*.ts`], ['compile']).on('change', function (e) {
console.log('TypeScript file ' + e.path + ' has been changed. Compiling.');
});
gulp.watch([`${ __dirname }/src/**/*.html`, `${ __dirname }/src/**/*.css`], ['resources']).on('change', function (e) {
console.log('Resource file ' + e.path + ' has been changed. Updating.');
});
});
/**
* Build the project.
*/
gulp.task("build", ['compile', 'resources', 'libs', 'files'], () => {
console.log("Building the project ...");
});
gulp.task("builder", function() {
var builder = new Builder();
builder.loadConfig('./system.config.js')
.then(function() {
builder.buildStatic('./build/main.js', './build/app.min.js')
.then(function () {
console.log('Build complete');
})
.catch((err) => {
console.log(err);
});
});
});
gulp.task('gh-pages', ['compile-and-inline-html', 'builder']);