Fixed a bug where KawAnime dist could not be started from another path

Wip on nightwatch
paths now use __dirname
This commit is contained in:
Kylart 2017-07-25 16:53:26 +02:00
parent 5492fd4c93
commit f1b697ca09
13 changed files with 86 additions and 57 deletions

View File

@ -3,7 +3,6 @@
<v-navigation-drawer class="pb-0"
style="width: 280px"
temporary
overflow
v-model="$store.state.drawer"
>
<v-list>
@ -35,7 +34,7 @@
class="ripple"
ripple
:to="subItem.href"
key="subItem.title">
:key="subItem.title">
<v-list-tile-action>
<v-icon>{{ subItem.action }}</v-icon>
</v-list-tile-action>
@ -45,7 +44,7 @@
</v-list-tile>
<v-divider></v-divider>
</v-list-group>
<v-subheader v-else-if="item.header">{{ item.header }}</v-subheader>
<v-subheader v-else-if="item.header" class="white--text">{{ item.header }}</v-subheader>
<v-divider v-else-if="item.divider"></v-divider>
</template>
</v-list>

0
dist/.gitkeep vendored Normal file
View File

37
main.js
View File

@ -7,7 +7,7 @@ const express = require('express')
const compression = require('compression')
const resolve = file => path.resolve(__dirname, file)
const { createBundleRenderer } = require('vue-server-renderer')
const redirects = require('./router/301.json')
const redirects = require(path.join(__dirname, '/router/301.json'))
const isDev = process.env.NODE_ENV === 'development'
const useMicroCache = process.env.MICRO_CACHE !== 'false'
@ -17,7 +17,7 @@ const serverInfo =
const app = express()
const template = fs.readFileSync(resolve('./assets/index.template.html'), 'utf-8')
const template = fs.readFileSync(path.join(__dirname, 'assets/index.template.html'), 'utf-8')
function createRenderer (bundle, options) {
// https://github.com/vuejs/vue/blob/dev/packages/vue-server-renderer/README.md#why-use-bundlerenderer
@ -29,7 +29,7 @@ function createRenderer (bundle, options) {
maxAge: 1000 * 60 * 15
}),
// this is only needed when vue-server-renderer is npm-linked
basedir: resolve('./public'),
basedir: resolve(__dirname, 'public'),
// performance
runInNewContext: false
}))
@ -38,14 +38,14 @@ function createRenderer (bundle, options) {
let renderer
let readyPromise
if (!isDev) {
const bundle = require('./public/vue-ssr-server-bundle.json')
const clientManifest = require('./public/vue-ssr-client-manifest.json')
const bundle = require(path.join(__dirname, 'public', 'vue-ssr-server-bundle.json'))
const clientManifest = require(path.join(__dirname, 'public', 'vue-ssr-client-manifest.json'))
renderer = createRenderer(bundle, {
clientManifest
})
} else {
// hot reload
readyPromise = require('./webpack/setup-dev-server')(app, (bundle, options) => {
readyPromise = require(path.join(__dirname, 'webpack', 'setup-dev-server.js'))(app, (bundle, options) => {
renderer = createRenderer(bundle, options)
})
}
@ -55,17 +55,11 @@ const serve = (path, cache) => express.static(resolve(path), {
})
app.use(compression({ threshold: 0 }))
app.use('/static', serve('./static', true))
app.use('/public', serve('./public', true))
app.use('/static/robots.txt', serve('./robots.txt'))
app.get('/sitemap.xml', (req, res) => {
res.setHeader('Content-Type', 'text/xml')
res.sendFile(resolve('./static/sitemap.xml'))
})
app.use('/static', serve(path.join(__dirname, 'static'), true))
app.use('/public', serve(path.join(__dirname, 'public'), true))
// Setup the api
require('./server')(app)
require(path.join(__dirname, 'server'))(app)
// 301 redirect for changed routes
Object.keys(redirects).forEach((k) => {
@ -92,7 +86,7 @@ function render ({url}, res) {
res.status(404).end('404 | Page Not Found')
} else {
// Render Error Page or Redirect
res.status(500).end('500 | Internal Server Error')
res.status(500).end('500 | Internal Server Error\n' + err.stack)
console.error(`error during render : ${url}`)
console.error(err.stack)
}
@ -129,11 +123,9 @@ app.get('*', !isDev ? render : (req, res) => {
})
})
const port = process.env.PORT || 9200
const _APP_URL_ = `http://localhost:${port}`
app.listen(port, '0.0.0.0', () => {
console.log(`> server started at localhost:${port}`.green)
})
const server = http.createServer(app).listen()
const _APP_URL_ = 'http://localhost:' + server.address().port
console.log(`> server started at ${_APP_URL_}`.green)
/*
** Electron app
@ -162,7 +154,7 @@ dialog.showErrorBox = (title, content) => {
}
process.on('uncaughtException', (err) => {
console.error('Uncaught exception occurred in main process.\n' + err.message)
console.error('Uncaught exception occurred in main process.\n', err)
})
const newWin = () => {
@ -223,6 +215,7 @@ Electron.on('window-all-closed', function () {
// to stay active until the user quits explicitly with Cmd + Q
if (process.platform !== 'darwin') {
app.quit()
Electron.quit()
}
})

View File

@ -2,7 +2,6 @@
* Taken and modified from https://github.com/dwyl/learn-nightwatch
*/
// require('env2')('.env') // optionally store your Evironment Variables in .env
process.NODE_ENV = 'KawAnime-test'
const SCREENSHOT_PATH = './screenshots/'
const BINPATH = './node_modules/nightwatch/bin/'

View File

@ -10,11 +10,11 @@
},
"license": "MIT",
"scripts": {
"dev": "cross-env NODE_ENV=development electron main.js",
"dev": "NODE_ENV=development electron main.js",
"dev:server": "node assets/serverStart.js",
"start": "NODE_ENV=production electron main.js",
"bstart": "npm run build && npm start",
"build": "rimraf dist && npm run build:client && npm run build:server",
"build": "rimraf public && npm run build:client && npm run build:server",
"build:client": "NODE_ENV=production webpack --config webpack/webpack.client.config.js --progress --hide-modules",
"build:server": "NODE_ENV=production webpack --config webpack/webpack.server.config.js --progress --hide-modules",
"cloc": "cloc $(git ls-files | grep -vE \".mkv|mp4|lock\")",
@ -35,8 +35,10 @@
},
"dependencies": {
"axios": "^0.16.2",
"compression": "^1.6.2",
"babel-core": "^6.25.0",
"babel-runtime": "^6.23.0",
"colors": "^1.1.2",
"compression": "^1.6.2",
"express": "^4.15.3",
"horrible-api": "^1.0.5",
"lodash": "^4.17.4",
@ -48,14 +50,13 @@
"vue": "^2.4.2",
"vue-router": "^2.7.0",
"vue-server-renderer": "^2.4.2",
"vuetify": "^0.14.5",
"vuetify": "^0.14.6",
"vuex": "^2.3.1",
"vuex-router-sync": "^4.1.2"
},
"devDependencies": {
"autoprefixer": "^7.1.1",
"ava": "^0.19.1",
"babel-core": "^6.22.1",
"babel-loader": "^7.0.0",
"babel-plugin-add-module-exports": "^0.2.1",
"babel-plugin-transform-runtime": "^6.22.0",

View File

@ -191,7 +191,7 @@
console.log(`[${(new Date()).toLocaleTimeString()}]: Opening modal`)
this.modalTitle = title
this.modalText = text
this.modalText = text + 'Blabla'
this.modal = true
},
@ -204,8 +204,8 @@
axios.post('download', {
name: name,
quality: quality,
fromEp: -Infinity,
untilEp: Infinity,
fromEp: 0,
untilEp: 20000,
fansub: fansub,
choice: 'si'
}).then(({data}) => {

Binary file not shown.

Before

Width:  |  Height:  |  Size: 104 KiB

View File

@ -1,2 +0,0 @@
User-agent: *
Disallow:

View File

@ -1,9 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">
<url>
<loc>/</loc>
<lastmod>2017-07-23</lastmod>
<changefreq>daily</changefreq>
<priority>1.0</priority>
</url>
</urlset>

View File

@ -3,25 +3,74 @@
*/
require('colors')
const {readdirSync, unlinkSync, rmdirSync} = require('fs')
const {readdirSync, unlinkSync, rmdirSync, readFileSync} = require('fs')
const {join} = require('path')
const path = require('path')
const {userInfo} = require('os')
const LRU = require('lru-cache')
const express = require('express')
const compression = require('compression')
const resolve = file => path.resolve(__dirname, file)
const { createBundleRenderer } = require('vue-server-renderer')
const redirects = require('../../router/301.json')
// We keep the nuxt and server instance
// So we can close them at the end of the test
let server = null
const uri = 'http://localhost:4000'
let renderer = null
const template = readFileSync(resolve('../../assets/index.template.html'), 'utf-8')
const uri = 'http://localhost:9200'
const DIR = join(userInfo().homedir, '.KawAnime-test')
const serve = (path, cache) => express.static(resolve(path), {
maxAge: cache && 60 * 60 * 24 * 30
})
const createRenderer = (bundle, options) => {
// https://github.com/vuejs/vue/blob/dev/packages/vue-server-renderer/README.md#why-use-bundlerenderer
return createBundleRenderer(bundle, Object.assign(options, {
template,
// for component caching
cache: LRU({
max: 1000,
maxAge: 1000 * 60 * 15
}),
// this is only needed when vue-server-renderer is npm-linked
basedir: resolve('./public'),
// performance
runInNewContext: false
}))
}
module.exports = { // adapted from: https://git.io/vodU0
before: function (browser, done) {
/**
* Server config
*/
done()
const app = express()
console.log(`KawAnime's server is at http://localhost:${uri}`.green)
const bundle = require('../../public/vue-ssr-server-bundle.json')
const clientManifest = require('../../public/vue-ssr-client-manifest.json')
renderer = createRenderer(bundle, {
clientManifest
})
console.log(renderer)
app.use(compression({ threshold: 0 }))
app.use('/static', serve('./static', true))
app.use('/public', serve('./public', true))
// Setup the api
require('../../server')(app)
// 301 redirect for changed routes
Object.keys(redirects).forEach((k) => {
app.get(k, (req, res) => res.redirect(301, redirects[k]))
})
server = app.listen(9200, '0.0.0.0', () => {
console.log(`> server started at ${uri}`.green)
done()
})
},
'Getting downloader page and downloading some anime': function (client) {
client
@ -34,7 +83,7 @@ module.exports = { // adapted from: https://git.io/vodU0
.click('div.choose-magnets .input-group__input')
.assert.visible('input[name="name-input"]')
.click('input[name="name-input"]')
.setValue('input[name="name-input"]', 'rewrite')
.setValue('input[name="name-input"]', 'sakura trick')
.assert.visible('input[name="from-ep-input"]')
.click('input[name="from-ep-input"]')
.setValue('input[name="from-ep-input"]', '3')

View File

@ -1,8 +1,8 @@
const path = require('path')
const webpack = require('webpack')
const MFS = require('memory-fs')
const clientConfig = require('./webpack.client.config')
const serverConfig = require('./webpack.server.config')
const clientConfig = require(path.join(__dirname, 'webpack.client.config'))
const serverConfig = require(path.join(__dirname, 'webpack.server.config'))
module.exports = function setupDevServer (app, cb) {
let bundle, clientManifest

View File

@ -1,5 +1,5 @@
module.exports = {
extractCSS: process.env.NODE_ENV === 'production',
extractCSS: !process.env.NODE_ENV === 'development',
preserveWhitespace: false,
postcss: [
require('autoprefixer')({

View File

@ -1,7 +1,6 @@
const webpack = require('webpack')
const merge = require('webpack-merge')
const base = require('./webpack.base.config')
// const SWPrecachePlugin = require('sw-precache-webpack-plugin')
const VueSSRClientPlugin = require('vue-server-renderer/client-plugin')
const config = merge(base, {