Federated video streaming platform using ActivityPub and P2P in the web browser with Angular. https://joinpeertube.org/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

97 lines
3.3 KiB

  1. import { execSync } from 'child_process'
  2. import depcheck, { PackageDependencies } from 'depcheck'
  3. import { copyFile, readJson, remove, writeFile, writeJSON } from 'fs-extra'
  4. import { join, resolve } from 'path'
  5. import { root } from '../../shared/core-utils'
  6. if (!process.argv[2]) {
  7. console.error('Need version as argument')
  8. process.exit(-1)
  9. }
  10. const version = process.argv[2]
  11. console.log('Will generate package version %s.', version)
  12. run()
  13. .then(() => process.exit(0))
  14. .catch(err => {
  15. console.error(err)
  16. process.exit(-1)
  17. })
  18. async function run () {
  19. const typesPath = __dirname
  20. const typesDistPath = join(typesPath, 'dist')
  21. const typesDistPackageJsonPath = join(typesDistPath, 'package.json')
  22. const typesDistGitIgnorePath = join(typesDistPath, '.gitignore')
  23. const mainPackageJson = await readJson(join(root(), 'package.json'))
  24. const distTsConfigPath = join(typesPath, 'tsconfig.dist.json')
  25. const distTsConfig = await readJson(distTsConfigPath)
  26. const clientPackageJson = await readJson(join(root(), 'client', 'package.json'))
  27. await remove(typesDistPath)
  28. execSync('npm run tsc -- -b --verbose packages/types', { stdio: 'inherit' })
  29. execSync(`npm run resolve-tspaths -- --project ${distTsConfigPath} --src ${typesDistPath} --out ${typesDistPath}`, { stdio: 'inherit' })
  30. const allDependencies = Object.assign(
  31. mainPackageJson.dependencies,
  32. mainPackageJson.devDependencies,
  33. clientPackageJson.dependencies,
  34. clientPackageJson.devDependencies
  35. ) as PackageDependencies
  36. // https://github.com/depcheck/depcheck#api
  37. const depcheckOptions = {
  38. parsers: { '**/*.ts': depcheck.parser.typescript },
  39. detectors: [
  40. depcheck.detector.requireCallExpression,
  41. depcheck.detector.importDeclaration
  42. ],
  43. ignoreMatches: Object.keys(distTsConfig?.compilerOptions?.paths || []),
  44. package: { dependencies: allDependencies }
  45. }
  46. const result = await depcheck(typesDistPath, depcheckOptions)
  47. if (Object.keys(result.invalidDirs).length !== 0) {
  48. console.error('Invalid directories detected.', { invalidDirs: result.invalidDirs })
  49. process.exit(-1)
  50. }
  51. if (Object.keys(result.invalidFiles).length !== 0) {
  52. console.error('Invalid files detected.', { invalidFiles: result.invalidFiles })
  53. process.exit(-1)
  54. }
  55. const unusedDependencies = result.dependencies
  56. console.log(`Removing ${Object.keys(unusedDependencies).length} unused dependencies.`)
  57. const dependencies = Object
  58. .keys(allDependencies)
  59. .filter(dependencyName => !unusedDependencies.includes(dependencyName))
  60. .reduce((dependencies, dependencyName) => {
  61. dependencies[dependencyName] = allDependencies[dependencyName]
  62. return dependencies
  63. }, {})
  64. const { description, licence, engines, author, repository } = mainPackageJson
  65. const typesPackageJson = {
  66. name: '@peertube/peertube-types',
  67. description,
  68. version,
  69. private: false,
  70. license: licence,
  71. engines,
  72. author,
  73. repository,
  74. dependencies
  75. }
  76. console.log(`Writing package.json to ${typesDistPackageJsonPath}`)
  77. await writeJSON(typesDistPackageJsonPath, typesPackageJson, { spaces: 2 })
  78. console.log(`Writing git ignore to ${typesDistGitIgnorePath}`)
  79. await writeFile(typesDistGitIgnorePath, '*.tsbuildinfo')
  80. await copyFile(resolve(typesPath, './README.md'), resolve(typesDistPath, './README.md'))
  81. }