@openeuropa/bcl-builder 0.11.0 → 0.15.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/bin/build.js +11 -0
- package/package.json +9 -9
- package/scripts/rename.js +93 -0
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 rename = require("../scripts/rename");
|
|
8
9
|
const copyFiles = require("../scripts/copy");
|
|
9
10
|
const pkg = require("../package.json");
|
|
10
11
|
|
|
@@ -65,6 +66,16 @@ program
|
|
|
65
66
|
);
|
|
66
67
|
});
|
|
67
68
|
|
|
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
|
+
});
|
|
78
|
+
|
|
68
79
|
// If no arguments provided, display help menu.
|
|
69
80
|
if (process.argv.slice(2).length <= 0) {
|
|
70
81
|
program.help();
|
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.
|
|
5
|
+
"version": "0.15.0",
|
|
6
6
|
"description": "Bootstrap Component Library builder",
|
|
7
7
|
"publishConfig": {
|
|
8
8
|
"access": "public"
|
|
@@ -11,23 +11,23 @@
|
|
|
11
11
|
"bcl-builder": "./bin/build.js"
|
|
12
12
|
},
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"@babel/core": "7.
|
|
15
|
-
"@babel/preset-env": "7.
|
|
16
|
-
"@babel/runtime": "7.
|
|
14
|
+
"@babel/core": "7.16.0",
|
|
15
|
+
"@babel/preset-env": "7.16.0",
|
|
16
|
+
"@babel/runtime": "7.16.3",
|
|
17
17
|
"@popperjs/core": "2.10.2",
|
|
18
18
|
"@rollup/plugin-babel": "5.3.0",
|
|
19
19
|
"@rollup/plugin-commonjs": "20.0.0",
|
|
20
20
|
"@rollup/plugin-node-resolve": "13.0.6",
|
|
21
21
|
"@rollup/plugin-replace": "3.0.0",
|
|
22
|
-
"autoprefixer": "10.
|
|
22
|
+
"autoprefixer": "10.4.0",
|
|
23
23
|
"babel-eslint": "10.1.0",
|
|
24
|
-
"browser-sync": "2.27.
|
|
24
|
+
"browser-sync": "2.27.7",
|
|
25
25
|
"commander": "8.3.0",
|
|
26
26
|
"copyfiles": "2.4.1",
|
|
27
27
|
"cross-env": "7.0.3",
|
|
28
|
-
"cssnano": "5.0.
|
|
28
|
+
"cssnano": "5.0.10",
|
|
29
29
|
"postcss": "8.3.11",
|
|
30
|
-
"rollup": "2.
|
|
30
|
+
"rollup": "2.59.0",
|
|
31
31
|
"rollup-plugin-istanbul": "3.0.0",
|
|
32
32
|
"rollup-plugin-terser": "7.0.2",
|
|
33
33
|
"sass": "1.43.4"
|
|
@@ -35,5 +35,5 @@
|
|
|
35
35
|
"engines": {
|
|
36
36
|
"node": ">=12.0.0"
|
|
37
37
|
},
|
|
38
|
-
"gitHead": "
|
|
38
|
+
"gitHead": "97a9f0822ee0d4d800e40aa17bf87dc698c5906c"
|
|
39
39
|
}
|
|
@@ -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 glob = 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 = glob.sync(path.join(from, options.glob, options.search));
|
|
36
|
+
} else {
|
|
37
|
+
files = glob.sync(path.join(from, options.glob));
|
|
38
|
+
}
|
|
39
|
+
} else {
|
|
40
|
+
if (options.search) {
|
|
41
|
+
files = glob.sync(path.join(from, options.search));
|
|
42
|
+
} else {
|
|
43
|
+
files = glob.sync(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
|
+
};
|