forked from prebid/Prebid.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpHelpers.js
51 lines (45 loc) · 1.57 KB
/
gulpHelpers.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
const fs = require('fs');
const path = require('path');
const argv = require('yargs').argv;
const MANIFEST = 'package.json';
module.exports = {
parseBrowserArgs: function (argv) {
return (argv.browsers) ? argv.browsers.split(',') : [];
},
toCapitalCase: function (str) {
return str.charAt(0).toUpperCase() + str.slice(1);
},
jsonifyHTML: function (str) {
console.log(arguments);
return str.replace(/\n/g, '')
.replace(/<\//g, '<\\/')
.replace(/\/>/g, '\\/>');
},
/*
* Get source files for analytics subdirectories in top-level `analytics`
* directory adjacent to Prebid.js.
* Invoke with gulp <task> --analytics
* Returns an array of source files for inclusion in build process
*/
getAnalyticsSources: function(directory) {
if (!argv.analytics) {return [];} // empty arrays won't affect a standard build
const directoryContents = fs.readdirSync(directory);
return directoryContents
.filter(file => isModuleDirectory(path.join(directory, file)))
.map(moduleDirectory => {
const module = require(path.join(directory, moduleDirectory, MANIFEST));
return path.join(directory, moduleDirectory, module.main);
});
// get only subdirectories that contain package.json with 'main' property
function isModuleDirectory(filePath) {
try {
const manifestPath = path.join(filePath, MANIFEST);
if (fs.statSync(manifestPath).isFile()) {
const module = require(manifestPath);
return module && module.main;
}
}
catch (error) {}
}
}
};