Created
October 10, 2017 09:19
-
-
Save benmerckx/b414aa1eb3db7e7d64d68914080d5640 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const path = require('path') | |
const fs = require('fs') | |
const [script, name] = process.argv.slice(2) | |
switch (script) { | |
case undefined: | |
case '-h': | |
case '--help': | |
console.log(` | |
nodejs port of appify v3.0.1 - http://mths.be/appify | |
Creates the simplest possible Mac app from a shell script. | |
Appify takes a shell script as its first argument: | |
appifyjs my-script.sh | |
Note that you cannot rename appified apps. If you want to give your app | |
a custom name, use the second argument: | |
appifyjs my-script.sh "My App" | |
Copyright (c) Thomas Aylott <http://subtlegradient.com/> | |
Modified by Mathias Bynens <http://mathiasbynens.be/> | |
Ported by Ben Merckx | |
`.split('\t').join('').trim()) | |
break | |
default: | |
const appName = name || path.basename(script).split('.').slice(0, -1).join('.') | |
const pwd = process.cwd() | |
const dir = `${appName}.app/Contents/MacOS` | |
if (fs.existsSync(dir)) { | |
console.log(`${pwd}/${appName}.app already exists :(`) | |
process.exit(1) | |
} | |
dir.split('/') | |
.reduce((acc, curr) => { | |
const dir = `${acc}/${curr}` | |
fs.mkdirSync(dir) | |
return dir | |
}, pwd) | |
fs.writeFileSync(`${dir}/${appName}`, fs.readFileSync(script)) | |
fs.chmodSync(`${dir}/${appName}`, 0755) | |
console.log(`${pwd}/${appName}.app`) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment