From ece8640cb21c758a6d915e07960b48912066403d Mon Sep 17 00:00:00 2001 From: Dimitri Benin Date: Tue, 25 Dec 2018 17:44:17 +0100 Subject: [PATCH] [gfc] Add types --- types/gfc/gfc-tests.ts | 43 ++++++++++++++++++++++++++++++++ types/gfc/index.d.ts | 54 +++++++++++++++++++++++++++++++++++++++++ types/gfc/tsconfig.json | 23 ++++++++++++++++++ types/gfc/tslint.json | 1 + 4 files changed, 121 insertions(+) create mode 100644 types/gfc/gfc-tests.ts create mode 100644 types/gfc/index.d.ts create mode 100644 types/gfc/tsconfig.json create mode 100644 types/gfc/tslint.json diff --git a/types/gfc/gfc-tests.ts b/types/gfc/gfc-tests.ts new file mode 100644 index 0000000000..d1deffaf32 --- /dev/null +++ b/types/gfc/gfc-tests.ts @@ -0,0 +1,43 @@ +import firstCommit = require('gfc'); + +firstCommit({ cwd: 'foo/bar' }); // $ExpectType Promise<{ stdout: string | Buffer; stderr: string | Buffer; }> +firstCommit({ exec: { encoding: 'buffer' } }); // $ExpectType Promise<{ stdout: string | Buffer; stderr: string | Buffer; }> +firstCommit({ exec: { input: 'foo' } }); // $ExpectError +firstCommit({ message: 'foo' }); // $ExpectType Promise<{ stdout: string | Buffer; stderr: string | Buffer; }> +firstCommit({ file: false }); // $ExpectType Promise<{ stdout: string | Buffer; stderr: string | Buffer; }> +firstCommit({ file: { path: 'foo' } }); // $ExpectType Promise<{ stdout: string | Buffer; stderr: string | Buffer; }> +firstCommit({ file: { path: 'foo', contents: 'bar' } }); // $ExpectType Promise<{ stdout: string | Buffer; stderr: string | Buffer; }> +firstCommit({ commit: false }); // $ExpectType Promise<{ stdout: string | Buffer; stderr: string | Buffer; }> +firstCommit({ forceFile: false }); // $ExpectType Promise<{ stdout: string | Buffer; stderr: string | Buffer; }> +firstCommit({ remote: 'foo' }); // $ExpectType Promise<{ stdout: string | Buffer; stderr: string | Buffer; }> +firstCommit({ push: false }); // $ExpectType Promise<{ stdout: string | Buffer; stderr: string | Buffer; }> + +firstCommit().then(res => { + res.stdout; // $ExpectType string | Buffer + res.stderr; // $ExpectType string | Buffer +}); +firstCommit('foo/bar').then(res => { + res.stdout; // $ExpectType string | Buffer + res.stderr; // $ExpectType string | Buffer +}); +firstCommit('foo/bar', { cwd: 'foo/bar' }).then(res => { + res.stdout; // $ExpectType string | Buffer + res.stderr; // $ExpectType string | Buffer +}); +// $ExpectType void +firstCommit('foo/bar', (err, stdout, stderr) => { + err; // $ExpectType ExecException | null + stdout; // $ExpectType string | Buffer + stderr; // $ExpectType string | Buffer +}); +// $ExpectType void +firstCommit('foo/bar', { cwd: 'foo/bar' }, (err, stdout, stderr) => { + err; // $ExpectType ExecException | null + stdout; // $ExpectType string | Buffer + stderr; // $ExpectType string | Buffer +}); + +firstCommit.sync(); // $ExpectType string | Buffer +firstCommit.sync('foo/bar'); // $ExpectType string | Buffer +firstCommit.sync('foo/bar', { exec: { input: 'foo' } }); // $ExpectType string | Buffer +firstCommit.sync({ exec: { input: 'foo' } }); // $ExpectType string | Buffer diff --git a/types/gfc/index.d.ts b/types/gfc/index.d.ts new file mode 100644 index 0000000000..6b5a1009d2 --- /dev/null +++ b/types/gfc/index.d.ts @@ -0,0 +1,54 @@ +// Type definitions for gfc 2.0 +// Project: https://github.com/jonschlinkert/gfc +// Definitions by: BendingBender +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.1 + +/// + +import { ExecOptions, ExecException, ExecSyncOptions } from 'child_process'; + +export = gitFirstCommit; + +declare function gitFirstCommit( + options?: gitFirstCommit.Options +): Promise<{ stdout: string | Buffer; stderr: string | Buffer }>; +declare function gitFirstCommit( + cwd: string, + options?: gitFirstCommit.Options +): Promise<{ stdout: string | Buffer; stderr: string | Buffer }>; +declare function gitFirstCommit( + cwd: string, + callback: ( + error: ExecException | null, + stdout: string | Buffer, + stderr: string | Buffer + ) => void +): void; +declare function gitFirstCommit( + cwd: string, + options: gitFirstCommit.Options, + callback: ( + error: ExecException | null, + stdout: string | Buffer, + stderr: string | Buffer + ) => void +): void; + +declare namespace gitFirstCommit { + function sync(options?: Options): string | Buffer; + function sync(cwd: string, options?: Options): string | Buffer; + + type ExecOptionsWithEncoding = { encoding?: BufferEncoding | 'buffer' | null } & ExecOptions; + + interface Options { + cwd?: string; + exec?: TExecOptions; + message?: string; + file?: { path: string; contents?: string } | false; + commit?: boolean; + forceFile?: boolean; + remote?: string; + push?: boolean; + } +} diff --git a/types/gfc/tsconfig.json b/types/gfc/tsconfig.json new file mode 100644 index 0000000000..bfed10e8ce --- /dev/null +++ b/types/gfc/tsconfig.json @@ -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", + "gfc-tests.ts" + ] +} diff --git a/types/gfc/tslint.json b/types/gfc/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/gfc/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }