Comparing version 0.1.0-alpha2 to 0.1.0-alpha3
{ | ||
"urls": [ | ||
"http://www.agst.co/" | ||
"http://96elephants.org/" | ||
], | ||
@@ -11,3 +11,6 @@ "widths": [ | ||
], | ||
"dest": "./dest/" | ||
"dest": "./dest/", | ||
"options": { | ||
"waitTime": 5000 | ||
} | ||
} |
{ | ||
"name": "recap", | ||
"preferGlobal": true, | ||
"version": "0.1.0-alpha2", | ||
"version": "0.1.0-alpha3", | ||
"author": "aintgoin2goa", | ||
@@ -6,0 +6,0 @@ "description": "creates responsive screenshots using phantomjs", |
@@ -6,5 +6,10 @@ /// <reference path="d/node.d.ts" /> | ||
var loadedConfig; | ||
var Config = (function () { | ||
function Config() { | ||
this.dest = "../dest/"; | ||
this.options = { | ||
waitTime: 5000 | ||
}; | ||
} | ||
@@ -39,2 +44,7 @@ return Config; | ||
} | ||
if (cfg.options && cfg.options.waitTime) { | ||
config.options.waitTime = cfg.options.waitTime; | ||
} | ||
loadedConfig = config; | ||
console.log("loadedConfig", loadedConfig); | ||
return config; | ||
@@ -44,2 +54,11 @@ } | ||
function getCurrentConfig() { | ||
console.log("loadedConfig", loadedConfig); | ||
if (loadedConfig == null) { | ||
throw new Error("No config has been loaded yet"); | ||
} | ||
return loadedConfig; | ||
} | ||
exports.getCurrentConfig = getCurrentConfig; | ||
//# sourceMappingURL=config.js.map |
@@ -7,46 +7,64 @@ /// <reference path="d/node.d.ts" /> | ||
var loadedConfig: IConfig; | ||
export class Config implements IConfig{ | ||
export class Config implements IConfig{ | ||
public urls: string[]; | ||
public urls: string[]; | ||
public widths: number[]; | ||
public widths: number[]; | ||
public dest: string = "../dest/"; | ||
public dest: string = "../dest/"; | ||
public options: IConfigOptions = { | ||
waitTime : 5000 | ||
} | ||
function loadFromFilePath(pth: string): Object | ||
{ | ||
pth = path.normalize(pth); | ||
var file = fs.readFileSync(pth, { encoding: "utf8" }); | ||
var contents; | ||
try { | ||
return JSON.parse(file); | ||
} catch (e) { | ||
console.error("JSON Parse Error", e); | ||
setTimeout(function () { | ||
process.exit(1); | ||
}, 10); | ||
} | ||
function loadFromFilePath(pth: string): Object | ||
{ | ||
pth = path.normalize(pth); | ||
var file = fs.readFileSync(pth, { encoding: "utf8" }); | ||
var contents; | ||
try { | ||
return JSON.parse(file); | ||
} catch (e) { | ||
console.error("JSON Parse Error", e); | ||
setTimeout(function () { | ||
process.exit(1); | ||
}, 10); | ||
} | ||
} | ||
} | ||
export function load(cfg: string): IConfig | ||
export function load(cfg: Object): IConfig | ||
export function load(cfg: any): IConfig | ||
{ | ||
if (typeof (cfg) == "string") { | ||
return load(loadFromFilePath(cfg)); | ||
} | ||
export function load(cfg: string): IConfig | ||
export function load(cfg: Object): IConfig | ||
export function load(cfg: any): IConfig | ||
{ | ||
if (typeof (cfg) == "string") { | ||
return load(loadFromFilePath(cfg)); | ||
} | ||
var config = new Config; | ||
config.urls = cfg.urls; | ||
config.widths = cfg.widths; | ||
if (cfg.dest) { | ||
config.dest = cfg.dest; | ||
} | ||
return config; | ||
} | ||
var config = new Config; | ||
config.urls = cfg.urls; | ||
config.widths = cfg.widths; | ||
if (cfg.dest) { | ||
config.dest = cfg.dest; | ||
} | ||
if (cfg.options && cfg.options.waitTime) { | ||
config.options.waitTime = cfg.options.waitTime; | ||
} | ||
loadedConfig = config; | ||
console.log("loadedConfig", loadedConfig); | ||
return config; | ||
} | ||
export function getCurrentConfig(): IConfig { | ||
console.log("loadedConfig", loadedConfig); | ||
if (loadedConfig == null) { | ||
throw new Error("No config has been loaded yet"); | ||
} | ||
return loadedConfig; | ||
} | ||
@@ -9,3 +9,6 @@ var prompt = require("prompt"); | ||
widths: [], | ||
dest: "" | ||
dest: "", | ||
options: { | ||
waitTime: 5000 | ||
} | ||
}; | ||
@@ -12,0 +15,0 @@ |
@@ -9,3 +9,6 @@ var prompt = require("prompt"); | ||
widths: [], | ||
dest: "" | ||
dest: "", | ||
options: { | ||
waitTime : 5000 | ||
} | ||
}; | ||
@@ -12,0 +15,0 @@ |
@@ -30,4 +30,7 @@ /// <reference path="IDestination.ts" /> | ||
if (err) { | ||
console.error("Failed to create destination directory", err); | ||
process.exit(1); | ||
if (err.code == "EEXIST") { | ||
console.warn("Destination directory already exists, will attempt to merge"); | ||
} else { | ||
console.error("Failed to create destination directory", err); | ||
} | ||
} | ||
@@ -34,0 +37,0 @@ |
@@ -44,4 +44,8 @@ /// <reference path="IDestination.ts" /> | ||
if (err) { | ||
console.error("Failed to create destination directory", err); | ||
process.exit(1); | ||
if (err.code == "EEXIST") { | ||
console.warn("Destination directory already exists, will attempt to merge"); | ||
} else { | ||
console.error("Failed to create destination directory", err); | ||
} | ||
} | ||
@@ -48,0 +52,0 @@ // if we have a data file already, delete the file but store contents in memory |
interface IConfig{ | ||
urls: string[]; | ||
@@ -9,2 +9,10 @@ | ||
options: IConfigOptions; | ||
} | ||
interface IConfigOptions { | ||
waitTime: number; | ||
} |
@@ -8,6 +8,7 @@ /// <reference path="../d/node.d.ts" /> | ||
var Q = require("Q"); | ||
var configModule = require("../config"); | ||
var config; | ||
var PhantomAdaptor = (function () { | ||
function PhantomAdaptor() { | ||
this.delay = 10; | ||
} | ||
@@ -17,2 +18,4 @@ PhantomAdaptor.prototype.init = function () { | ||
var dfd = Q.defer(); | ||
config = configModule.getCurrentConfig(); | ||
this.delay = config.options.waitTime; | ||
nodePhantom.create(function (err, phantom) { | ||
@@ -19,0 +22,0 @@ if (err) { |
@@ -10,2 +10,4 @@ /// <reference path="../d/node.d.ts" /> | ||
var Q = require("Q"); | ||
import configModule = require("../config"); | ||
var config: IConfig; | ||
@@ -18,3 +20,3 @@ class PhantomAdaptor implements IScreenshotAdaptor{ | ||
private delay: number = 10; | ||
private delay: number; | ||
@@ -25,2 +27,4 @@ | ||
var dfd: Q.Deferred<any> = Q.defer(); | ||
config = configModule.getCurrentConfig(); | ||
this.delay = config.options.waitTime; | ||
nodePhantom.create((err, phantom) => { | ||
@@ -27,0 +31,0 @@ if (err) { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
182830
3711