Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
WizardOfCodez committed Jul 4, 2020
0 parents commit 07cf903
Show file tree
Hide file tree
Showing 140 changed files with 27,116 additions and 0 deletions.
28 changes: 28 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Editor config helps developers define and maintain consistent
# coding styles between different editors and IDEs
# EditorConfig is awesome: http://editorconfig.org

# top-most EditorConfig file
root = true

# Unix-style newlines with a newline ending every file
[*]
end_of_line = lf
insert_final_newline = true
charset = utf-8
indent_style = space
indent_size = 2

# 2 space indentation
# Matches multiple files with brace expansion notation
[*.{yaml,yml}]
indent_style = space
indent_size = 2

# https://google.github.io/styleguide/shell.xml#Indentation
[*.{sh}]
indent_style = space
indent_size = 2

[*.md]
trim_trailing_whitespace = false
21 changes: 21 additions & 0 deletions .electron-nuxt/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const path = require('path')

const PROJECT_ROOT = path.join(__dirname, '..')
const SRC_DIR = path.join(PROJECT_ROOT, 'src')

const config = {
ELECTRON_RELAUNCH_CODE: 250, // valid range in unix system: <1,255>
ELECTRON_INSPECTION_PORT: 5858,
SERVER_PORT: 9080,
SERVER_HOST: 'http://localhost',

PROJECT_ROOT,
SRC_DIR,
MAIN_PROCESS_DIR: path.join(SRC_DIR, 'main'),
RENDERER_PROCESS_DIR: path.join(SRC_DIR, 'renderer'),
RESOURCES_DIR: path.join(SRC_DIR, 'resources'),
DIST_DIR: path.join(PROJECT_ROOT, 'dist'),
BUILD_DIR: path.join(PROJECT_ROOT, 'build')
}

module.exports = Object.freeze(config)
59 changes: 59 additions & 0 deletions .electron-nuxt/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@

const path = require('path')
const webpack = require('webpack')
const electron = require('electron')

const { Pipeline, Logger } = require('@xpda-dev/core')
const { ElectronLauncher } = require('@xpda-dev/electron-launcher')
const { ElectronBuilder } = require('@xpda-dev/electron-builder')
const { Webpack } = require('@xpda-dev/webpack-step')
const resourcesPath = require('./resources-path-provider')
const { DIST_DIR, MAIN_PROCESS_DIR, SERVER_HOST, SERVER_PORT } = require('./config')
const NuxtApp = require('./renderer/NuxtApp')

const isDev = process.env.NODE_ENV === 'development'

const launcher = new ElectronLauncher({
electronPath: electron,
entryFile: path.join(DIST_DIR, 'main/index.js')
})

const builder = new ElectronBuilder({
cliOptions: {
config: path.join(__dirname, '../builder.config.js')
}
})

const webpackConfig = Webpack.getBaseConfig({
entry: isDev
? path.join(MAIN_PROCESS_DIR, 'index.dev.js')
: path.join(MAIN_PROCESS_DIR, 'index.js'),
output: {
filename: 'index.js',
path: path.join(DIST_DIR, 'main')
},
plugins: [
new webpack.DefinePlugin({
INCLUDE_RESOURCES_PATH: resourcesPath.mainProcess(),
'process.env.DEV_SERVER_URL': `'${SERVER_HOST}:${SERVER_PORT}'`
})
]
})

const webpackMain = new Webpack({
logger: new Logger('Main', 'olive'),
webpackConfig,
launcher // need to restart launcher after compilation
})

const nuxt = new NuxtApp(new Logger('Nuxt', 'green'))

const pipe = new Pipeline({
title: 'Electron-nuxt',
isDevelopment: isDev,
steps: [webpackMain, nuxt],
launcher,
builder
})

pipe.run()
40 changes: 40 additions & 0 deletions .electron-nuxt/renderer/NuxtApp.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
const path = require('path')
const { fork } = require('child_process')
const { utils } = require('@xpda-dev/core')
const { killWithAllSubProcess } = utils

