|
| 1 | +import fs from 'node:fs' |
| 2 | +import path from 'node:path' |
| 3 | +import process from 'node:process' |
| 4 | + |
| 5 | +const PKG_ROOT = path.resolve(import.meta.dirname, '..') |
| 6 | +const SRC_STYLES = path.join(PKG_ROOT, 'src', 'styles') |
| 7 | +const DIST_STYLES = path.join(PKG_ROOT, 'dist', 'styles') |
| 8 | +const SHADCN_STYLES = path.resolve(PKG_ROOT, '..', 'shadcn', 'styles') |
| 9 | + |
| 10 | +// 1. Copy src/styles/ assets to dist/styles/ |
| 11 | +fs.mkdirSync(DIST_STYLES, { recursive: true }) |
| 12 | + |
| 13 | +fs.copyFileSync( |
| 14 | + path.join(SRC_STYLES, 'root.css'), |
| 15 | + path.join(DIST_STYLES, 'root.css'), |
| 16 | +) |
| 17 | + |
| 18 | +fs.copyFileSync( |
| 19 | + path.join(SRC_STYLES, 'fonts.css'), |
| 20 | + path.join(DIST_STYLES, 'fonts.css'), |
| 21 | +) |
| 22 | + |
| 23 | +fs.cpSync( |
| 24 | + path.join(SRC_STYLES, 'fonts'), |
| 25 | + path.join(DIST_STYLES, 'fonts'), |
| 26 | + { recursive: true }, |
| 27 | +) |
| 28 | + |
| 29 | +fs.cpSync( |
| 30 | + path.join(SRC_STYLES, 'tokens'), |
| 31 | + path.join(DIST_STYLES, 'tokens'), |
| 32 | + { recursive: true }, |
| 33 | +) |
| 34 | + |
| 35 | +fs.cpSync( |
| 36 | + path.join(SRC_STYLES, 'themes'), |
| 37 | + path.join(DIST_STYLES, 'themes'), |
| 38 | + { recursive: true }, |
| 39 | +) |
| 40 | + |
| 41 | +// 2. Copy shadcn CSS to dist/styles/shadcn/ |
| 42 | +const DIST_SHADCN = path.join(DIST_STYLES, 'shadcn') |
| 43 | +fs.mkdirSync(DIST_SHADCN, { recursive: true }) |
| 44 | + |
| 45 | +fs.copyFileSync( |
| 46 | + path.join(SHADCN_STYLES, 'shadcn.css'), |
| 47 | + path.join(DIST_SHADCN, 'shadcn.css'), |
| 48 | +) |
| 49 | + |
| 50 | +fs.copyFileSync( |
| 51 | + path.join(SHADCN_STYLES, 'animations.css'), |
| 52 | + path.join(DIST_SHADCN, 'animations.css'), |
| 53 | +) |
| 54 | + |
| 55 | +// 3. Rewrite import path in dist/styles/root.css |
| 56 | +const rootCssPath = path.join(DIST_STYLES, 'root.css') |
| 57 | +const rootCss = fs.readFileSync(rootCssPath, 'utf-8') |
| 58 | +const rewritten = rootCss.replace( |
| 59 | + '@import \'@repo/shadcn/styles/shadcn.css\'', |
| 60 | + '@import \'./shadcn/shadcn.css\'', |
| 61 | +) |
| 62 | +fs.writeFileSync(rootCssPath, rewritten, 'utf-8') |
| 63 | + |
| 64 | +// Validate no @repo/ references remain |
| 65 | +if (rewritten.includes('@repo/')) { |
| 66 | + console.error('ERROR: Unrewritten @repo/ imports remain in dist/styles/root.css') |
| 67 | + process.exit(1) |
| 68 | +} |
| 69 | + |
| 70 | +// 4. Copy component CSS to separate export locations |
| 71 | +const componentCopies = [ |
| 72 | + { |
| 73 | + src: path.join(PKG_ROOT, 'src', 'components', 'features', 'grid', 'style.css'), |
| 74 | + dest: path.join(PKG_ROOT, 'dist', 'grid', 'style.css'), |
| 75 | + }, |
| 76 | + { |
| 77 | + src: path.join(PKG_ROOT, 'src', 'components', 'features', 'nprogress', 'nprogress.css'), |
| 78 | + dest: path.join(PKG_ROOT, 'dist', 'nprogress', 'nprogress.css'), |
| 79 | + }, |
| 80 | +] |
| 81 | + |
| 82 | +for (const { src, dest } of componentCopies) { |
| 83 | + fs.mkdirSync(path.dirname(dest), { recursive: true }) |
| 84 | + fs.copyFileSync(src, dest) |
| 85 | +} |
| 86 | + |
| 87 | +console.log('Styles copied to dist/') |
0 commit comments