This repository has been archived by the owner on May 11, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 66
/
gulpfile.js
142 lines (120 loc) · 5.06 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
require('es6-promise').polyfill();
var gulp = require('gulp'),
bump = require('gulp-bump'),
ts = require('typescript'),
gulpts = require('gulp-typescript'),
es = require('event-stream'),
merge = require('merge'),
minifyjs = require('gulp-uglify'),
concat = require('gulp-concat'),
fs = require("fs"),
rename = require("gulp-rename"),
minifycss = require("gulp-cssnano"),
argv = require('yargs').argv,
insert = require("gulp-insert"),
browserify = require('browserify'),
source = require('vinyl-source-stream'),
buffer = require('vinyl-buffer'),
concatCss = require('gulp-concat-css'),
less = require('gulp-less');
var paths = {
sample: './sample',
sampleFontsSource: './node_modules/bootstrap/fonts/*.*',
sampleJsSource: './sample/sample.js',
sampleCssSource: './sample/sample.less',
sampleFontsOutput: './sample/fonts',
sampleJsOutput: 'sample-bundle.js',
sampleCssOutput: 'sample-bundle.css',
src:'./src',
tsSource: './src/typescript/**/*.ts',
cssSource: './src/css/**/*.css',
jsOutput: ".",
cssOutput: "."
};
// tasks can be run from npm as well. example: 'npm run gulp -- ts-compile --version x.x.x'
// the sample can be run and debugged with 'gulp build-sample' or 'gulp debug-sample', followed by 'npm start', which by default will execute 'npm server.js'
// typings can be queried with 'tsd query angular' and installed with 'tsd install angular'
gulp.task('ts-compile', function () {
// set the version if provided via gulp: gulp ts-compile --version x.x.x
var libVersion = argv.version;
if (libVersion !== undefined) {
gulp
.src('./bower.json')
.pipe(bump({ version: libVersion }))
.pipe(gulp.dest('./'));
gulp
.src('./package.json')
.pipe(bump({ version: libVersion }))
.pipe(gulp.dest('./'));
}
// read several definitions
eval("var npmProjectDef = " + fs.readFileSync("./package.json"));
eval("var bowerProjectDef = " + fs.readFileSync("./bower.json"));
var tsProject = gulpts.createProject('tsconfig.json', { typescript: ts});
//bowerProjectDef.version = npmProjectDef.version;
//fs.writeFileSync("./bower.json", JSON.stringify(bowerProjectDef, null, 4));
//.match(/var\s+version\s*=\s*\"(\d+.\d+.\d+)\"/)
var outputVersionInfo =
"/*========================================================================*/\n" +
"/* TrNgGrid version " + bowerProjectDef.version + " */\n" +
"/* ------------------------------------------------------------- */\n" +
"/* THIS FILE WAS GENERATED VIA GULP. DO NOT MODIFY THIS FILE MANUALLY. */\n" +
"/*======================================================================= */\n";
var outputJsResults = tsProject.src(paths.tsSource)
.pipe(gulpts(tsProject))
.pipe(concat('trNgGrid.js'))
.pipe(insert.prepend(outputVersionInfo))
.pipe(gulp.dest(paths.jsOutput));
var minifiedJsResults = outputJsResults
.pipe(insert.prepend(outputVersionInfo))
.pipe(concat('trNgGrid.min.js'))
.pipe(minifyjs())
.pipe(gulp.dest(paths.jsOutput));
var outputCssResults = gulp
.src(paths.cssSource)
.pipe(insert.prepend(outputVersionInfo))
.pipe(concat('trNgGrid.css'))
.pipe(gulp.dest(paths.cssOutput));
var minifiedCssResults = gulp
.src(paths.cssSource)
.pipe(insert.prepend(outputVersionInfo))
.pipe(concat('trNgGrid.min.css'))
.pipe(minifycss())
.pipe(gulp.dest(paths.cssOutput));
return merge([outputJsResults, outputCssResults, minifiedJsResults, minifiedCssResults]);
});
gulp.task('build-sample', ['ts-compile'],
function () {
var browserifySampleResults = browserify(paths.sampleJsSource,
{
insertGlobals: true
})
.bundle()
.pipe(source(paths.sampleJsOutput))
.pipe(buffer())
.pipe(gulp.dest(paths.sample));
//var bootstrapCssCompileResults = gulp
// .src('./node_modules/bootstrap/less/bootstrap.less', { base: "./node_modules/bootstrap/less" })
// .pipe(less());
//var cssConcatResults = es.merge(gulp.src(paths.cssOutput + '/trNgGrid.css'), bootstrapCssCompileResults)
// .pipe(concatCss('sample-bundle.css'))
// .pipe(gulp.dest(paths.sample));
var copyFontsResults = gulp
.src(paths.sampleFontsSource)
.pipe(gulp.dest(paths.sampleFontsOutput));
var cssConcatResults = gulp
.src(paths.sampleCssSource)
.pipe(less())
.pipe(rename(paths.sampleCssOutput))
.pipe(gulp.dest(paths.sample));
return merge([browserifySampleResults, cssConcatResults, copyFontsResults]);
});
gulp.task('debug-sample',
['ts-compile'],
function () {
gulp.watch(paths.src, ['build-sample']);
});
gulp.task('default',
['ts-compile'],
function() {
});