From 4a0664c37f22e187b59820fa95cbe3a40ddd811d Mon Sep 17 00:00:00 2001 From: Kylart Date: Sun, 21 May 2017 23:03:54 +0200 Subject: [PATCH] Better initFiles --- assets/scripts/init/main.js | 85 ++++++++++++++++++++++--------------- package.json | 2 +- test/nuxt.test.js | 4 +- 3 files changed, 54 insertions(+), 37 deletions(-) diff --git a/assets/scripts/init/main.js b/assets/scripts/init/main.js index d2a36e8..5091da3 100644 --- a/assets/scripts/init/main.js +++ b/assets/scripts/init/main.js @@ -6,65 +6,76 @@ const fs = require('fs') const {join} = require('path') const URL = require('url-parse') -// Initiating files and directory -// Create the .KawAnime directory const {userInfo} = require('os') const BASE_PATH = userInfo().homedir const dir = join(BASE_PATH, '.KawAnime') -if (!fs.existsSync(dir)) fs.mkdirSync(dir) +// Initiating files and directory +// Create the .KawAnime directory +const createDir = () => { + if (!fs.existsSync(dir)) fs.mkdirSync(dir) +} -// Conf file -const confPath = join(dir, 'config.json') +const createConfig = () => { + // Conf file + const confPath = join(dir, 'config.json') -if (!fs.existsSync(confPath)) { - console.log('No configuration file detected. Creating...') + if (!fs.existsSync(confPath)) { + console.log('No configuration file detected. Creating...') - const basicConf = { - config: { - fansub: 'HorribleSubs', - quality: '720p', - sound: 'Nyanpasu', - localPath: join(userInfo().homedir, 'Downloads'), - inside: true, - magnets: false + const basicConf = { + config: { + fansub: 'HorribleSubs', + quality: '720p', + sound: 'Nyanpasu', + localPath: join(userInfo().homedir, 'Downloads'), + inside: true, + magnets: false + } } - } - fs.writeFileSync(confPath, JSON.stringify(basicConf), 'utf-8') + fs.writeFileSync(confPath, JSON.stringify(basicConf), 'utf-8') + } } // Local file -const animeLocalPath = join(dir, 'locals.json') +const createLocal = () => { + const animeLocalPath = join(dir, 'locals.json') -if (!fs.existsSync(animeLocalPath)) { - console.log('No anime local file detected. Creating...') + if (!fs.existsSync(animeLocalPath)) { + console.log('No anime local file detected. Creating...') - fs.writeFileSync(animeLocalPath, '{}', 'utf-8') + fs.writeFileSync(animeLocalPath, '{}', 'utf-8') + } } // List file -const listPath = join(dir, 'lists.json') +const createList = () => { + const listPath = join(dir, 'lists.json') -if (!fs.existsSync(listPath)) { - console.log('No anime list file detected. Creating...') + if (!fs.existsSync(listPath)) { + console.log('No anime list file detected. Creating...') - const basicLists = { - watchList: [], - seen: [], - watching: [] + const basicLists = { + watchList: [], + seen: [], + watching: [] + } + + fs.writeFileSync(listPath, JSON.stringify(basicLists), 'utf-8') } - - fs.writeFileSync(listPath, JSON.stringify(basicLists), 'utf-8') } + // History file -const historyPath = join(dir, 'history.json') +const createHistory = () => { + const historyPath = join(dir, 'history.json') -if (!fs.existsSync(historyPath)) { - console.log('No watch history file detected. Creating...') + if (!fs.existsSync(historyPath)) { + console.log('No watch history file detected. Creating...') - fs.writeFileSync(historyPath, '{}', 'utf-8') + fs.writeFileSync(historyPath, '{}', 'utf-8') + } } const {openExternal, openInBrowser} = require('./openExternal.js') @@ -76,6 +87,12 @@ const history = require('./history') const horrible = require('./horrible.js') const route = (nuxt) => { + createDir() + createConfig() + createLocal() + createHistory() + createList() + return (req, res) => { const url = new URL(req.url) diff --git a/package.json b/package.json index 598b452..f2067f2 100755 --- a/package.json +++ b/package.json @@ -11,7 +11,7 @@ "license": "MIT", "scripts": { "dev": "cross-env NODE_ENV=development electron .", - "test:nuxt": "nyc ava --verbose test/nuxt.test.js", + "test:nuxt": "ava --verbose test/nuxt.test.js", "test:front": "nuxt build && nyc mocha test/mocha.js", "test": "standard --fix && nuxt build && mocha test/mocha.js && ava test/nuxt.js", "build": "nuxt build", diff --git a/test/nuxt.test.js b/test/nuxt.test.js index 0164cbd..604916e 100644 --- a/test/nuxt.test.js +++ b/test/nuxt.test.js @@ -25,7 +25,7 @@ let kawAnimeFilesPath = { } // Init Nuxt.js and create a server listening on localhost:4000 -test.before('Init Nuxt.js', async t => { +test.before('Init Nuxt.js', async () => { /** * Nuxt config */ @@ -100,7 +100,7 @@ test('Route /downloader exits and renders download button', async t => { // Close server and ask nuxt to stop listening to file changes -test.after('Closing server and nuxt.test.js', t => { +test.after('Closing server and nuxt.test.js', () => { server.close() nuxt.close() }) \ No newline at end of file