-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathrun.ts
39 lines (31 loc) · 1.09 KB
/
run.ts
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
import fs from 'node:fs';
import glob from 'fast-glob';
import type { AcceptedPlugin } from 'postcss';
import postcss from 'postcss';
import { readFile } from '../../../utils.js';
type CssCodemodProps = {
plugins: AcceptedPlugin[];
globPattern?: string;
};
export const runCssCodemod = async ({ plugins = [], globPattern = './**/*.css' }: CssCodemodProps) => {
const processor = postcss(plugins);
const transform = async () => {
console.log(`Running migration in ${globPattern}`);
const files = await glob([globPattern], {
ignore: ['**/node_modules/**', '**/dist/**'], // TODO: Not working as expected
absolute: true,
});
const filePromises = files.map(async (file) => {
if (file.includes('node_modules') || file.includes('dist')) {
// console.log(`Skipping ${file}`);
return;
}
const contents = readFile(file).toString();
const result = await processor.process(contents, { from: file });
fs.writeFileSync(file, result.css);
});
await Promise.all(filePromises);
};
// Run the transform.
return transform();
};