diff options
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/generate-types-package.ts | 78 | ||||
-rwxr-xr-x | scripts/release.sh | 5 | ||||
-rw-r--r-- | scripts/tsconfig.json | 2 |
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 @@ | |||
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 | } | ||
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 | ||
123 | npm run generate-types-package | ||
124 | cd types | ||
125 | npm 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" }, |