restructure code and make remote and local file delivery conform
This commit is contained in:
parent
9afe7c8a9e
commit
9a05df4200
4
dist/index.js
vendored
4
dist/index.js
vendored
@ -2,15 +2,17 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
var SmartfileChecks = require("./smartfile.checks");
|
var SmartfileChecks = require("./smartfile.checks");
|
||||||
var SmartfileFsaction = require("./smartfile.fsaction");
|
var SmartfileFsaction = require("./smartfile.fsaction");
|
||||||
|
var SmartfileGet = require("./smartfile.get");
|
||||||
var SmartfileLocal = require("./smartfile.local");
|
var SmartfileLocal = require("./smartfile.local");
|
||||||
var SmartfileRemote = require("./smartfile.remote");
|
var SmartfileRemote = require("./smartfile.remote");
|
||||||
var smartfile = {
|
var smartfile = {
|
||||||
fsaction: SmartfileFsaction,
|
fsaction: SmartfileFsaction,
|
||||||
checks: SmartfileChecks,
|
checks: SmartfileChecks,
|
||||||
|
get: SmartfileGet,
|
||||||
local: SmartfileLocal,
|
local: SmartfileLocal,
|
||||||
remote: SmartfileRemote,
|
remote: SmartfileRemote,
|
||||||
requireReload: SmartfileLocal.requireReload
|
requireReload: SmartfileLocal.requireReload
|
||||||
};
|
};
|
||||||
module.exports = smartfile;
|
module.exports = smartfile;
|
||||||
|
|
||||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImluZGV4LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLDRDQUE0Qzs7QUFHNUMsSUFBTyxlQUFlLFdBQVcsb0JBQW9CLENBQUMsQ0FBQztBQUN2RCxJQUFPLGlCQUFpQixXQUFXLHNCQUFzQixDQUFDLENBQUM7QUFDM0QsSUFBTyxjQUFjLFdBQVcsbUJBQW1CLENBQUMsQ0FBQztBQUNyRCxJQUFPLGVBQWUsV0FBVyxvQkFBb0IsQ0FBQyxDQUFDO0FBR3ZELElBQUksU0FBUyxHQUFPO0lBQ2hCLFFBQVEsRUFBRSxpQkFBaUI7SUFDM0IsTUFBTS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vcnQgU21hcnRmaWxlUmVtb3RlID0gcmVxdWlyZShcIi4vc21hcnRmaWxlLnJlbW90ZVwiKTtcblxuXG52YXIgc21hcnRmaWxlOmFueSA9IHtcbiAgICBmc2FjdGlvbjogU21hcnRmaWxlRnNhY3Rpb24sXG4gICAgY2hlY2tzOiBTbWFydGZpbGVDaGVja3MsXG4gICAgZ2V0OiBTbWFydGZpbGVHZXQsXG4gICAgbG9jYWw6IFNtYXJ0ZmlsZUxvY2FsLFxuICAgIHJlbW90ZTogU21hcnRmaWxlUmVtb3RlLFxuICAgIHJlcXVpcmVSZWxvYWQ6IFNtYXJ0ZmlsZUxvY2FsLnJlcXVpcmVSZWxvYWRcbn07XG5cbmV4cG9ydCA9IHNtYXJ0ZmlsZTtcbiJdLCJzb3VyY2VSb290IjoiL3NvdXJjZS8ifQ==
|
||||||
|
10
dist/smartfile.get.js
vendored
Normal file
10
dist/smartfile.get.js
vendored
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
"use strict";
|
||||||
|
/// <reference path="./typings/main.d.ts" />
|
||||||
|
var plugins = require("./smartfile.plugins");
|
||||||
|
exports.filetype = function (pathArg) {
|
||||||
|
var extName = plugins.path.extname(pathArg);
|
||||||
|
var fileType = extName.replace(/\.([a-z]*)/, "$1"); //remove . form fileType
|
||||||
|
return fileType;
|
||||||
|
};
|
||||||
|
|
||||||
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNtYXJ0ZmlsZS5nZXQudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLDRDQUE0QztBQUM1QyxJQUFPLE9BQU8sV0FBVyxxQkFBcUIsQ0FBQyxDQUFDO0FBRXJDLGdCQUFRLEdBQUcsVUFBUyxPQUFjO0lBQ3pDLElBQUksT0FBTyxHQUFHLE9BQU8sQ0FBQyxJQUFJLENBQUMsT0FBTyxDQUFDLE9BQU8sQ0FBQyxDQUFDO0lBQzVDLElBQUksUUFBUSxHQUFHLE9BQU8sQ0FBQyxPQUFPLENBQUMsWUFBWSxFQUFDLElBQUksQ0FBQyxDQUFDLENBQUMsd0JBQXdCO0lBQzNFLE1BQU0sQ0FBQyxRQUFRLENBQUM7QUFDcEIsQ0FBQyxDQUFDIiwiZmlsZSI6InNtYXJ0ZmlsZS5nZXQuanMiLCJzb3VyY2VzQ29udGVudCI6WyIvLy8gPHJlZmVyZW5jZSBwYXRoPVwiLi90eXBpbmdzL21haW4uZC50c1wiIC8+XG5pbXBvcnQgcGx1Z2lucyA9IHJlcXVpcmUoXCIuL3NtYXJ0ZmlsZS5wbHVnaW5zXCIpO1xuXG5leHBvcnQgbGV0IGZpbGV0eXBlID0gZnVuY3Rpb24ocGF0aEFyZzpzdHJpbmcpOnN0cmluZyB7XG4gICAgbGV0IGV4dE5hbWUgPSBwbHVnaW5zLnBhdGguZXh0bmFtZShwYXRoQXJnKTtcbiAgICBsZXQgZmlsZVR5cGUgPSBleHROYW1lLnJlcGxhY2UoL1xcLihbYS16XSopLyxcIiQxXCIpOyAvL3JlbW92ZSAuIGZvcm0gZmlsZVR5cGVcbiAgICByZXR1cm4gZmlsZVR5cGU7XG59OyJdLCJzb3VyY2VSb290IjoiL3NvdXJjZS8ifQ==
|
17
dist/smartfile.interpreter.js
vendored
Normal file
17
dist/smartfile.interpreter.js
vendored
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
/// <reference path="./typings/main.d.ts" />
|
||||||
|
"use strict";
|
||||||
|
var plugins = require("./smartfile.plugins");
|
||||||
|
module.exports = function (fileStringArg, fileTypeArg) {
|
||||||
|
switch (fileTypeArg) {
|
||||||
|
case "yml":
|
||||||
|
case "yaml":
|
||||||
|
return plugins.yaml.safeLoad(fileStringArg);
|
||||||
|
case "json":
|
||||||
|
return JSON.parse(fileStringArg);
|
||||||
|
default:
|
||||||
|
plugins.beautylog.error("file type " + fileTypeArg.blue + " not supported");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
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gICAgICAgICAgcmV0dXJuIHBsdWdpbnMueWFtbC5zYWZlTG9hZChmaWxlU3RyaW5nQXJnKTtcbiAgICAgICAgY2FzZSBcImpzb25cIjpcbiAgICAgICAgICAgIHJldHVybiBKU09OLnBhcnNlKGZpbGVTdHJpbmdBcmcpO1xuICAgICAgICBkZWZhdWx0OlxuICAgICAgICAgICAgcGx1Z2lucy5iZWF1dHlsb2cuZXJyb3IoXCJmaWxlIHR5cGUgXCIgKyBmaWxlVHlwZUFyZy5ibHVlICsgXCIgbm90IHN1cHBvcnRlZFwiKTtcbiAgICAgICAgICAgIGJyZWFrO1xuICAgIH1cbn0iXSwic291cmNlUm9vdCI6Ii9zb3VyY2UvIn0=
|
35
dist/smartfile.local.js
vendored
35
dist/smartfile.local.js
vendored
File diff suppressed because one or more lines are too long
16
dist/smartfile.remote.js
vendored
16
dist/smartfile.remote.js
vendored
File diff suppressed because one or more lines are too long
@ -3,6 +3,7 @@
|
|||||||
import plugins = require("./smartfile.plugins");
|
import plugins = require("./smartfile.plugins");
|
||||||
import SmartfileChecks = require("./smartfile.checks");
|
import SmartfileChecks = require("./smartfile.checks");
|
||||||
import SmartfileFsaction = require("./smartfile.fsaction");
|
import SmartfileFsaction = require("./smartfile.fsaction");
|
||||||
|
import SmartfileGet = require("./smartfile.get");
|
||||||
import SmartfileLocal = require("./smartfile.local");
|
import SmartfileLocal = require("./smartfile.local");
|
||||||
import SmartfileRemote = require("./smartfile.remote");
|
import SmartfileRemote = require("./smartfile.remote");
|
||||||
|
|
||||||
@ -10,6 +11,7 @@ import SmartfileRemote = require("./smartfile.remote");
|
|||||||
var smartfile:any = {
|
var smartfile:any = {
|
||||||
fsaction: SmartfileFsaction,
|
fsaction: SmartfileFsaction,
|
||||||
checks: SmartfileChecks,
|
checks: SmartfileChecks,
|
||||||
|
get: SmartfileGet,
|
||||||
local: SmartfileLocal,
|
local: SmartfileLocal,
|
||||||
remote: SmartfileRemote,
|
remote: SmartfileRemote,
|
||||||
requireReload: SmartfileLocal.requireReload
|
requireReload: SmartfileLocal.requireReload
|
||||||
|
8
ts/smartfile.get.ts
Normal file
8
ts/smartfile.get.ts
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
/// <reference path="./typings/main.d.ts" />
|
||||||
|
import plugins = require("./smartfile.plugins");
|
||||||
|
|
||||||
|
export let filetype = function(pathArg:string):string {
|
||||||
|
let extName = plugins.path.extname(pathArg);
|
||||||
|
let fileType = extName.replace(/\.([a-z]*)/,"$1"); //remove . form fileType
|
||||||
|
return fileType;
|
||||||
|
};
|
16
ts/smartfile.interpreter.ts
Normal file
16
ts/smartfile.interpreter.ts
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
/// <reference path="./typings/main.d.ts" />
|
||||||
|
|
||||||
|
import plugins = require("./smartfile.plugins");
|
||||||
|
|
||||||
|
export = function(fileStringArg:string, fileTypeArg){
|
||||||
|
switch (fileTypeArg) {
|
||||||
|
case "yml" :
|
||||||
|
case "yaml":
|
||||||
|
return plugins.yaml.safeLoad(fileStringArg);
|
||||||
|
case "json":
|
||||||
|
return JSON.parse(fileStringArg);
|
||||||
|
default:
|
||||||
|
plugins.beautylog.error("file type " + fileTypeArg.blue + " not supported");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
@ -1,7 +1,8 @@
|
|||||||
/// <reference path="./typings/main.d.ts" />
|
/// <reference path="./typings/main.d.ts" />
|
||||||
|
|
||||||
import plugins = require("./smartfile.plugins");
|
import plugins = require("./smartfile.plugins");
|
||||||
|
import SmartfileGet = require("./smartfile.get");
|
||||||
|
import SmartfileInterpreter = require("./smartfile.interpreter");
|
||||||
export let toFS = function(options:{from:string,toPath:string}, cb=undefined){
|
export let toFS = function(options:{from:string,toPath:string}, cb=undefined){
|
||||||
|
|
||||||
};
|
};
|
||||||
@ -22,33 +23,15 @@ export let toGulpDestSync = function(folderPathArg:string){
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param filePath
|
* @param filePathArg
|
||||||
* @param fileTypeArg
|
* @param fileTypeArg
|
||||||
* @returns {any}
|
* @returns {any}
|
||||||
*/
|
*/
|
||||||
export let toObjectSync = function(filePath,fileTypeArg = undefined) {
|
export let toObjectSync = function(filePathArg,fileTypeArg?) {
|
||||||
|
let fileString = plugins.fs.readFileSync(filePathArg, 'utf8');
|
||||||
let fileType;
|
let fileType;
|
||||||
if (typeof fileTypeArg == "undefined") {
|
fileTypeArg ? fileType = fileTypeArg : fileType = SmartfileGet.filetype(filePathArg);
|
||||||
fileType = plugins.path.extname(filePath);
|
return SmartfileInterpreter(fileString,fileType);
|
||||||
} else {
|
|
||||||
fileType = fileTypeArg;
|
|
||||||
}
|
|
||||||
fileType = fileType.replace(/\.([a-z]*)/,"$1"); //remove . form fileType
|
|
||||||
switch (fileType) {
|
|
||||||
case "yml" :
|
|
||||||
case "yaml":
|
|
||||||
try {
|
|
||||||
return plugins.yaml.safeLoad(plugins.fs.readFileSync(filePath, 'utf8'));
|
|
||||||
} catch (e){
|
|
||||||
plugins.beautylog.error("check that " + filePath.blue + " points to a valid file");
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case "json":
|
|
||||||
return plugins.fs.readJsonSync(filePath,{});
|
|
||||||
default:
|
|
||||||
plugins.beautylog.error("file type " + fileType.blue + " not supported");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
/// <reference path="./typings/main.d.ts" />
|
/// <reference path="./typings/main.d.ts" />
|
||||||
import plugins = require("./smartfile.plugins");
|
import plugins = require("./smartfile.plugins");
|
||||||
|
import SmartfileInterpreter = require("./smartfile.interpreter");
|
||||||
|
import SmartfileGet = require("./smartfile.get");
|
||||||
|
|
||||||
export let toFs = function(from:string,toPath:string) {
|
export let toFs = function(from:string,toPath:string) {
|
||||||
var done = plugins.q.defer();
|
var done = plugins.q.defer();
|
||||||
@ -30,14 +32,14 @@ export let toGulpStreamSync = function(filePathArg:string,baseArg:string){
|
|||||||
export let toObject = function(fromArg:string){
|
export let toObject = function(fromArg:string){
|
||||||
let done = plugins.q.defer();
|
let done = plugins.q.defer();
|
||||||
plugins.request.get(fromArg, function (error, response, bodyString) {
|
plugins.request.get(fromArg, function (error, response, bodyString) {
|
||||||
let jsonObject;
|
let returnObject;
|
||||||
if (!error && response.statusCode == 200) {
|
if (!error && response.statusCode == 200) {
|
||||||
jsonObject = JSON.parse(bodyString);
|
returnObject = SmartfileInterpreter(bodyString,SmartfileGet.filetype(fromArg));
|
||||||
done.resolve(jsonObject);
|
done.resolve(returnObject);
|
||||||
} else {
|
} else {
|
||||||
console.log('could not get remote file from ' + fromArg);
|
console.log('could not get remote file from ' + fromArg);
|
||||||
jsonObject = undefined;
|
returnObject = undefined;
|
||||||
done.reject(jsonObject);
|
done.reject(returnObject);
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
return done.promise;
|
return done.promise;
|
||||||
@ -54,7 +56,7 @@ export let toString = (fromArg:string) => {
|
|||||||
if (!error && response.statusCode == 200) {
|
if (!error && response.statusCode == 200) {
|
||||||
done.resolve(bodyString);
|
done.resolve(bodyString);
|
||||||
} else {
|
} else {
|
||||||
plugins.beautylog.error('could not get get remote file from ' + fromArg);
|
plugins.beautylog.error('could not get remote file from ' + fromArg);
|
||||||
bodyString = undefined;
|
bodyString = undefined;
|
||||||
done.reject(bodyString);
|
done.reject(bodyString);
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user