Skip to content

Commit

Permalink
unstyle and no-pro package options
Browse files Browse the repository at this point in the history
  • Loading branch information
jekuer committed Nov 3, 2023
1 parent a1cc939 commit 9f60e9f
Show file tree
Hide file tree
Showing 4 changed files with 152 additions and 42 deletions.
162 changes: 127 additions & 35 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,33 @@
const fs = require('fs');

function prepareFinalFile(content, stripAllImport = true, stripAllExport = true, transformToCommonJS = false) {
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
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 + '.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 (!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 + '.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
Expand Down Expand Up @@ -78,11 +80,11 @@ module.exports = function (grunt) {
src: ['demo/components/footer.vue'],
},
},
// cleans old built files
// clean old build files
clean: {
oldBuildFiles: ['dist/', 'assets/css/*.min.css', 'assets/css/*.min.css.map', 'demo_assets/css/*.min.css', 'demo_assets/css/*.min.css.map', 'demo_assets/js/*.js.css', 'demo_assets/js/*.min.js.map'],
},
// minifies the css file
// minify css files
cssmin: {
minify: {
files: [
Expand All @@ -103,10 +105,10 @@ module.exports = function (grunt) {
],
},
},
// generate the distributable JavaScript files (and also add a customized css file to the demo)
// generate the distributable JS files (and also add a customized css file to the demo)
concat: {
main: {
src: grunt.option('pro') ? ['node_modules/timezones-ical-library/dist/tzlib.js', ...jsCoreFilesToCombinePro] : ['node_modules/timezones-ical-library/dist/tzlib.js', ...jsCoreFilesToCombine],
src: ['node_modules/timezones-ical-library/dist/tzlib.js', ...jsCoreFilesToCombinePro],
dest: 'dist/atcb.js',
options: {
stripBanners: true,
Expand All @@ -115,26 +117,116 @@ module.exports = function (grunt) {
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: grunt.option('pro') ? jsCoreFilesToCombinePro : jsCoreFilesToCombine,
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: grunt.option('pro') ? 'export { atcb_action, i18nStrings, atcbCssTemplate as cssStyles, atcb_generate_ty };' : 'export { atcb_action, i18nStrings, atcbCssTemplate as cssStyles };',
footer: 'export { atcb_action, i18nStrings, atcbCssTemplate as cssStyles, atcb_generate_ty };',
process: (content) => prepareFinalFile(content),
},
},
module_no_pro: {
src: jsCoreFilesToCombine,
dest: 'dist/module/no-pro.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.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 };',
process: (content) => prepareFinalFile(content, true, true, false, true),
},
},
module_no_pro_unstyle: {
src: jsCoreFilesToCombine,
dest: 'dist/module/no-pro-unstyle.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, true, true, false, true),
},
},
commonJS: {
src: grunt.option('pro') ? jsCoreFilesToCombinePro : jsCoreFilesToCombine,
src: jsCoreFilesToCombinePro,
dest: 'dist/commonjs/index.js',
options: {
stripBanners: true,
banner: "// eslint-disable-next-line @typescript-eslint/no-var-requires\r\nconst tzlibActions = require('timezones-ical-library');\r\n",
footer: grunt.option('pro') ? 'module.exports = { atcb_action, i18nStrings, cssStyles: atcbCssTemplate, atcb_generate_ty };' : 'module.exports = { atcb_action, i18nStrings, cssStyles: atcbCssTemplate };',
footer: 'module.exports = { atcb_action, i18nStrings, cssStyles: atcbCssTemplate, atcb_generate_ty };',
process: (content) => prepareFinalFile(content, true, true, true),
},
},
commonJS_no_pro: {
src: jsCoreFilesToCombine,
dest: 'dist/commonjs/no-pro.js',
options: {
stripBanners: true,
banner: "// eslint-disable-next-line @typescript-eslint/no-var-requires\r\nconst tzlibActions = require('timezones-ical-library');\r\n",
footer: 'module.exports = { atcb_action, i18nStrings, cssStyles: atcbCssTemplate, atcb_generate_ty };',
process: (content) => prepareFinalFile(content, true, true, true),
},
},
commonJS_unstyle: {
src: jsCoreFilesToCombinePro,
dest: 'dist/commonjs/unstyle.js',
options: {
stripBanners: true,
banner: "// eslint-disable-next-line @typescript-eslint/no-var-requires\r\nconst tzlibActions = require('timezones-ical-library');\r\n",
footer: 'module.exports = { atcb_action, i18nStrings, cssStyles: atcbCssTemplate, atcb_generate_ty };',
process: (content) => prepareFinalFile(content, true, true, true, true),
},
},
commonJS_no_pro_unstyle: {
src: jsCoreFilesToCombine,
dest: 'dist/commonjs/no-pro-unstyle.js',
options: {
stripBanners: true,
banner: "// eslint-disable-next-line @typescript-eslint/no-var-requires\r\nconst tzlibActions = require('timezones-ical-library');\r\n",
footer: 'module.exports = { atcb_action, i18nStrings, cssStyles: atcbCssTemplate, atcb_generate_ty };',
process: (content) => prepareFinalFile(content, true, true, true, true),
},
},
cssDemo: {
src: ['assets/css/atcb.css'],
dest: 'demo/public/atcb.css',
Expand All @@ -143,7 +235,7 @@ module.exports = function (grunt) {
},
},
},
// creates files to support the dist structure
// create files to support the dist structure
'file-creator': {
'package.json ES Module': {
'dist/module/package.json': function (fs, fd, done) {
Expand All @@ -164,7 +256,7 @@ module.exports = function (grunt) {
},
},
},
// minifies the main js file
// minify the main js file
uglify: {
options: {
compress: true,
Expand All @@ -176,9 +268,9 @@ module.exports = function (grunt) {
comments: 'some',
},
},
newBuild: {
minify_main_js: {
files: {
'dist/atcb.js': ['dist/atcb.js'],
'dist/atcb.min.js': ['dist/atcb.js'], // only going for the main one here, as this gets copied and used in other projects, while the special builds are only delivered via CDN and minified there
},
},
},
Expand Down
6 changes: 4 additions & 2 deletions demo/pages/configuration.vue
Original file line number Diff line number Diff line change
Expand Up @@ -512,13 +512,15 @@ definePageMeta({
The iCal/ics file gets created dynamically.<br />
This has some drawbacks as it might be blocked in some rare cases.<br />
With this option, you can redirect to an existing ics file instead.<br /><br />
In the subscription case, you need to define the external calendar here.
In the subscription case, you need to define the external calendar here.<br /><br />
If you have multiple dates and an organizer or status set, you would need to prepare multiple ics files, where the one for the first date is specified here, while all subsequent dates look for a file with the same name and a number (starting with 2) appended (e.g. "event-2.ics").
</td>
<td v-else>
Die iCal/ics-Datei wir dynamisch generiert.<br />
Dies hat den Nachteil, dass der Prozess in seltenen Fällen vom Browser des Nutzers blockiert werden kann.<br />
Mit dieser Option kannst du stattdessen auf eine bestehende ics-Datei verweisen.<br /><br />
Im "subscribe"-Fall muss hier der externe Kalender referenziert werden.
Im "subscribe"-Fall muss hier der externe Kalender referenziert werden.<br /><br />
Falls du mehrere Termine und einen "organizer" oder "status" definiert hast, musst du mehrere ics-Dateien vorhalten. Die Datei für den ersten Termin wird hier referenziert, während alle weiteren Termine eine Datei mit dem gleichen Namen zzgl. einer fortlaufende Nummer (beginnend mit 2) benötigen (bspw. "event-2.ics").
</td>
</tr>
<tr id="icalfilename">
Expand Down
16 changes: 14 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"files": [
"dist",
"test",
"assets/css/*.css",
"index.d.ts",
".eslintrc.json",
"CHANGELOG.md",
Expand All @@ -20,6 +21,18 @@
".": {
"import": "./dist/module/index.js",
"require": "./dist/commonjs/index.js"
},
"./no-pro": {
"import": "./dist/module/no-pro.js",
"require": "./dist/commonjs/no-pro.js"
},
"./unstyle": {
"import": "./dist/module/unstyle.js",
"require": "./dist/commonjs/unstyle.js"
},
"./no-pro-unstyle": {
"import": "./dist/module/no-pro-unstyle.js",
"require": "./dist/commonjs/no-pro-unstyle.js"
}
},
"types": "index.d.ts",
Expand Down Expand Up @@ -72,8 +85,7 @@
"dev": "cd demo && npm run dev",
"build:all": "npm run build && npm run build:demo",
"build:demo": "cd demo && npm run generate",
"build": "npx grunt",
"build:pro": "npx grunt --pro=true"
"build": "npx grunt"
},
"dependencies": {
"timezones-ical-library": "^1.7.1"
Expand Down
10 changes: 7 additions & 3 deletions src/atcb-decorate.js
Original file line number Diff line number Diff line change
Expand Up @@ -397,12 +397,16 @@ function atcb_decorate_data_extend(data) {
} else {
data.dates[`${i}`].onlineEvent = false;
}
// for the uid, we do not copy from the top level, but rather generate it per event (except for the first one)
// for the uid, we do not simply copy from the top level, but iterate it to keep it unique
if (data.dates[`${i}`].uid == null) {
if (i == 0 && data.uid != null && data.uid != '') {
if (i === 0 && data.uid !== null && data.uid !== '') {
data.dates[0].uid = data.uid;
} else {
data.dates[`${i}`].uid = atcb_generate_uuid();
if (data.uid !== null && data.uid !== '') {
data.dates[`${i}`].uid = data.uid + '-' + (i + 1);
} else {
data.dates[`${i}`].uid = atcb_generate_uuid();
}
}
}
}
Expand Down

0 comments on commit 9f60e9f

Please sign in to comment.