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

Commit 1a3d683

Browse files
committed
♻️ Refactors the src structure
1 parent 692ee7c commit 1a3d683

Some content is hidden

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

88 files changed

+115
-116
lines changed

.storybook/webpack.config.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
const path = require('path')
2-
const genDefaultConfig = require('@storybook/react/dist/server/config/defaults/webpack.config.js')
1+
const path = require("path")
2+
const genDefaultConfig = require("@storybook/react/dist/server/config/defaults/webpack.config.js")
33

44
module.exports = (config, env) => {
55
const myConfig = genDefaultConfig(config, env)
66

77
myConfig.module.rules.push({
88
test: /\.tsx?$/,
9-
loader: 'ts-loader',
9+
loader: "ts-loader",
1010
exclude: /node_modules/,
11-
include: path.resolve(__dirname, '..', 'src'),
11+
include: [path.resolve(__dirname, "..", "src"), path.resolve(__dirname, "views")],
1212
})
13-
14-
myConfig.resolve.extensions.unshift('.tsx')
15-
myConfig.resolve.extensions.unshift('.ts')
13+
14+
myConfig.resolve.extensions.unshift(".tsx")
15+
myConfig.resolve.extensions.unshift(".ts")
1616

1717
return myConfig
1818
}

fuse.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const isProduction = process.env.NODE_ENV === "production"
1010

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

1616
// the default task
@@ -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("> [app/main.ts]")
3636

3737
// and watch unless we're bundling for production
3838
if (!isProduction) {
@@ -42,7 +42,7 @@ Sparky.task("default", ["copy-html"], () => {
4242
// bundle the electron renderer code
4343
const rendererBundle = fuse
4444
.bundle("renderer")
45-
.instructions("> [renderer/index.tsx] +fuse-box-css")
45+
.instructions("> [app/index.tsx] +fuse-box-css")
4646
.plugin(CSSPlugin())
4747
.plugin(CopyPlugin({ useDefault: false, files: ASSETS, dest: "assets", resolve: "assets/" }))
4848

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "typescript-with-electron-react-kit",
33
"productName": "Sweet Sweet App",
44
"main": "out/main.js",
5-
"version": "1.0.0",
5+
"version": "2.0.0",
66
"description": "An electron starter project.",
77
"license": "MIT",
88
"private": true,
File renamed without changes.

src/app/index.tsx

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// This is the entry point for the renderer process.
2+
//
3+
// Here we disable a few electron settings and mount the root component.
4+
import * as React from "react"
5+
import * as ReactDOM from "react-dom"
6+
import { RootComponent } from "./root-component"
7+
import { webFrame } from "electron"
8+
import { css } from "glamor"
9+
10+
/**
11+
* CSS reset
12+
*/
13+
import "glamor/reset"
14+
15+
/**
16+
* Electron-focused CSS resets
17+
*/
18+
css.global("html, body", {
19+
// turn off text highlighting
20+
userSelect: "none",
21+
22+
// reset the cursor pointer
23+
cursor: "default",
24+
25+
// font
26+
font: "caption",
27+
28+
// text rendering
29+
WebkitFontSmoothing: "subpixel-antialiased",
30+
textRendering: "optimizeLegibility",
31+
})
32+
33+
/**
34+
* Zooming resets
35+
*/
36+
webFrame.setVisualZoomLevelLimits(1, 1)
37+
webFrame.setLayoutZoomLevelLimits(0, 0)
38+
39+
/**
40+
* Drag and drop resets
41+
*/
42+
document.addEventListener("dragover", event => event.preventDefault())
43+
document.addEventListener("drop", event => event.preventDefault())
44+
45+
// mount the root component
46+
ReactDOM.render(<RootComponent />, document.getElementById("root"))

src/main/main.ts renamed to src/app/main.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1+
// This is the main process entry point. It is the
2+
// first file that is run on startup.
3+
//
4+
// It is responsible for launching a renderer window.
5+
16
import { app, dialog, ipcMain } from "electron"
2-
import { createMainWindow } from "./main-window/main-window"
3-
import { loadURL } from "./main-window/load-url"
7+
import { createMainWindow, loadURL } from "../views/main-window"
48
import * as log from "electron-log"
59
import * as isDev from "electron-is-dev"
6-
import { createUpdater } from "./updater/updater"
7-
import { createMenu } from "./menu/menu"
10+
import { createUpdater } from "../lib/updater"
11+
import { createMenu } from "../views/menu"
812

913
// set proper logging level
1014
log.transports.file.level = isDev ? false : "info"

src/renderer/features/app/app.tsx renamed to src/app/root-component.tsx

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,17 @@
1+
// This is the top-most component in the app.
12
import * as React from "react"
2-
import { WelcomeScreen } from ".."
3-
import { styles, colors } from "../../platform"
43
import { compose } from "glamor"
4+
import { styles, colors } from "../views/theme"
5+
import { WelcomeScreen } from "../views/example-using-tabs/welcome-screen"
56

67
const ROOT = compose(styles.fullScreen, {
78
background: colors.window.background,
8-
borderRadius: 0,
9-
"& ::-webkit-scrollbar": {
10-
backgroundColor: colors.scrollbar.base,
11-
width: 12,
12-
height: 12,
13-
},
9+
"& ::-webkit-scrollbar": { backgroundColor: colors.scrollbar.base, width: 12, height: 12 },
1410
"& ::-webkit-scrollbar-track": { backgroundColor: colors.scrollbar.track },
1511
"& ::-webkit-scrollbar-thumb": { backgroundColor: colors.scrollbar.thumb, borderRadius: 4 },
1612
})
1713

18-
export class App extends React.Component<{}, {}> {
14+
export class RootComponent extends React.Component<{}, {}> {
1915
render() {
2016
return (
2117
<div {...ROOT}>

src/i18n/index.ts

Whitespace-only changes.

src/renderer/platform/utils/keyboard/keyboard.test.ts renamed to src/lib/keyboard/keyboard.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ jest.mock("mousetrap", () => {
44
unbind: jest.fn(),
55
}
66
})
7-
jest.mock("../../../../shared", () => {
7+
jest.mock("../platform", () => {
88
return {
99
isMac: jest.fn().mockReturnValueOnce(true),
1010
}
@@ -29,7 +29,7 @@ test("mac is command key", () => {
2929

3030
test("non-mac is control", () => {
3131
// jest.resetModules()
32-
const shared = require("../../../../shared")
32+
const shared = require("../platform")
3333
shared.isMac = jest.fn().mockReturnValue(false)
3434
const { commandOrControlKey } = require("./keyboard")
3535
expect(commandOrControlKey()).toBe("ctrl")

src/renderer/platform/utils/keyboard/keyboard.ts renamed to src/lib/keyboard/keyboard.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// A straight thru wrapper with the intention to add contexts
22
// which will swap out groups of keybinds at a time.
33
import * as Mousetrap from "mousetrap"
4-
import { isMac } from "../../../../shared"
4+
import { isMac } from "../platform"
55

66
export type KeyboardCallback = (e: ExtendedKeyboardEvent, combo: string) => any
77
export type KeyboardAction = "keypress" | "keydown" | "keyup"
File renamed without changes.
File renamed without changes.

src/lib/updater/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from "./updater"
File renamed without changes.

src/main/database/database.fixtures.ts renamed to src/models/database/database.fixtures.ts

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

44
/**
55
* Creates a valid repo for use in tests.
66
*/
77
export function createRepo() {
8-
const repo: GithubRepo = {
8+
const repo: Repo = {
99
name: "typescript-with-electron-react-kit",
1010
fullName: "skellock/typescript-with-electron-react-kit",
1111
private: false,

src/main/database/database.ts renamed to src/models/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 { Repo } from "../repo"
33

44
interface DatabaseOptions {
55
readonly directory: string
@@ -18,10 +18,10 @@ export class Database {
1818
/**
1919
* Loads something from the database
2020
*/
21-
load(fullName: string): Promise<GithubRepo> {
21+
load(fullName: string): Promise<Repo> {
2222
return new Promise(resolve =>
2323
setTimeout(() => {
24-
const repo: GithubRepo = {
24+
const repo: Repo = {
2525
name: fullName.split("/")[1],
2626
fullName,
2727
private: false,
@@ -36,7 +36,7 @@ export class Database {
3636
*
3737
* @param repo The thing to save.
3838
*/
39-
save(repo: GithubRepo): Promise<boolean> {
39+
save(repo: Repo): Promise<boolean> {
4040
return new Promise(resolve => setTimeout(() => resolve(repo.fullName !== "crap"), 10))
4141
}
4242
}

src/models/repo/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from "./repo"

src/shared/models/github-repo.ts renamed to src/models/repo/repo.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export interface GithubRepo {
1+
export interface Repo {
22
name: string
33
description?: string
44
fullName: string

src/renderer/features/app/index.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/renderer/features/example-using-tabs/welcome-screen/index.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/renderer/features/index.ts

Lines changed: 0 additions & 2 deletions
This file was deleted.

src/renderer/index.tsx

Lines changed: 0 additions & 15 deletions
This file was deleted.

src/renderer/platform/components/index.ts

Lines changed: 0 additions & 6 deletions
This file was deleted.

src/renderer/platform/index.ts

Lines changed: 0 additions & 3 deletions
This file was deleted.

src/renderer/platform/utils/css-reset/css-reset.ts

Lines changed: 0 additions & 16 deletions
This file was deleted.

src/renderer/platform/utils/css-reset/index.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/renderer/platform/utils/index.ts

Lines changed: 0 additions & 2 deletions
This file was deleted.

src/services/index.ts

Whitespace-only changes.

src/shared/index.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/shared/utils/platform/index.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/renderer/features/example-using-tabs/dog-tab/dog-tab.tsx renamed to src/views/example-using-tabs/dog-tab/dog-tab.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import * as React from "react"
22
import { CSSProperties } from "react"
3-
import { Text, CenteredContent, spacing, cssProps } from "../../../platform"
3+
import { spacing, cssProps } from "../../theme"
4+
import { Text } from "../../shared/text"
5+
import { CenteredContent } from "../../shared/centered-content"
46
import { FunDog } from "../fun-dog"
57
import { Logo } from "../logo"
68

src/renderer/features/example-using-tabs/fun-dog/fun-dog.story.tsx renamed to src/views/example-using-tabs/fun-dog/fun-dog.story.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
import * as React from "react"
22
import { storiesOf } from "@storybook/react"
3-
import {
4-
StorybookStory as Story,
5-
StorybookGroup as Group,
6-
} from "../../../platform/components/storybook"
3+
import { StorybookStory as Story, StorybookGroup as Group } from "../../../../.storybook/views"
74

85
import { FunDog } from "./fun-dog"
96

src/renderer/features/example-using-tabs/fun-dog/fun-dog.tsx renamed to src/views/example-using-tabs/fun-dog/fun-dog.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as React from "react"
22
import { CSSProperties } from "react"
3-
import { colors, SpinAnimation } from "../../../platform"
3+
import { colors } from "../../theme"
4+
import { SpinAnimation } from "../../shared/spin-animation"
45
import { css } from "glamor"
56
const dogImage = require("./fun-dog.jpg")
67

src/renderer/features/example-using-tabs/logo/logo.tsx renamed to src/views/example-using-tabs/logo/logo.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as React from "react"
22
import { CSSProperties } from "react"
3-
import { cssProps, animations } from "../../../platform"
3+
import { cssProps, animations } from "../../theme"
44
const icon = require("./electron-icon.svg")
55
import { css } from "glamor"
66

src/renderer/features/example-using-tabs/long-tab/long-tab.tsx renamed to src/views/example-using-tabs/long-tab/long-tab.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import * as React from "react"
22
import { CSSProperties } from "react"
3-
import { Text, ScrollableContent, spacing, cssProps } from "../../../platform"
3+
import { spacing, cssProps } from "../../theme"
4+
import { Text } from "../../shared/text"
5+
import { ScrollableContent } from "../../shared/scrollable-content"
46
import { css } from "glamor"
57

68
const PADDED = cssProps({

src/renderer/features/example-using-tabs/welcome-screen/sample-tabs.tsx renamed to src/views/example-using-tabs/welcome-screen/sample-tabs.tsx

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,8 @@
11
import * as React from "react"
2-
import {
3-
Tab,
4-
bindKey,
5-
unbindKey,
6-
spacing,
7-
colors,
8-
styles,
9-
cssProps,
10-
commandOrControlKey,
11-
EnterAnimation,
12-
} from "../../../platform"
2+
import { Tab } from "../../shared/tab"
3+
import { bindKey, unbindKey, commandOrControlKey } from "../../../lib/keyboard"
4+
import { spacing, colors, styles, cssProps } from "../../theme"
5+
import { EnterAnimation } from "../../shared/enter-animation"
136
import { css } from "glamor"
147

158
export type SampleTabType = "one" | "two" | "three"

src/renderer/features/example-using-tabs/welcome-screen/welcome-screen.tsx renamed to src/views/example-using-tabs/welcome-screen/welcome-screen.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as React from "react"
22
import { SampleTabs, SampleTabType } from "./sample-tabs"
33
import { LongTab } from "../long-tab"
44
import { DogTab } from "../dog-tab"
5-
import { styles, cssProps } from "../../../platform"
5+
import { styles, cssProps } from "../../theme"
66
import Store = require("electron-store")
77
import { css } from "glamor"
88

src/views/main-window/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from "./main-window"
2+
export * from "./load-url"
File renamed without changes.

src/views/menu/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from "./menu"
File renamed without changes.
File renamed without changes.

src/main/menu/menu.ts renamed to src/views/menu/menu.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Menu } from "electron"
22
import { createMacMenu } from "./macos-menu"
33
import { createLinuxMenu } from "./linux-menu"
44
import { createWindowsMenu } from "./windows-menu"
5-
import { isMac, isLinux, isWindows } from "../../shared"
5+
import { isMac, isLinux, isWindows } from "../../lib/platform"
66

77
/**
88
* Attaches the menu to the appropriate place.
File renamed without changes.
File renamed without changes.

src/renderer/platform/components/centered-content/centered-content.story.tsx renamed to src/views/shared/centered-content/centered-content.story.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as React from "react"
2-
import { StorybookStory as Story, StorybookGroup as Group } from "../storybook"
2+
import { StorybookStory as Story, StorybookGroup as Group } from "../../../../.storybook/views"
33
import { storiesOf } from "@storybook/react"
44
import { CenteredContent } from "./index"
55

0 commit comments

Comments
 (0)