62 lines
1.6 KiB
JavaScript
62 lines
1.6 KiB
JavaScript
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(); |