fixed global settings holefully
This commit is contained in:
parent
7e58b4e703
commit
24a1543c2a
5 changed files with 50 additions and 44 deletions
29
bin/index.js
29
bin/index.js
|
@ -1,18 +1,11 @@
|
|||
#!/usr/bin/env node
|
||||
import fs from 'fs'
|
||||
import { Encoder } from "../lib/encoder.js"
|
||||
import { UI } from "../lib/ui.js"
|
||||
import termkit from "terminal-kit"
|
||||
import { SettingsManager } from "../lib/settingsManager.js"
|
||||
import path from "path"
|
||||
//get settings
|
||||
let settings = new SettingsManager()
|
||||
getSettings()
|
||||
async function getSettings() {
|
||||
await settings.start()
|
||||
}
|
||||
const fs = require('fs')
|
||||
const path = require("path")
|
||||
const termkit = require("terminal-kit")
|
||||
const { Encoder } = require("../lib/encoder.js")
|
||||
const { UI } = require("../lib/ui.js")
|
||||
const { SettingsManager } = require("../lib/settingsManager.js")
|
||||
let term = termkit.terminal
|
||||
const ui = new UI(settings.settings, settings.currentSetting)
|
||||
|
||||
/**
|
||||
* TODO : FIND A WAY TO COMPILE THIS:..
|
||||
|
@ -22,7 +15,7 @@ const ui = new UI(settings.settings, settings.currentSetting)
|
|||
const inputList = process.argv.slice(2)
|
||||
//if launched without params
|
||||
if (!inputList[0]) {
|
||||
ui.startMenu() //stops program here
|
||||
main(true)
|
||||
}
|
||||
|
||||
//Parse file inputs (n Drag n drop or arguments)
|
||||
|
@ -63,7 +56,13 @@ else {
|
|||
}
|
||||
main()
|
||||
|
||||
async function main() {
|
||||
async function main(menu = false) {
|
||||
//get settings
|
||||
let settings = new SettingsManager()
|
||||
await settings.start(__dirname)
|
||||
const ui = new UI(settings.settings, settings.currentSetting, settings.settingsFile)
|
||||
|
||||
if (menu) savesettings = await ui.startMenu()
|
||||
|
||||
//file checks
|
||||
let isListEncodable = true
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { exec } from 'child_process'
|
||||
const { exec } = require('child_process')
|
||||
|
||||
export class Encoder {
|
||||
class Encoder {
|
||||
currentSetting
|
||||
settings
|
||||
encoder
|
||||
|
@ -136,3 +136,5 @@ export class Encoder {
|
|||
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { Encoder }
|
|
@ -1,10 +1,11 @@
|
|||
import fs from "fs"
|
||||
import path from "path"
|
||||
export class SettingsManager {
|
||||
const fs = require("fs")
|
||||
const path = require("path")
|
||||
|
||||
class SettingsManager {
|
||||
|
||||
settings
|
||||
currentSetting
|
||||
|
||||
settingsFile = __dirname
|
||||
constructor() {
|
||||
}
|
||||
|
||||
|
@ -15,18 +16,18 @@ export class SettingsManager {
|
|||
|
||||
async #init() {
|
||||
let settings
|
||||
settings = await this.#getSettings().catch(async (err) => {
|
||||
settings = undefined
|
||||
})
|
||||
if (!settings) settings = await this.#makeNewSettingsFile()
|
||||
try {
|
||||
settings = await this.#getSettings()
|
||||
} catch (error) {
|
||||
console.log(error)
|
||||
settings = await this.#makeNewSettingsFile()
|
||||
}
|
||||
this.settings = JSON.parse(settings.toString())
|
||||
this.currentSetting = this.settings.presets[this.settings.currentSetting]
|
||||
}
|
||||
async #getSettings() {
|
||||
const dir = __dirname
|
||||
console.log(dir)
|
||||
return new Promise((resolve, reject) => {
|
||||
const getSettings = fs.readFile(path.resolve(dir, "settings.json"), (err, data) => {
|
||||
const getSettings = fs.readFile(path.resolve(this.settingsFile, "settings.json"), (err, data) => {
|
||||
if (err) reject(err)
|
||||
resolve(data)
|
||||
})
|
||||
|
@ -175,9 +176,12 @@ export class SettingsManager {
|
|||
}
|
||||
`
|
||||
return new Promise((resolve, reject) => {
|
||||
fs.writeFile("settings.json", settings, () => {
|
||||
fs.writeFile(path.resolve(this.settingsFile, "settings.json"), settings, (err) => {
|
||||
if (err) throw err
|
||||
resolve(settings)
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { SettingsManager }
|
24
lib/ui.js
24
lib/ui.js
|
@ -1,15 +1,15 @@
|
|||
import termkit from "terminal-kit"
|
||||
import cliProgress from "cli-progress"
|
||||
import fs from "fs"
|
||||
|
||||
export class UI {
|
||||
const termkit = require("terminal-kit")
|
||||
const cliProgress = require("cli-progress")
|
||||
const fs = require("fs")
|
||||
const path = require("path")
|
||||
class UI {
|
||||
term
|
||||
bars = []
|
||||
multibar
|
||||
settings
|
||||
currentSetting
|
||||
|
||||
constructor(settings, currentSetting) {
|
||||
settingsFile
|
||||
constructor(settings, currentSetting, settingsFile) {
|
||||
this.term = termkit.terminal
|
||||
|
||||
this.multibar = new cliProgress.MultiBar({
|
||||
|
@ -21,7 +21,7 @@ export class UI {
|
|||
|
||||
this.settings = settings
|
||||
this.currentSetting = currentSetting
|
||||
|
||||
this.settingsFile = settingsFile
|
||||
}
|
||||
/**
|
||||
*
|
||||
|
@ -92,10 +92,10 @@ export class UI {
|
|||
this.term.inputField(() => { process.exit() })
|
||||
}
|
||||
|
||||
async startMenu(settings) {
|
||||
async startMenu() {
|
||||
await this.#menu()
|
||||
}
|
||||
async #menu() {
|
||||
async #menu(settingsFile) {
|
||||
let menu = []
|
||||
for (let i = 0; i < this.settings.presets.length; i++) {
|
||||
menu.push(`${i}. ${this.settings.presets[i].name}`)
|
||||
|
@ -108,8 +108,8 @@ export class UI {
|
|||
this.term.yellow("Currently using ").bgMagenta(`"${this.settings.presets[this.settings.currentSetting].name}"`).yellow(" preset")
|
||||
this.term.singleColumnMenu(menu, (error, response) => {
|
||||
this.settings.currentSetting = response.selectedIndex
|
||||
fs.writeFileSync("settings.json", JSON.stringify(this.settings))
|
||||
this.term.green("\n Using").green.bold(` ${this.settings.presets[this.settings.currentSetting].name} `).green("setting\n")
|
||||
fs.writeFileSync(path.resolve(this.settingsFile, "settings.json"), JSON.stringify(this.settings))
|
||||
this.term.grey("Press enter to exit...")
|
||||
this.term.inputField(() => { process.exit() })
|
||||
})
|
||||
|
@ -117,3 +117,5 @@ export class UI {
|
|||
|
||||
|
||||
}
|
||||
|
||||
module.exports = { UI }
|
|
@ -6,7 +6,6 @@
|
|||
"bin": {
|
||||
"DMC": "bin/index.js"
|
||||
},
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"start": "node bin/index.js",
|
||||
"build": "pkg . --output dist --debug",
|
||||
|
|
Loading…
Reference in a new issue