forked from AllAlgorithms/java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidate.js
More file actions
42 lines (35 loc) · 959 Bytes
/
Copy pathvalidate.js
File metadata and controls
42 lines (35 loc) · 959 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/**
* validate.js
*
* The All ▲lgorithms validator CLI
*
* Author: Carlos Abraham Hernandez
* https://abranhe.com (abraham@abranhe.com)
*/
'use strict';
const glob = require('glob');
const path = require('path');
const camelCase = require('camelcase');
const chalk = require('chalk');
const getFiles = (src, callback) => glob(src + '/**', callback);
getFiles('../', (err, res) => {
if (err) {
console.log('Error', err);
}
let invalid = false;
res.map((file) => {
// Accept only valid Java Files
if (path.extname(file) !== '.java') {
return;
}
if (path.basename(file, '.java') !== camelCase(path.basename(file, '.java'), { pascalCase: true })) {
console.log(`${chalk.red(path.basename(file))} does not follow the correct style.`);
invalid = true;
} else {
console.log(`${chalk.green(path.basename(file))} is ok.`);
}
});
if (invalid) {
throw new TypeError(`Expected the All ▲lgorithms structure.`);
}
});