|
| 1 | +#!/usr/bin/env node |
| 2 | + |
| 3 | +'use strict'; |
| 4 | + |
| 5 | +/* eslint-disable no-process-exit */ |
| 6 | + |
| 7 | +/* |
| 8 | + * Dependencies. |
| 9 | + */ |
| 10 | +import { |
| 11 | + createSfxMac, |
| 12 | + createSfxLinux, |
| 13 | + createSfxWindows |
| 14 | +} from '../lib/index.mjs'; |
| 15 | +import minimist from 'minimist'; |
| 16 | +import { |
| 17 | + join |
| 18 | +} from 'path'; |
| 19 | +import { |
| 20 | + userInfo |
| 21 | +} from 'os'; |
| 22 | +import { |
| 23 | + createRequire |
| 24 | +} from 'module'; |
| 25 | + |
| 26 | +const require = createRequire( |
| 27 | + import.meta.url); |
| 28 | +const pack = require('../package.json'); |
| 29 | + |
| 30 | +/* |
| 31 | + * Arguments. |
| 32 | + */ |
| 33 | +let argv = minimist(process.argv.slice(2)); |
| 34 | + |
| 35 | +/* |
| 36 | + * Command. |
| 37 | + */ |
| 38 | +var command = Object.keys(pack.bin)[7]; |
| 39 | + |
| 40 | +/** |
| 41 | + * Help. |
| 42 | + * |
| 43 | + * @return {string} |
| 44 | + */ |
| 45 | +function help() { |
| 46 | + return [ |
| 47 | + 'Create an Sfx - self extracting installation package for targeted platform.', |
| 48 | + 'Usage: ' + command + ' platform packageName files --dir destination --gui --console ...options', |
| 49 | + '', |
| 50 | + pack.description, |
| 51 | + '', |
| 52 | + ' [platform] - Target platform, either `windows`, `linux`, or `macos`.', |
| 53 | + ' [name] - Installation package name.', |
| 54 | + ' [files] - Files to add.', |
| 55 | + ' --dir - Save the `SFX` package to directory. Defaults to current user desktop', |
| 56 | + ' --gui - Make the Sfx installation package have a Graphical User Interfere.', |
| 57 | + ' --console - Make the Sfx installation package have a Console interfere.', |
| 58 | + '', |
| 59 | + 'Options:', |
| 60 | + '', |
| 61 | + ' -h, --help output usage information', |
| 62 | + ' -v, --version output version number', |
| 63 | + '', |
| 64 | + ' Any of these 7zip switches this command accepts:', |
| 65 | + '', |
| 66 | + ' For Installer config if GUI and targeting Windows:', |
| 67 | + ' --title - Window title message, Default "`packageName` installation package created on `Current running platform OS`".', |
| 68 | + ' --prompt - Begin Prompt message, Default "Do you want to install `packageName`?"', |
| 69 | + ' --progress - Value can be "yes" or "no". Default value is "no".', |
| 70 | + ' --run - Command from archive for executing after extracting. Default value is "setup.exe". Substring `% % T` will be replaced with path to temporary folder, where files were extracted.', |
| 71 | + ' --directory - Directory prefix for --run. Default value is `.\\`', |
| 72 | + ' --execute - Name of some other system file for executing after extraction.', |
| 73 | + ' --parameters - Parameters for --execute.', |
| 74 | + '', |
| 75 | + '-----------', |
| 76 | + '', |
| 77 | + ' -i (Include filenames)', |
| 78 | + ' -m (Set compression Method)', |
| 79 | + ' -p (Set Password)', |
| 80 | + ' -r (Recurse subdirectories)', |
| 81 | + ' -sdel (Delete files after compression)', |
| 82 | + ' -si (read data from stdin)', |
| 83 | + ' -sni (Store NT security information)', |
| 84 | + ' -sns (Store NTFS alternate Streams)', |
| 85 | + ' -so (write data to stdout)', |
| 86 | + ' -spf (Use fully qualified file paths)', |
| 87 | + ' -ssw (Compress files open for writing)', |
| 88 | + ' -stl (Set archive timestamp from the most recently modified file)', |
| 89 | + ' -t (set Type of archive)', |
| 90 | + ' -u (Update options)', |
| 91 | + ' -v (Create Volumes)', |
| 92 | + ' -w (set Working directory)', |
| 93 | + ' -x (Exclude filenames)', |
| 94 | + '', |
| 95 | + 'Example:', |
| 96 | + '> ' + command + ' windows Support disc/* support.doc --dir user/desktop --gui --title "Sample Installer Package"', |
| 97 | + '' |
| 98 | + ].join('\n ') + '\n'; |
| 99 | +} |
| 100 | + |
| 101 | +/* |
| 102 | + * Program. |
| 103 | + */ |
| 104 | +if (argv.help || argv.h) { |
| 105 | + console.log(help()); |
| 106 | +} else if (argv.version || argv.v) { |
| 107 | + console.log(pack.version); |
| 108 | +} else if (argv) { |
| 109 | + let options = {}; |
| 110 | + let files = argv._; |
| 111 | + let platform = files.shift(); |
| 112 | + if (platform) { |
| 113 | + let packageName = files.shift(); |
| 114 | + let sfxPromise = null; |
| 115 | + let destination = (argv.dir) ? argv.dir : join(userInfo().homedir, 'Desktop'); |
| 116 | + let type = (argv.gui) ? 'gui' : 'console'; |
| 117 | + type = (argv.console || platform === 'linux' || platform === 'macos') ? 'console' : type; |
| 118 | + delete argv._; |
| 119 | + delete argv.gui; |
| 120 | + delete argv.console; |
| 121 | + delete argv.dir; |
| 122 | + options = Object.assign(options, argv) |
| 123 | + |
| 124 | + if (platform === 'win32') |
| 125 | + sfxPromise = createSfxWindows(packageName, files, destination, options, type); |
| 126 | + else if (platform === 'macos') |
| 127 | + sfxPromise = createSfxMac(packageName, files, destination, options); |
| 128 | + else if (platform === 'linux') |
| 129 | + sfxPromise = createSfxLinux(packageName, files, destination, options); |
| 130 | + |
| 131 | + if (packageName && files && typeof sfxPromise.then === 'function') { |
| 132 | + console.log("Creating Sfx Package..."); |
| 133 | + sfxPromise.progress((info) => { |
| 134 | + console.log(info); |
| 135 | + }) |
| 136 | + .then((file) => { |
| 137 | + console.log('Creation of installation package ' + packageName + ' saved to ' + file + ' done!'); |
| 138 | + }) |
| 139 | + .catch((error) => { |
| 140 | + console.log('--- error:'); |
| 141 | + console.log(error); |
| 142 | + }); |
| 143 | + } else { |
| 144 | + console.log(help()); |
| 145 | + } |
| 146 | + } else { |
| 147 | + console.log(help()); |
| 148 | + } |
| 149 | +} else { |
| 150 | + console.log(help()); |
| 151 | +} |
0 commit comments