const NUXT_PROCESS_PATH = path.join(__dirname, 'nuxt-process.js')

/**
* @implements {IStep}
*/
class NuxtApp {
constructor (logger) {
this.logger = logger
}

async build (isDev) {
this.nuxtProcess = fork(NUXT_PROCESS_PATH, { silent: true })
this.redirectStdout()
return new Promise((resolve, reject) => {
this.nuxtProcess.send({ action: 'build', target: isDev ? 'development' : 'production' })
this.nuxtProcess.once('message', ({ status, err }) => {
if (status === 'ok') resolve()
else reject(err)
})
})
}

redirectStdout () {
this.nuxtProcess.stdout.pipe(this.logger.stdout)
this.nuxtProcess.stderr.pipe(this.logger.stderr)
}

async terminate () {
this.nuxtProcess.kill()
if (this.nuxtProcess && !this.nuxtProcess.killed) killWithAllSubProcess(this.nuxtProcess.pid)
this.nuxtProcess = null
}
}

module.exports = NuxtApp
39 changes: 39 additions & 0 deletions .electron-nuxt/renderer/nuxt-process.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
const { Nuxt, Builder, Generator } = require('nuxt')
const { SERVER_PORT } = require('../config')
const nuxtConfig = require('./nuxt.config.js')

const nuxt = new Nuxt(nuxtConfig)

process.on('message', async ({ action, target }) => {
if (action !== 'build') {
console.warn('Unknown action')
process.send({ status: 'error', err: `Nuxt process: unknown action ('${action}')` })
return
}

await nuxt.ready()

// https://github.com/nuxt/nuxt.js/blob/dev/packages/builder/src/builder.js
const builder = new Builder(nuxt)

// https://github.com/nuxt/nuxt.js/blob/dev/packages/generator/src/generator.js
const generator = new Generator(nuxt, builder)

if (target === 'development') {
builder.build().then(() => {
nuxt.listen(SERVER_PORT)
process.send({ status: 'ok' })
}).catch(err => {
console.error(err)
process.send({ status: 'error', err: err.message })
})
} else {
generator.generate({ build: true, init: true }).then(({ errors }) => {
if (errors.length === 0) process.send({ status: 'ok' })
else process.send({ status: 'error', err: 'Error occurred while generating pages' })
}).catch(err => {
console.error(err)
process.send({ status: 'error', err: err.message })
})
}
})
59 changes: 59 additions & 0 deletions .electron-nuxt/renderer/nuxt.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/* eslint no-param-reassign: 0 */
process.env.BABEL_ENV = 'renderer'
const isProduction = process.env.NODE_ENV === 'production'
const isDev = process.env.NODE_ENV === 'development'
const path = require('path')
const webpack = require('webpack')
const nodeExternals = require('webpack-node-externals')
const resourcesPath = require('../resources-path-provider')
const { RENDERER_PROCESS_DIR, DIST_DIR } = require('../config')

const userNuxtConfig = require('../../src/renderer/nuxt.config')

module.exports = {
...userNuxtConfig,
srcDir: RENDERER_PROCESS_DIR,
rootDir: RENDERER_PROCESS_DIR,
router: {
mode: 'hash'
},
dev: isDev,
generate: {
dir: path.join(DIST_DIR, 'renderer')
},
plugins: [
{ ssr: true, src: path.join(__dirname, 'resources-plugin.js') },
...(userNuxtConfig.plugins || [])
],
build: {
extend (config, { isClient }) {
if (userNuxtConfig.build !== undefined && userNuxtConfig.build.extend !== undefined) {
userNuxtConfig.build.extend(...arguments) // eslint-disable-line prefer-rest-params
}

config.externals = [nodeExternals({
modulesFromFile: {
include: ['dependencies']
}
})]

config.target = 'electron-renderer'

config.node = {
__dirname: !isProduction,
__filename: !isProduction
}

if (!isDev) {
// absolute path to files on production (default value: '/_nuxt/')
config.output.publicPath = '_nuxt/'
}

config.plugins.push(
new webpack.DefinePlugin({
INCLUDE_RESOURCES_PATH: isClient ? resourcesPath.nuxtClient() : resourcesPath.nuxtServer()
})
)
}
}
}
12 changes: 12 additions & 0 deletions .electron-nuxt/renderer/resources-plugin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/* globals INCLUDE_RESOURCES_PATH */
import Vue from 'vue'

