-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
49 lines (42 loc) · 1.36 KB
/
index.js
File metadata and controls
49 lines (42 loc) · 1.36 KB
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
43
44
45
46
47
48
49
'use strict'
const fs = require('fs');
const path = require('path');
const validateWebpackConfig = require('./webpack-validator')
const program = require('commander');
const chalk = require('chalk');
let configFile;
program
.version('0.0.1')
.arguments('[configFileName]')
.action(function (configFileName) {
configFile = configFileName
});
program.parse(process.argv);
if (configFile) {
const fileExtension = path.extname(configFile)
if (! fileExtension) {
configFile = configFile + '.js'
}
}
const fileToRead = configFile || 'webpack.config.js'
console.log('Reading: ' + fileToRead)
const config = require(path.join(process.cwd(), fileToRead))
//console.log(config);
const result = validateWebpackConfig(config);
const problemCount = result.warnings + result.errors;
if (problemCount) {
console.log(chalk.red(`${problemCount} problems for "${fileToRead}": (${result.errors} errors, ${result.warnings} warnings)`))
} else {
console.log(chalk.green(`Validation for ${fileToRead} didnot find any problems :-)`));
}
// try {
// const config = require(path.join(process.cwd(), fileToRead))
// //const data = fs.readFileSync(path.join(process.cwd(), fileToRead));
// validateWebpackConfig(data.toString());
// console.log(config);
// } catch(e) {
// if (e.code === 'ENOENT') {
// console.log('File not found!');
// console.log(e);
// }
// }