/
utils.js
48 lines (37 loc) 路 982 Bytes
/
utils.js
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
"use strict";
const walkSync = require( "walk-sync" );
const existsStat = require( "exists-stat" );
function getFilesFromArgs( args ) {
let globs = args.slice();
// Default to files in the test directory
if ( !globs.length ) {
globs.push( "test/**/*.js" );
}
// For each of the potential globs, we check if it is a directory path and
// update it so that it matches the JS files in that directory.
globs = globs.map( glob => {
const stat = existsStat( glob );
if ( stat && stat.isDirectory() ) {
return `${glob}/**/*.js`;
} else {
return glob;
}
} );
const files = walkSync( process.cwd(), { globs } );
if ( !files.length ) {
error( "No files were found matching: " + args.join( ", " ) );
}
return files;
}
function error( message ) {
console.error( message );
process.exit( 1 );
}
function capitalize( string ) {
return string.charAt( 0 ).toUpperCase() + string.slice( 1 );
}
module.exports = {
capitalize,
error,
getFilesFromArgs
};