diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..dd5ab9b --- /dev/null +++ b/.travis.yml @@ -0,0 +1,3 @@ +language: node_js +node_js: + - '0.12' diff --git a/cli.js b/cli.js index 3534d3c..04dcbf8 100755 --- a/cli.js +++ b/cli.js @@ -13,8 +13,8 @@ if (!args.dir || !args.name) { packager(args, function done (err, appPath) { if (err) { console.error(err) - process.exit(1) + process.exit(1) } - + console.error('Wrote new app to', appPath) }) diff --git a/index.js b/index.js index d674989..ca4a239 100644 --- a/index.js +++ b/index.js @@ -3,78 +3,64 @@ var path = require('path') var fs = require('fs') var child = require('child_process') -var nugget = require('nugget') var plist = require('plist') -var unzip = require('extract-zip') var mkdirp = require('mkdirp') var rimraf = require('rimraf') var ncp = require('ncp').ncp -var latest = '0.22.1' - module.exports = function packager (opts, cb) { - if (!opts.version) opts.version = latest - - var names = { - mac: 'atom-shell-v' + opts.version + '-darwin-x64' + try { + var atomShellPath = require.resolve('atom-shell') + atomShellPath = path.join(atomShellPath, '..') + } catch (e) { + cb(new Error('Cannot find atom-shell from here, please install it from npm')) } - - var macUrl = 'https://github.com/atom/atom-shell/releases/download/v' + opts.version + '/' + names.mac + '.zip' - var localFile = path.join(__dirname, 'downloaded', names.mac + '.zip') - var tmpDir = path.join(os.tmpdir(), names.mac) - + + var atomPkg = require(path.join(atomShellPath, 'package.json')) + console.error('Using atom-shell version', atomPkg.version, 'from', atomShellPath) + + var atomShellApp = path.join(atomShellPath, 'dist', 'Atom.app') + var tmpDir = path.join(os.tmpdir(), 'atom-shell-packager-mac') + + var newApp = path.join(tmpDir, opts.name + '.app') + + // reset build folders + copy template app rimraf(tmpDir, function rmrfd () { // ignore errors - mkdirp(tmpDir, function mkdirpd () { + mkdirp(newApp, function mkdirpd () { // ignore errors - if (opts.zip) extractZip(opts.zip) - else downloadZip() + // copy .app folder and use as template (this is exactly what Atom editor does) + ncp(atomShellApp, newApp, function copied (err) { + if (err) return cb(err) + buildMacApp() + }) }) }) - - function downloadZip () { - nugget(macUrl, {target: localFile, dir: path.join(__dirname, 'downloaded'), resume: true, verbose: true}, function downloaded (err) { - if (err) return cb(err) - extractZip(localFile) - }) - } - - function extractZip (filename) { - unzip(filename, {dir: tmpDir}, function extracted (err) { - if (err) return cb(err) - buildApp() - }) - } - - function buildApp () { - var newApp = path.join(tmpDir, opts.name + '.app') - - // rename .app folder (this is exactly what Atom editor does) - fs.renameSync(path.join(tmpDir, 'Atom.app'), newApp) - + + function buildMacApp () { var paths = { info1: path.join(newApp, 'Contents', 'Info.plist'), info2: path.join(newApp, 'Contents', 'Frameworks', 'Atom Helper.app', 'Contents', 'Info.plist'), app: path.join(newApp, 'Contents', 'Resources', 'app') } - + // update plist files var pl1 = plist.parse(fs.readFileSync(paths.info1).toString()) var pl2 = plist.parse(fs.readFileSync(paths.info2).toString()) - + var bundleId = opts['app-bundle-id'] || 'com.atom-shell.' + opts.name.toLowerCase() var bundleHelperId = opts['helper-bundle-id'] || 'com.atom-shell.' + opts.name.toLowerCase() + '.helper' - + pl1.CFBundleDisplayName = opts.name pl1.CFBundleIdentifier = bundleId pl1.CFBundleName = opts.name pl2.CFBundleIdentifier = bundleHelperId pl2.CFBundleName = opts.name - + fs.writeFileSync(paths.info1, plist.build(pl1)) fs.writeFileSync(paths.info2, plist.build(pl2)) - - function filter(file) { + + function filter (file) { var ignore = opts.ignore || [] if (!Array.isArray(ignore)) ignore = [ignore] for (var i = 0; i < ignore.length; i++) { @@ -84,7 +70,7 @@ module.exports = function packager (opts, cb) { } return true } - + // copy users app into .app ncp(opts.dir, paths.app, {filter: filter}, function copied (err) { if (err) return cb(err) diff --git a/package.json b/package.json index f61c260..7edc083 100644 --- a/package.json +++ b/package.json @@ -17,16 +17,14 @@ }, "homepage": "https://github.com/maxogden/atom-shell-packager", "dependencies": { - "extract-zip": "^1.0.3", "minimist": "^1.1.1", "mkdirp": "^0.5.0", "ncp": "^2.0.0", - "nugget": "^1.4.1", "plist": "^1.1.0", "rimraf": "^2.3.2" }, "devDependencies": {}, "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" + "test": "standard" } } diff --git a/readme.md b/readme.md index 0955488..557cf5f 100644 --- a/readme.md +++ b/readme.md @@ -4,6 +4,8 @@ Build a distributable app from an atom-shell app source code directory. **Curren [![NPM](https://nodei.co/npm/atom-shell-packager.png)](https://nodei.co/npm/atom-shell-packager/) +[![Build Status](https://travis-ci.org/maxogden/atom-shell-packager.svg?branch=master)](https://travis-ci.org/maxogden/atom-shell-packager) + For an example project using this, check out [Monu](https://github.com/maxogden/monu) ### installation