Skip to content
This repository was archived by the owner on Jun 5, 2019. It is now read-only.

Commit 573c269

Browse files
authored
Merge pull request #105 from skellock/double-quotes
🎨 Switches to double-quotes
2 parents de4c83b + 1174f71 commit 573c269

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+460
-473
lines changed

.prettierrc

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
{
2-
"bracketSpacing": true,
3-
"jsxBracketSameLine": false,
42
"printWidth": 100,
53
"semi": false,
6-
"singleQuote": false,
7-
"tabWidth": 2,
8-
"trailingComma": "es5",
9-
"useTabs": false
4+
"trailingComma": "es5"
105
}

fuse.ts

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
1-
import { FuseBox, CSSPlugin, Sparky, CopyPlugin } from 'fuse-box'
2-
import { spawn } from 'child_process'
1+
import { FuseBox, CSSPlugin, Sparky, CopyPlugin } from "fuse-box"
2+
import { spawn } from "child_process"
33

44
const DEV_PORT = 4445
5-
const OUTPUT_DIR = 'out'
6-
const ASSETS = ['*.jpg', '*.png', '*.jpeg', '*.gif', '*.svg']
5+
const OUTPUT_DIR = "out"
6+
const ASSETS = ["*.jpg", "*.png", "*.jpeg", "*.gif", "*.svg"]
77

88
// are we running in production mode?
9-
const isProduction = process.env.NODE_ENV === 'production'
9+
const isProduction = process.env.NODE_ENV === "production"
1010

1111
// copy the renderer's html file into the right place
12-
Sparky.task('copy-html', () => {
13-
return Sparky.src('src/renderer/index.html').dest(`${OUTPUT_DIR}/$name`)
12+
Sparky.task("copy-html", () => {
13+
return Sparky.src("src/renderer/index.html").dest(`${OUTPUT_DIR}/$name`)
1414
})
1515

1616
// the default task
17-
Sparky.task('default', ['copy-html'], () => {
17+
Sparky.task("default", ["copy-html"], () => {
1818
// setup the producer with common settings
1919
const fuse = FuseBox.init({
20-
homeDir: 'src',
20+
homeDir: "src",
2121
output: `${OUTPUT_DIR}/$name.js`,
22-
target: 'electron',
22+
target: "electron",
2323
log: isProduction,
2424
cache: !isProduction,
2525
sourceMaps: true,
26-
tsConfig: 'tsconfig.json',
26+
tsConfig: "tsconfig.json",
2727
})
2828

2929
// start the hot reload server
@@ -32,7 +32,7 @@ Sparky.task('default', ['copy-html'], () => {
3232
}
3333

3434
// bundle the electron main code
35-
const mainBundle = fuse.bundle('main').instructions('> [main/main.ts]')
35+
const mainBundle = fuse.bundle("main").instructions("> [main/main.ts]")
3636

3737
// and watch unless we're bundling for production
3838
if (!isProduction) {
@@ -41,10 +41,10 @@ Sparky.task('default', ['copy-html'], () => {
4141

4242
// bundle the electron renderer code
4343
const rendererBundle = fuse
44-
.bundle('renderer')
45-
.instructions('> [renderer/index.tsx] +fuse-box-css')
44+
.bundle("renderer")
45+
.instructions("> [renderer/index.tsx] +fuse-box-css")
4646
.plugin(CSSPlugin())
47-
.plugin(CopyPlugin({ useDefault: false, files: ASSETS, dest: 'assets', resolve: 'assets/' }))
47+
.plugin(CopyPlugin({ useDefault: false, files: ASSETS, dest: "assets", resolve: "assets/" }))
4848

4949
// and watch & hot reload unless we're bundling for production
5050
if (!isProduction) {
@@ -56,7 +56,7 @@ Sparky.task('default', ['copy-html'], () => {
5656
return fuse.run().then(() => {
5757
if (!isProduction) {
5858
// startup electron
59-
spawn('node', [`${__dirname}/node_modules/electron/cli.js`, __dirname], { stdio: 'inherit' })
59+
spawn("node", [`${__dirname}/node_modules/electron/cli.js`, __dirname], { stdio: "inherit" })
6060
}
6161
})
6262
})

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,13 @@
4545
},
4646
"scripts": {
4747
"build-storybook": "build-storybook",
48-
"typecheck": "tsc -p . --noEmit --pretty",
4948
"clean": "rm -rf .fusebox out dist coverage",
5049
"compile": "NODE_ENV=production ts-node fuse",
5150
"coverage:upload": "cat ./coverage/lcov.info | coveralls",
5251
"coverage": "yarn test --coverage --no-cache",
5352
"dist": "electron-builder --mac --win --linux --ia32 --x64",
5453
"draft": "electron-builder -p always --draft --mac --win --linux --ia32 --x64",
54+
"format": "prettier --write **/*.ts && tslint -p . --fix",
5555
"lint": "tslint --project .",
5656
"pack": "electron-builder --dir",
5757
"postinstall": "electron-builder install-app-deps",
@@ -60,7 +60,8 @@
6060
"sanity": "npm-run-all clean typecheck lint test clean compile clean",
6161
"start": "ts-node fuse",
6262
"storybook": "start-storybook -p 6006",
63-
"test": "jest"
63+
"test": "jest",
64+
"typecheck": "tsc -p . --noEmit --pretty"
6465
},
6566
"dependencies": {
6667
"electron-is-dev": "^0.3.0",

src/main/database/database.fixtures.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
import { GithubRepo } from '../../shared/models/github-repo'
2-
import { Database } from './database'
1+
import { GithubRepo } from "../../shared/models/github-repo"
2+
import { Database } from "./database"
33

44
/**
55
* Creates a valid repo for use in tests.
66
*/
77
export function createRepo() {
88
const repo: GithubRepo = {
9-
name: 'typescript-with-electron-react-kit',
10-
fullName: 'skellock/typescript-with-electron-react-kit',
9+
name: "typescript-with-electron-react-kit",
10+
fullName: "skellock/typescript-with-electron-react-kit",
1111
private: false,
1212
}
1313
return repo
1414
}
1515

16-
const directory = './tmp'
16+
const directory = "./tmp"
1717

1818
/**
1919
* Creates a sample database.

src/main/database/database.test.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
1-
import { createDb, createRepo } from './database.fixtures'
1+
import { createDb, createRepo } from "./database.fixtures"
22

3-
test('can load', async () => {
3+
test("can load", async () => {
44
const db = createDb()
5-
const repo = await db.load('skellock/typescript-with-electron-react-kit')
5+
const repo = await db.load("skellock/typescript-with-electron-react-kit")
66

7-
expect(repo.name).toBe('typescript-with-electron-react-kit')
8-
expect(repo.fullName).toBe('skellock/typescript-with-electron-react-kit')
7+
expect(repo.name).toBe("typescript-with-electron-react-kit")
8+
expect(repo.fullName).toBe("skellock/typescript-with-electron-react-kit")
99
})
1010

11-
test('can save', async () => {
11+
test("can save", async () => {
1212
const db = createDb()
1313
const repo = createRepo()
1414
const result = await db.save(repo)
1515
expect(result).toBe(true)
1616
})
1717

18-
test('fails to save', async () => {
18+
test("fails to save", async () => {
1919
const db = createDb()
2020
const repo = createRepo()
21-
repo.fullName = 'crap'
21+
repo.fullName = "crap"
2222
const result = await db.save(repo)
2323
expect(result).toBe(false)
2424
})

src/main/database/database.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// this example is here only to show how some testing could work.
2-
import { GithubRepo } from '../../shared/models/github-repo'
2+
import { GithubRepo } from "../../shared/models/github-repo"
33

44
interface DatabaseOptions {
55
readonly directory: string
@@ -22,7 +22,7 @@ export class Database {
2222
return new Promise(resolve =>
2323
setTimeout(() => {
2424
const repo: GithubRepo = {
25-
name: fullName.split('/')[1],
25+
name: fullName.split("/")[1],
2626
fullName,
2727
private: false,
2828
}
@@ -33,10 +33,10 @@ export class Database {
3333

3434
/**
3535
* Saves something to the database.
36-
*
36+
*
3737
* @param repo The thing to save.
3838
*/
3939
save(repo: GithubRepo): Promise<boolean> {
40-
return new Promise(resolve => setTimeout(() => resolve(repo.fullName !== 'crap'), 10))
40+
return new Promise(resolve => setTimeout(() => resolve(repo.fullName !== "crap"), 10))
4141
}
4242
}
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
import { loadURL } from './load-url'
1+
import { loadURL } from "./load-url"
22

3-
test('loads from storybook', () => {
3+
test("loads from storybook", () => {
44
const loadStub = jest.fn()
5-
loadURL({ loadURL: loadStub } as any, 'a', true)
6-
expect(loadStub).toBeCalledWith('http://localhost:6006')
5+
loadURL({ loadURL: loadStub } as any, "a", true)
6+
expect(loadStub).toBeCalledWith("http://localhost:6006")
77
})
88

9-
test('loads from electron', () => {
9+
test("loads from electron", () => {
1010
const loadStub = jest.fn()
11-
loadURL({ loadURL: loadStub } as any, 'a', false)
12-
expect(loadStub).toBeCalledWith('file:///a/out/index.html')
11+
loadURL({ loadURL: loadStub } as any, "a", false)
12+
expect(loadStub).toBeCalledWith("file:///a/out/index.html")
1313
})

src/main/main-window/load-url.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
import { join } from 'path'
2-
import { format } from 'url'
1+
import { join } from "path"
2+
import { format } from "url"
33

44
export function loadURL(
55
window: Electron.BrowserWindow,
66
appPath: string,
77
showStorybook: boolean = false,
88
) {
99
if (showStorybook) {
10-
window.loadURL('http://localhost:6006')
10+
window.loadURL("http://localhost:6006")
1111
} else {
1212
window.loadURL(
1313
format({
14-
pathname: join(appPath, 'out/index.html'),
15-
protocol: 'file:',
14+
pathname: join(appPath, "out/index.html"),
15+
protocol: "file:",
1616
slashes: true,
1717
}),
1818
)

src/main/main-window/main-window.test.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,39 @@
1-
import { createMainWindow } from './main-window'
1+
import { createMainWindow } from "./main-window"
22
// @ts-ignore
3-
import * as containDeep from 'jest-expect-contain-deep'
4-
import { BrowserWindow } from 'electron'
5-
const WindowStateManager = require('electron-window-state-manager')
3+
import * as containDeep from "jest-expect-contain-deep"
4+
import { BrowserWindow } from "electron"
5+
const WindowStateManager = require("electron-window-state-manager")
66

7-
it('can read window state', () => {
7+
it("can read window state", () => {
88
WindowStateManager.mockImplementation(() => ({ width: 10, height: 40 }))
99
createMainWindow(__dirname)
1010
expect(BrowserWindow).toBeCalledWith(containDeep({ width: 10, height: 40 }))
1111
})
1212

13-
it('might maximize on startup', () => {
13+
it("might maximize on startup", () => {
1414
WindowStateManager.mockImplementation(() => ({ maximized: true }))
1515
const window = createMainWindow(__dirname)
1616
expect(window.maximize).toBeCalled()
1717
})
1818

19-
it('might not maximize on startup', () => {
19+
it("might not maximize on startup", () => {
2020
WindowStateManager.mockImplementation(() => ({ maximized: false }))
2121
expect(createMainWindow(__dirname).maximize).not.toBeCalled()
2222
})
2323

24-
test('saves window state', () => {
24+
test("saves window state", () => {
2525
let saveState = jest.fn()
2626
WindowStateManager.mockImplementation(() => ({ saveState: saveState }))
2727
const window: BrowserWindow = createMainWindow(__dirname)
28-
window.emit('close')
29-
window.emit('move')
30-
window.emit('resize')
28+
window.emit("close")
29+
window.emit("move")
30+
window.emit("resize")
3131
expect(saveState).toHaveBeenCalledTimes(3)
3232
})
3333

34-
test('show the window after we finish loading + delay', async () => {
34+
test("show the window after we finish loading + delay", async () => {
3535
const window: BrowserWindow = createMainWindow(__dirname, 1)
36-
window.webContents.emit('did-finish-load')
36+
window.webContents.emit("did-finish-load")
3737
const delay = (ms: number) => new Promise(resolve => setTimeout(resolve, ms))
3838
await delay(2)
3939
expect(window.show).toHaveBeenCalled()

src/main/main-window/main-window.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
const { app, BrowserWindow } = require('electron')
2-
const WindowStateManager = require('electron-window-state-manager')
3-
import { loadURL } from './load-url'
1+
const { app, BrowserWindow } = require("electron")
2+
const WindowStateManager = require("electron-window-state-manager")
3+
import { loadURL } from "./load-url"
44

55
// default dimensions
66
export const DIMENSIONS = { width: 600, height: 500, minWidth: 450, minHeight: 450 }
@@ -14,7 +14,7 @@ export const DIMENSIONS = { width: 600, height: 500, minWidth: 450, minHeight: 4
1414
*/
1515
export function createMainWindow(appPath: string, showDelay: number = 100) {
1616
// persistent window state manager
17-
const windowState = new WindowStateManager('main', {
17+
const windowState = new WindowStateManager("main", {
1818
defaultWidth: DIMENSIONS.width,
1919
defaultHeight: DIMENSIONS.height,
2020
})
@@ -29,10 +29,10 @@ export function createMainWindow(appPath: string, showDelay: number = 100) {
2929
y: windowState.y,
3030
show: false,
3131
useContentSize: true,
32-
titleBarStyle: 'hidden-inset',
32+
titleBarStyle: "hidden-inset",
3333
autoHideMenuBar: true,
3434
// backgroundColor: '#fff',
35-
vibrancy: 'light',
35+
vibrancy: "light",
3636
transparent: true,
3737
title: app.getName(),
3838
webPreferences: {
@@ -47,15 +47,15 @@ export function createMainWindow(appPath: string, showDelay: number = 100) {
4747
}
4848

4949
// trap movement events
50-
window.on('close', () => windowState.saveState(window))
51-
window.on('move', () => windowState.saveState(window))
52-
window.on('resize', () => windowState.saveState(window))
50+
window.on("close", () => windowState.saveState(window))
51+
window.on("move", () => windowState.saveState(window))
52+
window.on("resize", () => windowState.saveState(window))
5353

5454
// load entry html page in the renderer.
5555
loadURL(window, appPath)
5656

5757
// only appear once we've loaded
58-
window.webContents.on('did-finish-load', () => {
58+
window.webContents.on("did-finish-load", () => {
5959
setTimeout(() => {
6060
window.show()
6161
window.focus()

0 commit comments

Comments
 (0)