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-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) {
|
|
|
|
var 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;
|
|
|
|
};
|
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 {
|
|
|
|
plugins.beautylog.error('could not get get remote file from ' + fromArg);
|
|
|
|
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-19 21:07:59 +00:00
|
|
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNtYXJ0ZmlsZS5yZW1vdGUudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLDRDQUE0QztBQUM1QyxJQUFPLE9BQU8sV0FBVyxxQkFBcUIsQ0FBQyxDQUFDO0FBRXJDLFlBQUksR0FBRyxVQUFTLElBQVcsRUFBQyxNQUFhO0lBQ2hELElBQUksSUFBSSxHQUFHLE9BQU8sQ0FBQyxDQUFDLENBQUMsS0FBSyxFQUFFLENBQUM7SUFDN0IsSUFBSSxNQUFNLEdBQUcsT0FBTyxDQUFDLE9BQU8sQ0FBQyxJQUFJLENBQUMsQ0FBQyxJQUFJLENBQUMsT0FBTyxDQUFDLEVBQUUsQ0FBQyxpQkFBaUIsQ0FBQyxNQUFNLENBQUMsQ0FBQyxDQUFDO0lBQzlFLE1BQU0sQ0FBQyxFQUFFLENBQUMsUUFBUSxFQUFDO1FBQ2YsSUFBSSxDQUFDLE9BQU8sQ0FBQyxNQUFNLENBQUMsQ0FBQztJQUN6QixDQUFDLENBQUMsQ0FBQztJQUNILE1BQU0sQ0FBQyxJQUFJLENBQUMsT0FB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