@openeuropa/bcl-builder 1.3.0 → 1.4.0
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 +106 -0
- package/bin/build.js +11 -0
- package/package.json +2 -2
- package/scripts/colorScheme.js +127 -0
package/README.md
CHANGED
|
@@ -40,3 +40,109 @@ 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
|
+
* Example config object: {
|
|
50
|
+
colorScheme: [
|
|
51
|
+
{
|
|
52
|
+
entry: path.resolve("resources/sass/color-scheme-variables.scss"),
|
|
53
|
+
dest: path.resolve(outputFolder, "assets/css/color_scheme.min.css"),
|
|
54
|
+
options: {
|
|
55
|
+
includePaths,
|
|
56
|
+
sourceMap: "file",
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
],
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
This following example is the entry of the colorScheme. The scss file should look like this. It also support multiple color schemes.
|
|
63
|
+
Example SCSS file of color-scheme.scss:
|
|
64
|
+
|
|
65
|
+
```scss
|
|
66
|
+
$colors-schemes: (
|
|
67
|
+
"ocean": (
|
|
68
|
+
"primary": #4eac00,
|
|
69
|
+
"secondary": #fbff00,
|
|
70
|
+
"danger": #ff8800,
|
|
71
|
+
"success": #4dff00,
|
|
72
|
+
"text": #294d26,
|
|
73
|
+
"background": #ffdfb0,
|
|
74
|
+
"link": #7b00ff,
|
|
75
|
+
),
|
|
76
|
+
);
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
You can find multiple plugins here:
|
|
80
|
+
[Postcss Plugins](https://github.com/postcss/postcss/blob/main/docs/plugins.md)
|
|
81
|
+
|
|
82
|
+
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)).
|
|
83
|
+
|
|
84
|
+
We've also added some new variables that overwrite and make use of extra classes:
|
|
85
|
+
|
|
86
|
+
- `.text-color-default`: Text color is changed based on the 'text' variable, overriding all text colors inside a component.
|
|
87
|
+
- `.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`).
|
|
88
|
+
|
|
89
|
+
### Prerequisites
|
|
90
|
+
|
|
91
|
+
- BCL-Builder version >= 1.2.1
|
|
92
|
+
- BCL-Bootstrap version >= 1.2.1
|
|
93
|
+
- BCL-Theme-Default >= 1.2.1
|
|
94
|
+
|
|
95
|
+
### Setup Color Schema
|
|
96
|
+
|
|
97
|
+
Step 1:
|
|
98
|
+
Depending on your package manager:
|
|
99
|
+
|
|
100
|
+
Yarn:
|
|
101
|
+
|
|
102
|
+
- yarn add @openeuropa/bcl-builder --save
|
|
103
|
+
- yarn add @openeuropa/bcl-bootstrap --save
|
|
104
|
+
- yarn add @openeuropa/bcl-theme-default --save
|
|
105
|
+
|
|
106
|
+
NPM:
|
|
107
|
+
|
|
108
|
+
- npm install @openeuropa/bcl-builder --save
|
|
109
|
+
- npm install @openeuropa/bcl-bootstrap --save
|
|
110
|
+
- npm install @openeuropa/bcl-theme-default --save
|
|
111
|
+
|
|
112
|
+
Step 2:
|
|
113
|
+
Add the following bcl-builder.config.js file:
|
|
114
|
+
|
|
115
|
+
```javascript
|
|
116
|
+
colorScheme: [
|
|
117
|
+
{
|
|
118
|
+
entry: path.resolve(outputFolder, "path to the color-scheme scss file"),
|
|
119
|
+
dest: path.resolve(outputFolder, "compiled "),
|
|
120
|
+
options: {
|
|
121
|
+
includePaths,
|
|
122
|
+
minify: true,
|
|
123
|
+
sourceMap: "file",
|
|
124
|
+
},
|
|
125
|
+
},
|
|
126
|
+
],
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
Step 3:
|
|
130
|
+
Add in your package.json the following command:
|
|
131
|
+
|
|
132
|
+
```javascript
|
|
133
|
+
"build:color-scheme": "bcl-builder color-scheme",
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
Note: We are using ([npm-run-all package](https://www.npmjs.com/package/npm-run-all)) in BCL in order for all scripts for bcl-builder to be run at once:
|
|
137
|
+
Example:
|
|
138
|
+
|
|
139
|
+
```javascript
|
|
140
|
+
"build": "npm-run-all build:*",
|
|
141
|
+
"build:styles": "bcl-builder styles",
|
|
142
|
+
"build:color-scheme": "bcl-builder color-scheme",
|
|
143
|
+
"build:scripts": "bcl-builder scripts",
|
|
144
|
+
"build:copy": "bcl-builder copy",
|
|
145
|
+
"build:sprite": "bcl-builder sprite",
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
---
|
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")
|
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": "1.
|
|
5
|
+
"version": "1.4.0",
|
|
6
6
|
"description": "Bootstrap Component Library builder",
|
|
7
7
|
"publishConfig": {
|
|
8
8
|
"access": "public"
|
|
@@ -36,5 +36,5 @@
|
|
|
36
36
|
"engines": {
|
|
37
37
|
"node": ">=14.0.0"
|
|
38
38
|
},
|
|
39
|
-
"gitHead": "
|
|
39
|
+
"gitHead": "0271b344c41999ea181851f229385df1d539047b"
|
|
40
40
|
}
|
|
@@ -0,0 +1,127 @@
|
|
|
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("resources/sass/color-scheme-variables.scss"),
|
|
13
|
+
* dest: path.resolve(outputFolder, "assets/css/color_scheme.min.css"),
|
|
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
|
+
const sassResult = sass.renderSync({
|
|
73
|
+
data: scssContent,
|
|
74
|
+
outFile: dest,
|
|
75
|
+
noErrorCss: true,
|
|
76
|
+
outputStyle: "expanded",
|
|
77
|
+
sourceMap: options.sourceMap !== false,
|
|
78
|
+
sourceMapContents: options.sourceMap === true,
|
|
79
|
+
sourceMapEmbed: options.sourceMap === true,
|
|
80
|
+
includePaths: [
|
|
81
|
+
path.resolve(process.cwd(), "node_modules"),
|
|
82
|
+
...(options.includePaths || []),
|
|
83
|
+
],
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
postcss(plugins)
|
|
87
|
+
.use(
|
|
88
|
+
prefixer({
|
|
89
|
+
prefix: options.prefix ? options.prefix : "",
|
|
90
|
+
|
|
91
|
+
transform: function (
|
|
92
|
+
prefix,
|
|
93
|
+
selector,
|
|
94
|
+
prefixedSelector,
|
|
95
|
+
filePath,
|
|
96
|
+
rule
|
|
97
|
+
) {
|
|
98
|
+
if (prefix) {
|
|
99
|
+
return prefixedSelector;
|
|
100
|
+
} else {
|
|
101
|
+
return selector;
|
|
102
|
+
}
|
|
103
|
+
},
|
|
104
|
+
})
|
|
105
|
+
)
|
|
106
|
+
.process(sassResult.css, {
|
|
107
|
+
map:
|
|
108
|
+
postcssSourceMap === "file"
|
|
109
|
+
? { inline: false, prev: sassResult.map.toString() }
|
|
110
|
+
: postcssSourceMap,
|
|
111
|
+
from: entry,
|
|
112
|
+
to: dest,
|
|
113
|
+
})
|
|
114
|
+
.then((postcssResult) => {
|
|
115
|
+
fs.mkdirSync(path.dirname(dest), { recursive: true });
|
|
116
|
+
fs.writeFileSync(dest, postcssResult.css);
|
|
117
|
+
|
|
118
|
+
if (postcssResult.map) {
|
|
119
|
+
fs.writeFileSync(`${dest}.map`, postcssResult.map.toString());
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
module.exports = {
|
|
125
|
+
getPlugins,
|
|
126
|
+
buildColorScheme,
|
|
127
|
+
};
|