Add typings for mem-fs-editor (#24886)

* Add mem-fs-editor

* Tidy up imports

* wip

* Typings for mem-fs-editor

* Change type to ReadonlyArray<Transform>

* Bump minimum TypeScript version based on requirements of EJS

* revert

* ...
This commit is contained in:
Walter Rumsby
2018-04-12 06:43:07 +12:00
committed by Mohamed Hegazy
parent 53714e16a5
commit b46ec025ce
4 changed files with 90 additions and 0 deletions

48
types/mem-fs-editor/index.d.ts vendored Normal file
View File

@@ -0,0 +1,48 @@
// Type definitions for mem-fs-editor 4.0
// Project: https://github.com/SBoudrias/mem-fs-editor#readme
// Definitions by: My Food Bag <https://github.com/MyFoodBag>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.4
/// <reference types="node" />
import * as Buffer from 'buffer';
import { Transform } from 'stream';
import { Store } from 'mem-fs';
import { Options as TemplateOptions } from 'ejs';
import { IOptions as GlobOptions } from 'glob';
export function create(store: Store): memFsEditor.Editor;
export namespace memFsEditor {
type Contents = string|Buffer;
type ReplacerFunc = (key: string, value: any) => string|null|undefined;
type Space = string|number;
type ProcessFunc = (contents: Buffer) => Contents;
interface CopyOptions {
process?: ProcessFunc;
globOptions?: GlobOptions;
}
interface Editor {
read: (filepath: string, options?: { raw: boolean, defaults: string }) => string;
readJSON: (filepath: string, defaults?: string) => string;
write: (filepath: string, contents: Contents) => void;
writeJSON: (filepath: string, contents: object, 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: (filters: ReadonlyArray<Transform>, callback: () => void) => void;
}
const prototype: {
};
}

View File

@@ -0,0 +1,18 @@
import memFs = require('mem-fs');
import editor = require('mem-fs-editor');
const store = memFs.create();
const fs = editor.create(store);
fs.write('template.js', 'var a = 1; console.log(\'<%= foo %>\', a);');
fs.copy('template.js', 'template.tpl', {
process: (contents) => contents,
globOptions: {
cwd: '.'
}
});
fs.copyTpl('template.tpl', 'output.js', {
foo: 'bar'
});

View File

@@ -0,0 +1,23 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"mem-fs-editor-tests.ts"
]
}

View File

@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }