| 
 | 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