]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
Convert scripts to typescript
authorChocobozzz <florian.bigard@gmail.com>
Mon, 12 Jun 2017 19:06:32 +0000 (21:06 +0200)
committerChocobozzz <florian.bigard@gmail.com>
Mon, 12 Jun 2017 19:06:32 +0000 (21:06 +0200)
package.json
scripts/check.ts [moved from scripts/check.js with 82% similarity]
scripts/reset-password.ts [moved from scripts/reset-password.js with 89% similarity]
scripts/update-host.js [deleted file]
scripts/update-host.ts [new file with mode: 0755]
server/models/video-interface.ts
yarn.lock

index 83ea17638c0298d5884d3a6f4864c1a14b97ec98..095d380bfdadde0105cc8a1c09b28c07eab49b0d 100644 (file)
     "danger:clean:dev": "scripty",
     "danger:clean:prod": "scripty",
     "danger:clean:modules": "scripty",
-    "reset-password": "scripty",
+    "reset-password": "ts-node ./scripts/reset-password.ts",
     "play": "scripty",
     "dev:server": "scripty",
     "dev:client": "scripty",
     "start": "node dist/server",
-    "check": "scripty",
+    "check": "ts-node ./scripts/check.ts",
     "upgrade": "scripty",
-    "update-host": "scripty",
+    "update-host": "ts-node ./scripts/update-host.ts",
     "test": "scripty",
     "help": "scripty",
     "postinstall": "cd client && yarn install",
@@ -85,6 +85,7 @@
     "@types/async": "^2.0.40",
     "@types/bcrypt": "^1.0.0",
     "@types/body-parser": "^1.16.3",
+    "@types/commander": "^2.9.1",
     "@types/config": "^0.0.32",
     "@types/express": "^4.0.35",
     "@types/lodash": "^4.14.64",
similarity index 82%
rename from scripts/check.js
rename to scripts/check.ts
index 3ccfbb3b201ae6a0e1380acdbd9f9e63dbeffcfc..28167482cf5060370c6cc2fee0d09e6bd506bf8c 100755 (executable)
@@ -1,12 +1,9 @@
-#!/usr/bin/env node
+import * as series from 'async/series'
+import * as request from 'request'
+import * as WebSocket from 'ws'
 
-'use strict'
+import { CONFIG } from '../server/initializers/constants'
 
