mirror of
https://github.com/zoriya/v10.git
synced 2026-08-16 02:45:09 +00:00
chore(root): migrate build scripts and plugins to TypeScript (#1052)
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
import { globSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
||||
import { dirname, join } from 'node:path';
|
||||
import { resolveImports } from './resolve-css-imports.ts';
|
||||
import type { BuildPlugin } from './types.ts';
|
||||
|
||||
interface CopyCssPluginOptions {
|
||||
skinsDir: string;
|
||||
outDir: string;
|
||||
}
|
||||
|
||||
export function copyCssPlugin(options: CopyCssPluginOptions): BuildPlugin {
|
||||
const { skinsDir, outDir } = options;
|
||||
|
||||
return {
|
||||
name: 'copy-css',
|
||||
buildStart() {
|
||||
for (const file of globSync('src/**/*.css')) {
|
||||
this.addWatchFile(file);
|
||||
}
|
||||
for (const file of globSync(join(skinsDir, '**/*.css'))) {
|
||||
this.addWatchFile(file);
|
||||
}
|
||||
},
|
||||
writeBundle() {
|
||||
for (const file of globSync('src/**/*.css')) {
|
||||
const content = readFileSync(file, 'utf-8');
|
||||
const resolved = resolveImports(content, dirname(file), skinsDir);
|
||||
const outFile = join(outDir, file.replace(/^src\//, ''));
|
||||
mkdirSync(dirname(outFile), { recursive: true });
|
||||
writeFileSync(outFile, resolved);
|
||||
}
|
||||
},
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user