1 import * as program from 'commander'
2 import * as Promise from 'bluebird'
3 import { isAbsolute, join } from 'path'
5 import { readdirPromise } from '../../../helpers/core-utils'
6 import { execCLI } from '../../utils'
9 .option('-u, --url <url>', 'Server url')
10 .option('-U, --username <username>', 'Username')
11 .option('-p, --password <token>', 'Password')
12 .option('-i, --input <directory>', 'Videos directory absolute path')
13 .option('-d, --description <description>', 'Video descriptions')
14 .option('-c, --category <category>', 'Video categories')
15 .option('-l, --licence <licence>', 'Video licences')
16 .option('-t, --tags <tags>', 'Video tags', list)
21 !program['username'] ||
22 !program['password'] ||
24 !program['description'] ||
25 !program['category'] ||
26 !program['licence'] ||
29 throw new Error('All arguments are required.')
32 if (isAbsolute(program['input']) === false) {
33 throw new Error('Input path should be absolute.')
36 let command = `npm run ts-node -- ${__dirname}/get-access-token.ts`
37 command += ` -u "${program['url']}"`
38 command += ` -n "${program['username']}"`
39 command += ` -p "${program['password']}"`
43 const accessToken = stdout.replace('\n', '')
45 console.log(accessToken)
47 return readdirPromise(program['input']).then(files => ({ accessToken, files }))
49 .then(({ accessToken, files }) => {
50 return Promise.each(files, file => {
52 tags: program['tags'],
54 description: program['description'],
55 category: program['category'],
56 licence: program['licence']
59 let command = `npm run ts-node -- ${__dirname}/upload.ts`
60 command += ` -u "${program['url']}"`
61 command += ` -a "${accessToken}"`
62 command += ` -n "${video.name}"`
63 command += ` -d "${video.description}"`
64 command += ` -c "${video.category}"`
65 command += ` -l "${video.licence}"`
66 command += ` -t "${video.tags.join(',')}"`
67 command += ` -f "${join(program['input'], file)}"`
69 return execCLI(command).then(stdout => console.log(stdout))
72 .then(() => process.exit(0))
78 // ----------------------------------------------------------------------------