diff --git a/.github/workflows/code-duplication.yml b/.github/workflows/code-duplication.yml new file mode 100644 index 0000000..918b9a2 --- /dev/null +++ b/.github/workflows/code-duplication.yml @@ -0,0 +1,202 @@ +name: "Check Code Duplication in PR Diff" + +on: + pull_request: + branches: + - '**' + workflow_dispatch: + +permissions: + contents: read + pull-requests: write + +jobs: + analyze: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 # scarica tutta la storia, serve per merge-base e diff + + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version: 20 + + - name: Fetch main branch fully + run: git fetch origin main --unshallow || true + + - name: Determine merge base with main + id: base + run: | + base=$(git merge-base origin/main HEAD) + echo "base=$base" >> $GITHUB_OUTPUT + + - name: Get changed files compared to base + id: changed + run: | + files=$(git diff --name-only ${{ steps.base.outputs.base }} HEAD | paste -sd ',' -) + echo "files=$files" >> $GITHUB_OUTPUT + + - name: Get code changes summary (additions/deletions) + id: codechange + run: | + stats=$(git diff --shortstat ${{ steps.base.outputs.base }} HEAD) + echo "stats=$stats" >> $GITHUB_OUTPUT + + - name: Install JSCPD + run: npm install -g jscpd + + - name: Run JSCPD on changed files only + run: | + echo "Running on: ${{ steps.changed.outputs.files }}" + files_csv="${{ steps.changed.outputs.files }}" + # Trasforma CSV in array di file e filtra quelli esistenti + files_filtered=$(echo "$files_csv" | tr ',' '\n' | while read f; do + if [ -f "$f" ]; then echo "$f"; fi + done | paste -sd ' ' -) + echo "Filtered files: $files_filtered" + if [ -z "$files_filtered" ]; then + echo "No valid files found to analyze, skipping jscpd" + exit 0 + fi + jscpd $files_filtered --reporters json,markdown --output report + + - name: Run JSCPD on main branch + run: | + git checkout origin/main + jscpd . --output report_main --reporters json + + - name: Return to PR branch + run: git checkout - + + - name: Upload JSCPD Reports + uses: actions/upload-artifact@v4 + with: + name: jscpd-reports + path: | + report + report_main + + - name: Comment on PR with JSCPD report + uses: actions/github-script@v7 + if: success() + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + const fs = require('fs'); + const path = require('path'); + const pr = context.issue.number; + + const COMMENT_MARKER = ''; + const MAX_DUPLICATION = 5; // soglia massima ammessa in % + + const jsonPathDiff = path.join(process.cwd(), 'report', 'jscpd-report.json'); + const jsonPathMain = path.join(process.cwd(), 'report_main', 'jscpd-report.json'); + + let title = '## ✅ Nessuna duplicazione nel diff.\n\n'; + let summaryTable = ''; + let details = ''; + let body = ''; + + let pctDiff = 0, clones = 0; + if (fs.existsSync(jsonPathDiff)) { + const rawDiff = fs.readFileSync(jsonPathDiff, 'utf8'); + const reportDiff = JSON.parse(rawDiff); + const total = reportDiff.statistics.total; + pctDiff = total.percentage; + clones = total.clones; + + if (pctDiff > 0) { + let pctMain = 0; + if (fs.existsSync(jsonPathMain)) { + const rawMain = fs.readFileSync(jsonPathMain, 'utf8'); + const reportMain = JSON.parse(rawMain); + pctMain = reportMain.statistics.total.percentage; + } + + const diffPctChange = pctDiff - pctMain; + const arrow = diffPctChange > 0 ? '📈' : diffPctChange < 0 ? '📉' : '⚖️'; + const changeStr = `(${arrow} ${diffPctChange > 0 ? '+' : ''}${diffPctChange.toFixed(2)}%)`; + + title = `## ⚠️ Duplicazione codice rilevata: ${pctDiff.toFixed(2)}% ${changeStr} in ${clones} blocc${clones !== 1 ? 'hi' : 'o'} duplicat${clones !== 1 ? 'i' : 'o'}\n\n`; + + summaryTable = '| Formato | Files | Linee | Cloni | Righe duplicate (%) |\n' + + '|---|---|---|---|---|\n'; + + for (const fmt in reportDiff.statistics.formats) { + const stat = reportDiff.statistics.formats[fmt].total; + summaryTable += `| ${fmt} | ${stat.sources} | ${stat.lines} | ${stat.clones} | ${stat.duplicatedLines} (${stat.percentage.toFixed(2)}%) |\n`; + } + + summaryTable += `| **Total** | ${total.sources} | ${total.lines} | ${total.clones} | ${total.duplicatedLines} (${total.percentage.toFixed(2)}%) |`; + + details = reportDiff.duplicates.map(d => { + const snippet = d.fragment + ? `\n\`\`\`${d.format}\n${d.fragment.trim()}\n\`\`\`\n` + : ''; + return `- **${d.firstFile.name}** ↔ **${d.secondFile.name}** (Linee ${d.firstFile.start}-${d.firstFile.end} ↔ ${d.secondFile.start}-${d.secondFile.end})${snippet}`; + }).join('\n'); + } + } + + const statsText = `${{ steps.codechange.outputs.stats }}`; + let codeChangeLine = ''; + if (statsText && statsText.trim() !== '') { + const added = statsText.match(/(\d+) insertions?/); + const deleted = statsText.match(/(\d+) deletions?/); + const files = statsText.match(/(\d+) files? changed/); + + const addedCount = added ? parseInt(added[1]) : 0; + const deletedCount = deleted ? parseInt(deleted[1]) : 0; + const filesChanged = files ? parseInt(files[1]) : 0; + + codeChangeLine = `📦 **Modifiche nel diff con \`main\`**: 📝 ${filesChanged} file cambiati, ➕ ${addedCount} righe aggiunte, ➖ ${deletedCount} rimosse `; + + if (addedCount > deletedCount) { + codeChangeLine += '📈'; + } else if (deletedCount > addedCount) { + codeChangeLine += '📉'; + } else { + codeChangeLine += '⚖️'; + } + + body += `${codeChangeLine}\n\n`; + } + + body = `${COMMENT_MARKER}\n${body}${title}`; + if (summaryTable) { + body += `
\n📊 Statistiche sintetiche (per formato)\n\n${summaryTable}\n
\n\n`; + } + if (details) { + body += `
\n📄 Elenco duplicati (espandi per vedere i dettagli)\n\n${details}\n
`; + } + + // Elimina vecchi commenti + const existing = await github.rest.issues.listComments({ + issue_number: pr, + owner: context.repo.owner, + repo: context.repo.repo + }); + for (const c of existing.data) { + if (c.body && c.body.includes(COMMENT_MARKER)) { + await github.rest.issues.deleteComment({ + comment_id: c.id, + owner: context.repo.owner, + repo: context.repo.repo + }); + } + } + + await github.rest.issues.createComment({ + issue_number: pr, + owner: context.repo.owner, + repo: context.repo.repo, + body + }); + + // 🚨 Fallisce se supera la soglia + if (pctDiff > MAX_DUPLICATION) { + core.setFailed(`❌ La duplicazione del codice (${pctDiff.toFixed(2)}%) supera la soglia massima consentita (${MAX_DUPLICATION}%). Fare refactor prima del merge.`); + } diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml new file mode 100644 index 0000000..dca1e50 --- /dev/null +++ b/.github/workflows/push.yml @@ -0,0 +1,45 @@ +name: Test CLI + eslint + +on: + push: + branches: + - '*' + - '*/*' + - '**' + - '!main' + +jobs: + eslint: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + + - name: Setup Node.js + uses: actions/setup-node@v3 + with: + node-version: 20 + + - name: Install dependencies + run: yarn install + + - name: Run Eslint + run: yarn lint + + test-cli: + needs: eslint + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + + - name: Setup Node.js + uses: actions/setup-node@v3 + with: + node-version: 20 + + - name: Install dependencies + run: yarn install + + - name: Run CLI smoke test + run: yarn dev --help \ No newline at end of file diff --git a/eslint.config.mjs b/eslint.config.mjs new file mode 100644 index 0000000..29cc5ab --- /dev/null +++ b/eslint.config.mjs @@ -0,0 +1,37 @@ +import pluginJs from '@eslint/js' +import eslintPluginPrettierRecommended from 'eslint-plugin-prettier/recommended' +import simpleImportSort from 'eslint-plugin-simple-import-sort' +import globals from 'globals' + +export default [ + { + ignores: [ + 'node_modules', + 'package.json', + 'yarn.lock', + 'pnpm-lock.yaml', + 'package-lock.json', + ], + }, + { + files: ['**/*.{js,mjs,cjs,ts,jsx,tsx}'], + }, + { languageOptions: { ecmaVersion: 2020, globals: globals.node } }, + pluginJs.configs.recommended, + eslintPluginPrettierRecommended, + { + plugins: { + 'simple-import-sort': simpleImportSort, + }, + }, + { + rules: { + 'prettier/prettier': 'error', + 'react/react-in-jsx-scope': 'off', + 'no-unused-vars': 'off', + 'no-debugger': 'off', + 'simple-import-sort/imports': 'error', + 'simple-import-sort/exports': 'error', + }, + }, +] diff --git a/locales/en.json b/locales/en.json index 63587ec..d74acbb 100644 --- a/locales/en.json +++ b/locales/en.json @@ -97,6 +97,6 @@ "checkoutFailed": "❌ Failed to switch to branch '{branch}'.", "nothingToPush": "❌ No commits to push.", "pushCancelled": "❌ Push cancelled.", - "pushError": "❌ Errore durante il push: ", + "pushError": "❌ Errore durante il push:", "askForPreCommit": "Select the pre-commit commands to run:" } \ No newline at end of file diff --git a/locales/it.json b/locales/it.json index 678309a..819dde7 100644 --- a/locales/it.json +++ b/locales/it.json @@ -97,6 +97,6 @@ "checkoutFailed": "❌ Impossibile spostarsi sul branch '{branch}'.", "nothingToPush": "❌ Non ci sono commit da pushare.", "pushCancelled": "❌ Push annullato.", - "pushError": "❌ Errore durante il push: ", + "pushError": "❌ Errore durante il push:", "askForPreCommit": "Seleziona i comandi di pre-commit da eseguire:" } \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index f83c1f2..11f97b1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -25,12 +25,172 @@ "gch-init": "bin/init-config.cjs" }, "devDependencies": { - "prettier": "^3.5.3" + "@eslint/js": "^9.30.1", + "eslint": "^9.30.1", + "eslint-config-prettier": "^10.1.5", + "eslint-plugin-prettier": "^5.5.1", + "eslint-plugin-simple-import-sort": "^12.1.1", + "globals": "^16.3.0", + "prettier": "3.6.2" }, "engines": { "node": ">=18.0.0" } }, + "node_modules/@eslint-community/eslint-utils": { + "version": "4.7.0", + "resolved": "https://registry.npmjs.org/@eslint-community/eslint-utils/-/eslint-utils-4.7.0.tgz", + "integrity": "sha512-dyybb3AcajC7uha6CvhdVRJqaKyn7w2YKqKyAN37NKYgZT36w+iRb0Dymmc5qEJ549c/S31cMMSFd75bteCpCw==", + "dev": true, + "license": "MIT", + "dependencies": { + "eslint-visitor-keys": "^3.4.3" + }, + "engines": { + "node": "^12.22.0 || ^14.17.0 || >=16.0.0" + }, + "funding": { + "url": "https://opencollective.com/eslint" + }, + "peerDependencies": { + "eslint": "^6.0.0 || ^7.0.0 || >=8.0.0" + } + }, + "node_modules/@eslint-community/eslint-utils/node_modules/eslint-visitor-keys": { + "version": "3.4.3", + "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-3.4.3.tgz", + "integrity": "sha512-wpc+LXeiyiisxPlEkUzU6svyS1frIO3Mgxj1fdy7Pm8Ygzguax2N3Fa/D/ag1WqbOprdI+uY6wMUl8/a2G+iag==", + "dev": true, + "license": "Apache-2.0", + "engines": { + "node": "^12.22.0 || ^14.17.0 || >=16.0.0" + }, + "funding": { + "url": "https://opencollective.com/eslint" + } + }, + "node_modules/@eslint-community/regexpp": { + "version": "4.12.1", + "resolved": "https://registry.npmjs.org/@eslint-community/regexpp/-/regexpp-4.12.1.tgz", + "integrity": "sha512-CCZCDJuduB9OUkFkY2IgppNZMi2lBQgD2qzwXkEia16cge2pijY/aXi96CJMquDMn3nJdlPV1A5KrJEXwfLNzQ==", + "dev": true, + "license": "MIT", + "engines": { + "node": "^12.0.0 || ^14.0.0 || >=16.0.0" + } + }, + "node_modules/@eslint/config-array": { + "version": "0.21.0", + "resolved": "https://registry.npmjs.org/@eslint/config-array/-/config-array-0.21.0.tgz", + "integrity": "sha512-ENIdc4iLu0d93HeYirvKmrzshzofPw6VkZRKQGe9Nv46ZnWUzcF1xV01dcvEg/1wXUR61OmmlSfyeyO7EvjLxQ==", + "dev": true, + "license": "Apache-2.0", + "dependencies": { + "@eslint/object-schema": "^2.1.6", + "debug": "^4.3.1", + "minimatch": "^3.1.2" + }, + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + } + }, + "node_modules/@eslint/config-helpers": { + "version": "0.3.1", + "resolved": "https://registry.npmjs.org/@eslint/config-helpers/-/config-helpers-0.3.1.tgz", + "integrity": "sha512-xR93k9WhrDYpXHORXpxVL5oHj3Era7wo6k/Wd8/IsQNnZUTzkGS29lyn3nAT05v6ltUuTFVCCYDEGfy2Or/sPA==", + "dev": true, + "license": "Apache-2.0", + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + } + }, + "node_modules/@eslint/core": { + "version": "0.15.2", + "resolved": "https://registry.npmjs.org/@eslint/core/-/core-0.15.2.tgz", + "integrity": "sha512-78Md3/Rrxh83gCxoUc0EiciuOHsIITzLy53m3d9UyiW8y9Dj2D29FeETqyKA+BRK76tnTp6RXWb3pCay8Oyomg==", + "dev": true, + "license": "Apache-2.0", + "dependencies": { + "@types/json-schema": "^7.0.15" + }, + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + } + }, + "node_modules/@eslint/eslintrc": { + "version": "3.3.1", + "resolved": "https://registry.npmjs.org/@eslint/eslintrc/-/eslintrc-3.3.1.tgz", + "integrity": "sha512-gtF186CXhIl1p4pJNGZw8Yc6RlshoePRvE0X91oPGb3vZ8pM3qOS9W9NGPat9LziaBV7XrJWGylNQXkGcnM3IQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "ajv": "^6.12.4", + "debug": "^4.3.2", + "espree": "^10.0.1", + "globals": "^14.0.0", + "ignore": "^5.2.0", + "import-fresh": "^3.2.1", + "js-yaml": "^4.1.0", + "minimatch": "^3.1.2", + "strip-json-comments": "^3.1.1" + }, + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + }, + "funding": { + "url": "https://opencollective.com/eslint" + } + }, + "node_modules/@eslint/eslintrc/node_modules/globals": { + "version": "14.0.0", + "resolved": "https://registry.npmjs.org/globals/-/globals-14.0.0.tgz", + "integrity": "sha512-oahGvuMGQlPw/ivIYBjVSrWAfWLBeku5tpPE2fOPLi+WHffIWbuh2tCjhyQhTBPMf5E9jDEH4FOmTYgYwbKwtQ==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/@eslint/js": { + "version": "9.33.0", + "resolved": "https://registry.npmjs.org/@eslint/js/-/js-9.33.0.tgz", + "integrity": "sha512-5K1/mKhWaMfreBGJTwval43JJmkip0RmM+3+IuqupeSKNC/Th2Kc7ucaq5ovTSra/OOKB9c58CGSz3QMVbWt0A==", + "dev": true, + "license": "MIT", + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + }, + "funding": { + "url": "https://eslint.org/donate" + } + }, + "node_modules/@eslint/object-schema": { + "version": "2.1.6", + "resolved": "https://registry.npmjs.org/@eslint/object-schema/-/object-schema-2.1.6.tgz", + "integrity": "sha512-RBMg5FRL0I0gs51M/guSAj5/e14VQ4tpZnQNWwuDT66P14I43ItmPfIZRhO9fUVIPOAQXU47atlywZ/czoqFPA==", + "dev": true, + "license": "Apache-2.0", + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + } + }, + "node_modules/@eslint/plugin-kit": { + "version": "0.3.5", + "resolved": "https://registry.npmjs.org/@eslint/plugin-kit/-/plugin-kit-0.3.5.tgz", + "integrity": "sha512-Z5kJ+wU3oA7MMIqVR9tyZRtjYPr4OC004Q4Rw7pgOKUOKkJfZ3O24nz3WYfGRpMDNmcOi3TwQOmgm7B7Tpii0w==", + "dev": true, + "license": "Apache-2.0", + "dependencies": { + "@eslint/core": "^0.15.2", + "levn": "^0.4.1" + }, + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + } + }, "node_modules/@google/genai": { "version": "1.8.0", "resolved": "https://registry.npmjs.org/@google/genai/-/genai-1.8.0.tgz", @@ -54,6 +214,72 @@ } } }, + "node_modules/@humanfs/core": { + "version": "0.19.1", + "resolved": "https://registry.npmjs.org/@humanfs/core/-/core-0.19.1.tgz", + "integrity": "sha512-5DyQ4+1JEUzejeK1JGICcideyfUbGixgS9jNgex5nqkW+cY7WZhxBigmieN5Qnw9ZosSNVC9KQKyb+GUaGyKUA==", + "dev": true, + "license": "Apache-2.0", + "engines": { + "node": ">=18.18.0" + } + }, + "node_modules/@humanfs/node": { + "version": "0.16.6", + "resolved": "https://registry.npmjs.org/@humanfs/node/-/node-0.16.6.tgz", + "integrity": "sha512-YuI2ZHQL78Q5HbhDiBA1X4LmYdXCKCMQIfw0pw7piHJwyREFebJUvrQN4cMssyES6x+vfUbx1CIpaQUKYdQZOw==", + "dev": true, + "license": "Apache-2.0", + "dependencies": { + "@humanfs/core": "^0.19.1", + "@humanwhocodes/retry": "^0.3.0" + }, + "engines": { + "node": ">=18.18.0" + } + }, + "node_modules/@humanfs/node/node_modules/@humanwhocodes/retry": { + "version": "0.3.1", + "resolved": "https://registry.npmjs.org/@humanwhocodes/retry/-/retry-0.3.1.tgz", + "integrity": "sha512-JBxkERygn7Bv/GbN5Rv8Ul6LVknS+5Bp6RgDC/O8gEBU/yeH5Ui5C/OlWrTb6qct7LjjfT6Re2NxB0ln0yYybA==", + "dev": true, + "license": "Apache-2.0", + "engines": { + "node": ">=18.18" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/nzakas" + } + }, + "node_modules/@humanwhocodes/module-importer": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/@humanwhocodes/module-importer/-/module-importer-1.0.1.tgz", + "integrity": "sha512-bxveV4V8v5Yb4ncFTT3rPSgZBOpCkjfK0y4oVVVJwIuDVBRMDXrPyXRL988i5ap9m9bnyEEjWfm5WkBmtffLfA==", + "dev": true, + "license": "Apache-2.0", + "engines": { + "node": ">=12.22" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/nzakas" + } + }, + "node_modules/@humanwhocodes/retry": { + "version": "0.4.3", + "resolved": "https://registry.npmjs.org/@humanwhocodes/retry/-/retry-0.4.3.tgz", + "integrity": "sha512-bV0Tgo9K4hfPCek+aMAn81RppFKv2ySDQeMoSZuvTASywNTnVJCArCZE2FWqpvIatKu7VMRLWlR1EazvVhDyhQ==", + "dev": true, + "license": "Apache-2.0", + "engines": { + "node": ">=18.18" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/nzakas" + } + }, "node_modules/@inquirer/checkbox": { "version": "4.1.9", "resolved": "https://registry.npmjs.org/@inquirer/checkbox/-/checkbox-4.1.9.tgz", @@ -474,6 +700,56 @@ "win32" ] }, + "node_modules/@pkgr/core": { + "version": "0.2.9", + "resolved": "https://registry.npmjs.org/@pkgr/core/-/core-0.2.9.tgz", + "integrity": "sha512-QNqXyfVS2wm9hweSYD2O7F0G06uurj9kZ96TRQE5Y9hU7+tgdZwIkbAKc5Ocy1HxEY2kuDQa6cQ1WRs/O5LFKA==", + "dev": true, + "license": "MIT", + "engines": { + "node": "^12.20.0 || ^14.18.0 || >=16.0.0" + }, + "funding": { + "url": "https://opencollective.com/pkgr" + } + }, + "node_modules/@types/estree": { + "version": "1.0.8", + "resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.8.tgz", + "integrity": "sha512-dWHzHa2WqEXI/O1E9OjrocMTKJl2mSrEolh1Iomrv6U+JuNwaHXsXx9bLu5gG7BUWFIN0skIQJQ/L1rIex4X6w==", + "dev": true, + "license": "MIT" + }, + "node_modules/@types/json-schema": { + "version": "7.0.15", + "resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.15.tgz", + "integrity": "sha512-5+fP8P8MFNC+AyZCDxrB2pkZFPGzqQWUzpSeuuVLvm8VMcorNYavBqoFcxK8bQz4Qsbn4oUEEem4wDLfcysGHA==", + "dev": true, + "license": "MIT" + }, + "node_modules/acorn": { + "version": "8.15.0", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.15.0.tgz", + "integrity": "sha512-NZyJarBfL7nWwIq+FDL6Zp/yHEhePMNnnJ0y3qfieCrmNvYct8uvtiV41UvlSe6apAfk0fY1FbWx+NwfmpvtTg==", + "dev": true, + "license": "MIT", + "bin": { + "acorn": "bin/acorn" + }, + "engines": { + "node": ">=0.4.0" + } + }, + "node_modules/acorn-jsx": { + "version": "5.3.2", + "resolved": "https://registry.npmjs.org/acorn-jsx/-/acorn-jsx-5.3.2.tgz", + "integrity": "sha512-rq9s+JNhf0IChjtDXxllJ7g41oZk5SlXtp0LHwyA5cejwn7vKmKp4pPri6YEePv2PU65sAsegbXtIinmDFDXgQ==", + "dev": true, + "license": "MIT", + "peerDependencies": { + "acorn": "^6.0.0 || ^7.0.0 || ^8.0.0" + } + }, "node_modules/agent-base": { "version": "7.1.4", "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-7.1.4.tgz", @@ -483,6 +759,23 @@ "node": ">= 14" } }, + "node_modules/ajv": { + "version": "6.12.6", + "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.6.tgz", + "integrity": "sha512-j3fVLgvTo527anyYyJOGTYJbG+vnnQYvE0m5mmkc1TK+nxAppkCLMIL0aZ4dblVCNoGShhm+kzE4ZUykBoMg4g==", + "dev": true, + "license": "MIT", + "dependencies": { + "fast-deep-equal": "^3.1.1", + "fast-json-stable-stringify": "^2.0.0", + "json-schema-traverse": "^0.4.1", + "uri-js": "^4.2.2" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/epoberezkin" + } + }, "node_modules/ansi-escapes": { "version": "4.3.2", "resolved": "https://registry.npmjs.org/ansi-escapes/-/ansi-escapes-4.3.2.tgz", @@ -522,6 +815,20 @@ "url": "https://github.com/chalk/ansi-styles?sponsor=1" } }, + "node_modules/argparse": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz", + "integrity": "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==", + "dev": true, + "license": "Python-2.0" + }, + "node_modules/balanced-match": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", + "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==", + "dev": true, + "license": "MIT" + }, "node_modules/base64-js": { "version": "1.5.1", "resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.5.1.tgz", @@ -551,12 +858,33 @@ "node": "*" } }, + "node_modules/brace-expansion": { + "version": "1.1.12", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.12.tgz", + "integrity": "sha512-9T9UjW3r0UW5c1Q7GTwllptXwhvYmEzFhzMfZ9H7FQWt+uZePjZPjBP/W1ZEyZ1twGWom5/56TF4lPcqjnDHcg==", + "dev": true, + "license": "MIT", + "dependencies": { + "balanced-match": "^1.0.0", + "concat-map": "0.0.1" + } + }, "node_modules/buffer-equal-constant-time": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/buffer-equal-constant-time/-/buffer-equal-constant-time-1.0.1.tgz", "integrity": "sha512-zRpUiDwd/xk6ADqPMATG8vc9VPrkck7T07OIx0gnjmJAnHnTVXNQG3vfvWNuiZIkwu9KrKdA1iJKfsfTVxE6NA==", "license": "BSD-3-Clause" }, + "node_modules/callsites": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/callsites/-/callsites-3.1.0.tgz", + "integrity": "sha512-P8BjAsXvZS+VIDUI11hHCQEv74YT67YUi5JJFNWIqL235sBmjX4+qx9Muvls5ivyNENctx46xQLQ3aTuE7ssaQ==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=6" + } + }, "node_modules/chalk": { "version": "5.4.1", "resolved": "https://registry.npmjs.org/chalk/-/chalk-5.4.1.tgz", @@ -695,6 +1023,13 @@ "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", "license": "MIT" }, + "node_modules/concat-map": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", + "integrity": "sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==", + "dev": true, + "license": "MIT" + }, "node_modules/cross-spawn": { "version": "7.0.6", "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.6.tgz", @@ -735,6 +1070,13 @@ } } }, + "node_modules/deep-is": { + "version": "0.1.4", + "resolved": "https://registry.npmjs.org/deep-is/-/deep-is-0.1.4.tgz", + "integrity": "sha512-oIPzksmTg4/MriiaYGO+okXDT7ztn/w3Eptv/+gSIdMdKsJo0u4CfYNFJPy+4SKMuCqGw2wxnA+URMg3t8a/bQ==", + "dev": true, + "license": "MIT" + }, "node_modules/ecdsa-sig-formatter": { "version": "1.0.11", "resolved": "https://registry.npmjs.org/ecdsa-sig-formatter/-/ecdsa-sig-formatter-1.0.11.tgz", @@ -759,6 +1101,248 @@ "node": ">=6" } }, + "node_modules/escape-string-regexp": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-4.0.0.tgz", + "integrity": "sha512-TtpcNJ3XAzx3Gq8sWRzJaVajRs0uVxA2YAkdb1jm2YkPz4G6egUFAyA3n5vtEIZefPk5Wa4UXbKuS5fKkJWdgA==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/eslint": { + "version": "9.33.0", + "resolved": "https://registry.npmjs.org/eslint/-/eslint-9.33.0.tgz", + "integrity": "sha512-TS9bTNIryDzStCpJN93aC5VRSW3uTx9sClUn4B87pwiCaJh220otoI0X8mJKr+VcPtniMdN8GKjlwgWGUv5ZKA==", + "dev": true, + "license": "MIT", + "dependencies": { + "@eslint-community/eslint-utils": "^4.2.0", + "@eslint-community/regexpp": "^4.12.1", + "@eslint/config-array": "^0.21.0", + "@eslint/config-helpers": "^0.3.1", + "@eslint/core": "^0.15.2", + "@eslint/eslintrc": "^3.3.1", + "@eslint/js": "9.33.0", + "@eslint/plugin-kit": "^0.3.5", + "@humanfs/node": "^0.16.6", + "@humanwhocodes/module-importer": "^1.0.1", + "@humanwhocodes/retry": "^0.4.2", + "@types/estree": "^1.0.6", + "@types/json-schema": "^7.0.15", + "ajv": "^6.12.4", + "chalk": "^4.0.0", + "cross-spawn": "^7.0.6", + "debug": "^4.3.2", + "escape-string-regexp": "^4.0.0", + "eslint-scope": "^8.4.0", + "eslint-visitor-keys": "^4.2.1", + "espree": "^10.4.0", + "esquery": "^1.5.0", + "esutils": "^2.0.2", + "fast-deep-equal": "^3.1.3", + "file-entry-cache": "^8.0.0", + "find-up": "^5.0.0", + "glob-parent": "^6.0.2", + "ignore": "^5.2.0", + "imurmurhash": "^0.1.4", + "is-glob": "^4.0.0", + "json-stable-stringify-without-jsonify": "^1.0.1", + "lodash.merge": "^4.6.2", + "minimatch": "^3.1.2", + "natural-compare": "^1.4.0", + "optionator": "^0.9.3" + }, + "bin": { + "eslint": "bin/eslint.js" + }, + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + }, + "funding": { + "url": "https://eslint.org/donate" + }, + "peerDependencies": { + "jiti": "*" + }, + "peerDependenciesMeta": { + "jiti": { + "optional": true + } + } + }, + "node_modules/eslint-config-prettier": { + "version": "10.1.8", + "resolved": "https://registry.npmjs.org/eslint-config-prettier/-/eslint-config-prettier-10.1.8.tgz", + "integrity": "sha512-82GZUjRS0p/jganf6q1rEO25VSoHH0hKPCTrgillPjdI/3bgBhAE1QzHrHTizjpRvy6pGAvKjDJtk2pF9NDq8w==", + "dev": true, + "license": "MIT", + "bin": { + "eslint-config-prettier": "bin/cli.js" + }, + "funding": { + "url": "https://opencollective.com/eslint-config-prettier" + }, + "peerDependencies": { + "eslint": ">=7.0.0" + } + }, + "node_modules/eslint-plugin-prettier": { + "version": "5.5.4", + "resolved": "https://registry.npmjs.org/eslint-plugin-prettier/-/eslint-plugin-prettier-5.5.4.tgz", + "integrity": "sha512-swNtI95SToIz05YINMA6Ox5R057IMAmWZ26GqPxusAp1TZzj+IdY9tXNWWD3vkF/wEqydCONcwjTFpxybBqZsg==", + "dev": true, + "license": "MIT", + "dependencies": { + "prettier-linter-helpers": "^1.0.0", + "synckit": "^0.11.7" + }, + "engines": { + "node": "^14.18.0 || >=16.0.0" + }, + "funding": { + "url": "https://opencollective.com/eslint-plugin-prettier" + }, + "peerDependencies": { + "@types/eslint": ">=8.0.0", + "eslint": ">=8.0.0", + "eslint-config-prettier": ">= 7.0.0 <10.0.0 || >=10.1.0", + "prettier": ">=3.0.0" + }, + "peerDependenciesMeta": { + "@types/eslint": { + "optional": true + }, + "eslint-config-prettier": { + "optional": true + } + } + }, + "node_modules/eslint-plugin-simple-import-sort": { + "version": "12.1.1", + "resolved": "https://registry.npmjs.org/eslint-plugin-simple-import-sort/-/eslint-plugin-simple-import-sort-12.1.1.tgz", + "integrity": "sha512-6nuzu4xwQtE3332Uz0to+TxDQYRLTKRESSc2hefVT48Zc8JthmN23Gx9lnYhu0FtkRSL1oxny3kJ2aveVhmOVA==", + "dev": true, + "license": "MIT", + "peerDependencies": { + "eslint": ">=5.0.0" + } + }, + "node_modules/eslint-scope": { + "version": "8.4.0", + "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-8.4.0.tgz", + "integrity": "sha512-sNXOfKCn74rt8RICKMvJS7XKV/Xk9kA7DyJr8mJik3S7Cwgy3qlkkmyS2uQB3jiJg6VNdZd/pDBJu0nvG2NlTg==", + "dev": true, + "license": "BSD-2-Clause", + "dependencies": { + "esrecurse": "^4.3.0", + "estraverse": "^5.2.0" + }, + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + }, + "funding": { + "url": "https://opencollective.com/eslint" + } + }, + "node_modules/eslint-visitor-keys": { + "version": "4.2.1", + "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-4.2.1.tgz", + "integrity": "sha512-Uhdk5sfqcee/9H/rCOJikYz67o0a2Tw2hGRPOG2Y1R2dg7brRe1uG0yaNQDHu+TO/uQPF/5eCapvYSmHUjt7JQ==", + "dev": true, + "license": "Apache-2.0", + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + }, + "funding": { + "url": "https://opencollective.com/eslint" + } + }, + "node_modules/eslint/node_modules/chalk": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", + "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", + "dev": true, + "license": "MIT", + "dependencies": { + "ansi-styles": "^4.1.0", + "supports-color": "^7.1.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/chalk/chalk?sponsor=1" + } + }, + "node_modules/espree": { + "version": "10.4.0", + "resolved": "https://registry.npmjs.org/espree/-/espree-10.4.0.tgz", + "integrity": "sha512-j6PAQ2uUr79PZhBjP5C5fhl8e39FmRnOjsD5lGnWrFU8i2G776tBK7+nP8KuQUTTyAZUwfQqXAgrVH5MbH9CYQ==", + "dev": true, + "license": "BSD-2-Clause", + "dependencies": { + "acorn": "^8.15.0", + "acorn-jsx": "^5.3.2", + "eslint-visitor-keys": "^4.2.1" + }, + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + }, + "funding": { + "url": "https://opencollective.com/eslint" + } + }, + "node_modules/esquery": { + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/esquery/-/esquery-1.6.0.tgz", + "integrity": "sha512-ca9pw9fomFcKPvFLXhBKUK90ZvGibiGOvRJNbjljY7s7uq/5YO4BOzcYtJqExdx99rF6aAcnRxHmcUHcz6sQsg==", + "dev": true, + "license": "BSD-3-Clause", + "dependencies": { + "estraverse": "^5.1.0" + }, + "engines": { + "node": ">=0.10" + } + }, + "node_modules/esrecurse": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/esrecurse/-/esrecurse-4.3.0.tgz", + "integrity": "sha512-KmfKL3b6G+RXvP8N1vr3Tq1kL/oCFgn2NYXEtqP8/L3pKapUA4G8cFVaoF3SU323CD4XypR/ffioHmkti6/Tag==", + "dev": true, + "license": "BSD-2-Clause", + "dependencies": { + "estraverse": "^5.2.0" + }, + "engines": { + "node": ">=4.0" + } + }, + "node_modules/estraverse": { + "version": "5.3.0", + "resolved": "https://registry.npmjs.org/estraverse/-/estraverse-5.3.0.tgz", + "integrity": "sha512-MMdARuVEQziNTeJD8DgMqmhwR11BRQ/cBP+pLtYdSTnf3MIO8fFeiINEbX36ZdNlfU/7A9f3gUw49B3oQsvwBA==", + "dev": true, + "license": "BSD-2-Clause", + "engines": { + "node": ">=4.0" + } + }, + "node_modules/esutils": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/esutils/-/esutils-2.0.3.tgz", + "integrity": "sha512-kVscqXk4OCp68SZ0dkgEKVi6/8ij300KBWTJq32P/dYeWTSwK41WyTxalN1eRmA5Z9UU/LX9D7FWSmV9SAYx6g==", + "dev": true, + "license": "BSD-2-Clause", + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/execa": { "version": "7.2.0", "resolved": "https://registry.npmjs.org/execa/-/execa-7.2.0.tgz", @@ -802,6 +1386,34 @@ "node": ">=4" } }, + "node_modules/fast-deep-equal": { + "version": "3.1.3", + "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz", + "integrity": "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==", + "dev": true, + "license": "MIT" + }, + "node_modules/fast-diff": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/fast-diff/-/fast-diff-1.3.0.tgz", + "integrity": "sha512-VxPP4NqbUjj6MaAOafWeUn2cXWLcCtljklUtZf0Ind4XQ+QPtmA0b18zZy0jIQx+ExRVCR/ZQpBmik5lXshNsw==", + "dev": true, + "license": "Apache-2.0" + }, + "node_modules/fast-json-stable-stringify": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/fast-json-stable-stringify/-/fast-json-stable-stringify-2.1.0.tgz", + "integrity": "sha512-lhd/wF+Lk98HZoTCtlVraHtfh5XYijIjalXck7saUtuanSDyLMxnHhSXEDJqHxD7msR8D0uCmqlkwjCV8xvwHw==", + "dev": true, + "license": "MIT" + }, + "node_modules/fast-levenshtein": { + "version": "2.0.6", + "resolved": "https://registry.npmjs.org/fast-levenshtein/-/fast-levenshtein-2.0.6.tgz", + "integrity": "sha512-DCXu6Ifhqcks7TZKY3Hxp3y6qphY5SJZmrWMDrKcERSOXWQdMhU9Ig/PYrzyw/ul9jOIyh0N4M0tbC5hodg8dw==", + "dev": true, + "license": "MIT" + }, "node_modules/fetch-blob": { "version": "3.2.0", "resolved": "https://registry.npmjs.org/fetch-blob/-/fetch-blob-3.2.0.tgz", @@ -837,6 +1449,57 @@ "node": ">= 0.4.0" } }, + "node_modules/file-entry-cache": { + "version": "8.0.0", + "resolved": "https://registry.npmjs.org/file-entry-cache/-/file-entry-cache-8.0.0.tgz", + "integrity": "sha512-XXTUwCvisa5oacNGRP9SfNtYBNAMi+RPwBFmblZEF7N7swHYQS6/Zfk7SRwx4D5j3CH211YNRco1DEMNVfZCnQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "flat-cache": "^4.0.0" + }, + "engines": { + "node": ">=16.0.0" + } + }, + "node_modules/find-up": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/find-up/-/find-up-5.0.0.tgz", + "integrity": "sha512-78/PXT1wlLLDgTzDs7sjq9hzz0vXD+zn+7wypEe4fXQxCmdmqfGsEPQxmiCSQI3ajFV91bVSsvNtrJRiW6nGng==", + "dev": true, + "license": "MIT", + "dependencies": { + "locate-path": "^6.0.0", + "path-exists": "^4.0.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/flat-cache": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/flat-cache/-/flat-cache-4.0.1.tgz", + "integrity": "sha512-f7ccFPK3SXFHpx15UIGyRJ/FJQctuKZ0zVuN3frBo4HnK3cay9VEW0R6yPYFHC0AgqhukPzKjq22t5DmAyqGyw==", + "dev": true, + "license": "MIT", + "dependencies": { + "flatted": "^3.2.9", + "keyv": "^4.5.4" + }, + "engines": { + "node": ">=16" + } + }, + "node_modules/flatted": { + "version": "3.3.3", + "resolved": "https://registry.npmjs.org/flatted/-/flatted-3.3.3.tgz", + "integrity": "sha512-GX+ysw4PBCz0PzosHDepZGANEuFCMLrnRTiEy9McGjmkCQYwRq4A/X786G/fjM/+OjsWSU1ZrY5qyARZmO/uwg==", + "dev": true, + "license": "ISC" + }, "node_modules/formdata-polyfill": { "version": "4.0.10", "resolved": "https://registry.npmjs.org/formdata-polyfill/-/formdata-polyfill-4.0.10.tgz", @@ -944,6 +1607,32 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/glob-parent": { + "version": "6.0.2", + "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-6.0.2.tgz", + "integrity": "sha512-XxwI8EOhVQgWp6iDL+3b0r86f4d6AX6zSU55HfB4ydCEuXLXc5FcYeOu+nnGftS4TEju/11rt4KJPTMgbfmv4A==", + "dev": true, + "license": "ISC", + "dependencies": { + "is-glob": "^4.0.3" + }, + "engines": { + "node": ">=10.13.0" + } + }, + "node_modules/globals": { + "version": "16.3.0", + "resolved": "https://registry.npmjs.org/globals/-/globals-16.3.0.tgz", + "integrity": "sha512-bqWEnJ1Nt3neqx2q5SFfGS8r/ahumIakg3HcwtNlrVlwXIeNumWn/c7Pn/wKzGhf6SaW6H6uWXLqC30STCMchQ==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/google-auth-library": { "version": "9.15.1", "resolved": "https://registry.npmjs.org/google-auth-library/-/google-auth-library-9.15.1.tgz", @@ -983,6 +1672,16 @@ "node": ">=14.0.0" } }, + "node_modules/has-flag": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", + "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=8" + } + }, "node_modules/https-proxy-agent": { "version": "7.0.6", "resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-7.0.6.tgz", @@ -1017,6 +1716,43 @@ "node": ">=0.10.0" } }, + "node_modules/ignore": { + "version": "5.3.2", + "resolved": "https://registry.npmjs.org/ignore/-/ignore-5.3.2.tgz", + "integrity": "sha512-hsBTNUqQTDwkWtcdYI2i06Y/nUBEsNEDJKjWdigLvegy8kDuJAS8uRlpkkcQpyEXL0Z/pjDy5HBmMjRCJ2gq+g==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">= 4" + } + }, + "node_modules/import-fresh": { + "version": "3.3.1", + "resolved": "https://registry.npmjs.org/import-fresh/-/import-fresh-3.3.1.tgz", + "integrity": "sha512-TR3KfrTZTYLPB6jUjfx6MF9WcWrHL9su5TObK4ZkYgBdWKPOFoSoQIdEuTuR82pmtxH2spWG9h6etwfr1pLBqQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "parent-module": "^1.0.0", + "resolve-from": "^4.0.0" + }, + "engines": { + "node": ">=6" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/imurmurhash": { + "version": "0.1.4", + "resolved": "https://registry.npmjs.org/imurmurhash/-/imurmurhash-0.1.4.tgz", + "integrity": "sha512-JmXMZ6wuvDmLiHEml9ykzqO6lwFbof0GG4IkcGaENdCRDDmMVnny7s5HsIgHCbaq0w2MyPhDqkhTUgS2LU2PHA==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=0.8.19" + } + }, "node_modules/inquirer": { "version": "12.7.0", "resolved": "https://registry.npmjs.org/inquirer/-/inquirer-12.7.0.tgz", @@ -1055,6 +1791,16 @@ "url": "https://github.com/sindresorhus/invert-kv?sponsor=1" } }, + "node_modules/is-extglob": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/is-extglob/-/is-extglob-2.1.1.tgz", + "integrity": "sha512-SbKbANkN603Vi4jEZv49LeVJMn4yGwsbzZworEoyEiutsN3nJYdbO36zfhGJ6QEDpOZIFkDtnq5JRxmvl3jsoQ==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/is-fullwidth-code-point": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz", @@ -1064,6 +1810,19 @@ "node": ">=8" } }, + "node_modules/is-glob": { + "version": "4.0.3", + "resolved": "https://registry.npmjs.org/is-glob/-/is-glob-4.0.3.tgz", + "integrity": "sha512-xelSayHH36ZgE7ZWhli7pW34hNbNl8Ojv5KVmkJD4hBdD3th8Tfk9vYasLM+mXWOZhFkgZfxhLSnrwRr4elSSg==", + "dev": true, + "license": "MIT", + "dependencies": { + "is-extglob": "^2.1.1" + }, + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/is-stream": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/is-stream/-/is-stream-3.0.0.tgz", @@ -1082,6 +1841,19 @@ "integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==", "license": "ISC" }, + "node_modules/js-yaml": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.1.0.tgz", + "integrity": "sha512-wpxZs9NoxZaJESJGIZTyDEaYpl0FKSA+FB9aJiyemKhMwkxQg63h4T1KJgUGHpTqPDNRcmmYLugrRjJlBtWvRA==", + "dev": true, + "license": "MIT", + "dependencies": { + "argparse": "^2.0.1" + }, + "bin": { + "js-yaml": "bin/js-yaml.js" + } + }, "node_modules/json-bigint": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/json-bigint/-/json-bigint-1.0.0.tgz", @@ -1091,6 +1863,27 @@ "bignumber.js": "^9.0.0" } }, + "node_modules/json-buffer": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/json-buffer/-/json-buffer-3.0.1.tgz", + "integrity": "sha512-4bV5BfR2mqfQTJm+V5tPPdf+ZpuhiIvTuAB5g8kcrXOZpTT/QwwVRWBywX1ozr6lEuPdbHxwaJlm9G6mI2sfSQ==", + "dev": true, + "license": "MIT" + }, + "node_modules/json-schema-traverse": { + "version": "0.4.1", + "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz", + "integrity": "sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg==", + "dev": true, + "license": "MIT" + }, + "node_modules/json-stable-stringify-without-jsonify": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/json-stable-stringify-without-jsonify/-/json-stable-stringify-without-jsonify-1.0.1.tgz", + "integrity": "sha512-Bdboy+l7tA3OGW6FjyFHWkP5LuByj1Tk33Ljyq0axyzdk9//JSi2u3fP1QSmd1KNwq6VOKYGlAu87CisVir6Pw==", + "dev": true, + "license": "MIT" + }, "node_modules/jwa": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/jwa/-/jwa-2.0.1.tgz", @@ -1112,6 +1905,16 @@ "safe-buffer": "^5.0.1" } }, + "node_modules/keyv": { + "version": "4.5.4", + "resolved": "https://registry.npmjs.org/keyv/-/keyv-4.5.4.tgz", + "integrity": "sha512-oxVHkHR/EJf2CNXnWxRLW6mg7JyCCUcG0DtEGmL2ctUo1PNTin1PUil+r/+4r5MpVgC/fn1kjsx7mjSujKqIpw==", + "dev": true, + "license": "MIT", + "dependencies": { + "json-buffer": "3.0.1" + } + }, "node_modules/lcid": { "version": "3.1.1", "resolved": "https://registry.npmjs.org/lcid/-/lcid-3.1.1.tgz", @@ -1124,6 +1927,43 @@ "node": ">=8" } }, + "node_modules/levn": { + "version": "0.4.1", + "resolved": "https://registry.npmjs.org/levn/-/levn-0.4.1.tgz", + "integrity": "sha512-+bT2uH4E5LGE7h/n3evcS/sQlJXCpIp6ym8OWJ5eV6+67Dsql/LaaT7qJBAt2rzfoa/5QBGBhxDix1dMt2kQKQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "prelude-ls": "^1.2.1", + "type-check": "~0.4.0" + }, + "engines": { + "node": ">= 0.8.0" + } + }, + "node_modules/locate-path": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-6.0.0.tgz", + "integrity": "sha512-iPZK6eYjbxRu3uB4/WZ3EsEIMJFMqAoopl3R+zuq0UjcAm/MO6KCweDgPfP3elTztoKP3KtnVHxTn2NHBSDVUw==", + "dev": true, + "license": "MIT", + "dependencies": { + "p-locate": "^5.0.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/lodash.merge": { + "version": "4.6.2", + "resolved": "https://registry.npmjs.org/lodash.merge/-/lodash.merge-4.6.2.tgz", + "integrity": "sha512-0KpjqXRVvrYyCsX1swR/XTK0va6VQkQM6MNo7PqW77ByjAhoARA8EfrP1N4+KlKj8YS0ZUCtRT/YUuhyYDujIQ==", + "dev": true, + "license": "MIT" + }, "node_modules/merge-stream": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/merge-stream/-/merge-stream-2.0.0.tgz", @@ -1142,6 +1982,19 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/minimatch": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", + "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==", + "dev": true, + "license": "ISC", + "dependencies": { + "brace-expansion": "^1.1.7" + }, + "engines": { + "node": "*" + } + }, "node_modules/ms": { "version": "2.1.3", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", @@ -1157,6 +2010,13 @@ "node": "^18.17.0 || >=20.5.0" } }, + "node_modules/natural-compare": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/natural-compare/-/natural-compare-1.4.0.tgz", + "integrity": "sha512-OWND8ei3VtNC9h7V60qff3SVobHr996CTwgxubgyQYEpg290h9J0buyECNNJexkFm5sOajh5G116RYA1c8ZMSw==", + "dev": true, + "license": "MIT" + }, "node_modules/node-domexception": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/node-domexception/-/node-domexception-1.0.0.tgz", @@ -1267,6 +2127,24 @@ } } }, + "node_modules/optionator": { + "version": "0.9.4", + "resolved": "https://registry.npmjs.org/optionator/-/optionator-0.9.4.tgz", + "integrity": "sha512-6IpQ7mKUxRcZNLIObR0hz7lxsapSSIYNZJwXPGeF0mTVqGKFIXj1DQcMoT22S3ROcLyY/rz0PWaWZ9ayWmad9g==", + "dev": true, + "license": "MIT", + "dependencies": { + "deep-is": "^0.1.3", + "fast-levenshtein": "^2.0.6", + "levn": "^0.4.1", + "prelude-ls": "^1.2.1", + "type-check": "^0.4.0", + "word-wrap": "^1.2.5" + }, + "engines": { + "node": ">= 0.8.0" + } + }, "node_modules/os-locale": { "version": "6.0.2", "resolved": "https://registry.npmjs.org/os-locale/-/os-locale-6.0.2.tgz", @@ -1317,6 +2195,61 @@ "@oxlint/win32-x64": "1.5.0" } }, + "node_modules/p-limit": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-3.1.0.tgz", + "integrity": "sha512-TYOanM3wGwNGsZN2cVTYPArw454xnXj5qmWF1bEoAc4+cU/ol7GVh7odevjp1FNHduHc3KZMcFduxU5Xc6uJRQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "yocto-queue": "^0.1.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/p-locate": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/p-locate/-/p-locate-5.0.0.tgz", + "integrity": "sha512-LaNjtRWUBY++zB5nE/NwcaoMylSPk+S+ZHNB1TzdbMJMny6dynpAGt7X/tl/QYq3TIeE6nxHppbo2LGymrG5Pw==", + "dev": true, + "license": "MIT", + "dependencies": { + "p-limit": "^3.0.2" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/parent-module": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/parent-module/-/parent-module-1.0.1.tgz", + "integrity": "sha512-GQ2EWRpQV8/o+Aw8YqtfZZPfNRWZYkbidE9k5rpl/hC3vtHHBfGm2Ifi6qWV+coDGkrUKZAxE3Lot5kcsRlh+g==", + "dev": true, + "license": "MIT", + "dependencies": { + "callsites": "^3.0.0" + }, + "engines": { + "node": ">=6" + } + }, + "node_modules/path-exists": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-4.0.0.tgz", + "integrity": "sha512-ak9Qy5Q7jYb2Wwcey5Fpvg2KoAc/ZIhLSLOSBmRmygPsGwkVVt0fZa0qrtMz+m6tJTAHfZQ8FnmB4MG4LWy7/w==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=8" + } + }, "node_modules/path-key": { "version": "3.1.1", "resolved": "https://registry.npmjs.org/path-key/-/path-key-3.1.1.tgz", @@ -1326,6 +2259,16 @@ "node": ">=8" } }, + "node_modules/prelude-ls": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.2.1.tgz", + "integrity": "sha512-vkcDPrRZo1QZLbn5RLGPpg/WmIQ65qoWWhcGKf/b5eplkkarX0m9z8ppCat4mlOqUsWpyNuYgO3VRyrYHSzX5g==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">= 0.8.0" + } + }, "node_modules/prettier": { "version": "3.6.2", "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.6.2.tgz", @@ -1341,6 +2284,39 @@ "url": "https://github.com/prettier/prettier?sponsor=1" } }, + "node_modules/prettier-linter-helpers": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/prettier-linter-helpers/-/prettier-linter-helpers-1.0.0.tgz", + "integrity": "sha512-GbK2cP9nraSSUF9N2XwUwqfzlAFlMNYYl+ShE/V+H8a9uNl/oUqB1w2EL54Jh0OlyRSd8RfWYJ3coVS4TROP2w==", + "dev": true, + "license": "MIT", + "dependencies": { + "fast-diff": "^1.1.2" + }, + "engines": { + "node": ">=6.0.0" + } + }, + "node_modules/punycode": { + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.3.1.tgz", + "integrity": "sha512-vYt7UD1U9Wg6138shLtLOvdAu+8DsC/ilFtEVHcH+wydcSpNE20AfSOduf6MkRFahL5FY7X1oU7nKVZFtfq8Fg==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=6" + } + }, + "node_modules/resolve-from": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/resolve-from/-/resolve-from-4.0.0.tgz", + "integrity": "sha512-pb/MYmXstAkysRFx8piNI1tGFNQIFA3vkE3Gq4EuA1dF6gHp/+vgZqsCGJapvy8N3Q+4o7FwvquPJcnZ7RYy4g==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=4" + } + }, "node_modules/run-async": { "version": "4.0.4", "resolved": "https://registry.npmjs.org/run-async/-/run-async-4.0.4.tgz", @@ -1454,6 +2430,48 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/strip-json-comments": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-3.1.1.tgz", + "integrity": "sha512-6fPc+R4ihwqP6N/aIv2f1gMH8lOVtWQHoqC4yK6oSDVVocumAsfCqjkXnqiYMhmMwS/mEHLp7Vehlt3ql6lEig==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=8" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/supports-color": { + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", + "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==", + "dev": true, + "license": "MIT", + "dependencies": { + "has-flag": "^4.0.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/synckit": { + "version": "0.11.11", + "resolved": "https://registry.npmjs.org/synckit/-/synckit-0.11.11.tgz", + "integrity": "sha512-MeQTA1r0litLUf0Rp/iisCaL8761lKAZHaimlbGK4j0HysC4PLfqygQj9srcs0m2RdtDYnF8UuYyKpbjHYp7Jw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@pkgr/core": "^0.2.9" + }, + "engines": { + "node": "^14.18.0 || >=16.0.0" + }, + "funding": { + "url": "https://opencollective.com/synckit" + } + }, "node_modules/tmp": { "version": "0.0.33", "resolved": "https://registry.npmjs.org/tmp/-/tmp-0.0.33.tgz", @@ -1478,6 +2496,19 @@ "integrity": "sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w==", "license": "0BSD" }, + "node_modules/type-check": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/type-check/-/type-check-0.4.0.tgz", + "integrity": "sha512-XleUoc9uwGXqjWwXaUTZAmzMcFZ5858QA2vvx1Ur5xIcixXIP+8LnFDgRplU30us6teqdlskFfu+ae4K79Ooew==", + "dev": true, + "license": "MIT", + "dependencies": { + "prelude-ls": "^1.2.1" + }, + "engines": { + "node": ">= 0.8.0" + } + }, "node_modules/type-fest": { "version": "0.21.3", "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.21.3.tgz", @@ -1490,6 +2521,16 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/uri-js": { + "version": "4.4.1", + "resolved": "https://registry.npmjs.org/uri-js/-/uri-js-4.4.1.tgz", + "integrity": "sha512-7rKUyy33Q1yc98pQ1DAmLtwX109F7TIfWlW1Ydo8Wl1ii1SeHieeh0HHfPeL2fMXK6z0s8ecKs9frCuLJvndBg==", + "dev": true, + "license": "BSD-2-Clause", + "dependencies": { + "punycode": "^2.1.0" + } + }, "node_modules/uuid": { "version": "9.0.1", "resolved": "https://registry.npmjs.org/uuid/-/uuid-9.0.1.tgz", @@ -1549,6 +2590,16 @@ "node": ">= 8" } }, + "node_modules/word-wrap": { + "version": "1.2.5", + "resolved": "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.5.tgz", + "integrity": "sha512-BN22B5eaMMI9UMtjrGd5g5eCYPpCPDUy0FJXbYsaT5zYxjFOckS53SQDE3pWkVoWpHXVb3BrYcEN4Twa55B5cA==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/wrap-ansi": { "version": "6.2.0", "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-6.2.0.tgz", @@ -1669,6 +2720,19 @@ "url": "https://github.com/chalk/strip-ansi?sponsor=1" } }, + "node_modules/yocto-queue": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/yocto-queue/-/yocto-queue-0.1.0.tgz", + "integrity": "sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/yoctocolors-cjs": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/yoctocolors-cjs/-/yoctocolors-cjs-2.1.2.tgz", diff --git a/package.json b/package.json index 7825537..98037a6 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,10 @@ "init": "node ./bin/init-config.cjs", "setup": "node ./bin/setup.cjs", "dev": "node ./src/index.js", - "format": "prettier --write ." + "lint": "eslint src --max-warnings=10", + "lint:fix": "npm run lint -- --fix", + "format": "npx prettier src --check", + "format:fix": "npm run prettier -- --write" }, "dependencies": { "@google/genai": "^1.8.0", @@ -32,7 +35,13 @@ "yargs": "^18.0.0" }, "devDependencies": { - "prettier": "^3.5.3" + "prettier": "3.6.2", + "@eslint/js": "^9.30.1", + "eslint": "^9.30.1", + "eslint-config-prettier": "^10.1.5", + "eslint-plugin-prettier": "^5.5.1", + "eslint-plugin-simple-import-sort": "^12.1.1", + "globals": "^16.3.0" }, "keywords": [ "git", @@ -50,4 +59,4 @@ "engines": { "node": ">=18.0.0" } -} +} \ No newline at end of file diff --git a/src/ai-provider.js b/src/ai-provider.js index 5674685..f0bd3a3 100644 --- a/src/ai-provider.js +++ b/src/ai-provider.js @@ -1,22 +1,22 @@ +import { typeOfAI } from './config.js' import { - askGeminiForReview, - askGeminiForGeneratedCommitMessage, - askGeminiForCommitBody, askGeminiForBranchName, + askGeminiForCommitBody, + askGeminiForGeneratedCommitMessage, + askGeminiForReview, } from './gemini.js' import { - askOpenaiForReview, - askOpenaiForGeneratedCommitMessage, - askOpenaiForCommitBody, - askOpenaiForBranchName, -} from './openai.js' -import { - askOllamaForReview, - askOllamaForGeneratedCommitMessage, - askOllamaForCommitBody, askOllamaForBranchName, + askOllamaForCommitBody, + askOllamaForGeneratedCommitMessage, + askOllamaForReview, } from './ollama.js' -import { typeOfAI } from './config.js' +import { + askOpenaiForBranchName, + askOpenaiForCommitBody, + askOpenaiForGeneratedCommitMessage, + askOpenaiForReview, +} from './openai.js' export function getAIProvider(config) { const ai = typeOfAI(config) diff --git a/src/config.js b/src/config.js index 95216c0..2f92ae3 100644 --- a/src/config.js +++ b/src/config.js @@ -1,6 +1,7 @@ -import { resolve } from 'path' import { existsSync, readFileSync } from 'fs' import { homedir } from 'os' +import { resolve } from 'path' + import { t } from './i18n.js' // Funzione per caricare la configurazione diff --git a/src/gemini.js b/src/gemini.js index 1f9ab48..8db3d86 100644 --- a/src/gemini.js +++ b/src/gemini.js @@ -1,5 +1,6 @@ import { GoogleGenAI } from '@google/genai' import chalk from 'chalk' + import { getDiff } from './git.js' import { t } from './i18n.js' import { getPrompt as getGenericPrompt } from './prompt-loader.js' @@ -11,7 +12,7 @@ function getPrompt(name) { export async function callGemini(prompt, config) { try { const APPROX_CHARS_PER_TOKEN = 4 - const MAX_INPUT_TOKENS = 900_000 // lasciamo margine all'output + const MAX_INPUT_TOKENS = 900000 // lasciamo margine all'output const maxChars = MAX_INPUT_TOKENS * APPROX_CHARS_PER_TOKEN // ≈ 3.6M caratteri const sliced = prompt.substring(0, maxChars) @@ -19,7 +20,7 @@ export async function callGemini(prompt, config) { const response = await ai.models.generateContent({ model: config.geminiModel || 'gemini-2.5-flash', // Default to gemini-2.5-flash if not specified contents: sliced, - maxOutputTokens: 60_000, + maxOutputTokens: 60000, config: { thinkingConfig: { thinkingBudget: 0, // Disables thinking @@ -76,6 +77,7 @@ export async function askGeminiForCommitBody(config) { export async function askGeminiForBranchName(config) { const diff = getDiff(false) // Get unstaged changes if (!diff) { + console.log('No changes detected for branch name suggestion.') return null } const branchPromptTemplate = getPrompt('branch') diff --git a/src/git.js b/src/git.js index b04a374..60aa861 100644 --- a/src/git.js +++ b/src/git.js @@ -1,12 +1,12 @@ -import { execSync } from 'child_process' import chalk from 'chalk' -import inquirer from 'inquirer' +import { execSync } from 'child_process' import fs from 'fs' -import path from 'path' +import inquirer from 'inquirer' import os from 'os' -import { t } from './i18n.js' -import { askGeminiForBranchName } from './gemini.js' +import path from 'path' +import { askGeminiForBranchName } from './gemini.js' +import { t } from './i18n.js' export function getDiff(cached = true) { try { @@ -22,20 +22,29 @@ export function getModifiedFiles() { try { // Unstage all files to get a clean slate, ignoring errors if nothing is staged try { - execSync('git restore --staged .'); + execSync('git restore --staged .') } catch (error) { // Ignore errors, as this command can fail if the staging area is empty } - const deleted = execSync('git ls-files --deleted').toString().trim().split('\n'); - const modified = execSync('git ls-files --modified').toString().trim().split('\n'); - const others = execSync('git ls-files --others --exclude-standard').toString().trim().split('\n'); - - const allFiles = [...deleted, ...modified, ...others].filter(Boolean); - return [...new Set(allFiles)]; // Remove duplicates + const deleted = execSync('git ls-files --deleted') + .toString() + .trim() + .split('\n') + const modified = execSync('git ls-files --modified') + .toString() + .trim() + .split('\n') + const others = execSync('git ls-files --others --exclude-standard') + .toString() + .trim() + .split('\n') + + const allFiles = [...deleted, ...modified, ...others].filter(Boolean) + return [...new Set(allFiles)] // Remove duplicates } catch (error) { console.error(chalk.red(t('getDiffError')), error.message) - return []; + return [] } } @@ -53,12 +62,12 @@ export function getDiffForFiles(files) { } export function getLocalBranches() { - try { - return execSync('git branch').toString() - } catch (error) { - console.error(chalk.red('Error fetching local branches:'), error.message); - return null; - } + try { + return execSync('git branch').toString() + } catch (error) { + console.error(chalk.red('Error fetching local branches:'), error.message) + return null + } } export function getCurrentBranch() { @@ -70,17 +79,20 @@ export function getCurrentBranch() { } } -export async function checkBranchAndMaybeCreateNew(config, autoConfirm = false) { +export async function checkBranchAndMaybeCreateNew( + config, + autoConfirm = false +) { const forbiddenBranches = ['main', 'master', 'dev'] const currentBranch = getCurrentBranch() if (forbiddenBranches.includes(currentBranch)) { console.log(chalk.red(t('protectedBranch', { branch: currentBranch }))) - const branches = getLocalBranches(); + const branches = getLocalBranches() if (branches) { - console.log(chalk.blue('Local branches:')); - console.log(branches); + console.log(chalk.blue('Local branches:')) + console.log(branches) } const suggestedBranchName = await askGeminiForBranchName(config) @@ -111,8 +123,7 @@ export async function checkBranchAndMaybeCreateNew(config, autoConfirm = false) name: 'newBranchName', message: t('newBranchName'), default: suggestedBranchName, - validate: (input) => - /^[\w\/-]+$/.test(input) || t('invalidBranchName'), + validate: (input) => /^[\w/-]+$/.test(input) || t('invalidBranchName'), }, ]) @@ -167,79 +178,83 @@ export function push(branch) { export function getLatestLogs() { try { - return execSync('git log -n 5 --pretty=format:"%h - %an, %ar : %s"').toString(); + return execSync( + 'git log -n 5 --pretty=format:"%h - %an, %ar : %s"' + ).toString() } catch (error) { - console.error(chalk.red('Error fetching git logs:'), error.message); - return null; + console.error(chalk.red('Error fetching git logs:'), error.message) + return null } } export function getBranchGraph() { try { - return execSync('git log --all --decorate --oneline --graph --color').toString(); + return execSync( + 'git log --all --decorate --oneline --graph --color' + ).toString() } catch (error) { - console.error(chalk.red('Error fetching git graph:'), error.message); - return null; + console.error(chalk.red('Error fetching git graph:'), error.message) + return null } } export function rebase(branch) { try { - execSync(`git rebase ${branch}`, { stdio: 'inherit' }); - console.log(chalk.green(t('rebaseSuccess', { branch }))); + execSync(`git rebase ${branch}`, { stdio: 'inherit' }) + console.log(chalk.green(t('rebaseSuccess', { branch }))) } catch (error) { - console.error(chalk.red(t('rebaseFailed', { branch })), error.message); - process.exit(1); + console.error(chalk.red(t('rebaseFailed', { branch })), error.message) + process.exit(1) } } export function isLastCommitPushed() { - try { - const localHead = execSync('git rev-parse HEAD').toString().trim(); - const remoteHead = execSync('git rev-parse @{u}').toString().trim(); - return localHead === remoteHead; - } catch (error) { - // This will fail if the upstream branch is not set, which means the commit can't have been pushed. - return false; - } + try { + const localHead = execSync('git rev-parse HEAD').toString().trim() + const remoteHead = execSync('git rev-parse @{u}').toString().trim() + return localHead === remoteHead + } catch (error) { + // This will fail if the upstream branch is not set, which means the commit can't have been pushed. + return false + } } export function undoLastCommit() { - try { - execSync('git reset HEAD~1', { stdio: 'inherit' }); - console.log(chalk.green(t('undoSuccess'))); - } catch (error) { - console.error(chalk.red(t('undoFailed')), error.message); - process.exit(1); - } + try { + execSync('git reset HEAD~1', { stdio: 'inherit' }) + console.log(chalk.green(t('undoSuccess'))) + } catch (error) { + console.error(chalk.red(t('undoFailed')), error.message) + process.exit(1) + } } export function checkoutBranch(branch) { - try { - execSync(`git checkout ${branch}`, { stdio: 'inherit' }); - console.log(chalk.green(t('checkoutSuccess', { branch }))); - } catch (error) { - console.error(chalk.red(t('checkoutFailed', { branch })), error.message); - process.exit(1); - } + try { + execSync(`git checkout ${branch}`, { stdio: 'inherit' }) + console.log(chalk.green(t('checkoutSuccess', { branch }))) + } catch (error) { + console.error(chalk.red(t('checkoutFailed', { branch })), error.message) + process.exit(1) + } } export function hasCommitsToPush() { try { const branch = execSync('git rev-parse --abbrev-ref HEAD', { encoding: 'utf-8', - }).trim(); + }).trim() const count = parseInt( execSync(`git rev-list --count origin/${branch}..${branch}`, { encoding: 'utf-8', }).trim(), 10 - ); + ) - return count > 0; + return count > 0 } catch (error) { - console.error(chalk.red(t('pushError', { branch })), error.message) - return false; + console.error(chalk.red(t('pushError')), error.message) + return false } } diff --git a/src/i18n.js b/src/i18n.js index 3d6b9d7..4da7970 100644 --- a/src/i18n.js +++ b/src/i18n.js @@ -1,7 +1,7 @@ -import { readFileSync, existsSync } from 'fs' -import { resolve, dirname } from 'path' -import { fileURLToPath } from 'url' +import { existsSync, readFileSync } from 'fs' import { osLocaleSync } from 'os-locale' +import { dirname, resolve } from 'path' +import { fileURLToPath } from 'url' const __filename = fileURLToPath(import.meta.url) const __dirname = dirname(__filename) diff --git a/src/index.js b/src/index.js index 6993b2a..491f794 100644 --- a/src/index.js +++ b/src/index.js @@ -1,7 +1,7 @@ #!/usr/bin/env node -import { main } from './main.js'; +import { main } from './main.js' main(process.argv).catch((error) => { - console.error("An unexpected error occurred:", error.message); - process.exit(1); -}); + console.error('An unexpected error occurred:', error.message) + process.exit(1) +}) diff --git a/src/main.js b/src/main.js index c9be987..9b5e722 100644 --- a/src/main.js +++ b/src/main.js @@ -1,43 +1,45 @@ +import chalk from 'chalk' +import { execSync } from 'child_process' import yargs from 'yargs' import { hideBin } from 'yargs/helpers' -import { execSync } from 'child_process' + +import { getAIProvider } from './ai-provider.js' import { loadConfig, typeOfAI } from './config.js' import { - getModifiedFiles, checkBranchAndMaybeCreateNew, - stageFiles, + checkoutBranch, commit, - push, + getBranchGraph, getCurrentBranch, getDiffForFiles, getLatestLogs, - getBranchGraph, - rebase, getLocalBranches, + getModifiedFiles, + hasCommitsToPush, isLastCommitPushed, + push, + rebase, + stageFiles, undoLastCommit, - checkoutBranch, - hasCommitsToPush, } from './git.js' -import { getAIProvider } from './ai-provider.js' +import { t } from './i18n.js' +import { translateIfNeeded } from './translator.js' import { - printTitle, - selectFilesToStage, - confirmReview, - printMessage, - printError, - confirmProceed, - getEditedCommitMessage, - validateMessage, confirmCommit, - confirmPush, confirmGenerateBody, + confirmProceed, + confirmPush, + confirmReview, + confirmRunPreCommit, + getEditedCommitMessage, + printError, + printMessage, + printTitle, selectBranchForRebase, selectBranchToCheckout, - confirmRunPreCommit, + selectFilesToStage, + validateMessage, } from './ui.js' -import { t } from './i18n.js' -import { translateIfNeeded } from './translator.js' // Helper function to initialize configuration async function initialize(printHeader = true) { diff --git a/src/ollama.js b/src/ollama.js index c99dbad..809973d 100644 --- a/src/ollama.js +++ b/src/ollama.js @@ -1,5 +1,6 @@ import chalk from 'chalk' import ollama from 'ollama' + import { getDiff } from './git.js' import { t } from './i18n.js' import { getPrompt as getGenericPrompt } from './prompt-loader.js' @@ -11,7 +12,7 @@ function getPrompt(name) { export async function callOllama(prompt, config) { try { const APPROX_CHARS_PER_TOKEN = 4 - const MAX_INPUT_TOKENS = 900_000 // lasciamo margine all'output + const MAX_INPUT_TOKENS = 900000 // lasciamo margine all'output const maxChars = MAX_INPUT_TOKENS * APPROX_CHARS_PER_TOKEN // ≈ 3.6M caratteri const sliced = prompt.substring(0, maxChars) @@ -20,10 +21,10 @@ export async function callOllama(prompt, config) { } const result = await ollama .generate({ - model: config.ollamaModel || 'codellama', - prompt: sliced, - stream: false, - }) + model: config.ollamaModel || 'codellama', + prompt: sliced, + stream: false, + }) .catch((error) => { console.error(error) console.error( diff --git a/src/openai.js b/src/openai.js index 686b836..1b632ac 100644 --- a/src/openai.js +++ b/src/openai.js @@ -1,5 +1,6 @@ -import OpenAI from 'openai' import chalk from 'chalk' +import OpenAI from 'openai' + import { getDiff } from './git.js' import { t } from './i18n.js' import { getPrompt as getGenericPrompt } from './prompt-loader.js' @@ -11,7 +12,7 @@ function getPrompt(name) { export async function callOpenai(prompt, config) { try { const APPROX_CHARS_PER_TOKEN = 4 - const MAX_INPUT_TOKENS = 900_000 // lasciamo margine all'output + const MAX_INPUT_TOKENS = 900000 // lasciamo margine all'output const maxChars = MAX_INPUT_TOKENS * APPROX_CHARS_PER_TOKEN // ≈ 3.6M caratteri const sliced = prompt.substring(0, maxChars) diff --git a/src/prompt-loader.js b/src/prompt-loader.js index bb36932..73b08ba 100644 --- a/src/prompt-loader.js +++ b/src/prompt-loader.js @@ -1,6 +1,6 @@ import fs from 'fs' +import { dirname, resolve } from 'path' import { fileURLToPath } from 'url' -import { resolve, dirname } from 'path' const __filename = fileURLToPath(import.meta.url) const __dirname = dirname(__filename) @@ -14,9 +14,6 @@ export function getPrompt(providerName, promptName) { return fs.readFileSync(promptPath, 'utf-8') } // Fallback to gemini if the provider-specific prompt doesn't exist - const fallbackPath = resolve( - __dirname, - `../prompts/gemini/${promptName}.txt` - ) + const fallbackPath = resolve(__dirname, `../prompts/gemini/${promptName}.txt`) return fs.readFileSync(fallbackPath, 'utf-8') } diff --git a/src/translator.js b/src/translator.js index 1dc0197..20c1975 100644 --- a/src/translator.js +++ b/src/translator.js @@ -1,8 +1,8 @@ -import { getLocale } from './i18n.js' import { typeOfAI } from './config.js' import { callGemini } from './gemini.js' -import { callOpenai } from './openai.js' +import { getLocale } from './i18n.js' import { callOllama } from './ollama.js' +import { callOpenai } from './openai.js' import { getPrompt } from './prompt-loader.js' async function translate(text, config) { diff --git a/src/ui.js b/src/ui.js index da25196..d2b952e 100644 --- a/src/ui.js +++ b/src/ui.js @@ -1,8 +1,9 @@ -import inquirer from 'inquirer' import chalk from 'chalk' import figlet from 'figlet' -import { t } from './i18n.js' +import inquirer from 'inquirer' + import { COMMIT_TYPES } from './config.js' +import { t } from './i18n.js' export function printTitle() { const asciiTitle = figlet.textSync(t('mainTitle'), { @@ -67,12 +68,12 @@ export function validateMessage(msg, config) { export async function selectFilesToStage(modifiedFiles, autoConfirm = false) { if (autoConfirm) { - console.log(chalk.blue(t('filesSelected', { count: modifiedFiles.length }))); - return modifiedFiles; + console.log(chalk.blue(t('filesSelected', { count: modifiedFiles.length }))) + return modifiedFiles } if (modifiedFiles.length === 1) { - console.log(chalk.blue(t('fileModified', { file: modifiedFiles[0] }))); - return modifiedFiles; + console.log(chalk.blue(t('fileModified', { file: modifiedFiles[0] }))) + return modifiedFiles } console.log( @@ -81,7 +82,7 @@ export async function selectFilesToStage(modifiedFiles, autoConfirm = false) { count: modifiedFiles.length, }) ) - ); + ) const { selectedFiles } = await inquirer.prompt([ { @@ -93,9 +94,9 @@ export async function selectFilesToStage(modifiedFiles, autoConfirm = false) { checked: true, })), }, - ]); + ]) - return selectedFiles; + return selectedFiles } export async function confirmReview(aiProviderName, autoConfirm = false) { @@ -215,36 +216,36 @@ export function printError(msg) { } export async function selectBranchForRebase(branches) { - const { branch } = await inquirer.prompt([ - { - type: 'list', - name: 'branch', - message: t('selectBranchForRebase'), - choices: branches, - }, - ]); - return branch; + const { branch } = await inquirer.prompt([ + { + type: 'list', + name: 'branch', + message: t('selectBranchForRebase'), + choices: branches, + }, + ]) + return branch } export async function selectBranchToCheckout(branches) { - const { branch } = await inquirer.prompt([ - { - type: 'list', - name: 'branch', - message: t('selectBranchToCheckout'), - choices: branches, - }, - ]); - return branch; + const { branch } = await inquirer.prompt([ + { + type: 'list', + name: 'branch', + message: t('selectBranchToCheckout'), + choices: branches, + }, + ]) + return branch } export async function confirmRunPreCommit(commands, autoConfirm = false) { - if (autoConfirm) return commands; + if (autoConfirm) return commands const { selectedCommands } = await inquirer.prompt({ type: 'checkbox', name: 'selectedCommands', message: t('askForPreCommit'), - choices: commands.map(cmd => ({ name: cmd, checked: true })), - }); - return selectedCommands; + choices: commands.map((cmd) => ({ name: cmd, checked: true })), + }) + return selectedCommands }