|
| 1 | +'use strict' |
| 2 | + |
| 3 | +const path = require('path') |
| 4 | +const spawn = require('child_process').spawn |
| 5 | +const yargs = require('yargs') |
| 6 | +const {app} = require('electron') |
| 7 | + |
| 8 | +class InstallShell { |
| 9 | + |
| 10 | + installShell() { |
| 11 | + const commandName = 'eme' |
| 12 | + const commandPath = path.join(this.getResourcesDirectory(), 'app', 'eme.sh') |
| 13 | + const destinationPath = path.join(this.getInstallDirectory(), commandName) |
| 14 | + this.createSymLink(commandPath, destinationPath) |
| 15 | + } |
| 16 | + |
| 17 | + getInstallDirectory() { |
| 18 | + return '/usr/local/bin' |
| 19 | + } |
| 20 | + |
| 21 | + getResourcesDirectory() { |
| 22 | + return process.resourcesPath |
| 23 | + } |
| 24 | + |
| 25 | + createSymLink(commandPath, destinationPath) { |
| 26 | + try { |
| 27 | + spawn('rm', ['-f', destinationPath]) |
| 28 | + spawn('mkdir', ['-p', path.dirname(destinationPath)]) |
| 29 | + spawn('ln', ['-s', commandPath, destinationPath]) |
| 30 | + } catch (e) { |
| 31 | + console.log(e) |
| 32 | + } |
| 33 | + } |
| 34 | +} |
| 35 | + |
| 36 | +function writeFullVersion() { |
| 37 | + return ( |
| 38 | + process.stdout.write( |
| 39 | + ` |
| 40 | + Atom : ${app.getVersion()} |
| 41 | + Electron: ${process.versions.electron} |
| 42 | + Chrome : ${process.versions.chrome} |
| 43 | + Node : ${process.versions.node} |
| 44 | + ` |
| 45 | + ) |
| 46 | + ) |
| 47 | +} |
| 48 | + |
| 49 | +function parseShellCommand() { |
| 50 | + const options = yargs(process.argv.slice(1)) |
| 51 | + options.usage( |
| 52 | + ` |
| 53 | + Eme Editor |
| 54 | +
|
| 55 | + Usage: eme [options] [path ...] |
| 56 | + ` |
| 57 | + ) |
| 58 | + options.alias('h', 'help').boolean('h').describe('h', 'Print this usage message.') |
| 59 | + options.alias('v', 'version').boolean('v').describe('v', 'Print the version information.') |
| 60 | + |
| 61 | + const args = options.argv |
| 62 | + if (args.help) { |
| 63 | + process.stdout.write(options.help()) |
| 64 | + process.exit(0) |
| 65 | + } |
| 66 | + |
| 67 | + if (args.version) { |
| 68 | + writeFullVersion() |
| 69 | + process.exit(0) |
| 70 | + } |
| 71 | + |
| 72 | + const pathsToOpen = args._ |
| 73 | + const resourcePath = args.executedFrom |
| 74 | + return { |
| 75 | + resourcePath, pathsToOpen |
| 76 | + } |
| 77 | +} |
| 78 | + |
| 79 | +module.exports = { |
| 80 | + InstallShell, |
| 81 | + parseShellCommand |
| 82 | +} |
0 commit comments