-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild-content-replacer.js
50 lines (39 loc) · 1.46 KB
/
build-content-replacer.js
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
44
45
46
47
48
49
50
/* eslint-disable no-console */
import fs from 'fs';
import path from 'path';
import {glob} from 'glob';
const replaceRules = [
{
before: '(,\\s*["\']data-testid["\']\\s*:\\s*["\'][^"\']*["\'])|(\\s*["\']data-testid["\']\\s*:\\s*["\'][^"\']*["\']\\s*,?)',
after: '',
},
{
before: '~style/designToken/ThemeToken.module.scss',
after: 'tksui-components/lib/styles/ThemeToken.module.css',
},
];
const replaceContent = async (filePath) => {
let fileContent = await fs.promises.readFile(filePath, 'utf8');
replaceRules.forEach((rule) => {
const regex = new RegExp(rule.before, 'g');
fileContent = fileContent.replace(regex, rule.after);
});
await fs.promises.writeFile(filePath, fileContent, 'utf8');
};
const replaceBuildContents = async () => {
const absolutePath = path.resolve('lib/esm/src/components/**/T*.js');
const ignorePattern = '**/*.interface.js';
try {
const files = glob.sync(absolutePath, {nodir: true, ignore: ignorePattern});
console.log('Files found:', files);
// eslint-disable-next-line no-restricted-syntax
for (const file of files) {
// eslint-disable-next-line no-await-in-loop
await replaceContent(file);
}
console.log('ThemToken path replacement complete.');
} catch (err) {
console.error('Error finding files:', err);
}
};
replaceBuildContents().then(() => { /* Nothing to do */ });