-
-
Notifications
You must be signed in to change notification settings - Fork 114
/
Gruntfile.js
294 lines (289 loc) · 11.5 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
const fs = require('fs');
function prepareFinalFile(content, stripAllImport = true, stripAllExport = true, transformToCommonJS = false, skipStyles = false) {
// remove TimeZones iCal Library version output (do not do this, if your are using the time zone library standalone!)
content = content.replace(/^console\.log\('Add to Calendar TimeZones iCal Library loaded \(version ' \+ tzlibVersion \+ '\)'\);$/m, '');
// add style inline
if (!skipStyles) {
const styleRegex = /const\satcbCssTemplate\s=\s\{\};/;
if (styleRegex.test(content)) {
const availableStyles = ['default', '3d', 'flat', 'round', 'neumorphism', 'text', 'date'];
let inlineStyleOutput = 'const atcbCssTemplate = {';
availableStyles.forEach((style) => {
const styleString = (function () {
if (style != 'default') {
return '-' + style;
}
return '';
})();
// determining the input data. Mind that we remove any multiple "." as well as backslashs for security reasons - should not be used anyway
const cssFileContent = fs
.readFileSync('./assets/css/atcb' + styleString.replace(/[^a-z0-9-]/gi, '') + '.min.css')
.toString()
.replace(/\.{2,}/g, '')
.replace(/\\/g, '')
.replace(/"/g, '\\"');
inlineStyleOutput += '\r\n"' + style + '": "' + cssFileContent + '",';
});
inlineStyleOutput += '\r\n};\r\n';
content = content.replace(styleRegex, inlineStyleOutput);
}
}
if (stripAllImport) {
// remove all import statements
content = content.replace(/^import[\w\s{}\+-_,'"`\/\\.]*';/gim, '');
// remove regular comments
content = content.replace(/(^|(?<=;\s))\s*\/\/(?!\seslint).*$/gm, '');
// remove empty lines
content = content.replace(/^\s*$(?:\r\n?|\n)/gm, '');
}
if (stripAllExport) {
// remove all export statements
content = content.replace(/^export {[\w\s-_,]*};/gim, '');
}
if (transformToCommonJS) {
content = content
.replace(/tzlib_get_offset/gm, 'tzlibActions.tzlib_get_offset')
.replace(/tzlib_get_ical_block/gm, 'tzlibActions.tzlib_get_ical_block')
.replace(/tzlib_get_timezones/gm, 'tzlibActions.tzlib_get_timezones');
}
return content;
}
const jsCoreFilesToCombine = ['src/atcb-globals.js', 'src/atcb-decorate.js', 'src/atcb-validate.js', 'src/atcb-control.js', 'src/atcb-generate.js', 'src/atcb-generate-rich-data.js', 'src/atcb-links.js', 'src/atcb-util.js', 'src/atcb-event.js', 'src/atcb-i18n.js', 'src/atcb-init.js'];
const jsCoreFilesToCombinePro = [
'src/atcb-globals.js',
'src/atcb-decorate.js',
'src/atcb-validate.js',
'src/atcb-control.js',
'src/atcb-generate-pro.js',
'src/atcb-generate.js',
'src/atcb-generate-rich-data.js',
'src/atcb-links.js',
'src/atcb-util.js',
'src/atcb-event.js',
'src/atcb-i18n.js',
'src/atcb-init.js',
];
// The config.
module.exports = function (grunt) {
grunt.initConfig({
// update version. Either use via `npm run release -- patch` (default), `npm run release -- minor`, `npm run release -- major`, or `npm run release -- x.x.x` (with x.x.x being the exact version number)
version: {
package: {
src: ['package.json'],
},
js: {
options: {
prefix: 'Version(.=..|:.)',
},
src: ['src/*.js'],
},
css: {
options: {
prefix: 'Version:.',
},
src: ['assets/css/*.css'],
},
demo: {
options: {
prefix: 'Version:.',
},
src: ['demo/components/footer.vue'],
},
},
// clean old build files
clean: {
oldBuildFiles: ['dist/', 'assets/css/*.min.css', 'assets/css/*.min.css.map'],
},
// minify css files
cssmin: {
minify: {
files: [
{
expand: true,
cwd: 'assets/css',
src: ['*.css', '!*.min.css'],
dest: 'assets/css',
ext: '.min.css',
},
],
},
},
// generate the distributable JS files (and also add a customized css file to the demo)
concat: {
main: {
src: ['node_modules/timezones-ical-library/dist/tzlib.js', ...jsCoreFilesToCombinePro],
dest: 'dist/atcb.js',
options: {
stripBanners: true,
banner: '( function(atcbGlobal) { atcbGlobal.atcb_action = function (data, triggerElement, keyboardTrigger = false) {return atcb_action(data, triggerElement, keyboardTrigger);}',
footer: ' } )(window);',
process: (content) => prepareFinalFile(content),
},
},
main_no_pro: {
src: ['node_modules/timezones-ical-library/dist/tzlib.js', ...jsCoreFilesToCombine],
dest: 'dist/atcb-no-pro.js',
options: {
stripBanners: true,
banner: '( function(atcbGlobal) { atcbGlobal.atcb_action = function (data, triggerElement, keyboardTrigger = false) {return atcb_action(data, triggerElement, keyboardTrigger);}',
footer: ' } )(window);',
process: (content) => prepareFinalFile(content),
},
},
main_unstyle: {
src: ['node_modules/timezones-ical-library/dist/tzlib.js', ...jsCoreFilesToCombinePro],
dest: 'dist/atcb-unstyle.js',
options: {
stripBanners: true,
banner: '( function(atcbGlobal) { atcbGlobal.atcb_action = function (data, triggerElement, keyboardTrigger = false) {return atcb_action(data, triggerElement, keyboardTrigger);}',
footer: ' } )(window);',
process: (content) => prepareFinalFile(content, true, true, false, true),
},
},
main_no_pro_unstyle: {
src: ['node_modules/timezones-ical-library/dist/tzlib.js', ...jsCoreFilesToCombine],
dest: 'dist/atcb-no-pro-unstyle.js',
options: {
stripBanners: true,
banner: '( function(atcbGlobal) { atcbGlobal.atcb_action = function (data, triggerElement, keyboardTrigger = false) {return atcb_action(data, triggerElement, keyboardTrigger);}',
footer: ' } )(window);',
process: (content) => prepareFinalFile(content, true, true, false, true),
},
},
module: {
src: jsCoreFilesToCombinePro,
dest: 'dist/module/index.js',
options: {
stripBanners: true,
banner: "import { tzlib_get_ical_block, tzlib_get_offset, tzlib_get_timezones } from 'timezones-ical-library';\r\n",
footer: 'export { atcb_action, i18nStrings, atcbCssTemplate as cssStyles, atcb_generate_ty, atcb_generate_timestring };',
process: (content) => prepareFinalFile(content),
},
},
module_no_pro: {
src: jsCoreFilesToCombine,
dest: 'dist/module/no-pro/index.js',
options: {
stripBanners: true,
banner: "import { tzlib_get_ical_block, tzlib_get_offset, tzlib_get_timezones } from 'timezones-ical-library';\r\n",
footer: 'export { atcb_action, i18nStrings, atcbCssTemplate as cssStyles };',
process: (content) => prepareFinalFile(content),
},
},
module_unstyle: {
src: jsCoreFilesToCombinePro,
dest: 'dist/module/unstyle/index.js',
options: {
stripBanners: true,
banner: "import { tzlib_get_ical_block, tzlib_get_offset, tzlib_get_timezones } from 'timezones-ical-library';\r\n",
footer: 'export { atcb_action, i18nStrings, atcb_generate_ty, atcb_generate_timestring };',
process: (content) => prepareFinalFile(content, true, true, false, true),
},
},
module_no_pro_unstyle: {
src: jsCoreFilesToCombine,
dest: 'dist/module/no-pro-unstyle/index.js',
options: {
stripBanners: true,
banner: "import { tzlib_get_ical_block, tzlib_get_offset, tzlib_get_timezones } from 'timezones-ical-library';\r\n",
footer: 'export { atcb_action, i18nStrings };',
process: (content) => prepareFinalFile(content, true, true, false, true),
},
},
commonJS: {
src: jsCoreFilesToCombinePro,
dest: 'dist/commonjs/index.js',
options: {
stripBanners: true,
banner: "const tzlibActions = require('timezones-ical-library');\r\n",
footer: 'module.exports = { atcb_action, i18nStrings, cssStyles: atcbCssTemplate, atcb_generate_ty, atcb_generate_timestring };',
process: (content) => prepareFinalFile(content, true, true, true),
},
},
commonJS_no_pro: {
src: jsCoreFilesToCombine,
dest: 'dist/commonjs/no-pro/index.js',
options: {
stripBanners: true,
banner: "const tzlibActions = require('timezones-ical-library');\r\n",
footer: 'module.exports = { atcb_action, i18nStrings, cssStyles: atcbCssTemplate };',
process: (content) => prepareFinalFile(content, true, true, true),
},
},
commonJS_unstyle: {
src: jsCoreFilesToCombinePro,
dest: 'dist/commonjs/unstyle/index.js',
options: {
stripBanners: true,
banner: "const tzlibActions = require('timezones-ical-library');\r\n",
footer: 'module.exports = { atcb_action, i18nStrings, atcb_generate_ty, atcb_generate_timestring };',
process: (content) => prepareFinalFile(content, true, true, true, true),
},
},
commonJS_no_pro_unstyle: {
src: jsCoreFilesToCombine,
dest: 'dist/commonjs/no-pro-unstyle/index.js',
options: {
stripBanners: true,
banner: "const tzlibActions = require('timezones-ical-library');\r\n",
footer: 'module.exports = { atcb_action, i18nStrings };',
process: (content) => prepareFinalFile(content, true, true, true, true),
},
},
cssDemo: {
src: ['assets/css/atcb.css'],
dest: 'demo/public/atcb.css',
options: {
footer: ':host { --btn-background: #ffa255; }:host(.atcb-dark), :host-context(html.atcb-dark):host(.atcb-bodyScheme), :host-context(body.atcb-dark):host(.atcb-bodyScheme) { --btn-background: #000; }',
},
},
},
// create files to support the dist structure
'file-creator': {
'package.json ES Module': {
'dist/module/package.json': function (fs, fd, done) {
fs.writeSync(fd, '{ "type": "module" }');
done();
},
},
'package.json commonJS': {
'dist/commonjs/package.json': function (fs, fd, done) {
fs.writeSync(fd, '{ "type": "commonjs" }');
done();
},
},
},
// minify js files
uglify: {
options: {
compress: false,
mangle: true,
beautify: false,
sourceMap: false,
output: {
comments: 'some',
},
},
minify_main_js: {
files: {
'dist/atcb.min.js': ['dist/atcb.js'], // only going for the main and unstyle ones here, as those get copied and used in other projects, while others are only delivered via CDN and minified there
},
},
minify_unstyle_js: {
files: {
'dist/atcb-unstyle.min.js': ['dist/atcb-unstyle.js'],
},
},
},
});
// Load the plugins.
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-cssmin');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-file-creator');
grunt.loadNpmTasks('grunt-version');
// Register task(s).
grunt.registerTask('default', ['clean', 'cssmin', 'concat', 'file-creator']);
grunt.registerTask('uglifyMain', ['clean', 'cssmin', 'concat', 'file-creator', 'uglify']);
};