2016-03-18 09:19:46 +00:00
|
|
|
"use strict";
|
2016-05-23 06:15:47 +00:00
|
|
|
require("typings-global");
|
2016-03-18 16:34:31 +00:00
|
|
|
var plugins = require("./smartfile.plugins");
|
2016-03-20 16:36:38 +00:00
|
|
|
var SmartfileInterpreter = require("./smartfile.interpreter");
|
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-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-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-06-23 16:31:55 +00:00
|
|
|
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNtYXJ0ZmlsZS5yZW1vdGUudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLFFBQU8sZ0JBQWdCLENBQUMsQ0FBQTtBQUN4QixJQUFPLE9BQU8sV0FBVyxxQkFBcUIsQ0FBQyxDQUFDO0FBQ2hELElBQU8sb0JBQW9CLFdBQVcseUJBQXlCLENBQUMsQ0FBQztBQUV0RCxZQUFJLEdBQUcsVUFBUyxJQUFXLEVBQUMsTUFBYTtJQUNoRCxJQUFJLElBQUksR0FBRyxPQUFPLENBQUMsQ0FBQyxDQUFDLEtBQUssRUFBRSxDQUFDO0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