|
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'); |
8 |
| - |
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 |
| -}); |
| 1 | +const gulp = require('gulp'); |
| 2 | +const runSequence = require('run-sequence'); |
| 3 | +const del = require('del'); |
| 4 | +const vinylPaths = require('vinyl-paths'); |
| 5 | +const jspm = require('jspm'); |
| 6 | +const paths = require('../paths'); |
| 7 | +const bundles = require('../bundles.js'); |
| 8 | +const resources = require('../export.js'); |
14 | 9 |
|
15 | 10 | function getBundles() {
|
16 |
| - var bl = []; |
17 |
| - for (var b in bundles.bundles) { |
18 |
| - bl.push(paths.exportSourceRoot + b + '.js'); |
| 11 | + let bl = []; |
| 12 | + for (let b in bundles.bundles) { |
| 13 | + bl.push(paths.exportSourceRoot + b + '*.js'); |
19 | 14 | }
|
20 | 15 | return bl;
|
21 | 16 | }
|
22 | 17 |
|
23 | 18 | function getExportList() {
|
24 |
| - return resources.list.map(function(item) { |
25 |
| - return paths.exportSourceRoot + item; |
26 |
| - }).concat(getBundles()); |
| 19 | + return resources.list.map(function (item) { |
| 20 | + return paths.exportSourceRoot + item; |
| 21 | + }).concat(getBundles()); |
| 22 | +} |
| 23 | + |
| 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 => paths.exportSourceRoot + packagePath + file); |
| 34 | + }); |
| 35 | + }); |
| 36 | + |
| 37 | + return Promise.all(promises) |
| 38 | + .then((normalizedPaths) => { |
| 39 | + return normalizedPaths.reduce((prev, curr) => prev.concat(curr), []); |
| 40 | + }); |
27 | 41 | }
|
28 | 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 | + |
29 | 49 | gulp.task('export-copy', function() {
|
30 |
| - return gulp.src(getExportList(), {base: "."}) |
| 50 | + return gulp.src(getExportList(), { base: '.' }) |
31 | 51 | .pipe(gulp.dest(paths.exportSrv));
|
32 | 52 | });
|
33 | 53 |
|
| 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 | + |
34 | 61 | // use after prepare-release
|
35 | 62 | gulp.task('export', function(callback) {
|
36 | 63 | return runSequence(
|
37 | 64 | 'bundle',
|
38 | 65 | 'clean-export',
|
| 66 | + 'export-normalized-resources', |
39 | 67 | 'export-copy',
|
40 | 68 | callback
|
41 | 69 | );
|
42 | 70 | });
|
| 71 | + |
0 commit comments