forked from Catrobat/Catroweb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gruntfile.js
360 lines (345 loc) · 10.2 KB
/
Gruntfile.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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
// --------------------------------------------------------------------------------------------------
// JS & (S)CSS should always be placed in the assets directory.
// Grunt will tweak the code to our preferences and put it into the assets directory.
//
const ASSETS_DIRECTORY = 'assets'
const PUBLIC_DIRECTORY = 'public'
const TEMPLATE_DIRECTORY = 'templates'
// -------------------------------------------------------------------------------------------------
// Register all grunt tasks here:
//
module.exports = function (grunt) {
// enable plugins
grunt.loadNpmTasks('grunt-contrib-copy')
grunt.loadNpmTasks('grunt-contrib-concat')
grunt.loadNpmTasks('grunt-contrib-uglify-es')
grunt.loadNpmTasks('grunt-contrib-sass')
grunt.loadNpmTasks('grunt-contrib-watch')
grunt.loadNpmTasks('grunt-purgecss');
// define project configuration
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
copy: COPY_CONFIG,
concat: CONCAT_CONFIG,
uglify: UGLIFY_CONFIG,
sass: SASS_CONFIG,
watch: WATCH_CONFIG,
purgecss: PURGECSS_CONFIG
})
// define default tasks to run on `grunt`
grunt.registerTask('default', ['copy', 'concat', 'sass', 'uglify', 'purgecss'])
}
// -------------------------------------------------------------------------------------------------
// Copy task:
//
// - copies assets to the public directory
// - copies node modules to the public directory
//
const COPY_CONFIG =
{
bootstrap: {
expand: true,
cwd: 'node_modules/bootstrap/',
src: '**',
dest: PUBLIC_DIRECTORY + '/bootstrap/'
},
vis: { // @deprecated
// We need the whole dist folder because the css references multiple images
expand: true,
cwd: 'node_modules/vis/dist/',
src: '**',
dest: PUBLIC_DIRECTORY + '/vis/'
},
font_awesome: {
expand: true,
cwd: 'node_modules/@fortawesome/',
src: '**',
dest: PUBLIC_DIRECTORY + '/font_awesome_wrapper/'
},
font_awesome_webfonts: {
expand: true,
cwd: PUBLIC_DIRECTORY + '/font_awesome_wrapper/fontawesome-free/webfonts/',
src: '**',
dest: PUBLIC_DIRECTORY + '/webfonts/'
},
fonts: {
expand: true,
cwd: ASSETS_DIRECTORY + '/css/fonts',
src: '**',
dest: PUBLIC_DIRECTORY + '/css/fonts/'
},
materialIcons: {
expand: true,
cwd: 'node_modules/material-design-icons/iconfont',
src: '**',
dest: PUBLIC_DIRECTORY + '/css/fonts/'
},
material: {
expand: true,
cwd: 'node_modules/@material/',
src: '**',
dest: PUBLIC_DIRECTORY + '/@material/'
},
images: {
expand: true,
cwd: ASSETS_DIRECTORY + '/images',
src: '**',
dest: PUBLIC_DIRECTORY + '/images/'
},
favicon: {
// must be in root dir of public folder
expand: true,
cwd: ASSETS_DIRECTORY + '/images',
src: 'favicon.ico',
dest: PUBLIC_DIRECTORY
},
catBlocks: {
expand: true,
cwd: ASSETS_DIRECTORY + '/catblocks',
src: '**',
dest: PUBLIC_DIRECTORY + '/catblocks/'
},
custom: {
expand: true,
cwd: ASSETS_DIRECTORY + '/js/custom',
src: '**/*.js',
dest: PUBLIC_DIRECTORY + '/js/'
},
analytics: {
expand: true,
cwd: ASSETS_DIRECTORY + '/js/analytics',
src: '**/*.js',
dest: PUBLIC_DIRECTORY + '/js/'
},
clipboard_js: {
src: 'node_modules/clipboard/dist/clipboard.min.js',
dest: PUBLIC_DIRECTORY + '/js/modules/clipboard.min.js'
},
bootstrap_js: {
expand: true,
cwd: 'node_modules/bootstrap/dist/js',
src: '*',
dest: PUBLIC_DIRECTORY + '/js/modules/'
},
sweetalert_all: {
src: 'node_modules/sweetalert2/dist/sweetalert2.all.min.js',
dest: PUBLIC_DIRECTORY + '/js/modules/sweetalert2.all.min.js'
},
jquery: {
src: 'node_modules/jquery/dist/jquery.min.js',
dest: PUBLIC_DIRECTORY + '/js/modules/jquery.min.js'
},
textfill_js: {
src: 'node_modules/textfilljs/dist/textfill.min.js',
dest: PUBLIC_DIRECTORY + '/js/modules/textfill.min.js'
},
jquery_ui: {
src: 'node_modules/jquery-ui-dist/jquery-ui.min.js',
dest: PUBLIC_DIRECTORY + '/js/modules/jquery-ui.min.js'
},
jquery_contextmenu_js: {
src: 'node_modules/jquery-contextmenu/dist/jquery.contextMenu.min.js',
dest: PUBLIC_DIRECTORY + '/js/modules/jquery.contextMenu.min.js'
},
jquery_contextmenu_css: {
src: 'node_modules/jquery-contextmenu/dist/jquery.contextMenu.min.css',
dest: PUBLIC_DIRECTORY + '/css/modules/jquery.contextMenu.min.css'
},
jquery_ui_position: {
src: 'node_modules/jquery-contextmenu/dist/jquery.ui.position.min.js',
dest: PUBLIC_DIRECTORY + '/js/modules/jquery.ui.position.min.js'
},
animatedModal_js: {
src: 'node_modules/animatedmodal/animatedModal.min.js',
dest: PUBLIC_DIRECTORY + '/js/modules/animatedModal.min.js'
},
animate_css: {
src: 'node_modules/animate.css/animate.min.css',
dest: PUBLIC_DIRECTORY + '/css/modules/animate.min.css'
},
lazysizes: {
src: 'node_modules/lazysizes/lazysizes.min.js',
dest: PUBLIC_DIRECTORY + '/js/modules/lazysizes.min.js'
}
}
const PURGECSS_CONFIG = {
pocketcode: {
options: {
content: [TEMPLATE_DIRECTORY + '/**/*.html.twig', PUBLIC_DIRECTORY + '/js/**/*.min.js']
},
files: {
'public/css/pocketcode/base.css': ['public/css/pocketcode/base.css'],
}
},
arduino: {
options: {
content: [ TEMPLATE_DIRECTORY + '/**/*.html.twig', PUBLIC_DIRECTORY + '/js/**/*.min.js']
},
files: {
'public/css/arduino/base.css': ['public/css/arduino/base.css'],
}
},
school: {
options: {
content: [ TEMPLATE_DIRECTORY + '/**/*.html.twig', PUBLIC_DIRECTORY + '/js/**/*.min.js']
},
files: {
'public/css/create@school/base.css': ['public/css/create@school/base.css'],
}
},
embroidery: {
options: {
content: [ TEMPLATE_DIRECTORY + '/**/*.html.twig', PUBLIC_DIRECTORY + '/js/**/*.min.js']
},
files: {
'public/css/embroidery/base.css': ['public/css/embroidery/base.css'],
}
},
luna: {
options: {
content: [ TEMPLATE_DIRECTORY + '/**/*.html.twig', PUBLIC_DIRECTORY + '/js/**/*.min.js']
},
files: {
'public/css/luna/base.css': ['public/css/luna/base.css'],
}
},
phirocode: {
options: {
content: [ TEMPLATE_DIRECTORY + '/**/*.html.twig', PUBLIC_DIRECTORY + '/js/**/*.min.js']
},
files: {
'public/css/phirocode/base.css': ['public/css/phirocode/base.css'],
}
},
pocketalice: {
options: {
content: [ TEMPLATE_DIRECTORY + '/**/*.html.twig', PUBLIC_DIRECTORY + '/js/**/*.min.js']
},
files: {
'public/css/pocketalice/base.css': ['public/css/pocketalice/base.css'],
}
},
pocketgalaxy: {
options: {
content: [ TEMPLATE_DIRECTORY + '/**/*.html.twig', PUBLIC_DIRECTORY + '/js/**/*.min.js']
},
files: {
'public/css/pocketgalaxy/base.css': ['public/css/pocketgalaxy/base.css'],
}
}
}
// -------------------------------------------------------------------------------------------------
// Concat task:
//
// - multiple files are combined into one
//
const CONCAT_CONFIG =
{
base: {
src: ASSETS_DIRECTORY + '/js/base/*.js',
dest: PUBLIC_DIRECTORY + '/js/base.js'
}
}
// -------------------------------------------------------------------------------------------------
// SASS to CSS task:
//
// - loading all supported themes from the themes config
// - creating an entry for every theme
//
const SASS_CONFIG = {}
const THEMES = loadThemesFromSymfonyParameters()
THEMES.forEach(function (theme) {
addThemeConfig(SASS_CONFIG, theme)
})
function loadThemesFromSymfonyParameters () {
// Requiring all necessary Modules
const yaml = require('js-yaml')
const fs = require('fs')
// load the yaml file
try {
const themeConfig = yaml.load(
fs.readFileSync('config/packages/themes.yaml', 'utf8')
)
const flavors = themeConfig.parameters.flavors
if (!Array.isArray(flavors) || !flavors.length) {
console.error('Flavors array is empty!')
}
return flavors
} catch (e) {
console.error('Themes could not be loaded!\n' + e)
return undefined
}
}
function addThemeConfig (SASS_CONFIG, theme) {
// all css files should be available for every theme
const PUBLIC_CSS_BASE_FILE_PATH = PUBLIC_DIRECTORY + '/css/' + theme + '/base.css'
const THEME_CONFIG = {}
THEME_CONFIG[PUBLIC_CSS_BASE_FILE_PATH] = [ASSETS_DIRECTORY + '/css/themes/' + theme + '/' + theme + '.scss']
SASS_CONFIG[theme] =
{
options: {
loadPath: [ASSETS_DIRECTORY + '/css/base', ASSETS_DIRECTORY + '/css/themes/' + theme, 'node_modules'],
style: 'compressed',
sourceMap: true
},
files: [
THEME_CONFIG,
{
expand: true,
cwd: ASSETS_DIRECTORY + '/css/custom/',
src: ['**/*.scss'],
dest: PUBLIC_DIRECTORY + '/css/' + theme + '/',
ext: '.css',
extDot: 'first'
}
]
}
}
// -------------------------------------------------------------------------------------------------
// Uglify task:
//
// - minify JS files
//
const UGLIFY_CONFIG =
{
options: {
mangle: false
},
compiledFiles: {
files: [
{
expand: true,
src: [PUBLIC_DIRECTORY + '/js/**/*.js', '!' + PUBLIC_DIRECTORY + '/js/**/*.min.js'],
dest: PUBLIC_DIRECTORY + '/js',
rename: function (dst, src) {
return src.replace('.js', '.min.js')
}
}
]
}
}
// -------------------------------------------------------------------------------------------------
// Watch task:
//
// - detect changes to specified files and run the specified tasks on changes
//
const WATCH_CONFIG =
{
options: {
nospawn: true
},
styles: {
files: [ASSETS_DIRECTORY + '/css/**/*.scss'],
tasks: ['sass'],
options: {
nospawn: true
}
},
scripts: {
files: [ASSETS_DIRECTORY + '/js/**/*.js'],
tasks: ['copy:custom', 'copy:analytics', 'concat', 'uglify'],
options: {
nospawn: true
}
}
}