Merge pull request #27 from desktop/fix-start-race

Fix start race
This commit is contained in:
Markus Olsson 2016-05-27 18:15:56 +02:00
commit 2d960c6abf
5 changed files with 42 additions and 42 deletions

View file

@ -6,16 +6,8 @@ Just playin around with some computering.
npm install
```
If you want hot loading:
To build and run the app:
```
# Start the dev server
npm start
```
Or if you don't care:
```
npm run build
npm run dev
```

View file

@ -1,24 +0,0 @@
'use strict'
const express = require('express')
const webpack = require('webpack')
const config = require('./webpack.development')
const app = express()
const compiler = webpack(config)
const port = process.env.PORT || 3000
app.use(require('webpack-dev-middleware')(compiler, {
publicPath: config.output.publicPath
}))
app.use(require('webpack-hot-middleware')(compiler))
app.listen(port, 'localhost', err => {
if (err) {
console.log(err)
return
}
console.log(`Listening at http://localhost:${port}`)
})

View file

@ -13,9 +13,7 @@
"scripts": {
"test": "electron-mocha --renderer --require ts-node/register test/*.ts test/*.tsx",
"postinstall": "typings install",
"start-server": "node dev_server.js",
"start": "npm run build:dev && npm-run-all --parallel run start-server",
"run": "env NODE_ENV=development node script/run",
"start": "npm run build:dev && node script/start",
"compile:dev": "tsc && env NODE_ENV=development webpack --config webpack.development.js",
"compile:prod": "tsc && env NODE_ENV=production webpack --config webpack.production.js",
"build:dev": "npm run compile:dev && env NODE_ENV=development node script/build",
@ -55,7 +53,6 @@
"express": "^4.13.4",
"fs-extra": "^0.30.0",
"mocha": "^2.4.5",
"npm-run-all": "^1.8.0",
"react-addons-test-utils": "^15.0.2",
"ts-loader": "^0.8.2",
"ts-node": "^0.7.2",

View file

@ -1,5 +1,3 @@
#!/usr/bin/env node
'use strict'
const path = require('path')
@ -7,15 +5,19 @@ const cp = require('child_process')
const distInfo = require('./dist-info')
const distPath = distInfo.getDistPath()
const productName = distInfo.getProductName()
let binaryPath = ''
if (process.platform === 'darwin') {
binaryPath = path.join(distPath, 'GitHub.app', 'Contents', 'MacOS', 'GitHub')
binaryPath = path.join(distPath, `${productName}.app`, 'Contents', 'MacOS', `${productName}`)
} else if (process.platform === 'win32') {
binaryPath = path.join(distPath, 'GitHub')
binaryPath = path.join(distPath, `${productName}`)
} else {
console.error(`I dunno how to run on ${process.arch} :(`)
process.exit(1)
}
cp.spawn(binaryPath, [], {env: process.env})
module.exports = function () {
const env = Object.assign({}, process.env, {NODE_ENV: 'development'})
return cp.spawn(binaryPath, [], {env})
}

33
script/start Normal file
View file

@ -0,0 +1,33 @@
#!/usr/bin/env node
'use strict'
const express = require('express')
const webpack = require('webpack')
const config = require('../webpack.development')
const run = require('./run')
const server = express()
const compiler = webpack(config)
const port = process.env.PORT || 3000
server.use(require('webpack-dev-middleware')(compiler, {
publicPath: config.output.publicPath
}))
server.use(require('webpack-hot-middleware')(compiler))
server.listen(port, 'localhost', err => {
if (err) {
console.log(err)
process.exit(1)
return
}
console.log(`Server running at http://localhost:${port}`)
const runningApp = run()
runningApp.on('close', () => {
process.exit(0)
})
})