smartfile/dist/smartfile.remote.js

64 lines
4.3 KiB
JavaScript
Raw Normal View History

2016-03-18 09:19:46 +00:00
"use strict";
require("typings-global");
2016-07-17 15:34:15 +00:00
const plugins = require("./smartfile.plugins");
const SmartfileInterpreter = require("./smartfile.interpreter");
2016-03-19 21:07:59 +00:00
exports.toFs = function (from, toPath) {
2016-09-20 15:56:49 +00:00
let done = plugins.q.defer();
let 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
});
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) {
2016-07-17 15:34:15 +00:00
let stream = plugins.g.remoteSrc(filePathArg, {
2016-03-19 21:07:59 +00:00
base: baseArg
});
return stream;
};
/**
*
* @param fromArg
* @returns {any}
*/
exports.toObject = function (fromArg) {
2016-09-17 21:11:44 +00:00
let done = plugins.q.defer();
plugins.request.get(fromArg, function (error, response, bodyString) {
2016-07-17 15:34:15 +00:00
let returnObject;
2016-09-20 15:56:49 +00:00
if (!error && response.statusCode === 200) {
2016-06-23 16:31:55 +00:00
returnObject = SmartfileInterpreter.objectFile(bodyString, SmartfileInterpreter.filetype(fromArg));
done.resolve(returnObject);
}
else {
console.log('could not get remote file from ' + fromArg);
returnObject = undefined;
done.reject(returnObject);
}
});
return done.promise;
};
2016-03-19 21:07:59 +00:00
/**
*
* @param fromArg
* @returns {any}
*/
2016-07-17 15:34:15 +00:00
exports.toString = (fromArg) => {
2016-09-17 21:11:44 +00:00
let done = plugins.q.defer();
2016-03-19 21:07:59 +00:00
plugins.request.get(fromArg, function (error, response, bodyString) {
2016-09-20 15:56:49 +00:00
if (!error && response.statusCode === 200) {
2016-03-19 21:07:59 +00:00
done.resolve(bodyString);
}
else {
plugins.beautylog.error('could not get remote file from ' + fromArg);
2016-03-19 21:07:59 +00:00
bodyString = undefined;
done.reject(bodyString);
}
});
return done.promise;
2016-03-18 09:19:46 +00:00
};
2016-09-20 15:56:49 +00:00
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRmaWxlLnJlbW90ZS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0ZmlsZS5yZW1vdGUudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLDBCQUF1QjtBQUN2QiwrQ0FBK0M7QUFDL0MsZ0VBQWdFO0FBRXJELFFBQUEsSUFBSSxHQUFHLFVBQVMsSUFBWSxFQUFDLE1BQWM7SUFDbEQsSUFBSSxJQUFJLEdBQUcsT0FBTyxDQUFDLENBQUMsQ0FBQyxLQUFLLEVBQUUsQ0FBQTtJQUM1QixJQUFJLE1BQU0sR0FBRyxPQUFPLENBQUMsT0FBTyxDQUFDLElBQUksQ0FBQyxDQUFDLElBQUksQ0FBQyxPQUFPLENBQUMsT0FBTyxDQUFDLGlCQUFpQixDQUFDLE1BQU0sQ0FBQyxDQUFDLENBQUE7SUFDbEYsTUFBTSxDQUFDLEVBQUUsQ0FBQyxRQUFRLEVBQUM7UUFDZixJQUFJLENBQUMsT0FBTyxDQUFDLE1BQU0sQ0FBQyxDQUFBO0lBQ3hCLENBQUMsQ0FBQyxDQUFBO0lBQ0YsTUFBTSxDQUFDLElBQUksQ0FBQyxPQUFPLENBQUE7QUFDdkIsQ0FBQyxDQUFBO0FBRUQ7Ozs7R0FJRztBQUNRLFFBQUEsZ0JBQWdCLEdBQUcsVUFBUyxXQUFtQixFQUFDLE9BQWU7SUFDdEUsSUFBSSxNQUFNLEdBQUcsT0FBTyxDQUFDLENBQUMsQ0FBQyxTQUFTLENBQUMsV0FBVyxFQUFFO1FBQzFDLElBQUksRUFBRSxPQUFPO0tBQ2hCLENBQUMsQ0FBQTtJQUNGLE1BQU0sQ0FBQyxNQU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