@stencil/templates 5.0.0-alpha.8 → 5.0.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +149 -0
- package/dist/index.d.mts +40 -2
- package/dist/index.mjs +76 -1
- package/package.json +7 -4
- package/templates/project/component-starter/_gitignore +4 -0
- package/templates/project/component-starter/package.json +1 -1
- package/templates/project/component-starter/src/components/my-component/usage/example.md +5 -0
- package/templates/project/component-starter/tsconfig.json +1 -0
- /package/{LICENSE.md → LICENSE} +0 -0
package/README.md
ADDED
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
# @stencil/templates
|
|
2
|
+
|
|
3
|
+
Boilerplate generators and project templates for Stencil — used internally by `stencil generate` and `stencil init`.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install --save-dev @stencil/templates
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## API
|
|
12
|
+
|
|
13
|
+
### `getComponentBoilerplate(tagName, styleExtension?)` — component TSX
|
|
14
|
+
|
|
15
|
+
Generates the `.tsx` file content for a new Stencil component:
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
import { getComponentBoilerplate } from '@stencil/templates';
|
|
19
|
+
|
|
20
|
+
// With a stylesheet
|
|
21
|
+
const tsx = getComponentBoilerplate('my-button', 'css');
|
|
22
|
+
|
|
23
|
+
// Without (no styleUrl in @Component decorator)
|
|
24
|
+
const bare = getComponentBoilerplate('my-button');
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
`styleExtension` accepts `'css'`, `'scss'`, `'sass'`, or `'less'`.
|
|
28
|
+
|
|
29
|
+
Output for `getComponentBoilerplate('my-button', 'css')`:
|
|
30
|
+
|
|
31
|
+
```tsx
|
|
32
|
+
import { Component, Host } from '@stencil/core';
|
|
33
|
+
|
|
34
|
+
@Component({
|
|
35
|
+
tag: 'my-button',
|
|
36
|
+
styleUrl: 'my-button.css',
|
|
37
|
+
encapsulation: { type: 'shadow' },
|
|
38
|
+
})
|
|
39
|
+
export class MyButton {
|
|
40
|
+
render() {
|
|
41
|
+
return (
|
|
42
|
+
<Host>
|
|
43
|
+
<slot></slot>
|
|
44
|
+
</Host>
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
---
|
|
51
|
+
|
|
52
|
+
### `getStyleBoilerplate(ext)` — stylesheet
|
|
53
|
+
|
|
54
|
+
Generates the initial stylesheet content. Pass the file extension — not the tag name:
|
|
55
|
+
|
|
56
|
+
```ts
|
|
57
|
+
import { getStyleBoilerplate } from '@stencil/templates';
|
|
58
|
+
|
|
59
|
+
const css = getStyleBoilerplate('css'); // :host {\n display: block;\n}
|
|
60
|
+
const scss = getStyleBoilerplate('scss'); // same, brace syntax
|
|
61
|
+
const sass = getStyleBoilerplate('sass'); // :host\n display: block (indented syntax)
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
---
|
|
65
|
+
|
|
66
|
+
### `toPascalCase(str)` — tag name to class name
|
|
67
|
+
|
|
68
|
+
Converts a dash-case tag name to a PascalCase class name:
|
|
69
|
+
|
|
70
|
+
```ts
|
|
71
|
+
import { toPascalCase } from '@stencil/templates';
|
|
72
|
+
|
|
73
|
+
toPascalCase('my-button'); // 'MyButton'
|
|
74
|
+
toPascalCase('ui-card-header'); // 'UiCardHeader'
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
---
|
|
78
|
+
|
|
79
|
+
### `generateStencilConfig(selections)` — `stencil.config.ts` source
|
|
80
|
+
|
|
81
|
+
Generates the content for a `stencil.config.ts` file based on wizard selections. Returns `null` when the default zero-config covers everything (loader-bundle only, no signals, no docs):
|
|
82
|
+
|
|
83
|
+
```ts
|
|
84
|
+
import { generateStencilConfig } from '@stencil/templates';
|
|
85
|
+
import type { ConfigSelections } from '@stencil/templates';
|
|
86
|
+
|
|
87
|
+
const sel: ConfigSelections = {
|
|
88
|
+
namespace: 'MyLib',
|
|
89
|
+
outputs: ['loader', 'standalone'],
|
|
90
|
+
signals: false,
|
|
91
|
+
docs: ['cem'],
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
const src = generateStencilConfig(sel);
|
|
95
|
+
// null if only loader + no signals + no docs (zero-config case)
|
|
96
|
+
// otherwise: TypeScript source string ready to write to stencil.config.ts
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
**`ConfigSelections` shape:**
|
|
100
|
+
|
|
101
|
+
| Field | Type | Description |
|
|
102
|
+
|---|---|---|
|
|
103
|
+
| `namespace` | `string` | Component library namespace (e.g. `'MyLib'`) |
|
|
104
|
+
| `outputs` | `OutputKey[]` | Output targets to enable |
|
|
105
|
+
| `signals` | `boolean` | Enable `signalBacking: true` |
|
|
106
|
+
| `docs` | `DocKey[]` | Documentation targets to include |
|
|
107
|
+
|
|
108
|
+
**`OutputKey` values:** `'loader'` \| `'standalone'` \| `'ssr'` \| `'ssr-wasm'` \| `'www'`
|
|
109
|
+
|
|
110
|
+
**`DocKey` values:** `'cem'` \| `'json'` \| `'vscode'`
|
|
111
|
+
|
|
112
|
+
---
|
|
113
|
+
|
|
114
|
+
### `generatePackageJsonFields(outputs)` — `package.json` distributable fields
|
|
115
|
+
|
|
116
|
+
Returns the `module`, `types`, and `type` fields to merge into `package.json` for a given set of output targets. Returns an empty object for `'www'`-only (non-publishable app mode):
|
|
117
|
+
|
|
118
|
+
```ts
|
|
119
|
+
import { generatePackageJsonFields } from '@stencil/templates';
|
|
120
|
+
|
|
121
|
+
generatePackageJsonFields([]); // loader-bundle (default)
|
|
122
|
+
// { type: 'module', module: './dist/loader-bundle/index.js', types: './dist/types/loader.d.ts' }
|
|
123
|
+
|
|
124
|
+
generatePackageJsonFields(['standalone']);
|
|
125
|
+
// { type: 'module', module: './dist/standalone/index.js', types: './dist/types/standalone.d.ts' }
|
|
126
|
+
|
|
127
|
+
generatePackageJsonFields(['www']);
|
|
128
|
+
// {} — www is an app, not a publishable package
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
Priority when multiple outputs are selected: `loader` > `standalone` > `ssr` > `ssr-wasm`.
|
|
132
|
+
|
|
133
|
+
---
|
|
134
|
+
|
|
135
|
+
### `getTemplatePath(templateId)` — project template directory
|
|
136
|
+
|
|
137
|
+
Returns the absolute path to a project template directory, ready to copy into a new project:
|
|
138
|
+
|
|
139
|
+
```ts
|
|
140
|
+
import { getTemplatePath, PROJECT_TEMPLATES } from '@stencil/templates';
|
|
141
|
+
|
|
142
|
+
// Currently: ['component-starter']
|
|
143
|
+
console.log(PROJECT_TEMPLATES);
|
|
144
|
+
|
|
145
|
+
const dir = getTemplatePath('component-starter');
|
|
146
|
+
// → /absolute/path/to/@stencil/templates/templates/project/component-starter
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
The `component-starter` template includes a `stencil.config.ts`, `tsconfig.json`, `package.json`, `.gitignore`, a sample component, and a utility file.
|
package/dist/index.d.mts
CHANGED
|
@@ -43,7 +43,7 @@ declare function getTemplatePath(templateId: ProjectTemplateId): string;
|
|
|
43
43
|
//#endregion
|
|
44
44
|
//#region src/project/config.d.ts
|
|
45
45
|
type OutputKey = 'loader' | 'standalone' | 'ssr' | 'ssr-wasm' | 'www';
|
|
46
|
-
type DocKey = 'cem' | 'json' | 'vscode';
|
|
46
|
+
type DocKey = 'cem' | 'json' | 'skill' | 'vscode';
|
|
47
47
|
interface PackageJsonFields {
|
|
48
48
|
type?: 'module';
|
|
49
49
|
module?: string;
|
|
@@ -72,4 +72,42 @@ declare function generateStencilConfig(sel: ConfigSelections): string | null;
|
|
|
72
72
|
*/
|
|
73
73
|
declare function generatePackageJsonFields(outputs: ReadonlyArray<OutputKey>): PackageJsonFields;
|
|
74
74
|
//#endregion
|
|
75
|
-
|
|
75
|
+
//#region src/project/index-html.d.ts
|
|
76
|
+
interface IndexHtmlSelections {
|
|
77
|
+
projectName: string;
|
|
78
|
+
namespace: string;
|
|
79
|
+
globalStyle: boolean;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Returns src/index.html source for a `www`-output project: entry <script> tag pointing
|
|
83
|
+
* at the compiled bundle, and a <link> to the global stylesheet if one was selected.
|
|
84
|
+
*
|
|
85
|
+
* @param sel - Wizard selections to encode into the HTML file.
|
|
86
|
+
* @returns HTML source string.
|
|
87
|
+
*/
|
|
88
|
+
declare function generateIndexHtml(sel: IndexHtmlSelections): string;
|
|
89
|
+
//#endregion
|
|
90
|
+
//#region src/generate/preview.d.ts
|
|
91
|
+
/**
|
|
92
|
+
* Returns the `usage/example.md` boilerplate for `stencil generate`. Read by the docs
|
|
93
|
+
* pipeline (readme / docs-json / custom-elements-manifest demos) and by the dev server's
|
|
94
|
+
* live component preview.
|
|
95
|
+
*
|
|
96
|
+
* @param tagName - Dash-case custom element tag name.
|
|
97
|
+
* @returns Markdown source string.
|
|
98
|
+
*/
|
|
99
|
+
declare function getUsageExampleBoilerplate(tagName: string): string;
|
|
100
|
+
/**
|
|
101
|
+
* Returns a standalone index.html boilerplate for `stencil generate`, scoped to a single
|
|
102
|
+
* component's own directory. Its presence opts that directory out of the dev server's
|
|
103
|
+
* auto-generated preview, trading it for a hand-authored demo page.
|
|
104
|
+
*
|
|
105
|
+
* @param tagName - Dash-case custom element tag name.
|
|
106
|
+
* @param entryScriptSrc - Resolved src for the project's browser entry bundle (see
|
|
107
|
+
* `resolveEntryScriptSrc` in the CLI package), or `null` if the project has no browser-loadable
|
|
108
|
+
* output target (e.g. an SSR-only project) - the script tag is omitted in that case.
|
|
109
|
+
* @returns HTML source string.
|
|
110
|
+
*/
|
|
111
|
+
declare function getPreviewHtmlBoilerplate(tagName: string, entryScriptSrc: string | null): string;
|
|
112
|
+
//#endregion
|
|
113
|
+
export { type ConfigSelections, type DocKey, type IndexHtmlSelections, type OutputKey, PROJECT_TEMPLATES, type PackageJsonFields, type ProjectTemplateId, type StyleExtension, generateIndexHtml, generatePackageJsonFields, generateStencilConfig, getComponentBoilerplate, getPreviewHtmlBoilerplate, getStyleBoilerplate, getTemplatePath, getUsageExampleBoilerplate, toPascalCase };
|
package/dist/index.mjs
CHANGED
|
@@ -83,6 +83,7 @@ function generateStencilConfig(sel) {
|
|
|
83
83
|
if (sel.outputs.includes("www")) outputLines.push(` { type: 'www' },`);
|
|
84
84
|
if (sel.docs.includes("cem")) outputLines.push(` { type: 'docs-custom-elements-manifest', file: 'custom-elements.json' },`);
|
|
85
85
|
if (sel.docs.includes("json")) outputLines.push(` { type: 'docs-json', file: 'docs/api.json' },`);
|
|
86
|
+
if (sel.docs.includes("skill")) outputLines.push(` { type: 'docs-agent-skill' },`);
|
|
86
87
|
if (sel.docs.includes("vscode")) outputLines.push(` { type: 'docs-vscode', file: 'vscode-data.json' },`);
|
|
87
88
|
const parts = [
|
|
88
89
|
`import type { Config } from '@stencil/core';`,
|
|
@@ -133,4 +134,78 @@ function generatePackageJsonFields(outputs) {
|
|
|
133
134
|
return {};
|
|
134
135
|
}
|
|
135
136
|
//#endregion
|
|
136
|
-
|
|
137
|
+
//#region src/project/index-html.ts
|
|
138
|
+
/**
|
|
139
|
+
* Returns src/index.html source for a `www`-output project: entry <script> tag pointing
|
|
140
|
+
* at the compiled bundle, and a <link> to the global stylesheet if one was selected.
|
|
141
|
+
*
|
|
142
|
+
* @param sel - Wizard selections to encode into the HTML file.
|
|
143
|
+
* @returns HTML source string.
|
|
144
|
+
*/
|
|
145
|
+
function generateIndexHtml(sel) {
|
|
146
|
+
const fsNamespace = sel.namespace.toLowerCase();
|
|
147
|
+
const headLines = [
|
|
148
|
+
` <meta charset="UTF-8" />`,
|
|
149
|
+
` <title>${sel.projectName}</title>`,
|
|
150
|
+
` <meta name="viewport" content="width=device-width, initial-scale=1" />`
|
|
151
|
+
];
|
|
152
|
+
if (sel.globalStyle) headLines.push(` <link rel="stylesheet" href="/build/${fsNamespace}.css" />`);
|
|
153
|
+
headLines.push(` <script type="module" src="/build/${fsNamespace}.js"><\/script>`);
|
|
154
|
+
return [
|
|
155
|
+
`<!doctype html>`,
|
|
156
|
+
`<html lang="en">`,
|
|
157
|
+
` <head>`,
|
|
158
|
+
...headLines,
|
|
159
|
+
` </head>`,
|
|
160
|
+
` <body>`,
|
|
161
|
+
` <my-component first="Stencil" last="'Don't call me a framework' JS"></my-component>`,
|
|
162
|
+
` </body>`,
|
|
163
|
+
`</html>`,
|
|
164
|
+
``
|
|
165
|
+
].join("\n");
|
|
166
|
+
}
|
|
167
|
+
//#endregion
|
|
168
|
+
//#region src/generate/preview.ts
|
|
169
|
+
/**
|
|
170
|
+
* Returns the `usage/example.md` boilerplate for `stencil generate`. Read by the docs
|
|
171
|
+
* pipeline (readme / docs-json / custom-elements-manifest demos) and by the dev server's
|
|
172
|
+
* live component preview.
|
|
173
|
+
*
|
|
174
|
+
* @param tagName - Dash-case custom element tag name.
|
|
175
|
+
* @returns Markdown source string.
|
|
176
|
+
*/
|
|
177
|
+
function getUsageExampleBoilerplate(tagName) {
|
|
178
|
+
return `# Example
|
|
179
|
+
|
|
180
|
+
\`\`\`html
|
|
181
|
+
<${tagName}></${tagName}>
|
|
182
|
+
\`\`\`
|
|
183
|
+
`;
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Returns a standalone index.html boilerplate for `stencil generate`, scoped to a single
|
|
187
|
+
* component's own directory. Its presence opts that directory out of the dev server's
|
|
188
|
+
* auto-generated preview, trading it for a hand-authored demo page.
|
|
189
|
+
*
|
|
190
|
+
* @param tagName - Dash-case custom element tag name.
|
|
191
|
+
* @param entryScriptSrc - Resolved src for the project's browser entry bundle (see
|
|
192
|
+
* `resolveEntryScriptSrc` in the CLI package), or `null` if the project has no browser-loadable
|
|
193
|
+
* output target (e.g. an SSR-only project) - the script tag is omitted in that case.
|
|
194
|
+
* @returns HTML source string.
|
|
195
|
+
*/
|
|
196
|
+
function getPreviewHtmlBoilerplate(tagName, entryScriptSrc) {
|
|
197
|
+
return `<!doctype html>
|
|
198
|
+
<html lang="en">
|
|
199
|
+
<head>
|
|
200
|
+
<meta charset="UTF-8" />
|
|
201
|
+
<title>${tagName}</title>
|
|
202
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
203
|
+
${entryScriptSrc ? ` <script type="module" src="${entryScriptSrc}"><\/script>\n` : ` <!-- no browser-loadable output target configured - add your own entry script -->\n`} </head>
|
|
204
|
+
<body>
|
|
205
|
+
<${tagName}></${tagName}>
|
|
206
|
+
</body>
|
|
207
|
+
</html>
|
|
208
|
+
`;
|
|
209
|
+
}
|
|
210
|
+
//#endregion
|
|
211
|
+
export { PROJECT_TEMPLATES, generateIndexHtml, generatePackageJsonFields, generateStencilConfig, getComponentBoilerplate, getPreviewHtmlBoilerplate, getStyleBoilerplate, getTemplatePath, getUsageExampleBoilerplate, toPascalCase };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stencil/templates",
|
|
3
|
-
"version": "5.0.0-
|
|
3
|
+
"version": "5.0.0-beta.0",
|
|
4
4
|
"description": "Project and generate templates for Stencil",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"scaffolding",
|
|
@@ -28,9 +28,12 @@
|
|
|
28
28
|
}
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
"tsdown": "
|
|
32
|
-
"typescript": ">
|
|
33
|
-
"vitest": "^4.1.
|
|
31
|
+
"tsdown": "^0.22.14",
|
|
32
|
+
"typescript": ">5.0.0 <7.0.0",
|
|
33
|
+
"vitest": "^4.1.10"
|
|
34
|
+
},
|
|
35
|
+
"peerDependencies": {
|
|
36
|
+
"@stencil/core": "^5.0.0 || 5.0.0-beta.0"
|
|
34
37
|
},
|
|
35
38
|
"volta": {
|
|
36
39
|
"extends": "../../package.json"
|
/package/{LICENSE.md → LICENSE}
RENAMED
|
File without changes
|