-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
147 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,13 @@ | ||
import { exists, readdir, unlink } from 'node:fs/promises' | ||
import dts from 'bun-plugin-dts' | ||
import { build } from './common' | ||
|
||
const rmDist = async () => { | ||
const hasDist = await exists('./dist') | ||
if (hasDist) { | ||
const distFiles = await readdir('./dist') | ||
const rmFiles = distFiles.map((file) => { | ||
return unlink(`./dist/${file}`) | ||
}) | ||
const result = await build() | ||
|
||
await Promise.all(rmFiles) | ||
} | ||
} | ||
|
||
export const getEntrypoints = async () => { | ||
const files = await readdir('./src') | ||
const entrypoints = files | ||
.filter((file) => !file.includes('_')) | ||
.map((file) => `./src/${file}`) | ||
|
||
return entrypoints | ||
} | ||
|
||
const runBuild = async () => { | ||
if (result.success) { | ||
// biome-ignore lint/suspicious/noConsoleLog: <explanation> | ||
console.log('📦 打包中...') | ||
await rmDist() | ||
const entrypoints = await getEntrypoints() | ||
const result = await Bun.build({ | ||
entrypoints, | ||
outdir: './dist', | ||
naming: '[name].[ext]', | ||
splitting: true, | ||
minify: true, | ||
format: 'esm', | ||
plugins: [dts()], | ||
}) | ||
|
||
if (result.success) { | ||
// biome-ignore lint/suspicious/noConsoleLog: <explanation> | ||
console.log('📦 打包成功 🎉🎉🎉') | ||
} else { | ||
// biome-ignore lint/suspicious/noConsoleLog: <explanation> | ||
console.log('📦 打包失败 🚨\n') | ||
// biome-ignore lint/suspicious/noConsoleLog: <explanation> | ||
console.log(result.logs) | ||
} | ||
console.log('📦 打包成功 🎉🎉🎉') | ||
} else { | ||
// biome-ignore lint/suspicious/noConsoleLog: <explanation> | ||
console.log('📦 打包失败 🚨\n') | ||
// biome-ignore lint/suspicious/noConsoleLog: <explanation> | ||
console.log(result.logs) | ||
} | ||
|
||
runBuild() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
import { exists, readdir, unlink } from 'node:fs/promises' | ||
import dts from 'bun-plugin-dts' | ||
|
||
/** | ||
* 删除dist 目录 | ||
*/ | ||
export const rmDist = async () => { | ||
const hasDist = await exists('./dist') | ||
if (hasDist) { | ||
const distFiles = await readdir('./dist') | ||
const rmFiles = distFiles.map((file) => { | ||
return unlink(`./dist/${file}`) | ||
}) | ||
|
||
await Promise.all(rmFiles) | ||
} | ||
} | ||
|
||
/** | ||
* 获取入口文件 | ||
*/ | ||
const getEntrypoints = async () => { | ||
const files = await readdir('./src') | ||
const entrypoints = files | ||
.filter((file) => !file.includes('_')) | ||
.map((file) => `./src/${file}`) | ||
|
||
return entrypoints | ||
} | ||
|
||
/** | ||
* 打包 | ||
*/ | ||
export const build = async () => { | ||
// biome-ignore lint/suspicious/noConsoleLog: <explanation> | ||
console.log('📦 打包中...') | ||
await rmDist() | ||
const entrypoints = await getEntrypoints() | ||
return await Bun.build({ | ||
entrypoints, | ||
outdir: './dist', | ||
naming: '[name].[ext]', | ||
splitting: true, | ||
minify: true, | ||
format: 'esm', | ||
plugins: [dts()], | ||
}) | ||
} | ||
|
||
/** | ||
* npm发布 | ||
*/ | ||
export const npmPublish = async () => { | ||
await Bun.$`bunx standard-version` | ||
await Bun.$`npm publish` | ||
} | ||
|
||
/** | ||
* 获取jsr导出路径 | ||
*/ | ||
const getExports = async () => { | ||
const files = await readdir('./src') | ||
const exports = files | ||
.filter((file) => !file.includes('_')) | ||
.reduce((prev, file) => { | ||
if (file === 'index.ts') { | ||
return { ...prev, '.': './src/index.ts' } | ||
} | ||
|
||
return { | ||
...prev, | ||
[`./${file.replace('.ts', '')}`]: `./src/${file}`, | ||
} | ||
}, {}) | ||
|
||
return exports | ||
} | ||
|
||
/** | ||
* jsr发布 | ||
*/ | ||
export const jsrPublish = async () => { | ||
const pkg = await Bun.file('./package.json').json() | ||
const jsr = await Bun.file('./jsr.json').json() | ||
|
||
if (jsr.version === pkg.version) { | ||
// biome-ignore lint/suspicious/noConsoleLog: <explanation> | ||
console.log('无新版本发布') | ||
return | ||
} | ||
|
||
const exports = await getExports() | ||
const jsrConfig = { | ||
name: pkg.name, | ||
version: pkg.version, | ||
exports, | ||
} | ||
|
||
await Bun.write('./jsr.json', JSON.stringify(jsrConfig, null, 2)) | ||
await Bun.$`bunx jsr publish --allow-dirty` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { build, jsrPublish, npmPublish } from './common' | ||
|
||
const result = await build() | ||
|
||
if (result.success) { | ||
// biome-ignore lint/suspicious/noConsoleLog: <explanation> | ||
console.log('📦 打包成功 🎉🎉🎉') | ||
await npmPublish() | ||
await jsrPublish() | ||
await Bun.$`git push origin --follow-tags` | ||
} else { | ||
// biome-ignore lint/suspicious/noConsoleLog: <explanation> | ||
console.log('📦 打包失败 🚨\n') | ||
// biome-ignore lint/suspicious/noConsoleLog: <explanation> | ||
console.log(result.logs) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,3 @@ | ||
import { readdir } from 'node:fs/promises' | ||
import { jsrPublish } from './common' | ||
|
||
const pkg = await Bun.file('./package.json').json() | ||
|
||
const getExports = async () => { | ||
const files = await readdir('./src') | ||
const exports = files | ||
.filter((file) => !file.includes('_')) | ||
.reduce((prev, file) => { | ||
if (file === 'index.ts') { | ||
return { ...prev, '.': './src/index.ts' } | ||
} | ||
|
||
return { | ||
...prev, | ||
[`./${file.replace('.ts', '')}`]: `./src/${file}`, | ||
} | ||
}, {}) | ||
|
||
return exports | ||
} | ||
|
||
const exports = await getExports() | ||
const jsrConfig = { | ||
name: pkg.name, | ||
version: pkg.version, | ||
exports, | ||
} | ||
|
||
await Bun.write('./jsr.json', JSON.stringify(jsrConfig, null, 2)) | ||
|
||
await Bun.$`bunx jsr publish --allow-dirty` | ||
jsrPublish() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { build, npmPublish } from './common' | ||
|
||
const result = await build() | ||
|
||
if (result.success) { | ||
// biome-ignore lint/suspicious/noConsoleLog: <explanation> | ||
console.log('📦 打包成功 🎉🎉🎉') | ||
await npmPublish() | ||
await Bun.$`git push origin --follow-tags` | ||
} else { | ||
// biome-ignore lint/suspicious/noConsoleLog: <explanation> | ||
console.log('📦 打包失败 🚨\n') | ||
// biome-ignore lint/suspicious/noConsoleLog: <explanation> | ||
console.log(result.logs) | ||
} |