feat(pkg): Add core extensions package
This commit is contained in:
52
packages/core-extensions/scripts/generate-exports.js
Normal file
52
packages/core-extensions/scripts/generate-exports.js
Normal file
@@ -0,0 +1,52 @@
|
||||
import fs from 'node:fs'
|
||||
import path from 'node:path'
|
||||
import { fileURLToPath } from 'node:url'
|
||||
|
||||
const __filename = fileURLToPath(import.meta.url)
|
||||
const __dirname = path.dirname(__filename)
|
||||
const srcDir = path.resolve(__dirname, '../src')
|
||||
const distDir = 'dist'
|
||||
const pkgPath = path.resolve(__dirname, '../package.json')
|
||||
|
||||
function walk(dir) {
|
||||
let result = []
|
||||
const entries = fs.readdirSync(dir, { withFileTypes: true })
|
||||
|
||||
for (const entry of entries) {
|
||||
const fullPath = path.join(dir, entry.name)
|
||||
if (entry.isDirectory()) {
|
||||
result = result.concat(walk(fullPath))
|
||||
} else if (entry.isFile() && entry.name.endsWith('.ts') && !entry.name.endsWith('.d.ts')) {
|
||||
result.push(fullPath)
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
function toSubpath(filePath) {
|
||||
const relativePath = path.relative(srcDir, filePath).replace(/\.ts$/, '')
|
||||
return relativePath.replace(/\\/g, '/') // For Windows compatibility
|
||||
}
|
||||
|
||||
function updatePackageJson() {
|
||||
const packageJson = JSON.parse(fs.readFileSync(pkgPath, 'utf8'))
|
||||
const files = walk(srcDir)
|
||||
|
||||
const exportsMap = {}
|
||||
|
||||
files.forEach((file) => {
|
||||
const subpath = toSubpath(file)
|
||||
exportsMap[`./${subpath}`] = {
|
||||
import: `./${distDir}/${subpath}.js`,
|
||||
types: `./${distDir}/${subpath}.d.ts`
|
||||
}
|
||||
})
|
||||
|
||||
packageJson.exports = exportsMap
|
||||
|
||||
fs.writeFileSync(pkgPath, JSON.stringify(packageJson, null, 2))
|
||||
console.log('✅ Modern exports updated in package.json')
|
||||
}
|
||||
|
||||
updatePackageJson()
|
||||
Reference in New Issue
Block a user