Skip to content

Commit c9cb0d2

Browse files
authored
Introduce a Heft plugin for generating types for static assets. (#5666)
* Introduce the heft-image-typings-generator-plugin. * Use the new plugin in build-tests projects. * Add the typigns generator to the web rig. * Rewrite the plugin to handle general static assets. * fixup! Rewrite the plugin to handle general static assets. * fixup! Rewrite the plugin to handle general static assets. * Remove usage of the plugin in the heft-typescript-composite-test project. * fixup! Use the new plugin in build-tests projects. * fixup! Rewrite the plugin to handle general static assets. * Add unit test. * Rationalzie the plugin options. * fixup! Use the new plugin in build-tests projects. * fixup! Rationalzie the plugin options. * PR feedback. * fixup! Rationalzie the plugin options. * fixup! PR feedback. * Refactor binary and text to resource and source.
1 parent 2eda68f commit c9cb0d2

68 files changed

Lines changed: 1562 additions & 37 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ These GitHub repositories provide supplementary resources for Rush Stack:
7676
| [/heft-plugins/heft-sass-load-themed-styles-plugin](./heft-plugins/heft-sass-load-themed-styles-plugin/) | [![npm version](https://badge.fury.io/js/%40rushstack%2Fheft-sass-load-themed-styles-plugin.svg)](https://badge.fury.io/js/%40rushstack%2Fheft-sass-load-themed-styles-plugin) | [changelog](./heft-plugins/heft-sass-load-themed-styles-plugin/CHANGELOG.md) | [@rushstack/heft-sass-load-themed-styles-plugin](https://www.npmjs.com/package/@rushstack/heft-sass-load-themed-styles-plugin) |
7777
| [/heft-plugins/heft-sass-plugin](./heft-plugins/heft-sass-plugin/) | [![npm version](https://badge.fury.io/js/%40rushstack%2Fheft-sass-plugin.svg)](https://badge.fury.io/js/%40rushstack%2Fheft-sass-plugin) | [changelog](./heft-plugins/heft-sass-plugin/CHANGELOG.md) | [@rushstack/heft-sass-plugin](https://www.npmjs.com/package/@rushstack/heft-sass-plugin) |
7878
| [/heft-plugins/heft-serverless-stack-plugin](./heft-plugins/heft-serverless-stack-plugin/) | [![npm version](https://badge.fury.io/js/%40rushstack%2Fheft-serverless-stack-plugin.svg)](https://badge.fury.io/js/%40rushstack%2Fheft-serverless-stack-plugin) | [changelog](./heft-plugins/heft-serverless-stack-plugin/CHANGELOG.md) | [@rushstack/heft-serverless-stack-plugin](https://www.npmjs.com/package/@rushstack/heft-serverless-stack-plugin) |
79+
| [/heft-plugins/heft-static-asset-typings-plugin](./heft-plugins/heft-static-asset-typings-plugin/) | [![npm version](https://badge.fury.io/js/%40rushstack%2Fheft-static-asset-typings-plugin.svg)](https://badge.fury.io/js/%40rushstack%2Fheft-static-asset-typings-plugin) | [changelog](./heft-plugins/heft-static-asset-typings-plugin/CHANGELOG.md) | [@rushstack/heft-static-asset-typings-plugin](https://www.npmjs.com/package/@rushstack/heft-static-asset-typings-plugin) |
7980
| [/heft-plugins/heft-storybook-plugin](./heft-plugins/heft-storybook-plugin/) | [![npm version](https://badge.fury.io/js/%40rushstack%2Fheft-storybook-plugin.svg)](https://badge.fury.io/js/%40rushstack%2Fheft-storybook-plugin) | [changelog](./heft-plugins/heft-storybook-plugin/CHANGELOG.md) | [@rushstack/heft-storybook-plugin](https://www.npmjs.com/package/@rushstack/heft-storybook-plugin) |
8081
| [/heft-plugins/heft-typescript-plugin](./heft-plugins/heft-typescript-plugin/) | [![npm version](https://badge.fury.io/js/%40rushstack%2Fheft-typescript-plugin.svg)](https://badge.fury.io/js/%40rushstack%2Fheft-typescript-plugin) | [changelog](./heft-plugins/heft-typescript-plugin/CHANGELOG.md) | [@rushstack/heft-typescript-plugin](https://www.npmjs.com/package/@rushstack/heft-typescript-plugin) |
8182
| [/heft-plugins/heft-vscode-extension-plugin](./heft-plugins/heft-vscode-extension-plugin/) | [![npm version](https://badge.fury.io/js/%40rushstack%2Fheft-vscode-extension-plugin.svg)](https://badge.fury.io/js/%40rushstack%2Fheft-vscode-extension-plugin) | [changelog](./heft-plugins/heft-vscode-extension-plugin/CHANGELOG.md) | [@rushstack/heft-vscode-extension-plugin](https://www.npmjs.com/package/@rushstack/heft-vscode-extension-plugin) |

build-tests-samples/heft-web-rig-app-tutorial/src/ExampleApp.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import * as React from 'react';
55
import { ToggleSwitch, type IToggleEventArgs } from 'heft-web-rig-library-tutorial';
66

7+
import exampleImage from './example-image.png';
8+
79
/**
810
* This React component renders the application page.
911
*/
@@ -24,10 +26,7 @@ export class ExampleApp extends React.Component {
2426
<ToggleSwitch leftColor={'#800000'} rightColor={'#008000'} onToggle={this._onToggle} />
2527

2628
<p>Here is an example image:</p>
27-
<img
28-
// eslint-disable-next-line @typescript-eslint/no-require-imports
29-
src={require('./example-image.png')}
30-
/>
29+
<img src={exampleImage} />
3130
</div>
3231
);
3332
}

build-tests/heft-node-everything-esm-module-test/config/heft.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,18 @@
99
"cleanFiles": [{ "includeGlobs": ["dist", "lib-commonjs", "lib", "lib-esm", "lib-esnext", "lib-umd"] }],
1010

1111
"tasksByName": {
12+
"text-typings": {
13+
"taskPlugin": {
14+
"pluginPackage": "@rushstack/heft-static-asset-typings-plugin",
15+
"pluginName": "source-assets-plugin",
16+
"options": {
17+
"configType": "file",
18+
"configFileName": "source-assets.json"
19+
}
20+
}
21+
},
1222
"typescript": {
23+
"taskDependencies": ["text-typings"],
1324
"taskPlugin": {
1425
"pluginPackage": "@rushstack/heft-typescript-plugin"
1526
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"fileExtensions": [".html"],
3+
"cjsOutputFolders": ["lib-commonjs"],
4+
"esmOutputFolders": ["lib-esm"],
5+
"generatedTsFolders": ["temp/text-typings"]
6+
}

build-tests/heft-node-everything-esm-module-test/etc/heft-node-everything-esm-module-test.api.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
55
```ts
66

7+
// @public
8+
export const templateContent: string;
9+
710
// @public (undocumented)
811
export class TestClass {
912
}

build-tests/heft-node-everything-esm-module-test/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"@rushstack/heft-api-extractor-plugin": "workspace:*",
1818
"@rushstack/heft-jest-plugin": "workspace:*",
1919
"@rushstack/heft-lint-plugin": "workspace:*",
20+
"@rushstack/heft-static-asset-typings-plugin": "workspace:*",
2021
"@rushstack/heft-typescript-plugin": "workspace:*",
2122
"@types/heft-jest": "1.0.1",
2223
"@types/node": "20.17.19",
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<p>This is an example template imported as a text asset.</p>

build-tests/heft-node-everything-esm-module-test/src/index.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
22
// See LICENSE in the project root for license information.
33

4+
import exampleTemplate from './exampleTemplate.html';
5+
6+
/**
7+
* The content of exampleTemplate.html, imported as a text asset.
8+
* @public
9+
*/
10+
export const templateContent: string = exampleTemplate;
11+
412
/**
513
* @public
614
*/

build-tests/heft-node-everything-esm-module-test/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"compilerOptions": {
55
"outDir": "lib-commonjs",
66
"declarationDir": "lib-dts",
7-
"rootDir": "src",
7+
"rootDirs": ["src", "temp/text-typings"],
88

99
"forceConsistentCasingInFileNames": true,
1010
"jsx": "react",

build-tests/heft-node-everything-test/config/heft.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,23 @@
1616
"cleanFiles": [{ "includeGlobs": ["dist", "lib-commonjs", "lib", "lib-esm", "lib-esnext", "lib-umd"] }],
1717

1818
"tasksByName": {
19+
"text-typings": {
20+
"taskPlugin": {
21+
"pluginPackage": "@rushstack/heft-static-asset-typings-plugin",
22+
"pluginName": "source-assets-plugin",
23+
"options": {
24+
"configType": "inline",
25+
"config": {
26+
"fileExtensions": [".html"],
27+
"cjsOutputFolders": ["lib-commonjs"],
28+
"esmOutputFolders": ["lib-esm"],
29+
"generatedTsFolders": ["temp/text-typings"]
30+
}
31+
}
32+
}
33+
},
1934
"typescript": {
35+
"taskDependencies": ["text-typings"],
2036
"taskPlugin": {
2137
"pluginPackage": "@rushstack/heft-typescript-plugin"
2238
}

0 commit comments

Comments
 (0)