Init commit

This commit is contained in:
ShreejitPanchal
2026-05-19 19:56:02 +08:00
commit 6601501eff
4047 changed files with 2185372 additions and 0 deletions

View File

@@ -0,0 +1,14 @@
# PeerTube typings
These **Typescript** *types* are mainly used to write **PeerTube** plugins.
## Installation
Npm:
```
npm install --save-dev @peertube/peertube-types
```
## Usage
> See [contribute-plugins](https://docs.joinpeertube.org/contribute/plugins#typescript) **Typescript** section of the doc.

View File

@@ -0,0 +1,117 @@
import { currentDir, root } from '@peertube/peertube-node-utils'
import { execSync } from 'child_process'
import depcheck, { PackageDependencies } from 'depcheck'
import { readJson, remove, writeJSON } from 'fs-extra/esm'
import { copyFile, writeFile } from 'fs/promises'
import { join, resolve } from 'path'
if (!process.argv[2]) {
console.error('Need version as argument')
process.exit(-1)
}
const version = process.argv[2]
console.log('Will generate package version %s.', version)
run()
.then(() => process.exit(0))
.catch(err => {
console.error(err)
process.exit(-1)
})
async function run () {
const typesPath = currentDir(import.meta.url)
const typesDistTMPPath = join(typesPath, 'dist-tmp')
await remove(typesDistTMPPath)
const mainPackageJson = await readJson(join(root(), 'package.json'))
const typesTsConfigPath = join(typesPath, 'tsconfig.types.json')
const distTmpTsConfigPath = join(typesPath, 'tsconfig.dist-tmp.json')
const distTmpTsConfig = await readJson(distTmpTsConfigPath)
const clientPackageJson = await readJson(join(root(), 'client', 'package.json'))
const typesDistPath = join(typesPath, 'dist')
const rollupConfig = join(typesPath, 'rollup.config.js')
await remove(typesDistTMPPath)
execSync(`npm run tsc -- -b ${typesTsConfigPath} --verbose`, { stdio: 'inherit' })
// eslint-disable-next-line max-len
execSync(`npm run resolve-tspaths -- --project ${distTmpTsConfigPath} --src ${typesDistTMPPath} --out ${typesDistTMPPath}`, { stdio: 'inherit' })
execSync(`./node_modules/.bin/rollup -c ${rollupConfig}`, { stdio: 'inherit' })
await remove(typesDistTMPPath)
const allDependencies = Object.assign(
mainPackageJson.dependencies,
mainPackageJson.devDependencies,
clientPackageJson.dependencies,
clientPackageJson.devDependencies
) as PackageDependencies
const toIgnore = Object.keys(distTmpTsConfig?.compilerOptions?.paths || [])
// https://github.com/depcheck/depcheck#api
const depcheckOptions = {
parsers: { '**/*.ts': depcheck.parser.typescript },
detectors: [
depcheck.detector.requireCallExpression,
depcheck.detector.importDeclaration
],
ignoreMatches: toIgnore,
package: { dependencies: allDependencies }
}
const result = await depcheck(typesDistPath, depcheckOptions)
if (Object.keys(result.invalidDirs).length !== 0) {
console.error('Invalid directories detected.', { invalidDirs: result.invalidDirs })
process.exit(-1)
}
if (Object.keys(result.invalidFiles).length !== 0) {
console.error('Invalid files detected.', { invalidFiles: result.invalidFiles })
process.exit(-1)
}
const unusedDependencies = result.dependencies
console.log(`Removing ${Object.keys(unusedDependencies).length} unused dependencies.`)
const dependencies = Object
.keys(allDependencies)
.filter(dependencyName => !unusedDependencies.includes(dependencyName) && !toIgnore.includes(dependencyName))
.reduce((dependencies, dependencyName) => {
dependencies[dependencyName] = allDependencies[dependencyName]
return dependencies
}, {})
const { description, licence, engines, author, repository } = mainPackageJson
const typesPackageJson = {
name: '@peertube/peertube-types',
description,
version,
private: false,
main: '',
license: licence,
engines,
author,
repository,
dependencies
}
const typesDistPackageJsonPath = join(typesDistPath, 'package.json')
const typesDistGitIgnorePath = join(typesDistPath, '.gitignore')
console.log(`Writing package.json to ${typesDistPackageJsonPath}`)
await writeJSON(typesDistPackageJsonPath, typesPackageJson, { spaces: 2 })
console.log(`Writing git ignore to ${typesDistGitIgnorePath}`)
await writeFile(typesDistGitIgnorePath, '*.tsbuildinfo')
await copyFile(resolve(typesPath, './README.md'), resolve(typesDistPath, './README.md'))
}

View File

@@ -0,0 +1,9 @@
{
"name": "@peertube/peertube-types-generator",
"private": true,
"version": "0.0.0",
"type": "module",
"dependencies": {
"@peertube/peertube-core-utils": "workspace:*"
}
}

View File

@@ -0,0 +1,16 @@
import { dts } from 'rollup-plugin-dts'
const config = [
{
input: './packages/types-generator/dist-tmp/index.d.ts',
output: [ { file: './packages/types-generator/dist/index.d.ts', format: 'es' } ],
plugins: [ dts({ tsconfig: './packages/types-generator/tsconfig.dist-tmp.json' }) ],
},
{
input: './packages/types-generator/dist-tmp/client/index.d.ts',
output: [ { file: './packages/types-generator/dist/client/index.d.ts', format: 'es' } ],
plugins: [ dts({ tsconfig: './packages/types-generator/tsconfig.dist-tmp.json' }) ],
}
]
export default config

View File

@@ -0,0 +1 @@
export * from '@client/types/index.js'

View File

@@ -0,0 +1,19 @@
{
"extends": "../../../../tsconfig.base.json",
"compilerOptions": {
"stripInternal": true,
"removeComments": false,
"emitDeclarationOnly": true,
"outDir": "../../dist-tmp/client/",
"rootDir": "./",
"baseUrl": "./",
"tsBuildInfoFile": "../../dist-tmp/tsconfig.client.types.tsbuildinfo",
"paths": {
"@client/*": [ "../../../../client/src/*" ]
}
},
"references": [
{ "path": "../../../../client/tsconfig.types.json" }
],
"files": [ "./index.ts" ]
}

View File

@@ -0,0 +1,11 @@
export * from '@server/types/index.js'
export * from '@server/types/models/index.js'
export * from '@peertube/peertube-models'
declare global {
namespace Express {
interface Request {
rawBody: Buffer
}
}
}

View File

@@ -0,0 +1,41 @@
import { RegisterServerOptions, Video, MVideo } from '../dist/index.js'
import { RegisterClientOptions } from '../dist/client/index.js'
function register1 ({ registerHook, getRouter }: RegisterServerOptions) {
registerHook({
target: 'action:application.listening',
handler: () => console.log('hello')
})
const router = getRouter()
router.get('/ping', (req, res) => {
console.log(req.rawBody)
res.status(200).json({ message: 'pong' })
})
}
function register2 ({ registerHook, peertubeHelpers }: RegisterClientOptions) {
registerHook({
target: 'action:admin-plugin-settings.init',
handler: ({ npmName }: { npmName: string }) => {
let video: MVideo
if ('peertube-plugin-transcription' !== npmName) {
return
}
}
})
registerHook({
target: 'action:video-watch.video.loaded',
handler: ({ video }: { video: Video }) => {
fetch(`${peertubeHelpers.getBaseRouterRoute()}/videos/${video.uuid}/captions`, {
method: 'PUT',
headers: peertubeHelpers.getAuthHeader()
})
.then(res => res.json())
.then(data => console.log('Hi %s.', data))
}
})
}

View File

@@ -0,0 +1,18 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"typeRoots": [
"node_modules/@types",
"client/node_modules/@types"
],
"baseUrl": "./dist-tmp",
"paths": {
"@server/*": [ "server/core/*" ],
"@client/*": [ "client/*" ],
"@peertube/peertube-models": [ "peertube-models" ],
"@peertube/peertube-typescript-utils": [ "peertube-typescript-utils" ],
"@peertube/peertube-transcription": [ "peertube-transcription" ]
}
}
}

View File

@@ -0,0 +1,11 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"rootDir": ".",
"noEmit": true
},
"files": [ "./generate-package.ts" ],
"references": [
{ "path": "../node-utils" }
]
}

View File

@@ -0,0 +1,24 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"stripInternal": true,
"removeComments": false,
"emitDeclarationOnly": true,
"sourceMap": false,
"outDir": "./dist-tmp/",
"baseUrl": "./",
"rootDir": "./src",
"tsBuildInfoFile": "./dist-tmp/tsconfig.server.types.tsbuildinfo",
"paths": {
"@server/*": [ "../../server/core/*" ]
}
},
"references": [
{ "path": "../models/tsconfig.types.json" },
{ "path": "../typescript-utils/tsconfig.types.json" },
{ "path": "../transcription/tsconfig.types.json" },
{ "path": "../../server/tsconfig.types.json" },
{ "path": "./src/client/tsconfig.types.json" }
],
"files": ["./src/index.ts"]
}