Add bin CLI tool

This commit is contained in:
Shawn 2019-03-28 21:49:05 -05:00
parent 142684f134
commit 9380736640
3 changed files with 1663 additions and 0 deletions

51
lbry-format.js Normal file
View file

@ -0,0 +1,51 @@
#!/usr/bin/env node
const {
packDirectory,
unpackDirectory,
} = require('lbry-format');
const path = require('path');
require('yargs')
.scriptName('lbry-pack')
.usage('$0 <cmd> [args]')
.command('pack [directory] [file]', 'Pack a directory', (yargs) => {
yargs.positional('directory', {
default: './src',
describe: 'The source directory to pack'
}).positional('file', {
describe: 'Output file',
default: './package.lbry',
})
}, function (argv) {
console.log(`Packing ${argv.directory} to ${argv.file}`);
const resolvedDirectory = path.resolve(argv.directory);
const resolvedfile = path.resolve(argv.file);
packDirectory(resolvedDirectory, {
fileName: resolvedfile,
});
})
.command('unpack [directory] [file]', 'Unpack a file', (yargs) => {
yargs.positional('destination', {
type: 'string',
default: './src',
describe: 'The folder destination to unpack to'
}).positional('file', {
describe: 'Input filename',
default: 'package.lbry',
})
}, function (argv) {
console.log(`Packing ${argv.directory} to ${argv.file}`);
const resolvedDirectory = path.resolve(argv.directory);
const resolvedfile = path.resolve(argv.file);
unpackDirectory(resolvedDirectory, {
fileName: resolvedfile,
});
})
.help()
.demandCommand()
.argv

1604
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -10,6 +10,14 @@
"license": "MIT",
"dependencies": {
"tar-stream": "^1.6.2",
"yargs": "^13.2.2",
"zstd-codec": "^0.1.1"
},
"devDependencies": {
"browserify": "^16.2.3",
"filereader-stream": "^2.0.0"
},
"bin": {
"lbry-format": "./lbry-format.js"
}
}