Skip to content

ActivityPub-federated video streaming platform using P2P directly in your web browser

Use typescript paths in cli scripts too

Chocobozzz2aaa1a3fdc49
diff --git a/scripts/create-import-video-file-job.ts b/scripts/create-import-video-file-job.ts
index 2b636014a6..204337d551 100644
--- a/scripts/create-import-video-file-job.ts
+++ b/scripts/create-import-video-file-job.ts
@@ -1,3 +1,6 @@
+import { registerTSPaths } from '../server/helpers/register-ts-paths'
+registerTSPaths()
+
import * as program from 'commander'
import { resolve } from 'path'
import { VideoModel } from '../server/models/video/video'
diff --git a/scripts/create-transcoding-job.ts b/scripts/create-transcoding-job.ts
index 2eb872169f..67a270a866 100755
--- a/scripts/create-transcoding-job.ts
+++ b/scripts/create-transcoding-job.ts
@@ -1,3 +1,6 @@
+import { registerTSPaths } from '../server/helpers/register-ts-paths'
+registerTSPaths()
+
import * as program from 'commander'
import { VideoModel } from '../server/models/video/video'
import { initDatabaseModels } from '../server/initializers'
diff --git a/scripts/danger/clean/cleaner.ts b/scripts/danger/clean/cleaner.ts
index d575af2832..ed35ef79f8 100644
--- a/scripts/danger/clean/cleaner.ts
+++ b/scripts/danger/clean/cleaner.ts
@@ -1,3 +1,6 @@
+import { registerTSPaths } from '../../../server/helpers/register-ts-paths'
+registerTSPaths()
+
import * as Promise from 'bluebird'
import * as rimraf from 'rimraf'
import { initDatabaseModels, sequelizeTypescript } from '../../../server/initializers'
diff --git a/scripts/generate-code-contributors.ts b/scripts/generate-code-contributors.ts
index c745b1cb24..8493d3d0ca 100755
--- a/scripts/generate-code-contributors.ts
+++ b/scripts/generate-code-contributors.ts
@@ -1,3 +1,6 @@
+import { registerTSPaths } from '../server/helpers/register-ts-paths'
+registerTSPaths()
+
import { doRequest } from '../server/helpers/requests'
import { readFileSync } from 'fs-extra'
diff --git a/scripts/i18n/create-custom-files.ts b/scripts/i18n/create-custom-files.ts
index 95897afa35..e946b8fd63 100755
--- a/scripts/i18n/create-custom-files.ts
+++ b/scripts/i18n/create-custom-files.ts
@@ -1,3 +1,6 @@
+import { registerTSPaths } from '../../server/helpers/register-ts-paths'
+registerTSPaths()
+
import * as jsToXliff12 from 'xliff/jsToXliff12'
import { writeFile } from 'fs-extra'
import { join } from 'path'
diff --git a/scripts/i18n/xliff2json.ts b/scripts/i18n/xliff2json.ts
index 7e6de28935..68fc95f349 100755
--- a/scripts/i18n/xliff2json.ts
+++ b/scripts/i18n/xliff2json.ts
@@ -1,3 +1,6 @@
+import { registerTSPaths } from '../../server/helpers/register-ts-paths'
+registerTSPaths()
+
import * as xliff12ToJs from 'xliff/xliff12ToJs'
import { readFileSync, unlink, writeFile } from 'fs-extra'
import { join } from 'path'
diff --git a/scripts/optimize-old-videos.ts b/scripts/optimize-old-videos.ts
index 0b0e6037e4..eb61ec43c4 100644
--- a/scripts/optimize-old-videos.ts
+++ b/scripts/optimize-old-videos.ts
@@ -1,3 +1,6 @@
+import { registerTSPaths } from '../server/helpers/register-ts-paths'
+registerTSPaths()
+
import { VIDEO_TRANSCODING_FPS } from '../server/initializers/constants'
import { getDurationFromVideoFile, getVideoFileBitrate, getVideoFileFPS, getVideoFileResolution } from '../server/helpers/ffmpeg-utils'
import { getMaxBitrate } from '../shared/models/videos'
diff --git a/scripts/parse-log.ts b/scripts/parse-log.ts
index 83ad45b72a..9e6653ca3e 100755
--- a/scripts/parse-log.ts
+++ b/scripts/parse-log.ts
@@ -1,3 +1,6 @@
+import { registerTSPaths } from '../server/helpers/register-ts-paths'
+registerTSPaths()
+
import * as program from 'commander'
import { createReadStream, readdir } from 'fs-extra'
import { join } from 'path'
diff --git a/scripts/plugin/install.ts b/scripts/plugin/install.ts
index 5d7fe4ba04..54738f50f1 100755
--- a/scripts/plugin/install.ts
+++ b/scripts/plugin/install.ts
@@ -1,3 +1,6 @@
+import { registerTSPaths } from '../../server/helpers/register-ts-paths'
+registerTSPaths()
+
import { initDatabaseModels } from '../../server/initializers/database'
import * as program from 'commander'
import { PluginManager } from '../../server/lib/plugins/plugin-manager'
diff --git a/scripts/plugin/uninstall.ts b/scripts/plugin/uninstall.ts
index b5e1ddea29..c56f184663 100755
--- a/scripts/plugin/uninstall.ts
+++ b/scripts/plugin/uninstall.ts
@@ -1,3 +1,6 @@
+import { registerTSPaths } from '../../server/helpers/register-ts-paths'
+registerTSPaths()
+
import { initDatabaseModels } from '../../server/initializers/database'
import * as program from 'commander'
import { PluginManager } from '../../server/lib/plugins/plugin-manager'
@@ -19,6 +22,7 @@ run()
})
async function run () {
+
await initDatabaseModels(true)
const toUninstall = program['npmName']
diff --git a/scripts/prune-storage.ts b/scripts/prune-storage.ts
index df4bdeebe0..c8968013b8 100755
--- a/scripts/prune-storage.ts
+++ b/scripts/prune-storage.ts
@@ -1,3 +1,6 @@
+import { registerTSPaths } from '../server/helpers/register-ts-paths'
+registerTSPaths()
+
import * as prompt from 'prompt'
import { join } from 'path'
import { CONFIG } from '../server/initializers/config'
diff --git a/scripts/reset-password.ts b/scripts/reset-password.ts
index 4a90372808..6126c3cd09 100755
--- a/scripts/reset-password.ts
+++ b/scripts/reset-password.ts
@@ -1,3 +1,6 @@
+import { registerTSPaths } from '../server/helpers/register-ts-paths'
+registerTSPaths()
+
import * as program from 'commander'
import { initDatabaseModels } from '../server/initializers'
import { UserModel } from '../server/models/account/user'
diff --git a/scripts/update-host.ts b/scripts/update-host.ts
index 57919b9981..a946d2e422 100755
--- a/scripts/update-host.ts
+++ b/scripts/update-host.ts
@@ -1,3 +1,6 @@
+import { registerTSPaths } from '../server/helpers/register-ts-paths'
+registerTSPaths()
+
import { WEBSERVER } from '../server/initializers/constants'
import { ActorFollowModel } from '../server/models/activitypub/actor-follow'
import { VideoModel } from '../server/models/video/video'
diff --git a/server.ts b/server.ts
index b49d10344b..b2541eed68 100644
--- a/server.ts
+++ b/server.ts
@@ -1,13 +1,6 @@
-import { resolve } from 'path'
+import { registerTSPaths } from './server/helpers/register-ts-paths'
-const tsConfig = require('./tsconfig.json')
-const tsConfigPaths = require('tsconfig-paths')
-
-// Thanks: https://github.com/dividab/tsconfig-paths/issues/75#issuecomment-458936883
-tsConfigPaths.register({
- baseUrl: resolve(tsConfig.compilerOptions.baseUrl || '', tsConfig.compilerOptions.outDir || ''),
- paths: tsConfig.compilerOptions.paths
-})
+registerTSPaths()
// FIXME: https://github.com/nodejs/node/pull/16853
require('tls').DEFAULT_ECDH_CURVE = 'auto'
diff --git a/server/helpers/register-ts-paths.ts b/server/helpers/register-ts-paths.ts
new file mode 100644
index 0000000000..e8db369e33
--- /dev/null
+++ b/server/helpers/register-ts-paths.ts
@@ -0,0 +1,16 @@
+import { resolve } from 'path'
+const tsConfigPaths = require('tsconfig-paths')
+
+const tsConfig = require('../../tsconfig.json')
+
+function registerTSPaths () {
+ // Thanks: https://github.com/dividab/tsconfig-paths/issues/75#issuecomment-458936883
+ tsConfigPaths.register({
+ baseUrl: resolve(tsConfig.compilerOptions.baseUrl || '', tsConfig.compilerOptions.outDir || ''),
+ paths: tsConfig.compilerOptions.paths
+ })
+}
+
+export {
+ registerTSPaths
+}
diff --git a/server/tools/peertube-auth.ts b/server/tools/peertube-auth.ts
index b5ecbd4706..6597a5c367 100644
--- a/server/tools/peertube-auth.ts
+++ b/server/tools/peertube-auth.ts
@@ -1,3 +1,6 @@
+import { registerTSPaths } from '../helpers/register-ts-paths'
+registerTSPaths()
+
import * as program from 'commander'
import * as prompt from 'prompt'
import { getNetrc, getSettings, writeSettings } from './cli'
diff --git a/server/tools/peertube-get-access-token.ts b/server/tools/peertube-get-access-token.ts
index 103495347c..6d47d89220 100644
--- a/server/tools/peertube-get-access-token.ts
+++ b/server/tools/peertube-get-access-token.ts
@@ -1,3 +1,6 @@
+import { registerTSPaths } from '../helpers/register-ts-paths'
+registerTSPaths()
+
import * as program from 'commander'
import { getClient, Server, serverLogin } from '../../shared/extra-utils'
diff --git a/server/tools/peertube-import-videos.ts b/server/tools/peertube-import-videos.ts
index fcb90cca3f..39184f46d5 100644
--- a/server/tools/peertube-import-videos.ts
+++ b/server/tools/peertube-import-videos.ts
@@ -1,3 +1,6 @@
+import { registerTSPaths } from '../helpers/register-ts-paths'
+registerTSPaths()
+
// FIXME: https://github.com/nodejs/node/pull/16853
require('tls').DEFAULT_ECDH_CURVE = 'auto'
diff --git a/server/tools/peertube-plugins.ts b/server/tools/peertube-plugins.ts
index 20254b3b45..e406061072 100644
--- a/server/tools/peertube-plugins.ts
+++ b/server/tools/peertube-plugins.ts
@@ -1,3 +1,6 @@
+import { registerTSPaths } from '../helpers/register-ts-paths'
+registerTSPaths()
+
import * as program from 'commander'
import { PluginType } from '../../shared/models/plugins/plugin.type'
import { getAccessToken } from '../../shared/extra-utils/users/login'
diff --git a/server/tools/peertube-repl.ts b/server/tools/peertube-repl.ts
index fbdec16132..ab6e215d9d 100644
--- a/server/tools/peertube-repl.ts
+++ b/server/tools/peertube-repl.ts
@@ -1,3 +1,6 @@
+import { registerTSPaths } from '../helpers/register-ts-paths'
+registerTSPaths()
+
import * as repl from 'repl'
import * as path from 'path'
import * as _ from 'lodash'
diff --git a/server/tools/peertube-upload.ts b/server/tools/peertube-upload.ts
index 4569cbb85b..f604c9bee8 100644
--- a/server/tools/peertube-upload.ts
+++ b/server/tools/peertube-upload.ts
@@ -1,3 +1,6 @@
+import { registerTSPaths } from '../helpers/register-ts-paths'
+registerTSPaths()
+
import * as program from 'commander'
import { access, constants } from 'fs-extra'
import { isAbsolute } from 'path'
diff --git a/server/tools/peertube-watch.ts b/server/tools/peertube-watch.ts
index 7c27c13642..9ac1d05f91 100644
--- a/server/tools/peertube-watch.ts
+++ b/server/tools/peertube-watch.ts
@@ -1,3 +1,6 @@
+import { registerTSPaths } from '../helpers/register-ts-paths'
+registerTSPaths()
+
import * as program from 'commander'
import { join } from 'path'
import { execSync } from 'child_process'
diff --git a/server/tools/peertube.ts b/server/tools/peertube.ts
index ddfe5b771a..fc85c42109 100644
--- a/server/tools/peertube.ts
+++ b/server/tools/peertube.ts
@@ -1,5 +1,8 @@
#!/usr/bin/env node
+import { registerTSPaths } from '../helpers/register-ts-paths'
+registerTSPaths()
+
import * as program from 'commander'
import {
version,