Skip to content

Commit

Permalink
refactor: extract libs and electron code to project root (LN-Zap#1895)
Browse files Browse the repository at this point in the history
* refactor: extract libs and electron code to project root

* refactor: rename app to renderer
  • Loading branch information
mrfelton authored Mar 27, 2019
1 parent 027223d commit ad08942
Show file tree
Hide file tree
Showing 469 changed files with 364 additions and 330 deletions.
13 changes: 13 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"plugins": [
[
"module-resolver",
{
"root": ["./renderer"],
"alias": {
"^@zap/(.+)": "./\\1"
}
}
]
]
}
1 change: 0 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ build/Release
# Dependency directory
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
node_modules
app/node_modules

# OSX
.DS_Store
Expand Down
13 changes: 7 additions & 6 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,13 @@ module.exports = {
],
settings: {
'import/resolver': {
node: {
moduleDirectory: ['app', 'node_modules', 'app/node_modules'],
},
webpack: {
config: path.resolve(__dirname, 'webpack', 'webpack.config.eslint.js'),
},
'babel-module': {},
},
node: {
moduleDirectory: ['renderer', 'node_modules'],
},
webpack: {
config: path.resolve(__dirname, 'webpack', 'webpack.config.eslint.js'),
},
},
}
26 changes: 12 additions & 14 deletions .flowconfig
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
[ignore]
<PROJECT_ROOT>/app/dist/.*
<PROJECT_ROOT>/resources/.*
<PROJECT_ROOT>/release/.*
<PROJECT_ROOT>/icons/.*
<PROJECT_ROOT>/dist/.*
<PROJECT_ROOT>/dll/.*
<PROJECT_ROOT>/release/.*
<PROJECT_ROOT>/icons/.*
<PROJECT_ROOT>/storybook-static/.*
<PROJECT_ROOT>/.git/.*
.*/node_modules/config-chain/test/broken.json
Expand All @@ -20,21 +19,20 @@ esproposal.class_instance_fields=enable
esproposal.export_star_as=enable

module.system.node.resolve_dirname=node_modules
module.system.node.resolve_dirname=app/node_modules

# Map images to WebpackAsset tyoe def
module.name_mapper.extension='png' -> '<PROJECT_ROOT>/flow/WebpackAsset.js.flow'
module.name_mapper.extension='jpg' -> '<PROJECT_ROOT>/flow/WebpackAsset.js.flow'
module.name_mapper.extension='svg' -> '<PROJECT_ROOT>/flow/WebpackAsset.js.flow'

# Map webpack resolved module imports to the app directory
# Example: components/Foo -> `<project_root>/app/components/Foo`
module.name_mapper='^components/\(.*\)$' -> '<PROJECT_ROOT>/app/components/\1'
module.name_mapper='^containers/\(.*\)$' -> '<PROJECT_ROOT>/app/containers/\1'
module.name_mapper='^icons/\(.*\)$' -> '<PROJECT_ROOT>/app/icons/\1'
module.name_mapper='^lib/\(.*\)$' -> '<PROJECT_ROOT>/app/lib/\1'
module.name_mapper='^reducers/\(.*\)$' -> '<PROJECT_ROOT>/app/reducers/\1'
module.name_mapper='^store/\(.*\)$' -> '<PROJECT_ROOT>/app/store/\1'
module.name_mapper='^themes/\(.*\)$' -> '<PROJECT_ROOT>/app/themes/\1'
module.name_mapper='^hocs/\(.*\)$' -> '<PROJECT_ROOT>/app/hocs/\1'
module.name_mapper='^hooks/\(.*\)$' -> '<PROJECT_ROOT>/app/hooks/\1'
# Example: components/Foo -> `<project_root>/src/components/Foo`
module.name_mapper='^components/\(.*\)$' -> '<PROJECT_ROOT>/renderer/components/\1'
module.name_mapper='^containers/\(.*\)$' -> '<PROJECT_ROOT>/renderer/containers/\1'
module.name_mapper='^reducers/\(.*\)$' -> '<PROJECT_ROOT>/renderer/reducers/\1'
module.name_mapper='^store/\(.*\)$' -> '<PROJECT_ROOT>/renderer/store/\1'
module.name_mapper='^themes/\(.*\)$' -> '<PROJECT_ROOT>/renderer/themes/\1'
module.name_mapper='^hocs/\(.*\)$' -> '<PROJECT_ROOT>/renderer/hocs/\1'
module.name_mapper='^hooks/\(.*\)$' -> '<PROJECT_ROOT>/renderer/hooks/\1'