/**
* Set `__resources` path to resources files in renderer process
*/
global.__resources = undefined // eslint-disable-line no-underscore-dangle
// noinspection BadExpressionStatementJS
INCLUDE_RESOURCES_PATH // eslint-disable-line no-unused-expressions
if (__resources === undefined) console.error('[Renderer-process]: Resources path is undefined')

Vue.prototype.__resources = __resources
47 changes: 47 additions & 0 deletions .electron-nuxt/resources-path-provider.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
const { RESOURCES_DIR } = require('./config')

const RESOURCES_DIR_PATH = RESOURCES_DIR.replace(/\\/g, '/')

const isProduction = process.env.NODE_ENV === 'production'

function staticPath () {
// resolve during compilation
return `
global.__resources = \`${RESOURCES_DIR_PATH}\`;
`
}

function pathFromRendererOnRuntime () {
// resolve on runtime
// path depends on production directory structure

// renderer entry: ./dist/renderer/index.html
// resources: ./dist/resources/
return `
global.__resources = require('path').join(__dirname, '..', 'resources');
`
}

function pathFromMainOnRuntime () {
// resolve on runtime
// path depends on production directory structure

// main entry: ./dist/main/index.js
// resources: ./dist/resources/
return `
global.__resources = require('path').join(__dirname, '..', 'resources');
`
}

module.exports = {

mainProcess () {
return isProduction ? pathFromMainOnRuntime() : staticPath()
},

nuxtClient () {
return isProduction ? pathFromRendererOnRuntime() : staticPath()
},

nuxtServer: staticPath
}
38 changes: 38 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
module.exports = {
root: true,
env: {
browser: true,
node: true
},
globals: {
__resources: true
},
parserOptions: {
sourceType: 'module',
parser: 'babel-eslint'
},
extends: [
'@nuxtjs'

],
// add your custom rules here
rules: {
// StandardJS — The Rules
"indent": ["error", 2], // 2 spaces – for indentation
"no-console": "off",
"arrow-parens": ["error", "as-needed"],
"curly": ["error", "multi-line"],
"import/no-extraneous-dependencies": "off",
"require-await": 0,

"global-require": 0,
'import/no-unresolved': 0,
'import/newline-after-import': 0,
'no-underscore-dangle': 0,

'no-debugger': process.env.NODE_ENV === 'production' ? 2 : 0,

"vue/max-attributes-per-line": "off",
"vue/singleline-html-element-content-newline": 0
}
}
27 changes: 27 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# https://git-scm.com/docs/gitattributes
#
# A gitattributes file is a simple text file that gives attributes to path names.
# Each line in gitattributes file is of form: pattern attr1 attr2 ...
# That is, a pattern followed by an attributes list, separated by white spaces.
# When the pattern matches the path in question, the attributes listed on the line are given to the path.
# Each attribute can be in one of these states for a given path:
# FIX CRLF always when developer has not set
# Linux/Mac: git config --global core.autocrlf input
# Windows: git config --global core.autocrlf true
# Auto detect text files and perform LF normalization
* text=auto
* text eol=lf

# git objects as binary
*.png binary
*.ico binary
*.icns binary
*.vue text

# git objects as text for diff
*.md text
*.js text
*.yml text
.editorconfig text
.gitattributes text
.gitignore text
Loading

0 comments on commit 07cf903

Please sign in to comment.