Skip to content

Commit

Permalink
build: update build scripts (#244)
Browse files Browse the repository at this point in the history
  • Loading branch information
climba03003 authored Sep 13, 2024
1 parent 489514d commit 65dd4e9
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 34 deletions.
3 changes: 0 additions & 3 deletions packages/config/lib/mjs/package.json

This file was deleted.

3 changes: 0 additions & 3 deletions packages/cronjob/lib/mjs/package.json

This file was deleted.

3 changes: 0 additions & 3 deletions packages/mongodb/lib/mjs/package.json

This file was deleted.

3 changes: 0 additions & 3 deletions packages/multipart/lib/mjs/package.json

This file was deleted.

3 changes: 0 additions & 3 deletions packages/oauth2/lib/mjs/package.json

This file was deleted.

33 changes: 14 additions & 19 deletions scripts/build.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,20 @@ const { values } = parseArgs({
}
})

function isBuildAsset (name) {
function isBuildAsset(name) {
return String(name).endsWith('.js') ||
String(name).endsWith('.cjs') ||
String(name).endsWith('.mjs') ||
String(name).endsWith('.map') ||
String(name).endsWith('.d.ts') ||
String(name).endsWith('.d.cts') ||
String(name).endsWith('.d.mts')
String(name).endsWith('.cjs') ||
String(name).endsWith('.mjs') ||
String(name).endsWith('.map') ||
String(name).endsWith('.d.ts') ||
String(name).endsWith('.d.cts') ||
String(name).endsWith('.d.mts')
}

async function clean () {
async function clean() {
// remove ESM folder
await fs.rm(path.resolve('lib', 'mjs'), { recursive: true, force: true })

for (const file of await fs.readdir(path.resolve('lib'), { recursive: true })) {
if (isBuildAsset(file)) {
await fs.rm(path.resolve('lib', file), { force: true })
Expand All @@ -35,25 +38,17 @@ async function clean () {
}
}

async function build (mode = 'all') {
async function build(mode = 'all') {
if (mode === 'all' || mode === 'cjs') {
console.log('build cjs - start')
execSync('tsc -p tsconfig.cjs.json', { stdio: 'pipe' })
// for (const file of await fs.readdir(path.resolve('lib'), { recursive: true })) {
// if (isBuildAsset(file)) {
// await fs.rename(path.resolve('lib', file), path.resolve('lib', file).replace('.js', '.cjs').replace('.d.ts', '.d.cts'))
// }
// }
console.log('build cjs - end')
}
if (mode === 'all' || mode === 'mjs') {
console.log('build mjs - start')
await fs.mkdir(path.resolve('lib', 'mjs'), { recursive: true })
await fs.writeFile(path.resolve('lib', 'mjs', 'package.json'), JSON.stringify({ type: 'module' }, null, 2))
execSync('tsc -p tsconfig.mjs.json', { stdio: 'pipe' })
// for (const file of await fs.readdir(path.resolve('lib'), { recursive: true })) {
// if (isBuildAsset(file)) {
// await fs.rename(path.resolve('lib', file), path.resolve('lib', file).replace('.js', '.mjs').replace('.d.ts', '.d.mts'))
// }
// }
execSync('tsc-alias -p tsconfig.mjs.json', { stdio: 'pipe' })
console.log('build mjs - end')
}
Expand Down

0 comments on commit 65dd4e9

Please sign in to comment.