From: Rigel Kent Date: Fri, 19 Oct 2018 12:24:35 +0000 (+0200) Subject: add repl to the cli wrapper, remove extraneous TOC in tools.md X-Git-Tag: v1.1.0-alpha.2~4 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=c141f68be14193fb92d3f5cfc82cd1e156823c17;p=oweals%2Fpeertube.git add repl to the cli wrapper, remove extraneous TOC in tools.md --- diff --git a/server/tools/peertube-repl.ts b/server/tools/peertube-repl.ts new file mode 100644 index 000000000..6800ff8ab --- /dev/null +++ b/server/tools/peertube-repl.ts @@ -0,0 +1,79 @@ +import * as repl from 'repl' +import * as path from 'path' +import * as _ from 'lodash' +import * as uuidv1 from 'uuid/v1' +import * as uuidv3 from 'uuid/v3' +import * as uuidv4 from 'uuid/v4' +import * as uuidv5 from 'uuid/v5' +import * as Sequelize from 'sequelize' +import * as YoutubeDL from 'youtube-dl' + +import { initDatabaseModels, sequelizeTypescript } from '../initializers' +import * as cli from '../tools/cli' +import { logger } from '../helpers/logger' +import * as constants from '../initializers/constants' +import * as modelsUtils from '../models/utils' +import * as coreUtils from '../helpers/core-utils' +import * as ffmpegUtils from '../helpers/ffmpeg-utils' +import * as peertubeCryptoUtils from '../helpers/peertube-crypto' +import * as signupUtils from '../helpers/signup' +import * as utils from '../helpers/utils' +import * as YoutubeDLUtils from '../helpers/youtube-dl' + +let versionCommitHash + +const start = async () => { + await initDatabaseModels(true) + + await utils.getVersion().then((data) => { + versionCommitHash = data + }) + + const initContext = (replServer) => { + return (context) => { + const properties = { + context, repl: replServer, env: process.env, + lodash: _, path, + uuidv1, uuidv3, uuidv4, uuidv5, + cli, logger, constants, + Sequelize, sequelizeTypescript, modelsUtils, + models: sequelizeTypescript.models, transaction: sequelizeTypescript.transaction, + query: sequelizeTypescript.query, queryInterface: sequelizeTypescript.getQueryInterface(), + YoutubeDL, + coreUtils, ffmpegUtils, peertubeCryptoUtils, signupUtils, utils, YoutubeDLUtils + } + + for (let prop in properties) { + Object.defineProperty(context, prop, { + configurable: false, + enumerable: true, + value: properties[prop] + }) + } + } + } + + const replServer = repl.start({ + prompt: `PeerTube [${cli.version}] (${versionCommitHash})> ` + }) + + initContext(replServer)(replServer.context) + replServer.on('reset', initContext(replServer)) + + const resetCommand = { + help: 'Reset REPL', + action () { + this.write('.clear\n') + this.displayPrompt() + } + } + replServer.defineCommand('reset', resetCommand) + replServer.defineCommand('r', resetCommand) + +} + +start().then((data) => { + // do nothing +}).catch((err) => { + console.error(err) +}) diff --git a/server/tools/peertube.ts b/server/tools/peertube.ts index ad76bafb4..c8b9fa744 100755 --- a/server/tools/peertube.ts +++ b/server/tools/peertube.ts @@ -17,6 +17,7 @@ program .command('import-videos', 'import a video from a streaming platform').alias('import') .command('get-access-token', 'get a peertube access token', { noHelp: true }).alias('token') .command('watch', 'watch a video in the terminal ✩°。⋆').alias('w') + .command('repl', 'initiate a REPL to access internals') /* Not Yet Implemented */ program diff --git a/server/tools/repl.ts b/server/tools/repl.ts deleted file mode 100644 index 6800ff8ab..000000000 --- a/server/tools/repl.ts +++ /dev/null @@ -1,79 +0,0 @@ -import * as repl from 'repl' -import * as path from 'path' -import * as _ from 'lodash' -import * as uuidv1 from 'uuid/v1' -import * as uuidv3 from 'uuid/v3' -import * as uuidv4 from 'uuid/v4' -import * as uuidv5 from 'uuid/v5' -import * as Sequelize from 'sequelize' -import * as YoutubeDL from 'youtube-dl' - -import { initDatabaseModels, sequelizeTypescript } from '../initializers' -import * as cli from '../tools/cli' -import { logger } from '../helpers/logger' -import * as constants from '../initializers/constants' -import * as modelsUtils from '../models/utils' -import * as coreUtils from '../helpers/core-utils' -import * as ffmpegUtils from '../helpers/ffmpeg-utils' -import * as peertubeCryptoUtils from '../helpers/peertube-crypto' -import * as signupUtils from '../helpers/signup' -import * as utils from '../helpers/utils' -import * as YoutubeDLUtils from '../helpers/youtube-dl' - -let versionCommitHash - -const start = async () => { - await initDatabaseModels(true) - - await utils.getVersion().then((data) => { - versionCommitHash = data - }) - - const initContext = (replServer) => { - return (context) => { - const properties = { - context, repl: replServer, env: process.env, - lodash: _, path, - uuidv1, uuidv3, uuidv4, uuidv5, - cli, logger, constants, - Sequelize, sequelizeTypescript, modelsUtils, - models: sequelizeTypescript.models, transaction: sequelizeTypescript.transaction, - query: sequelizeTypescript.query, queryInterface: sequelizeTypescript.getQueryInterface(), - YoutubeDL, - coreUtils, ffmpegUtils, peertubeCryptoUtils, signupUtils, utils, YoutubeDLUtils - } - - for (let prop in properties) { - Object.defineProperty(context, prop, { - configurable: false, - enumerable: true, - value: properties[prop] - }) - } - } - } - - const replServer = repl.start({ - prompt: `PeerTube [${cli.version}] (${versionCommitHash})> ` - }) - - initContext(replServer)(replServer.context) - replServer.on('reset', initContext(replServer)) - - const resetCommand = { - help: 'Reset REPL', - action () { - this.write('.clear\n') - this.displayPrompt() - } - } - replServer.defineCommand('reset', resetCommand) - replServer.defineCommand('r', resetCommand) - -} - -start().then((data) => { - // do nothing -}).catch((err) => { - console.error(err) -}) diff --git a/support/doc/tools.md b/support/doc/tools.md index 7f93c94f2..eb3f97eb4 100644 --- a/support/doc/tools.md +++ b/support/doc/tools.md @@ -1,42 +1,31 @@ +# CLI tools guide + -**Table of Contents** *generated with [DocToc](https://github.com/thlorenz/doctoc)* - -- [CLI tools guide](#cli-tools-guide) - - [CLI wrapper](#cli-wrapper) - - [Remote Tools](#remote-tools) - - [Dependencies](#dependencies) - - [Installation](#installation) - - [peertube-import-videos.js](#peertube-import-videosjs) - - [peertube-upload.js](#peertube-uploadjs) - - [peertube-watch.js](#peertube-watchjs) - - [Server tools](#server-tools) - - [parse-log](#parse-log) - - [create-transcoding-job.js](#create-transcoding-jobjs) - - [create-import-video-file-job.js](#create-import-video-file-jobjs) - - [prune-storage.js](#prune-storagejs) - - [optimize-old-videos.js](#optimize-old-videosjs) - - [update-host.js](#update-hostjs) - - [REPL (Read Eval Print Loop)](#repl-read-eval-print-loop) - - [.help](#help) - - [Lodash example](#lodash-example) - - [YoutubeDL example](#youtubedl-example) - - [Models examples](#models-examples) +**Table of Contents** + +- [CLI wrapper](#cli-wrapper) +- [Remote Tools](#remote-tools) + - [Dependencies](#dependencies) + - [Installation](#installation) + - [peertube-import-videos.js](#peertube-import-videosjs) + - [peertube-upload.js](#peertube-uploadjs) + - [peertube-watch.js](#peertube-watchjs) +- [Server tools](#server-tools) + - [parse-log](#parse-log) + - [create-transcoding-job.js](#create-transcoding-jobjs) + - [create-import-video-file-job.js](#create-import-video-file-jobjs) + - [prune-storage.js](#prune-storagejs) + - [optimize-old-videos.js](#optimize-old-videosjs) + - [update-host.js](#update-hostjs) + - [REPL (Read Eval Print Loop)](#repl-read-eval-print-loop) + - [.help](#help) + - [Lodash example](#lodash-example) + - [YoutubeDL example](#youtubedl-example) + - [Models examples](#models-examples) -# CLI tools guide - - [CLI wrapper](#cli-wrapper) - - [Remote tools](#remote-tools) - - [peertube-import-videos.js](#peertube-import-videosjs) - - [peertube-upload.js](#peertube-uploadjs) - - [peertube-watch.js](#peertube-watch) - - [Server tools](#server-tools) - - [parse-log](#parse-log) - - [create-transcoding-job.js](#create-transcoding-jobjs) - - [create-import-video-file-job.js](#create-import-video-file-jobjs) - - [prune-storage.js](#prune-storagejs) - ## CLI wrapper The wrapper provides a convenient interface to most scripts, and requires the [same dependencies](#dependencies). You can access it as `peertube` via an alias in your `.bashrc` like `alias peertube="node ${PEERTUBE_PATH}/dist/server/tools/peertube.js"`: @@ -55,6 +44,7 @@ The wrapper provides a convenient interface to most scripts, and requires the [s upload|up upload a video import-videos|import import a video from a streaming platform watch|w watch a video in the terminal ✩°。⋆ + repl initiate a REPL to access internals help [cmd] display help for [cmd] ```