Skip to content

Commit 2078a5a

Browse files
committed
fix: 清理优化
1 parent 66efee3 commit 2078a5a

1 file changed

Lines changed: 10 additions & 47 deletions

File tree

clean.ts

Lines changed: 10 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,27 @@
1-
import fs from 'fs-extra'
2-
import { join, parse } from 'path'
31
import childProcess from 'child_process'
4-
import globby from 'globby'
2+
import { join } from 'path'
53

64
async function clean(rootDir: string) {
7-
const projectFilePath = join.bind(null, rootDir)
8-
const pkgFilePath = join.bind(null, projectFilePath('node_modules'))
9-
10-
// 需要保留的文件列表
11-
const reservedFiles = [
12-
pkgFilePath('react/cjs/react.production.min.js'),
13-
pkgFilePath('react-dom/cjs/react-dom.production.min.js'),
14-
pkgFilePath('react-is/cjs/react-is.production.min.js'),
15-
pkgFilePath('scheduler/cjs/scheduler.production.min.js'),
16-
pkgFilePath('history/cjs/history.min.js'),
17-
pkgFilePath('resolve-pathname/cjs/resolve-pathname.min.js'),
18-
pkgFilePath('value-equal/cjs/value-equal.min.js'),
19-
pkgFilePath('jsondiffpatch/dist/jsondiffpatch.umd.js'),
20-
pkgFilePath('ajv-i18n/localize/es'),
21-
pkgFilePath('svgo/.svgo.yml'),
22-
pkgFilePath('.bin'),
23-
...(await globby('**/*.min.*', {
24-
absolute: true,
25-
cwd: rootDir,
26-
ignore: ['**/node_modules/**'],
27-
})),
28-
].map((filePath) => {
29-
const { dir, base } = parse(filePath)
30-
return {
31-
from: filePath,
32-
to: join(dir, 'r_' + base.replace(/\./g, '')),
33-
}
34-
})
35-
36-
await Promise.all(
37-
reservedFiles.map(async ({ from, to }) => {
38-
await fs.rename(from, to).catch(() => {})
39-
}),
40-
)
5+
const binPath = join(rootDir, `node_modules/.bin`)
6+
const binTmpPath = join(rootDir, `node_modules/tmp@.bin`)
417

428
childProcess.execSync(
439
`
4410
cd ${rootDir}
4511
shopt -s globstar
12+
yarn cache clean
13+
mv ${binPath} ${binTmpPath}
4614
rm -rf \\
47-
**/*.{map,lock,log,md,yml,yaml,ts,txt} \\
15+
**/*.{map,lock,log,md,yml,yaml,ts,tsx,vue,txt} \\
4816
**/.[!.]* \\
4917
**/__*__ \\
50-
**/{tsconfig.json,package-lock.json,Makefile,CHANGELOG} \\
51-
**/*.{test,spec,min,umd,es,esm}.* \\
52-
**/{test,tests,example,examples,doc,docs,coverage,demo,umd,es,esm}/
18+
**/{tsconfig.json,package-lock.json,Makefile,CHANGELOG,.DS_Store} \\
19+
**/*.{test,spec,es,esm}.* \\
20+
**/{test,tests,example,examples,doc,docs,coverage,demo,es,esm}/
21+
mv ${binTmpPath} ${binPath}
5322
`,
5423
{ shell: '/bin/bash' },
5524
)
56-
57-
await Promise.all(
58-
reservedFiles.map(async ({ from, to }) => {
59-
await fs.rename(to, from).catch(() => {})
60-
}),
61-
)
6225
}
6326

6427
clean(process.argv[2])

0 commit comments

Comments
 (0)