Skip to content

Commit

Permalink
- update dependencies
Browse files Browse the repository at this point in the history
- simplify setup
- remove nwb sass plugin, use glamorous instead
- prettier config
  • Loading branch information
brumm committed Feb 11, 2018
1 parent fd52b1a commit 3f35e43
Show file tree
Hide file tree
Showing 17 changed files with 14,364 additions and 6,976 deletions.
34 changes: 18 additions & 16 deletions dev-server.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
"use strict"
'use strict'

let args = require('minimist')(process.argv.slice(2))
const port = args.port || 8080
const express = require('express')
const app = express()
const electron = require('electron')
const proc = require('child_process')
let args = require('minimist')(process.argv.slice(2))
const port = args.port || 8080
const express = require('express')
const app = express()
const electron = require('electron')
const proc = require('child_process')
const nwbExpress = require('nwb/express')

app.use(nwbExpress(express, {
info: false,
reload: true,
fallback: true,
// autoInstall: true
}))
app.use(
nwbExpress(express, {
info: false,
reload: true,
fallback: true,
// autoInstall: true
})
)

app.listen(port, 'localhost', function(err) {
if (err) {
Expand All @@ -27,13 +29,13 @@ app.listen(port, 'localhost', function(err) {
console.log('starting electron', electron)
const child = proc.spawn(electron, ['.', '--enable-logging'], {
env: {
DEV: true
DEV: true,
},
stdio: "inherit"
stdio: 'inherit',
})

child.on('exit', function(code) {
process.exit()
});
})
}
})
19 changes: 7 additions & 12 deletions main/index.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,24 @@

import { app, BrowserWindow, Menu, screen, ipcMain } from 'electron'
import template from './menu-template.js'
import windowStateKeeper from 'electron-window-state'
import installExtension, { REACT_DEVELOPER_TOOLS } from 'electron-devtools-installer'

const { DEV, PORT = '8080' } = process.env
const windowUrl = DEV
? `http://0.0.0.0:${PORT}/`
: 'file://' + __dirname + '/index.html'
const windowUrl = DEV ? `http://0.0.0.0:${PORT}/` : 'file://' + __dirname + '/index.html'

let mainWindow

function createWindow () {
function createWindow() {
installExtension(REACT_DEVELOPER_TOOLS)
.then(name => {
let { width, height } = screen.getPrimaryDisplay().workAreaSize

Menu.setApplicationMenu(
Menu.buildFromTemplate(template)
)
Menu.setApplicationMenu(Menu.buildFromTemplate(template))

let mainWindowState = windowStateKeeper({
defaultWidth: width * 0.9,
defaultHeight: height * 0.9
});
defaultHeight: height * 0.9,
})

mainWindow = new BrowserWindow({
width: mainWindowState.width,
Expand All @@ -34,9 +29,9 @@ function createWindow () {
minHeight: 700,
titleBarStyle: 'hidden-inset',
webPreferences: {
webSecurity: false
webSecurity: false,
},
show: false
show: false,
})

mainWindowState.manage(mainWindow)
Expand Down
66 changes: 35 additions & 31 deletions main/menu-template.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import electron from 'electron'
const { app } = electron
const { app } = electron
const { name } = app

const template = [
Expand All @@ -8,80 +8,82 @@ const template = [
submenu: [
{
label: 'About ' + name,
role: 'about'
role: 'about',
},
{
type: 'separator'
type: 'separator',
},
{
label: 'Services',
role: 'services',
submenu: []
submenu: [],
},
{
type: 'separator'
type: 'separator',
},
{
label: 'Hide ' + name,
accelerator: 'Command+H',
role: 'hide'
role: 'hide',
},
{
label: 'Hide Others',
accelerator: 'Command+Shift+H',
role: 'hideothers'
role: 'hideothers',
},
{
label: 'Show All',
role: 'unhide'
role: 'unhide',
},
{
type: 'separator'
type: 'separator',
},
{
label: 'Quit',
accelerator: 'Command+Q',
click() { app.quit() }
click() {
app.quit()
},
},
]
],
},
{
label: 'Edit',
submenu: [
{
label: 'Undo',
accelerator: 'CmdOrCtrl+Z',
role: 'undo'
role: 'undo',
},
{
label: 'Redo',
accelerator: 'Shift+CmdOrCtrl+Z',
role: 'redo'
role: 'redo',
},
{
type: 'separator'
type: 'separator',
},
{
label: 'Cut',
accelerator: 'CmdOrCtrl+X',
role: 'cut'
role: 'cut',
},
{
label: 'Copy',
accelerator: 'CmdOrCtrl+C',
role: 'copy'
role: 'copy',
},
{
label: 'Paste',
accelerator: 'CmdOrCtrl+V',
role: 'paste'
role: 'paste',
},
{
label: 'Select All',
accelerator: 'CmdOrCtrl+A',
role: 'selectall'
role: 'selectall',
},
]
],
},
{
label: 'View',
Expand All @@ -93,7 +95,7 @@ const template = [
if (focusedWindow) {
focusedWindow.reload()
}
}
},
},
{
label: 'Toggle Full Screen',
Expand All @@ -102,7 +104,7 @@ const template = [
if (focusedWindow) {
focusedWindow.setFullScreen(!focusedWindow.isFullScreen())
}
}
},
},
{
label: 'Toggle Developer Tools',
Expand All @@ -111,9 +113,9 @@ const template = [
if (focusedWindow) {
focusedWindow.toggleDevTools()
}
}
},
},
]
],
},
{
label: 'Window',
Expand All @@ -122,31 +124,33 @@ const template = [
{
label: 'Minimize',
accelerator: 'CmdOrCtrl+M',
role: 'minimize'
role: 'minimize',
},
{
label: 'Close',
accelerator: 'CmdOrCtrl+W',
role: 'close'
role: 'close',
},
{
type: 'separator'
type: 'separator',
},
{
label: 'Bring All to Front',
role: 'front'
}
]
role: 'front',
},
],
},
{
label: 'Help',
role: 'help',
submenu: [
{
label: 'Learn More',
click() { shell.openExternal('http://electron.atom.io') }
click() {
shell.openExternal('http://electron.atom.io')
},
},
]
],
},
]

Expand Down
30 changes: 14 additions & 16 deletions nwb.config.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
const path = require('path');
const webpack = require('webpack');
const package = require('./package.json');
const ComponentDirectoryPlugin = require('component-directory-webpack-plugin');
const path = require('path')
const webpack = require('webpack')
const package = require('./package.json')

const cssConfig = {
options: {
modules: true,
localIdentName: '[local]-[hash:base64:10]'
}
localIdentName: '[local]-[hash:base64:10]',
},
}

module.exports = {
Expand All @@ -16,26 +15,25 @@ module.exports = {
webpack: {
extra: {
resolve: {
plugins: [new ComponentDirectoryPlugin()],
modules: [path.resolve('./src'), 'node_modules'],
extensions: ['.scss']
extensions: ['.scss'],
},
output: {
publicPath: ''
publicPath: '',
},
target: 'electron-renderer'
target: 'electron-renderer',
},
html: {
template: path.resolve('./src/index.html'),
title: package.name
title: package.name,
},
rules: {
'css': cssConfig,
'sass-css': cssConfig
}
css: cssConfig,
'sass-css': cssConfig,
},
},

babel: {
stage: 0
}
stage: 0,
},
}
Loading

0 comments on commit 3f35e43

Please sign in to comment.