-
Notifications
You must be signed in to change notification settings - Fork 17
/
gulpfile.js
201 lines (165 loc) · 6.38 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
const gulp = require("gulp");
const del = require("del");
const minHTML = require("gulp-htmlmin");
const minifyCSS = require("gulp-csso");
const concat = require("gulp-concat");
const htmlReplace = require("gulp-html-replace");
const uglifyes = require("uglify-es");
const composer = require("gulp-uglify/composer");
const uglify = composer(uglifyes, console);
const imagemin = require("gulp-imagemin");
const babel = require('gulp-babel');
const destinationFolder = releaseFolder();
function releaseFolder() {
var arr = __dirname.split("/");
var fldr = arr.pop();
arr.push(fldr + "_release");
return arr.join("/");
}
console.log(">> Building to ", destinationFolder);
const cssTasks = [
{ name: "widgetCSS", src: "widget/**/*.css", dest: "/widget/assets/css" },
{ name: "controlContentCSS", src: "control/content/**/**/*.css", dest: "/control/content" },
{ name: "controlDesignCSS", src: "control/design/**/**/*.css", dest: "/control/design" },
{ name: "controlSettingsCSS", src: "control/settings/**/**/*.css", dest: "/control/settings" },
{ name: "controlLanguagesCSS", src: "control/languages/**/**/*.css", dest: "/control/languages" },
];
cssTasks.forEach(function (task) {
/*
Define a task called 'css' the recursively loops through
the widget and control folders, processes each CSS file and puts
a processes copy in the 'build' folder
note if the order matters you can import each css separately in the array
*/
gulp.task(task.name, function () {
return (
gulp
.src(task.src, { base: "." })
/// minify the CSS contents
.pipe(minifyCSS())
///merge
.pipe(concat("styles.min.css"))
/// write result to the 'build' folder
.pipe(gulp.dest(destinationFolder + task.dest))
);
});
});
const cfTasks = [
{name: "CommunityFeedJS1",src:["widget/CommunityFeedAPI/**/*.js"],dest: "/widget/CommunityFeed"},
]
cfTasks.forEach(function (task){
gulp.task(task.name, function(){
return(
gulp
.src(task.src, {base: "."})
.pipe(babel({
presets: ['@babel/env']
}))
.pipe(uglify())
.pipe(concat("cfScripts.min.js"))
.pipe(gulp.dest(destinationFolder+task.dest))
);
})
})
const jsTasks = [
{ name: "widgetJS", src: ["widget/**/**/**/*.js","!widget/CommunityFeedAPI/data/*.js","!widget/CommunityFeedAPI/dataAccess/*.js"], dest: "/widget" },
{ name: "controlContentJS", src: "control/content/**/**/**/*.js", dest: "/control/content" },
{ name: "controlDesignJS", src: "control/design/**/**/*.js", dest: "/control/design" },
{ name: "controlSettingsJS", src: "control/settings/**/**/*.js", dest: "/control/settings"},
{ name: "controlLanguagesJS", src: "control/languages/**/**/*.js", dest: "/control/languages" }
];
jsTasks.forEach(function (task) {
gulp.task(task.name, function () {
return (
gulp
.src(task.src, { base: "." })
/// obfuscate and minify the JS files
.pipe(uglify())
/// merge all the JS files together. If the
/// order matters you can pass each file to the function
/// in an array in the order you like
.pipe(concat("scripts.min.js"))
///output here
.pipe(gulp.dest(destinationFolder + task.dest))
);
});
});
gulp.task("sharedJS", function () {
return gulp
.src(["widget/assets/js/shared/**.js"], { base: "." })
.pipe(uglify())
.pipe(concat("scripts.shared-min.js"))
.pipe(gulp.dest(destinationFolder + "/widget"));
});
gulp.task("clean", function () {
return del([destinationFolder], { force: true });
});
gulp.task("controlHtml", function () {
return (
gulp
.src(["control/**/*.html", "control/**/*.htm"], { base: "." })
/// replace all the <!-- build:bundleJSFiles --> comment bodies
/// with scripts.min.js with cache buster
.pipe(
htmlReplace({
bundleJSFiles: "scripts.min.js?v=" + new Date().getTime(),
bundleCSSFiles: "styles.min.css?v=" + new Date().getTime(),
bundleCFFiles: "../../widget/CommunityFeed/cfScripts.min.js?v=" + new Date().getTime(),
bundleSharedJSFiles: "../../widget/scripts.shared-min.js?v=" + new Date().getTime(),
bundleLibFiles: "./assets/js/ladda/ladda.min.js?v=" + new Date().getTime(),
})
)
/// then strip the html from any comments
.pipe(minHTML({ removeComments: true, collapseWhitespace: true }))
/// write results to the 'build' folder
.pipe(gulp.dest(destinationFolder))
);
});
gulp.task("widgetHtml", function () {
return (
gulp
.src(["widget/**/*.html", "widget/**/*.htm"], { base: "." })
/// replace all the <!-- build:bundleJSFiles --> comment bodies
/// with scripts.min.js with cache buster
.pipe(
htmlReplace({
bundleCFFiles: "./CommunityFeed/cfScripts.min.js?v=" + new Date().getTime(),
bundleJSFiles: "scripts.min.js?v=" + new Date().getTime(),
bundleSharedJSFiles: "scripts.shared-min.js?v=" + new Date().getTime(),
bundleCSSFiles: "./assets/css/styles.min.css?v=" + new Date().getTime(),
})
)
/// then strip the html from any comments
.pipe(minHTML({ removeComments: true, collapseWhitespace: true }))
/// write results to the 'build' folder
.pipe(gulp.dest(destinationFolder))
);
});
gulp.task("resources", function () {
return gulp.src(["resources/*", "plugin.json"], { base: "." }).pipe(gulp.dest(destinationFolder));
});
gulp.task("images", function () {
console.log(destinationFolder)
return gulp.src(["widget/assets/img/*"], { base: "." }).pipe(imagemin()).pipe(gulp.dest(destinationFolder));
});
gulp.task("lib", function () {
return gulp
.src([
"control/content/assets/js/ladda/spin.min.js",
"control/content/assets/js/ladda/ladda.min.js",
"control/content/assets/js/ladda/angular-ladda.min.js"
], { base: "." })
.pipe(concat("ladda.min.js"))
.pipe(gulp.dest(destinationFolder + "/control/content/assets/js/ladda"));
});
var buildTasksToRun = ["widgetHtml", "controlHtml", "resources", "images", "sharedJS" ,"lib"];
cssTasks.forEach(function (task) {
buildTasksToRun.push(task.name);
});
cfTasks.forEach(function (task) {
buildTasksToRun.push(task.name);
});
jsTasks.forEach(function (task) {
buildTasksToRun.push(task.name);
});
gulp.task("build", gulp.series("clean", buildTasksToRun));