forked from shenglol/arm-visualizer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsystemjs.js
66 lines (60 loc) · 1.67 KB
/
systemjs.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
const gulp = require('gulp');
const replace = require('gulp-replace');
const Builder = require('jspm').Builder;
const inlineNg2Template = require('gulp-inline-ng2-template');
const del = require('del');
const conf = require('../conf/gulp.conf');
gulp.task('systemjs', gulp.series(replaceTemplates, systemjs));
gulp.task('systemjs:html', gulp.parallel(updateIndexHtml, copyVendor));
function systemjs(done) {
const builder = new Builder('./', 'jspm.config.js');
builder.config({
paths: {
"github:*": "jspm_packages/github/*",
"npm:*": "jspm_packages/npm/*"
},
packageConfigPaths: [
'npm:@*/*.json',
'npm:*.json',
'github:*/*.json'
]
});
builder.buildStatic(
'.tmp/templates/app/main.ts',
conf.path.tmp('index.js'),
{
production: true,
browser: true
}
).then(() => {
del(['.tmp/templates']);
done();
}, done);
}
function copyVendor() {
return gulp.src([
'node_modules/reflect-metadata/Reflect.js'
])
.pipe(gulp.dest(conf.path.dist('vendor')));
}
function replaceTemplates() {
return gulp.src(conf.path.src(`**/*.ts`))
.pipe(inlineNg2Template({base: conf.path.src('app'), useRelativePaths: true}))
.pipe(gulp.dest(conf.path.tmp('templates')));
}
function updateIndexHtml() {
return gulp.src(conf.path.src('index.html'))
.pipe(replace(
/src\//g,
``
))
.pipe(replace(
/<script src="jspm_packages\/system.js">[\s\S]*<\/script>/,
`<script src="index.js"></script>`
))
.pipe(replace(
/<!-- <script src="(node_modules)(\/([\s\S]*?))*"><\/script> -->/g,
`<script src="vendor$2"></script>`
))
.pipe(gulp.dest(conf.path.tmp()));
}