2016-05-23 06:15:47 +00:00
|
|
|
import "typings-global";
|
2016-03-18 09:19:46 +00:00
|
|
|
import plugins = require("./smartfile.plugins");
|
2016-03-20 16:36:38 +00:00
|
|
|
import SmartfileInterpreter = require("./smartfile.interpreter");
|
2016-03-18 09:19:46 +00:00
|
|
|
|
2016-03-19 21:07:59 +00:00
|
|
|
export let toFs = function(from:string,toPath:string) {
|
2016-07-01 04:07:58 +00:00
|
|
|
var done = plugins.Q.defer();
|
2016-07-19 18:28:28 +00:00
|
|
|
var stream = plugins.request(from).pipe(plugins.fsExtra.createWriteStream(toPath));
|
2016-03-19 21:07:59 +00:00
|
|
|
stream.on('finish',function(){
|
|
|
|
done.resolve(toPath);
|
2016-03-18 09:19:46 +00:00
|
|
|
});
|
2016-03-18 16:34:31 +00:00
|
|
|
return done.promise;
|
|
|
|
};
|
2016-03-18 09:19:46 +00:00
|
|
|
|
2016-03-19 21:07:59 +00:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param filePathArg
|
|
|
|
* @returns {*}
|
|
|
|
*/
|
|
|
|
export let toGulpStreamSync = function(filePathArg:string,baseArg:string){
|
|
|
|
let stream = plugins.g.remoteSrc(filePathArg, {
|
|
|
|
base: baseArg
|
|
|
|
});
|
|
|
|
return stream;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param fromArg
|
|
|
|
* @returns {any}
|
|
|
|
*/
|
2016-03-18 16:34:31 +00:00
|
|
|
export let toObject = function(fromArg:string){
|
2016-07-01 04:07:58 +00:00
|
|
|
let done = plugins.Q.defer();
|
2016-03-18 16:34:31 +00:00
|
|
|
plugins.request.get(fromArg, function (error, response, bodyString) {
|
2016-03-20 16:36:38 +00:00
|
|
|
let returnObject;
|
2016-03-18 16:34:31 +00:00
|
|
|
if (!error && response.statusCode == 200) {
|
2016-06-23 16:31:55 +00:00
|
|
|
returnObject = SmartfileInterpreter.objectFile(bodyString,SmartfileInterpreter.filetype(fromArg));
|
2016-03-20 16:36:38 +00:00
|
|
|
done.resolve(returnObject);
|
2016-03-18 16:34:31 +00:00
|
|
|
} else {
|
|
|
|
console.log('could not get remote file from ' + fromArg);
|
2016-03-20 16:36:38 +00:00
|
|
|
returnObject = undefined;
|
|
|
|
done.reject(returnObject);
|
2016-03-18 16:34:31 +00:00
|
|
|
};
|
|
|
|
});
|
|
|
|
return done.promise;
|
|
|
|
};
|
2016-03-18 09:19:46 +00:00
|
|
|
|
2016-03-19 21:07:59 +00:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param fromArg
|
|
|
|
* @returns {any}
|
|
|
|
*/
|
|
|
|
export let toString = (fromArg:string) => {
|
2016-07-01 04:07:58 +00:00
|
|
|
let done = plugins.Q.defer();
|
2016-03-19 21:07:59 +00:00
|
|
|
plugins.request.get(fromArg, function (error, response, bodyString) {
|
|
|
|
if (!error && response.statusCode == 200) {
|
|
|
|
done.resolve(bodyString);
|
|
|
|
} else {
|
2016-03-20 16:36:38 +00:00
|
|
|
plugins.beautylog.error('could not get remote file from ' + fromArg);
|
2016-03-19 21:07:59 +00:00
|
|
|
bodyString = undefined;
|
|
|
|
done.reject(bodyString);
|
|
|
|
};
|
2016-03-18 16:34:31 +00:00
|
|
|
});
|
|
|
|
return done.promise;
|
2016-03-19 21:07:59 +00:00
|
|
|
};
|
|
|
|
|