work in progress

This commit is contained in:
2016-03-18 09:19:46 +00:00
parent 834b22ed8d
commit 34d38cd3d4
12 changed files with 170 additions and 26 deletions

View File

@@ -2,15 +2,16 @@
import plugins = require("./smartfile.plugins");
import SmartfileChecks = require("./smartfile.checks");
import SmartfileSimple = require("./smartfile.simple");
import SmartfileFsaction = require("./smartfile.fsaction");
import SmartfileRead = require("./smartfile.read");
import SmartfileRemote = require("./smartfile.remote");
var smartfile:any = {
copy: SmartfileSimple.copy,
checks: SmartfileChecks,
readFileToString: SmartfileSimple.readFileToString,
readFileToObject: SmartfileSimple.readFileToObject,
readFileToVinyl: SmartfileSimple.readFileToVinyl,
read: SmartfileRead,
remote: SmartfileRemote,
requireReload: SmartfileSimple.requireReload
};

7
ts/smartfile.fsaction.ts Normal file
View File

@@ -0,0 +1,7 @@
/// <reference path="./typings/main.d.ts" />
import plugins = require("./smartfile.plugins");
export let copy = function(fromArg:string,toArg:string){
plugins.shelljs.cp("-r",fromArg,toArg);
};

View File

@@ -6,5 +6,6 @@ export let q = require("q");
export let vinyl = require("vinyl");
export let vinylFile = require("vinyl-file");
export let yaml = require("js-yaml");
export let request = require("request");
export let requireReload = require("require-reload");
export let shelljs = require("shelljs");

View File

@@ -2,19 +2,8 @@
import plugins = require("./smartfile.plugins");
export let copy = function(fromArg:string,toArg:string){
plugins.shelljs.cp("-r",fromArg,toArg);
};
/**
* reads a file content to a String
* @param filePath
* @returns {string|Buffer|any}
*/
export let readFileToString = function(filePath) {
let fileString;
fileString = plugins.fs.readFileSync(filePath, "utf8");
return fileString;
export let toFS = function(options:{from:string,toPath:string}, cb=undefined){
};
/**
@@ -23,7 +12,7 @@ export let readFileToString = function(filePath) {
* @param fileTypeArg
* @returns {any}
*/
export let readFileToObject = function(filePath,fileTypeArg = undefined) {
export let toObject = function(filePath,fileTypeArg = undefined) {
let fileType;
if (typeof fileTypeArg == "undefined") {
fileType = plugins.path.extname(filePath);
@@ -48,13 +37,24 @@ export let readFileToObject = function(filePath,fileTypeArg = undefined) {
}
};
/**
* reads a file content to a String
* @param filePath
* @returns {string|Buffer|any}
*/
export let toString = function(filePath) {
let fileString;
fileString = plugins.fs.readFileSync(filePath, "utf8");
return fileString;
};
/**
*
* @param filePathArg
* @param options
* @returns {number}
*/
export let readFileToVinyl = function(filePathArg,options = {}) {
export let toVinyl = function(filePathArg,options = {}) {
return plugins.vinylFile.readSync(filePathArg,options);
};

26
ts/smartfile.remote.ts Normal file
View File

@@ -0,0 +1,26 @@
/// <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) {
if (!error && response.statusCode == 200) {
bodyString = body;
console.log('successfully requested' + options.from);
if (options.parseJson = true) {
var jsonObject = JSON.parse(bodyString);
return jsonObject;
};
} else {
console.log('could not get get remote file from ' + options.from);
return bodyString = 'could not get file'
};
});
return bodyString;
},
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);
}