2016-03-18 09:19:46 +00:00
|
|
|
"use strict";
|
2016-03-18 16:34:31 +00:00
|
|
|
/// <reference path="./typings/main.d.ts" />
|
|
|
|
var plugins = require("./smartfile.plugins");
|
2016-03-20 16:36:38 +00:00
|
|
|
var SmartfileInterpreter = require("./smartfile.interpreter");
|
|
|
|
var SmartfileGet = require("./smartfile.get");
|
2016-03-19 21:07:59 +00:00
|
|
|
exports.toFs = function (from, toPath) {
|
2016-03-18 16:34:31 +00:00
|
|
|
var done = plugins.q.defer();
|
2016-03-19 21:07:59 +00:00
|
|
|
var stream = plugins.request(from).pipe(plugins.fs.createWriteStream(toPath));
|
|
|
|
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 {*}
|
|
|
|
*/
|
|
|
|
exports.toGulpStreamSync = function (filePathArg, baseArg) {
|
|
|
|
var stream = plugins.g.remoteSrc(filePathArg, {
|
|
|
|
base: baseArg
|
|
|
|
});
|
|
|
|
return stream;
|
|
|
|
};
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param fromArg
|
|
|
|
* @returns {any}
|
|
|
|
*/
|
2016-03-18 16:34:31 +00:00
|
|
|
exports.toObject = function (fromArg) {
|
|
|
|
var done = plugins.q.defer();
|
|
|
|
plugins.request.get(fromArg, function (error, response, bodyString) {
|
2016-03-20 16:36:38 +00:00
|
|
|
var returnObject;
|
2016-03-18 16:34:31 +00:00
|
|
|
if (!error && response.statusCode == 200) {
|
2016-03-20 16:36:38 +00:00
|
|
|
returnObject = SmartfileInterpreter(bodyString, SmartfileGet.filetype(fromArg));
|
|
|
|
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-19 21:07:59 +00:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param fromArg
|
|
|
|
* @returns {any}
|
|
|
|
*/
|
|
|
|
exports.toString = function (fromArg) {
|
2016-03-18 16:34:31 +00:00
|
|
|
var 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-18 09:19:46 +00:00
|
|
|
};
|
|
|
|
|
2016-03-20 16:36:38 +00:00
|
|
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNtYXJ0ZmlsZS5yZW1vdGUudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLDRDQUE0QztBQUM1QyxJQUFPLE9BQU8sV0FBVyxxQkFBcUIsQ0FBQyxDQUFDO0FBQ2hELElBQU8sb0JBQW9CLFdBQVcseUJBQXlCLENBQUMsQ0FBQztBQUNqRSxJQUFPLFlBQVksV0FBVyxpQkFBaUIsQ0FBQyxDQUFDO0FBRXRDLFlBQUksR0FBRyxVQUFTLElBQVcsRUFBQyxNQUFhO0lBQ2hELElBQUksSUFBSSxHQUFHLE9BQU8sQ0FBQyxDQUFDLENBQUMsS0F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