diff options
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/generate-types-package.ts | 78 |
1 files changed, 0 insertions, 78 deletions
diff --git a/scripts/generate-types-package.ts b/scripts/generate-types-package.ts deleted file mode 100644 index 3543fa472..000000000 --- a/scripts/generate-types-package.ts +++ /dev/null | |||
@@ -1,78 +0,0 @@ | |||
1 | import { copyFile, readJson, writeFile, writeJSON } from 'fs-extra' | ||
2 | import { resolve } from 'path' | ||
3 | import { cwd } from 'process' | ||
4 | import { execSync } from 'child_process' | ||
5 | import depcheck, { PackageDependencies } from 'depcheck' | ||
6 | |||
7 | run() | ||
8 | .then(() => process.exit(0)) | ||
9 | .catch(err => { | ||
10 | console.error(err) | ||
11 | process.exit(-1) | ||
12 | }) | ||
13 | |||
14 | async function run () { | ||
15 | execSync('npm run build:types', { stdio: 'inherit' }) | ||
16 | const typesPath = resolve(cwd(), './types/') | ||
17 | const typesPackageJsonPath = resolve(typesPath, './package.json') | ||
18 | const typesGitIgnorePath = resolve(typesPath, './.gitignore') | ||
19 | const mainPackageJson = await readJson(resolve(cwd(), './package.json')) | ||
20 | const tsConfigPath = resolve(cwd(), './tsconfig.json') | ||
21 | const tsConfig = await readJson(tsConfigPath) | ||
22 | const clientPackageJson = await readJson(resolve(cwd(), './client/package.json')) | ||
23 | |||
24 | const allDependencies = Object.assign( | ||
25 | mainPackageJson.dependencies, | ||
26 | mainPackageJson.devDepencies, | ||
27 | clientPackageJson.dependencies | ||
28 | ) as PackageDependencies | ||
29 | |||
30 | // https://github.com/depcheck/depcheck#api | ||
31 | const depcheckOptions = { | ||
32 | parsers: { '**/*.ts': depcheck.parser.typescript }, | ||
33 | detectors: [ | ||
34 | depcheck.detector.requireCallExpression, | ||
35 | depcheck.detector.importDeclaration | ||
36 | ], | ||
37 | ignoreMatches: Object.keys(tsConfig?.compilerOptions?.paths || []), | ||
38 | package: { dependencies: allDependencies } | ||
39 | } | ||
40 | |||
41 | const { dependencies: unusedDependencies } = await depcheck(resolve(cwd(), './types/'), depcheckOptions) | ||
42 | console.log(`Removing ${Object.keys(unusedDependencies).length} unused dependencies.`) | ||
43 | const dependencies = Object | ||
44 | .keys(allDependencies) | ||
45 | .filter(dependencyName => !unusedDependencies.includes(dependencyName)) | ||
46 | .reduce((dependencies, dependencyName) => { | ||
47 | dependencies[dependencyName] = allDependencies[dependencyName] | ||
48 | return dependencies | ||
49 | }, {}) | ||
50 | |||
51 | const { description, version, licence, engines, author, repository } = mainPackageJson | ||
52 | const typesPackageJson = { | ||
53 | name: '@peertube/peertube-types', | ||
54 | description, | ||
55 | version, | ||
56 | private: false, | ||
57 | license: licence, | ||
58 | engines, | ||
59 | author, | ||
60 | repository, | ||
61 | dependencies | ||
62 | } | ||
63 | console.log(`Writing package.json to ${typesPackageJsonPath}`) | ||
64 | await writeJSON(typesPackageJsonPath, typesPackageJson, { spaces: 2 }) | ||
65 | |||
66 | console.log(`Writing git ignore to ${typesGitIgnorePath}`) | ||
67 | await writeFile(typesGitIgnorePath, '*.tsbuildinfo') | ||
68 | |||
69 | console.log('Copying tsconfig files') | ||
70 | await copyFile(tsConfigPath, resolve(typesPath, './tsconfig.json')) | ||
71 | await copyFile(resolve(cwd(), './tsconfig.base.json'), resolve(typesPath, './tsconfig.base.json')) | ||
72 | tsConfig.references.map(({ path }) => path).forEach((path) => { | ||
73 | const src = resolve(cwd(), path, '/tsconfig.json') | ||
74 | const dest = resolve(typesPath, path, './tsconfig.json') | ||
75 | console.log(`${src} -> ${dest}`) | ||
76 | copyFile(src, dest).catch((e) => console.error(e)) | ||
77 | }) | ||
78 | } | ||