From 9f60e9fcb677a9b88591b343fd144bab64249e2d Mon Sep 17 00:00:00 2001 From: Jens Kuerschner Date: Fri, 3 Nov 2023 17:29:50 +0100 Subject: [PATCH] unstyle and no-pro package options --- Gruntfile.js | 162 +++++++++++++++++++++++++++-------- demo/pages/configuration.vue | 6 +- package.json | 16 +++- src/atcb-decorate.js | 10 ++- 4 files changed, 152 insertions(+), 42 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index 90b90c14..d0dd2f78 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -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 @@ -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: [ @@ -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, @@ -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', @@ -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) { @@ -164,7 +256,7 @@ module.exports = function (grunt) { }, }, }, - // minifies the main js file + // minify the main js file uglify: { options: { compress: true, @@ -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 }, }, }, diff --git a/demo/pages/configuration.vue b/demo/pages/configuration.vue index 403fd717..410ddee1 100644 --- a/demo/pages/configuration.vue +++ b/demo/pages/configuration.vue @@ -512,13 +512,15 @@ definePageMeta({ The iCal/ics file gets created dynamically.
This has some drawbacks as it might be blocked in some rare cases.
With this option, you can redirect to an existing ics file instead.

- In the subscription case, you need to define the external calendar here. + In the subscription case, you need to define the external calendar here.

+ 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"). Die iCal/ics-Datei wir dynamisch generiert.
Dies hat den Nachteil, dass der Prozess in seltenen Fällen vom Browser des Nutzers blockiert werden kann.
Mit dieser Option kannst du stattdessen auf eine bestehende ics-Datei verweisen.

- Im "subscribe"-Fall muss hier der externe Kalender referenziert werden. + Im "subscribe"-Fall muss hier der externe Kalender referenziert werden.

+ 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"). diff --git a/package.json b/package.json index eff819cd..9738165f 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,7 @@ "files": [ "dist", "test", + "assets/css/*.css", "index.d.ts", ".eslintrc.json", "CHANGELOG.md", @@ -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", @@ -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" diff --git a/src/atcb-decorate.js b/src/atcb-decorate.js index 9951af39..4e50a0f7 100644 --- a/src/atcb-decorate.js +++ b/src/atcb-decorate.js @@ -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(); + } } } }