Skip to content

Latest commit

 

History

History
178 lines (130 loc) · 3.26 KB

javascript-api.md

File metadata and controls

178 lines (130 loc) · 3.26 KB
eleventyNavigation
order
-1

JavaScript API

Methods

getMockData

Returns the resolved mock data as a plain JSON object.

Options

{
	component: String, // Required — Path to the component directory, relative from config.components.folder.
	variant: String // Optional — Variant name. If omitted, the default variant is used.
}

Response

Promise<{
	success: Boolean,
	data: null|Object|Array, // The resolved mock data
	message: String // Optional — Error message in case that no mock data could be returned
}>

getHtml

Returns the rendered variant as a string of HTML.

Options

{
	component: String, // Required — Path to the component directory, relative from config.components.folder.
	variant: String // Optional — Variant name. If omitted, the default variant is used.
}

Response

Promise<{
	success: Boolean,
	data: null|String, // Optional — The HTML string
	message: String // Optional — Error message in case that no HTML could be returned
}>

createMockData

Creates a mock data file based on the components schema file, same as the CLI command.

Options

{
	component: String; // Required — Path to the component directory, relative from config.components.folder.
}

Response

Promise<{
	success: Boolean,
	message: String // Optional — Error message in case that the mock data could not be created
}>

createBuild

Simply triggers a build, same as the CLI command.

Options

None

Response

Promise<{
	success: Boolean,
	message: String
}>

createComponent

Creates component files for a given path.

Options

{
	component: String, // Required — Path to component directory.
	only: String[] // Optional — Values can be any of "tpl", "css", js", "mocks", "schema", "docs". If omitted, all files are created.
	skip: String[] // Optional — Values can be any of "tpl", "css", js", "mocks", "schema", "docs". If omitted, all files are created.
}

Please note that only either only or skip should be passed. If both are passed, only is used and skip is ignored.

Response

Promise<{
	success: Boolean,
	message: String
}>

lintComponent

Validates the schema and mock data for a single component.

Options

{
	component: String; // Required — Path to component directory.
}

Response

Promise<{
	success: Boolean, // only indicates if linting in general was successful for not, not if there are errors or not
	data: [{
		type: String, // Any of "mocks", "schema"
		data: [{
			message: String
		}]
	}],
	message: String // Optional — Error message in case success was false
}>

lintComponents

Validates the schema and mock data for all components.

Options

None

Response

Promise<{
	success: Boolean, // only indicates if linting in general was successful for not, not if there are errors or not
	data: [{
		component: String, // Path to component directory.
		errors: [{
			type: String, // Any of "mocks", "schema"
			data: [{
				message: String
			}]
		}]
	}],
	message: String // Optional — Error message in case success was false
}>

Usage

import { getMockData } from "@miyagi/core/api";

await getMockData({});