now adhering to standard js
This commit is contained in:
24
ts/index.ts
24
ts/index.ts
@ -1,15 +1,15 @@
|
||||
import "typings-global";
|
||||
import 'typings-global'
|
||||
|
||||
import * as plugins from "./smartfile.plugins";
|
||||
import * as SmartfileFs from "./smartfile.fs";
|
||||
import * as SmartfileInterpreter from "./smartfile.interpreter"
|
||||
import * as SmartfileMemory from "./smartfile.memory";
|
||||
import * as SmartfileRemote from "./smartfile.remote";
|
||||
import * as plugins from './smartfile.plugins'
|
||||
import * as SmartfileFs from './smartfile.fs'
|
||||
import * as SmartfileInterpreter from './smartfile.interpreter'
|
||||
import * as SmartfileMemory from './smartfile.memory'
|
||||
import * as SmartfileRemote from './smartfile.remote'
|
||||
|
||||
export {Smartfile} from "./smartfile.classes.smartfile";
|
||||
export {Smartfile} from './smartfile.classes.smartfile'
|
||||
|
||||
export let fs = SmartfileFs;
|
||||
export let interpreter = SmartfileInterpreter;
|
||||
export let memory = SmartfileMemory;
|
||||
export let remote = SmartfileRemote;
|
||||
export let requireReload = SmartfileFs.requireReload;
|
||||
export let fs = SmartfileFs
|
||||
export let interpreter = SmartfileInterpreter
|
||||
export let memory = SmartfileMemory
|
||||
export let remote = SmartfileRemote
|
||||
export let requireReload = SmartfileFs.requireReload
|
||||
|
@ -1,5 +1,5 @@
|
||||
export class Smartfile {
|
||||
constructor(){
|
||||
|
||||
};
|
||||
}
|
||||
constructor() {
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
import "typings-global";
|
||||
import 'typings-global'
|
||||
|
||||
import plugins = require("./smartfile.plugins");
|
||||
import SmartfileInterpreter = require("./smartfile.interpreter");
|
||||
import plugins = require('./smartfile.plugins')
|
||||
import SmartfileInterpreter = require('./smartfile.interpreter')
|
||||
|
||||
/*===============================================================
|
||||
============================ Checks =============================
|
||||
@ -12,17 +12,16 @@ import SmartfileInterpreter = require("./smartfile.interpreter");
|
||||
* @param filePath
|
||||
* @returns {boolean}
|
||||
*/
|
||||
export let fileExistsSync = function(filePath):boolean {
|
||||
let fileExistsBool:boolean = false;
|
||||
export let fileExistsSync = function(filePath): boolean {
|
||||
let fileExistsBool: boolean = false
|
||||
try {
|
||||
plugins.fsExtra.readFileSync(filePath);
|
||||
plugins.fsExtra.readFileSync(filePath)
|
||||
fileExistsBool = true
|
||||
} catch (err) {
|
||||
fileExistsBool = false
|
||||
}
|
||||
catch(err){
|
||||
fileExistsBool = false;
|
||||
}
|
||||
return fileExistsBool;
|
||||
};
|
||||
return fileExistsBool
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
@ -30,26 +29,26 @@ export let fileExistsSync = function(filePath):boolean {
|
||||
* @returns {any}
|
||||
*/
|
||||
export let fileExists = function(filePath){
|
||||
let done = plugins.q.defer();
|
||||
let done = plugins.q.defer()
|
||||
plugins.fs.access(filePath, plugins.fs.R_OK, function (err) {
|
||||
err ? done.reject(err) : done.resolve();
|
||||
});
|
||||
return done.promise;
|
||||
};
|
||||
err ? done.reject(err) : done.resolve()
|
||||
})
|
||||
return done.promise
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if given path points to an existing directory
|
||||
*/
|
||||
export let isDirectory = function(pathArg):boolean{
|
||||
return plugins.fsExtra.statSync(pathArg).isDirectory();
|
||||
};
|
||||
export let isDirectory = function(pathArg): boolean{
|
||||
return plugins.fsExtra.statSync(pathArg).isDirectory()
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a given path points to an existing file
|
||||
*/
|
||||
export let isFile = function(pathArg):boolean{
|
||||
return plugins.fsExtra.statSync(pathArg).isFile();
|
||||
};
|
||||
export let isFile = function(pathArg): boolean{
|
||||
return plugins.fsExtra.statSync(pathArg).isFile()
|
||||
}
|
||||
|
||||
/*===============================================================
|
||||
============================ FS ACTIONS =========================
|
||||
@ -58,57 +57,56 @@ export let isFile = function(pathArg):boolean{
|
||||
/**
|
||||
* ensures that a directory is in place
|
||||
*/
|
||||
export let ensureDir = (dirPathArg:string) => {
|
||||
let done = plugins.q.defer();
|
||||
plugins.fsExtra.ensureDir(dirPathArg,done.resolve);
|
||||
return done.promise;
|
||||
export let ensureDir = (dirPathArg: string) => {
|
||||
let done = plugins.q.defer()
|
||||
plugins.fsExtra.ensureDir(dirPathArg,done.resolve)
|
||||
return done.promise
|
||||
}
|
||||
|
||||
/**
|
||||
* ensures that a directory is in place
|
||||
*/
|
||||
export let ensureDirSync = (dirPathArg:string) => {
|
||||
plugins.fsExtra.ensureDirSync(dirPathArg);
|
||||
export let ensureDirSync = (dirPathArg: string) => {
|
||||
plugins.fsExtra.ensureDirSync(dirPathArg)
|
||||
}
|
||||
|
||||
/**
|
||||
* copies a file from A to B on the local disk
|
||||
*/
|
||||
export let copy = function(fromArg:string, toArg:string){
|
||||
var done = plugins.q.defer();
|
||||
export let copy = function(fromArg: string, toArg: string){
|
||||
let done = plugins.q.defer()
|
||||
plugins.fsExtra.copy(fromArg,toArg,{},function(){
|
||||
done.resolve();
|
||||
});
|
||||
return done.promise;
|
||||
};
|
||||
done.resolve()
|
||||
})
|
||||
return done.promise
|
||||
}
|
||||
|
||||
/**
|
||||
* copies a file SYNCHRONOUSLY from A to B on the local disk
|
||||
*/
|
||||
export let copySync = function(fromArg:string,toArg:string):boolean{
|
||||
plugins.fsExtra.copySync(fromArg,toArg);
|
||||
return true;
|
||||
};
|
||||
|
||||
export let copySync = function(fromArg: string,toArg: string): boolean{
|
||||
plugins.fsExtra.copySync(fromArg,toArg)
|
||||
return true
|
||||
}
|
||||
|
||||
/**
|
||||
* removes a file or folder from local disk
|
||||
*/
|
||||
export let remove = function(pathArg:string){
|
||||
var done = plugins.q.defer();
|
||||
export let remove = function(pathArg: string){
|
||||
let done = plugins.q.defer()
|
||||
plugins.fsExtra.remove(pathArg,function(){
|
||||
done.resolve();
|
||||
});
|
||||
return done.promise;
|
||||
};
|
||||
done.resolve()
|
||||
})
|
||||
return done.promise
|
||||
}
|
||||
|
||||
/**
|
||||
* removes a file SYNCHRONOUSLY from local disk
|
||||
*/
|
||||
export let removeSync = function(pathArg:string):boolean{
|
||||
plugins.fsExtra.removeSync(pathArg);
|
||||
return true;
|
||||
};
|
||||
|
||||
export let removeSync = function(pathArg: string): boolean{
|
||||
plugins.fsExtra.removeSync(pathArg)
|
||||
return true
|
||||
}
|
||||
|
||||
/*===============================================================
|
||||
============================ Write/Read =========================
|
||||
@ -119,14 +117,14 @@ export let removeSync = function(pathArg:string):boolean{
|
||||
* @param filePathArg
|
||||
* @returns {*}
|
||||
*/
|
||||
export let toGulpStreamSync = function(filePathArg:string){
|
||||
let stream = plugins.gulp.src(filePathArg);
|
||||
return stream;
|
||||
};
|
||||
export let toGulpStreamSync = function(filePathArg: string){
|
||||
let stream = plugins.gulp.src(filePathArg)
|
||||
return stream
|
||||
}
|
||||
|
||||
export let toGulpDestSync = function(folderPathArg:string){
|
||||
return plugins.gulp.dest(folderPathArg);
|
||||
};
|
||||
export let toGulpDestSync = function(folderPathArg: string){
|
||||
return plugins.gulp.dest(folderPathArg)
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
@ -135,11 +133,11 @@ export let toGulpDestSync = function(folderPathArg:string){
|
||||
* @returns {any}
|
||||
*/
|
||||
export let toObjectSync = function(filePathArg,fileTypeArg?) {
|
||||
let fileString = plugins.fsExtra.readFileSync(filePathArg, 'utf8');
|
||||
let fileType;
|
||||
fileTypeArg ? fileType = fileTypeArg : fileType = SmartfileInterpreter.filetype(filePathArg);
|
||||
return SmartfileInterpreter.objectFile(fileString,fileType);
|
||||
};
|
||||
let fileString = plugins.fsExtra.readFileSync(filePathArg, 'utf8')
|
||||
let fileType
|
||||
fileTypeArg ? fileType = fileTypeArg : fileType = SmartfileInterpreter.filetype(filePathArg)
|
||||
return SmartfileInterpreter.objectFile(fileString,fileType)
|
||||
}
|
||||
|
||||
/**
|
||||
* reads a file content to a String
|
||||
@ -147,10 +145,10 @@ export let toObjectSync = function(filePathArg,fileTypeArg?) {
|
||||
* @returns {string|Buffer|any}
|
||||
*/
|
||||
export let toStringSync = function(filePath) {
|
||||
let fileString;
|
||||
fileString = plugins.fsExtra.readFileSync(filePath, "utf8");
|
||||
return fileString;
|
||||
};
|
||||
let fileString
|
||||
fileString = plugins.fsExtra.readFileSync(filePath, 'utf8')
|
||||
return fileString
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
@ -159,135 +157,134 @@ export let toStringSync = function(filePath) {
|
||||
* @returns {number}
|
||||
*/
|
||||
export let toVinylSync = function(filePathArg,options = {}) {
|
||||
return plugins.vinylFile.readSync(filePathArg,options);
|
||||
};
|
||||
return plugins.vinylFile.readSync(filePathArg,options)
|
||||
}
|
||||
|
||||
/**
|
||||
* lets you reload files hot.
|
||||
* @param path
|
||||
* @returns {any}
|
||||
*/
|
||||
export let requireReload = function(path:string){
|
||||
return plugins.requireReload(path);
|
||||
};
|
||||
export let requireReload = function(path: string){
|
||||
return plugins.requireReload(path)
|
||||
}
|
||||
|
||||
/**
|
||||
* lists Folders in a directory on local disk
|
||||
* @returns Promise
|
||||
*/
|
||||
export let listFolders = function(pathArg:string,regexFilter?:RegExp){
|
||||
let done = plugins.q.defer();
|
||||
export let listFolders = function(pathArg: string,regexFilter?: RegExp){
|
||||
let done = plugins.q.defer()
|
||||
let folderArray = plugins.fsExtra.readdirSync(pathArg).filter(function(file) {
|
||||
return plugins.fsExtra.statSync(plugins.path.join(pathArg, file)).isDirectory();
|
||||
});
|
||||
if(regexFilter){
|
||||
return plugins.fsExtra.statSync(plugins.path.join(pathArg, file)).isDirectory()
|
||||
})
|
||||
if (regexFilter) {
|
||||
folderArray = folderArray.filter((fileItem) => {
|
||||
return regexFilter.test(fileItem);
|
||||
});
|
||||
return regexFilter.test(fileItem)
|
||||
})
|
||||
}
|
||||
done.resolve(folderArray);
|
||||
return done.promise;
|
||||
};
|
||||
done.resolve(folderArray)
|
||||
return done.promise
|
||||
}
|
||||
|
||||
/**
|
||||
* lists Folders SYNCHRONOUSLY in a directory on local disk
|
||||
* @returns an array with the folder names as strings
|
||||
*/
|
||||
export let listFoldersSync = function(pathArg:string,regexFilter?:RegExp):string[]{
|
||||
export let listFoldersSync = function(pathArg: string,regexFilter?: RegExp): string[]{
|
||||
let folderArray = plugins.fsExtra.readdirSync(pathArg).filter(function(file) {
|
||||
return plugins.fsExtra.statSync(plugins.path.join(pathArg, file)).isDirectory();
|
||||
});
|
||||
if(regexFilter){
|
||||
return plugins.fsExtra.statSync(plugins.path.join(pathArg, file)).isDirectory()
|
||||
})
|
||||
if (regexFilter) {
|
||||
folderArray = folderArray.filter((fileItem) => {
|
||||
return regexFilter.test(fileItem);
|
||||
});
|
||||
};
|
||||
return folderArray;
|
||||
};
|
||||
|
||||
return regexFilter.test(fileItem)
|
||||
})
|
||||
}
|
||||
return folderArray
|
||||
}
|
||||
|
||||
/**
|
||||
* lists Files in a directory on local disk
|
||||
* @returns Promise
|
||||
*/
|
||||
export let listFiles = function(pathArg:string, regexFilter?:RegExp){
|
||||
let done = plugins.q.defer();
|
||||
export let listFiles = function(pathArg: string, regexFilter?: RegExp){
|
||||
let done = plugins.q.defer()
|
||||
let fileArray = plugins.fsExtra.readdirSync(pathArg).filter(function(file) {
|
||||
return plugins.fsExtra.statSync(plugins.path.join(pathArg, file)).isFile();
|
||||
});
|
||||
if(regexFilter){
|
||||
return plugins.fsExtra.statSync(plugins.path.join(pathArg, file)).isFile()
|
||||
})
|
||||
if (regexFilter) {
|
||||
fileArray = fileArray.filter((fileItem) => {
|
||||
return regexFilter.test(fileItem);
|
||||
});
|
||||
};
|
||||
done.resolve(fileArray);
|
||||
return done.promise;
|
||||
};
|
||||
return regexFilter.test(fileItem)
|
||||
})
|
||||
}
|
||||
done.resolve(fileArray)
|
||||
return done.promise
|
||||
}
|
||||
|
||||
/**
|
||||
* lists Files SYNCHRONOUSLY in a directory on local disk
|
||||
* @returns an array with the folder names as strings
|
||||
*/
|
||||
export let listFilesSync = function(pathArg:string, regexFilter?:RegExp):string[]{
|
||||
export let listFilesSync = function(pathArg: string, regexFilter?: RegExp): string[]{
|
||||
let fileArray = plugins.fsExtra.readdirSync(pathArg).filter(function(file) {
|
||||
return plugins.fsExtra.statSync(plugins.path.join(pathArg, file)).isFile();
|
||||
});
|
||||
if(regexFilter){
|
||||
return plugins.fsExtra.statSync(plugins.path.join(pathArg, file)).isFile()
|
||||
})
|
||||
if (regexFilter) {
|
||||
fileArray = fileArray.filter((fileItem) => {
|
||||
return regexFilter.test(fileItem);
|
||||
});
|
||||
};
|
||||
return fileArray;
|
||||
};
|
||||
return regexFilter.test(fileItem)
|
||||
})
|
||||
}
|
||||
return fileArray
|
||||
}
|
||||
|
||||
/**
|
||||
* lists all items (folders AND files) in a directory on local disk
|
||||
* @returns Promise<string[]>
|
||||
*/
|
||||
export let listAllItems = function(pathArg:string, regexFilter?:RegExp): plugins.q.Promise<string[]> {
|
||||
let done = plugins.q.defer<string[]>();
|
||||
let allItmesArray = plugins.fsExtra.readdirSync(pathArg);
|
||||
if(regexFilter){
|
||||
export let listAllItems = function(pathArg: string, regexFilter?: RegExp): plugins.q.Promise<string[]> {
|
||||
let done = plugins.q.defer<string[]>()
|
||||
let allItmesArray = plugins.fsExtra.readdirSync(pathArg)
|
||||
if (regexFilter) {
|
||||
allItmesArray = allItmesArray.filter((fileItem) => {
|
||||
return regexFilter.test(fileItem);
|
||||
});
|
||||
return regexFilter.test(fileItem)
|
||||
})
|
||||
};
|
||||
done.resolve(allItmesArray);
|
||||
return done.promise;
|
||||
};
|
||||
done.resolve(allItmesArray)
|
||||
return done.promise
|
||||
}
|
||||
|
||||
/**
|
||||
* lists all items (folders AND files) in a directory on local disk
|
||||
* @returns an array with the folder names as strings
|
||||
* @executes SYNC
|
||||
*/
|
||||
export let listAllItemsSync = function(pathArg:string, regexFilter?:RegExp):string[]{
|
||||
export let listAllItemsSync = function(pathArg: string, regexFilter?: RegExp): string[]{
|
||||
let allItmesArray = plugins.fsExtra.readdirSync(pathArg).filter(function(file) {
|
||||
return plugins.fsExtra.statSync(plugins.path.join(pathArg, file)).isFile();
|
||||
});
|
||||
if(regexFilter){
|
||||
return plugins.fsExtra.statSync(plugins.path.join(pathArg, file)).isFile()
|
||||
})
|
||||
if (regexFilter) {
|
||||
allItmesArray = allItmesArray.filter((fileItem) => {
|
||||
return regexFilter.test(fileItem);
|
||||
});
|
||||
};
|
||||
return allItmesArray;
|
||||
};
|
||||
return regexFilter.test(fileItem)
|
||||
})
|
||||
}
|
||||
return allItmesArray
|
||||
}
|
||||
|
||||
/**
|
||||
* lists a file tree using a miniMatch filter
|
||||
* @returns Promise<string[]> string array with the absolute paths of all matching files
|
||||
*/
|
||||
export let listFileTree = (dirPath:string, miniMatchFilter:string): plugins.q.Promise<string[]> => {
|
||||
let done = plugins.q.defer<string[]>();
|
||||
export let listFileTree = (dirPath: string, miniMatchFilter: string): plugins.q.Promise<string[]> => {
|
||||
let done = plugins.q.defer<string[]>()
|
||||
let options = {
|
||||
cwd:dirPath
|
||||
cwd: dirPath
|
||||
}
|
||||
plugins.glob(miniMatchFilter,options,(err,files:string[]) => {
|
||||
if(err){
|
||||
console.log(err);
|
||||
done.reject(err);
|
||||
};
|
||||
done.resolve(files);
|
||||
});
|
||||
return done.promise;
|
||||
};
|
||||
plugins.glob(miniMatchFilter,options,(err,files: string[]) => {
|
||||
if (err) {
|
||||
console.log(err)
|
||||
done.reject(err)
|
||||
}
|
||||
done.resolve(files)
|
||||
})
|
||||
return done.promise
|
||||
}
|
||||
|
@ -1,22 +1,22 @@
|
||||
import "typings-global";
|
||||
import 'typings-global'
|
||||
|
||||
import plugins = require("./smartfile.plugins");
|
||||
import plugins = require('./smartfile.plugins')
|
||||
|
||||
export let filetype = (pathArg:string):string => {
|
||||
let extName = plugins.path.extname(pathArg);
|
||||
let fileType = extName.replace(/\.([a-z]*)/,"$1"); //remove . form fileType
|
||||
return fileType;
|
||||
};
|
||||
export let filetype = (pathArg: string): string => {
|
||||
let extName = plugins.path.extname(pathArg)
|
||||
let fileType = extName.replace(/\.([a-z]*)/,'$1') // remove . form fileType
|
||||
return fileType
|
||||
}
|
||||
|
||||
export let objectFile = (fileStringArg:string, fileTypeArg) => {
|
||||
export let objectFile = (fileStringArg: string, fileTypeArg) => {
|
||||
switch (fileTypeArg) {
|
||||
case "yml" :
|
||||
case "yaml":
|
||||
return plugins.yaml.safeLoad(fileStringArg);
|
||||
case "json":
|
||||
return JSON.parse(fileStringArg);
|
||||
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;
|
||||
plugins.beautylog.error('file type ' + fileTypeArg.blue + ' not supported')
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,11 @@
|
||||
import "typings-global";
|
||||
import 'typings-global'
|
||||
|
||||
import plugins = require('./smartfile.plugins')
|
||||
import SmartfileInterpreter = require('./smartfile.interpreter')
|
||||
import vinyl = require('vinyl')
|
||||
let Readable = require('stream').Readable
|
||||
|
||||
|
||||
import plugins = require("./smartfile.plugins");
|
||||
import SmartfileInterpreter = require("./smartfile.interpreter");
|
||||
import vinyl = require("vinyl");
|
||||
let Readable = require("stream").Readable;
|
||||
/**
|
||||
* allows you to create a gulp stream
|
||||
* from String, from an Array of Strings, from Vinyl File, from an Array of VinylFiles
|
||||
@ -11,34 +13,34 @@ let Readable = require("stream").Readable;
|
||||
* @returns stream.Readable
|
||||
* @TODO: make it async;
|
||||
*/
|
||||
export let toGulpStream = function(fileArg:string|string[]|plugins.vinyl|plugins.vinyl[],baseArg:string = "/"){
|
||||
let fileArray = [];
|
||||
export let toGulpStream = function(fileArg: string|string[]|plugins.vinyl|plugins.vinyl[],baseArg: string = '/'){
|
||||
let fileArray = []
|
||||
|
||||
if(typeof fileArg === "string" || fileArg instanceof plugins.vinyl){ // make sure we work with an array later on
|
||||
fileArray.push(fileArg);
|
||||
} else if (Array.isArray(fileArg)){
|
||||
fileArray = fileArg;
|
||||
if (typeof fileArg === 'string' || fileArg instanceof plugins.vinyl) { // make sure we work with an array later on
|
||||
fileArray.push(fileArg)
|
||||
} else if (Array.isArray(fileArg)) {
|
||||
fileArray = fileArg
|
||||
} else {
|
||||
throw new Error("fileArg has unknown format");
|
||||
throw new Error('fileArg has unknown format')
|
||||
}
|
||||
|
||||
let vinylFileArray:plugins.vinyl[] = []; //we want to have an array of vinylFiles
|
||||
let vinylFileArray: plugins.vinyl[] = [] // we want to have an array of vinylFiles
|
||||
|
||||
for (let fileIndexArg in fileArray){ //convert fileArray in vinylArray
|
||||
let file = fileArray[fileIndexArg];
|
||||
for (let fileIndexArg in fileArray) { // convert fileArray in vinylArray
|
||||
let file = fileArray[fileIndexArg]
|
||||
file instanceof plugins.vinyl ?
|
||||
vinylFileArray.push(file) :
|
||||
vinylFileArray.push(toVinylFileSync(file,{filename:fileIndexArg,base:baseArg}));
|
||||
vinylFileArray.push(toVinylFileSync(file,{filename: fileIndexArg,base: baseArg}))
|
||||
};
|
||||
|
||||
let stream = new Readable({ objectMode: true });
|
||||
for(let vinylFileIndexArg in vinylFileArray){
|
||||
let vinylFile = vinylFileArray[vinylFileIndexArg];
|
||||
stream.push(vinylFile);
|
||||
let stream = new Readable({ objectMode: true })
|
||||
for (let vinylFileIndexArg in vinylFileArray) {
|
||||
let vinylFile = vinylFileArray[vinylFileIndexArg]
|
||||
stream.push(vinylFile)
|
||||
};
|
||||
stream.push(null); //signal end of stream;
|
||||
return stream;
|
||||
};
|
||||
stream.push(null) // signal end of stream;
|
||||
return stream
|
||||
}
|
||||
|
||||
/**
|
||||
* converts file to Object
|
||||
@ -46,26 +48,26 @@ export let toGulpStream = function(fileArg:string|string[]|plugins.vinyl|plugins
|
||||
* @param fileTypeArg
|
||||
* @returns {any|any}
|
||||
*/
|
||||
export let toObject = function(fileStringArg:string,fileTypeArg:string){
|
||||
return SmartfileInterpreter.objectFile(fileStringArg,fileTypeArg);
|
||||
};
|
||||
export let toObject = function(fileStringArg: string,fileTypeArg: string){
|
||||
return SmartfileInterpreter.objectFile(fileStringArg,fileTypeArg)
|
||||
}
|
||||
|
||||
/**
|
||||
* takes a string and converts it to vinyl file
|
||||
* @param fileArg
|
||||
* @param optionsArg
|
||||
*/
|
||||
export let toVinylFileSync = function(fileArg:string,optionsArg?:{filename?:string,base?:string,relPath?:string}){
|
||||
optionsArg? void(0) : optionsArg = {filename: "vinylfile", base: "/"};
|
||||
optionsArg.filename ? void(0) : optionsArg.filename = "vinylfile";
|
||||
optionsArg.base ? void(0) : optionsArg.base = "/";
|
||||
optionsArg.relPath ? void("0") : optionsArg.relPath = "";
|
||||
export let toVinylFileSync = function(fileArg: string,optionsArg?: {filename?: string,base?: string,relPath?: string}){
|
||||
optionsArg ? void(0) : optionsArg = {filename: 'vinylfile', base: '/'}
|
||||
optionsArg.filename ? void(0) : optionsArg.filename = 'vinylfile'
|
||||
optionsArg.base ? void(0) : optionsArg.base = '/'
|
||||
optionsArg.relPath ? void('0') : optionsArg.relPath = ''
|
||||
let vinylFile = new plugins.vinyl({
|
||||
base: optionsArg.base,
|
||||
path: plugins.path.join(optionsArg.base,optionsArg.relPath,optionsArg.filename),
|
||||
contents: new Buffer(fileArg)
|
||||
});
|
||||
return vinylFile;
|
||||
})
|
||||
return vinylFile
|
||||
};
|
||||
|
||||
/**
|
||||
@ -73,21 +75,21 @@ export let toVinylFileSync = function(fileArg:string,optionsArg?:{filename?:stri
|
||||
* @param arrayArg
|
||||
* @param optionsArg
|
||||
*/
|
||||
export let toVinylArraySync = function(arrayArg:string[],optionsArg?:{filename?:string,base?:string,relPath?:string}){
|
||||
let vinylArray = [];
|
||||
for(let stringIndexArg in arrayArg){
|
||||
let myString = arrayArg[stringIndexArg];
|
||||
vinylArray.push(toVinylFileSync(myString,optionsArg));
|
||||
export let toVinylArraySync = function(arrayArg: string[],optionsArg?: {filename?: string,base?: string,relPath?: string}){
|
||||
let vinylArray = []
|
||||
for (let stringIndexArg in arrayArg) {
|
||||
let myString = arrayArg[stringIndexArg]
|
||||
vinylArray.push(toVinylFileSync(myString,optionsArg))
|
||||
}
|
||||
return vinylArray;
|
||||
};
|
||||
return vinylArray
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* takes a vinylFile object and converts it to String
|
||||
*/
|
||||
export let toStringSync = function(fileArg:plugins.vinyl){
|
||||
return fileArg.contents.toString("utf8");
|
||||
export let toStringSync = function(fileArg: plugins.vinyl){
|
||||
return fileArg.contents.toString('utf8')
|
||||
};
|
||||
|
||||
|
||||
@ -97,37 +99,41 @@ export let toStringSync = function(fileArg:plugins.vinyl){
|
||||
* @param fileNameArg
|
||||
* @param fileBaseArg
|
||||
*/
|
||||
export let toFs = function(fileContentArg:string|vinyl,filePathArg){
|
||||
let done = plugins.q.defer();
|
||||
export let toFs = function(fileContentArg: string|vinyl,filePathArg){
|
||||
let done = plugins.q.defer()
|
||||
|
||||
//function checks to abort if needed
|
||||
if (!fileContentArg || !filePathArg) throw new Error("expected valid arguments");
|
||||
// function checks to abort if needed
|
||||
if (!fileContentArg || !filePathArg) {
|
||||
throw new Error('expected valid arguments')
|
||||
}
|
||||
|
||||
// prepare actual write action
|
||||
let fileString:string;
|
||||
let filePath:string = filePathArg;
|
||||
if (fileContentArg instanceof plugins.vinyl){
|
||||
fileString = toStringSync(fileContentArg);
|
||||
} else if (typeof fileContentArg === "string") {
|
||||
fileString = fileContentArg;
|
||||
let fileString: string
|
||||
let filePath: string = filePathArg;
|
||||
if (fileContentArg instanceof plugins.vinyl) {
|
||||
fileString = toStringSync(fileContentArg)
|
||||
} else if (typeof fileContentArg === 'string') {
|
||||
fileString = fileContentArg
|
||||
}
|
||||
plugins.fsExtra.writeFile(filePath,fileString,"utf8",done.resolve);
|
||||
return done.promise;
|
||||
};
|
||||
plugins.fsExtra.writeFile(filePath,fileString,'utf8',done.resolve)
|
||||
return done.promise
|
||||
}
|
||||
|
||||
export let toFsSync = function(fileArg,filePathArg:string){
|
||||
//function checks to abort if needed
|
||||
if (!fileArg || !filePathArg) throw new Error("expected a valid arguments");
|
||||
export let toFsSync = function(fileArg,filePathArg: string){
|
||||
// function checks to abort if needed
|
||||
if (!fileArg || !filePathArg) {
|
||||
throw new Error('expected a valid arguments')
|
||||
}
|
||||
|
||||
// prepare actual write action
|
||||
let fileString:string;
|
||||
let filePath:string = filePathArg;
|
||||
let fileString: string
|
||||
let filePath: string = filePathArg
|
||||
|
||||
if (fileArg instanceof plugins.vinyl){
|
||||
fileString = toStringSync(fileArg);
|
||||
} else if (typeof fileArg === "string") {
|
||||
fileString = fileArg;
|
||||
if (fileArg instanceof plugins.vinyl) {
|
||||
fileString = toStringSync(fileArg)
|
||||
} else if (typeof fileArg === 'string') {
|
||||
fileString = fileArg
|
||||
}
|
||||
plugins.fsExtra.writeFileSync(filePath,fileString,"utf8");
|
||||
};
|
||||
plugins.fsExtra.writeFileSync(filePath,fileString,'utf8')
|
||||
}
|
||||
|
||||
|
@ -1,16 +1,16 @@
|
||||
import "typings-global";
|
||||
export import beautylog = require("beautylog");
|
||||
export import fs = require("fs");
|
||||
export import fsExtra = require("fs-extra");
|
||||
export let gulp = require("gulp");
|
||||
export let glob = require("glob");
|
||||
import 'typings-global'
|
||||
export import beautylog = require('beautylog')
|
||||
export import fs = require('fs')
|
||||
export import fsExtra = require('fs-extra')
|
||||
export let gulp = require('gulp')
|
||||
export let glob = require('glob')
|
||||
export let g = {
|
||||
remoteSrc: require("gulp-remote-src")
|
||||
};
|
||||
export import path = require("path");
|
||||
export import q = require("q");
|
||||
export let vinyl = require("vinyl");
|
||||
export let vinylFile = require("vinyl-file");
|
||||
export let yaml = require("js-yaml");
|
||||
export let request = require("request");
|
||||
export let requireReload = require("require-reload");
|
||||
remoteSrc: require('gulp-remote-src')
|
||||
}
|
||||
export import path = require('path')
|
||||
export import q = require('q')
|
||||
export import vinyl = require('vinyl')
|
||||
export let vinylFile = require('vinyl-file')
|
||||
export let yaml = require('js-yaml')
|
||||
export let request = require('request')
|
||||
export let requireReload = require('require-reload')
|
||||
|
@ -1,65 +1,64 @@
|
||||
import "typings-global";
|
||||
import plugins = require("./smartfile.plugins");
|
||||
import SmartfileInterpreter = require("./smartfile.interpreter");
|
||||
import 'typings-global'
|
||||
import plugins = require('./smartfile.plugins')
|
||||
import SmartfileInterpreter = require('./smartfile.interpreter')
|
||||
|
||||
export let toFs = function(from:string,toPath:string) {
|
||||
var done = plugins.q.defer();
|
||||
var stream = plugins.request(from).pipe(plugins.fsExtra.createWriteStream(toPath));
|
||||
export let toFs = function(from: string,toPath: string) {
|
||||
let done = plugins.q.defer()
|
||||
let stream = plugins.request(from).pipe(plugins.fsExtra.createWriteStream(toPath))
|
||||
stream.on('finish',function(){
|
||||
done.resolve(toPath);
|
||||
});
|
||||
return done.promise;
|
||||
};
|
||||
done.resolve(toPath)
|
||||
})
|
||||
return done.promise
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param filePathArg
|
||||
* @returns {*}
|
||||
*/
|
||||
export let toGulpStreamSync = function(filePathArg:string,baseArg:string){
|
||||
export let toGulpStreamSync = function(filePathArg: string,baseArg: string){
|
||||
let stream = plugins.g.remoteSrc(filePathArg, {
|
||||
base: baseArg
|
||||
});
|
||||
return stream;
|
||||
};
|
||||
})
|
||||
return stream
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param fromArg
|
||||
* @returns {any}
|
||||
*/
|
||||
export let toObject = function(fromArg:string){
|
||||
let done = plugins.q.defer();
|
||||
export let toObject = function(fromArg: string){
|
||||
let done = plugins.q.defer()
|
||||
plugins.request.get(fromArg, function (error, response, bodyString) {
|
||||
let returnObject;
|
||||
if (!error && response.statusCode == 200) {
|
||||
returnObject = SmartfileInterpreter.objectFile(bodyString,SmartfileInterpreter.filetype(fromArg));
|
||||
done.resolve(returnObject);
|
||||
let returnObject
|
||||
if (!error && response.statusCode === 200) {
|
||||
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;
|
||||
};
|
||||
console.log('could not get remote file from ' + fromArg)
|
||||
returnObject = undefined
|
||||
done.reject(returnObject)
|
||||
}
|
||||
})
|
||||
return done.promise
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param fromArg
|
||||
* @returns {any}
|
||||
*/
|
||||
export let toString = (fromArg:string) => {
|
||||
let done = plugins.q.defer();
|
||||
export let toString = (fromArg: string) => {
|
||||
let done = plugins.q.defer()
|
||||
plugins.request.get(fromArg, function (error, response, bodyString) {
|
||||
if (!error && response.statusCode == 200) {
|
||||
done.resolve(bodyString);
|
||||
if (!error && response.statusCode === 200) {
|
||||
done.resolve(bodyString)
|
||||
} else {
|
||||
plugins.beautylog.error('could not get remote file from ' + fromArg);
|
||||
bodyString = undefined;
|
||||
done.reject(bodyString);
|
||||
};
|
||||
});
|
||||
return done.promise;
|
||||
};
|
||||
|
||||
plugins.beautylog.error('could not get remote file from ' + fromArg)
|
||||
bodyString = undefined
|
||||
done.reject(bodyString)
|
||||
}
|
||||
})
|
||||
return done.promise
|
||||
}
|
||||
|
Reference in New Issue
Block a user