Initial commit

This commit is contained in:
2026-03-05 16:08:09 +01:00
commit e775333bfe
28 changed files with 7579 additions and 0 deletions

48
exam/common.js Normal file
View File

@@ -0,0 +1,48 @@
import fs from 'fs';
import path from 'path';
import { exec, execSync } from 'child_process';
import { promisify } from 'util';
const execPromise = promisify(exec);
export function installDeps() {
let parentDirectory = process.cwd();
if (parentDirectory.includes('exam') && !fs.existsSync(path.join(parentDirectory, 'exam'))) {
parentDirectory = path.join(parentDirectory, '..');
}
const examDirectory = path.join(parentDirectory, 'exam');
// install starter/exam dependencies
if (!fs.existsSync(path.join(examDirectory, 'node_modules'))) {
console.log('Installing starter dependencies...');
execSync('npm install', { stdio: 'inherit', cwd: examDirectory });
console.log('Starter dependencies installed');
}
// install dev dependencies
if (!fs.existsSync(path.join(parentDirectory, 'node_modules'))) {
// install dev dependencies (in the background)
console.log(); console.log(); console.log();
console.log('Installing dev dependencies...');
installDevDeps(parentDirectory);
}
}
async function installDevDeps(workingDirectory, attempt = 1) {
try {
await execPromise('npm install', { stdio: 'inherit', cwd: workingDirectory });
console.log('Dev dependencies installed');
} catch (error) {
console.error('Error installing dev dependencies:', error.message);
if (attempt < 3) {
const retryDelay = 5000 * attempt;
console.log(`Retrying in ${Math.round(retryDelay / 1000)} seconds...`);
setTimeout(() => installDevDeps(workingDirectory, attempt + 1), retryDelay);
} else {
console.error('Failed to install dev dependencies.');
console.error('Please try again manually, by running "npm install" in the project directory.');
}
}
}