From b94b775e93d30f94ff0b13ecb14f97823d7aa2b7 Mon Sep 17 00:00:00 2001 From: Thanh Ngo Date: Fri, 4 May 2018 11:01:42 -0400 Subject: [PATCH] [idyll] add type declaration for idyll (#25454) * add type declaration for idyll * incorrect export: expected a function export --- types/idyll/idyll-tests.ts | 7 ++ types/idyll/index.d.ts | 130 +++++++++++++++++++++++++++++++++++++ types/idyll/tsconfig.json | 16 +++++ types/idyll/tslint.json | 3 + 4 files changed, 156 insertions(+) create mode 100644 types/idyll/idyll-tests.ts create mode 100644 types/idyll/index.d.ts create mode 100644 types/idyll/tsconfig.json create mode 100644 types/idyll/tslint.json diff --git a/types/idyll/idyll-tests.ts b/types/idyll/idyll-tests.ts new file mode 100644 index 0000000000..3f4b90c18c --- /dev/null +++ b/types/idyll/idyll-tests.ts @@ -0,0 +1,7 @@ +import idyll = require("idyll"); + +// $ExpectType IdyllInstance +idyll({ + watch: true, + datasets: "." +}); diff --git a/types/idyll/index.d.ts b/types/idyll/index.d.ts new file mode 100644 index 0000000000..a2f1846a7a --- /dev/null +++ b/types/idyll/index.d.ts @@ -0,0 +1,130 @@ +// Type definitions for idyll 2.10 +// Project: https://github.com/idyll-lang/idyll/tree/master/packages/idyll-cli +// Definitions by: Thanh Ngo +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.8 + +import { EventEmitter } from "events"; +import { Options as CompilerOptions } from "idyll-compiler"; + +interface Options { + /** + * Monitor input files and rebuild on changes + */ + watch?: boolean; + /** + * The datasets directory + */ + datasets?: string; + /** + * Whether to minify output build + */ + minify?: boolean; + /** + * + * Pre-render HTML as part of the build + */ + ssr?: boolean; + /** + * The components directory + */ + components?: boolean; + /** + * The default component directory + * This corresponds to where the idyll-components package stays + */ + defaultComponents?: boolean; + /** + * The layout defined in idyll-layouts package + */ + layout?: string; + /** + * The theme defined in idyll-theme package + */ + theme?: string; + /** + * The output directory for compiled documents + */ + output?: string; + /** + * Custom port to bind the local server to. + */ + port?: number; + /** + * Temporary directory used by idyll + */ + temp?: string; + /** + * path to HTML template + * + */ + template?: string; + + /** + * Custom CSS file to include in output + */ + css?: string; + /** + * Custom browserify transforms to apply. + */ + transform?: string[]; + /** + * Compiler options + */ + compiler?: CompilerOptions; + /** + * the idyll file to be compiled into + */ + inputFile?: string; + + /** + * used internally by IdyllInstance + */ + inputConfig?: { + components: any; + transform: any[]; + compiler: CompilerOptions; + }; +} + +type PredefinedFile = + | "APP_PATH" + | "CSS_INPUT_FILE" + | "DATA_DIR" + | "HTML_TEMPLATE_FILE" + | "IDYLL_INPUT_FILE" + | "INPUT_DIR" + | "PACKAGE_FILE" + | "OUTPUT_DIR" + | "TMP_DIR" + | "CSS_OUTPUT_FILE" + | "HTML_OUTPUT_FILE" + | "JS_OUTPUT_FILE"; + +type ComponentFiles = "COMPONENT_DIRS" | "DEFAULT_COMPONENT_DIRS"; + +type Paths = Record & Record; + +declare class IdyllInstance extends EventEmitter { + /** + * Returns internal paths used by idyll-cli + */ + getPaths(): Paths; + /** + * Returns idyll compiling's options + */ + getOptions(): Options; + /** + * + * if indexIdyllMarkup is provided, compiles it + * + * Otherwise, compiles and optionally watches + * the idyll file at IOptions.inputFile + * + */ + build(indexIdyllMarkup?: string | null): this; +} + +declare function idyll(options: Options, callback?: () => void): IdyllInstance; + +export = idyll; diff --git a/types/idyll/tsconfig.json b/types/idyll/tsconfig.json new file mode 100644 index 0000000000..6e24200367 --- /dev/null +++ b/types/idyll/tsconfig.json @@ -0,0 +1,16 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": ["es6"], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": ["../"], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true, + "strictFunctionTypes": true + }, + "files": ["index.d.ts", "idyll-tests.ts"] +} diff --git a/types/idyll/tslint.json b/types/idyll/tslint.json new file mode 100644 index 0000000000..f93cf8562a --- /dev/null +++ b/types/idyll/tslint.json @@ -0,0 +1,3 @@ +{ + "extends": "dtslint/dt.json" +}