@openeuropa/bcl-builder 0.1.3 → 0.1.202408021145
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 +148 -0
- package/bin/build.js +31 -0
- package/conf/svgoDefaultPlugins.js +22 -0
- package/package.json +23 -22
- package/scripts/colorScheme.js +127 -0
- package/scripts/copy.js +17 -0
- package/scripts/rename.js +93 -0
- package/scripts/scripts.js +33 -0
- package/scripts/sprite.js +96 -0
- package/scripts/styles.js +41 -0
package/README.md
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
## BCL builder
|
|
2
|
+
|
|
3
|
+
The `@openeuropa/bcl-builder` is a package providing scripts to be executed via
|
|
4
|
+
the command line, `styles`, `scripts`, `copy`, `rename` and `sprite`.
|
|
5
|
+
They can be used respectively to compile SASS files and minify css
|
|
6
|
+
files, compile and minify js files, to copy files or rename files and to generate
|
|
7
|
+
svg sprites.
|
|
8
|
+
It comes with a `bin` file that is available when the package is installed and
|
|
9
|
+
can be run as `npm run ecl-builder scriptName`.
|
|
10
|
+
It supports a configuration file `bcl-builder.config.js` where each script can
|
|
11
|
+
be configured to perform specific operations in the enviroment where they are
|
|
12
|
+
used.
|
|
13
|
+
|
|
14
|
+
### Api
|
|
15
|
+
|
|
16
|
+
The builder uses by default a bcl-builder.config.js in the same folder where the
|
|
17
|
+
builder script is executed.
|
|
18
|
+
This file will define the different operations you want to perform via the builder.
|
|
19
|
+
The config file is basically an export of the configuration for the different
|
|
20
|
+
commands which all supports multiple operations as items in an array.
|
|
21
|
+
|
|
22
|
+
`module.exports = { scripts: [{ entry, dest, options } ...], styles: [{ entry, dest, options } ...], rename: [{ entry, dest, options } ...], copy: [{ from, to, options } ...], sprite: [[{ entry, dest, options } ...], };`
|
|
23
|
+
|
|
24
|
+
#### Styles
|
|
25
|
+
|
|
26
|
+
`styles: [ { entry (string), dest (string), options (object) [plugins for postcss] https://github.com/postcss/postcss/blob/main/docs/plugins.md { minify (includes css nano for minification) } }, ],`
|
|
27
|
+
|
|
28
|
+
#### Scripts
|
|
29
|
+
|
|
30
|
+
`scripts: [ { entry (string), dest (string), options: (object) [rollup js configuration https://rollupjs.org/guide/en/#javascript-api] }, }, ],`
|
|
31
|
+
|
|
32
|
+
#### Copy
|
|
33
|
+
|
|
34
|
+
`copy: [ { from: (string), to: (string), options: (object) [copyfiles api conf https://www.npmjs.com/package/copyfiles], }, ],`
|
|
35
|
+
|
|
36
|
+
#### Reaname
|
|
37
|
+
|
|
38
|
+
`rename: [ { from: (string), to: (string), options: (object) { search: (glob), operation: [prefix|suffix|rewrite|extension], }, }, ],`
|
|
39
|
+
|
|
40
|
+
#### Sprite
|
|
41
|
+
|
|
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,7 +5,10 @@ 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");
|
|
9
|
+
const rename = require("../scripts/rename");
|
|
8
10
|
const copyFiles = require("../scripts/copy");
|
|
11
|
+
const makeSprite = require("../scripts/sprite");
|
|
9
12
|
const pkg = require("../package.json");
|
|
10
13
|
|
|
11
14
|
const loadConfig = (configFile) => {
|
|
@@ -55,6 +58,26 @@ program
|
|
|
55
58
|
);
|
|
56
59
|
});
|
|
57
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
|
+
|
|
71
|
+
program
|
|
72
|
+
.command("sprite")
|
|
73
|
+
.description("make svg sprites")
|
|
74
|
+
.action(() => {
|
|
75
|
+
const config = loadConfig(program.config);
|
|
76
|
+
config.sprite.forEach((conf) =>
|
|
77
|
+
makeSprite(conf.entry || "**", conf.dest, conf.options)
|
|
78
|
+
);
|
|
79
|
+
});
|
|
80
|
+
|
|
58
81
|
program
|
|
59
82
|
.command("copy")
|
|
60
83
|
.description("copy static files")
|
|
@@ -65,6 +88,14 @@ program
|
|
|
65
88
|
);
|
|
66
89
|
});
|
|
67
90
|
|
|
91
|
+
program
|
|
92
|
+
.command("rename")
|
|
93
|
+
.description("rename files")
|
|
94
|
+
.action(() => {
|
|
95
|
+
const config = loadConfig(program.config);
|
|
96
|
+
config.rename.forEach((conf) => rename(conf.from, conf.to, conf.options));
|
|
97
|
+
});
|
|
98
|
+
|
|
68
99
|
// If no arguments provided, display help menu.
|
|
69
100
|
if (process.argv.slice(2).length <= 0) {
|
|
70
101
|
program.help();
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
module.exports = [
|
|
2
|
+
{
|
|
3
|
+
name: "preset-default",
|
|
4
|
+
params: {
|
|
5
|
+
overrides: {
|
|
6
|
+
removeUnknownsAndDefaults: {
|
|
7
|
+
keepRoleAttr: true,
|
|
8
|
+
},
|
|
9
|
+
removeViewBox: false,
|
|
10
|
+
},
|
|
11
|
+
},
|
|
12
|
+
},
|
|
13
|
+
"cleanupListOfValues",
|
|
14
|
+
"removeXMLNS",
|
|
15
|
+
"sortAttrs",
|
|
16
|
+
{
|
|
17
|
+
name: "removeAttrs",
|
|
18
|
+
params: {
|
|
19
|
+
attrs: ["clip-rule", "data-name", "fill"],
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
];
|
package/package.json
CHANGED
|
@@ -2,38 +2,39 @@
|
|
|
2
2
|
"name": "@openeuropa/bcl-builder",
|
|
3
3
|
"author": "European Commission",
|
|
4
4
|
"license": "EUPL-1.2",
|
|
5
|
-
"version": "0.1.
|
|
5
|
+
"version": "0.1.202408021145",
|
|
6
6
|
"description": "Bootstrap Component Library builder",
|
|
7
7
|
"publishConfig": {
|
|
8
8
|
"access": "public"
|
|
9
9
|
},
|
|
10
|
-
"bin":
|
|
11
|
-
"bcl-builder": "./bin/build.js"
|
|
12
|
-
},
|
|
10
|
+
"bin": "./bin/build.js",
|
|
13
11
|
"dependencies": {
|
|
14
|
-
"@babel/core": "7.
|
|
15
|
-
"@babel/preset-env": "7.
|
|
16
|
-
"@babel/runtime": "7.
|
|
17
|
-
"@popperjs/core": "2.
|
|
18
|
-
"@rollup/plugin-babel": "
|
|
19
|
-
"@rollup/plugin-commonjs": "
|
|
20
|
-
"@rollup/plugin-node-resolve": "
|
|
21
|
-
"@rollup/plugin-replace": "
|
|
22
|
-
"autoprefixer": "10.
|
|
12
|
+
"@babel/core": "7.24.7",
|
|
13
|
+
"@babel/preset-env": "7.24.7",
|
|
14
|
+
"@babel/runtime": "7.24.7",
|
|
15
|
+
"@popperjs/core": "2.11.8",
|
|
16
|
+
"@rollup/plugin-babel": "6.0.4",
|
|
17
|
+
"@rollup/plugin-commonjs": "25.0.8",
|
|
18
|
+
"@rollup/plugin-node-resolve": "15.2.3",
|
|
19
|
+
"@rollup/plugin-replace": "5.0.7",
|
|
20
|
+
"autoprefixer": "10.4.19",
|
|
23
21
|
"babel-eslint": "10.1.0",
|
|
24
|
-
"browser-sync": "
|
|
25
|
-
"commander": "
|
|
22
|
+
"browser-sync": "3.0.2",
|
|
23
|
+
"commander": "11.1.0",
|
|
26
24
|
"copyfiles": "2.4.1",
|
|
27
25
|
"cross-env": "7.0.3",
|
|
28
|
-
"cssnano": "
|
|
29
|
-
"postcss": "8.
|
|
30
|
-
"
|
|
31
|
-
"rollup
|
|
26
|
+
"cssnano": "6.1.2",
|
|
27
|
+
"postcss": "8.4.39",
|
|
28
|
+
"postcss-prefix-selector": "^1.16.1",
|
|
29
|
+
"rollup": "3.29.4",
|
|
30
|
+
"rollup-plugin-istanbul": "4.0.0",
|
|
32
31
|
"rollup-plugin-terser": "7.0.2",
|
|
33
|
-
"sass": "1.
|
|
32
|
+
"sass": "1.77.6",
|
|
33
|
+
"svg-sprite": "2.0.4",
|
|
34
|
+
"svgo": "3.3.2"
|
|
34
35
|
},
|
|
35
36
|
"engines": {
|
|
36
|
-
"node": ">=
|
|
37
|
+
"node": ">=14.0.0"
|
|
37
38
|
},
|
|
38
|
-
"gitHead": "
|
|
39
|
+
"gitHead": "7ee2013f7f64a70ddfa35228a9a65967dd71eec3"
|
|
39
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
|
+
};
|
package/scripts/copy.js
CHANGED
|
@@ -1,3 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copy 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
|
+
* copy: [
|
|
10
|
+
* {
|
|
11
|
+
* from: [path.resolve(nodeModules, "myfile.js")],
|
|
12
|
+
* to: path.resolve(outputFolder, "js"),
|
|
13
|
+
* options: { up: true },
|
|
14
|
+
* },
|
|
15
|
+
* ],
|
|
16
|
+
*/
|
|
17
|
+
|
|
1
18
|
const fs = require("fs");
|
|
2
19
|
const path = require("path");
|
|
3
20
|
const copy = require("copyfiles");
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Rename 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 - Options available:
|
|
7
|
+
* search: (string) the glob to find the files in the "from"
|
|
8
|
+
* glob: (glob) The glob to be added as a segment in the "from"
|
|
9
|
+
* operation: (string) Available options:
|
|
10
|
+
* prefix (string), suffix (String), rewrite (String),
|
|
11
|
+
* extension (boolean), newExtension (string)
|
|
12
|
+
* Example config object: {
|
|
13
|
+
* rename: [
|
|
14
|
+
* {
|
|
15
|
+
* from: path.resolve(outputFolder, "templates"),
|
|
16
|
+
* to: "bcl-",
|
|
17
|
+
* options: {
|
|
18
|
+
* search: "*.twig",
|
|
19
|
+
* operation: "prefix",
|
|
20
|
+
* },
|
|
21
|
+
* }
|
|
22
|
+
* ]
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
const path = require("path");
|
|
26
|
+
const { globSync } = require("glob");
|
|
27
|
+
const { rename } = require("fs");
|
|
28
|
+
|
|
29
|
+
module.exports = (from, to, options) => {
|
|
30
|
+
const executor = async () => {
|
|
31
|
+
let files = false;
|
|
32
|
+
|
|
33
|
+
if (options.glob) {
|
|
34
|
+
if (options.search) {
|
|
35
|
+
files = globSync(path.join(from, options.glob, options.search));
|
|
36
|
+
} else {
|
|
37
|
+
files = globSync(path.join(from, options.glob));
|
|
38
|
+
}
|
|
39
|
+
} else {
|
|
40
|
+
if (options.search) {
|
|
41
|
+
files = globSync(path.join(from, options.search));
|
|
42
|
+
} else {
|
|
43
|
+
files = globSync(from);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (files[0]) {
|
|
48
|
+
files.forEach(async (file) => {
|
|
49
|
+
const fileName = path.basename(file);
|
|
50
|
+
const folder = path.dirname(file);
|
|
51
|
+
let newFileName = fileName;
|
|
52
|
+
|
|
53
|
+
if (!options.operation) {
|
|
54
|
+
options.operation = "prefix";
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
switch (options.operation) {
|
|
58
|
+
case "prefix":
|
|
59
|
+
newFileName = `${to}${fileName}`;
|
|
60
|
+
break;
|
|
61
|
+
|
|
62
|
+
case "suffix":
|
|
63
|
+
newFileName = `${fileName}${to}`;
|
|
64
|
+
break;
|
|
65
|
+
|
|
66
|
+
case "rewrite":
|
|
67
|
+
newFileName = to;
|
|
68
|
+
break;
|
|
69
|
+
|
|
70
|
+
case "extension":
|
|
71
|
+
const currentExtension = fileName.substring(fileName.indexOf("."));
|
|
72
|
+
const withoutExtension = fileName.replace(currentExtension, "");
|
|
73
|
+
const newExtension = options.newExtension || currentExtension;
|
|
74
|
+
newFileName = `${withoutExtension}${newExtension}`;
|
|
75
|
+
break;
|
|
76
|
+
|
|
77
|
+
default:
|
|
78
|
+
console.error("The requested operation was not recognized");
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const newFile = `${folder}/${newFileName}`;
|
|
82
|
+
|
|
83
|
+
await rename(file, newFile, function (err) {
|
|
84
|
+
if (err) console.error(err);
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
} else {
|
|
88
|
+
console.error("We couldn't find the file(s) you wanted to rename");
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
executor();
|
|
93
|
+
};
|
package/scripts/scripts.js
CHANGED
|
@@ -1,3 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Compile and bundle js files.
|
|
3
|
+
*
|
|
4
|
+
* @param {string} input - Path to a folder or file.
|
|
5
|
+
* @param {string} dest - String to prefix, suffix or replace the current file name.
|
|
6
|
+
* @param {object} options - Object
|
|
7
|
+
*
|
|
8
|
+
* Example config object: {
|
|
9
|
+
*
|
|
10
|
+
* scripts: [
|
|
11
|
+
* {
|
|
12
|
+
* entry: path.resolve(__dirname, "src/js/index.esm.js"),
|
|
13
|
+
* dest: path.resolve(outputFolder, "js/oe-bcl-default.esm.js"),
|
|
14
|
+
* options: {
|
|
15
|
+
* format: "esm",
|
|
16
|
+
* globals: { "@popperjs/core": "Popper" },
|
|
17
|
+
* minify: true,
|
|
18
|
+
* sourceMap: true,
|
|
19
|
+
* minifyOptions: {
|
|
20
|
+
* mangle: true,
|
|
21
|
+
* format: {
|
|
22
|
+
* comments: /^!/,
|
|
23
|
+
* },
|
|
24
|
+
* compress: {
|
|
25
|
+
* passes: 2,
|
|
26
|
+
* },
|
|
27
|
+
* },
|
|
28
|
+
* external: ["@popperjs/core"],
|
|
29
|
+
* },
|
|
30
|
+
* },
|
|
31
|
+
* ],
|
|
32
|
+
*/
|
|
33
|
+
|
|
1
34
|
const path = require("path");
|
|
2
35
|
const { babel } = require("@rollup/plugin-babel");
|
|
3
36
|
const { nodeResolve } = require("@rollup/plugin-node-resolve");
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generate svg sprites.
|
|
3
|
+
*
|
|
4
|
+
* @param {string} entry - array of paths to a folder or file.
|
|
5
|
+
* @param {string} dest - Output folder path
|
|
6
|
+
* @param {object} options - Object
|
|
7
|
+
*
|
|
8
|
+
* Example config object: {
|
|
9
|
+
*
|
|
10
|
+
* sprite: [
|
|
11
|
+
* {
|
|
12
|
+
* entry: [
|
|
13
|
+
* path.resolve(nodeModules, "bootstrap-icons/icons/"),
|
|
14
|
+
* path.resolve(__dirname, "src/icons/custom-icons")
|
|
15
|
+
* ],
|
|
16
|
+
* dest: path.resolve(outputFolder, "icons/"),
|
|
17
|
+
* options: {
|
|
18
|
+
* file: "bcl-default-icons.svg",
|
|
19
|
+
* list: myList,
|
|
20
|
+
* transformPlugins: (array of svgo plugins objects)
|
|
21
|
+
* },
|
|
22
|
+
* },
|
|
23
|
+
* ],
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
const fs = require("fs");
|
|
27
|
+
const { globSync } = require("glob");
|
|
28
|
+
const mkdirp = require("mkdirp");
|
|
29
|
+
const path = require("path");
|
|
30
|
+
const defaultPlugins = require("../conf/svgoDefaultPlugins");
|
|
31
|
+
const SVGSpriter = require("svg-sprite");
|
|
32
|
+
|
|
33
|
+
module.exports = (entry, dest, options) => {
|
|
34
|
+
const iconList = Array.isArray(options.list)
|
|
35
|
+
? options.list.flat(1)
|
|
36
|
+
: options.list;
|
|
37
|
+
const outputFile = options.file
|
|
38
|
+
? `${dest}/${options.file}`
|
|
39
|
+
: `${dest}/bcl-default-icons.svg`;
|
|
40
|
+
const files = iconList || globSync("*.svg", { cwd: entry });
|
|
41
|
+
|
|
42
|
+
const plugins = options.transformPlugins || defaultPlugins;
|
|
43
|
+
|
|
44
|
+
const spriter = new SVGSpriter({
|
|
45
|
+
dest,
|
|
46
|
+
shape: {
|
|
47
|
+
transform: [
|
|
48
|
+
{
|
|
49
|
+
svgo: {
|
|
50
|
+
multipass: true,
|
|
51
|
+
plugins: defaultPlugins,
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
],
|
|
55
|
+
},
|
|
56
|
+
svg: {
|
|
57
|
+
namespaceClassnames: false,
|
|
58
|
+
xmlDeclaration: false,
|
|
59
|
+
},
|
|
60
|
+
mode: {
|
|
61
|
+
symbol: {
|
|
62
|
+
dest: "",
|
|
63
|
+
sprite: outputFile,
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
files.forEach((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
|
+
}
|
|
78
|
+
spriter.add(
|
|
79
|
+
filePath,
|
|
80
|
+
file,
|
|
81
|
+
fs.readFileSync(filePath, { encoding: "utf-8" })
|
|
82
|
+
);
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
spriter.compile((error, result, data) => {
|
|
86
|
+
Object.keys(result).forEach((mode) => {
|
|
87
|
+
Object.keys(result[mode]).forEach((resource) => {
|
|
88
|
+
mkdirp.sync(path.dirname(result[mode][resource].path));
|
|
89
|
+
fs.writeFileSync(
|
|
90
|
+
result[mode][resource].path,
|
|
91
|
+
result[mode][resource].contents
|
|
92
|
+
);
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
};
|
package/scripts/styles.js
CHANGED
|
@@ -1,8 +1,30 @@
|
|
|
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
|
+
* styles: [
|
|
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
|
+
|
|
1
22
|
const sass = require("sass");
|
|
2
23
|
const path = require("path");
|
|
3
24
|
const fs = require("fs");
|
|
4
25
|
const postcss = require("postcss");
|
|
5
26
|
const cssnano = require("cssnano");
|
|
27
|
+
const prefixer = require("postcss-prefix-selector");
|
|
6
28
|
const autoprefixer = require("autoprefixer");
|
|
7
29
|
|
|
8
30
|
const getPlugins = (options) => {
|
|
@@ -42,6 +64,25 @@ const buildStyles = (entry, dest, options) => {
|
|
|
42
64
|
});
|
|
43
65
|
|
|
44
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
|
+
)
|
|
45
86
|
.process(sassResult.css, {
|
|
46
87
|
map:
|
|
47
88
|
postcssSourceMap === "file"
|