|
3 | 3 | // Bumps @require'd JS in userscripts |
4 | 4 |
|
5 | 5 | // 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 |
7 | 7 |
|
8 | 8 | (async () => { |
9 | 9 |
|
|
17 | 17 | const bump = await import(require('url').pathToFileURL(bumpUtilsFilePath)) |
18 | 18 |
|
19 | 19 | // 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') } |
22 | 21 |
|
23 | 22 | // Init REGEX |
24 | 23 | const regEx = { |
|
28 | 27 | } |
29 | 28 |
|
30 | 29 | // 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`) |
32 | 31 | let userJSfiles = [] |
33 | | - if (cacheMode) { |
| 32 | + if (cache.mode) { |
34 | 33 | 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`) |
38 | 37 | userJSfiles = await bump.findUserJS() ; console.log('') |
39 | 38 | 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}`) |
41 | 40 | } 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')) |
43 | 42 | console.log(userJSfiles) ; console.log('') |
44 | 43 | } |
45 | 44 | } else { // use findUserJS() |
|
0 commit comments