module.name_mapper='^@zap/\(.*\)$' -> '<PROJECT_ROOT>/\1'
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ build/Release
# Dependency directory
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
node_modules
app/node_modules

# OSX
.DS_Store
Expand Down
24 changes: 12 additions & 12 deletions .storybook/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { linkTo } from '@storybook/addon-links'
import { setIntlConfig, withIntl } from 'storybook-addon-intl'
import StoryRouter from 'storybook-react-router'
import { dark, light } from 'themes'
import { getDefaultLocale, locales } from 'lib/i18n'
import { getDefaultLocale, locales } from '@zap/i18n'
import { BackgroundPrimary, GlobalStyle } from 'components/UI'

const BackgroundPrimaryWithTheme = withTheme(({ theme, ...rest }) => (
Expand All @@ -24,16 +24,16 @@ const BackgroundPrimaryWithTheme = withTheme(({ theme, ...rest }) => (
))

// Register supported locales.
import '../app/lib/i18n/locale'
import '@zap/i18n/locale'

// Get translations.
import translations from '../app/lib/i18n/translation'
import translations from '@zap/i18n/translation'

// Set intl configuration
setIntlConfig({
locales: locales,
defaultLocale: getDefaultLocale(),
getMessages: locale => translations[locale]
getMessages: locale => translations[locale],
})

// Info
Expand All @@ -42,10 +42,10 @@ addDecorator(
styles: {
button: {
base: {
background: dark.colors.lightningOrange
}
}
}
background: dark.colors.lightningOrange,
},
},
},
})
)

Expand All @@ -67,8 +67,8 @@ addParameters({
name: 'Zap',
url: 'https://ln-zap.github.io/zap-desktop',
theme: themes.dark,
hierarchySeparator: /\./
}
hierarchySeparator: /\./,
},
})

// Zap Global style.
Expand All @@ -90,8 +90,8 @@ setDefaults({
showSource: false,
allowSourceToggling: false,
showPropTables: false,
allowPropTablesToggling: true
}
allowPropTablesToggling: true,
},
})

// automatically import all files ending in *.stories.js
Expand Down
4 changes: 2 additions & 2 deletions .testcafe-electron-rc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"mainWindowUrl": "./app/dist/index.html",
"appPath": "./app"
"mainWindowUrl": "./dist/index.html",
"appPath": "."
}
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ cache:
directories:
- node_modules
- flow-typed
- app/node_modules

