@openeuropa/bcl-builder 0.28.0 → 0.313.202403151055

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -40,3 +40,78 @@ commands which all supports multiple operations as items in an array.
40
40
  #### Sprite
41
41
 
42
42
  `sprite: [ { entry: (string), dest: (string), options: (object) { file: (string) (defaut: bcl-icons.svg), list: (array of file names) (optional), }, }, ],`
43
+
44
+ ---
45
+
46
+ #### Color Scheme
47
+
48
+ ```javascript
49
+ color-scheme: [
50
+ {
51
+ entry (ex: ../path/to/your-colour-scheme.scss),
52
+ dest (ex: ../path/to/compiled.css),
53
+ options (object with plugins for postcss) {
54
+ minify (includes css nano for minification)
55
+ }
56
+ },
57
+ ],
58
+
59
+ * Example config object: {
60
+ color-scheme: [
61
+ {
62
+ entry: [path.resolve(nodeModules, "color-scheme.scss")],
63
+ dest: path.resolve(outputFolder, "css"),
64
+ options: {
65
+ includePaths,
66
+ sourceMap: "file",
67
+ },
68
+ },
69
+ ],
70
+ ```
71
+
72
+ Example SCSS color-scheme:
73
+
74
+ ```scss
75
+ $colors-schemes: (
76
+ "pixy-pink": (
77
+ "primary": #4eac00,
78
+ "secondary": #fbff00,
79
+ "danger": #ff8800,
80
+ "success": #4dff00,
81
+ "text": #294d26,
82
+ "background": #ffdfb0,
83
+ "link": #7b00ff,
84
+ ),
85
+ );
86
+ ```
87
+
88
+ You can find multiple plugins here:
89
+ [Postcss Plugins](https://github.com/postcss/postcss/blob/main/docs/plugins.md)
90
+
91
+ The color-scheme enables the possibility to theme the colors used in BCL. It overrides the variables `$theme-colors` used by Bootstrap ([Bootstrap Theme Colors](https://getbootstrap.com/docs/5.0/customize/color/#theme-colors)).
92
+
93
+ ### Prerequisites
94
+
95
+ - BCL-Builder version >= 1.2.1
96
+ - BCL-Theme-Default >= 1.2.1
97
+
98
+ We've also added some new variables that overwrite and make use of extra classes:
99
+
100
+ - `.text-color-default`: Text color is changed based on the 'text' variable, overriding all text colors inside a component.
101
+ - `.bg-default`: Background color is changed based on the 'background' variable. It adds a background for the component but does not override if it already has a `bg` class (e.g., `bg-primary`).
102
+
103
+ ### Files Inside the Theme Default
104
+
105
+ - `scss/color_scheme/alert`: Mixin that changes the colors of alerts
106
+ - `scss/color_scheme/background`: Mixin that adds the `bg-default` class
107
+ - `scss/color_scheme/badge`: Mixin that changes the colors of badges
108
+ - `scss/color_scheme/buttons`: Mixin that changes the colors of buttons
109
+ - `scss/color_scheme/link`: Mixin that changes the color of links
110
+ - `scss/color_scheme/list_group`: Mixin that changes the colors of list groups
111
+ - `scss/color_scheme/text`: Mixin that adds the `text-color-default` class
112
+ - `scss/color_scheme/utilities`: Mixin that changes the utilities: `bg-{color}` (e.g., `bg-primary`), `text-bg-{color}` (e.g., `text-bg-primary`), and `link-{color}` (e.g., `link-primary`)
113
+ - `scss/color_scheme/generator`: This includes all the mentioned mixins and calls them. It also adds the CSS variables on the color scheme class.
114
+
115
+ - `scss/color-scheme.scss`: This is the starting imports needed.
116
+
117
+ ---
package/bin/build.js CHANGED
@@ -5,6 +5,7 @@ const program = require("commander");
5
5
  const buildScript = require("../scripts/scripts");
6
6
  const browserslist = require("browserslist");
7
7
  const { buildStyles } = require("../scripts/styles");
8
+ const { buildColorScheme } = require("../scripts/colorScheme");
8
9
  const rename = require("../scripts/rename");
9
10
  const copyFiles = require("../scripts/copy");
10
11
  const makeSprite = require("../scripts/sprite");
@@ -57,6 +58,16 @@ program
57
58
  );
58
59
  });
