Skip to content

Commit a142ccd

Browse files
committed
Added e2e, changed the gulp plugin for server, finished.
1 parent 9e4c3d4 commit a142ccd

File tree

3 files changed

+134
-101
lines changed

3 files changed

+134
-101
lines changed

gulpfile.js

Lines changed: 132 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const karma = require('karma');
1515

1616
// Gulp plugins.
1717
const gulpClean = require('gulp-clean');
18-
const gulpLiveServer = require('gulp-live-server');
18+
const gulpServer = require('gulp-server-livereload');
1919
const gulpMerge = require('merge2');
2020
const gulpRunSequence = require('run-sequence');
2121
const gulpSass = require('gulp-sass');
@@ -81,15 +81,37 @@ function makeSassBuildTask(options) {
8181
}
8282

8383

84+
/**
85+
* Create a Gulp task that executes a process.
86+
*/
87+
function makeExecTask(packageName, executable, args) {
88+
if (!args) {
89+
args = executable;
90+
executable = undefined;
91+
}
92+
return function(done) {
93+
resolveBin(packageName, { executable: executable }, function (err, binPath) {
94+
child_process.exec(`${binPath} ${args.join(' ')}`, function (error) {
95+
if (error) {
96+
console.error(error);
97+
throw error;
98+
} else {
99+
done();
100+
}
101+
});
102+
});
103+
}
104+
}
105+
84106
/***************************************************************************************************
85107
* Components Build Tasks.
86108
*/
87-
gulp.task('build:components:ts', makeTsBuildTask({ tsConfigPath: componentsDir }));
88-
gulp.task('build:components:assets', function() {
109+
gulp.task(':build:components:ts', makeTsBuildTask({ tsConfigPath: componentsDir }));
110+
gulp.task(':build:components:assets', function() {
89111
return gulp.src(path.join(componentsDir, '*/**/*.!(ts|spec.ts)'))
90112
.pipe(gulp.dest(outLibDir));
91113
});
92-
gulp.task('build:components:scss', function() {
114+
gulp.task(':build:components:scss', function() {
93115
const cssTask = makeSassBuildTask({
94116
dest: outLibDir,
95117
root: componentsDir,
@@ -103,36 +125,22 @@ gulp.task('build:components:scss', function() {
103125
]);
104126
});
105127
gulp.task('build:components', [
106-
'build:components:ts',
107-
'build:components:assets',
108-
'build:components:scss'
128+
':build:components:ts',
129+
':build:components:assets',
130+
':build:components:scss'
109131
], function() {
110132
inlineResources([outLibDir]);
111133
});
112-
gulp.task('build:components:ngc', ['build:components'], function(done) {
113-
resolveBin('@angular/compiler-cli', { executable: 'ngc' }, function(err, cliPath) {
114-
if (err) {
115-
console.error(err);
116-
process.exit(1);
117-
}
118-
119-
child_process.exec(`${cliPath} -p ${path.relative(__dirname, componentsDir)}`, function(error) {
120-
console.log(arguments);
121-
if (error) {
122-
console.error(error);
123-
process.exit(1);
124-
}
125-
126-
done();
127-
});
128-
});
129-
});
134+
gulp.task(':build:components:ngc', ['build:components'], makeExecTask(
135+
'@angular/compiler-cli', 'ngc', ['-p', path.relative(__dirname, componentsDir)]
136+
));
137+
130138

131139
/***************************************************************************************************
132140
* DevApp Build Tasks.
133141
*/
134-
gulp.task('build:devapp:ts', ['build:components:ts'], makeTsBuildTask({ tsConfigPath: devAppDir }));
135-
gulp.task('build:devapp:scss', ['build:components:scss'], makeSassBuildTask({
142+
gulp.task(':build:devapp:ts', [':build:components:ts'], makeTsBuildTask({ tsConfigPath: devAppDir }));
143+
gulp.task(':build:devapp:scss', [':build:components:scss'], makeSassBuildTask({
136144
dest: outDir,
137145
root: devAppDir,
138146
// Change this once we have a better strategy for releasing SCSS files.
@@ -141,11 +149,11 @@ gulp.task('build:devapp:scss', ['build:components:scss'], makeSassBuildTask({
141149
componentsDir
142150
]
143151
}));
144-
gulp.task('build:devapp:assets', function() {
152+
gulp.task(':build:devapp:assets', function() {
145153
return gulp.src(path.join(devAppDir, '**/*'))
146154
.pipe(gulp.dest(outDir));
147155
});
148-
gulp.task('build:devapp:vendor', function() {
156+
gulp.task(':build:devapp:vendor', function() {
149157
const npmVendorFiles = [
150158
'core-js/client', 'zone.js/dist', 'hammerjs', 'systemjs/dist', 'rxjs', '@angular', 'hammerjs'
151159
];
@@ -160,17 +168,17 @@ gulp.task('build:devapp:vendor', function() {
160168

161169
gulp.task('build:devapp', [
162170
'build:components',
163-
'build:devapp:vendor',
164-
'build:devapp:ts',
165-
'build:devapp:scss',
166-
'build:devapp:assets'
171+
':build:devapp:vendor',
172+
':build:devapp:ts',
173+
':build:devapp:scss',
174+
':build:devapp:assets'
167175
]);
168176

169177
/***************************************************************************************************
170178
* DevApp Build Tasks.
171179
*/
172-
gulp.task('build:e2eapp:ts', ['build:components:ts'], makeTsBuildTask({ tsConfigPath: e2eAppDir }));
173-
gulp.task('build:e2eapp:scss', ['build:components:scss'], makeSassBuildTask({
180+
gulp.task(':build:e2eapp:ts', [':build:components:ts'], makeTsBuildTask({ tsConfigPath: e2eAppDir }));
181+
gulp.task(':build:e2eapp:scss', [':build:components:scss'], makeSassBuildTask({
174182
dest: outDir,
175183
root: e2eAppDir,
176184
// Change this once we have a better strategy for releasing SCSS files.
@@ -179,11 +187,11 @@ gulp.task('build:e2eapp:scss', ['build:components:scss'], makeSassBuildTask({
179187
componentsDir
180188
]
181189
}));
182-
gulp.task('build:e2eapp:assets', function() {
190+
gulp.task(':build:e2eapp:assets', function() {
183191
return gulp.src(path.join(e2eAppDir, '**/*'))
184192
.pipe(gulp.dest(outDir));
185193
});
186-
gulp.task('build:e2eapp:vendor', function() {
194+
gulp.task(':build:e2eapp:vendor', function() {
187195
const npmVendorFiles = [
188196
'core-js/client', 'zone.js/dist', 'hammerjs', 'systemjs/dist', 'rxjs', '@angular', 'hammerjs'
189197
];
@@ -198,18 +206,26 @@ gulp.task('build:e2eapp:vendor', function() {
198206

199207
gulp.task('build:e2eapp', [
200208
'build:components',
201-
'build:e2eapp:vendor',
202-
'build:e2eapp:ts',
203-
'build:e2eapp:scss',
204-
'build:e2eapp:assets'
209+
':build:e2eapp:vendor',
210+
':build:e2eapp:ts',
211+
':build:e2eapp:scss',
212+
':build:e2eapp:assets'
205213
]);
206214

207215

208216
/***************************************************************************************************
209217
* Global tasks.
210218
*/
211-
gulp.task('default', function() {
212-
console.log(`You're probably looking for "build" or "serve:devapp".`);
219+
gulp.task('default', ['help']);
220+
221+
gulp.task('help', function() {
222+
const tasks = Object.keys(gulp.tasks)
223+
.filter(x => !x.startsWith(':'))
224+
.filter(x => x != 'default')
225+
.sort();
226+
227+
console.log(`\nHere's a list of supported tasks:\n `, tasks.join('\n '));
228+
console.log(`\nYou're probably looking for "test" or "serve:devapp".\n\n`);
213229
});
214230

215231
gulp.task('build', ['build:devapp']);
@@ -218,11 +234,11 @@ gulp.task('clean', function() {
218234
return gulp.src('dist', { read: false })
219235
.pipe(gulpClean());
220236
});
221-
gulp.task('clean:spec', function() {
237+
gulp.task(':clean:spec', function() {
222238
return gulp.src('dist/**/*.spec.*', { read: false })
223239
.pipe(gulpClean());
224240
});
225-
gulp.task('clean:assets', function() {
241+
gulp.task(':clean:assets', function() {
226242
return gulp.src('dist/**/*+(.html|.css)', { read: false })
227243
.pipe(gulpClean());
228244
});
@@ -231,66 +247,105 @@ gulp.task('clean:assets', function() {
231247
/***************************************************************************************************
232248
* Watch Tasks.
233249
*/
234-
gulp.task('watch:components', ['build:components'], function() {
235-
gulp.watch(path.join(componentsDir, '**/*'), ['build:components']);
236-
});
237-
238-
gulp.task('watch:devapp', ['watch:components', 'build:devapp'], function() {
239-
gulp.watch(path.join(devAppDir, '**/*'), ['build:devapp']);
250+
gulp.task(':watch:components', ['build:components'], function() {
251+
return gulp.watch(path.join(componentsDir, '**/*'), ['build:components']);
240252
});
241253

242254

243255
/***************************************************************************************************
244256
* Serve Tasks.
245257
*/
246258
gulp.task('serve:devapp', ['build:devapp'], function() {
247-
const server = gulpLiveServer('scripts/serve-dist.js');
259+
const stream = gulp.src('dist')
260+
.pipe(gulpServer({
261+
livereload: true,
262+
fallback: 'index.html',
263+
port: 4200
264+
}));
248265

249-
server.start();
250-
function reload(file) {
251-
server.notify(file);
252-
}
266+
gulp.watch(path.join(componentsDir, '**/*.ts'), [':build:components:ts']);
267+
gulp.watch(path.join(componentsDir, '**/*.scss'), [':build:components:scss']);
268+
gulp.watch(path.join(componentsDir, '**/*.html'), [':build:components:assets']);
269+
gulp.watch(path.join(devAppDir, '**/*.ts'), [':build:devapp:ts']);
270+
gulp.watch(path.join(devAppDir, '**/*.scss'), [':build:devapp:scss']);
271+
gulp.watch(path.join(devAppDir, '**/*.html'), [':build:devapp:assets']);
253272

254-
gulp.watch(path.join(componentsDir, '**/*.ts'), ['build:components:ts'], reload);
255-
gulp.watch(path.join(componentsDir, '**/*.scss'), ['build:components:scss'], reload);
256-
gulp.watch(path.join(componentsDir, '**/*.html'), ['build:components:assets'], reload);
257-
gulp.watch(path.join(devAppDir, '**/*.ts'), ['build:devapp:ts'], reload);
258-
gulp.watch(path.join(devAppDir, '**/*.scss'), ['build:devapp:scss'], reload);
259-
gulp.watch(path.join(devAppDir, '**/*.html'), ['build:devapp:assets'], reload);
273+
return stream;
260274
});
261275

262-
gulp.task('serve:e2eapp', ['build:e2eapp'], function() {
263-
const server = gulpLiveServer('scripts/serve-dist.js');
264276

265-
server.start();
266-
function reload(file) {
267-
server.notify.apply(server, [file]);
268-
}
277+
let stopE2eServer = null;
278+
gulp.task('serve:e2eapp', ['build:e2eapp'], function(done) {
279+
const stream = gulp.src('dist')
280+
.pipe(gulpServer({
281+
livereload: false,
282+
fallback: 'index.html',
283+
port: 4200
284+
}));
285+
286+
gulp.watch(path.join(componentsDir, '**/*.ts'), [':build:components:ts']);
287+
gulp.watch(path.join(componentsDir, '**/*.scss'), [':build:components:scss']);
288+
gulp.watch(path.join(componentsDir, '**/*.html'), [':build:components:assets']);
289+
gulp.watch(path.join(e2eAppDir, '**/*.ts'), [':build:devapp:ts']);
290+
gulp.watch(path.join(e2eAppDir, '**/*.scss'), [':build:devapp:scss']);
291+
gulp.watch(path.join(e2eAppDir, '**/*.html'), [':build:devapp:assets']);
269292

270-
gulp.watch(path.join(componentsDir, '**/*.ts'), ['build:components:ts'], reload);
271-
gulp.watch(path.join(componentsDir, '**/*.scss'), ['build:components:scss'], reload);
272-
gulp.watch(path.join(componentsDir, '**/*.html'), ['build:components:assets'], reload);
273-
gulp.watch(path.join(e2eAppDir, '**/*.ts'), ['build:e2eapp:ts'], reload);
274-
gulp.watch(path.join(e2eAppDir, '**/*.scss'), ['build:e2eapp:scss'], reload);
275-
gulp.watch(path.join(e2eAppDir, '**/*.html'), ['build:e2eapp:assets'], reload);
293+
stopE2eServer = function() {
294+
stream.emit('kill');
295+
done();
296+
};
297+
});
298+
299+
gulp.task(':serve:e2eapp:stop', function() {
300+
if (stopE2eServer) {
301+
stopE2eServer();
302+
}
276303
});
277304

278305

279306
/***************************************************************************************************
280-
* Release builds.
307+
* Tests.
281308
*/
282309
gulp.task('test', function(done) {
283310
new karma.Server({
284311
configFile: path.join(__dirname, 'test/karma.conf.js')
285312
}, done).start();
286313
});
314+
287315
gulp.task('test:single-run', function(done) {
288316
new karma.Server({
289317
configFile: path.join(__dirname, 'test/karma.conf.js'),
290318
singleRun: true
291319
}, done).start();
292320
});
293321

322+
gulp.task(':test:protractor:setup', makeExecTask('protractor', 'webdriver-manager', ['update']));
323+
324+
gulp.task(':test:protractor', makeExecTask(
325+
'protractor', [path.join(__dirname, 'test/protractor.conf.js')]
326+
));
327+
328+
gulp.task(':test:protractor:and-stop', function(done) {
329+
gulpRunSequence(
330+
':test:protractor',
331+
':serve:e2eapp:stop',
332+
done
333+
);
334+
});
335+
336+
gulp.task(':e2e:done', function() {
337+
process.exit(0);
338+
});
339+
340+
gulp.task('e2e', function(done) {
341+
gulpRunSequence(
342+
':test:protractor:setup',
343+
['serve:e2eapp', ':test:protractor:and-stop'],
344+
':e2e:done',
345+
done
346+
);
347+
});
348+
294349

295350
/***************************************************************************************************
296351
* Release builds.
@@ -299,8 +354,8 @@ gulp.task('build:release', function(done) {
299354
// Synchronously run those tasks.
300355
gulpRunSequence(
301356
'clean',
302-
'build:components:ngc',
303-
['clean:spec', 'clean:assets'],
357+
':build:components:ngc',
358+
[':clean:spec', ':clean:assets'],
304359
done
305360
);
306361
});

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@
2828
"@angular/common": "2.0.0-rc.5",
2929
"@angular/compiler": "2.0.0-rc.5",
3030
"@angular/core": "2.0.0-rc.5",
31+
"@angular/forms": "0.3.0",
3132
"@angular/http": "2.0.0-rc.5",
3233
"@angular/platform-browser": "2.0.0-rc.5",
3334
"@angular/platform-browser-dynamic": "2.0.0-rc.5",
34-
"@angular/forms": "0.3.0",
3535
"@angular/router": "3.0.0-rc.1",
3636
"core-js": "^2.4.0",
3737
"hammerjs": "^2.0.8",
@@ -51,8 +51,8 @@
5151
"glob": "^6.0.4",
5252
"gulp": "^3.9.1",
5353
"gulp-clean": "^0.3.2",
54-
"gulp-live-server": "0.0.30",
5554
"gulp-sass": "^2.3.2",
55+
"gulp-server-livereload": "^1.8.2",
5656
"gulp-shell": "^0.5.2",
5757
"gulp-sourcemaps": "^1.6.0",
5858
"gulp-typescript": "^2.13.6",

scripts/serve-dist.js

Lines changed: 0 additions & 22 deletions
This file was deleted.

0 commit comments

Comments
 (0)