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
commit8b03e2ce1a2098261de2f729f660b1ae2a320b65 (patch)
treeca4770cf86c9c54814dbb62bfc95ef38661646b2 /scripts
parent06aad80165d09a8863ab8103149a8ff518b10641 (diff)
downloadPeerTube-8b03e2ce1a2098261de2f729f660b1ae2a320b65.tar.gz
PeerTube-8b03e2ce1a2098261de2f729f660b1ae2a320b65.tar.zst
PeerTube-8b03e2ce1a2098261de2f729f660b1ae2a320b65.zip
feat(types): create peertube-types package
Create dedicated Typescript "types" configuration file for each "projects". Create a types folder which includes every useful ts definition: - client - server - shared Add tooling to create a proper package, extract dependencies, etc... Add CI Github task. refactor(types): publish types package in release script
Diffstat (limited to 'scripts')
-rw-r--r--scripts/generate-types-package.ts78
-rwxr-xr-xscripts/release.sh5
-rw-r--r--scripts/tsconfig.json2
3 files changed, 84 insertions, 1 deletions
diff --git a/scripts/generate-types-package.ts b/scripts/generate-types-package.ts
new file mode 100644
index 000000000..3543fa472
--- /dev/null
+++ b/scripts/generate-types-package.ts
@@ -0,0 +1,78 @@
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}
diff --git a/scripts/release.sh b/scripts/release.sh
index 6423d17ee..7681de90d 100755
--- a/scripts/release.sh
+++ b/scripts/release.sh
@@ -118,3 +118,8 @@ rm -f "./client/dist/embed-stats.json"
118 git checkout "$branch" 118 git checkout "$branch"
119 fi 119 fi
120) 120)
121
122# Release types package
123npm run generate-types-package
124cd types
125npm publish --access public
diff --git a/scripts/tsconfig.json b/scripts/tsconfig.json
index 0d9716f2d..0cfd927a6 100644
--- a/scripts/tsconfig.json
+++ b/scripts/tsconfig.json
@@ -1,7 +1,7 @@
1{ 1{
2 "extends": "../tsconfig.base.json", 2 "extends": "../tsconfig.base.json",
3 "compilerOptions": { 3 "compilerOptions": {
4 "outDir": "../dist/scripts", 4 "outDir": "../dist/scripts"
5 }, 5 },
6 "references": [ 6 "references": [
7 { "path": "../shared" }, 7 { "path": "../shared" },