aboutsummaryrefslogtreecommitdiffhomepage
path: root/scripts
diff options
context:
space:
mode:
authorlutangar <johan.dufour@gmail.com>2021-11-09 13:49:08 +0100
committerChocobozzz <chocobozzz@cpy.re>2021-12-16 10:08:43 +0100
commitb8fa3e8c734a46918118afe7976f248cc883f675 (patch)
tree0ebf8fd10b1c690602da14d4dd626cd04a9ff748 /scripts
parent8b03e2ce1a2098261de2f729f660b1ae2a320b65 (diff)
downloadPeerTube-b8fa3e8c734a46918118afe7976f248cc883f675.tar.gz
PeerTube-b8fa3e8c734a46918118afe7976f248cc883f675.tar.zst
PeerTube-b8fa3e8c734a46918118afe7976f248cc883f675.zip
refactor(types): create dedicated folder for types package src
fix guide examples and add types package readme refactor(tsconfig): move back base tsconfig to base directory
Diffstat (limited to 'scripts')
-rw-r--r--scripts/generate-types-package.ts78
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 @@
1import { copyFile, readJson, writeFile, writeJSON } from 'fs-extra'
2import { resolve } from 'path'
3import { cwd } from 'process'
4import { execSync } from 'child_process'
5import depcheck, { PackageDependencies } from 'depcheck'
6
7run()
8 .then(() => process.exit(0))
9 .catch(err => {
10 console.error(err)
11 process.exit(-1)
12 })
13
14async 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}