This repository has been archived by the owner on Aug 18, 2018. It is now read-only.
/
gulpfile.js
161 lines (136 loc) Β· 4.82 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
157
158
159
160
161
'use strict';
var gulp = require('gulp'),
debug = require('gulp-debug'),
inject = require('gulp-inject'),
tsc = require('gulp-typescript'),
tslint = require('gulp-tslint'),
sourcemaps = require('gulp-sourcemaps'),
del = require('del'),
Config = require('./gulpfile.config'),
tsProject = tsc.createProject('tsconfig.json'),
browserSync = require('browser-sync'),
superstatic = require( 'superstatic' );
var config = new Config();
/**
* Lint all custom TypeScript files.
*/
gulp.task('ts-lint', function () {
return gulp.src(config.allTypeScript).pipe(tslint()).pipe(tslint.report('prose'));
});
gulp.task('compile-ts', function () {
var sourceTsFiles = [config.allTypeScript, //path to typescript files
config.libraryTypeScriptDefinitions
]; //reference to library .d.ts files
var tsResult = gulp.src(sourceTsFiles)
.pipe(sourcemaps.init())
.pipe(tsc(tsProject));
tsResult.dts.pipe(gulp.dest(config.tsOutputPath));
return tsResult.js
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest(config.tsOutputPath));
});
/**
* Remove all generated JavaScript files from TypeScript compilation.
*/
gulp.task('clean-ts', function (cb) {
var typeScriptGenFiles = [
config.tsOutputPath +'/**/*.js', // path to all JS files auto gen'd by editor
config.tsOutputPath +'/**/*.js.map', // path to all sourcemap files auto gen'd by editor
'!' + config.tsOutputPath + '/lib'
];
// delete the files
del(typeScriptGenFiles, cb);
});
gulp.task('watch', function() {
gulp.watch(['./src/**/*.ts'], ['lib', 'demo']);
});
var concat = require('gulp-concat');
var ts = require('gulp-typescript');
var sourcemaps = require('gulp-sourcemaps');
var ngAnnotate = require('gulp-ng-annotate');
var uglify = require('gulp-uglify');
gulp.task('lib', function() {
var tsResult = gulp.src(['src/library/**/*.ts', 'src/*.ts'])
.pipe(sourcemaps.init()) // This means sourcemaps will be generated
.pipe(ts({
sortOutput: true,
}));
return tsResult.js
.pipe(ngAnnotate())
.pipe(concat('ts-angular-jsonapi.js')) // You can use other plugins that also support gulp-sourcemaps
.pipe(sourcemaps.write()) // Now the sourcemaps are added to the .js file
.pipe(gulp.dest('build'));
});
var merge = require('merge-stream');
var stripLine = require('gulp-strip-line');
gulp.task('dist', function() {
// get ts interfaces
var tsResult = gulp.src(['src/library/**/*.ts', 'src/library/**/*.d.ts', 'typings/globals/**/*.d.ts'])
.pipe(ts({
declarationFiles: true,
declaration: true,
noExternalResolve: true,
noImplicitAny: false,
removeComments: false,
target: 'ES5',
emitDecoratorMetadata: false
}));
var content1 = tsResult.dts;
// // get ts definitions
var content2 = gulp.src(['src/library/**/*.d.ts']);
// put all ts information
var final_content = merge(content1, content2);
final_content
.pipe(concat('tsd.d.ts'))
// remove lines with triple-slash references
// ref: https://www.typescriptlang.org/docs/handbook/typings-for-npm-packages.html
.pipe(stripLine([/^\/\/\//, 'use strict']))
.pipe(gulp.dest('dist'))
// get all ts information for compression
var tsResult = gulp.src(['src/library/**/*.ts', 'src/*.ts'])
.pipe(ts({
sortOutput: true,
}));
// library
tsResult.js
.pipe(ngAnnotate())
.pipe(concat('ts-angular-jsonapi.js')) // You can use other plugins that also support gulp-sourcemaps
.pipe(sourcemaps.write()) // Now the sourcemaps are added to the .js file
.pipe(gulp.dest('dist'));
// mifified library
return tsResult.js
.pipe(ngAnnotate())
.pipe(uglify())
.pipe(concat('ts-angular-jsonapi.min.js')) // You can use other plugins that also support gulp-sourcemaps
.pipe(gulp.dest('dist'));
});
gulp.task('demo', function() {
var tsResult = gulp.src('src/demo/**/*.ts')
.pipe(sourcemaps.init()) // This means sourcemaps will be generated
.pipe(ts({
sortOutput: true,
}));
return tsResult.js
.pipe(ngAnnotate())
.pipe(concat('demo.js')) // You can use other plugins that also support gulp-sourcemaps
.pipe(sourcemaps.write()) // Now the sourcemaps are added to the .js file
.pipe(gulp.dest('build'));
});
gulp.task('serve', ['lib', 'demo', 'watch'], function() {
process.stdout.write('Starting browserSync and superstatic...\n');
browserSync({
port: 3000,
files: ['index.html', '**/*.js'],
injectChanges: true,
logFileChanges: false,
logLevel: 'silent',
logPrefix: 'angularin20typescript',
notify: true,
reloadDelay: 0,
server: {
baseDir: './src/demo',
middleware: superstatic({ debug: false})
}
});
});
gulp.task('default', ['dist']);