snapshot of https://github.com/dream-num/univer.git (dev, 2026-09-16; blobs > 131072B omitted)
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
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
This commit is contained in:
58
common/shared/tsdown/plugins/output-alias.ts
Normal file
58
common/shared/tsdown/plugins/output-alias.ts
Normal file
@@ -0,0 +1,58 @@
|
||||
import { cpSync, existsSync, mkdirSync, unlinkSync } from 'node:fs';
|
||||
import path from 'node:path';
|
||||
|
||||
interface IBundleOutput {
|
||||
fileName?: string;
|
||||
}
|
||||
|
||||
export interface ICreateOutputAliasPluginOptions {
|
||||
copyToRoot: boolean;
|
||||
keepRootIndexCss: boolean;
|
||||
packageDir: string;
|
||||
}
|
||||
|
||||
export function createOutputAliasPlugin(options: ICreateOutputAliasPluginOptions) {
|
||||
const { copyToRoot, keepRootIndexCss, packageDir } = options;
|
||||
|
||||
return {
|
||||
name: 'create-output-alias',
|
||||
writeBundle(outputOptions: { dir?: string }, bundle: Record<string, IBundleOutput>) {
|
||||
if (!outputOptions.dir) {
|
||||
return;
|
||||
}
|
||||
|
||||
const outDir = path.resolve(packageDir, outputOptions.dir);
|
||||
const rootDir = path.resolve(outDir, '..');
|
||||
|
||||
for (const output of Object.values(bundle)) {
|
||||
if (!output.fileName || output.fileName.endsWith('.map')) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const sourcePath = path.join(outDir, output.fileName);
|
||||
|
||||
if (output.fileName.endsWith('.css')) {
|
||||
if (keepRootIndexCss) {
|
||||
const rootCssPath = path.join(rootDir, 'index.css');
|
||||
mkdirSync(path.dirname(rootCssPath), { recursive: true });
|
||||
cpSync(sourcePath, rootCssPath);
|
||||
}
|
||||
|
||||
if (existsSync(sourcePath)) {
|
||||
unlinkSync(sourcePath);
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!copyToRoot) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const targetPath = path.join(rootDir, output.fileName);
|
||||
mkdirSync(path.dirname(targetPath), { recursive: true });
|
||||
cpSync(sourcePath, targetPath);
|
||||
}
|
||||
},
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user