59
60
 
61
+ program
62
+ .command("color-scheme")
63
+ .description("compile Color scheme SCSS to CSS")
64
+ .action(() => {
65
+ const config = loadConfig(program.config);
66
+ config.colorScheme.forEach((conf) =>
67
+ buildColorScheme(conf.entry, conf.dest, conf.options)
68
+ );
69
+ });
70
+
60
71
  program
61
72
  .command("sprite")
62
73
  .description("make svg sprites")
@@ -1,118 +1,22 @@
1
1
  module.exports = [
2
2
  {
3
- cleanupAttrs: true,
4
- },
5
- {
6
- cleanupEnableBackground: true,
7
- },
8
- {
9
- cleanupIDs: true,
10
- },
11
- {
12
- cleanupListOfValues: true,
13
- },
14
- {
15
- cleanupNumericValues: true,
16
- },
17
- {
18
- collapseGroups: true,
19
- },
20
- {
21
- convertColors: true,
22
- },
23
- {
24
- convertPathData: {
25
- noSpaceAfterFlags: false,
3
+ name: "preset-default",
4
+ params: {
5
+ overrides: {
6
+ removeUnknownsAndDefaults: {
7
+ keepRoleAttr: true,
8
+ },
9
+ removeViewBox: false,
10
+ },
26
11
  },
27
12
  },
13
+ "cleanupListOfValues",
14
+ "removeXMLNS",
15
+ "sortAttrs",
28
16
  {
29
- convertShapeToPath: true,
30
- },
31
- {
32
- convertStyleToAttrs: true,
33
- },
34
- {
35
- convertTransform: true,
36
- },
37
- {
38
- inlineStyles: true,
39
- },
40
- {
41
- mergePaths: {
42
- noSpaceAfterFlags: false,
43
- },
44
- },
45
- {
46
- minifyStyles: true,
47
- },
48
- {
49
- moveElemsAttrsToGroup: true,
50
- },
51
- {
52
- moveGroupAttrsToElems: true,
53
- },
54
- {
55
- removeAttrs: {
56
- attrs: ["data-name", "fill", "clip-rule"],
57
- },
58
- },
59
- {
60
- removeComments: true,
61
- },
62
- {
63
- removeDesc: true,
64
- },
65
- {
66
- removeDoctype: true,
67
- },
68
- {
69
- removeEditorsNSData: true,
70
- },
71
- {
72
- removeEmptyAttrs: true,
73
- },
74
- {
75
- removeEmptyContainers: true,
76
- },
77
- {
78
- removeEmptyText: true,
79
- },
80
- {
81
- removeHiddenElems: true,
82
- },
83
- {
84
- removeMetadata: true,
85
- },
86
- {
87
- removeNonInheritableGroupAttrs: true,
88
- },
89
- {
90
- removeTitle: true,
91
- },
92
- {
93
- removeUnknownsAndDefaults: {
94
- keepRoleAttr: true,
17
+ name: "removeAttrs",
18
+ params: {
19
+ attrs: ["clip-rule", "data-name", "fill"],
95
20
  },
96
21
  },
97
- {
98
- removeUnusedNS: true,
99
- },
100
- {
101
- removeUselessDefs: true,
102
- },
103
- {
104
- removeUselessStrokeAndFill: true,
105
- },
106
- {
107
- removeViewBox: false,
108
- },
109
- {
110
- removeXMLNS: true,
111
- },
112
- {
113
- removeXMLProcInst: true,
114
- },
115
- {
116
- sortAttrs: true,
117
- },
118
22
  ];
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@openeuropa/bcl-builder",
3
3
  "author": "European Commission",
4
4
  "license": "EUPL-1.2",
5
- "version": "0.28.0",
5
+ "version": "0.313.202403151055",
6
6
  "description": "Bootstrap Component Library builder",
7
7
  "publishConfig": {
8
8
  "access": "public"
@@ -11,31 +11,32 @@
11
11
  "bcl-builder": "./bin/build.js"
12
12
  },
13
13
  "dependencies": {
14
- "@babel/core": "7.19.1",
15
- "@babel/preset-env": "7.19.1",
16
- "@babel/runtime": "7.19.0",
17
- "@popperjs/core": "2.11.6",
18
- "@rollup/plugin-babel": "5.3.1",
19
- "@rollup/plugin-commonjs": "22.0.2",
20
- "@rollup/plugin-node-resolve": "14.1.0",
21
- "@rollup/plugin-replace": "4.0.0",
22
- "autoprefixer": "10.4.12",
14
+ "@babel/core": "7.22.9",
15
+ "@babel/preset-env": "7.22.9",
16
+ "@babel/runtime": "7.22.6",
17
+ "@popperjs/core": "2.11.8",
18
+ "@rollup/plugin-babel": "6.0.3",
19
+ "@rollup/plugin-commonjs": "25.0.3",
20
+ "@rollup/plugin-node-resolve": "15.1.0",
21
+ "@rollup/plugin-replace": "5.0.2",
22
+ "autoprefixer": "10.4.14",
23
23
  "babel-eslint": "10.1.0",
24
- "browser-sync": "2.27.10",
25
- "commander": "9.4.0",
24
+ "browser-sync": "2.29.3",
25
+ "commander": "11.0.0",
26
26
  "copyfiles": "2.4.1",
27
27
  "cross-env": "7.0.3",
28
- "cssnano": "5.1.13",
29
- "postcss": "8.4.16",
30
- "rollup": "2.79.1",
31
- "rollup-plugin-istanbul": "3.0.0",
28
+ "cssnano": "6.0.1",
29
+ "postcss": "8.4.31",
30
+ "postcss-prefix-selector": "^1.16.0",
31
+ "rollup": "3.27.0",
32
+ "rollup-plugin-istanbul": "4.0.0",
32
33
  "rollup-plugin-terser": "7.0.2",
33
- "sass": "1.55.0",
34
- "svg-sprite": "1.5.4",
35
- "svgo": "2.8.0"
34
+ "sass": "1.64.2",
35
+ "svg-sprite": "2.0.2",
36
+ "svgo": "3.0.2"
36
37
  },
37
38
  "engines": {
38
- "node": ">=12.0.0"
39
+ "node": ">=14.0.0"
39
40
  },
40
- "gitHead": "9ceb916258c8c7331f37bbb7c4380a2121440e12"
41
+ "gitHead": "604a6149ce90e748b26cdcccc9c8fdc93fa431d9"
41
42
  }
@@ -0,0 +1,129 @@
1
+ /**
2
+ * Compile scss files.
3
+ *
4
+ * @param {string} from - Path to a folder or file.
5
+ * @param {string} to - String to prefix, suffix or replace the current file name.
6
+ * @param {object} options - Object
7
+ *
8
+ * Example config object: {
9
+ *
10
+ * color-scheme: [
11
+ * {
12
+ * entry: [path.resolve(nodeModules, "myfile.js")],
13
+ * dest: path.resolve(outputFolder, "js"),
14
+ * options: {
15
+ * includePaths,
16
+ * sourceMap: "file",
17
+ * },
18
+ * },
19
+ * ],
20
+ */
21
+
22
+ const sass = require("sass");
23
+ const path = require("path");
24
+ const fs = require("fs");
25
+ const postcss = require("postcss");
26
+ const cssnano = require("cssnano");
27
+ const prefixer = require("postcss-prefix-selector");
28
+ const autoprefixer = require("autoprefixer");
29
+
30
+ const getPlugins = (options) => {
31
+ const plugins = [];
32
+
33
+ plugins.push(autoprefixer({ grid: "no-autoplace" }));
34
+
35
+ if (options.minify) {
36
+ plugins.push(cssnano({ safe: true }));
37
+ }
38
+
39
+ return plugins;
40
+ };
41
+
42
+ const buildColorScheme = (entry, dest, options) => {
43
+ const plugins = getPlugins(options);
44
+
45
+ let postcssSourceMap = false;
46
+ if (options.sourceMap === true) {
47
+ postcssSourceMap = true; // inline
48
+ } else if (options.sourceMap === "file") {
49
+ postcssSourceMap = options.sourceMap; // as a file
50
+ }
51
+
52
+ // Read contents of the entry file and the base color scheme SCSS file
53
+ const entryVariables = fs.readFileSync(entry, "utf8");
54
+ const imports = fs.readFileSync(
55
+ path.resolve(
56
+ ...(options.includePaths || []),
57
+ "@openeuropa/bcl-theme-default/src/scss/color-scheme.scss"
58
+ ),
59
+ "utf8"
60
+ );
61
+ const generator = fs.readFileSync(
62
+ path.resolve(
63
+ ...(options.includePaths || []),
64
+ "@openeuropa/bcl-theme-default/src/scss/color_scheme/generator.scss"
65
+ ),
66
+ "utf8"
67
+ );
68
+
69
+ // Concatenate the contents
70
+ const scssContent = imports + "\n" + entryVariables + "\n" + generator;
71
+
72
+ console.log(scssContent);
73
+
74
+ const sassResult = sass.renderSync({
75
+ data: scssContent,
76
+ outFile: dest,
77
+ noErrorCss: true,
78
+ outputStyle: "expanded",
79
+ sourceMap: options.sourceMap !== false,
80
+ sourceMapContents: options.sourceMap === true,
81
+ sourceMapEmbed: options.sourceMap === true,
82
+ includePaths: [
83
+ path.resolve(process.cwd(), "node_modules"),
84
+ ...(options.includePaths || []),
85
+ ],
86
+ });
87
+
88
+ postcss(plugins)
89
+ .use(
90
+ prefixer({
91
+ prefix: options.prefix ? options.prefix : "",
92
+
93
+ transform: function (
94
+ prefix,
95
+ selector,
96
+ prefixedSelector,
97
+ filePath,
98
+ rule
99
+ ) {
100
+ if (prefix) {
101
+ return prefixedSelector;
102
+ } else {
103
+ return selector;
104
+ }
105
+ },
106
+ })
107
+ )
108
+ .process(sassResult.css, {
109
+ map:
110
+ postcssSourceMap === "file"
111
+ ? { inline: false, prev: sassResult.map.toString() }
112
+ : postcssSourceMap,
113
+ from: entry,
114
+ to: dest,
115
+ })
116
+ .then((postcssResult) => {
117
+ fs.mkdirSync(path.dirname(dest), { recursive: true });
118
+ fs.writeFileSync(dest, postcssResult.css);
119
+
120
+ if (postcssResult.map) {
121
+ fs.writeFileSync(`${dest}.map`, postcssResult.map.toString());
122
+ }
123
+ });
124
+ };
125
+
126
+ module.exports = {
127
+ getPlugins,
128
+ buildColorScheme,
129
+ };
package/scripts/rename.js CHANGED
@@ -23,7 +23,7 @@
23
23
  */
24
24
 
25
25
  const path = require("path");
26
- const glob = require("glob");
26
+ const { globSync } = require("glob");
27
27
  const { rename } = require("fs");
28
28
 
29
29
  module.exports = (from, to, options) => {
@@ -32,15 +32,15 @@ module.exports = (from, to, options) => {
32
32
 
33
33
  if (options.glob) {
34
34
  if (options.search) {
35
- files = glob.sync(path.join(from, options.glob, options.search));
35
+ files = globSync(path.join(from, options.glob, options.search));
36
36
  } else {
37
- files = glob.sync(path.join(from, options.glob));
37
+ files = globSync(path.join(from, options.glob));
38
38
  }
39
39
  } else {
40
40
  if (options.search) {
41
- files = glob.sync(path.join(from, options.search));
41
+ files = globSync(path.join(from, options.search));
42
42
  } else {
43
- files = glob.sync(from);
43
+ files = globSync(from);
44
44
  }
45
45
  }
46
46
 
package/scripts/sprite.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Generate svg sprites.
3
3
  *
4
- * @param {string} entry - Path to a folder or file.
4
+ * @param {string} entry - array of paths to a folder or file.
5
5
  * @param {string} dest - Output folder path
6
6
  * @param {object} options - Object
7
7
  *
@@ -9,7 +9,10 @@
9
9
  *
10
10
  * sprite: [
11
11
  * {
12
- * entry: path.resolve(nodeModules, "bootstrap-icons/icons/"),
12
+ * entry: [
13
+ * path.resolve(nodeModules, "bootstrap-icons/icons/"),
14
+ * path.resolve(__dirname, "src/icons/custom-icons")
15
+ * ],
13
16
  * dest: path.resolve(outputFolder, "icons/"),
14
17
  * options: {
15
18
  * file: "bcl-default-icons.svg",
@@ -21,17 +24,20 @@
21
24
  */
22
25
 
23
26
  const fs = require("fs");
24
- const glob = require("glob");
27
+ const { globSync } = require("glob");
25
28
  const mkdirp = require("mkdirp");
26
29
  const path = require("path");
27
30
  const defaultPlugins = require("../conf/svgoDefaultPlugins");
28
31
  const SVGSpriter = require("svg-sprite");
29
32
 
30
33
  module.exports = (entry, dest, options) => {
34
+ const iconList = Array.isArray(options.list)
35
+ ? options.list.flat(1)
36
+ : options.list;
31
37
  const outputFile = options.file
32
38
  ? `${dest}/${options.file}`
33
39
  : `${dest}/bcl-default-icons.svg`;
34
- const files = options.list || glob.sync("*.svg", { cwd: entry });
40
+ const files = iconList || globSync("*.svg", { cwd: entry });
35
41
 
36
42
  const plugins = options.transformPlugins || defaultPlugins;
37
43
 
@@ -42,7 +48,7 @@ module.exports = (entry, dest, options) => {
42
48
  {
43
49
  svgo: {
44
50
  multipass: true,
45
- plugins: plugins,
51
+ plugins: defaultPlugins,
46
52
  },
47
53
  },
48
54
  ],
@@ -60,7 +66,15 @@ module.exports = (entry, dest, options) => {
60
66
  });
61
67
 
62
68
  files.forEach((file) => {
63
- const filePath = path.resolve(entry, file);
69
+ let filePath;
70
+ if (Array.isArray(entry)) {
71
+ filePath = path.resolve(entry[0], file);
72
+ if (!fs.existsSync(filePath)) {
73
+ filePath = path.resolve(entry[1], file);
74
+ }
75
+ } else {
76
+ filePath = path.resolve(entry, file);
77
+ }
64
78
  spriter.add(
65
79
  filePath,
66
80
  file,
package/scripts/styles.js CHANGED
@@ -24,6 +24,7 @@ const path = require("path");
24
24
  const fs = require("fs");
25
25
  const postcss = require("postcss");
26
26
  const cssnano = require("cssnano");
27
+ const prefixer = require("postcss-prefix-selector");
27
28
  const autoprefixer = require("autoprefixer");
28
29
 
29
30
  const getPlugins = (options) => {
@@ -63,6 +64,25 @@ const buildStyles = (entry, dest, options) => {
63
64
  });
64
65
 
65
66
  postcss(plugins)
67
+ .use(
68
+ prefixer({
69
+ prefix: options.prefix ? options.prefix : "",
70
+
71
+ transform: function (
72
+ prefix,
73
+ selector,
74
+ prefixedSelector,
75
+ filePath,
76
+ rule
77
+ ) {
78
+ if (prefix) {
79
+ return prefixedSelector;
80
+ } else {
81
+ return selector;
82
+ }
83
+ },
84
+ })
85
+ )
66
86
  .process(sassResult.css, {
67
87
  map:
68
88
  postcssSourceMap === "file"