Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update naming conventions #22

Merged
merged 3 commits into from Aug 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/cli/build.ts
Expand Up @@ -9,13 +9,13 @@ export async function build() {
const cwd = process.cwd();
const buildDirectory = `${cwd}/build`;
const publicDirectory = `${cwd}/public`;
const wcDirectory = `${cwd}/src/components/wc`;
const islandsDirectory = `${cwd}/src/components/islands`;
const pagesDirectory = `${cwd}/src/pages`;

delDir(buildDirectory);
createDir(buildDirectory);
copyDirContents(publicDirectory, buildDirectory);
copyDirContents(wcDirectory, buildDirectory);
copyDirContents(islandsDirectory, buildDirectory);

await buildPages(buildDirectory, pagesDirectory);

Expand All @@ -42,10 +42,10 @@ async function buildPages(buildDirectory: string, pagesDirectory: string) {
let pageName = '';
switch (fileExtension) {
case '.js':
pageName = file.replace('.js', '');
pageName = file.replace('.js', '').toLowerCase();
break;
case '.md':
pageName = file.replace('.md', '');
pageName = file.replace('.md', '').toLowerCase();
break;
default:
throw new Error(
Expand Down
9 changes: 7 additions & 2 deletions src/core/webComponents.ts
Expand Up @@ -6,8 +6,13 @@ export function addWebComponents(output: string) {
for (const file of buildFiles) {
const fileExtension = path.extname(file);
if (fileExtension === '.js') {
const wcName = file.replace('.js', '');
// Developer note: When checking for an opening tag, we leave out the
// Turn a file (WebComponent.js) into its name `web-component`
const wcName = file
.replace('.js', '')
.split(/(?=[A-Z])/)
.join('-')
.toLowerCase();
// Developer note: When checking for an opening tag, we leave out the
// closing alligator (`>`) because the web component might include attributes.
if (output.includes(`<${wcName}`) && output.includes(`</${wcName}>`)) {
const wcScript = `<script type="module" src="/${file}"></script>`;
Expand Down