forked from IgniteUI/igniteui-angular
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
104 lines (92 loc) · 3.49 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
"use strict";
const autoprefixer = require("autoprefixer");
const gulp = require("gulp");
const sass = require("gulp-sass");
const sourcemaps = require("gulp-sourcemaps");
const postcss = require("gulp-postcss");
const inlineTemplates = require("gulp-inline-ng2-template");
const exec = require("child_process").exec;
const fs = require("fs");
const INLINE_TEMPLATES = {
SRC: "./src/**/*.ts",
DIST: "./tmp/src-inlined",
CONFIG: {
base: "/src",
target: "es6",
removeLineBreaks: true,
useRelativePaths: true
}
};
const STYLES = {
SRC: "./src/core/styles/themes/presets/*",
DIST: "./dist/styles",
MAPS: "./maps",
THEMING: {
SRC: "./src/core/styles/**/*",
DIST: "./dist/core/styles"
},
CONFIG: {
outputStyle: "compressed"
}
}
gulp.task("make-packagejson", () => {
fs.readFile("package.json", "utf8", (err, data) => {
if (err) throw err;
data = JSON.parse(data.trim());
let hammerjs = data.dependencies.hammerjs;
delete data.scripts;
data.dependencies["@types/hammerjs"] = data.devDependencies["@types/hammerjs"];
delete data.devDependencies;
data.peerDependencies = {
"@angular/animations": "" + data.dependencies["@angular/animations"] + "",
"@angular/common": "" + data.dependencies["@angular/common"] + "",
"@angular/compiler":"" + data.dependencies["@angular/compiler"] + "",
"@angular/core": "" + data.dependencies["@angular/core"] + "",
"@angular/forms":"" + data.dependencies["@angular/forms"] + "",
"@angular/platform-browser": "" + data.dependencies["@angular/platform-browser"] + "",
"@angular/platform-browser-dynamic": "" + data.dependencies["@angular/platform-browser-dynamic"] + "",
"rxjs": "" + data.dependencies["rxjs"] + "",
"web-animations-js": "^2.3.1"
}
delete data.dependencies["@angular/animations"];
delete data.dependencies["@angular/common"];
delete data.dependencies["@angular/compiler"];
delete data.dependencies["@angular/core"];
delete data.dependencies["@angular/forms"];
delete data.dependencies["@angular/platform-browser"];
delete data.dependencies["@angular/platform-browser-dynamic"];
delete data.dependencies["rxjs"];
fs.writeFile("dist/package.json", JSON.stringify(data, null, 4), "utf8", (err) => {
if (err) throw err;
});
});
});
gulp.task("build-style", () => {
const prefixer = postcss([autoprefixer({
browsers: ["last 5 versions", "> 3%"],
cascade: false,
grid: true
})]);
gulp.src(STYLES.THEMING.SRC)
.pipe(gulp.dest(STYLES.THEMING.DIST));
return gulp.src(STYLES.SRC)
.pipe(sourcemaps.init())
.pipe(sass.sync(STYLES.CONFIG).on('error', sass.logError))
.pipe(prefixer)
.pipe(sourcemaps.write(STYLES.MAPS))
.pipe(gulp.dest(STYLES.DIST));
});
gulp.task("inline-templates", () => {
return gulp.src(INLINE_TEMPLATES.SRC)
.pipe(inlineTemplates(INLINE_TEMPLATES.CONFIG))
.pipe(gulp.dest(INLINE_TEMPLATES.DIST));
});
gulp.task("build:esm", ["inline-templates"], (callback) => {
exec("npm run ngcompile && npm run build:styles", function (err, stdout, stderr) {
console.log(stdout, stderr);
callback(err);
});
});
gulp.task("build:esm:watch", ["build:esm"], () => {
gulp.watch("src/**/*", ["build:esm"]);
});