-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
55 lines (50 loc) · 1.48 KB
/
index.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
/*
* Command Line Interface for Frost
*
* Parses arguments from STDIN and calls Frost accordingly
*/
// Dependency loading
var options = require(phantom.libraryPath + "/lib/options.js");
var Frost = require(phantom.libraryPath + "/lib/frost.js");
// Environment detection and config loading
var env = options.getOption("env", "default");
try {
var Cfg = require(phantom.libraryPath + "/config/" + env + ".js");
} catch (e) {
console.log("No configuration file with name " + env + ".js was found on the config folder");
phantom.exit(1);
}
global.Cfg = Cfg;
// Argument parsing
var type = options.getOption("type", "page");
var mode = options.getOption("mode", "crawl");
var list = options.getOption("list", Cfg.baseUrl());
var pathReplaceInsideAssets = options.getOption("path-replace-inside-assets", false);
var pageLoadTimeout = Cfg.pageLoadTimeout || 35;
pageLoadTimeout *= 1000;
// Building the formatted arguments from the input
if (type === "page") {
list = list.split(",").map(function(item){
return item.trim();
});
} else if (type === "asset") {
list = list.split(",").map(function(item){
item = item.split("->");
return {
url: item[0],
path: item[1]
};
});
} else {
// Unrecognized type error
console.log("Unrecognized type, please use 'asset' or 'page'.");
phantom.exit(1);
}
// Frost handling
var frost = new Frost({
pageLoadTimeout: pageLoadTimeout,
type: type,
mode: mode,
list: list,
pathReplaceInsideAssets: pathReplaceInsideAssets
});