-const series = require('async/series')
-const request = require('request')
-const WebSocket = require('ws')
-
-const constants = require('../server/initializers/constants')
 const requestHeaders = {
   'Range': '',
   'Keep-Alive': '',
@@ -29,8 +26,8 @@ series([
 
 // ---------------------------------------------------------------------------
 
-function pingServer (callback) {
-  const pingUrl = constants.CONFIG.WEBSERVER.URL + '/api/v1/ping'
+function pingServer (callback: () => void) {
+  const pingUrl = CONFIG.WEBSERVER.URL + '/api/v1/ping'
   console.log('Checking server is up (%s)...', pingUrl)
 
   request(pingUrl, function (err, res, body) {
@@ -44,8 +41,8 @@ function pingServer (callback) {
   })
 }
 
-function checkCORSTorrent (callback) {
-  const torrentUrl = constants.CONFIG.WEBSERVER.URL + '/static/torrents/test.torrent'
+function checkCORSTorrent (callback: () => void) {
+  const torrentUrl = CONFIG.WEBSERVER.URL + '/static/torrents/test.torrent'
   console.log('Checking CORS headers for the torrent (%s)...', torrentUrl)
 
   request({
@@ -63,8 +60,8 @@ function checkCORSTorrent (callback) {
   })
 }
 
-function checkCORSWebSeed (callback) {
-  const webseedUrl = constants.CONFIG.WEBSERVER.URL + '/static/webseed/test.mp4'
+function checkCORSWebSeed (callback: () => void) {
+  const webseedUrl = CONFIG.WEBSERVER.URL + '/static/webseed/test.mp4'
   console.log('Checking CORS headers for the video (%s)...', webseedUrl)
 
   request({
@@ -82,9 +79,9 @@ function checkCORSWebSeed (callback) {
   })
 }
 
-function checkTracker (callback) {
-  const trackerUrl = constants.CONFIG.WEBSERVER.WS + '://' +
-                     constants.CONFIG.WEBSERVER.HOST +
+function checkTracker (callback: () => void) {
+  const trackerUrl = CONFIG.WEBSERVER.WS + '://' +
+                     CONFIG.WEBSERVER.HOST +
                      '/tracker/socket'
   console.log('Checking tracker websocket (%s)...', trackerUrl)
 
@@ -111,7 +108,7 @@ function checkTracker (callback) {
   }
 }
 
-function isThereValidCORSHeaders (res) {
+function isThereValidCORSHeaders (res: request.RequestResponse) {
   let fail = false
 
   // Check Access-Control-Allow-Origin
@@ -160,7 +157,7 @@ function isThereValidCORSHeaders (res) {
   return !fail
 }
 
-function findPatternNotInString (stringChain, patterns) {
+function findPatternNotInString (stringChain: string, patterns: string[]) {
   let res = null
   const stringChainLowerCase = stringChain.toLowerCase()
 
similarity index 89%
rename from scripts/reset-password.js
rename to scripts/reset-password.ts
index 49a481a18ae515a8e9a30e1fd49f03225fe3b521..50e11c69c0195fbe4b7d446e7c0864d0ae5e30d2 100755 (executable)
@@ -1,10 +1,6 @@
-#!/usr/bin/env node
+import * as program from 'commander'
 
-'use strict'
-
-const program = require('commander')
-
-const db = require('../server/initializers/database')
+import { database as db } from '../server/initializers/database'
 
 program
   .option('-u, --user [user]', 'User')
diff --git a/scripts/update-host.js b/scripts/update-host.js
deleted file mode 100755 (executable)
index 8ae0f0d..0000000
+++ /dev/null
@@ -1,42 +0,0 @@
-#!/usr/bin/env node
-
-'use strict'
-
-const fs = require('fs')
-const parseTorrent = require('parse-torrent')
-
-const constants = require('../server/initializers/constants')
-const db = require('../server/initializers/database')
-
-const friends = require('../server/lib/friends')
-
-db.init(true, function () {
-  friends.hasFriends(function (err, hasFriends) {
-    if (err) throw err
-
-    if (hasFriends === true) {
-      console.log('Cannot update host because you have friends!')
-      process.exit(-1)
-    }
-
-    console.log('Updating torrent files.')
-    db.Video.list(function (err, videos) {
-      if (err) throw err
-
-      videos.forEach(function (video) {
-        const torrentName = video.id + '.torrent'
-        const torrentPath = constants.CONFIG.STORAGE.TORRENTS_DIR + torrentName
-        const filename = video.id + video.extname
-
-        const parsed = parseTorrent(fs.readFileSync(torrentPath))
-        parsed.announce = [ constants.CONFIG.WEBSERVER.WS + '://' + constants.CONFIG.WEBSERVER.HOST + '/tracker/socket' ]
-        parsed.urlList = [ constants.CONFIG.WEBSERVER.URL + constants.STATIC_PATHS.WEBSEED + filename ]
-
-        const buf = parseTorrent.toTorrentFile(parsed)
-        fs.writeFileSync(torrentPath, buf)
-      })
-
-      process.exit(0)
-    })
-  })
-})
diff --git a/scripts/update-host.ts b/scripts/update-host.ts
new file mode 100755 (executable)
index 0000000..0f6af09
--- /dev/null
@@ -0,0 +1,37 @@
+import { readFileSync, writeFileSync } from 'fs'
+import * as parseTorrent from 'parse-torrent'
+
+import { CONFIG, STATIC_PATHS } from '../server/initializers/constants'
+import { database as db } from '../server/initializers/database'
+import { hasFriends } from '../server/lib/friends'
+
+db.init(true, function () {
+  hasFriends(function (err, itHasFriends) {
+    if (err) throw err
+
+    if (itHasFriends === true) {
+      console.log('Cannot update host because you have friends!')
+      process.exit(-1)
+    }
+
+    console.log('Updating torrent files.')
+    db.Video.list(function (err, videos) {
+      if (err) throw err
+
+      videos.forEach(function (video) {
+        const torrentName = video.id + '.torrent'
+        const torrentPath = CONFIG.STORAGE.TORRENTS_DIR + torrentName
+        const filename = video.id + video.extname
+
+        const parsed = parseTorrent(readFileSync(torrentPath))
+        parsed.announce = [ CONFIG.WEBSERVER.WS + '://' + CONFIG.WEBSERVER.HOST + '/tracker/socket' ]
+        parsed.urlList = [ CONFIG.WEBSERVER.URL + STATIC_PATHS.WEBSEED + filename ]
+
+        const buf = parseTorrent.toTorrentFile(parsed)
+        writeFileSync(torrentPath, buf)
+      })
+
+      process.exit(0)
+    })
+  })
+})
index 7005f213c481bfdc88fcd2578ce6ccdb4654e825..7120f91cda7733c6e7b7b327f24c036f4b629759 100644 (file)
@@ -70,7 +70,7 @@ export namespace VideoMethods {
   export type GetDurationFromFileCallback = (err: Error, duration?: number) => void
   export type GetDurationFromFile = (videoPath, callback) => void
 
-  export type ListCallback = () => void
+  export type ListCallback = (err: Error, videoInstances: VideoInstance[]) => void
   export type List = (callback: ListCallback) => void
 
   export type ListForApiCallback = (err: Error, videoInstances?: VideoInstance[], total?: number) => void
index a4f880cc2d8125ca0dd1b35acbd2604daced0f6a..9c0af9d327791d9547d5e4b733d42000bfe97f41 100644 (file)
--- a/yarn.lock
+++ b/yarn.lock
     "@types/express" "*"
     "@types/node" "*"
 
+"@types/commander@^2.9.1":
+  version "2.9.1"
+  resolved "https://registry.yarnpkg.com/@types/commander/-/commander-2.9.1.tgz#d4e464425baf4685bd49dd233be11de9c00c0784"
+  dependencies:
+    "@types/node" "*"
+
 "@types/config@^0.0.32":
   version "0.0.32"
   resolved "https://registry.yarnpkg.com/@types/config/-/config-0.0.32.tgz#c106055802d78e234e28374adc4dad460d098558"