forked from innovaccer/design-system
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrollupPlugin.js
More file actions
43 lines (38 loc) · 1.32 KB
/
rollupPlugin.js
File metadata and controls
43 lines (38 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import fs from 'fs';
import path from 'path';
export function concatTokenCSS(directories, files) {
return {
name: 'concat-token-css',
generateBundle(options, bundle) {
let concatenatedCSSContent = '';
// Iterate over each directory
directories.forEach(directory => {
// Read all files in the specified directory
const dirFiles = fs.readdirSync(directory);
// Filter and read the contents of CSS files
dirFiles.forEach(file => {
if (file.endsWith('.css')) {
const absolutePath = path.resolve(directory, file);
const fileContent = fs.readFileSync(absolutePath, 'utf8');
concatenatedCSSContent += `${fileContent}\n`;
}
});
});
// Iterate over each file
files.forEach(file => {
if (file.endsWith('.css')) {
const absolutePath = path.resolve(file);
const fileContent = fs.readFileSync(absolutePath, 'utf8');
concatenatedCSSContent += `${fileContent}\n`;
}
});
// Append the concatenated content to the resultant CSS file
for (const fileName of Object.keys(bundle)) {
if (fileName.endsWith('.css')) {
const asset = bundle[fileName];
asset.source = `${concatenatedCSSContent}${asset.source}`;
}
}
}
};
}