@openeuropa/bcl-builder 0.16.0 → 0.17.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 ADDED
@@ -0,0 +1,42 @@
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), }, }, ],`
package/bin/build.js CHANGED
@@ -7,6 +7,7 @@ const browserslist = require("browserslist");
7
7
  const { buildStyles } = require("../scripts/styles");
8
8
  const rename = require("../scripts/rename");
9
9
  const copyFiles = require("../scripts/copy");
10
+ const makeSprite = require("../scripts/sprite");
10
11
  const pkg = require("../package.json");
11
12
 
12
13
  const loadConfig = (configFile) => {
@@ -56,6 +57,16 @@ program
56
57
  );
57
58
  });
58
59
 
60
+ program
61
+ .command("sprite")
62
+ .description("make svg sprites")
63
+ .action(() => {
64
+ const config = loadConfig(program.config);
65
+ config.sprite.forEach((conf) =>
66
+ makeSprite(conf.entry || "**", conf.dest, conf.options)
67
+ );
68
+ });
69
+
59
70
  program
60
71
  .command("copy")
61
72
  .description("copy static files")
@@ -66,15 +77,13 @@ program
66
77
  );
67
78
  });
68
79
 
69
- program
70
- .command("rename")
71
- .description("rename files")
72
- .action(() => {
73
- const config = loadConfig(program.config);
74
- config.rename.forEach((conf) =>
75
- rename(conf.from, conf.to, conf.options)
76
- );
77
- });
80
+ program
81
+ .command("rename")
82
+ .description("rename files")
83
+ .action(() => {
84
+ const config = loadConfig(program.config);
85
+ config.rename.forEach((conf) => rename(conf.from, conf.to, conf.options));
86
+ });
78
87
 
79
88
  // If no arguments provided, display help menu.
80
89
  if (process.argv.slice(2).length <= 0) {
@@ -0,0 +1,118 @@
1
+ module.exports = [
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,
26
+ },
27
+ },
28
+ {
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,
95
+ },
96
+ },
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
+ ];
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.16.0",
5
+ "version": "0.17.0",
6
6
  "description": "Bootstrap Component Library builder",
7
7
  "publishConfig": {
8
8
  "access": "public"
@@ -11,13 +11,13 @@
11
11
  "bcl-builder": "./bin/build.js"
12
12
  },
13
13
  "dependencies": {
14
- "@babel/core": "7.16.0",
15
- "@babel/preset-env": "7.16.4",
16
- "@babel/runtime": "7.16.3",
14
+ "@babel/core": "7.16.5",
15
+ "@babel/preset-env": "7.16.5",
16
+ "@babel/runtime": "7.16.5",
17
17
  "@popperjs/core": "2.11.0",
18
18
  "@rollup/plugin-babel": "5.3.0",
19
- "@rollup/plugin-commonjs": "20.0.0",
20
- "@rollup/plugin-node-resolve": "13.0.6",
19
+ "@rollup/plugin-commonjs": "21.0.1",
20
+ "@rollup/plugin-node-resolve": "13.1.1",
21
21
  "@rollup/plugin-replace": "3.0.0",
22
22
  "autoprefixer": "10.4.0",
23
23
  "babel-eslint": "10.1.0",
@@ -26,14 +26,16 @@
26
26
  "copyfiles": "2.4.1",
27
27
  "cross-env": "7.0.3",
28
28
  "cssnano": "5.0.12",
29
- "postcss": "8.4.4",
30
- "rollup": "2.60.2",
29
+ "postcss": "8.4.5",
30
+ "rollup": "2.61.1",
31
31
  "rollup-plugin-istanbul": "3.0.0",
32
32
  "rollup-plugin-terser": "7.0.2",
33
- "sass": "1.44.0"
33
+ "sass": "1.45.0",
34
+ "svg-sprite": "1.5.3",
35
+ "svgo": "2.8.0"
34
36
  },
35
37
  "engines": {
36
38
  "node": ">=12.0.0"
37
39
  },
38
- "gitHead": "39a52d25c36789a0c4712b0f6e55cbc5cbbedcb5"
40
+ "gitHead": "07ff24de8a209d80750a32cd52dfe9663fabf8e2"
39
41
  }
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");
@@ -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,82 @@
1
+ /**
2
+ * Generate svg sprites.
3
+ *
4
+ * @param {string} entry - Path 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: path.resolve(nodeModules, "bootstrap-icons/icons/"),
13
+ * dest: path.resolve(outputFolder, "icons/"),
14
+ * options: {
15
+ * file: "bcl-default-icons.svg",
16
+ * list: myList,
17
+ * transformPlugins: (array of svgo plugins objects)
18
+ * },
19
+ * },
20
+ * ],
21
+ */
22
+
23
+ const fs = require("fs");
24
+ const glob = require("glob");
25
+ const mkdirp = require("mkdirp");
26
+ const path = require("path");
27
+ const defaultPlugins = require("../conf/svgoDefaultPlugins");
28
+ const SVGSpriter = require("svg-sprite");
29
+
30
+ module.exports = (entry, dest, options) => {
31
+ const outputFile = options.file
32
+ ? `${dest}/${options.file}`
33
+ : `${dest}/'bcl-icons.svg`;
34
+ const files = options.list || glob.sync("*.svg", { cwd: entry });
35
+
36
+ const plugins = options.transformPlugins || defaultPlugins;
37
+
38
+ const spriter = new SVGSpriter({
39
+ dest,
40
+ shape: {
41
+ transform: [
42
+ {
43
+ svgo: {
44
+ multipass: true,
45
+ plugins: plugins,
46
+ },
47
+ },
48
+ ],
49
+ },
50
+ svg: {
51
+ namespaceClassnames: false,
52
+ xmlDeclaration: false,
53
+ },
54
+ mode: {
55
+ symbol: {
56
+ dest: "",
57
+ sprite: outputFile,
58
+ },
59
+ },
60
+ });
61
+
62
+ files.forEach((file) => {
63
+ const filePath = path.resolve(entry, file);
64
+ spriter.add(
65
+ filePath,
66
+ file,
67
+ fs.readFileSync(filePath, { encoding: "utf-8" })
68
+ );
69
+ });
70
+
71
+ spriter.compile((error, result, data) => {
72
+ Object.keys(result).forEach((mode) => {
73
+ Object.keys(result[mode]).forEach((resource) => {
74
+ mkdirp.sync(path.dirname(result[mode][resource].path));
75
+ fs.writeFileSync(
76
+ result[mode][resource].path,
77
+ result[mode][resource].contents
78
+ );
79
+ });
80
+ });
81
+ });
82
+ };
package/scripts/styles.js CHANGED
@@ -1,3 +1,24 @@
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");