@stencil/templates 5.0.0-alpha.11
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/LICENSE.md +27 -0
- package/dist/index.d.mts +75 -0
- package/dist/index.mjs +136 -0
- package/package.json +43 -0
- package/templates/project/component-starter/package.json +18 -0
- package/templates/project/component-starter/src/components/my-component/my-component.css +3 -0
- package/templates/project/component-starter/src/components/my-component/my-component.tsx +27 -0
- package/templates/project/component-starter/src/utils/utils.ts +3 -0
- package/templates/project/component-starter/stencil.config.ts +6 -0
- package/templates/project/component-starter/tsconfig.json +16 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2019-present Drifty Co.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
|
22
|
+
|
|
23
|
+
-----------------------------------------
|
|
24
|
+
Third-party components, software, and/or libraries (collectively, "components")
|
|
25
|
+
are included under the licenses specified by their authors. For information
|
|
26
|
+
about these third-party licenses, refer to the separate legal notices governing
|
|
27
|
+
such components at NOTICE file at the top level of the package.
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
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
|
+
//#region src/project/config.d.ts
|
|
45
|
+
type OutputKey = 'loader' | 'standalone' | 'ssr' | 'ssr-wasm' | 'www';
|
|
46
|
+
type DocKey = 'cem' | 'json' | 'vscode';
|
|
47
|
+
interface PackageJsonFields {
|
|
48
|
+
type?: 'module';
|
|
49
|
+
module?: string;
|
|
50
|
+
types?: string;
|
|
51
|
+
}
|
|
52
|
+
interface ConfigSelections {
|
|
53
|
+
namespace: string;
|
|
54
|
+
outputs: ReadonlyArray<OutputKey>;
|
|
55
|
+
signals: boolean;
|
|
56
|
+
docs: ReadonlyArray<DocKey>;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Returns stencil.config.ts source for the given selections, or null if zero-config
|
|
60
|
+
* covers everything (outputs = [] | ['loader'], no signals, no docs).
|
|
61
|
+
*
|
|
62
|
+
* @param sel - Wizard selections to encode into the config file.
|
|
63
|
+
* @returns TypeScript source string, or null if no config file is needed.
|
|
64
|
+
*/
|
|
65
|
+
declare function generateStencilConfig(sel: ConfigSelections): string | null;
|
|
66
|
+
/**
|
|
67
|
+
* Returns the package.json distributable fields for the given output selections.
|
|
68
|
+
* Returns an empty object for www-only (non-publishable app mode).
|
|
69
|
+
* Priority: loader > standalone > ssr > ssr-wasm.
|
|
70
|
+
* @param outputs - Wizard output selections to encode into package.json.
|
|
71
|
+
* @returns An object with the fields to write into package.json.
|
|
72
|
+
*/
|
|
73
|
+
declare function generatePackageJsonFields(outputs: ReadonlyArray<OutputKey>): PackageJsonFields;
|
|
74
|
+
//#endregion
|
|
75
|
+
export { type ConfigSelections, type DocKey, type OutputKey, PROJECT_TEMPLATES, type PackageJsonFields, type ProjectTemplateId, type StyleExtension, generatePackageJsonFields, generateStencilConfig, getComponentBoilerplate, getStyleBoilerplate, getTemplatePath, toPascalCase };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
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
|
+
//#region src/project/config.ts
|
|
69
|
+
/**
|
|
70
|
+
* Returns stencil.config.ts source for the given selections, or null if zero-config
|
|
71
|
+
* covers everything (outputs = [] | ['loader'], no signals, no docs).
|
|
72
|
+
*
|
|
73
|
+
* @param sel - Wizard selections to encode into the config file.
|
|
74
|
+
* @returns TypeScript source string, or null if no config file is needed.
|
|
75
|
+
*/
|
|
76
|
+
function generateStencilConfig(sel) {
|
|
77
|
+
if ((sel.outputs.length === 0 || sel.outputs.length === 1 && sel.outputs[0] === "loader") && !sel.signals && sel.docs.length === 0) return null;
|
|
78
|
+
const outputLines = [];
|
|
79
|
+
if (sel.outputs.includes("loader") || sel.outputs.length === 0) outputLines.push(` { type: 'loader-bundle' },`);
|
|
80
|
+
if (sel.outputs.includes("standalone")) outputLines.push(` { type: 'standalone' },`);
|
|
81
|
+
if (sel.outputs.includes("ssr")) outputLines.push(` { type: 'ssr' },`);
|
|
82
|
+
if (sel.outputs.includes("ssr-wasm")) outputLines.push(` { type: 'ssr-wasm' },`);
|
|
83
|
+
if (sel.outputs.includes("www")) outputLines.push(` { type: 'www' },`);
|
|
84
|
+
if (sel.docs.includes("cem")) outputLines.push(` { type: 'docs-custom-elements-manifest', file: 'custom-elements.json' },`);
|
|
85
|
+
if (sel.docs.includes("json")) outputLines.push(` { type: 'docs-json', file: 'docs/api.json' },`);
|
|
86
|
+
if (sel.docs.includes("vscode")) outputLines.push(` { type: 'docs-vscode', file: 'vscode-data.json' },`);
|
|
87
|
+
const parts = [
|
|
88
|
+
`import type { Config } from '@stencil/core';`,
|
|
89
|
+
``,
|
|
90
|
+
`export const config: Config = {`,
|
|
91
|
+
` namespace: '${sel.namespace}',`
|
|
92
|
+
];
|
|
93
|
+
if (outputLines.length > 0) {
|
|
94
|
+
parts.push(` outputTargets: [`);
|
|
95
|
+
parts.push(...outputLines);
|
|
96
|
+
parts.push(` ],`);
|
|
97
|
+
}
|
|
98
|
+
if (sel.signals) parts.push(` signalBacking: true,`);
|
|
99
|
+
parts.push(`};`);
|
|
100
|
+
parts.push(``);
|
|
101
|
+
return parts.join("\n");
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Returns the package.json distributable fields for the given output selections.
|
|
105
|
+
* Returns an empty object for www-only (non-publishable app mode).
|
|
106
|
+
* Priority: loader > standalone > ssr > ssr-wasm.
|
|
107
|
+
* @param outputs - Wizard output selections to encode into package.json.
|
|
108
|
+
* @returns An object with the fields to write into package.json.
|
|
109
|
+
*/
|
|
110
|
+
function generatePackageJsonFields(outputs) {
|
|
111
|
+
const isDefault = outputs.length === 0;
|
|
112
|
+
const has = (key) => outputs.includes(key);
|
|
113
|
+
if (isDefault || has("loader")) return {
|
|
114
|
+
type: "module",
|
|
115
|
+
module: "./dist/loader-bundle/index.js",
|
|
116
|
+
types: "./dist/types/loader.d.ts"
|
|
117
|
+
};
|
|
118
|
+
if (has("standalone")) return {
|
|
119
|
+
type: "module",
|
|
120
|
+
module: "./dist/standalone/index.js",
|
|
121
|
+
types: "./dist/types/standalone.d.ts"
|
|
122
|
+
};
|
|
123
|
+
if (has("ssr")) return {
|
|
124
|
+
type: "module",
|
|
125
|
+
module: "./dist/ssr/index.js",
|
|
126
|
+
types: "./dist/ssr/index.d.ts"
|
|
127
|
+
};
|
|
128
|
+
if (has("ssr-wasm")) return {
|
|
129
|
+
type: "module",
|
|
130
|
+
module: "./dist/ssr-wasm/index.js",
|
|
131
|
+
types: "./dist/ssr-wasm/plugin.d.ts"
|
|
132
|
+
};
|
|
133
|
+
return {};
|
|
134
|
+
}
|
|
135
|
+
//#endregion
|
|
136
|
+
export { PROJECT_TEMPLATES, generatePackageJsonFields, generateStencilConfig, getComponentBoilerplate, getStyleBoilerplate, getTemplatePath, toPascalCase };
|
package/package.json
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@stencil/templates",
|
|
3
|
+
"version": "5.0.0-alpha.11",
|
|
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
|
+
"devDependencies": {
|
|
31
|
+
"tsdown": ">=0.21.0 <1.0.0",
|
|
32
|
+
"typescript": ">4.0.0 <7.0.0",
|
|
33
|
+
"vitest": "^4.1.7"
|
|
34
|
+
},
|
|
35
|
+
"volta": {
|
|
36
|
+
"extends": "../../package.json"
|
|
37
|
+
},
|
|
38
|
+
"scripts": {
|
|
39
|
+
"build": "tsdown",
|
|
40
|
+
"test": "vitest run --passWithNoTests",
|
|
41
|
+
"typecheck": "tsc --noEmit"
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
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
|
+
"scripts": {
|
|
10
|
+
"build": "stencil build",
|
|
11
|
+
"dev": "stencil build --dev --watch --serve",
|
|
12
|
+
"generate": "stencil generate"
|
|
13
|
+
},
|
|
14
|
+
"devDependencies": {
|
|
15
|
+
"@stencil/core": "{{STENCIL_VERSION}}"
|
|
16
|
+
},
|
|
17
|
+
"collection": "./dist/collection/collection-manifest.json"
|
|
18
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Component, Prop } from '@stencil/core';
|
|
2
|
+
|
|
3
|
+
import { format } from '../../utils/utils';
|
|
4
|
+
|
|
5
|
+
@Component({
|
|
6
|
+
tag: 'my-component',
|
|
7
|
+
styleUrl: 'my-component.css',
|
|
8
|
+
encapsulation: { type: 'shadow' },
|
|
9
|
+
})
|
|
10
|
+
export class MyComponent {
|
|
11
|
+
/** The first name */
|
|
12
|
+
@Prop() first?: string;
|
|
13
|
+
|
|
14
|
+
/** The middle name */
|
|
15
|
+
@Prop() middle?: string;
|
|
16
|
+
|
|
17
|
+
/** The last name */
|
|
18
|
+
@Prop() last?: string;
|
|
19
|
+
|
|
20
|
+
private getText(): string {
|
|
21
|
+
return format(this.first, this.middle, this.last);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
render() {
|
|
25
|
+
return <div>Hello, World! I'm {this.getText()}</div>;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -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
|
+
}
|