Files
upstream-mirror bcf6ef63ad
Some checks failed
📦 Build / build (push) Has been cancelled
🧪 CI Test / test shard (1/4) (push) Has been cancelled
🧪 CI Test / test shard (2/4) (push) Has been cancelled
🧪 CI Test / test shard (3/4) (push) Has been cancelled
🧪 CI Test / test shard (4/4) (push) Has been cancelled
🧪 CI Test / test (push) Has been cancelled
🧪 CI Test / eslint (push) Has been cancelled
🧪 CI Test / typecheck (push) Has been cancelled
🔫 Sync to Pro / dispatch-sync (push) Has been cancelled
🔮 Sync Mirror / sync (push) Has been cancelled
snapshot of https://github.com/dream-num/univer.git (dev, 2026-09-16; blobs > 131072B omitted)
2026-09-16 05:09:45 +05:00

61 lines
1.5 KiB
TypeScript

import { existsSync, readdirSync, unlinkSync } from 'node:fs';
import path from 'node:path';
import { SOURCE_DIRECTORY } from '../constants.ts';
/**
* Walks the package source tree and returns whether a given file suffix exists.
*/
export function hasSourceFiles(packageDir: string, extension: string) {
const sourceDir = path.join(packageDir, SOURCE_DIRECTORY);
if (!existsSync(sourceDir)) {
return false;
}
const stack = [sourceDir];
while (stack.length > 0) {
const currentDir = stack.pop()!;
const entries = readdirSync(currentDir, { withFileTypes: true });
for (const entry of entries) {
const fullPath = path.join(currentDir, entry.name);
if (entry.isDirectory()) {
stack.push(fullPath);
continue;
}
if (entry.name.endsWith(extension)) {
return true;
}
}
}
return false;
}
/**
* Removes emitted css artifacts before a new build so alias copies stay deterministic.
*/
export function removeCssArtifacts(dir: string) {
if (!existsSync(dir)) {
return;
}
const entries = readdirSync(dir, { withFileTypes: true });
for (const entry of entries) {
const fullPath = path.join(dir, entry.name);
if (entry.isDirectory()) {
removeCssArtifacts(fullPath);
continue;
}
if (entry.name.endsWith('.css')) {
unlinkSync(fullPath);
}
}
}