tests running though, can now handle local and remote files

This commit is contained in:
2016-03-18 17:34:31 +01:00
parent 34d38cd3d4
commit 4a8df9c12f
10 changed files with 278 additions and 129 deletions

View File

@@ -3,16 +3,16 @@
import plugins = require("./smartfile.plugins");
import SmartfileChecks = require("./smartfile.checks");
import SmartfileFsaction = require("./smartfile.fsaction");
import SmartfileRead = require("./smartfile.read");
import SmartfileLocal = require("./smartfile.local");
import SmartfileRemote = require("./smartfile.remote");
var smartfile:any = {
copy: SmartfileSimple.copy,
fsaction: SmartfileFsaction,
checks: SmartfileChecks,
read: SmartfileRead,
local: SmartfileLocal,
remote: SmartfileRemote,
requireReload: SmartfileSimple.requireReload
requireReload: SmartfileLocal.requireReload
};
export = smartfile;

View File

@@ -12,7 +12,7 @@ export let toFS = function(options:{from:string,toPath:string}, cb=undefined){
* @param fileTypeArg
* @returns {any}
*/
export let toObject = function(filePath,fileTypeArg = undefined) {
export let toObjectSync = function(filePath,fileTypeArg = undefined) {
let fileType;
if (typeof fileTypeArg == "undefined") {
fileType = plugins.path.extname(filePath);
@@ -42,7 +42,7 @@ export let toObject = function(filePath,fileTypeArg = undefined) {
* @param filePath
* @returns {string|Buffer|any}
*/
export let toString = function(filePath) {
export let toStringSync = function(filePath) {
let fileString;
fileString = plugins.fs.readFileSync(filePath, "utf8");
return fileString;
@@ -54,7 +54,7 @@ export let toString = function(filePath) {
* @param options
* @returns {number}
*/
export let toVinyl = function(filePathArg,options = {}) {
export let toVinylSync = function(filePathArg,options = {}) {
return plugins.vinylFile.readSync(filePathArg,options);
};

View File

@@ -1,26 +1,41 @@
/// <reference path="./typings/main.d.ts" />
import plugins = require("./smartfile.plugins");
export let toVar = (options:{from:string,parseJson?:boolean}, cb):any => {
var bodyString:string;
request.get(options.from, function (error, response, body) {
export let toString = (fromArg:string) => {
let done = plugins.q.defer();
plugins.request.get(fromArg, function (error, response, bodyString) {
if (!error && response.statusCode == 200) {
bodyString = body;
console.log('successfully requested' + options.from);
if (options.parseJson = true) {
var jsonObject = JSON.parse(bodyString);
return jsonObject;
};
done.resolve(bodyString);
} else {
console.log('could not get get remote file from ' + options.from);
return bodyString = 'could not get file'
plugins.beautylog.error('could not get get remote file from ' + fromArg);
bodyString = undefined;
done.reject(bodyString);
};
});
return done.promise;
};
return bodyString;
},
export let toObject = function(fromArg:string){
let done = plugins.q.defer();
plugins.request.get(fromArg, function (error, response, bodyString) {
let jsonObject;
if (!error && response.statusCode == 200) {
jsonObject = JSON.parse(bodyString);
done.resolve(jsonObject);
} else {
console.log('could not get remote file from ' + fromArg);
jsonObject = undefined;
done.reject(jsonObject);
};
});
return done.promise;
};
export let toFS = function(options:{from:string,toPath:string}, cb=undefined) {
var stream = request(options.from).pipe(fs.createWriteStream(options.toPath));
if (cb != undefined) stream.on('finish',cb);
}
export let toFs = function(from:string,toPath:string) {
var done = plugins.q.defer();
var stream = plugins.request(from).pipe(plugins.fs.createWriteStream(toPath));
stream.on('finish',function(){
done.resolve(toPath);
});
return done.promise;
};