Last active
June 9, 2024 13:37
-
-
Save NerOcrO/51f0d11d772de01fc9bc019b06af0595 to your computer and use it in GitHub Desktop.
tampermonkey
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Vérifier la bonne configuration d'un projet JavaScript | |
// @namespace http://tampermonkey.net/ | |
// @version 2024-06-09 | |
// @description Vérifier la bonne configuration d'un projet JavaScript | |
// @match https://github.com/inclusion-numerique/* | |
// @match https://github.com/anct-cnum/* | |
// @grant GM_xmlhttpRequest | |
// @connect raw.githubusercontent.com | |
// ==/UserScript== | |
(function () { | |
// https://www.tampermonkey.net/documentation.php?locale=en | |
const repos = [ | |
'inclusion-numerique/inclusion-numerique', | |
'anct-cnum/suite-gestionnaire-numerique', | |
'anct-cnum/api-admin-conseillers-numerique', | |
'anct-cnum/dashboard', | |
'anct-cnum/api-conseiller-numerique', | |
'anct-cnum/site-vitrine', | |
'anct-cnum/portail-conseiller', | |
'anct-cnum/portail-candidat', | |
]; | |
const nodes = []; | |
const style = document.createElement('style'); | |
style.innerHTML = ` | |
.nerocro-highlight { | |
border: 1px solid red !important; | |
} | |
`; | |
document.head.appendChild(style); | |
for (const repo of repos) { | |
if (location.href === `https://github.com/${repo}`) { | |
GM_xmlhttpRequest({ | |
method: 'GET', | |
url: `https://raw.githubusercontent.com/${repo}/main/package.json`, | |
headers: { | |
'Content-Type': 'application/json', | |
}, | |
onload(response) { | |
const { engines } = JSON.parse(response.response); | |
if (engines === undefined) { | |
console.error('Il manque la version de node dans package.json'); | |
} else { | |
console.log(`Version de Node : ${engines.node}`); | |
// TODO: proposer la dernière version LTS | |
} | |
}, | |
}); | |
const license = document.querySelector('.Layout-sidebar .octicon-law'); | |
if (license) { | |
const licenseLabel = license.parentElement.innerText.trim(); | |
if (licenseLabel === 'View license') { | |
console.error('La licence n’est pas claire'); | |
nodes.push(license); | |
} else { | |
console.log(`La licence ${licenseLabel} est présente`); | |
} | |
} else { | |
console.error('Une licence n’est pas présente'); | |
} | |
let hasNvmrc = false; | |
document.querySelectorAll('.react-directory-row a').forEach((link) => { | |
if (link.innerText === 'pnpm-lock.yaml') { | |
console.error('La package manager est pnpm, il faut utiliser yarn'); | |
nodes.push(link); | |
} else if (link.innerText === 'package-lock.json') { | |
console.error('La package manager est npm, il faut utiliser yarn'); | |
nodes.push(link); | |
} else if (link.innerText === 'yarn.lock') { | |
console.log('La package manager est yarn'); | |
} | |
if (link.innerText.includes('jest.config.')) { | |
console.error( | |
'Le framework de test est Jest, il faut utiliser Vitest', | |
); | |
nodes.push(link); | |
} else if (link.innerText.includes('vitest.config.')) { | |
console.log('Le framework de test est Vitest'); | |
} | |
if (link.innerText === '.nvmrc') { | |
hasNvmrc = true; | |
} | |
if (link.innerText === '.editorconfig') { | |
console.error( | |
'Le fichier .editorconfig est présent, il faut l’effacer', | |
); | |
nodes.push(link); | |
} | |
}); | |
if (hasNvmrc) { | |
console.log('Le fichier .nvmrc est présent'); | |
} else { | |
console.error('Le fichier .nvmrc n’est pas présent'); | |
} | |
nodes.forEach((node) => { | |
node.classList.add('nerocro-highlight'); | |
}); | |
} | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment