Skip to content

Commit

Permalink
console.log replacement for utilities
Browse files Browse the repository at this point in the history
This is purely down to me using console.log as a debugger, and having these in the utilities makes it harder to find them when done.
  • Loading branch information
jtsage committed Aug 26, 2021
1 parent ba80deb commit 4459a4b
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 59 deletions.
2 changes: 1 addition & 1 deletion lib/util-extract-conflicts-strings.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ for ( const [modName, conflictDetails] of Object.entries(conflictListData.confli
}

fs.writeFileSync('conflicts.json', JSON.stringify(newData))
console.log('written')
process.stdout.write('written\n')
70 changes: 36 additions & 34 deletions modChecker.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,11 @@ const myArgs = yargs(hideBin(process.argv))
.argv


console.log(' _______ __ ______ __ __ ')
console.log('| | |.-----.--| | | |--.-----.----.| |--.-----.----.')
console.log('| || _ | _ | ---| | -__| __|| <| -__| _|')
console.log('|__|_|__||_____|_____|______|__|__|_____|____||__|__|_____|__| ')
console.log(' (c) 2021 JTSage')
writeLn(' _______ __ ______ __ __ ')
writeLn('| | |.-----.--| | | |--.-----.----.| |--.-----.----.')
writeLn('| || _ | _ | ---| | -__| __|| <| -__| _|')
writeLn('|__|_|__||_____|_____|______|__|__|_____|____||__|__|_____|__| ')
writeLn(' (c) 2021 JTSage')

const myTranslator = new translator.translator(myArgs.lang === null ? translator.getSystemLocale() : myArgs.lang)

Expand All @@ -105,15 +105,15 @@ if ( myArgs.modFolder === null ) {
/* Could not parse the settings file. */
location_savegame = null
logger.fatal('loader', `Unable to parse gameSettings.xml : ${xmlErr.toString()}`)
console.log(logger.toDisplayText)
writeLn(logger.toDisplayText)
process.exit(1)
}

if ( ! ('gamesettings' in xmlTree) ) {
/* Not a valid config */
location_savegame = null
logger.fatal('loader', 'gameSettings.xml does not contain the root gamesettings tag (not a settings file)')
console.log(logger.toDisplayText)
writeLn(logger.toDisplayText)
process.exit(1)
}

Expand Down Expand Up @@ -144,25 +144,25 @@ const modList = new modReader(location_savegame, location_modfolder, logger, myT

modList.readAll().then(async () => {
if ( myArgs.broken === true ) {
console.log('')
writeLn('')
sepLine()
console.log(await myTranslator.stringLookup('tab_broken'))
console.log('')
console.log(await myTranslator.stringLookup('broken_blurb'))
writeLn(await myTranslator.stringLookup('tab_broken'))
writeLn('')
writeLn(await myTranslator.stringLookup('broken_blurb'))
sepLine()

await modList.search({
columns : ['filenameSlash', 'failedTestList', 'copyName', 'shortName'],
terms : ['didTestingFail'],
}).then(async (searchResults) => {
for ( let i = 0; i < searchResults.length; i++) {
console.log(searchResults[i][0])
writeLn(searchResults[i][0])
for ( let j = 0; j < searchResults[i][1].length; j++ ) {
/* eslint-disable no-await-in-loop */
console.log(` ${await myTranslator.stringLookup(searchResults[i][1][j])}`)
writeLn(` ${await myTranslator.stringLookup(searchResults[i][1][j])}`)
/* eslint-enable */
}
console.log('')
writeLn('')
}
}).catch((unknownError) => {
// Shouldn't happen. No idea
Expand All @@ -171,11 +171,11 @@ modList.readAll().then(async () => {
}

if ( myArgs.conflicts === true ) {
console.log('')
writeLn('')
sepLine()
console.log(await myTranslator.stringLookup('tab_conflict'))
console.log('')
console.log(await myTranslator.stringLookup('conflict_blurb'))
writeLn(await myTranslator.stringLookup('tab_conflict'))
writeLn('')
writeLn(await myTranslator.stringLookup('conflict_blurb'))
sepLine()

const folderAndZipText = await myTranslator.stringLookup('conflict_error_folder_and_file')
Expand All @@ -184,19 +184,19 @@ modList.readAll().then(async () => {
const output = searchResults.map((record) => {
return ` ${record[0]} (${record[1]}) - ${record[2]}`
})
console.log(output.join('\n\n'))
writeLn(output.join('\n\n'))
}).catch((unknownError) => {
// Shouldn't happen. No idea
logger.notice('reader', `Could not get "conflict list" : ${unknownError}`)
})
}

if ( myArgs.missing === true ) {
console.log('')
writeLn('')
sepLine()
console.log(await myTranslator.stringLookup('tab_missing'))
console.log('')
console.log(await myTranslator.stringLookup('missing_blurb'))
writeLn(await myTranslator.stringLookup('tab_missing'))
writeLn('')
writeLn(await myTranslator.stringLookup('missing_blurb'))
sepLine()
const usedString = await myTranslator.stringLookup('detail_mod_used_games')

Expand All @@ -210,17 +210,17 @@ modList.readAll().then(async () => {
}
return ` ${record[0]} (${record[1]})`
})
console.log(output.join('\n'))
writeLn(output.join('\n'))
}).catch((unknownError) => {
// Shouldn't happen. No idea
logger.notice('reader', `Could not get "missing list" : ${unknownError}`)
})
}

if ( myArgs.inactive === true ) {
console.log('')
writeLn('')
sepLine()
console.log(await myTranslator.stringLookup('explore_options_special_inactive'))
writeLn(await myTranslator.stringLookup('explore_options_special_inactive'))
sepLine()

await modList.search({
Expand All @@ -234,17 +234,17 @@ modList.readAll().then(async () => {
const output = searchResults.map((record) => {
return ` ${record[0]} (${record[1]}) - ${record[2][0]}`
})
console.log(output.join('\n'))
writeLn(output.join('\n'))
}).catch((unknownError) => {
// Shouldn't happen. No idea
logger.notice('reader', `Could not get "explore list" : ${unknownError}`)
})
}

if ( myArgs.unused === true ) {
console.log('')
writeLn('')
sepLine()
console.log(await myTranslator.stringLookup('explore_options_special_unused'))
writeLn(await myTranslator.stringLookup('explore_options_special_unused'))
sepLine()

await modList.search({
Expand All @@ -259,25 +259,27 @@ modList.readAll().then(async () => {
const output = searchResults.map((record) => {
return ` ${record[0]} (${record[1]}) - ${record[2][0]}`
})
console.log(output.join('\n'))
writeLn(output.join('\n'))
}).catch((unknownError) => {
// Shouldn't happen. No idea
logger.notice('reader', `Could not get "explore list" : ${unknownError}`)
})
}

if ( myArgs.verbose === true ) {
console.log('')
writeLn('')
sepLine()
console.log('Debug Log')
writeLn('Debug Log')
sepLine()
console.log(logger.toDisplayText)
writeLn(logger.toDisplayText)
}

})


function sepLine() {
console.log(' -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-')
writeLn(' -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-')
}

function writeLn(text) { process.stdout.write(`${text}\n`) }

26 changes: 14 additions & 12 deletions test/mod-reader-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,42 +77,42 @@ const expectedGoodList = [


modList.readAll().then(() => {
console.log(c.cyan('NOTICE: File Read Done, Testing Proceeding Async - Calling First Search, will return when testing is complete.'))
writeLn(c.cyan('NOTICE: File Read Done, Testing Proceeding Async - Calling First Search, will return when testing is complete.'))

/* Check broken list */
modList.getBrokenList(['shortName', 'failedTestList']).then((results) => {
if (JSON.stringify(expectedBrokenList) === JSON.stringify(results)) {
console.log(c.green('PASS: Broken list is as expected'))
writeLn(c.green('PASS: Broken list is as expected'))
} else {
exitCode = 1
console.log(c.red('FAIL: Broken list is not as expected'))
writeLn(c.red('FAIL: Broken list is not as expected'))
const diff = Diff.diffChars(JSON.stringify(expectedBrokenList), JSON.stringify(results))

diff.forEach((part) => {
const color = part.added ? 'green' :
part.removed ? 'red' : 'grey'
process.stderr.write(part.value[color])
})
console.log()
writeLn()
}
})

/* Check conflict list */
modList.conflictList('').then((results) => {
const simpleResults = results.map((x) => { return x[0] })
if (JSON.stringify(simpleResults) === JSON.stringify(expectedConflictList)) {
console.log(c.green('PASS: Conflict list is as expected'))
writeLn(c.green('PASS: Conflict list is as expected'))
} else {
exitCode = 1
console.log(c.red('FAIL: Conflict list is not as expected'))
writeLn(c.red('FAIL: Conflict list is not as expected'))
const diff = Diff.diffChars(JSON.stringify(expectedConflictList), JSON.stringify(simpleResults))

diff.forEach((part) => {
const color = part.added ? 'green' :
part.removed ? 'red' : 'grey'
process.stderr.write(part.value[color])
})
console.log()
writeLn()
}
})

Expand All @@ -123,25 +123,27 @@ modList.readAll().then(() => {
terms : ['isNotMissing', 'didTestingPassEnough'],
}).then((results) => {
if (JSON.stringify(expectedGoodList) === JSON.stringify(results)) {
console.log(c.green('PASS: Good list is as expected'))
writeLn(c.green('PASS: Good list is as expected'))
} else {
exitCode = 1
console.log(c.red('FAIL: Good list is not as expected'))
writeLn(c.red('FAIL: Good list is not as expected'))
const diff = Diff.diffChars(JSON.stringify(expectedGoodList), JSON.stringify(results))

diff.forEach((part) => {
const color = part.added ? 'green' :
part.removed ? 'red' : 'grey'
process.stderr.write(part.value[color])
})
console.log()
writeLn()
}
if ( exitCode === 1 ) {
console.log(logger.toDisplayText)
writeLn(logger.toDisplayText)
}
process.exit(exitCode)
})
})


console.log(c.cyan('NOTICE: End File Code. There may (should!) still be running async processes'))
writeLn(c.cyan('NOTICE: End File Code. There may (should!) still be running async processes'))

function writeLn(text) { process.stdout.write(`${text}\n`) }
26 changes: 14 additions & 12 deletions test/simpleQuery.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const modList = new modReader(gameFolder, fileFolder, logger, myTranslator.defer


modList.readAll().then(() => {
console.log('File Read Done, Testing Proceeding Async - Calling First Search, will return when testing is complete.')
writeLn('File Read Done, Testing Proceeding Async - Calling First Search, will return when testing is complete.')

modList.search({
columns : [
Expand All @@ -42,38 +42,40 @@ modList.readAll().then(() => {
terms : ['isModBroken'],
debug : true,
}).then((searchResults) => {
console.log('test.js results:', searchResults)
//console.log(modList.log.toDisplayText)
writeLn('test.js results:', searchResults)
//writeLn(modList.log.toDisplayText)
})
})

async function _promiseStatus() {
/* This is *spiffy* - it looks at the status of the testing promises, with a quick delay.
Assuming everything is working correctly, you should see them resolve in parallel. */
/* eslint-disable no-promise-executor-return */
console.log(modList.testPromise)
writeLn(modList.testPromise)
await new Promise((resolve) => setTimeout(resolve, 150))
console.log(modList.testPromise)
writeLn(modList.testPromise)
await new Promise((resolve) => setTimeout(resolve, 150))
console.log(modList.testPromise)
writeLn(modList.testPromise)
await new Promise((resolve) => setTimeout(resolve, 150))
console.log(modList.testPromise)
writeLn(modList.testPromise)
await new Promise((resolve) => setTimeout(resolve, 150))
console.log(modList.testPromise)
writeLn(modList.testPromise)
await new Promise((resolve) => setTimeout(resolve, 150))
console.log(modList.testPromise)
writeLn(modList.testPromise)
/* eslint-enable no-promise-executor-return */
}
//_promiseStatus().then(() => { console.log('blag')})
//_promiseStatus().then(() => { writeLn('blag')})

/* Race the parser!! We initialized in "de", changing to "en" to get the list from the search
above in english. As long as this line is run before the search can return, we should see english
This is a deliberate race condition to make sure async is working. */
myTranslator.currentLocale = 'en'

myTranslator.getLangList().then((data) => {
console.log('Languages List (async loading - likely returning before file load is done):', data)
writeLn('Languages List (async loading - likely returning before file load is done):', data)
})


console.log('End File Code. There may (should!) still be running async processes')
writeLn('End File Code. There may (should!) still be running async processes')

function writeLn(text) { process.stdout.write(`${text}\n`) }

0 comments on commit 4459a4b

Please sign in to comment.
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy