Skip to content

Commit

Permalink
add clicker and client example to create-hwy template & cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
sjc5 committed Oct 24, 2023
1 parent d483cd6 commit ada88af
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 12 deletions.
12 changes: 12 additions & 0 deletions packages/create-hwy/__common/pages/_index.client.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/// <reference lib="dom" />

const el = document.getElementById("increment-button");

if (el) {
let count = 0;

el.addEventListener("click", () => {
count++;
el.innerHTML = count.toString();
});
}
9 changes: 9 additions & 0 deletions packages/create-hwy/__common/pages/_index.page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@ export default function () {
The nav bar above is being rendered from <code>src/main.tsx</code>,
which is your site's main server "entry point".
</p>

<p>
Click the button below to increment the number (my click handler is in{" "}
<code>src/pages/_index.client.tsx</code>):
</p>

<button id="increment-button" class="btn">
0
</button>
</>
);
}
21 changes: 15 additions & 6 deletions packages/create-hwy/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -355,8 +355,8 @@ async function main() {
is_jsx: false,
});

// pages
const pages_to_copy = [
// pages dir in __common
const tsx_list = [
"about.page",
"$.page",
"_index.page",
Expand All @@ -365,15 +365,24 @@ async function main() {
"__auth/login.page",
];

const ts_list = ["_index.client"];

const files_to_copy = [...tsx_list, ...ts_list];

await Promise.all(
pages_to_copy.map(async (page) => {
files_to_copy.map(async (file) => {
const is_jsx = tsx_list.includes(file);

return handle_ts_or_js_file_copy({
code: fs.readFileSync(
path.join(root_dir_path, "__common/pages/" + page + ".tsx"),
path.join(
root_dir_path,
"__common/pages/" + file + (is_jsx ? ".tsx" : ".ts"),
),
"utf8",
),
destination_without_extension: "src/pages/" + page,
is_jsx: true,
destination_without_extension: "src/pages/" + file,
is_jsx,
});
}),
);
Expand Down
6 changes: 1 addition & 5 deletions packages/create-hwy/src/get-main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,7 @@ ${
: `await hwyInit({
app,
importMetaUrl: import.meta.url,
serveStatic,${
options.css_preference === "tailwind"
? `\n watchExclusions: ["src/styles/tw-output.bundle.css"],`
: ""
}
serveStatic,
});`
}
Expand Down
1 change: 0 additions & 1 deletion packages/create-hwy/src/get-readme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ await hwyInit({
* to add a publicUrlPrefix.
*/
publicUrlPrefix: process.env.NODE_ENV === "production" ? "docs/" : undefined,
watchExclusions: ["src/styles/tw-output.bundle.css"],
});
\`\`\`
`.trim() +
Expand Down

0 comments on commit ada88af

Please sign in to comment.