Skip to content

Commit ca17278

Browse files
committed
Moved cache vars into obj
1 parent bbd2a2d commit ca17278

1 file changed

Lines changed: 9 additions & 10 deletions

File tree

utils/bump/resources.js

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// Bumps @require'd JS in userscripts
44

55
// NOTE: Doesn't git commit to allow script editing from breaking changes
6-
// NOTE: Pass --cache to use cacheFilePath for faster init
6+
// NOTE: Pass --cache to use cache.filePath for faster init
77

88
(async () => {
99

@@ -17,8 +17,7 @@
1717
const bump = await import(require('url').pathToFileURL(bumpUtilsFilePath))
1818

1919
// Init CACHE vars
20-
const cacheMode = process.argv.includes('--cache'),
21-
cacheFilePath = path.join(__dirname, '.cache/userJSpaths.json')
20+
const cache = { mode: process.argv.includes('--cache'), filePath: path.join(__dirname, '.cache/userJSpaths.json') }
2221

2322
// Init REGEX
2423
const regEx = {
@@ -28,18 +27,18 @@
2827
}
2928

3029
// Collect userscripts
31-
bump.log.working(`\n${ cacheMode ? 'Collecting' : 'Searching for' } userscripts...\n`)
30+
bump.log.working(`\n${ cache.mode ? 'Collecting' : 'Searching for' } userscripts...\n`)
3231
let userJSfiles = []
33-
if (cacheMode) {
32+
if (cache.mode) {
3433
try { // create missing cache file
35-
fs.mkdirSync(path.dirname(cacheFilePath), { recursive: true })
36-
const fd = fs.openSync(cacheFilePath, fs.constants.O_CREAT | fs.constants.O_EXCL | fs.constants.O_RDWR)
37-
bump.log.error(`Cache file missing. Generating ${cacheFilePath}...\n`)
34+
fs.mkdirSync(path.dirname(cache.filePath), { recursive: true })
35+
const fd = fs.openSync(cache.filePath, fs.constants.O_CREAT | fs.constants.O_EXCL | fs.constants.O_RDWR)
36+
bump.log.error(`Cache file missing. Generating ${cache.filePath}...\n`)
3837
userJSfiles = await bump.findUserJS() ; console.log('')
3938
fs.writeFileSync(fd, JSON.stringify(userJSfiles, null, 2), 'utf-8')
40-
bump.log.success(`\nCache file created @ ${cacheFilePath}`)
39+
bump.log.success(`\nCache file created @ ${cache.filePath}`)
4140
} catch (err) { // use existing cache file
42-
userJSfiles = JSON.parse(fs.readFileSync(cacheFilePath, 'utf-8'))
41+
userJSfiles = JSON.parse(fs.readFileSync(cache.filePath, 'utf-8'))
4342
console.log(userJSfiles) ; console.log('')
4443
}
4544
} else { // use findUserJS()

0 commit comments

Comments
 (0)