Skip to content

Commit 6c573b8

Browse files
committed
Moved paths into cache.paths, re-ordered routines for readability
1 parent a8fdc54 commit 6c573b8

1 file changed

Lines changed: 19 additions & 14 deletions

File tree

utils/bump/resources.js

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,26 @@
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 cache.filePath for faster init
6+
// NOTE: Pass --cache to use cache.paths.userJSpaths for faster init
77

88
(async () => {
99

10+
1011
// Import LIBS
1112
const fs = require('fs'), // to read/write files
12-
path = require('path'), // to manipulate paths
13-
bumpUtilsFilePath = path.join(__dirname, '.cache/bump-utils.mjs')
14-
fs.mkdirSync(path.dirname(bumpUtilsFilePath), { recursive: true })
15-
fs.writeFileSync(bumpUtilsFilePath, (await (await fetch(
16-
'https://cdn.jsdelivr.net/gh/adamlui/ai-web-extensions@latest/utils/bump/bump-utils.min.mjs')).text()
17-
).replace(/^\/\*\*[\s\S]*?\*\/\s*/, '')) // strip JSD header minification comment
18-
const bump = await import(`file://${bumpUtilsFilePath}`)
13+
path = require('path') // to manipulate paths
1914

2015
// Init CACHE vars
21-
const cache = { mode: process.argv.includes('--cache'), filePath: path.join(__dirname, '.cache/userJSpaths.json') }
16+
const cache = { mode: process.argv.includes('--cache'), paths: { root: '.cache/' }}
17+
cache.paths.bumpUtils = path.join(__dirname, `${cache.paths.root}bump-utils.min.mjs`)
18+
cache.paths.userJSpaths = path.join(__dirname, `${cache.paths.root}userJSpaths.json`)
19+
20+
// Import BUMP UTILS
21+
fs.mkdirSync(path.dirname(cache.paths.bumpUtils), { recursive: true })
22+
fs.writeFileSync(cache.paths.bumpUtils, (await (await fetch(
23+
'https://cdn.jsdelivr.net/gh/adamlui/ai-web-extensions@latest/utils/bump/bump-utils.min.mjs')).text()
24+
).replace(/^\/\*\*[\s\S]*?\*\/\s*/, '')) // strip JSD header minification comment
25+
const bump = await import(`file://${cache.paths.bumpUtils}`)
2226

2327
// Init REGEX
2428
const regEx = {
@@ -32,14 +36,15 @@
3236
let userJSfiles = []
3337
if (cache.mode) {
3438
try { // create missing cache file
35-
fs.mkdirSync(path.dirname(cache.filePath), { recursive: true })
36-
const fd = fs.openSync(cache.filePath, fs.constants.O_CREAT | fs.constants.O_EXCL | fs.constants.O_RDWR)
37-
bump.log.error(`Cache file missing. Generating ${cache.filePath}...\n`)
39+
fs.mkdirSync(path.dirname(cache.paths.userJSpaths), { recursive: true })
40+
const fd = fs.openSync(cache.paths.userJSpaths,
41+
fs.constants.O_CREAT | fs.constants.O_EXCL | fs.constants.O_RDWR)
42+
bump.log.error(`Cache file missing. Generating ${cache.paths.userJSpaths}...\n`)
3843
userJSfiles = await bump.findUserJS() ; console.log('')
3944
fs.writeFileSync(fd, JSON.stringify(userJSfiles, null, 2), 'utf-8')
40-
bump.log.success(`\nCache file created @ ${cache.filePath}`)
45+
bump.log.success(`\nCache file created @ ${cache.paths.userJSpaths}`)
4146
} catch (err) { // use existing cache file
42-
userJSfiles = JSON.parse(fs.readFileSync(cache.filePath, 'utf-8'))
47+
userJSfiles = JSON.parse(fs.readFileSync(cache.paths.userJSpaths, 'utf-8'))
4348
console.log(userJSfiles) ; console.log('')
4449
}
4550
} else { // use bump.findUserJS()

0 commit comments

Comments
 (0)