forked from fjc0k/docker-YApi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
clean.ts
64 lines (58 loc) · 1.83 KB
/
clean.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import fs from 'fs-extra'
import { join, parse } from 'path'
import childProcess from 'child_process'
import globby from 'globby'
async function clean(rootDir: string) {
const projectFilePath = join.bind(null, rootDir)
const pkgFilePath = join.bind(null, projectFilePath('node_modules'))
// 需要保留的文件列表
const reservedFiles = [
pkgFilePath('react/cjs/react.production.min.js'),
pkgFilePath('react-dom/cjs/react-dom.production.min.js'),
pkgFilePath('react-is/cjs/react-is.production.min.js'),
pkgFilePath('scheduler/cjs/scheduler.production.min.js'),
pkgFilePath('history/cjs/history.min.js'),
pkgFilePath('resolve-pathname/cjs/resolve-pathname.min.js'),
pkgFilePath('value-equal/cjs/value-equal.min.js'),
pkgFilePath('jsondiffpatch/dist/jsondiffpatch.umd.js'),
pkgFilePath('ajv-i18n/localize/es'),
pkgFilePath('svgo/.svgo.yml'),
pkgFilePath('.bin'),
...(await globby('**/*.min.*', {
absolute: true,
cwd: rootDir,
ignore: ['**/node_modules/**'],
})),
].map((filePath) => {
const { dir, base } = parse(filePath)
return {
from: filePath,
to: join(dir, 'r_' + base.replace(/\./g, '')),
}
})
await Promise.all(
reservedFiles.map(async ({ from, to }) => {
await fs.rename(from, to)
}),
)
childProcess.execSync(
`
cd ${rootDir}
shopt -s globstar
rm -rf \\
**/*.{map,lock,log,md,yml,yaml,ts,txt} \\
**/.[!.]* \\
**/__*__ \\
**/{tsconfig.json,package-lock.json,Makefile,CHANGELOG} \\
**/*.{test,spec,min,umd,es,esm}.* \\
**/{test,tests,example,examples,doc,docs,coverage,demo,umd,es,esm}/
`,
{ shell: '/bin/bash' },
)
await Promise.all(
reservedFiles.map(async ({ from, to }) => {
await fs.rename(to, from)
}),
)
}
clean(process.argv[2])