create-backtick-app 0.0.0-stage → 0.1.1

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 (44) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +84 -2
  3. package/dist/index.d.ts +2 -0
  4. package/dist/index.js +150 -0
  5. package/package.json +56 -3
  6. package/templates/react/.prettierignore +8 -0
  7. package/templates/react/.prettierrc +3 -0
  8. package/templates/react/.vscode/extensions.json +6 -0
  9. package/templates/react/gitignore +16 -0
  10. package/templates/react/package.json +31 -0
  11. package/templates/react/scripts/reset-project.mjs +21 -0
  12. package/templates/react/scripts/start.mjs +20 -0
  13. package/templates/react/server/HelloWave.tsx +30 -0
  14. package/templates/react/server/Home.tsx +65 -0
  15. package/templates/react/server/html.ts +62 -0
  16. package/templates/react/server/index.tsx +33 -0
  17. package/templates/react/tsconfig.json +18 -0
  18. package/templates/react-native/.prettierignore +16 -0
  19. package/templates/react-native/.prettierrc +3 -0
  20. package/templates/react-native/.vscode/extensions.json +6 -0
  21. package/templates/react-native/App.tsx +117 -0
  22. package/templates/react-native/app.json +9 -0
  23. package/templates/react-native/gitignore +41 -0
  24. package/templates/react-native/index.ts +8 -0
  25. package/templates/react-native/package.json +44 -0
  26. package/templates/react-native/scripts/reset-project.mjs +22 -0
  27. package/templates/react-native/scripts/start.mjs +31 -0
  28. package/templates/react-native/server/HelloWave.tsx +51 -0
  29. package/templates/react-native/server/Home.tsx +84 -0
  30. package/templates/react-native/server/index.tsx +50 -0
  31. package/templates/react-native/server/tsconfig.json +17 -0
  32. package/templates/react-native/tsconfig.json +7 -0
  33. package/templates/solid-js/.prettierignore +8 -0
  34. package/templates/solid-js/.prettierrc +3 -0
  35. package/templates/solid-js/.vscode/extensions.json +6 -0
  36. package/templates/solid-js/gitignore +16 -0
  37. package/templates/solid-js/package.json +31 -0
  38. package/templates/solid-js/scripts/reset-project.mjs +21 -0
  39. package/templates/solid-js/scripts/start.mjs +20 -0
  40. package/templates/solid-js/server/HelloWave.tsx +34 -0
  41. package/templates/solid-js/server/Home.tsx +65 -0
  42. package/templates/solid-js/server/html.ts +62 -0
  43. package/templates/solid-js/server/index.tsx +33 -0
  44. package/templates/solid-js/tsconfig.json +18 -0
