@stencil/templates 5.0.0-alpha.6

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.
@@ -0,0 +1,44 @@
1
+ //#region src/types.d.ts
2
+ type StyleExtension = 'css' | 'sass' | 'scss' | 'less';
3
+ //#endregion
4
+ //#region src/generate/component.d.ts
5
+ /**
6
+ * Returns the tag name converted to PascalCase for use as a class name.
7
+ *
8
+ * @param str - Dash-case string to convert.
9
+ * @returns PascalCase equivalent of `str`.
10
+ */
11
+ declare function toPascalCase(str: string): string;
12
+ /**
13
+ * Returns the component TSX boilerplate for `stencil generate`.
14
+ * Uses the v5 `encapsulation` API.
15
+ *
16
+ * @param tagName - Dash-case custom element tag name.
17
+ * @param styleExtension - Optional stylesheet extension (e.g. `'css'`, `'scss'`).
18
+ * @returns TSX source string for the new component file.
19
+ */
20
+ declare function getComponentBoilerplate(tagName: string, styleExtension?: string): string;
21
+ //#endregion
22
+ //#region src/generate/style.d.ts
23
+ /**
24
+ * Returns the stylesheet boilerplate for `stencil generate`.
25
+ * SASS indented syntax uses indentation instead of braces.
26
+ *
27
+ * @param ext - File extension (e.g. `'css'`, `'sass'`, `'scss'`).
28
+ * @returns Stylesheet source string.
29
+ */
30
+ declare function getStyleBoilerplate(ext: string): string;
31
+ //#endregion
32
+ //#region src/project/paths.d.ts
33
+ declare const PROJECT_TEMPLATES: readonly ["component-starter"];
34
+ type ProjectTemplateId = (typeof PROJECT_TEMPLATES)[number];
35
+ /**
36
+ * Returns the absolute path to a project template directory.
37
+ * Resolves from the compiled dist/ location up to the sibling templates/ directory.
38
+ *
39
+ * @param templateId - One of the known template identifiers (e.g. `'component-starter'`).
40
+ * @returns Absolute path to the template directory.
41
+ */
42
+ declare function getTemplatePath(templateId: ProjectTemplateId): string;
43
+ //#endregion
44
+ export { PROJECT_TEMPLATES, type ProjectTemplateId, type StyleExtension, getComponentBoilerplate, getStyleBoilerplate, getTemplatePath, toPascalCase };
package/dist/index.mjs ADDED
@@ -0,0 +1,68 @@
1
+ import { dirname, join } from "node:path";
2
+ import { fileURLToPath } from "node:url";
3
+ //#region src/generate/component.ts
4
+ /**
5
+ * Returns the tag name converted to PascalCase for use as a class name.
6
+ *
7
+ * @param str - Dash-case string to convert.
8
+ * @returns PascalCase equivalent of `str`.
9
+ */
10
+ function toPascalCase(str) {
11
+ return str.split("-").reduce((res, part) => res + part[0].toUpperCase() + part.slice(1), "");
12
+ }
13
+ /**
14
+ * Returns the component TSX boilerplate for `stencil generate`.
15
+ * Uses the v5 `encapsulation` API.
16
+ *
17
+ * @param tagName - Dash-case custom element tag name.
18
+ * @param styleExtension - Optional stylesheet extension (e.g. `'css'`, `'scss'`).
19
+ * @returns TSX source string for the new component file.
20
+ */
21
+ function getComponentBoilerplate(tagName, styleExtension) {
22
+ const decorator = ["{"];
23
+ decorator.push(` tag: '${tagName}',`);
24
+ if (styleExtension) decorator.push(` styleUrl: '${tagName}.${styleExtension}',`);
25
+ decorator.push(` encapsulation: { type: 'shadow' },`);
26
+ decorator.push("}");
27
+ return `import { Component, Host } from '@stencil/core';
28
+
29
+ @Component(${decorator.join("\n")})
30
+ export class ${toPascalCase(tagName)} {
31
+ render() {
32
+ return (
33
+ <Host>
34
+ <slot></slot>
35
+ </Host>
36
+ );
37
+ }
38
+ }
39
+ `;
40
+ }
41
+ //#endregion
42
+ //#region src/generate/style.ts
43
+ /**
44
+ * Returns the stylesheet boilerplate for `stencil generate`.
45
+ * SASS indented syntax uses indentation instead of braces.
46
+ *
47
+ * @param ext - File extension (e.g. `'css'`, `'sass'`, `'scss'`).
48
+ * @returns Stylesheet source string.
49
+ */
50
+ function getStyleBoilerplate(ext) {
51
+ return ext === "sass" ? `:host\n display: block\n` : `:host {\n display: block;\n}\n`;
52
+ }
53
+ //#endregion
54
+ //#region src/project/paths.ts
55
+ const __dirname = dirname(fileURLToPath(import.meta.url));
56
+ const PROJECT_TEMPLATES = ["component-starter"];
57
+ /**
58
+ * Returns the absolute path to a project template directory.
59
+ * Resolves from the compiled dist/ location up to the sibling templates/ directory.
60
+ *
61
+ * @param templateId - One of the known template identifiers (e.g. `'component-starter'`).
62
+ * @returns Absolute path to the template directory.
63
+ */
64
+ function getTemplatePath(templateId) {
65
+ return join(__dirname, "..", "templates", "project", templateId);
66
+ }
67
+ //#endregion
68
+ export { PROJECT_TEMPLATES, getComponentBoilerplate, getStyleBoilerplate, getTemplatePath, toPascalCase };
package/package.json ADDED
@@ -0,0 +1,43 @@
1
+ {
2
+ "name": "@stencil/templates",
3
+ "version": "5.0.0-alpha.6",
4
+ "description": "Project and generate templates for Stencil",
5
+ "keywords": [
6
+ "scaffolding",
7
+ "stencil",
8
+ "templates"
9
+ ],
10
+ "homepage": "https://stenciljs.com/",
11
+ "license": "MIT",
12
+ "author": "StencilJs Contributors",
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "git+https://github.com/stenciljs/core.git"
16
+ },
17
+ "files": [
18
+ "dist/",
19
+ "templates/"
20
+ ],
21
+ "type": "module",
22
+ "main": "./dist/index.mjs",
23
+ "types": "./dist/index.d.mts",
24
+ "exports": {
25
+ ".": {
26
+ "types": "./dist/index.d.mts",
27
+ "import": "./dist/index.mjs"
28
+ }
29
+ },
30
+ "scripts": {
31
+ "build": "tsdown",
32
+ "test": "vitest run --passWithNoTests",
33
+ "typecheck": "tsc --noEmit"
34
+ },
35
+ "devDependencies": {
36
+ "tsdown": "catalog:",
37
+ "typescript": "catalog:",
38
+ "vitest": "catalog:"
39
+ },
40
+ "volta": {
41
+ "extends": "../../package.json"
42
+ }
43
+ }
@@ -0,0 +1,21 @@
1
+ {
2
+ "name": "{{PROJECT_NAME}}",
3
+ "version": "0.0.1",
4
+ "description": "A Stencil component library",
5
+ "license": "MIT",
6
+ "files": [
7
+ "dist/"
8
+ ],
9
+ "main": "dist/loader-bundle/index.cjs",
10
+ "module": "dist/loader-bundle/index.js",
11
+ "types": "dist/types/index.d.ts",
12
+ "scripts": {
13
+ "build": "stencil build",
14
+ "dev": "stencil build --dev --watch --serve",
15
+ "generate": "stencil generate"
16
+ },
17
+ "devDependencies": {
18
+ "@stencil/core": "^5.0.0"
19
+ },
20
+ "collection": "dist/collection/collection-manifest.json"
21
+ }
@@ -0,0 +1,16 @@
1
+ import { Component, Host } from '@stencil/core';
2
+
3
+ @Component({
4
+ tag: 'my-component',
5
+ styleUrl: 'my-component.css',
6
+ encapsulation: { type: 'shadow' },
7
+ })
8
+ export class MyComponent {
9
+ render() {
10
+ return (
11
+ <Host>
12
+ <slot></slot>
13
+ </Host>
14
+ );
15
+ }
16
+ }
@@ -0,0 +1,6 @@
1
+ import type { Config } from '@stencil/core';
2
+
3
+ export const config: Config = {
4
+ namespace: '{{NAMESPACE}}',
5
+ outputTargets: [{ type: 'loader-bundle' }, { type: 'types' }],
6
+ };
@@ -0,0 +1,16 @@
1
+ {
2
+ "compilerOptions": {
3
+ "strictPropertyInitialization": false,
4
+ "experimentalDecorators": true,
5
+ "target": "ES2022",
6
+ "module": "ESNext",
7
+ "moduleResolution": "bundler",
8
+ "lib": ["ES2022", "DOM"],
9
+ "jsx": "react-jsx",
10
+ "jsxImportSource": "@stencil/core",
11
+ "resolveJsonModule": true,
12
+ "allowJs": true,
13
+ "rootDir": "./"
14
+ },
15
+ "include": ["src"]
16
+ }