addons:
apt:
Expand Down
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"search.exclude": {
".git": true,
".eslintcache": true,
"app/dist": true,
"bower_components": true,
"dist": true,
"dll": true,
"flow-typed": true,
"release": true,
Expand Down
3 changes: 0 additions & 3 deletions app/.eslintrc

This file was deleted.

45 changes: 0 additions & 45 deletions app/lib/i18n/translation.js

This file was deleted.

17 changes: 0 additions & 17 deletions app/package.json

This file was deleted.

4 changes: 0 additions & 4 deletions app/yarn.lock

This file was deleted.

1 change: 0 additions & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ environment:

cache:
- node_modules -> package.json
- app/node_modules -> app/package.json
- flow-typed

matrix:
Expand Down
9 changes: 8 additions & 1 deletion babel.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
module.exports = {
babelrcRoots: [
// Keep the root as a root
'.',

// Also consider renderer as "root" and load it's .babelrc files.
'./renderer/*',
],
presets: [
[
'@babel/preset-env',
Expand All @@ -17,7 +24,7 @@ module.exports = {
[
'react-intl-auto',
{
removePrefix: 'app/',
removePrefix: 'renderer/',
filebase: false,
},
],
Expand Down
2 changes: 1 addition & 1 deletion config/default.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { getPackageDetails, isStableVersion } = require('../app/lib/utils')
const { getPackageDetails, isStableVersion } = require('@zap/utils')

// The current stable base version.
// If the current version is in the same range asd this, the default database domain will be used.
Expand Down
1 change: 0 additions & 1 deletion docs/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ Tests should try to be written for every feature/fix and pass `npm run test` bef
Before making a new release, the version number should be incremented in the following files:

- `package.json`: The main repo package file.
- `app/package.json`: The electron app package file.

If the release is a major or minor number increment (eg, `0.3.x` -> `0.4.x`), you should also update `STABLE_VERSION` in the main app config file to reference the correct new stable version (this is used to determine the app's database namespace):

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
16 changes: 8 additions & 8 deletions app/lib/zap/controller.js → electron/controller.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// @flow
import { app, ipcMain, dialog, BrowserWindow } from 'electron'
import StateMachine from 'javascript-state-machine'
import { mainLog } from '../utils/log'
import delay from '../utils/delay'
import truncate from '../utils/truncate'
import sanitize from '../utils/sanitize'
import LndConfig, { type LndConfigOptions } from '../lnd/config'
import Lightning from '../lnd/lightning'
import Neutrino from '../lnd/neutrino'
import WalletUnlocker from '../lnd/walletUnlocker'
import { mainLog } from '@zap/utils/log'
import delay from '@zap/utils/delay'
import truncate from '@zap/utils/truncate'
import sanitize from '@zap/utils/sanitize'
import LndConfig, { type LndConfigOptions } from '@zap/lnd/config'
import Lightning from '@zap/lnd/lightning'
import Neutrino from '@zap/lnd/neutrino'
import WalletUnlocker from '@zap/lnd/walletUnlocker'

const LND_GRPC_HOST_ERROR = 'LND_GRPC_HOST_ERROR'
const LND_GRPC_CERT_ERROR = 'LND_GRPC_CERT_ERROR'
Expand Down
18 changes: 9 additions & 9 deletions app/main.js → electron/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* through IPC.
*
* When running `npm run build` or `npm run build-main`, this file is compiled to
* `./app/dist/main.prod.js` using webpack. This gives us some performance wins.
* `/dist/main.prod.js` using webpack. This gives us some performance wins.
*/
import { app, BrowserWindow, session } from 'electron'
import installExtension, {
Expand All @@ -16,13 +16,13 @@ import path from 'path'
import os from 'os'
import fs from 'fs'
import bip21 from 'bip21'
import { mainLog } from './lib/utils/log'
import ZapMenuBuilder from './lib/zap/menuBuilder'
import ZapController from './lib/zap/controller'
import ZapUpdater from './lib/zap/updater'
import ZapMigrator from './lib/zap/migrator'
import themes from './themes'
import { getDbName } from './lib/utils/db'
import { mainLog } from '@zap/utils/log'
import themes from '@zap/renderer/themes'
import { getDbName } from '@zap/utils/db'
import ZapMenuBuilder from './menuBuilder'
import ZapController from './controller'
import ZapUpdater from './updater'
import ZapMigrator from './migrator'

// When we run in production mode, this file is processd with webpack and our config is made available in the
// global CONFIG object. If this is not set then we must be running in development mode (where this file is loaded
Expand Down Expand Up @@ -252,7 +252,7 @@ app.on('ready', async () => {
webPreferences: {
nodeIntegration: false,
preload: process.env.HOT
? path.resolve(__dirname, 'dist', 'preload.dev.js')
? path.resolve(__dirname, '..', 'dist', 'preload.dev.js')
: path.resolve(__dirname, 'preload.prod.js'),
},
})
Expand Down
13 changes: 6 additions & 7 deletions app/lib/zap/menuBuilder.js → electron/menuBuilder.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
// @flow
import os from 'os'
import { app, Menu, shell, BrowserWindow, ipcMain } from 'electron'
import { appRootPath } from '@zap/lnd/util'
import { getLanguageName, locales } from '@zap/i18n'
import { getPackageDetails } from '@zap/utils'
import openAboutWindow from './about'
import { getLanguageName, locales } from '../i18n'
import { getPackageDetails } from '../utils'

import { appRootPath } from '../lnd/util'

const path = require('path')

Expand All @@ -17,12 +16,12 @@ const buildAboutMenu = () => {
openAboutWindow(
{
icon_path: path.resolve(appRootPath(), 'resources', 'icon.png'),
open_devtools: process.env.NODE_ENV !== 'production',
open_devtools: process.env.NODE_ENV === 'development' || process.env.DEBUG_PROD,
product_name: `${productName} ${version}`,
},
`file://${path.resolve(
process.env.HOT ? 'app' : app.getAppPath(),
'lib/zap/about/public/',
process.env.HOT ? '' : app.getAppPath(),
'electron/about/public/',
'about.html'
)}`
)
Expand Down
Loading

0 comments on commit ad08942

Please sign in to comment.