|
| 1 | +const path = require('path'); |
| 2 | +const { Commander } = require('algorithm-visualizer'); |
| 3 | +const { rootDir } = require('../constants'); |
| 4 | +const { signale } = require('../utils'); |
| 5 | +const { MAX_STEPS } = require('../constants'); |
| 6 | + |
| 7 | +module.exports = (category, algorithm, file, content) => { |
| 8 | + const errors = []; |
| 9 | + const error = message => errors.push(message); |
| 10 | + const warns = []; |
| 11 | + const warn = message => warns.push(message); |
| 12 | + |
| 13 | + try { |
| 14 | + Commander.init(); |
| 15 | + require(path.resolve(rootDir, category, algorithm, file)); |
| 16 | + } catch (e) { |
| 17 | + error(e); |
| 18 | + } |
| 19 | + const steps = Commander.commands.filter(command => command.method === 'delay').length; |
| 20 | + if (steps > MAX_STEPS) { |
| 21 | + warn('Too many steps.'); |
| 22 | + } |
| 23 | + if (!/\/\/ import visualization libraries {/.test(content)) { |
| 24 | + error('Missing the code folding for importing visualization libraries.'); |
| 25 | + } |
| 26 | + if (!/\/\/ define tracer variables {/.test(content)) { |
| 27 | + error('Missing the code folding for defining tracer variables.'); |
| 28 | + } |
| 29 | + if (!/\/\/ visualize {/.test(content)) { |
| 30 | + error('Missing the code folding for visualizing.'); |
| 31 | + } |
| 32 | + |
| 33 | + if (errors.length || warns.length) { |
| 34 | + signale.log(`${category}/${algorithm}/${file}`); |
| 35 | + warns.forEach(error => signale.warn(error)); |
| 36 | + errors.forEach(error => signale.error(error)); |
| 37 | + signale.log(); |
| 38 | + } |
| 39 | + return errors.length === 0; |
| 40 | +}; |
0 commit comments