@@ -0,0 +1,65 @@
1
+ import { cs } from "@backtickjs/core";
2
+ import { HelloWave } from "./HelloWave.js";
3
+
4
+ // A server component: it runs on your server for every request, and hands the
5
+ // browser its data and its client components.
6
+ export async function Home() {
7
+ // Read here, on your server, and sent to the browser as plain values.
8
+ const node = process.version;
9
+ const assembledAt = new Date().toLocaleTimeString();
10
+
11
+ return cs`{
12
+ const styles = {
13
+ page: {
14
+ "max-width": "640px",
15
+ padding: "24px",
16
+ "font-family": "system-ui, sans-serif",
17
+ display: "grid",
18
+ gap: "24px",
19
+ },
20
+ titleRow: { display: "flex", "align-items": "center", gap: "8px" },
21
+ title: { margin: "0", "font-size": "32px", "line-height": "1" },
22
+ step: { display: "grid", gap: "8px" },
23
+ subtitle: { margin: "0", "font-size": "20px" },
24
+ body: { margin: "0", "font-size": "16px", "line-height": "1.5" },
25
+ link: { "font-size": "16px", color: "#0a7ea4" },
26
+ };
27
+
28
+ return (
29
+ <main style={styles.page}>
30
+ <div style={styles.titleRow}>
31
+ <h1 style={styles.title}>Welcome!</h1>
32
+ <$HelloWave />
33
+ </div>
34
+
35
+ <section style={styles.step}>
36
+ <h2 style={styles.subtitle}>Step 1: Try it</h2>
37
+ <p style={styles.body}>
38
+ Edit <b>server/Home.tsx</b> and save. This page redraws on its own.
39
+ </p>
40
+ </section>
41
+
42
+ <section style={styles.step}>
43
+ <h2 style={styles.subtitle}>Step 2: Server and client</h2>
44
+ <p style={styles.body}>
45
+ Your server assembled this page with Node {$node} at {$assembledAt}.
46
+ The waving hand is a client component: its animation runs in your
47
+ browser. Click it.
48
+ </p>
49
+ </section>
50
+
51
+ <section style={styles.step}>
52
+ <h2 style={styles.subtitle}>Step 3: Get a fresh start</h2>
53
+ <p style={styles.body}>
54
+ When you're ready, run <b>npm run reset-project</b> for a blank{" "}
55
+ <b>server/Home.tsx</b>.
56
+ </p>
57
+ </section>
58
+
59
+ <a style={styles.link} href="https://backtickjs.com/docs">
60
+ Read the docs →
61
+ </a>
62
+ </main>
63
+ );
64
+ }`;
65
+ }
@@ -0,0 +1,62 @@
1
+ import { bundler } from "@backtickjs/bundler";
2
+ import { cs } from "@backtickjs/core";
3
+ import { render } from "@backtickjs/solid-js/web";
4
+ import type { JSX } from "@backtickjs/solid-js/jsx-runtime";
5
+
6
+ // The version of Solid the page loads, below: what each page is bundled for.
7
+ const packageVersions = { "solid-js": "1.9.14" };
8
+
9
+ // Development is only what `npm start` runs, which sets NODE_ENV: any other
10
+ // run, a deploy included, is production.
11
+ export const development = process.env.NODE_ENV === "development";
12
+
13
+ // In development, what reloads the page whenever the server restarts, as it
14
+ // does when you save.
15
+ const reload = `
16
+ <script type="module">
17
+ let run;
18
+ setInterval(async () => {
19
+ try {
20
+ const next = await (await fetch("/live")).text();
21
+ if (run !== undefined && next !== run) location.reload();
22
+ run = next;
23
+ } catch {}
24
+ }, 1000);
25
+ </script>`;
26
+
27
+ // A page: the element, bundled for the browser, and Solid from a CDN.
28
+ export async function toHtml(element: JSX.Element): Promise<string> {
29
+ const bundle = await bundler.build({
30
+ input: cs`$render(() => $element, document.getElementById("app")!)`,
31
+ packageVersions,
32
+ });
33
+ // In development, a map back to the files you wrote, for the browser's
34
+ // devtools.
35
+ const { code } = bundle.generate({
36
+ format: "es",
37
+ sourcemap: development ? "inline" : false,
38
+ });
39
+
40
+ return `<!doctype html>
41
+ <html lang="en">
42
+ <head>
43
+ <meta charset="utf-8">
44
+ <meta name="viewport" content="width=device-width, initial-scale=1">
45
+ <title>Backtick</title>
46
+ <script type="importmap">
47
+ {
48
+ "imports": {
49
+ "solid-js": "https://cdn.jsdelivr.net/npm/solid-js@1.9.14/dist/solid.js",
50
+ "solid-js/web": "https://cdn.jsdelivr.net/npm/solid-js@1.9.14/web/dist/web.js",
51
+ "solid-js/store": "https://cdn.jsdelivr.net/npm/solid-js@1.9.14/store/dist/store.js"
52
+ }
53
+ }
54
+ </script>
55
+ </head>
56
+ <body style="margin: 0">
57
+ <div id="app"></div>
58
+ <script type="module" src="data:text/javascript,${encodeURIComponent(code)}"></script>
59
+ ${development ? reload : ""}
60
+ </body>
61
+ </html>`;
62
+ }
@@ -0,0 +1,33 @@
1
+ import { createServer } from "node:http";
2
+ import { Home } from "./Home.js";
3
+ import { development, toHtml } from "./html.js";
4
+
5
+ // In development, this run of the server: `--watch` starts a new one whenever
6
+ // you save, and the page, seeing a new one at `/live`, reloads.
7
+ const run = crypto.randomUUID();
8
+
9
+ const server = createServer(async (request, response) => {
10
+ if (development && request.url === "/live") {
11
+ response.end(run);
12
+ return;
13
+ }
14
+ if (request.url === "/") {
15
+ try {
16
+ const html = await toHtml(<Home />);
17
+ response.setHeader("content-type", "text/html");
18
+ response.end(html);
19
+ } catch (error) {
20
+ // Answered rather than crashed on, so the browser can show why.
21
+ console.error(error);
22
+ response.statusCode = 500;
23
+ response.end(String(error));
24
+ }
25
+ return;
26
+ }
27
+ response.statusCode = 404;
28
+ response.end();
29
+ });
30
+
31
+ server.listen(3000, () => {
32
+ console.log("Backtick server on http://localhost:3000");
33
+ });
@@ -0,0 +1,18 @@
1
+ {
2
+ "compilerOptions": {
3
+ // Imports kept as written: a name a page only splices, as `$onMount`, looks
4
+ // unused to TypeScript, which would otherwise drop its import.
5
+ "verbatimModuleSyntax": true,
6
+ "module": "esnext",
7
+ "moduleResolution": "bundler",
8
+ "target": "esnext",
9
+ "strict": true,
10
+ "noEmit": true,
11
+ "skipLibCheck": true,
12
+ "lib": ["esnext", "dom"],
13
+ "types": ["node"],
14
+ "jsx": "react-jsx",
15
+ "jsxImportSource": "@backtickjs/solid-js"
16
+ },
17
+ "include": ["server"]
18
+ }