|
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 cache.filePath for faster init |
| 6 | +// NOTE: Pass --cache to use cache.paths.userJSpaths for faster init |
7 | 7 |
|
8 | 8 | (async () => { |
9 | 9 |
|
| 10 | + |
10 | 11 | // Import LIBS |
11 | 12 | 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 |
19 | 14 |
|
20 | 15 | // 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}`) |
22 | 26 |
|
23 | 27 | // Init REGEX |
24 | 28 | const regEx = { |
|
32 | 36 | let userJSfiles = [] |
33 | 37 | if (cache.mode) { |
34 | 38 | 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`) |
38 | 43 | userJSfiles = await bump.findUserJS() ; console.log('') |
39 | 44 | 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}`) |
41 | 46 | } 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')) |
43 | 48 | console.log(userJSfiles) ; console.log('') |
44 | 49 | } |
45 | 50 | } else { // use bump.findUserJS() |
|
0 commit comments