dce-dev-wizard
Version:
Wizard for managing development apps at Harvard DCE.
49 lines (38 loc) • 1.73 kB
text/typescript
import path from 'path';
// Import shared helpers
import print from './helpers/print';
import exec from './helpers/exec';
import getPackageJSON from './helpers/getPackageJSON';
// Get current working directory
const wizardPackageJSON = getPackageJSON(path.join(__dirname, '../package.json'));
/*----------------------------------------*/
/* ---------------- Main ---------------- */
/*----------------------------------------*/
/**
* Validate that the user is running the most up-to-date version of the dev wizard
* @author Gabe Abrams
*/
const validateWizardVersion = () => {
const passValidation = ['1', 'true', 'yes', 'on'].includes((process.env.PASS_WIZARD_VERSION_VALIDATION || '').toLowerCase());
// Get latest wizard version
const latestWizardVersionString = exec(`npm view dce-dev-wizard versions --json | jq -r '.[] | select(test("-beta") | not)' | sort -rV | head -n 1`);
const latestWizardVersion = latestWizardVersionString.trim();
// Get current wizard version
const currentWizardVersion = wizardPackageJSON.version;
// If versions don't match, show warning
if (latestWizardVersion !== currentWizardVersion) {
print.title('Wizard Out of Date');
console.log('');
console.error(`You are running version ${currentWizardVersion} of the dev wizard.`);
console.error(`The latest version of the dev wizard is ${latestWizardVersion}.`);
console.log('');
if (passValidation) {
console.log('PASS_WIZARD_VERSION_VALIDATION is set; skipping version enforcement.');
return;
}
console.log('Upgrade and try again:');
console.log(`npm i --save-dev dce-dev-wizard@${latestWizardVersion}`);
process.exit(0);
}
};
export default validateWizardVersion;