Skip to content
This repository has been archived by the owner on Dec 2, 2019. It is now read-only.

Commit

Permalink
packager
Browse files Browse the repository at this point in the history
  • Loading branch information
xwartz committed Apr 24, 2016
1 parent fc028cd commit 4cfbee9
Show file tree
Hide file tree
Showing 10 changed files with 294 additions and 73 deletions.
47 changes: 24 additions & 23 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
module.exports = {
"extends": "standard",
"env": {
"browser": true,
"mocha": true,
"node": true
},
"rules": {
"react/jsx-uses-react": 2,
"react/jsx-uses-vars": 2,
"react/react-in-jsx-scope": 2,
"react/sort-comp": 0,
"react/no-multi-comp": 0,
"comma-dangle": 0,
"id-length": 0,
"new-cap": 0,
"eol-last": 0,
"jsx-quotes": 0,
"consistent-return": 0
},
"plugins": [
"standard",
"react"
]
// "parser": "babel-eslint",
"extends": "standard",
"env": {
"browser": true,
"mocha": true,
"node": true
},
"rules": {
"react/jsx-uses-react": 2,
"react/jsx-uses-vars": 2,
"react/react-in-jsx-scope": 2,
"react/sort-comp": 0,
"react/no-multi-comp": 0,
"comma-dangle": 0,
"id-length": 0,
"new-cap": 0,
"eol-last": 0,
"jsx-quotes": 0,
"consistent-return": 0
},
"plugins": [
"standard",
"react"
]
}
35 changes: 31 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,33 @@
.DS_Store
# Logs
logs
*.log

# Runtime data
pids
*.pid
*.seed

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directory
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
node_modules
!/app/node_modules
npm-debug.log
*.test

# OSX
.DS_Store

# App packaged
dist
release
main.js
main.js.map
Binary file added icons/logo.icns
Binary file not shown.
Binary file added icons/logo.ico
Binary file not shown.
Binary file added icons/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
39 changes: 39 additions & 0 deletions main.dev.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
'use strict'

import { app, BrowserWindow } from 'electron'

let mainWindow = null

app.on('window-all-closed', () => {
app.quit()
})

let winProps = {
width: 1000,
height: 800
}

if (process.env.NODE_ENV !== 'development') {
winProps = {
width: 800,
height: 350,
frame: true,
resizeable: false
}
}

app.on('ready', () => {
mainWindow = new BrowserWindow(winProps)

// mainWindow.loadURL('http://douban.fm')

mainWindow.loadURL(`file://${__dirname}/index.html`)

// if (process.env.NODE_ENV === 'development') {
mainWindow.webContents.openDevTools()
// }

mainWindow.on('closed', () => {
mainWindow = null
})
})
44 changes: 2 additions & 42 deletions main.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

134 changes: 134 additions & 0 deletions package.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
'use strict'

import os from 'os'
import webpack from 'webpack'
import packager from 'electron-packager'
import del from 'del'
import { exec } from 'child_process'
import parseArgs from 'minimist'

import electronCfg from './webpack.config.electron'
import proCfg from './webpack.config.pro'
import pkg from './package'

const argv = parseArgs(process.argv.slice(2))

// const deps = Object.keys(pkg.dependencies)
// const devDeps = Object.keys(pkg.devDependencies)

const appName = argv.name || argv.n || pkg.productName
const shouldUseAsar = argv.asar || argv.a || false
const shouldBuildAll = argv.all || false

const DEFAULT_OPTS = {
dir: './',
name: appName,
asar: shouldUseAsar,
ignore: [
'/test($|/)',
'/tools($|/)',
'/release($|/)',
'/main.dev.js',
'webpack.config.*',
'screen.png',
'/node_modules/',
'/app/'
]
// .concat(devDeps.map((name) => `/node_modules/${name}($|/)`))
// .concat(
// deps.filter((name) => !electronCfg.externals.includes(name))
// .map((name) => `/node_modules/${name}($|/)`)
// )
}

const icon = argv.icon || argv.i || 'icons/logo'

if (icon) {
DEFAULT_OPTS.icon = icon
}

const version = argv.version || argv.v

