From 7404397529d83f00fc2a8f983e9b2fd7232da622 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Kr=C3=B6g?= Date: Mon, 8 Aug 2022 22:13:48 +0200 Subject: [PATCH 1/2] Improve example-builder code Reduce amount of async calls and some other small changes --- examples/templates/example.html | 4 +- examples/webpack/example-builder.js | 79 +++++++++++++---------------- 2 files changed, 37 insertions(+), 46 deletions(-) diff --git a/examples/templates/example.html b/examples/templates/example.html index 5a0493d975..6e894f0ec7 100644 --- a/examples/templates/example.html +++ b/examples/templates/example.html @@ -170,7 +170,9 @@ - {{{ js.tag }}} +{{#each js.scripts}} + +{{/each}} `, @@ -339,7 +329,7 @@ export default class ExampleBuilder { ); } - const pkg = await getPackageInfo(); + data.olVersion = pkg.version; data.pkgJson = JSON.stringify( { name: data.name, @@ -376,7 +366,6 @@ export default class ExampleBuilder { // add additional resources if (data.resources) { - const pkg = await getPackageInfo(); const localResources = []; const remoteResources = []; data.resources.forEach((resource) => { From 2c9cf00126dae2938eeb411d525959ca2ae13975 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Kr=C3=B6g?= Date: Mon, 8 Aug 2022 22:17:17 +0200 Subject: [PATCH 2/2] Fix source formatting for some examples For some css or html files a missing new line at end of file will concatenate the last line with the following style or script tag --- examples/webpack/example-builder.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/examples/webpack/example-builder.js b/examples/webpack/example-builder.js index 4494f8d1aa..e2172a005d 100644 --- a/examples/webpack/example-builder.js +++ b/examples/webpack/example-builder.js @@ -262,6 +262,13 @@ export default class ExampleBuilder { }); } + ensureNewLineAtEnd(source) { + if (source[source.length - 1] !== '\n') { + source += '\n'; + } + return source; + } + transformJsSource(source) { return ( source @@ -298,8 +305,7 @@ export default class ExampleBuilder { let jsSource = await fse.readFile(jsPath, {encoding: 'utf8'}); jsSource = this.transformJsSource(this.cloakSource(jsSource, data.cloak)); data.js = { - tag: ` - `, + scripts: [`${this.common}.js`, jsName], source: jsSource, }; @@ -359,7 +365,7 @@ export default class ExampleBuilder { if (cssSource) { data.css = { tag: ``, - source: cssSource, + source: this.ensureNewLineAtEnd(cssSource), }; assets[cssName] = cssSource; }