From 2ea1342b8fcead09a74f1e2264ce267b1849635d Mon Sep 17 00:00:00 2001 From: Phil McCloghry-Laing Date: Thu, 26 Jul 2018 04:52:54 +1000 Subject: [PATCH] Add type definitions for @frctl/fractal (#27555) --- types/frctl__fractal/frctl__fractal-tests.ts | 198 ++++++ types/frctl__fractal/index.d.ts | 700 +++++++++++++++++++ types/frctl__fractal/tsconfig.json | 27 + types/frctl__fractal/tslint.json | 1 + 4 files changed, 926 insertions(+) create mode 100644 types/frctl__fractal/frctl__fractal-tests.ts create mode 100644 types/frctl__fractal/index.d.ts create mode 100644 types/frctl__fractal/tsconfig.json create mode 100644 types/frctl__fractal/tslint.json diff --git a/types/frctl__fractal/frctl__fractal-tests.ts b/types/frctl__fractal/frctl__fractal-tests.ts new file mode 100644 index 0000000000..b641563a45 --- /dev/null +++ b/types/frctl__fractal/frctl__fractal-tests.ts @@ -0,0 +1,198 @@ +// Source: https://fractal.build/guide + +/* Create a new Fractal instance and export it for use elsewhere if required */ +import { create } from '@frctl/fractal'; + +const fractal = create(); + +/* Set the title of the project */ +fractal.set('project.title', 'FooCorp Component Library'); +fractal.set('project.version', 'v1.0'); +fractal.set('project.author', 'Mickey Mouse'); + +/* Tell Fractal where the components will live */ +fractal.components.set('path', __dirname + '/src/components'); + +/* Tell Fractal where the documentation pages will live */ +fractal.docs.set('path', __dirname + '/src/docs'); + +/* Specify a directory of static assets */ +fractal.web.set('static.path', __dirname + '/public'); + +/* Set the static HTML build destination */ +fractal.web.set('builder.dest', __dirname + '/build'); + +// Source: https://fractal.build/guide/components/configuration + +fractal.components.set('default.collated', true); +fractal.components.set('default.collator', (markup: string, item: any) => { + return `\n${markup}\n\n`; +}); +fractal.components.set('default.context', { + 'site-name': 'FooCorp' +}); +fractal.components.set('default.display', { + 'max-width': '400px' +}); +fractal.components.set('default.prefix', 'foobar'); +fractal.components.set('default.preview', '@my-preview-layout'); +fractal.components.set('default.status', 'wip'); +fractal.components.set('ext', '.handlebars'); +fractal.components.set('label', 'Patterns'); +fractal.components.set('path', __dirname + '/src/components'); +fractal.components.set('statuses', { + doing: { + label: "Doing", + description: "I'm doing it.", + color: '#F00' + }, + done: { + label: "Done", + description: "I'm done with this.", + color: "green" + } +}); +fractal.components.set('title', 'Patterns'); +fractal.components.set('yield', 'rendered_content'); + +// Source: https://fractal.build/guide/docs/configuration + +fractal.docs.set('default.context', { + 'site-name': 'FooCorp' +}); +fractal.docs.set('default.prefix', 'foobar'); +fractal.docs.set('default.status', 'wip'); +fractal.docs.set('ext', '.html'); +fractal.docs.set('indexLabel', 'Listing'); +fractal.docs.set('label', 'Pages'); +fractal.docs.set('markdown', false); +fractal.docs.set('markdown.smartypants', false); +fractal.docs.set('path', __dirname + '/src/docs'); +fractal.docs.set('statuses', { + doing: { + label: "Doing", + description: "I'm doing it.", + color: '#F00' + }, + done: { + label: "Done", + description: "I'm done with this.", + color: "green" + } +}); +fractal.docs.set('title', 'Pages'); + +// Source: https://fractal.build/guide/web/configuration + +fractal.web.set('builder.concurrency', 5); +fractal.web.set('builder.dest', __dirname + '/export'); +fractal.web.set('builder.ext', '.php'); +fractal.web.set('builder.urls.ext', null); +fractal.web.set('server.sync', true); +fractal.web.set('server.syncOptions', { + open: true, + browser: ['google chrome', 'firefox'], + notify: true +}); +fractal.web.set('server.port', 4444); +fractal.web.set('server.watch', true); +fractal.web.set('static.path', __dirname + '/public'); +fractal.web.set('static.mount', 'project-assets'); + +// Source: https://fractal.build/guide/cli/custom-commands + +{ + const config = { + description: 'Lists components in the project' + }; + + fractal.cli.command('list-components', function(args, done) { + const app = this.fractal; + for (const item of app.components.flatten()) { + this.log(`${item.handle} - ${item.status.label}`); + } + done(); + }, config); +} + +fractal.cli.exec('list-components'); + +fractal.cli.command('foo [optionalArg] [anotherOptionalArg]', (args, done) => { + console.log(args.requiredArg); + done(); +}); + +{ + const config = { + options: [ + ['-p, --port ', 'The port to use.'], + ] + }; + + fractal.cli.command('foo', (args, done) => { + // do something + console.log(`Something was started on port ${args.options.port}`); + done(); + }, config); +} + +// Source: https://fractal.build/guide/integration/build-tools + +import * as gulp from 'gulp'; +{ + /* + * Configure a Fractal instance. + * + * This configuration could also be done in a separate file, provided that this file + * then imported the configured fractal instance from it to work with in your Gulp tasks. + * i.e. const fractal = require('./my-fractal-config-file'); + */ + + fractal.set('project.title', 'FooCorp Component Library'); // title for the project + fractal.web.set('builder.dest', 'build'); // destination for the static export + fractal.docs.set('path', `${__dirname}/docs`); // location of the documentation directory. + fractal.components.set('path', `${__dirname}/components`); // location of the component directory. + + // any other configuration or customisation here + + const logger = fractal.cli.console; // keep a reference to the fractal CLI console utility + + /* + * Start the Fractal server + * + * In this example we are passing the option 'sync: true' which means that it will + * use BrowserSync to watch for changes to the filesystem and refresh the browser automatically. + * Obviously this is completely optional! + * + * This task will also log any errors to the console. + */ + + gulp.task('fractal:start', () => { + const server = fractal.web.server({ + sync: true + }); + server.on('error', err => logger.error(err.message)); + return server.start().then(() => { + logger.success(`Fractal server is now running at ${server.url}`); + }); + }); + + /* + * Run a static export of the project web UI. + * + * This task will report on progress using the 'progress' event emitted by the + * builder instance, and log any errors to the terminal. + * + * The build destination will be the directory specified in the 'builder.dest' + * configuration option set above. + */ + + gulp.task('fractal:build', () => { + const builder = fractal.web.builder(); + builder.on('progress', (completed, total) => logger.update(`Exported ${completed} of ${total} items`, 'info')); + builder.on('error', err => logger.error(err.message)); + return builder.build().then(() => { + logger.success('Fractal build completed!'); + }); + }); +} diff --git a/types/frctl__fractal/index.d.ts b/types/frctl__fractal/index.d.ts new file mode 100644 index 0000000000..8e88f82948 --- /dev/null +++ b/types/frctl__fractal/index.d.ts @@ -0,0 +1,700 @@ +// Type definitions for @frctl/fractal 1.x +// Project: https://github.com/frctl/fractal +// Definitions by: Phil McCloghry-Laing +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.3 + +import { EventEmitter } from 'events'; +import { Stats as FileStats } from 'fs'; +import { Server as HttpServer } from 'http'; +import { Readable as ReadableStream } from 'stream'; +import * as VinylFile from 'vinyl'; + +export namespace fractal { + namespace core { + interface StatusInfo { + label: string; + description?: string; + color?: string; + } + namespace entities { + abstract class Entity extends mixins.Entity { + readonly isComponent?: true; + readonly isCollection?: true; + readonly isDoc?: true; + readonly isVariant?: true; + readonly status: StatusInfo; + getResolvedContext(): any; + hasContext(): Promise; + setContext(data: any): void; + getContext(): any; + toJSON(): {}; + } + interface EntitySource extends mixins.Source { + entities(): T[]; + + engine(adapterFactory?: string | { + register(source: EntitySource, app: any): Adapter; + } | (() => ({ + register(source: EntitySource, app: any): Adapter; + }))): Adapter; + + getProp(key: string): string | {}; + statusInfo(handle: string): StatusInfo | null; + toJSON(): {}; + } + interface EntityCollection extends mixins.Entity, mixins.Collection { + readonly entities: this; + toJSON(): {}; + } + } + + namespace mixins { + abstract class Configurable { + config(): T; + config(config: T): this; + set(path: K, value: T[K] | null): this; + get(path: K, defaultValue?: V): T[K] | V | null | undefined; + } + /** + * Combined EventEmitter and Configurable mixins + */ + abstract class ConfigurableEmitter extends EventEmitter { } + interface ConfigurableEmitter extends Configurable { } + interface Collection { + readonly isAsset: undefined; + readonly isComponent: undefined; + readonly isCollection: true; + readonly isDoc: undefined; + readonly isFile: undefined; + readonly isVariant: undefined; + readonly size: number; + readonly items: T[]; + toArray(): T[]; + setItems(items: T[]): this; + pushItem(item: T): this; + removeItem(item: T): this; + toJSON(): {}; + toStream(): ReadableStream; + each(fn: (item: T) => void): this; + forEach(fn: (item: T) => void): this; + map(fn: (item: T) => T): this; + first(): T | undefined; + last(): T | undefined; + eq(pos: number): T | undefined; + collections(): this; + orderBy(): this; + find(handle: string): T; + find(name: TKey, value: T[TKey]): T; + findCollection(handle: string): Collection; + findCollection(name: TKey, value: T[TKey]): Collection; + flatten(): this; + flattenDeep(): this; + squash(): this; + filter(handle: string): T[]; + filter(name: TKey, value: T[TKey]): T[]; + filterItems(items: T[], handle: string): T[]; + filterItems(items: T[], name: TKey, value: T[TKey]): T[]; + flattenItems(items: T[], deep?: boolean): T[]; + squashItems(items: T[]): T[]; + newSelf(items: T[]): this; + [Symbol.iterator](): IterableIterator; + } + abstract class Entity { + initEntity(name: string, config: any, parent: Entity): void; + name: string; + handle: string; + label: string; + title: string; + order: number; + id: string; + config: any; + readonly alias: string | null; + readonly source: entities.EntitySource; + readonly parent: Entity; + readonly isHidden: boolean; + toJSON(): {}; + } + interface Source extends ConfigurableEmitter, Collection { + readonly label: string; + readonly title: string; + readonly source: this; + readonly isWatching: boolean; + readonly fullPath: string | null; + readonly relPath: string; + toStream(): ReadableStream; + exists(): boolean; + load(force?: boolean): Promise; + refresh(): Promise; + watch(): void; + unwatch(): void; + isConfig(file: string): boolean; + } + } + } + + namespace api { + namespace assets { + class Asset extends core.entities.Entity { + readonly isAsset: true; + readonly isComponent: undefined; + readonly isCollection: undefined; + readonly isDoc: undefined; + readonly isFile: undefined; + readonly isVariant: undefined; + toVinyl(): VinylFile; + } + interface AssetCollection extends core.entities.EntityCollection { + assets(): this; + toVinylArray(): VinylFile[]; + } + interface AssetSource extends core.mixins.Source { + assets(): VinylFile[]; + toVinylArray(): VinylFile[]; + toVinylStream(): ReadableStream; + gulpify(): ReadableStream; + } + interface AssetSourceCollection extends core.mixins.ConfigurableEmitter { + readonly label: string; + readonly title: string; + add(name: string, config: any): AssetSource; + remove(name: string): this; + find(name: string): AssetSource | undefined; + sources(): AssetSource[]; + toArray(): AssetSource[]; + visible(): AssetSource[]; + watch(): this; + unwatch(): this; + load(): Promise; + toJSON(): {}; + [Symbol.iterator](): IterableIterator; + } + } + + namespace components { + class Component extends core.entities.Entity { + constructor(config: {}, files: files.FileCollection, resources: assets.AssetCollection, parent: core.entities.Entity); + readonly isAsset: undefined; + readonly isComponent: true; + readonly isCollection: undefined; + readonly isDoc: undefined; + readonly isFile: undefined; + readonly isVariant: undefined; + defaultName: string; + lang: string; + editorMode: string; + editorScope: string; + viewPath: string; + viewDir: string; + configData: string; + relViewPath: string; + isCollated(): boolean; + readonly content: string; + readonly references: any[]; + readonly referencedBy: any[]; + readonly baseHandle: string; + readonly notes: string; + render(context: any, env: any, opts: any): Promise; + getPreviewContext(): Promise; + getPreviewContent(): Promise; + setVariants(variantCollection: variants.VariantCollection): void; + hasTag(tag: string): boolean; + resources(): assets.AssetCollection; + resourcesJSON(): {}; + flatten(): variants.VariantCollection; + component(): this; + variants(): variants.VariantCollection; + static create(config: {}, files: files.FileCollection, resources: assets.AssetCollection, parent: core.entities.Entity): IterableIterator<{} | variants.VariantCollection | Component>; + } + interface ComponentCollection extends core.entities.EntityCollection { + components(): this; + variants(): this; + } + type Collator = (markup: string, item: { handle: string; }) => string; + interface ComponentDefaultConfig { + collated?: boolean; + collator?: Collator; + context?: any; + display?: any; + prefix?: string; + preview?: string; + status?: string; + } + interface ComponentConfig { + path?: string; + ext?: string; + default?: ComponentDefaultConfig; + label?: string; + statuses?: { + [status: string]: core.StatusInfo; + }; + title?: string; + yield?: string; + 'default.collated'?: boolean; + 'default.collator'?: Collator; + 'default.context'?: any; + 'default.display'?: any; + 'default.prefix'?: string; + 'default.preview'?: string; + 'default.status'?: string; + } + interface ComponentSource extends core.entities.EntitySource { + resources(): files.FileCollection; + components(): Component[]; + getReferencesOf(target: { id: string; handle: string; alias: string; }): any[]; + variants(): this; + find(): any; + findFile(filePath: string): files.File | undefined; + resolve(context: any): any; + renderString(str: string, context: any, env: any): Promise; + renderPreview(entity: string | core.entities.Entity, preview?: boolean, env?: any): Promise; + render(entity: string | core.entities.Entity, context: any, env?: any, opts?: {}): Promise; + } + } + namespace docs { + class Doc extends core.entities.Entity { + constructor(config: any, content: string, parent: core.entities.Entity); + readonly isAsset: undefined; + readonly isComponent: undefined; + readonly isCollection: undefined; + readonly isDoc: true; + readonly isFile: undefined; + readonly isVariant: undefined; + readonly isIndex: boolean; + getContent(): Promise; + getContentSync(): string; + render(context: any, env?: any, opts?: any): Promise; + toc(maxDepth?: number): Promise; + static create(config: any, content: string, parent: core.entities.Entity): Doc; + } + interface DocCollection extends core.entities.EntityCollection { + pages(): this; + } + interface DocDefaultConfig { + context?: any; + prefix?: string; + status?: string; + } + interface DocMarkdownConfig { + gfm?: boolean; + tables?: boolean; + breaks?: boolean; + pedantic?: boolean; + sanitize?: boolean; + smartLists?: boolean; + smartypants?: boolean; + } + interface DocConfig { + default?: DocDefaultConfig; + ext?: string; + indexLabel?: string; + label?: string; + markdown?: boolean | DocMarkdownConfig; + path?: string; + statuses?: { + [status: string]: core.StatusInfo; + }; + title?: string; + 'default.context'?: any; + 'default.prefix'?: string; + 'default.status'?: string; + 'markdown.gfm'?: boolean; + 'markdown.tables'?: boolean; + 'markdown.breaks'?: boolean; + 'markdown.pedantic'?: boolean; + 'markdown.sanitize'?: boolean; + 'markdown.smartLists'?: boolean; + 'markdown.smartypants'?: boolean; + } + interface DocSource extends core.entities.EntitySource { + pages(): this; + docs(): this; + resolve(context: any): any; + toc(page: files.File, maxDepth?: number): Promise; + render(page: string | files.File, context?: any, env?: any, opts?: {}): Promise; + renderString(str: string, context: any, env?: any): Promise; + isPage(file: string): boolean; + isTemplate(file: string): boolean; + } + } + namespace files { + interface FileCollection extends core.mixins.Collection { + files(): this; + match(test: string | RegExp | Array): this; + matchItems(items: core.mixins.Collection, test: string | RegExp | Array): File; + toVinylArray(): VinylFile[]; + toVinylStream(): ReadableStream; + gulpify(): ReadableStream; + } + interface File { + readonly isAsset: undefined; + readonly isComponent: undefined; + readonly isCollection: undefined; + readonly isDoc: undefined; + readonly isFile: true; + readonly isVariant: undefined; + id: string; + path: string; + cwd: string; + relPath: string; + base: string; + dir: string; + handle: string; + name: string; + ext: string; + stat: FileStats | null; + lang: string; + editorMode: string; + editorScope: string; + githubColor: string; + isBinary: boolean; + mime: string; + getContext(): any; + readonly contents: Buffer; + readonly isImage: boolean; + getContent(): Promise; + getContentSync(): string; + read(): Promise; + readSync(): string; + toVinyl(): VinylFile; + } + } + namespace variants { + class Variant extends core.entities.Entity { + constructor(config: {}, view: any, resources: assets.AssetCollection, parent: components.Component); + readonly isAsset: undefined; + readonly isComponent: undefined; + readonly isCollection: undefined; + readonly isDoc: undefined; + readonly isFile: true; + readonly isVariant: true; + view: any; + viewPath: string; + viewDir: string; + relViewPath: string; + isDefault: boolean; + lang: string; + editorMode: string; + editorScope: string; + readonly notes: string; + readonly alias: string | null; + readonly siblings: VariantCollection; + readonly content: string; + readonly baseHandle: string; + readonly references: any[]; + readonly referencedBy: any[]; + render(context: any, env?: any, opts?: any): Promise; + getPreviewContext(): Promise; + getPreviewContent(): Promise; + component(): components.Component; + variant(): this; + defaultVariant(): this; + resources(): assets.AssetCollection; + resourcesJSON(): {}; + getContent(): Promise; + getContentSync(): string; + static create(config: {}, view: any, resources: assets.AssetCollection, parent: components.Component): Variant; + } + interface VariantCollection extends core.entities.EntityCollection { + default(): Variant; + getCollatedContent(): Promise; + getCollatedContentSync(): string; + getCOllatedContext(): Promise; + readonly references: any[]; + readonly referencedBy: any[]; + } + } + } + + namespace cli { + class Cli { + console: Console; + notify: Notifier; + has(command: string): boolean; + get(command: string): any; + isInteractive(): boolean; + command( + commandString: string, + callback: (this: Cli & { fractal: Fractal }, args: any, done: () => void) => void, opts?: string | { + description?: string; + options?: string[][]; + }): void; + exec(command: string): void; + log(message: string): void; + error(message: string): void; + } + class Console { + theme: CliTheme; + br(): this; + log(text: string): this; + debug(text: string, data?: any): this; + success(text: string): this; + warn(text: string): this; + update(text: string, type?: string): this; + clear(): this; + persist(): this; + error(err: Error): this; + error(err: string, data: Error): this; + dump(data: any): void; + box(header?: string, body?: string[], footer?: string): this; + write(str: string, type?: string): void; + columns(data: any, options?: any): this; + slog(): this; + unslog(): this; + isSlogging(): boolean; + debugMode(status: boolean): void; + } + class Notifier { + updateAvailable(details: { + current: string; + latest: string; + name: string; + }): void; + versionMismatch(details: { + cli: string; + local: string; + }): void; + } + } + + namespace web { + class Builder extends EventEmitter { + /** + * @deprecated Use start() instead. + */ + build(): Promise<{ errorCount: number; }>; + start(): Promise<{ errorCount: number; }>; + stop(): void; + use(): void; + } + class Server extends EventEmitter { + readonly isSynced: boolean; + readonly port?: number; + readonly ports: { + sync?: number; + server?: number; + }; + readonly url?: string; + readonly urls: { + sync?: { + local?: string; + external?: string; + ui?: string; + }; + server?: string; + }; + start(sync?: boolean): Promise; + stop(): void; + use(mount: string, middleware: any): void; + } + interface WebServerSyncOptions { + open?: boolean; + browser?: string[]; + notify?: boolean; + } + interface WebServerConfig { + sync?: boolean; + syncOptions?: WebServerSyncOptions; + port?: number; + watch?: boolean; + theme?: WebTheme | string; + } + interface WebBuilderUrls { + ext?: string; + } + interface WebBuilderConfig { + concurrency?: number; + dest?: string; + ext?: string; + urls?: WebBuilderUrls; + theme?: WebTheme | string; + } + interface WebStaticConfig { + path?: string; + mount?: string; + } + interface WebConfig { + builder?: WebBuilderConfig; + server?: WebServerConfig; + static?: WebStaticConfig; + 'builder.concurrency'?: number; + 'builder.dest'?: string; + 'builder.ext'?: string; + 'builder.urls'?: WebBuilderUrls; + 'builder.urls.ext'?: string; + 'builder.theme'?: WebTheme | string; + 'server.sync'?: boolean; + 'server.syncOptions'?: WebServerSyncOptions; + 'server.syncOptions.open'?: boolean; + 'server.syncOptions.browser'?: string[]; + 'server.syncOptions.notify'?: boolean; + 'server.port'?: number; + 'server.watch'?: boolean; + 'server.theme'?: WebTheme | string; + 'static.path'?: string; + 'static.mount'?: string; + } + class Web extends core.mixins.ConfigurableEmitter { + server(config?: WebServerConfig): Server; + builder(config?: WebBuilderConfig): Builder; + theme(name: string, instance?: WebTheme): this; + defaultTheme(): WebTheme; + defaultTheme(instance: WebTheme): this; + } + } + + const Fractal: { + new: Fractal; + }; +} + +export interface FractalConfig { + project?: { + title?: string; + version?: string; + author?: string; + }; + 'project.title'?: string; + 'project.version'?: string; + 'project.author'?: string; +} + +export function create(config?: FractalConfig): Fractal; + +export class Fractal extends fractal.core.mixins.ConfigurableEmitter { + constructor(config?: FractalConfig); + readonly components: fractal.api.components.ComponentSource; + readonly docs: fractal.api.docs.DocSource; + readonly assets: fractal.api.assets.AssetSourceCollection; + readonly cli: fractal.cli.Cli; + readonly web: fractal.web.Web; + readonly version: string; + readonly debug: boolean; + + extend(plugin: string | ((this: this, core: any) => void)): this; + + watch(): this; + unwatch(): this; + + load(): Promise; +} + +export interface CliThemeConfig { + delimiter?: { + text?: string; + format?: (str: string) => string; + }; + styles?: { + [key: string]: any; + }; + 'delimiter.text'?: string; + 'delimiter.format'?: (str: string) => string; +} +export class CliTheme extends fractal.core.mixins.ConfigurableEmitter { + constructor(config?: CliThemeConfig); + setDelimiter(text: string, formatter: (str: string) => string): void; + delimiter(): string; + setStyle(name: string, opts: any): void; + style(name: string): any; + format(str: string, style?: string, strip?: boolean): string; +} + +export interface WebThemeOptions { + skin?: string; + panels?: string[]; + rtl: boolean; + lang?: string; + styles?: string[]; + scripts?: string[]; + format?: string; + static?: { + mount?: string; + }; + version?: string; + favicon?: string; + nav?: string[]; + 'static.mount': string; +} +export class WebTheme extends fractal.core.mixins.ConfigurableEmitter { + constructor(viewPaths: string[], options?: WebThemeOptions); + options(): WebThemeOptions; + options(value: WebThemeOptions): this; + setOption(key: K, value: WebThemeOptions[K]): this; + getOption(key: K): WebThemeOptions[K]; + addLoadPath(path: string): this; + loadPaths(): string[]; + setErrorView(view: string): void; + errorView(): string; + setRedirectView(view: string): void; + redirectView(): string; + addStatic(path: string, mount: string): void; + static(): Array<{ path: string; mount: string; }>; + addRoute(path: string, opts: { + handle?: string; + }, resolver?: any): this; + addResolver(handle: string, resolvers: any): this; + routes(): any[]; + resolvers(): any; + matchRoute(urlPath: string): { + route: { + handle: string; + view: string; + }; + params: any; + } | false; + urlFromRoute(handle: string, params: any, noRedirect?: boolean): string | null; +} + +export abstract class Adapter extends EventEmitter { + constructor(engine: TEngine, source: fractal.core.entities.EntitySource); + protected _source: fractal.core.entities.EntitySource; + readonly engine: TEngine; + readonly views: Array<{ + handle: string; + path: string; + content: string; + }>; + setHandlePrefix(prefix: string): this; + load(): void; + getReferencesForView(handle: string): any[]; + getView(handle: string): any; + + protected _resolve(value: PromiseLike | T): Promise; + + abstract render(path: string, str: string, context: any, meta: any): Promise; +} + +export namespace utils { + function lang(filePath: string): { + name: string, + mode: string, + scope: string | null, + color: string | null, + }; + function titlize(str: string): string; + function slugify(str: string): string; + function toJSON(item: any): {}; + function escapeForRegexp(str: string): string; + function parseArgv(): { + command: string; + args: string[]; + opts: any; + }; + function stringify(data: any, indent?: number): string; + function fileExistsSync(path: string): boolean; + function isPromise(value: T | PromiseLike): value is PromiseLike; + function isPromise(value: any): value is PromiseLike; + function md5(str: string): string; + function mergeProp(prop: any, upstream: any): any; + function defaultsDeep(...args: T[]): T; + function relUrlPath(toPath: string, fromPath: string, opts?: any): string; +} + +export namespace core { + type Component = fractal.api.components.Component; + const Component: typeof fractal.api.components.Component; + type Variant = fractal.api.variants.Variant; + const Variant: typeof fractal.api.variants.Variant; + type Doc = fractal.api.docs.Doc; + const Doc: typeof fractal.api.docs.Doc; +} diff --git a/types/frctl__fractal/tsconfig.json b/types/frctl__fractal/tsconfig.json new file mode 100644 index 0000000000..7ef7117640 --- /dev/null +++ b/types/frctl__fractal/tsconfig.json @@ -0,0 +1,27 @@ +{ + "compilerOptions": { + "module": "commonjs", + "target": "es6", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true, + "paths": { + "@frctl/fractal": ["frctl__fractal"] + } + }, + "files": [ + "index.d.ts", + "frctl__fractal-tests.ts" + ] +} diff --git a/types/frctl__fractal/tslint.json b/types/frctl__fractal/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/frctl__fractal/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }