From 04a7f91091d8dec8aa718d99f672b864b7977011 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Alvergnat?= Date: Sat, 17 Nov 2018 14:00:17 +0100 Subject: [PATCH] Upgrade to mem-fs-editor 5.1 and export more interfaces --- types/mem-fs-editor/index.d.ts | 62 ++++++++++------------ types/mem-fs-editor/mem-fs-editor-tests.ts | 10 ++-- 2 files changed, 34 insertions(+), 38 deletions(-) diff --git a/types/mem-fs-editor/index.d.ts b/types/mem-fs-editor/index.d.ts index 60f5b51867..179fdadf66 100644 --- a/types/mem-fs-editor/index.d.ts +++ b/types/mem-fs-editor/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for mem-fs-editor 4.0 +// Type definitions for mem-fs-editor 5.1 // Project: https://github.com/SBoudrias/mem-fs-editor#readme // Definitions by: My Food Bag // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped @@ -9,43 +9,39 @@ import * as Buffer from 'buffer'; import { Transform } from 'stream'; import { Store } from 'mem-fs'; -import { Options as TemplateOptions } from 'ejs'; +import { Options as TemplateOptions, Data as TemplateData } from 'ejs'; import { IOptions as GlobOptions } from 'glob'; -export function create(store: Store): memFsEditor.Editor; +type ReplacerFunc = (key: string, value: any) => any; -export namespace memFsEditor { - type Contents = string|Buffer; +type Space = string|number; - type ReplacerFunc = (key: string, value: any) => any; +type Contents = string|Buffer; - type Space = string|number; +type Callback = (err: any) => any; - type ProcessFunc = (contents: Buffer) => Contents; +export type ProcessingFunc = (contents: Buffer, path: string) => Contents; - type Callback = (err: any) => any; - - interface CopyOptions { - process?: ProcessFunc; - globOptions?: GlobOptions; - } - - interface Editor { - read(filepath: string, options?: { raw: boolean, defaults: string }): string; - readJSON(filepath: string, defaults?: any): any; - write(filepath: string, contents: Contents): void; - writeJSON(filepath: string, contents: any, replacer?: ReplacerFunc, space?: Space): void; - append(filepath: string, contents: Contents, options?: { trimEnd: boolean, separator: string }): void; - extendJSON(filepath: string, contents: object, replacer?: ReplacerFunc, space?: Space): void; - delete(filepath: string, options?: { globOptions: GlobOptions }): void; - copy(from: string, to: string, options?: CopyOptions): void; - copyTpl(from: string, to: string, context: object, templateOptions?: TemplateOptions, copyOptions?: CopyOptions): void; - move(from: string, to: string, options?: { globOptions: GlobOptions }): void; - exists(filepath: string): boolean; - commit(callback: Callback): void; - commit(filters: ReadonlyArray, callback: Callback): void; - } - - const prototype: { - }; +export interface CopyOptions { + process?: ProcessingFunc; + globOptions?: GlobOptions; } + +export interface Editor { + read(filepath: string, options?: { raw?: boolean, defaults: string }): string; + readJSON(filepath: string, defaults?: any): any; + exists(filepath: string): boolean; + write(filepath: string, contents: Contents): string; + writeJSON(filepath: string, contents: any, replacer?: ReplacerFunc, space?: Space): string; + append(to: string, contents: Contents, options?: { trimEnd?: boolean, separator?: string }): string; + delete(paths: string|string[], options?: { globOptions?: GlobOptions }): void; + copy(from: string|string[], to: string, options?: CopyOptions, context?: TemplateData, templateOptions?: TemplateOptions): void; + copyTpl(from: string|string[], to: string, context?: TemplateData, templateOptions?: TemplateOptions, copyOptions?: CopyOptions): void; + move(from: string|string[], to: string, options?: { globOptions: GlobOptions }): void; + commit(callback: Callback): void; + commit(filters: ReadonlyArray, callback: Callback): void; +} + +export function create(store: Store): Editor; + +export {}; diff --git a/types/mem-fs-editor/mem-fs-editor-tests.ts b/types/mem-fs-editor/mem-fs-editor-tests.ts index ff3c52c5a0..e000fefb92 100644 --- a/types/mem-fs-editor/mem-fs-editor-tests.ts +++ b/types/mem-fs-editor/mem-fs-editor-tests.ts @@ -1,18 +1,19 @@ import { Transform } from 'stream'; -import memFs = require('mem-fs'); -import editor = require('mem-fs-editor'); +import * as memFs from 'mem-fs'; +import * as editor from 'mem-fs-editor'; const store = memFs.create(); const fs = editor.create(store); fs.write('template.js', 'var a = 1; console.log(\'<%= foo %>\', a);'); +fs.append('template.js', 'var b = 2;'); fs.copy('template.js', 'template.tpl', { - process: (contents) => contents, globOptions: { cwd: '.' - } + }, + process: (contents) => contents }); fs.copyTpl('template.tpl', 'output.js', { @@ -21,7 +22,6 @@ fs.copyTpl('template.tpl', 'output.js', { const obj = fs.readJSON('template.json'); fs.writeJSON('template.json', obj); -fs.extendJSON('template.json', {qwer: 'asdf'}); fs.writeJSON('template.json', 'qwer'); // should not be an error, because the parameter is passed to JSON.stringify and it accepts the string // fs.extendJSON('template.json', 'qwer'); // should be an error, because it does not make sense to extend a json with string