From 07aebfaf318f34fec2f934041c577b1ee8093f24 Mon Sep 17 00:00:00 2001 From: Vladislav Tasev Date: Mon, 27 Jul 2020 14:41:54 +0300 Subject: [PATCH] fix(tools): Building third-party packages no longer fails (#1994) --- packages/theme-base/package-scripts.js | 2 +- packages/tools/components-package/nps.js | 2 +- .../tools/lib/generate-json-imports/themes.js | 19 ++++++++++++++----- packages/tools/lib/init-package/index.js | 4 ++-- .../sap_fiori_3_hcb/parameters-bundle.css | 3 +++ .../sap_fiori_3_hcw/parameters-bundle.css | 3 +++ 6 files changed, 24 insertions(+), 9 deletions(-) create mode 100644 packages/tools/lib/init-package/resources/src/themes/sap_fiori_3_hcb/parameters-bundle.css create mode 100644 packages/tools/lib/init-package/resources/src/themes/sap_fiori_3_hcw/parameters-bundle.css diff --git a/packages/theme-base/package-scripts.js b/packages/theme-base/package-scripts.js index a8ba63810090..03a78d71d46c 100644 --- a/packages/theme-base/package-scripts.js +++ b/packages/theme-base/package-scripts.js @@ -27,7 +27,7 @@ module.exports = { ...buildThemesCommands }, postcss: "postcss dist/**/parameters-bundle.css --config config/postcss.themes --base dist/ --dir dist/css/", - jsonImports: `node "${jsonImportsScript}" dist/generated/json-imports`, + jsonImports: `node "${jsonImportsScript}" dist/generated/assets/themes dist/generated/json-imports`, }, generateReport: `node "${generateReportScript}"`, }, diff --git a/packages/tools/components-package/nps.js b/packages/tools/components-package/nps.js index 22bcee62922a..2e145269a1e0 100644 --- a/packages/tools/components-package/nps.js +++ b/packages/tools/components-package/nps.js @@ -28,7 +28,7 @@ const getScripts = (options) => { }, jsonImports: { default: "mkdirp dist/generated/json-imports && nps build.jsonImports.themes build.jsonImports.i18n", - themes: `node "${LIB}/generate-json-imports/themes.js" dist/generated/json-imports`, + themes: `node "${LIB}/generate-json-imports/themes.js" dist/generated/assets/themes dist/generated/json-imports`, i18n: `node "${LIB}/generate-json-imports/i18n.js" dist/generated/assets/i18n dist/generated/json-imports`, }, bundle: "rollup --config config/rollup.config.js --environment ES5_BUILD", diff --git a/packages/tools/lib/generate-json-imports/themes.js b/packages/tools/lib/generate-json-imports/themes.js index 14f4f527b1b3..0d8577d705c4 100644 --- a/packages/tools/lib/generate-json-imports/themes.js +++ b/packages/tools/lib/generate-json-imports/themes.js @@ -3,15 +3,24 @@ const path = require('path'); const mkdirp = require("mkdirp"); const assets = require("../../assets-meta.js"); -const outputFile = path.normalize(`${process.argv[2]}/Themes.js`); +const inputFolder = path.normalize(process.argv[2]); +const outputFile = path.normalize(`${process.argv[3]}/Themes.js`); +// All supported optional themes const optionalThemes = assets.themes.all.filter(theme => theme !== assets.themes.default); +// All themes present in the file system +const dirs = fs.readdirSync(inputFolder); +const themesOnFileSystem = dirs.map(dir => { + const matches = dir.match(/sap_.*$/); + return matches ? dir : undefined; +}).filter(key => !!key && optionalThemes.includes(key)); + const packageName = JSON.parse(fs.readFileSync("package.json")).name; -const importLines = optionalThemes.map(theme => `import ${theme} from "../assets/themes/${theme}/parameters-bundle.css.json";`).join("\n"); -const isInlinedCondition = optionalThemes.map(theme => `isInlined(${theme})`).join(" || "); -const registerLines = optionalThemes.map(theme => `registerThemeProperties("${packageName}", "${theme}", ${theme});`).join("\n"); +const importLines = themesOnFileSystem.map(theme => `import ${theme} from "../assets/themes/${theme}/parameters-bundle.css.json";`).join("\n"); +const isInlinedCondition = themesOnFileSystem.map(theme => `isInlined(${theme})`).join(" || "); +const registerLines = themesOnFileSystem.map(theme => `registerThemeProperties("${packageName}", "${theme}", ${theme});`).join("\n"); // Resulting file content const content = `import { registerThemeProperties } from "@ui5/webcomponents-base/dist/asset-registries/Themes.js"; @@ -26,7 +35,7 @@ See rollup-plugin-url or webpack file-loader for more information. Suggested pattern: "assets\\\\\\/.*\\\\\\.json"\`); } -${registerLines}; +${registerLines} `; mkdirp.sync(path.dirname(outputFile)); diff --git a/packages/tools/lib/init-package/index.js b/packages/tools/lib/init-package/index.js index 4d294cc9718b..377e8292f341 100644 --- a/packages/tools/lib/init-package/index.js +++ b/packages/tools/lib/init-package/index.js @@ -38,8 +38,8 @@ try { // Ensure correct tag const tag = options.tag || DEFAULT_TAG; -if (!tag.match(/^ui5-/)) { - console.log("tag name should start with ui5-"); +if (!tag.includes("-")) { + console.log("tag name should contain at least one dash"); process.exit(1); } const className = capitalizeFirst(kebabToCamelCase(tag.substr(4))); diff --git a/packages/tools/lib/init-package/resources/src/themes/sap_fiori_3_hcb/parameters-bundle.css b/packages/tools/lib/init-package/resources/src/themes/sap_fiori_3_hcb/parameters-bundle.css new file mode 100644 index 000000000000..aaeb206965f6 --- /dev/null +++ b/packages/tools/lib/init-package/resources/src/themes/sap_fiori_3_hcb/parameters-bundle.css @@ -0,0 +1,3 @@ +:root { + --ui5-demo-border-color: lightblue; +} diff --git a/packages/tools/lib/init-package/resources/src/themes/sap_fiori_3_hcw/parameters-bundle.css b/packages/tools/lib/init-package/resources/src/themes/sap_fiori_3_hcw/parameters-bundle.css new file mode 100644 index 000000000000..01eafe87bfe1 --- /dev/null +++ b/packages/tools/lib/init-package/resources/src/themes/sap_fiori_3_hcw/parameters-bundle.css @@ -0,0 +1,3 @@ +:root { + --ui5-demo-border-color: gray; +}