Skip to content

Commit

Permalink
dont download atom-shell -- use local version instead
Browse files Browse the repository at this point in the history
  • Loading branch information
max-mapper committed Apr 4, 2015
1 parent 95c236d commit 330e376
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 49 deletions.
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
language: node_js
node_js:
- '0.12'
4 changes: 2 additions & 2 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
74 changes: 30 additions & 44 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand All @@ -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)
Expand Down
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
2 changes: 2 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 330e376

Please sign in to comment.