@stencil/templates 5.0.0-alpha.16 → 5.0.0-alpha.18

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.
Files changed (2) hide show
  1. package/README.md +149 -0
  2. package/package.json +1 -1
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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stencil/templates",
3
- "version": "5.0.0-alpha.16",
3
+ "version": "5.0.0-alpha.18",
4
4
  "description": "Project and generate templates for Stencil",
5
5
  "keywords": [
6
6
  "scaffolding",