Skip to content

Commit cf2d031

Browse files
committed
chore(skeleton-typescript): sync with es2015 tasks
* browser-sync watch * normalized export
1 parent 58dc3dc commit cf2d031

File tree

3 files changed

+82
-32
lines changed

3 files changed

+82
-32
lines changed

skeleton-typescript/build/export.js

+31-14
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,34 @@
1+
// this file provides a list of unbundled files that
2+
// need to be included when exporting the application
3+
// for production.
14
module.exports = {
2-
"list": [
3-
"index.html",
4-
"config.js",
5-
"favicon.ico",
6-
"LICENSE",
7-
"jspm_packages/system.js",
8-
"jspm_packages/system-polyfills.js",
9-
"jspm_packages/system-csp-production.js",
10-
"styles/styles.css",
11-
"jspm_packages/npm/[email protected]/css/font-awesome.min.css",
12-
"jspm_packages/npm/[email protected]/fonts/*",
13-
"jspm_packages/github/github/[email protected]",
14-
"jspm_packages/github/github/[email protected]/fetch.js",
15-
"jspm_packages/github/twbs/[email protected]/fonts/*"
5+
'list': [
6+
'index.html',
7+
'config.js',
8+
'favicon.ico',
9+
'LICENSE',
10+
'jspm_packages/system.js',
11+
'jspm_packages/system-polyfills.js',
12+
'jspm_packages/system-csp-production.js',
13+
'styles/styles.css'
14+
],
15+
// this section lists any jspm packages that have
16+
// unbundled resources that need to be exported.
17+
// these files are in versioned folders and thus
18+
// must be 'normalized' by jspm to get the proper
19+
// path.
20+
'normalize': [
21+
[
22+
// include font-awesome.css and its fonts files
23+
'font-awesome', [
24+
'/css/font-awesome.min.css',
25+
'/fonts/*'
26+
]
27+
], [
28+
// include bootstrap's font files
29+
'bootstrap', [
30+
'/fonts/*'
31+
]
32+
]
1633
]
1734
};

skeleton-typescript/build/tasks/build.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ var sourcemaps = require('gulp-sourcemaps');
66
var paths = require('../paths');
77
var assign = Object.assign || require('object.assign');
88
var notify = require('gulp-notify');
9+
var browserSync = require('browser-sync');
910
var typescript = require('gulp-typescript');
1011

1112
// transpiles changed es6 files to SystemJS format
@@ -20,7 +21,8 @@ gulp.task('build-system', function() {
2021
});
2122
}
2223
return gulp.src(paths.dtsSrc.concat(paths.source))
23-
.pipe(plumber())
24+
.pipe(plumber({errorHandler: notify.onError('Error: <%= error.message %>')}))
25+
.pipe(changed(paths.output, {extension: '.ts'}))
2426
.pipe(sourcemaps.init({loadMaps: true}))
2527
.pipe(typescript(typescriptCompiler))
2628
.pipe(sourcemaps.write('.', {includeContent: false, sourceRoot: '/src'}))
@@ -38,7 +40,8 @@ gulp.task('build-html', function() {
3840
gulp.task('build-css', function() {
3941
return gulp.src(paths.css)
4042
.pipe(changed(paths.output, {extension: '.css'}))
41-
.pipe(gulp.dest(paths.output));
43+
.pipe(gulp.dest(paths.output))
44+
.pipe(browserSync.stream());
4245
});
4346

4447
// this task calls the clean task (located

skeleton-typescript/build/tasks/export-release.js

+46-16
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,18 @@
1-
var gulp = require('gulp');
2-
var runSequence = require('run-sequence');
3-
var del = require('del');
4-
var vinylPaths = require('vinyl-paths');
5-
var paths = require('../paths');
6-
var bundles = require('../bundles.js');
7-
var resources = require('../export.js');
1+
'use strict';
82

9-
// deletes all files in the output path
10-
gulp.task('clean-export', function() {
11-
return gulp.src([paths.exportSrv])
12-
.pipe(vinylPaths(del));
13-
});
3+
const gulp = require('gulp');
4+
const runSequence = require('run-sequence');
5+
const del = require('del');
6+
const vinylPaths = require('vinyl-paths');
7+
const jspm = require('jspm');
8+
const paths = require('../paths');
9+
const bundles = require('../bundles.js');
10+
const resources = require('../export.js');
1411

1512
function getBundles() {
16-
var bl = [];
17-
for (var b in bundles.bundles) {
18-
bl.push(b + '.js');
13+
let bl = [];
14+
for (let b in bundles.bundles) {
15+
bl.push(b + '*.js');
1916
}
2017
return bl;
2118
}
@@ -24,16 +21,49 @@ function getExportList() {
2421
return resources.list.concat(getBundles());
2522
}
2623

24+
function normalizeExportPaths() {
25+
const pathsToNormalize = resources.normalize;
26+
27+
let promises = pathsToNormalize.map(pathSet => {
28+
const packageName = pathSet[ 0 ];
29+
const fileList = pathSet[ 1 ];
30+
31+
return jspm.normalize(packageName).then((normalized) => {
32+
const packagePath = normalized.substring(normalized.indexOf('jspm_packages'), normalized.lastIndexOf('.js'));
33+
return fileList.map(file => packagePath + file);
34+
});
35+
});
36+
37+
return Promise.all(promises)
38+
.then((normalizedPaths) => {
39+
return normalizedPaths.reduce((prev, curr) => prev.concat(curr), []);
40+
});
41+
}
42+
43+
// deletes all files in the output path
44+
gulp.task('clean-export', function() {
45+
return gulp.src([ paths.exportSrv ])
46+
.pipe(vinylPaths(del));
47+
});
48+
2749
gulp.task('export-copy', function() {
28-
return gulp.src(getExportList(), {base: "."})
50+
return gulp.src(getExportList(), { base: '.' })
2951
.pipe(gulp.dest(paths.exportSrv));
3052
});
3153

54+
gulp.task('export-normalized-resources', function() {
55+
return normalizeExportPaths().then(normalizedPaths => {
56+
return gulp.src(normalizedPaths, { base: '.' })
57+
.pipe(gulp.dest(paths.exportSrv));
58+
});
59+
});
60+
3261
// use after prepare-release
3362
gulp.task('export', function(callback) {
3463
return runSequence(
3564
'bundle',
3665
'clean-export',
66+
'export-normalized-resources',
3767
'export-copy',
3868
callback
3969
);

0 commit comments

Comments
 (0)