-
Notifications
You must be signed in to change notification settings - Fork 34
/
gulpfile.js
110 lines (96 loc) · 3.1 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
var gulp = require('gulp');
var path = require('path');
var del = require('del');
var ts = require('gulp-typescript');
var lazypipe = require('lazypipe');
var pug = require('pug');
var inlineTemplates = require('gulp-inline-ng2-template');
var cache = require('gulp-cached');
var exec = require('child_process').exec;
var isWin = /^win/.test(process.platform);
var executable = isWin ? 'node_modules\\.bin\\ngc.cmd' : './node_modules/.bin/ngc';
var webpack = require('webpack');
var argv = require('yargs')
.boolean('failOnError').default('failOnError', false) // tslint
.argv;
var PATHS = {
src: ['src/**/*.ts','!src/**/*.spec.ts'],
templates: 'src/**/*.pug',
spec: 'src/**/*.ts',
temp: 'temp/',
tsInline: 'temp/inline/',
dist: 'node_modules/ngx-card',
};
var inlineTemplatesTask = lazypipe()
.pipe(inlineTemplates, {
base: '/src',
useRelativePaths: true,
templateProcessor: function(filepath, ext, file, cb) {
const rendered = pug.render(file, {
doctype: 'html',
filename: filepath,
});
cb(null, rendered);
},
templateExtension: '.pug',
});
gulp.task('clean', function() {
return del([PATHS.dist, PATHS.temp]);
});
gulp.task('lint:ts', function lint_ts_impl() {
var tslint = require('gulp-tslint');
return gulp.src( PATHS.spec )
.pipe(cache('lint:ts'))
.pipe(tslint({
formatter: 'prose',
}))
.pipe(tslint.report({
emitError: argv.failOnError,
summarizeFailureOutput: true,
}));
});
gulp.task('ngc:templates', function() {
return gulp.src(PATHS.src, {base: 'src'})
.pipe(gulp.dest(PATHS.tsInline));
});
gulp.task('ngc', gulp.series('lint:ts', 'ngc:templates', function __ngc(cb) {
exec(`${executable} -p ./tsconfig.json`, (e) => {
if (e) console.log(e);
del('./temp/waste');
cb();
}).stdout.on('data', function(data) { console.log(data); });
}));
gulp.task('bundle', function __bundle(done) {
webpack({
devtool: 'source-map',
resolve: { extensions: ['.js'] },
entry: path.resolve(__dirname, PATHS.dist, 'ngx-card.js'),
output: {
filename: PATHS.dist + '/bundles/ngx-card.umd.js',
library: 'ngx-card',
libraryTarget: 'umd'
},
externals: [/^\@angular\//, /^rxjs\//], // require but don't bundle
}, function(err, stats) {
if (err) throw new Error('bundle [webpack]', err);
done();
});
});
gulp.task('build', gulp.series('clean', 'ngc', 'bundle'));
gulp.task('build:watch', function() {
gulp.watch([ PATHS.src ], gulp.series('ngc', 'bundle'));
});
gulp.task('demo:clean', function() {
return del(['demo/**/*.ngfactory.ts', 'demo/**/*.ngsummary.json', 'demo/node_modules', 'temp/demo']);
});
gulp.task('demo:ngc', gulp.series('demo:clean', function __ngc(cb) {
exec(`${executable} -p ./demo/tsconfig-aot.json`, (e) => {
if (e) console.log(e);
cb();
}).stdout.on('data', function(data) { console.log(data); });
}));
gulp.task('prepublish', gulp.series('build', function prepublish_impl() {
return gulp.src(['package.json', '*.md', 'LICENSE'])
.pipe(gulp.dest(PATHS.dist));
}));
gulp.task('default', gulp.series('build'));