if (version) {
DEFAULT_OPTS.version = version
startPack()
} else {
// use the same version as the currently-installed electron-prebuilt
exec('npm list electron-prebuilt --dev', (err, stdout) => {
if (err) {
DEFAULT_OPTS.version = '0.37.6'
} else {
DEFAULT_OPTS.version = stdout.split('electron-prebuilt@')[1].replace(/\s/g, '')
}
startPack()
})
}

function build (cfg) {
return new Promise((resolve, reject) => {
webpack(cfg, (err, stats) => {
if (err) return reject(err)
resolve(stats)
})
})
}

function startPack () {
console.log('start pack...')
build(electronCfg)
.then(() => build(proCfg))
.then(() => del('release/**', { force: true }))
.then((paths) => {
if (shouldBuildAll) {
// build for all platforms
const archs = ['ia32', 'x64']
const platforms = ['linux', 'win32', 'darwin']

platforms.forEach((plat) => {
archs.forEach((arch) => {
pack(plat, arch, log(plat, arch))
})
})
} else {
// build for current platform only
pack(os.platform(), os.arch(), log(os.platform(), os.arch()))
}
})
.catch((err) => {
console.error(err)
})
}

function pack (plat, arch, cb) {
// there is no darwin ia32 electron
if (plat === 'darwin' && arch === 'ia32') return

const iconObj = {
icon: DEFAULT_OPTS.icon + (() => {
let extension = '.png'
if (plat === 'darwin') {
extension = '.icns'
} else if (plat === 'win32') {
extension = '.ico'
}
return extension
})()
}

const opts = Object.assign({}, DEFAULT_OPTS, iconObj, {
platform: plat,
arch,
prune: true,
'app-version': pkg.version || DEFAULT_OPTS.version,
out: `release/${plat}-${arch}`
})

packager(opts, cb)
}

function log (plat, arch) {
return (err, filepath) => {
if (err) return console.error(err)
console.log(`${plat}-${arch} finished!`)
}
}
13 changes: 9 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
{
"name": "douban.fm",
"productName": "doubanFM",
"version": "1.0.0",
"description": "豆瓣fm的桌面版",
"main": "main.js",
"scripts": {
"lint": "eslint app test *.js",
"server-hot": "node -r babel-register dev-server.js",
"start-hot": "NODE_ENV=development electron -r babel-register ./",
"build-renderer": "NODE_ENV=production node -r babel-register ./node_modules/.bin/webpack --config webpack.config.pro.js --progress --profile --colors",
"start": "NODE_ENV=production electron -r babel-register ./",
"start-hot": "cross-env NODE_ENV=development electron -r babel-register ./main.dev",
"build-renderer": "cross-env NODE_ENV=production node -r babel-register ./node_modules/.bin/webpack --config webpack.config.pro.js --progress --profile --colors",
"start": "cross-env NODE_ENV=production electron -r babel-register ./main.dev",
"package": "cross-env NODE_ENV=production node -r babel-register package.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
Expand All @@ -27,12 +29,15 @@
"devDependencies": {
"babel": "^6.5.2",
"babel-core": "^6.7.2",
"babel-eslint": "^6.0.3",
"babel-loader": "^6.2.4",
"babel-polyfill": "^6.7.4",
"babel-preset-es2015": "^6.5.0",
"babel-preset-react": "^6.5.0",
"babel-preset-stage-0": "^6.5.0",
"babel-register": "^6.7.2",
"css-loader": "^0.23.1",
"del": "^2.2.0",
"electron-builder": "^2.8.3",
"electron-packager": "^5.2.1",
"electron-prebuilt": "^0.37.2",
Expand All @@ -44,8 +49,8 @@
"express": "^4.13.4",
"extract-text-webpack-plugin": "^1.0.1",
"gulp": "^3.9.1",
"html-webpack-plugin": "^2.15.0",
"json-loader": "^0.5.4",
"minimist": "^1.2.0",
"node-sass": "^3.5.3",
"react-hot-loader": "^1.3.0",
"sass-loader": "^3.2.0",
Expand Down
Loading

0 comments on commit 4cfbee9

Please sign in to comment.