forked from shlomiassaf/ngx-modialog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
78 lines (64 loc) · 2.32 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
var gulp = require('gulp');
var inlineNg2Template = require('gulp-inline-ng2-template');
var transform = require('gulp-transform-js-ast');
var jsStringEscape = require('js-string-escape');
function doCss(ext, file) {
return jsStringEscape(file);
}
gulp.task('inline-resources', function () {
gulp.src('./dist/build/components/**/*.js')
.pipe(inlineNg2Template({base: './dist/build/', target: 'es5', styleProcessor: doCss}))
.pipe(gulp.dest('./dist/build/components/'));
gulp.src('./dist/build/demo/**/*.js')
.pipe(inlineNg2Template({base: './dist/build/', target: 'es5', styleProcessor: doCss}))
.pipe(gulp.dest('./dist/build/demo/'));
});
gulp.task('replace-core-relative-imports', function () {
var CORE_PACKAGE_NAME = 'angular2-modal';
var CORE_IMPORT_REGEX = /^(.*\.\.?\/components\/angular2-modal)(.*)$/;
function isRequireMethod(path) {
var node = path.value;
return node.type === 'CallExpression' &&
node.callee &&
node.callee.type === 'Identifier' &&
node.callee.name === 'require';
}
function isLiteral(path) {
var args = path.value.arguments;
return args &&
args.length === 1 &&
args[0].type === 'Literal';
}
function isCandidate(path) {
return isRequireMethod(path) && isLiteral(path);
}
function visitCallExpression(path) {
if (isCandidate(path)) {
var match,
arg = path.value.arguments["0"];
if ((match = CORE_IMPORT_REGEX.exec(arg.value)) !== null) {
arg.value = arg.value.replace(CORE_IMPORT_REGEX, `${CORE_PACKAGE_NAME}$2`);
}
}
return path.value;
}
gulp.src(['./dist/build/bootstrap.js'])
.pipe(transform({visitCallExpression: visitCallExpression}))
.pipe(gulp.dest('./dist/build'));
gulp.src(['./dist/build/demo/**/*.js'])
.pipe(transform({visitCallExpression: visitCallExpression}))
.pipe(gulp.dest('./dist/build/demo'));
gulp.src(['./dist/build/components/angular2-modal/plugins/**/*.js'])
.pipe(transform({visitCallExpression: visitCallExpression}))
.pipe(gulp.dest('./dist/build/components/angular2-modal/plugins'));
});
require('require-dir')('./gulp');
const runSequence = require('run-sequence');
gulp.task('build', (done) => {
runSequence(
['clean:dist', 'clean:tmp'],
['copyReleaseAssets', 'scripts', 'bundle'],
'createPackageJson',
done
);
});