Skip to content

Commit 0781b88

Browse files
committed
Converted bash scripts to JS for speed
Co-Authored-By: DeepSeek AI <[email protected]> ↞ [auto-sync from https://github.com/adamlui/ai-web-extensions/tree/main/perplexity-omnibox]
1 parent 437e29e commit 0781b88

File tree

4 files changed

+112
-95
lines changed

4 files changed

+112
-95
lines changed

eslint.config.mjs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ export default [
1111
{
1212
files: ['**/*.{js,mjs}'],
1313
languageOptions: {
14-
ecmaVersion: 'latest', sourceType: 'script', globals: { ...globals.browser, chrome: 'readonly' }},
14+
ecmaVersion: 'latest', sourceType: 'script',
15+
globals: { ...globals.browser, ...globals.node, chrome: 'readonly' }
16+
},
1517
plugins: { 'import': importPlugin, 'js-styles': stylisticJS },
1618
rules: {
1719
...js.configs.recommended.rules,

package.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@
2121
"translate": "py chromium/utils/translate-en-messages.py",
2222
"translate:chrome": "py chromium/utils/translate-en-messages.py",
2323
"translate:chromium": "py chromium/utils/translate-en-messages.py",
24-
"bump": "bash utils/bump.sh",
25-
"bump:ext": "bash utils/bump.sh",
26-
"bump:ext-nc": "bash utils/bump.sh --no-commit",
27-
"bump:ext-np": "bash utils/bump.sh --no-push",
28-
"bump:extension": "bash utils/bump.sh",
29-
"bump:extensions": "bash utils/bump.sh",
30-
"bump:manifest": "bash utils/bump.sh",
31-
"bump:manifests": "bash utils/bump.sh"
24+
"bump": "node utils/bump/extension-manifests",
25+
"bump:ext": "node utils/bump/extension-manifests",
26+
"bump:ext-nc": "node utils/bump/extension-manifests --no-commit",
27+
"bump:ext-np": "node utils/bump/extension-manifests --no-push",
28+
"bump:extension": "node utils/bump/extension-manifests",
29+
"bump:extensions": "node utils/bump/extension-manifests",
30+
"bump:manifest": "node utils/bump/extension-manifests",
31+
"bump:manifests": "node utils/bump/extension-manifests"
3232
},
3333
"devDependencies": {
3434
"@eslint/json": "^0.13.2",

utils/bump.sh

Lines changed: 0 additions & 86 deletions
This file was deleted.

utils/bump/extension-manifests.js

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
#!/usr/bin/env node
2+
3+
// Bumps extension manifests if changes detected + git commit/push
4+
// NOTE: Pass --chrom<e|ium> to forcibly bump Chromium manifest only
5+
// NOTE: Pass --<ff|firefox> to forcibly bump Firefox manifest only
6+
// NOTE: Pass --no-<commit|push> to skip git commit/push
7+
8+
(async () => {
9+
10+
// Import LIBS
11+
const fs = require('fs'),
12+
path = require('path'),
13+
{ execSync } = require('child_process')
14+
15+
// Init CACHE vars
16+
const cache = { paths: { root: '.cache/' }}
17+
cache.paths.bumpUtils = path.join(__dirname, `${cache.paths.root}bump-utils.min.mjs`)
18+
19+
// Import BUMP UTILS
20+
fs.mkdirSync(path.dirname(cache.paths.bumpUtils), { recursive: true })
21+
fs.writeFileSync(cache.paths.bumpUtils, (await (await fetch(
22+
'https://cdn.jsdelivr.net/gh/adamlui/ai-web-extensions@latest/utils/bump/bump-utils.min.mjs')).text()
23+
).replace(/^\/\*\*[\s\S]*?\*\/\s*/, '')) // strip JSD header minification comment
24+
const bump = await import('../../../utils/bump/bump-utils.mjs')
25+
26+
// Parse ARGS
27+
const args = process.argv.slice(2),
28+
chromiumOnly = args.some(arg => /chrom/i.test(arg)),
29+
ffOnly = args.some(arg => /f{2}/i.test(arg)),
30+
noCommit = args.includes('--no-commit'),
31+
noPush = args.includes('--no-push')
32+
33+
// Init manifest PATHS
34+
const manifestPaths = ['chromium/extension/manifest.json']
35+
36+
// BUMP versions
37+
const bumpedManifests = {}
38+
for (const manifestPath of manifestPaths) {
39+
40+
// Check latest commit for extension changes if forcible platform flag not set
41+
const platformManifestPath = path.dirname(manifestPath)
42+
if (!chromiumOnly && !ffOnly) {
43+
console.log(`Checking last commit details for ${platformManifestPath}...`)
44+
try {
45+
const latestCommitMsg = execSync(
46+
`git log -1 --format=%s -- "${platformManifestPath}"`, { encoding: 'utf8' }).trim()
47+
bump.log.hash(`${latestCommitMsg}\n`)
48+
if (/bump.*(?:ersion|manifest)/i.test(latestCommitMsg)) {
49+
console.log('No changes found. Skipping...\n') ; continue }
50+
} catch (err) { bump.log.error('Error checking git history\n') }
51+
}
52+
53+
console.log(`Bumping version in ${chromiumOnly ? 'Chromium' : ffOnly ? 'Firefox' : ''} manifest...`)
54+
const { oldVer, newVer } = bump.bumpDateVer(manifestPath)
55+
bumpedManifests[`${platformManifestPath}/manifest.json`] = `${oldVer};${newVer}`
56+
}
57+
58+
// LOG manifests bumped
59+
const pluralSuffix = Object.keys(bumpedManifests).length > 1 ? 's' : ''
60+
if (Object.keys(bumpedManifests).length == 0) {
61+
bump.log.info('Completed. No manifests bumped.') ; process.exit(0)
62+
} else bump.log.success(`${Object.keys(bumpedManifests).length} manifest${pluralSuffix} bumped!`)
63+
64+
65+
// ADD/COMMIT/PUSH bump(s)
66+
if (!noCommit) {
67+
bump.log.working(`\nCommitting bump${pluralSuffix} to Git...\n`)
68+
69+
// Init commit msg
70+
let commitMsg = 'Bumped `version`' ; const uniqueVers = {}
71+
Object.values(bumpedManifests).forEach(vers => {
72+
const newVer = vers.split(';')[1] ; uniqueVers[newVer] = true })
73+
if (Object.keys(uniqueVers).length == 1)
74+
commitMsg += ` to \`${Object.keys(uniqueVers)[0]}\``
75+
76+
// git add/commit/push
77+
try {
78+
execSync('git add ./**/manifest.json')
79+
execSync(`git commit -n -m "${commitMsg}"`)
80+
if (!noPush) {
81+
bump.log.working('\nPulling latest changes from remote to sync local repository...\n')
82+
execSync('git pull')
83+
bump.log.working('\nPushing bump${pluralSuffix} to Git...\n')
84+
execSync('git push')
85+
}
86+
const gitAction = `updated${ !noCommit ? '/committed' : '' }${ !noPush ? '/pushed' : '' }`
87+
bump.log.success(
88+
`Success! ${Object.keys(bumpedManifests).length} manifest${pluralSuffix} ${gitAction} to GitHub`)
89+
} catch (err) { bump.log.error('Git operation failed: ' + err.message) }
90+
}
91+
92+
93+
// Final SUMMARY log
94+
console.log() // line break
95+
Object.entries(bumpedManifests).forEach(([manifest, versions]) => {
96+
const [oldVer, newVer] = versions.split(';')
97+
console.log(` ± ${manifest} ${
98+
bump.colors.bw}v${oldVer}${bump.colors.nc}${bump.colors.bg}v${newVer}${bump.colors.nc}`)
99+
})
100+
101+
})()

0 commit comments

Comments
 (0)