switch to smartq

This commit is contained in:
2017-01-21 00:47:48 +01:00
parent bf618512e2
commit 353058ed73
13 changed files with 136 additions and 138 deletions

View File

@ -30,7 +30,7 @@ export let fileExistsSync = function(filePath): boolean {
*/
export let fileExists = function(filePath){
let done = plugins.q.defer()
plugins.fs.access(filePath, plugins.fs.R_OK, function (err) {
plugins.fs.access(filePath, 4, function (err) {
err ? done.reject(err) : done.resolve()
})
return done.promise
@ -117,7 +117,7 @@ export let ensureEmptyDirSync = (dirPathArg: string) => {
* @returns Promise<void>
* @exec ASYNC
*/
export let ensureFile = (filePathArg, initFileStringArg): plugins.q.Promise<void> => {
export let ensureFile = (filePathArg, initFileStringArg): Promise<void> => {
let done = plugins.q.defer<void>()
ensureFileSync(filePathArg, initFileStringArg)
done.resolve()
@ -142,7 +142,7 @@ export let ensureFileSync = (filePathArg: string, initFileStringArg: string): vo
/**
* removes a file or folder from local disk
*/
export let remove = function(pathArg: string): plugins.q.Promise<void> {
export let remove = function(pathArg: string): Promise<void> {
let done = plugins.q.defer<void>()
plugins.fsExtra.remove(pathArg,function(){
done.resolve()
@ -162,11 +162,11 @@ export let removeSync = function(pathArg: string): boolean{
* removes an array of filePaths from disk
*/
export let removeMany = function(filePathArrayArg: string[]){
let promiseArray: plugins.q.Promise<void>[] = []
let promiseArray: Promise<void>[] = []
for (let filePath of filePathArrayArg) {
promiseArray.push(remove(filePath))
}
return plugins.q.all(promiseArray)
return Promise.all(promiseArray)
}
/**
@ -297,7 +297,7 @@ export let listFilesSync = function(pathArg: string, regexFilter?: RegExp): stri
* 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[]> {
export let listAllItems = function(pathArg: string, regexFilter?: RegExp): Promise<string[]> {
let done = plugins.q.defer<string[]>()
let allItmesArray = plugins.fsExtra.readdirSync(pathArg)
if (regexFilter) {
@ -331,7 +331,7 @@ export let listAllItemsSync = function(pathArg: string, regexFilter?: RegExp): s
* note: if the miniMatch Filter is an absolute path, the cwdArg will be omitted
* @returns Promise<string[]> string array with the absolute paths of all matching files
*/
export let listFileTree = (dirPathArg: string, miniMatchFilter: string): plugins.q.Promise<string[]> => {
export let listFileTree = (dirPathArg: string, miniMatchFilter: string): Promise<string[]> => {
let done = plugins.q.defer<string[]>()
// handle absolute miniMatchFilter

View File

@ -4,7 +4,7 @@ import plugins = require('./smartfile.plugins')
import SmartfileInterpreter = require('./smartfile.interpreter')
let vinyl = require('vinyl')
export interface vinyl {
export interface IVinylFile {
contents: Buffer
base: string
path: string,
@ -19,10 +19,10 @@ let Readable = require('stream').Readable
* @returns stream.Readable
* @TODO: make it async;
*/
export let toGulpStream = function(fileArg: string|string[]|vinyl|vinyl[],baseArg: string = '/'){
export let toGulpStream = function(fileArg: string|string[]|IVinylFile|IVinylFile[],baseArg: string = '/'){
let fileArray = []
if (typeof fileArg === 'string' || fileArg instanceof vinyl) { // make sure we work with an array later on
if (typeof fileArg === 'string' || vinyl.isVinyl(fileArg)) { // make sure we work with an array later on
fileArray.push(fileArg)
} else if (Array.isArray(fileArg)) {
fileArray = fileArg
@ -30,7 +30,7 @@ export let toGulpStream = function(fileArg: string|string[]|vinyl|vinyl[],baseAr
throw new Error('fileArg has unknown format')
}
let vinylFileArray: vinyl[] = [] // we want to have an array of vinylFiles
let vinylFileArray: IVinylFile[] = [] // we want to have an array of vinylFiles
for (let fileIndexArg in fileArray) { // convert fileArray in vinylArray
let file = fileArray[fileIndexArg]
@ -100,7 +100,7 @@ export let toVinylArraySync = function(
/**
* takes a vinylFile object and converts it to String
*/
export let vinylToStringSync = function(fileArg: vinyl){
export let vinylToStringSync = function(fileArg: IVinylFile): string {
return fileArg.contents.toString('utf8')
}
@ -110,7 +110,7 @@ export let vinylToStringSync = function(fileArg: vinyl){
* @param fileNameArg
* @param fileBaseArg
*/
export let toFs = function(fileContentArg: string|vinyl,filePathArg){
export let toFs = function(fileContentArg: string|IVinylFile,filePathArg){
let done = plugins.q.defer()
// function checks to abort if needed
@ -121,8 +121,9 @@ export let toFs = function(fileContentArg: string|vinyl,filePathArg){
// prepare actual write action
let fileString: string
let filePath: string = filePathArg
if (fileContentArg instanceof vinyl) {
fileString = vinylToStringSync(fileContentArg)
if (vinyl.isVinyl(fileContentArg)) {
let fileContentArg2: any = fileContentArg
fileString = vinylToStringSync(fileContentArg2)
} else if (typeof fileContentArg === 'string') {
fileString = fileContentArg
}

View File

@ -4,7 +4,7 @@ export import fs = require('fs')
export import fsExtra = require('fs-extra')
export let glob = require('glob')
export import path = require('path')
export import q = require('q')
export import q = require('smartq')
export let request = require('request')
export let requireReload = require('require-reload')
export import smartpath = require('smartpath')