@stencil-community/web-types-output-target
Advanced tools
Comparing version 0.2.0 to 0.3.0
import type { OutputTargetCustom } from '@stencil/core/internal'; | ||
/** | ||
* A representation of the configuration object that this output target accepts at compile time | ||
*/ | ||
export type WebTypesConfig = { | ||
/** | ||
* The output location of the generated JSON file. | ||
*/ | ||
outFile?: string; | ||
}; | ||
/** | ||
* A Stencil output target for generating [web-types](https://github.com/JetBrains/web-types) for a Stencil project. | ||
@@ -16,3 +25,3 @@ * Web-Types are a JSON format for documenting web components to provide metadata to Integrated Development Environments | ||
*/ | ||
export declare const webTypesOutputTarget: () => OutputTargetCustom; | ||
export declare const webTypesOutputTarget: (outputTargetConfig?: WebTypesConfig) => OutputTargetCustom; | ||
export type WebType = { | ||
@@ -19,0 +28,0 @@ $schema: string; |
@@ -14,2 +14,3 @@ "use strict"; | ||
const generate_web_types_js_1 = require("./generate-web-types.js"); | ||
const path_1 = require("path"); | ||
/** | ||
@@ -29,3 +30,3 @@ * A Stencil output target for generating [web-types](https://github.com/JetBrains/web-types) for a Stencil project. | ||
*/ | ||
const webTypesOutputTarget = () => ({ | ||
const webTypesOutputTarget = (outputTargetConfig = {}) => ({ | ||
type: 'custom', | ||
@@ -38,2 +39,11 @@ name: 'web-types-output-target', | ||
} | ||
if (!outputTargetConfig.outFile) { | ||
outputTargetConfig.outFile = 'web-types.json'; | ||
} | ||
else if ((0, path_1.extname)(outputTargetConfig.outFile) !== '.json') { | ||
outputTargetConfig.outFile = (0, path_1.join)(outputTargetConfig.outFile, 'web-types.json'); | ||
} | ||
if (!(0, path_1.isAbsolute)(outputTargetConfig.outFile)) { | ||
outputTargetConfig.outFile = (0, path_1.join)(config.rootDir, outputTargetConfig.outFile); | ||
} | ||
}, | ||
@@ -51,3 +61,3 @@ generator(config, compilerCtx, buildCtx) { | ||
const webTypes = (0, generate_web_types_js_1.generateWebTypes)(buildCtx, stencilRootDirectory); | ||
yield compilerCtx.fs.writeFile('web-types.json', JSON.stringify(webTypes, null, 2)); | ||
yield compilerCtx.fs.writeFile(outputTargetConfig.outFile, JSON.stringify(webTypes, null, 2)); | ||
timespan.finish('generate web-types finished'); | ||
@@ -54,0 +64,0 @@ }); |
{ | ||
"name": "@stencil-community/web-types-output-target", | ||
"version": "0.2.0", | ||
"version": "0.3.0", | ||
"description": "an experimental stencil output target supporting web-types", | ||
@@ -37,5 +37,5 @@ "main": "dist/index.js", | ||
"volta": { | ||
"node": "20.12.2", | ||
"npm": "10.6.0" | ||
"node": "20.13.1", | ||
"npm": "10.7.0" | ||
} | ||
} |
@@ -62,4 +62,22 @@ # Stencil Web Types Output Target | ||
## Usage | ||
## Configuration | ||
The `webTypesOutputTarget` output target takes an optional argument, an object literal to configure the output target. | ||
The following are properties on that configuration object. | ||
### `outFile` | ||
Defaults to `StencilConfig#{rootDir}/web-types.json`. | ||
Since v0.3.0. | ||
Description: A string that represents the directory to place the output file. | ||
Users may specify either a directory (e.g. '../'), a filename (e.g. 'my-types.json') or both (e.g. '../my-types.json'). | ||
If no filename ending is '.json' is provided, the output target assumes that a filename must be added to the path. | ||
In such cases, the default 'web-types.json' will be added to the path. | ||
It is not recommended that users use absolute paths for this setting, as this can cause errors in projects shared by more than one developer. | ||
## Using Web Types | ||
Once web types have been written to disk, they need to be picked up by the IDE. | ||
@@ -66,0 +84,0 @@ Web types for your project can be picked by JetBrains IDEs by setting the `web-types` property at the root level of your project's `package.json` file: |
27941
476
100