|
1 | | -import fs from 'fs-extra' |
2 | | -import { join, parse } from 'path' |
3 | 1 | import childProcess from 'child_process' |
4 | | -import globby from 'globby' |
| 2 | +import { join } from 'path' |
5 | 3 |
|
6 | 4 | 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`) |
41 | 7 |
|
42 | 8 | childProcess.execSync( |
43 | 9 | ` |
44 | 10 | cd ${rootDir} |
45 | 11 | shopt -s globstar |
| 12 | + yarn cache clean |
| 13 | + mv ${binPath} ${binTmpPath} |
46 | 14 | rm -rf \\ |
47 | | - **/*.{map,lock,log,md,yml,yaml,ts,txt} \\ |
| 15 | + **/*.{map,lock,log,md,yml,yaml,ts,tsx,vue,txt} \\ |
48 | 16 | **/.[!.]* \\ |
49 | 17 | **/__*__ \\ |
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} |
53 | 22 | `, |
54 | 23 | { shell: '/bin/bash' }, |
55 | 24 | ) |
56 | | - |
57 | | - await Promise.all( |
58 | | - reservedFiles.map(async ({ from, to }) => { |
59 | | - await fs.rename(to, from).catch(() => {}) |
60 | | - }), |
61 | | - ) |
62 | 25 | } |
63 | 26 |
|
64 | 27 | clean(process.argv[2]) |
0 commit comments