Better initFiles

This commit is contained in:
Kylart 2017-05-21 23:03:54 +02:00
parent 646b261eec
commit 4a0664c37f
3 changed files with 54 additions and 37 deletions

View File

@ -6,14 +6,17 @@ 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')
// Initiating files and directory
// Create the .KawAnime directory
const createDir = () => {
if (!fs.existsSync(dir)) fs.mkdirSync(dir)
}
const createConfig = () => {
// Conf file
const confPath = join(dir, 'config.json')
@ -33,8 +36,10 @@ if (!fs.existsSync(confPath)) {
fs.writeFileSync(confPath, JSON.stringify(basicConf), 'utf-8')
}
}
// Local file
const createLocal = () => {
const animeLocalPath = join(dir, 'locals.json')
if (!fs.existsSync(animeLocalPath)) {
@ -42,8 +47,10 @@ if (!fs.existsSync(animeLocalPath)) {
fs.writeFileSync(animeLocalPath, '{}', 'utf-8')
}
}
// List file
const createList = () => {
const listPath = join(dir, 'lists.json')
if (!fs.existsSync(listPath)) {
@ -57,8 +64,11 @@ if (!fs.existsSync(listPath)) {
fs.writeFileSync(listPath, JSON.stringify(basicLists), 'utf-8')
}
}
// History file
const createHistory = () => {
const historyPath = join(dir, 'history.json')
if (!fs.existsSync(historyPath)) {
@ -66,6 +76,7 @@ if (!fs.existsSync(historyPath)) {
fs.writeFileSync(historyPath, '{}', 'utf-8')
}
}
const {openExternal, openInBrowser} = require('./openExternal.js')
const seasons = require('./seasons.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)

View File

@ -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",

View File

@ -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()
})