diff --git a/promised-temp/index.d.ts b/promised-temp/index.d.ts new file mode 100644 index 0000000000..e7dc2556b7 --- /dev/null +++ b/promised-temp/index.d.ts @@ -0,0 +1,24 @@ +// Type definitions for promised-temp 0.1 +// Project: https://www.npmjs.com/package/promised-temp, https://github.com/mikaturunen/promised-temp +// Definitions by: Saqib Rokadia +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/// + +import * as fs from 'fs'; +import { AffixOptions, OpenFile, Stats } from "temp"; +export { AffixOptions, OpenFile, Stats } from "temp"; + +interface TempStatic { + dir: string; + track(value?: boolean): TempStatic; + + path(affixes?: string | AffixOptions, defaultPrefix?: string): string; + mkdir(affixes?: string | AffixOptions): Promise; + open(affixes?: string | AffixOptions): Promise; + cleanup(): Promise; + createWriteStream(affixes?: string | AffixOptions): Promise; +} + +declare var PromisedTemp: TempStatic; +export default PromisedTemp; diff --git a/promised-temp/package.json b/promised-temp/package.json new file mode 100644 index 0000000000..55849714d6 --- /dev/null +++ b/promised-temp/package.json @@ -0,0 +1,6 @@ +{ + "dependencies": { + "@types/temp": "latest", + "@types/node": "latest" + } +} diff --git a/promised-temp/promised-temp-tests.ts b/promised-temp/promised-temp-tests.ts new file mode 100644 index 0000000000..2b77184e25 --- /dev/null +++ b/promised-temp/promised-temp-tests.ts @@ -0,0 +1,59 @@ + +/// + +import * as fs from "fs"; +import temp from 'promised-temp'; +import { AffixOptions, OpenFile, Stats } from "promised-temp"; + +function testCleanup() { + temp.cleanup().then((result: boolean | Stats) => { + if (typeof result === "boolean") { + const x = result === true; + } + else { + const { files, dirs } = result; + files.toPrecision(4); + } + }); +} + +function testOpen() { + temp.open({ dir: "tempDir", prefix: "pref", suffix: "suff" }).then((result: OpenFile) => { + const { path, fd } = result; + path.length; + fd.toPrecision(5); + }); + + temp.open("strPrefix").then((result: OpenFile) => { + const { path, fd } = result; + path.length; + fd.toPrecision(5); + }); +} + +function testCreateWriteStream() { + const stream = + temp.createWriteStream("HelloStreamAffix") + .then((stream: fs.WriteStream) => stream.write("data")); + + const stream2 = temp.createWriteStream(); +} + +function testMkdir() { + temp.mkdir("prefix").then((dirPath: string) => { + dirPath.length; + }); +} + +function testPath() { + const p = temp.path({ suffix: "justSuffix" }, "defaultPrefix"); + p.length; + const p2: string = temp.path("prefix"); + const p3: string = temp.path({ prefix: "prefix" }); +} + +function testTrack() { + const tempChained = temp.track().track(true).track(false); + tempChained.dir; + tempChained.cleanup(); +} diff --git a/promised-temp/tsconfig.json b/promised-temp/tsconfig.json new file mode 100644 index 0000000000..e1c7a3aef8 --- /dev/null +++ b/promised-temp/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6", + "dom" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": false, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "promised-temp-tests.ts" + ] +} diff --git a/promised-temp/tslint.json b/promised-temp/tslint.json new file mode 100644 index 0000000000..f9e30021f4 --- /dev/null +++ b/promised-temp/tslint.json @@ -0,0 +1,3 @@ +{ + "extends": "../tslint.json" +}