Skip to content

Commit

Permalink
[update] add standard linter and fix warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
sergiodxa committed May 24, 2017
1 parent 6e37d9e commit 44f9fea
Show file tree
Hide file tree
Showing 12 changed files with 893 additions and 102 deletions.
11 changes: 3 additions & 8 deletions main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const setIPCEvents = require('./ipc-events')

const windows = []

async function createWindow() {
async function createWindow () {
let win
let server

Expand All @@ -30,8 +30,8 @@ async function createWindow() {
show: false,
webPreferences: {
devTools: dev,
textAreasAreResizable: false,
},
textAreasAreResizable: false
}
})

windows.push(win)
Expand Down Expand Up @@ -78,8 +78,3 @@ app.on('activate', () => {
createWindow()
}
})

app.on('open-url', (event, string) => {
event.preventDefault()
fs.writeFileSync('~/test', 'utf8', string)
})
4 changes: 2 additions & 2 deletions main/ipc-events.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module.exports = () => {
const files = dialog.showOpenDialog({
defaultPath: app.getPath('documents'),
filters: [{ name: 'Markdown', extensions: ['md'] }],
properties: ['openFile'],
properties: ['openFile']
})

if (!files || files.length === 0) return
Expand All @@ -31,7 +31,7 @@ module.exports = () => {
dialog.showSaveDialog({
defaultPath: app.getPath('documents'),
filters: [{ name: 'Markdown', extensions: ['md'] }, { name: 'All Files', extensions: ['*'] }],
showsTagField: false,
showsTagField: false
})

if (!fileName) return
Expand Down
27 changes: 13 additions & 14 deletions main/menu.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const { app, Menu, shell } = require('electron')
const dev = require('electron-is-dev')

const template = [
{
Expand All @@ -13,8 +12,8 @@ const template = [
{ role: 'paste' },
{ role: 'pasteandmatchstyle' },
{ role: 'delete' },
{ role: 'selectall' },
],
{ role: 'selectall' }
]
},
{
label: 'View',
Expand All @@ -26,22 +25,22 @@ const template = [
{ role: 'zoomin' },
{ role: 'zoomout' },
{ type: 'separator' },
{ role: 'togglefullscreen' },
],
{ role: 'togglefullscreen' }
]
},
{
role: 'window',
submenu: [{ role: 'minimize' }, { role: 'close' }],
submenu: [{ role: 'minimize' }, { role: 'close' }]
},
{
role: 'help',
submenu: [
{
label: 'Learn More',
click: () => shell.openExternal('https://platzi.com'),
},
],
},
click: () => shell.openExternal('https://platzi.com')
}
]
}
]

if (process.platform === 'darwin') {
Expand All @@ -56,16 +55,16 @@ if (process.platform === 'darwin') {
{ role: 'hideothers' },
{ role: 'unhide' },
{ type: 'separator' },
{ role: 'quit' },
],
{ role: 'quit' }
]
})

// Edit menu
template[1].submenu.push(
{ type: 'separator' },
{
label: 'Speech',
submenu: [{ role: 'startspeaking' }, { role: 'stopspeaking' }],
submenu: [{ role: 'startspeaking' }, { role: 'stopspeaking' }]
}
)

Expand All @@ -75,7 +74,7 @@ if (process.platform === 'darwin') {
{ role: 'minimize' },
{ role: 'zoom' },
{ type: 'separator' },
{ role: 'front' },
{ role: 'front' }
]
}

Expand Down
1 change: 0 additions & 1 deletion main/server.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const { app } = require('electron')
const { createServer } = require('http')
const next = require('next')

const dev = require('electron-is-dev')

Expand Down
19 changes: 17 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,19 @@
"prepack": "npm run clean",
"predist": "npm run clean",
"pack": "npm run build && build --dir",
"dist": "npm run build && build"
"dist": "npm run build && build",
"lint": "standard 'main/*.js' 'renderer/**/*.js'",
"precommit": "lint-staged"
},
"standard": {
"parser": "babel-eslint",
"ignore": [
"**/node_modules/**",
"**/.next/**"
]
},
"lint-staged": {
"*.js": "standard"
},
"build": {
"appId": "co.platzi.pulse",
Expand Down Expand Up @@ -62,8 +74,11 @@
"react-icons": "^2.2.5"
},
"devDependencies": {
"babel-eslint": "^7.2.3",
"babili-webpack-plugin": "^0.0.11",
"electron": "^1.6.8",
"electron-builder": "^17.8.0"
"electron-builder": "^17.8.0",
"lint-staged": "^3.4.2",
"standard": "^10.0.2"
}
}
14 changes: 7 additions & 7 deletions renderer/components/new-button.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Component } from 'react'
import { Base } from 'pulse-editor/buttons'
import { string, func } from 'prop-types'
import { func } from 'prop-types'
import isMac from 'pulse-editor/built/utils/is-mac'
import Icon from 'react-icons/lib/fa/file-o'

Expand All @@ -9,10 +9,10 @@ export default class NewButton extends Component {
setShortcut: func.isRequired,
setFileName: func.isRequired,
removeShortcut: func.isRequired,
writeValue: func.isRequired,
writeValue: func.isRequired
}

componentDidMount() {
componentDidMount () {
this.context.setShortcut({
ctrlKey: !isMac(),
metaKey: isMac(),
Expand All @@ -23,11 +23,11 @@ export default class NewButton extends Component {
handler: event => {
this.createFile()
return event.selection
},
}
})
}

componentWillUnmount() {
componentWillUnmount () {
this.context.removeShortcut({ keyName: 'o' })
}

Expand All @@ -39,8 +39,8 @@ export default class NewButton extends Component {
handleClick = () => this.createFile()

render = () => (
<Base onClick={this.handleClick} name="new">
<span title="New file [CMD+N]">
<Base onClick={this.handleClick} name='new'>
<span title='New file [CMD+N]'>
<Icon /> New file
</span>
</Base>
Expand Down
14 changes: 7 additions & 7 deletions renderer/components/open-button.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Component } from 'react'
import { Base } from 'pulse-editor/buttons'
import { ipcRenderer } from 'electron'
import { string, func } from 'prop-types'
import { func } from 'prop-types'
import isMac from 'pulse-editor/built/utils/is-mac'
import Icon from 'react-icons/lib/fa/folder-open-o'

Expand All @@ -10,10 +10,10 @@ export default class OpenButton extends Component {
setShortcut: func.isRequired,
removeShortcut: func.isRequired,
writeValue: func.isRequired,
setFileName: func.isRequired,
setFileName: func.isRequired
}

componentDidMount() {
componentDidMount () {
ipcRenderer.on('file-opened', this.handleOpen)
this.context.setShortcut({
ctrlKey: !isMac(),
Expand All @@ -25,11 +25,11 @@ export default class OpenButton extends Component {
handler: event => {
this.openFile()
return event.selection
},
}
})
}

componentWillUnmount() {
componentWillUnmount () {
this.context.removeShortcut({ keyName: 'o' })
ipcRenderer.removeListener('file-opened', this.handleOpen)
}
Expand All @@ -44,8 +44,8 @@ export default class OpenButton extends Component {
}

render = () => (
<Base onClick={this.handleClick} name="open">
<span title="Open file [CMD+O]">
<Base onClick={this.handleClick} name='open'>
<span title='Open file [CMD+O]'>
<Icon /> Open file
</span>
</Base>
Expand Down
14 changes: 7 additions & 7 deletions renderer/components/save-button.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Component } from 'react'
import { Base } from 'pulse-editor/buttons'
import { ipcRenderer } from 'electron'
import { string, func, bool } from 'prop-types'
import { string, func } from 'prop-types'
import isMac from 'pulse-editor/built/utils/is-mac'
import Icon from 'react-icons/lib/fa/floppy-o'

Expand All @@ -11,10 +11,10 @@ export default class SaveButton extends Component {
value: string.isRequired,
setShortcut: func.isRequired,
removeShortcut: func.isRequired,
setFileName: func.isRequired,
setFileName: func.isRequired
}

componentDidMount() {
componentDidMount () {
ipcRenderer.on('file-saved', this.handleSaved)
this.context.setShortcut({
ctrlKey: !isMac(),
Expand All @@ -26,11 +26,11 @@ export default class SaveButton extends Component {
handler: event => {
this.saveFile()
return event.selection
},
}
})
}

componentWillUnmount() {
componentWillUnmount () {
ipcRenderer.removeListener('file-saved', this.handleSaved)
this.context.removeShortcut({ keyName: 's' })
}
Expand All @@ -46,8 +46,8 @@ export default class SaveButton extends Component {
}

render = () => (
<Base onClick={this.handleClick} name="save">
<span title="Save file [CMD+S]">
<Base onClick={this.handleClick} name='save'>
<span title='Save file [CMD+S]'>
<Icon /> Save file
</span>
</Base>
Expand Down
8 changes: 4 additions & 4 deletions renderer/next.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const BabiliPlugin = require('babili-webpack-plugin')

module.exports = {
webpack(config, { dev }) {
webpack (config, { dev }) {
config.target = 'electron-renderer'

config.plugins = config.plugins.filter(plugin => {
Expand All @@ -14,10 +14,10 @@ module.exports = {

return config
},
exportPathMap() {
exportPathMap () {
return {
'/': { page: '/' },
'/': { page: '/' }
}
},
assetPrefix: './',
assetPrefix: './'
}
4 changes: 2 additions & 2 deletions renderer/pages/_document.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import Document, { Head, Main, NextScript } from 'next/document'
import flush from 'styled-jsx/server'

export default class extends Document {
static getInitialProps({ renderPage }) {
static getInitialProps ({ renderPage }) {
const { html, head, errorHtml, chunks } = renderPage()
const styles = flush()
return { html, head, errorHtml, chunks, styles }
}

render() {
render () {
return (
<html>
<Head>
Expand Down
Loading

0 comments on commit 44f9fea

Please sign in to comment.