added tests for Smartfile instance
This commit is contained in:
@ -4,7 +4,7 @@ export interface ISmartfileConstructorOptions {
|
||||
path?: string
|
||||
contentString?: string
|
||||
contentBuffer?: Buffer
|
||||
cwd?: string
|
||||
base?: string
|
||||
}
|
||||
|
||||
/**
|
||||
@ -17,11 +17,6 @@ export class Smartfile {
|
||||
*/
|
||||
path: string
|
||||
|
||||
/**
|
||||
* gulp-compatibility: alias of this.contentBuffer
|
||||
*/
|
||||
contents: Buffer
|
||||
|
||||
/**
|
||||
* the content of the file as Buffer
|
||||
*/
|
||||
@ -30,7 +25,7 @@ export class Smartfile {
|
||||
/**
|
||||
* The current working directory of the file
|
||||
*/
|
||||
cwd: string
|
||||
base: string
|
||||
|
||||
/**
|
||||
* sync the file with disk
|
||||
@ -44,23 +39,13 @@ export class Smartfile {
|
||||
constructor (optionsArg: ISmartfileConstructorOptions) {
|
||||
if (optionsArg.contentBuffer) {
|
||||
this.contentBuffer = optionsArg.contentBuffer
|
||||
this.contents = optionsArg.contentBuffer
|
||||
} else if (optionsArg.contentString) {
|
||||
this.contentBuffer = optionsArg.contentBuffer
|
||||
this.contents = Buffer.from(optionsArg.contentString)
|
||||
this.setContentsFromString(optionsArg.contentString)
|
||||
} else {
|
||||
console.log('created empty Smartfile?')
|
||||
}
|
||||
this.path = optionsArg.path
|
||||
this.cwd = optionsArg.cwd
|
||||
}
|
||||
|
||||
/**
|
||||
* return relative path of file
|
||||
* ->
|
||||
*/
|
||||
get relative () {
|
||||
return ''
|
||||
this.base = optionsArg.base
|
||||
}
|
||||
|
||||
|
||||
@ -84,4 +69,59 @@ export class Smartfile {
|
||||
*/
|
||||
async read () {
|
||||
}
|
||||
|
||||
// -----------------------------------------------
|
||||
// vinyl compatibility
|
||||
// -----------------------------------------------
|
||||
/**
|
||||
* vinyl-compatibility: alias of this.contentBuffer
|
||||
*/
|
||||
get contents (): Buffer {
|
||||
return this.contentBuffer
|
||||
}
|
||||
set contents (contentsArg) {
|
||||
this.contentBuffer = contentsArg
|
||||
}
|
||||
|
||||
/**
|
||||
* vinyl-compatibility
|
||||
*/
|
||||
get cwd () {
|
||||
return this.base
|
||||
}
|
||||
|
||||
/**
|
||||
* return relative path of file
|
||||
*/
|
||||
get relative (): string {
|
||||
return this.path
|
||||
}
|
||||
|
||||
/**
|
||||
* return truw when the file has content
|
||||
*/
|
||||
isNull (): boolean {
|
||||
if (!this.contentBuffer) {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
/**
|
||||
* return true if contents are Buffer
|
||||
*/
|
||||
isBuffer (): boolean {
|
||||
if (this.contents instanceof Buffer) {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
isDirectory () {
|
||||
return false
|
||||
}
|
||||
|
||||
isStream () {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
@ -221,10 +221,11 @@ export let fileTreeToObject = async (dirPathArg: string, miniMatchFilter: string
|
||||
let smartfileArray: Smartfile[] = []
|
||||
for (let filePath of fileTree) {
|
||||
smartfileArray.push(new Smartfile({
|
||||
path: filePath,
|
||||
contentBuffer: new Buffer(toStringSync(
|
||||
plugins.path.join(dirPath, filePath)
|
||||
))
|
||||
)),
|
||||
base: dirPath,
|
||||
path: filePath
|
||||
}))
|
||||
}
|
||||
return smartfileArray
|
||||
|
Reference in New Issue
Block a user