This commit is contained in:
2026-02-19 02:14:33 +01:00
commit 4f1c803b81
18 changed files with 5778 additions and 0 deletions

62
exam/zip.js Normal file
View File

@@ -0,0 +1,62 @@
import fs from 'fs';
import path from 'path';
import { installDeps } from './common.js';
import packageJson from '../package.json' with { type: 'json' };
async function main() {
installDeps();
const prompts = await import('prompts');
console.log(`Lets create a zip archive for your submission.`);
const { studentId } = await prompts.default({
type: 'text',
name: 'studentId',
message: 'What is your student ID?',
format: (value) => value.trim().replace(/[^A-Za-z0-9]/g, ''),
});
if (!studentId) {
console.error('Student ID is required');
process.exit(1);
}
const parentDirectory = process.cwd();
const archiveName = `${packageJson.name}-${studentId}.zip`;
const zipPath = path.join(parentDirectory, archiveName);
if (fs.existsSync(zipPath)) {
console.log(`Removing existing archive at ${zipPath}`);
fs.unlinkSync(zipPath);
}
const archiver = await import('archiver');
const archive = archiver.default('zip');
archive.on('error', (err) => {
console.error(err);
throw err;
});
archive.glob('**/*', {
cwd: parentDirectory,
ignore: [
'node_modules/**',
'.git/**',
'artifacts/**',
'cache/**',
'.env',
'.DS_Store',
'*.zip',
'exam/common.js',
'exam/exam.js',
'exam/index.html',
'exam/zip.js'
]
});
archive.pipe(fs.createWriteStream(zipPath));
await archive.finalize();
console.log();
console.log(`Archive created: ${zipPath}`);
}
main();