|
| 1 | +import fs from 'node:fs/promises'; |
1 | 2 | import path from 'node:path'; |
2 | 3 | import { runCopy } from './copy'; |
3 | 4 | import { runReadmeFooter } from './readmeFooter'; |
| 5 | +import { findWorkspaceRoot } from './workspace'; |
| 6 | + |
| 7 | +async function resolveRootFile(root: string | null, filename: string): Promise<string | null> { |
| 8 | + if (!root) return null; |
| 9 | + const filePath = path.join(root, filename); |
| 10 | + try { |
| 11 | + await fs.access(filePath); |
| 12 | + return filePath; |
| 13 | + } catch { |
| 14 | + return null; |
| 15 | + } |
| 16 | +} |
4 | 17 |
|
5 | 18 | export async function runAssets(_args: string[]) { |
6 | | - // assumes we are in the package dir, LICENSE lives two levels up |
7 | | - await runCopy(['../../LICENSE', 'package.json', 'dist', '--flat']); |
8 | | - |
9 | | - // README + FOOTER -> dist/README.md |
10 | | - await runReadmeFooter([ |
11 | | - '--source', 'README.md', |
12 | | - '--footer', '../../FOOTER.md', |
13 | | - '--dest', path.join('dist', 'README.md') |
14 | | - ]); |
| 19 | + const root = await findWorkspaceRoot(process.cwd()); |
| 20 | + const licensePath = await resolveRootFile(root, 'LICENSE'); |
| 21 | + const footerPath = await resolveRootFile(root, 'FOOTER.md'); |
| 22 | + |
| 23 | + if (licensePath) { |
| 24 | + await runCopy([licensePath, 'package.json', 'dist', '--flat']); |
| 25 | + } else { |
| 26 | + await runCopy(['package.json', 'dist', '--flat']); |
| 27 | + console.log('[makage] no LICENSE found at workspace root, skipping'); |
| 28 | + } |
| 29 | + |
| 30 | + if (footerPath) { |
| 31 | + await runReadmeFooter([ |
| 32 | + '--source', 'README.md', |
| 33 | + '--footer', footerPath, |
| 34 | + '--dest', path.join('dist', 'README.md') |
| 35 | + ]); |
| 36 | + } else { |
| 37 | + await runCopy(['README.md', 'dist', '--flat']); |
| 38 | + } |
15 | 39 | } |
0 commit comments