-
Notifications
You must be signed in to change notification settings - Fork 1
/
wiredep_karma.js
executable file
·92 lines (80 loc) · 2.67 KB
/
wiredep_karma.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/usr/bin/env node
'use strict';
var pkg = require('./node_modules/wiredep/package.json');
var wiredep = require('./node_modules/wiredep');
var argv = require('./node_modules/wiredep/node_modules/minimist')(process.argv.slice(2));
var chalk = require('./node_modules/wiredep/node_modules/chalk');
var fs = require('fs');
var fileTypes= {js:
{ block: /(([\s\t]*)\/\/\s*bower:*(\S*))(\n|\r|.)*?(\/\/\s*endbower)/gi,
detect: {js: /-\s(.+js)/gi},
replace: {js:'\'{{filePath}}\','}
}
}
var args = [
{ short: 'h', full: 'help' },
{ short: 'v', full: 'version' },
{ short: 'b', full: 'bowerJson' },
{ short: 'd', full: 'directory' },
{ short: 'e', full: 'exclude' },
{ short: 'i', full: 'ignorePath' },
{ short: 's', full: 'src' }
];
function help() {
console.log(pkg.description);
console.log('');
console.log('Usage: ' + chalk.cyan('$') + chalk.bold(' wiredep ') + chalk.yellow('[options]'));
console.log('');
console.log('Options:');
console.log(' -h, --help # Print usage information');
console.log(' -v, --version # Print the version');
console.log(' -b, --bowerJson # Path to `bower.json`');
console.log(' -d, --directory # Your Bower directory');
console.log(' -e, --exclude # A path to be excluded');
console.log(' -i, --ignorePath # A path to be ignored');
console.log(' -s, --src # Path to your source file');
console.log(' --dependencies # Include Bower `dependencies`');
console.log(' --devDependencies # Include Bower `devDependencies`');
console.log(' --verbose # Print the results of `wiredep`');
}
if (argv.v || argv.version) {
console.log(pkg.version);
return;
}
if (argv.h || argv.help || Object.keys(argv).length === 1) {
help();
return;
}
if (!argv.s) {
console.log(chalk.bold.red('> Source file not specified.'));
console.log('Please pass a `--src path/to/source.html` to `wiredep`.');
return;
}
if (argv.b || argv.bowerJson) {
try {
argv.bowerJson = JSON.parse(fs.readFileSync(argv.b || argv.bowerJson));
} catch (e) {}
}
try {
if (!argv.bowerJson) {
fs.statSync('./bower.json');
}
} catch (e) {
console.log(chalk.bold.red('> bower.json not found.'));
console.log('Please run `wiredep` from the directory where your `bower.json` file is located.');
console.log('Alternatively, pass a `--bowerJson path/to/bower.json`.');
return;
}
argv['fileTypes']=fileTypes
var results = wiredep(Object.keys(argv).reduce(function (acc, arg) {
args.filter(function (argObj) {
if (argObj.short === arg) {
acc[argObj.full] = argv[arg];
delete acc[arg];
}
});
return acc;
}, argv));
if (argv.verbose) {
console.log(results);
}