|
1 | 1 | import { join } from 'node:path'
|
2 | 2 | import { fileURLToPath } from 'node:url'
|
3 |
| -import { readFileSync, writeFileSync, copyFileSync } from 'node:fs' |
| 3 | +import { |
| 4 | + readFileSync, |
| 5 | + writeFileSync, |
| 6 | + copyFileSync, |
| 7 | + existsSync, |
| 8 | + mkdirSync, |
| 9 | + rmSync, |
| 10 | + readdirSync, |
| 11 | +} from 'node:fs' |
4 | 12 |
|
5 | 13 | const packagePath = join('..', '..', 'package.json')
|
6 | 14 | const packageURL = fileURLToPath(new URL(packagePath, import.meta.url))
|
@@ -28,3 +36,58 @@ docFiles.forEach((docFile) => {
|
28 | 36 | const docPackageURL = fileURLToPath(new URL(docPackagePath, import.meta.url))
|
29 | 37 | copyFileSync(docURL, docPackageURL)
|
30 | 38 | })
|
| 39 | + |
| 40 | +// Copy any type declarations that are needed in the distribution |
| 41 | +const typeGroups = [ |
| 42 | + { dir: 'common', files: ['index.d.ts'] }, |
| 43 | + { dir: 'css-animations', files: ['index.d.ts'] }, |
| 44 | + { dir: 'css-utilities', files: ['index.d.ts'] }, |
| 45 | +] |
| 46 | +typeGroups.forEach((typeGroup) => { |
| 47 | + const typeGroupPath = join('..', '..', 'src', typeGroup.dir) |
| 48 | + const typeGroupPackagePath = join('..', '..', 'dist', 'types', typeGroup.dir) |
| 49 | + const typeGroupPackageURL = fileURLToPath( |
| 50 | + new URL(typeGroupPackagePath, import.meta.url) |
| 51 | + ) |
| 52 | + |
| 53 | + if (!existsSync(typeGroupPackageURL)) { |
| 54 | + mkdirSync(typeGroupPackageURL, { recursive: true }) |
| 55 | + } |
| 56 | + |
| 57 | + typeGroup.files.forEach((typeFile) => { |
| 58 | + const typePath = join(typeGroupPath, typeFile) |
| 59 | + const typeURL = fileURLToPath(new URL(typePath, import.meta.url)) |
| 60 | + const typePackagePath = join(typeGroupPackagePath, typeFile) |
| 61 | + const typePackageURL = fileURLToPath( |
| 62 | + new URL(typePackagePath, import.meta.url) |
| 63 | + ) |
| 64 | + copyFileSync(typeURL, typePackageURL) |
| 65 | + }) |
| 66 | +}) |
| 67 | + |
| 68 | +// Remove empty javascript files generated from the type declaration files |
| 69 | +typeGroups.forEach((typeGroup) => { |
| 70 | + const typeGroupPackagePath = join('..', '..', 'dist', typeGroup.dir) |
| 71 | + typeGroup.files.forEach((typeFile) => { |
| 72 | + const typePackagePath = join( |
| 73 | + typeGroupPackagePath, |
| 74 | + typeFile.replace(/\.d\.ts$/, '.d.js') |
| 75 | + ) |
| 76 | + const typePackageURL = fileURLToPath( |
| 77 | + new URL(typePackagePath, import.meta.url) |
| 78 | + ) |
| 79 | + if (existsSync(typePackageURL)) { |
| 80 | + rmSync(typePackageURL) |
| 81 | + } |
| 82 | + }) |
| 83 | + const typeGroupPackageURL = fileURLToPath( |
| 84 | + new URL(typeGroupPackagePath, import.meta.url) |
| 85 | + ) |
| 86 | + if (!existsSync(typeGroupPackageURL)) { |
| 87 | + return |
| 88 | + } |
| 89 | + const typeGroupDir = readdirSync(typeGroupPackageURL) |
| 90 | + if (typeGroupDir.length < 1) { |
| 91 | + rmSync(typeGroupPackageURL, { recursive: true }) |
| 92 | + } |
| 93 | +}) |
0 commit comments