-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
148 lines (126 loc) · 4.48 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
var gulp = require('gulp');
var del = require('del');
var concat = require('gulp-concat');
var plumber = require('gulp-plumber');
var rename = require('gulp-rename');
var traceur = require('gulp-traceur');
var runSequence = require('run-sequence');
var PATHS = {
src: {
js: ['ng2/**/*.js'],
html: 'ng2/**/*.html',
css: 'ng2/**/*.css',
shared: "shared/*.js"
},
dist: "dist/ng2",
a2libs: [
'node_modules/gulp-traceur/node_modules/traceur/bin/traceur-runtime.js',
'node_modules/es6-module-loader/dist/es6-module-loader-sans-promises.src.js',
'node_modules/systemjs/lib/extension-cjs.js',
'node_modules/systemjs/lib/extension-register.js',
'node_modules/angular2/node_modules/zone.js/zone.js',
'node_modules/angular2/node_modules/zone.js/long-stack-trace-zone.js',
'node_modules/angular2/node_modules/rx/dist/rx.all.js',
'css/bootstrap.css',
'css/bootstrap.css.map'
]
};
gulp.task('clean', function(done) {
del([PATHS.dist], done);
});
gulp.task('js', function () {
return gulp.src(PATHS.src.js)
.pipe(rename({extname: ''})) //hack, see: https://github.com/sindresorhus/gulp-traceur/issues/54
.pipe(plumber())
.pipe(traceur({
modules: 'instantiate',
moduleName: true,
annotations: true,
types: true,
memberVariables: true
}))
.pipe(rename({extname: '.js'})) //hack, see: https://github.com/sindresorhus/gulp-traceur/issues/54
.pipe(gulp.dest(PATHS.dist));
});
gulp.task("ng1js", [], function() {
return gulp.src(PATHS.src.js)
.pipe(gulp.dest(PATHS.dist));
});
gulp.task('html', function () {
return gulp.src(PATHS.src.html)
.pipe(gulp.dest(PATHS.dist));
});
gulp.task('css', function () {
return gulp.src(PATHS.src.css)
.pipe(gulp.dest(PATHS.dist));
});
gulp.task('libs', ['angular2'], function () {
return gulp.src(PATHS.a2libs)
.pipe(gulp.dest(PATHS.dist+'/lib'));
});
gulp.task("shared", function() {
return gulp.src(PATHS.src.shared)
.pipe(gulp.dest(PATHS.dist+"/shared"));
})
gulp.task('angular2', function () {
//transpile & concat
return gulp.src([
'node_modules/angular2/es6/prod/*.es6',
'node_modules/angular2/es6/prod/src/**/*.es6'],
{ base: 'node_modules/angular2/es6/prod' })
.pipe(rename(function(path){
path.dirname = 'angular2/' + path.dirname; //this is not ideal... but not sure how to change angular's file structure
path.extname = ''; //hack, see: https://github.com/sindresorhus/gulp-traceur/issues/54
}))
.pipe(traceur({ modules: 'instantiate', moduleName: true}))
.pipe(concat('angular2.js'))
.pipe(gulp.dest(PATHS.dist+'/lib'));
});
gulp.task('play', ['ng2'], function () {
var http = require('http');
var connect = require('connect');
var serveStatic = require('serve-static');
var open = require('open');
var port = 9000, app;
gulp.watch(PATHS.src.html, ['html']);
gulp.watch(PATHS.src.js, ['js']);
gulp.watch(PATHS.src.css, ['css']);
gulp.watch(PATHS.src.shared, ['shared']);
app = connect().use(serveStatic(__dirname + '/dist')); // serve everything that is static
http.createServer(app).listen(port, function () {
open('http://localhost:' + port+"/ng2");
});
});
gulp.task("ng1watchers", ["shared"], function() {
gulp.watch(PATHS.src.html, ['html']);
gulp.watch(PATHS.src.js, ['ng1js']);
gulp.watch(PATHS.src.css, ['css']);
gulp.watch(PATHS.src.shared, ['shared']);
});
gulp.task("ng1play", ["ng1"], function() {
var http = require('http');
var connect = require('connect');
var serveStatic = require('serve-static');
var open = require('open');
var port = 9001, app;
app = connect().use(serveStatic(__dirname + '/dist')); // serve everything that is static
http.createServer(app).listen(port, function () {
open('http://localhost:' + port+"/ng1");
});
});
gulp.task("ng1paths", [], function() {
PATHS.src = {
js: ['ng1/**/*.js'],
html: 'ng1/**/*.html',
css: 'ng1/**/*.css',
shared: "shared/*.js"
};
PATHS.dist = "dist/ng1";
});
gulp.task("ng1", ["ng1paths"], function() {
runSequence("clean", ['ng1js', 'html', 'css', "shared"], "ng1watchers");
});
gulp.task('ng2', ['js', 'html', 'libs', 'css', "shared"]);
gulp.task("default", [], function() {
runSequence("play", "ng1play");
});