Skip to content

Commit

Permalink
build(cli): fix deps & pack the scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
Chilfish committed Apr 5, 2024
1 parent 47724ef commit 5f5bd15
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 16 deletions.
13 changes: 0 additions & 13 deletions apps/cli/build.config.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
import { defineBuildConfig } from 'unbuild'

const inShared = [
'axios',
'p-queue',
'@weibo-archiver/shared',
]

export default defineBuildConfig({
entries: [{
input: 'src/index.ts',
Expand All @@ -19,12 +13,5 @@ export default defineBuildConfig({
esbuild: {
target: 'esnext',
},
output: {
// 打包 @weibo-archiver/shared 依赖,会 tree-shaking
manualChunks(id: string) {
if (inShared.some(dep => id.includes(dep)))
return 'vendor'
},
},
},
})
16 changes: 14 additions & 2 deletions apps/cli/build.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { readFile, writeFile } from 'node:fs/promises'
import { copyFile, readFile, readdir, rm, writeFile } from 'node:fs/promises'
import path from 'node:path'
import { execSync } from 'node:child_process'

const dist = path.relative(path.resolve(), 'dist')
const root = path.resolve(path.resolve(), '../../')

const pkg = await readFile('package.json', 'utf-8')
// 移除 dist 前缀
.then(data => data.replace(/dist\/?/gm, ''))
.then(data => data.replace(/dist\//gm, ''))
// 移除 devDependencies
.then(data => JSON.parse(data))
.then((data) => {
Expand All @@ -22,3 +24,13 @@ execSync('cd dist && npm install', { stdio: 'inherit' })

const readme = await readFile('README.md', 'utf-8')
await writeFile(path.join(dist, 'README.md'), readme)

await rm(path.join(dist, 'package-lock.json'))

// 复制 scripts 的下载图片脚本
const scripts = path.join(root, 'scripts')
const files = await readdir(scripts)
for (const file of files) {
if (file.endsWith('.mjs'))
await copyFile(path.join(scripts, file), path.join(dist, file))
}
4 changes: 4 additions & 0 deletions apps/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
"lint": "eslint .",
"start": "node weibo-archiver.mjs"
},
"peerDependencies": {
"axios": "^1.6.8",
"p-queue": "^8.0.1"
},
"dependencies": {
"c12": "^1.10.0",
"citty": "^0.1.6",
Expand Down
1 change: 1 addition & 0 deletions packages/shared/src/types/auto-imports.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ declare global {
const imgsParser: typeof import('../parse')['imgsParser']
const inject: typeof import('vue')['inject']
const injectLocal: typeof import('@vueuse/core')['injectLocal']
const isBrowser: typeof import('../index')['isBrowser']
const isDark: typeof import('../../../core/src/composables/index')['isDark']
const isDefined: typeof import('@vueuse/core')['isDefined']
const isElectron: typeof import('../../../core/src/utils/index')['isElectron']
Expand Down
8 changes: 7 additions & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 5f5bd15

Please sign in to comment.