mirror of https://github.com/Kylart/KawAnime.git
Better initFiles
This commit is contained in:
parent
646b261eec
commit
4a0664c37f
|
@ -6,14 +6,17 @@ const fs = require('fs')
|
||||||
const {join} = require('path')
|
const {join} = require('path')
|
||||||
const URL = require('url-parse')
|
const URL = require('url-parse')
|
||||||
|
|
||||||
// Initiating files and directory
|
|
||||||
// Create the .KawAnime directory
|
|
||||||
const {userInfo} = require('os')
|
const {userInfo} = require('os')
|
||||||
const BASE_PATH = userInfo().homedir
|
const BASE_PATH = userInfo().homedir
|
||||||
const dir = join(BASE_PATH, '.KawAnime')
|
const dir = join(BASE_PATH, '.KawAnime')
|
||||||
|
|
||||||
|
// Initiating files and directory
|
||||||
|
// Create the .KawAnime directory
|
||||||
|
const createDir = () => {
|
||||||
if (!fs.existsSync(dir)) fs.mkdirSync(dir)
|
if (!fs.existsSync(dir)) fs.mkdirSync(dir)
|
||||||
|
}
|
||||||
|
|
||||||
|
const createConfig = () => {
|
||||||
// Conf file
|
// Conf file
|
||||||
const confPath = join(dir, 'config.json')
|
const confPath = join(dir, 'config.json')
|
||||||
|
|
||||||
|
@ -33,8 +36,10 @@ if (!fs.existsSync(confPath)) {
|
||||||
|
|
||||||
fs.writeFileSync(confPath, JSON.stringify(basicConf), 'utf-8')
|
fs.writeFileSync(confPath, JSON.stringify(basicConf), 'utf-8')
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Local file
|
// Local file
|
||||||
|
const createLocal = () => {
|
||||||
const animeLocalPath = join(dir, 'locals.json')
|
const animeLocalPath = join(dir, 'locals.json')
|
||||||
|
|
||||||
if (!fs.existsSync(animeLocalPath)) {
|
if (!fs.existsSync(animeLocalPath)) {
|
||||||
|
@ -42,8 +47,10 @@ if (!fs.existsSync(animeLocalPath)) {
|
||||||
|
|
||||||
fs.writeFileSync(animeLocalPath, '{}', 'utf-8')
|
fs.writeFileSync(animeLocalPath, '{}', 'utf-8')
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// List file
|
// List file
|
||||||
|
const createList = () => {
|
||||||
const listPath = join(dir, 'lists.json')
|
const listPath = join(dir, 'lists.json')
|
||||||
|
|
||||||
if (!fs.existsSync(listPath)) {
|
if (!fs.existsSync(listPath)) {
|
||||||
|
@ -57,8 +64,11 @@ if (!fs.existsSync(listPath)) {
|
||||||
|
|
||||||
fs.writeFileSync(listPath, JSON.stringify(basicLists), 'utf-8')
|
fs.writeFileSync(listPath, JSON.stringify(basicLists), 'utf-8')
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// History file
|
// History file
|
||||||
|
const createHistory = () => {
|
||||||
const historyPath = join(dir, 'history.json')
|
const historyPath = join(dir, 'history.json')
|
||||||
|
|
||||||
if (!fs.existsSync(historyPath)) {
|
if (!fs.existsSync(historyPath)) {
|
||||||
|
@ -66,6 +76,7 @@ if (!fs.existsSync(historyPath)) {
|
||||||
|
|
||||||
fs.writeFileSync(historyPath, '{}', 'utf-8')
|
fs.writeFileSync(historyPath, '{}', 'utf-8')
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const {openExternal, openInBrowser} = require('./openExternal.js')
|
const {openExternal, openInBrowser} = require('./openExternal.js')
|
||||||
const seasons = require('./seasons.js')
|
const seasons = require('./seasons.js')
|
||||||
|
@ -76,6 +87,12 @@ const history = require('./history')
|
||||||
const horrible = require('./horrible.js')
|
const horrible = require('./horrible.js')
|
||||||
|
|
||||||
const route = (nuxt) => {
|
const route = (nuxt) => {
|
||||||
|
createDir()
|
||||||
|
createConfig()
|
||||||
|
createLocal()
|
||||||
|
createHistory()
|
||||||
|
createList()
|
||||||
|
|
||||||
return (req, res) => {
|
return (req, res) => {
|
||||||
const url = new URL(req.url)
|
const url = new URL(req.url)
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "cross-env NODE_ENV=development electron .",
|
"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:front": "nuxt build && nyc mocha test/mocha.js",
|
||||||
"test": "standard --fix && nuxt build && mocha test/mocha.js && ava test/nuxt.js",
|
"test": "standard --fix && nuxt build && mocha test/mocha.js && ava test/nuxt.js",
|
||||||
"build": "nuxt build",
|
"build": "nuxt build",
|
||||||
|
|
|
@ -25,7 +25,7 @@ let kawAnimeFilesPath = {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Init Nuxt.js and create a server listening on localhost:4000
|
// 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
|
* 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
|
// 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()
|
server.close()
|
||||||
nuxt.close()
|
nuxt.close()
|
||||||
})
|
})
|
Loading…
Reference in New Issue