1 | #!/usr/bin/env node
|
2 | var asar = require('../lib/asar')
|
3 | var program = require('commander')
|
4 |
|
5 | program.version('v' + require('../package.json').version)
|
6 | .description('Manipulate asar archive files')
|
7 |
|
8 | program.command('pack <dir> <output>')
|
9 | .alias('p')
|
10 | .description('create asar archive')
|
11 | .option('--ordering <file path>', 'path to a text file for ordering contents')
|
12 | .option('--unpack <expression>', 'do not pack files matching glob <expression>')
|
13 | .option('--unpack-dir <expression>', 'do not pack dirs matching glob <expression> or starting with literal <expression>')
|
14 | .option('--exclude-hidden', 'exclude hidden files')
|
15 | .action(function (dir, output, options) {
|
16 | options = {
|
17 | unpack: options.unpack,
|
18 | unpackDir: options.unpackDir,
|
19 | ordering: options.ordering,
|
20 | version: options.sv,
|
21 | arch: options.sa,
|
22 | builddir: options.sb,
|
23 | dot: !options.excludeHidden
|
24 | }
|
25 | asar.createPackageWithOptions(dir, output, options, function (error) {
|
26 | if (error) {
|
27 | console.error(error.stack)
|
28 | process.exit(1)
|
29 | }
|
30 | })
|
31 | })
|
32 |
|
33 | program.command('list <archive>')
|
34 | .alias('l')
|
35 | .description('list files of asar archive')
|
36 | .option('-i, --is-pack', 'each file in the asar is pack or unpack')
|
37 | .action(function (archive, options) {
|
38 | options = {
|
39 | isPack: options.isPack
|
40 | }
|
41 | var files = asar.listPackage(archive, options)
|
42 | for (var i in files) {
|
43 | console.log(files[i])
|
44 | }
|
45 |
|
46 | process.exit(0)
|
47 | })
|
48 |
|
49 | program.command('extract-file <archive> <filename>')
|
50 | .alias('ef')
|
51 | .description('extract one file from archive')
|
52 | .action(function (archive, filename) {
|
53 | require('fs').writeFileSync(require('path').basename(filename),
|
54 | asar.extractFile(archive, filename))
|
55 | })
|
56 |
|
57 | program.command('extract <archive> <dest>')
|
58 | .alias('e')
|
59 | .description('extract archive')
|
60 | .action(function (archive, dest) {
|
61 | asar.extractAll(archive, dest)
|
62 | })
|
63 |
|
64 | program.command('*')
|
65 | .action(function (cmd) {
|
66 | console.log('asar: \'%s\' is not an asar command. See \'asar --help\'.', cmd)
|
67 | })
|
68 |
|
69 | program.parse(process.argv)
|
70 |
|
71 | if (program.args.length === 0) {
|
72 | program.help()
|
73 | }
|