create-waku 0.6.0 → 0.6.2

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 (189) hide show
  1. package/dist/cli.js +45 -45
  2. package/package.json +4 -4
  3. package/src/cli.ts +45 -45
  4. package/template/01_counter/dist/components/App.js +2 -2
  5. package/template/01_counter/dist/components/Counter.js +3 -3
  6. package/template/01_counter/dist/entries.js +18 -17
  7. package/template/01_counter/dist/main.js +9 -4
  8. package/template/01_counter/node_modules/.bin/vite +17 -0
  9. package/template/01_counter/package.json +11 -8
  10. package/template/01_counter/src/components/App.tsx +2 -2
  11. package/template/01_counter/src/components/Counter.tsx +3 -3
  12. package/template/01_counter/src/entries.tsx +18 -18
  13. package/template/01_counter/src/index.html +1 -0
  14. package/template/01_counter/src/main.tsx +8 -4
  15. package/template/01_counter/tsconfig.json +2 -2
  16. package/template/02_async/dist/components/App.js +13 -0
  17. package/template/02_async/dist/{src/components → components}/Counter.js +3 -3
  18. package/template/02_async/dist/entries.js +32 -0
  19. package/template/02_async/dist/main.js +11 -0
  20. package/template/02_async/node_modules/.bin/vite +17 -0
  21. package/template/02_async/package.json +11 -8
  22. package/template/02_async/src/components/App.tsx +5 -17
  23. package/template/02_async/src/components/Counter.tsx +3 -3
  24. package/template/02_async/src/entries.tsx +18 -18
  25. package/template/02_async/src/index.html +2 -1
  26. package/template/02_async/src/main.tsx +8 -15
  27. package/template/02_async/tsconfig.json +3 -10
  28. package/template/03_promise/dist/components/App.js +3 -3
  29. package/template/03_promise/dist/components/Counter.js +3 -3
  30. package/template/03_promise/dist/entries.js +18 -18
  31. package/template/03_promise/dist/main.js +9 -4
  32. package/template/03_promise/node_modules/.bin/vite +17 -0
  33. package/template/03_promise/package.json +11 -8
  34. package/template/03_promise/src/components/App.tsx +5 -4
  35. package/template/03_promise/src/components/Counter.tsx +3 -3
  36. package/template/03_promise/src/entries.tsx +22 -19
  37. package/template/03_promise/src/index.html +1 -0
  38. package/template/03_promise/src/main.tsx +8 -4
  39. package/template/03_promise/tsconfig.json +2 -2
  40. package/template/04_callserver/dist/components/App.js +3 -3
  41. package/template/04_callserver/dist/components/Counter.js +6 -5
  42. package/template/04_callserver/dist/components/TextBox.js +6 -0
  43. package/template/04_callserver/dist/components/funcs.js +1 -1
  44. package/template/04_callserver/dist/entries.js +18 -17
  45. package/template/04_callserver/dist/main.js +9 -4
  46. package/template/04_callserver/node_modules/.bin/vite +17 -0
  47. package/template/04_callserver/package.json +11 -8
  48. package/template/04_callserver/src/components/App.tsx +3 -3
  49. package/template/04_callserver/src/components/Counter.tsx +10 -7
  50. package/template/04_callserver/src/components/TextBox.tsx +11 -0
  51. package/template/04_callserver/src/components/funcs.ts +1 -1
  52. package/template/04_callserver/src/entries.tsx +18 -18
  53. package/template/04_callserver/src/index.html +1 -0
  54. package/template/04_callserver/src/main.tsx +8 -4
  55. package/template/04_callserver/tsconfig.json +2 -2
  56. package/template/05_mutation/dist/components/App.js +4 -3
  57. package/template/05_mutation/dist/components/Counter.js +3 -3
  58. package/template/05_mutation/dist/components/funcs.js +3 -3
  59. package/template/05_mutation/dist/entries.js +18 -17
  60. package/template/05_mutation/dist/main.js +9 -4
  61. package/template/05_mutation/node_modules/.bin/vite +17 -0
  62. package/template/05_mutation/package.json +12 -8
  63. package/template/05_mutation/src/components/App.tsx +6 -3
  64. package/template/05_mutation/src/components/Counter.tsx +5 -5
  65. package/template/05_mutation/src/components/funcs.ts +3 -3
  66. package/template/05_mutation/src/entries.tsx +18 -18
  67. package/template/05_mutation/src/index.html +1 -0
  68. package/template/05_mutation/src/main.tsx +8 -4
  69. package/template/05_mutation/tsconfig.json +2 -2
  70. package/template/06_nesting/dist/components/App.js +2 -2
  71. package/template/06_nesting/dist/components/Counter.js +6 -6
  72. package/template/06_nesting/dist/components/InnerApp.js +3 -3
  73. package/template/06_nesting/dist/entries.js +28 -27
  74. package/template/06_nesting/dist/main.js +9 -4
  75. package/template/06_nesting/node_modules/.bin/vite +17 -0
  76. package/template/06_nesting/package.json +11 -8
  77. package/template/06_nesting/src/components/App.tsx +2 -2
  78. package/template/06_nesting/src/components/Counter.tsx +8 -8
  79. package/template/06_nesting/src/components/InnerApp.tsx +3 -3
  80. package/template/06_nesting/src/entries.tsx +29 -29
  81. package/template/06_nesting/src/index.html +1 -0
  82. package/template/06_nesting/src/main.tsx +8 -4
  83. package/template/06_nesting/tsconfig.json +2 -2
  84. package/template/07_router/dist/node/tsconfig.node.tsbuildinfo +1 -0
  85. package/template/07_router/dist/node/vite.config.d.ts +14 -1
  86. package/template/07_router/dist/node/vite.config.js +9 -6
  87. package/template/07_router/dist/src/components/Counter.js +4 -4
  88. package/template/07_router/dist/src/components/ErrorBoundary.d.ts +1 -1
  89. package/template/07_router/dist/src/components/ErrorBoundary.js +2 -2
  90. package/template/07_router/dist/src/entries.js +9 -9
  91. package/template/07_router/dist/src/main.js +10 -5
  92. package/template/07_router/dist/src/routes/bar/page.js +1 -1
  93. package/template/07_router/dist/src/routes/foo/page.js +1 -1
  94. package/template/07_router/dist/src/routes/layout.d.ts +1 -1
  95. package/template/07_router/dist/src/routes/layout.js +2 -2
  96. package/template/07_router/dist/src/routes/nested/layout.d.ts +1 -1
  97. package/template/07_router/dist/src/routes/nested/layout.js +1 -1
  98. package/template/07_router/dist/tsconfig.tsbuildinfo +1 -0
  99. package/template/07_router/node_modules/.bin/vite +17 -0
  100. package/template/07_router/package.json +11 -8
  101. package/template/07_router/src/components/Counter.tsx +4 -4
  102. package/template/07_router/src/components/ErrorBoundary.tsx +3 -3
  103. package/template/07_router/src/entries.tsx +9 -10
  104. package/template/07_router/src/index.html +1 -0
  105. package/template/07_router/src/main.tsx +9 -5
  106. package/template/07_router/src/routes/bar/page.tsx +1 -1
  107. package/template/07_router/src/routes/foo/page.tsx +1 -1
  108. package/template/07_router/src/routes/layout.tsx +3 -3
  109. package/template/07_router/src/routes/nested/layout.tsx +2 -2
  110. package/template/07_router/tsconfig.json +0 -1
  111. package/template/07_router/tsconfig.node.json +0 -1
  112. package/template/07_router/vite.config.ts +9 -7
  113. package/template/08_cookies/dev.js +9 -13
  114. package/template/08_cookies/dist/components/App.js +3 -3
  115. package/template/08_cookies/dist/components/Counter.js +3 -3
  116. package/template/08_cookies/dist/entries.js +19 -6
  117. package/template/08_cookies/dist/main.js +9 -4
  118. package/template/08_cookies/node_modules/.bin/vite +17 -0
  119. package/template/08_cookies/package.json +13 -10
  120. package/template/08_cookies/src/components/App.tsx +3 -3
  121. package/template/08_cookies/src/components/Counter.tsx +3 -3
  122. package/template/08_cookies/src/entries.tsx +18 -19
  123. package/template/08_cookies/src/index.html +1 -0
  124. package/template/08_cookies/src/main.tsx +8 -4
  125. package/template/08_cookies/start.js +14 -16
  126. package/template/08_cookies/tsconfig.json +2 -2
  127. package/template/09_cssmodules/dist/components/App.js +3 -3
  128. package/template/09_cssmodules/dist/components/Counter.js +3 -3
  129. package/template/09_cssmodules/dist/entries.js +18 -17
  130. package/template/09_cssmodules/dist/main.js +9 -4
  131. package/template/09_cssmodules/node_modules/.bin/vite +17 -0
  132. package/template/09_cssmodules/package.json +11 -8
  133. package/template/09_cssmodules/src/components/App.tsx +3 -3
  134. package/template/09_cssmodules/src/components/Counter.tsx +3 -3
  135. package/template/09_cssmodules/src/entries.tsx +18 -18
  136. package/template/09_cssmodules/src/index.html +1 -0
  137. package/template/09_cssmodules/src/main.tsx +8 -4
  138. package/template/09_cssmodules/tsconfig.json +2 -2
  139. package/template/10_dynamicroute/dist/node/tsconfig.node.tsbuildinfo +1 -0
  140. package/template/10_dynamicroute/dist/node/vite.config.d.ts +14 -1
  141. package/template/10_dynamicroute/dist/node/vite.config.js +9 -6
  142. package/template/10_dynamicroute/dist/src/entries.js +15 -15
  143. package/template/10_dynamicroute/dist/src/main.js +9 -4
  144. package/template/10_dynamicroute/dist/src/routes/layout.d.ts +1 -1
  145. package/template/10_dynamicroute/dist/src/routes/layout.js +1 -1
  146. package/template/10_dynamicroute/dist/tsconfig.tsbuildinfo +1 -0
  147. package/template/10_dynamicroute/node_modules/.bin/vite +17 -0
  148. package/template/10_dynamicroute/package.json +11 -8
  149. package/template/10_dynamicroute/src/entries.tsx +15 -16
  150. package/template/10_dynamicroute/src/index.html +1 -0
  151. package/template/10_dynamicroute/src/main.tsx +8 -4
  152. package/template/10_dynamicroute/src/routes/layout.tsx +2 -2
  153. package/template/10_dynamicroute/tsconfig.json +0 -1
  154. package/template/10_dynamicroute/tsconfig.node.json +0 -1
  155. package/template/10_dynamicroute/vite.config.ts +9 -7
  156. package/template/11_form/dist/components/App.js +4 -4
  157. package/template/11_form/dist/components/Counter.js +4 -4
  158. package/template/11_form/dist/components/Form.js +4 -4
  159. package/template/11_form/dist/components/funcs.js +5 -5
  160. package/template/11_form/dist/entries.js +18 -17
  161. package/template/11_form/dist/main.js +9 -4
  162. package/template/11_form/node_modules/.bin/vite +17 -0
  163. package/template/11_form/package.json +11 -8
  164. package/template/11_form/src/components/App.tsx +4 -4
  165. package/template/11_form/src/components/Counter.tsx +4 -4
  166. package/template/11_form/src/components/Form.tsx +4 -4
  167. package/template/11_form/src/components/funcs.ts +5 -5
  168. package/template/11_form/src/entries.tsx +18 -18
  169. package/template/11_form/src/index.html +1 -0
  170. package/template/11_form/src/main.tsx +8 -4
  171. package/template/11_form/tsconfig.json +2 -2
  172. package/dist/.tsbuildinfo +0 -1
  173. package/template/02_async/dist/.tsbuildinfo +0 -1
  174. package/template/02_async/dist/node/.tsbuildinfo +0 -1
  175. package/template/02_async/dist/node/vite.config.d.ts +0 -2
  176. package/template/02_async/dist/node/vite.config.js +0 -14
  177. package/template/02_async/dist/src/components/App.d.ts +0 -4
  178. package/template/02_async/dist/src/components/App.js +0 -16
  179. package/template/02_async/dist/src/components/Counter.d.ts +0 -1
  180. package/template/02_async/dist/src/entries.d.ts +0 -6
  181. package/template/02_async/dist/src/entries.js +0 -31
  182. package/template/02_async/dist/src/main.d.ts +0 -1
  183. package/template/02_async/dist/src/main.js +0 -15
  184. package/template/02_async/tsconfig.node.json +0 -9
  185. package/template/02_async/vite.config.ts +0 -16
  186. package/template/07_router/dist/.tsbuildinfo +0 -1
  187. package/template/07_router/dist/node/.tsbuildinfo +0 -1
  188. package/template/10_dynamicroute/dist/.tsbuildinfo +0 -1
  189. package/template/10_dynamicroute/dist/node/.tsbuildinfo +0 -1
package/dist/cli.js CHANGED
@@ -1,10 +1,10 @@
1
1
  #!/usr/bin/env node
2
- import fs from "node:fs";
3
- import path from "node:path";
4
- import { default as prompts } from "prompts";
5
- import { red, green, bold } from "kolorist";
6
- import fse from "fs-extra/esm";
7
- import { fileURLToPath } from "node:url";
2
+ import fs from 'node:fs';
3
+ import path from 'node:path';
4
+ import { default as prompts } from 'prompts';
5
+ import { red, green, bold } from 'kolorist';
6
+ import fse from 'fs-extra/esm';
7
+ import { fileURLToPath } from 'node:url';
8
8
  function isValidPackageName(projectName) {
9
9
  return /^(?:@[a-z0-9-*~][a-z0-9-*._~]*\/)?[a-z0-9-~][a-z0-9-._~]*$/.test(projectName);
10
10
  }
@@ -12,63 +12,63 @@ function toValidPackageName(projectName) {
12
12
  return projectName
13
13
  .trim()
14
14
  .toLowerCase()
15
- .replace(/\s+/g, "-")
16
- .replace(/^[._]/, "")
17
- .replace(/[^a-z0-9-~]+/g, "-");
15
+ .replace(/\s+/g, '-')
16
+ .replace(/^[._]/, '')
17
+ .replace(/[^a-z0-9-~]+/g, '-');
18
18
  }
19
19
  // if the dir is empty or not exist
20
20
  function canSafelyOverwrite(dir) {
21
21
  return !fs.existsSync(dir) || fs.readdirSync(dir).length === 0;
22
22
  }
23
23
  async function init() {
24
- let targetDir = "";
25
- const defaultProjectName = "waku-project";
26
- const templateRoot = fileURLToPath(new URL("../template", import.meta.url));
24
+ let targetDir = '';
25
+ const defaultProjectName = 'waku-project';
26
+ const templateRoot = fileURLToPath(new URL('../template', import.meta.url));
27
27
  const CHOICES = fs.readdirSync(templateRoot);
28
28
  let result;
29
29
  try {
30
30
  result = await prompts([
31
31
  {
32
- name: "projectName",
33
- type: "text",
34
- message: "Project Name",
32
+ name: 'projectName',
33
+ type: 'text',
34
+ message: 'Project Name',
35
35
  initial: defaultProjectName,
36
36
  onState: (state) => (targetDir = String(state.value).trim() || defaultProjectName),
37
37
  },
38
38
  {
39
- name: "shouldOverwrite",
40
- type: () => (canSafelyOverwrite(targetDir) ? null : "confirm"),
39
+ name: 'shouldOverwrite',
40
+ type: () => (canSafelyOverwrite(targetDir) ? null : 'confirm'),
41
41
  message: `${targetDir} is not empty. Remove existing files and continue?`,
42
42
  },
43
43
  {
44
- name: "overwriteChecker",
44
+ name: 'overwriteChecker',
45
45
  type: (values) => {
46
46
  if (values === false) {
47
- throw new Error(red("") + " Operation cancelled");
47
+ throw new Error(red('') + ' Operation cancelled');
48
48
  }
49
49
  return null;
50
50
  },
51
51
  },
52
52
  {
53
- name: "packageName",
54
- type: () => (isValidPackageName(targetDir) ? null : "text"),
55
- message: "Package name",
53
+ name: 'packageName',
54
+ type: () => (isValidPackageName(targetDir) ? null : 'text'),
55
+ message: 'Package name',
56
56
  initial: () => toValidPackageName(targetDir),
57
- validate: (dir) => isValidPackageName(dir) || "Invalid package.json name",
57
+ validate: (dir) => isValidPackageName(dir) || 'Invalid package.json name',
58
58
  },
59
59
  {
60
- name: "chooseProject",
61
- type: "select",
62
- message: "Choose a starter template",
60
+ name: 'chooseProject',
61
+ type: 'select',
62
+ message: 'Choose a starter template',
63
63
  choices: [
64
- { title: "basic-template", value: CHOICES[0] },
65
- { title: "async-template", value: CHOICES[1] },
66
- { title: "promise-template", value: CHOICES[2] },
64
+ { title: 'basic-template', value: CHOICES[0] },
65
+ { title: 'async-template', value: CHOICES[1] },
66
+ { title: 'promise-template', value: CHOICES[2] },
67
67
  ],
68
68
  },
69
69
  ], {
70
70
  onCancel: () => {
71
- throw new Error(red("") + " Operation cancelled");
71
+ throw new Error(red('') + ' Operation cancelled');
72
72
  },
73
73
  });
74
74
  }
@@ -88,36 +88,36 @@ async function init() {
88
88
  }
89
89
  const pkg = {
90
90
  name: packageName ?? toValidPackageName(targetDir),
91
- version: "0.0.0",
91
+ version: '0.0.0',
92
92
  };
93
- console.log("Setting up project...");
93
+ console.log('Setting up project...');
94
94
  const templateDir = path.join(templateRoot, chooseProject);
95
95
  // Read existing package.json from the root directory
96
- const packageJsonPath = path.join(root, "package.json");
96
+ const packageJsonPath = path.join(root, 'package.json');
97
97
  // Read new package.json from the template directory
98
- const newPackageJsonPath = path.join(templateDir, "package.json");
99
- const newPackageJson = JSON.parse(fs.readFileSync(newPackageJsonPath, "utf-8"));
98
+ const newPackageJsonPath = path.join(templateDir, 'package.json');
99
+ const newPackageJson = JSON.parse(fs.readFileSync(newPackageJsonPath, 'utf-8'));
100
100
  fse.copySync(templateDir, root);
101
101
  fs.writeFileSync(packageJsonPath, JSON.stringify({
102
102
  ...newPackageJson,
103
103
  ...pkg,
104
104
  }, null, 2));
105
- const manager = process.env.npm_config_user_agent ?? "";
105
+ const manager = process.env.npm_config_user_agent ?? '';
106
106
  const packageManager = /pnpm/.test(manager)
107
- ? "pnpm"
107
+ ? 'pnpm'
108
108
  : /yarn/.test(manager)
109
- ? "yarn"
110
- : "npm";
109
+ ? 'yarn'
110
+ : 'npm';
111
111
  const commandsMap = {
112
112
  install: {
113
- pnpm: "pnpm install",
114
- yarn: "yarn",
115
- npm: "npm install",
113
+ pnpm: 'pnpm install',
114
+ yarn: 'yarn',
115
+ npm: 'npm install',
116
116
  },
117
117
  dev: {
118
- pnpm: "pnpm dev",
119
- yarn: "yarn dev",
120
- npm: "npm run dev",
118
+ pnpm: 'pnpm dev',
119
+ yarn: 'yarn dev',
120
+ npm: 'npm run dev',
121
121
  },
122
122
  };
123
123
  console.log(`\nDone. Now run:\n`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-waku",
3
- "version": "0.6.0",
3
+ "version": "0.6.2",
4
4
  "author": "Daishi Kato",
5
5
  "type": "module",
6
6
  "contributors": [
@@ -22,12 +22,12 @@
22
22
  "prompts": "^2.4.2"
23
23
  },
24
24
  "devDependencies": {
25
- "@types/fs-extra": "^11.0.2",
26
- "@types/prompts": "^2.4.5"
25
+ "@types/fs-extra": "^11.0.4",
26
+ "@types/prompts": "^2.4.8"
27
27
  },
28
28
  "scripts": {
29
29
  "start": "node dist/cli.js",
30
- "compile": "rm -rf template dist && pnpm run template && pnpm run build",
30
+ "compile": "rm -rf template dist *.tsbuildinfo && pnpm run template && pnpm run build",
31
31
  "template": "cp -r ../../examples template/",
32
32
  "build": "tsc -b"
33
33
  }
package/src/cli.ts CHANGED
@@ -1,11 +1,11 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- import fs from "node:fs";
4
- import path from "node:path";
5
- import { default as prompts } from "prompts";
6
- import { red, green, bold } from "kolorist";
7
- import fse from "fs-extra/esm";
8
- import { fileURLToPath } from "node:url";
3
+ import fs from 'node:fs';
4
+ import path from 'node:path';
5
+ import { default as prompts } from 'prompts';
6
+ import { red, green, bold } from 'kolorist';
7
+ import fse from 'fs-extra/esm';
8
+ import { fileURLToPath } from 'node:url';
9
9
 
10
10
  function isValidPackageName(projectName: string) {
11
11
  return /^(?:@[a-z0-9-*~][a-z0-9-*._~]*\/)?[a-z0-9-~][a-z0-9-._~]*$/.test(
@@ -17,9 +17,9 @@ function toValidPackageName(projectName: string) {
17
17
  return projectName
18
18
  .trim()
19
19
  .toLowerCase()
20
- .replace(/\s+/g, "-")
21
- .replace(/^[._]/, "")
22
- .replace(/[^a-z0-9-~]+/g, "-");
20
+ .replace(/\s+/g, '-')
21
+ .replace(/^[._]/, '')
22
+ .replace(/[^a-z0-9-~]+/g, '-');
23
23
  }
24
24
 
25
25
  // if the dir is empty or not exist
@@ -28,10 +28,10 @@ function canSafelyOverwrite(dir: string) {
28
28
  }
29
29
 
30
30
  async function init() {
31
- let targetDir = "";
32
- const defaultProjectName = "waku-project";
31
+ let targetDir = '';
32
+ const defaultProjectName = 'waku-project';
33
33
 
34
- const templateRoot = fileURLToPath(new URL("../template", import.meta.url));
34
+ const templateRoot = fileURLToPath(new URL('../template', import.meta.url));
35
35
  const CHOICES = fs.readdirSync(templateRoot);
36
36
  let result: {
37
37
  packageName: string;
@@ -43,49 +43,49 @@ async function init() {
43
43
  result = await prompts(
44
44
  [
45
45
  {
46
- name: "projectName",
47
- type: "text",
48
- message: "Project Name",
46
+ name: 'projectName',
47
+ type: 'text',
48
+ message: 'Project Name',
49
49
  initial: defaultProjectName,
50
50
  onState: (state: any) =>
51
51
  (targetDir = String(state.value).trim() || defaultProjectName),
52
52
  },
53
53
  {
54
- name: "shouldOverwrite",
55
- type: () => (canSafelyOverwrite(targetDir) ? null : "confirm"),
54
+ name: 'shouldOverwrite',
55
+ type: () => (canSafelyOverwrite(targetDir) ? null : 'confirm'),
56
56
  message: `${targetDir} is not empty. Remove existing files and continue?`,
57
57
  },
58
58
  {
59
- name: "overwriteChecker",
59
+ name: 'overwriteChecker',
60
60
  type: (values: any) => {
61
61
  if (values === false) {
62
- throw new Error(red("") + " Operation cancelled");
62
+ throw new Error(red('') + ' Operation cancelled');
63
63
  }
64
64
  return null;
65
65
  },
66
66
  },
67
67
  {
68
- name: "packageName",
69
- type: () => (isValidPackageName(targetDir) ? null : "text"),
70
- message: "Package name",
68
+ name: 'packageName',
69
+ type: () => (isValidPackageName(targetDir) ? null : 'text'),
70
+ message: 'Package name',
71
71
  initial: () => toValidPackageName(targetDir),
72
72
  validate: (dir: string) =>
73
- isValidPackageName(dir) || "Invalid package.json name",
73
+ isValidPackageName(dir) || 'Invalid package.json name',
74
74
  },
75
75
  {
76
- name: "chooseProject",
77
- type: "select",
78
- message: "Choose a starter template",
76
+ name: 'chooseProject',
77
+ type: 'select',
78
+ message: 'Choose a starter template',
79
79
  choices: [
80
- { title: "basic-template", value: CHOICES[0] },
81
- { title: "async-template", value: CHOICES[1] },
82
- { title: "promise-template", value: CHOICES[2] },
80
+ { title: 'basic-template', value: CHOICES[0] },
81
+ { title: 'async-template', value: CHOICES[1] },
82
+ { title: 'promise-template', value: CHOICES[2] },
83
83
  ],
84
84
  },
85
85
  ],
86
86
  {
87
87
  onCancel: () => {
88
- throw new Error(red("") + " Operation cancelled");
88
+ throw new Error(red('') + ' Operation cancelled');
89
89
  },
90
90
  },
91
91
  );
@@ -108,20 +108,20 @@ async function init() {
108
108
 
109
109
  const pkg = {
110
110
  name: packageName ?? toValidPackageName(targetDir),
111
- version: "0.0.0",
111
+ version: '0.0.0',
112
112
  };
113
113
 
114
- console.log("Setting up project...");
114
+ console.log('Setting up project...');
115
115
 
116
116
  const templateDir = path.join(templateRoot, chooseProject);
117
117
 
118
118
  // Read existing package.json from the root directory
119
- const packageJsonPath = path.join(root, "package.json");
119
+ const packageJsonPath = path.join(root, 'package.json');
120
120
 
121
121
  // Read new package.json from the template directory
122
- const newPackageJsonPath = path.join(templateDir, "package.json");
122
+ const newPackageJsonPath = path.join(templateDir, 'package.json');
123
123
  const newPackageJson = JSON.parse(
124
- fs.readFileSync(newPackageJsonPath, "utf-8"),
124
+ fs.readFileSync(newPackageJsonPath, 'utf-8'),
125
125
  );
126
126
 
127
127
  fse.copySync(templateDir, root);
@@ -138,23 +138,23 @@ async function init() {
138
138
  ),
139
139
  );
140
140
 
141
- const manager = process.env.npm_config_user_agent ?? "";
141
+ const manager = process.env.npm_config_user_agent ?? '';
142
142
  const packageManager = /pnpm/.test(manager)
143
- ? "pnpm"
143
+ ? 'pnpm'
144
144
  : /yarn/.test(manager)
145
- ? "yarn"
146
- : "npm";
145
+ ? 'yarn'
146
+ : 'npm';
147
147
 
148
148
  const commandsMap = {
149
149
  install: {
150
- pnpm: "pnpm install",
151
- yarn: "yarn",
152
- npm: "npm install",
150
+ pnpm: 'pnpm install',
151
+ yarn: 'yarn',
152
+ npm: 'npm install',
153
153
  },
154
154
  dev: {
155
- pnpm: "pnpm dev",
156
- yarn: "yarn dev",
157
- npm: "npm run dev",
155
+ pnpm: 'pnpm dev',
156
+ yarn: 'yarn dev',
157
+ npm: 'npm run dev',
158
158
  },
159
159
  };
160
160
 
@@ -1,6 +1,6 @@
1
1
  import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
2
- import { Counter } from "./Counter.js";
2
+ import { Counter } from './Counter.js';
3
3
  const App = ({ name }) => {
4
- return (_jsxs("div", { style: { border: "3px red dashed", margin: "1em", padding: "1em" }, children: [_jsxs("h1", { children: ["Hello ", name, "!!"] }), _jsx("h3", { children: "This is a server component." }), _jsx(Counter, {})] }));
4
+ return (_jsxs("div", { style: { border: '3px red dashed', margin: '1em', padding: '1em' }, children: [_jsxs("h1", { children: ["Hello ", name, "!!"] }), _jsx("h3", { children: "This is a server component." }), _jsx(Counter, {})] }));
5
5
  };
6
6
  export default App;
@@ -1,7 +1,7 @@
1
- "use client";
1
+ 'use client';
2
2
  import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
3
- import { useState } from "react";
3
+ import { useState } from 'react';
4
4
  export const Counter = () => {
5
5
  const [count, setCount] = useState(0);
6
- return (_jsxs("div", { style: { border: "3px blue dashed", margin: "1em", padding: "1em" }, children: [_jsxs("p", { children: ["Count: ", count] }), _jsx("button", { onClick: () => setCount((c) => c + 1), children: "Increment" }), _jsx("h3", { children: "This is a client component." })] }));
6
+ return (_jsxs("div", { style: { border: '3px blue dashed', margin: '1em', padding: '1em' }, children: [_jsxs("p", { children: ["Count: ", count] }), _jsx("button", { onClick: () => setCount((c) => c + 1), children: "Increment" }), _jsx("h3", { children: "This is a client component." })] }));
7
7
  };
@@ -1,31 +1,32 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
- import { lazy } from "react";
3
- import { defineEntries } from "waku/server";
4
- const App = lazy(() => import("./components/App.js"));
2
+ import { lazy } from 'react';
3
+ import { defineEntries } from 'waku/server';
4
+ import { Slot } from 'waku/client';
5
+ const App = lazy(() => import('./components/App.js'));
5
6
  export default defineEntries(
6
7
  // renderEntries
7
8
  async (input) => {
8
9
  return {
9
- App: _jsx(App, { name: input || "Waku" }),
10
+ App: _jsx(App, { name: input || 'Waku' }),
10
11
  };
11
12
  },
12
13
  // getBuildConfig
13
14
  async () => {
14
15
  return {
15
- "/": {
16
- entries: [[""]],
16
+ '/': {
17
+ entries: [['']],
17
18
  },
18
19
  };
19
20
  },
20
21
  // getSsrConfig
21
- () => ({
22
- getInput: async (pathStr) => {
23
- switch (pathStr) {
24
- case "/":
25
- return "";
26
- default:
27
- return null;
28
- }
29
- },
30
- filter: (elements) => elements.App,
31
- }));
22
+ async (pathStr) => {
23
+ switch (pathStr) {
24
+ case '/':
25
+ return {
26
+ input: '',
27
+ unstable_render: () => _jsx(Slot, { id: "App" }),
28
+ };
29
+ default:
30
+ return null;
31
+ }
32
+ });
@@ -1,6 +1,11 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
- import { StrictMode } from "react";
3
- import { createRoot } from "react-dom/client";
4
- import { Root, Slot } from "waku/client";
2
+ import { StrictMode } from 'react';
3
+ import { createRoot, hydrateRoot } from 'react-dom/client';
4
+ import { Root, Slot } from 'waku/client';
5
5
  const rootElement = (_jsx(StrictMode, { children: _jsx(Root, { children: _jsx(Slot, { id: "App" }) }) }));
6
- createRoot(document.getElementById("root")).render(rootElement);
6
+ if (globalThis.__WAKU_SSR_ENABLED__) {
7
+ hydrateRoot(document.getElementById('root'), rootElement);
8
+ }
9
+ else {
10
+ createRoot(document.getElementById('root')).render(rootElement);
11
+ }
@@ -0,0 +1,17 @@
1
+ #!/bin/sh
2
+ basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
3
+
4
+ case `uname` in
5
+ *CYGWIN*) basedir=`cygpath -w "$basedir"`;;
6
+ esac
7
+
8
+ if [ -z "$NODE_PATH" ]; then
9
+ export NODE_PATH="/home/runner/work/waku/waku/node_modules/.pnpm/vite@4.5.0_@types+node@20.9.0/node_modules/vite/bin/node_modules:/home/runner/work/waku/waku/node_modules/.pnpm/vite@4.5.0_@types+node@20.9.0/node_modules/vite/node_modules:/home/runner/work/waku/waku/node_modules/.pnpm/vite@4.5.0_@types+node@20.9.0/node_modules:/home/runner/work/waku/waku/node_modules/.pnpm/node_modules"
10
+ else
11
+ export NODE_PATH="/home/runner/work/waku/waku/node_modules/.pnpm/vite@4.5.0_@types+node@20.9.0/node_modules/vite/bin/node_modules:/home/runner/work/waku/waku/node_modules/.pnpm/vite@4.5.0_@types+node@20.9.0/node_modules/vite/node_modules:/home/runner/work/waku/waku/node_modules/.pnpm/vite@4.5.0_@types+node@20.9.0/node_modules:/home/runner/work/waku/waku/node_modules/.pnpm/node_modules:$NODE_PATH"
12
+ fi
13
+ if [ -x "$basedir/node" ]; then
14
+ exec "$basedir/node" "$basedir/../vite/bin/vite.js" "$@"
15
+ else
16
+ exec node "$basedir/../vite/bin/vite.js" "$@"
17
+ fi
@@ -5,19 +5,22 @@
5
5
  "private": true,
6
6
  "scripts": {
7
7
  "dev": "waku dev --with-ssr",
8
- "build": "waku build",
8
+ "build": "waku build --with-ssr",
9
9
  "start": "waku start --with-ssr"
10
10
  },
11
11
  "dependencies": {
12
12
  "express": "^4.18.2",
13
- "react": "18.3.0-canary-a41957507-20231017",
14
- "react-dom": "18.3.0-canary-a41957507-20231017",
15
- "react-server-dom-webpack": "18.3.0-canary-a41957507-20231017",
16
- "waku": "0.16.0"
13
+ "react": "18.3.0-canary-0e352ea01-20231109",
14
+ "react-dom": "18.3.0-canary-0e352ea01-20231109",
15
+ "react-server-dom-webpack": "18.3.0-canary-0e352ea01-20231109",
16
+ "waku": "0.17.0"
17
17
  },
18
18
  "devDependencies": {
19
- "@types/react": "^18.2.31",
20
- "@types/react-dom": "^18.2.14",
21
- "typescript": "^5.2.2"
19
+ "@swc/core": "1.3.96",
20
+ "@types/react": "^18.2.37",
21
+ "@types/react-dom": "^18.2.15",
22
+ "@vitejs/plugin-react": "4.1.1",
23
+ "typescript": "^5.2.2",
24
+ "vite": "4.5.0"
22
25
  }
23
26
  }
@@ -1,8 +1,8 @@
1
- import { Counter } from "./Counter.js";
1
+ import { Counter } from './Counter.js';
2
2
 
3
3
  const App = ({ name }: { name: string }) => {
4
4
  return (
5
- <div style={{ border: "3px red dashed", margin: "1em", padding: "1em" }}>
5
+ <div style={{ border: '3px red dashed', margin: '1em', padding: '1em' }}>
6
6
  <h1>Hello {name}!!</h1>
7
7
  <h3>This is a server component.</h3>
8
8
  <Counter />
@@ -1,11 +1,11 @@
1
- "use client";
1
+ 'use client';
2
2
 
3
- import { useState } from "react";
3
+ import { useState } from 'react';
4
4
 
5
5
  export const Counter = () => {
6
6
  const [count, setCount] = useState(0);
7
7
  return (
8
- <div style={{ border: "3px blue dashed", margin: "1em", padding: "1em" }}>
8
+ <div style={{ border: '3px blue dashed', margin: '1em', padding: '1em' }}>
9
9
  <p>Count: {count}</p>
10
10
  <button onClick={() => setCount((c) => c + 1)}>Increment</button>
11
11
  <h3>This is a client component.</h3>
@@ -1,34 +1,34 @@
1
- import { lazy } from "react";
1
+ import { lazy } from 'react';
2
+ import { defineEntries } from 'waku/server';
3
+ import { Slot } from 'waku/client';
2
4
 
3
- import { defineEntries } from "waku/server";
4
-
5
- const App = lazy(() => import("./components/App.js"));
5
+ const App = lazy(() => import('./components/App.js'));
6
6
 
7
7
  export default defineEntries(
8
8
  // renderEntries
9
9
  async (input) => {
10
10
  return {
11
- App: <App name={input || "Waku"} />,
11
+ App: <App name={input || 'Waku'} />,
12
12
  };
13
13
  },
14
14
  // getBuildConfig
15
15
  async () => {
16
16
  return {
17
- "/": {
18
- entries: [[""]],
17
+ '/': {
18
+ entries: [['']],
19
19
  },
20
20
  };
21
21
  },
22
22
  // getSsrConfig
23
- () => ({
24
- getInput: async (pathStr) => {
25
- switch (pathStr) {
26
- case "/":
27
- return "";
28
- default:
29
- return null;
30
- }
31
- },
32
- filter: (elements) => elements.App,
33
- }),
23
+ async (pathStr) => {
24
+ switch (pathStr) {
25
+ case '/':
26
+ return {
27
+ input: '',
28
+ unstable_render: () => <Slot id="App" />,
29
+ };
30
+ default:
31
+ return null;
32
+ }
33
+ },
34
34
  );
@@ -3,6 +3,7 @@
3
3
  <head>
4
4
  <meta charset="utf-8" />
5
5
  <title>Waku example</title>
6
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
6
7
  <style>
7
8
  @keyframes spinner {
8
9
  to {
@@ -1,6 +1,6 @@
1
- import { StrictMode } from "react";
2
- import { createRoot } from "react-dom/client";
3
- import { Root, Slot } from "waku/client";
1
+ import { StrictMode } from 'react';
2
+ import { createRoot, hydrateRoot } from 'react-dom/client';
3
+ import { Root, Slot } from 'waku/client';
4
4
 
5
5
  const rootElement = (
6
6
  <StrictMode>
@@ -10,4 +10,8 @@ const rootElement = (
10
10
  </StrictMode>
11
11
  );
12
12
 
13
- createRoot(document.getElementById("root")!).render(rootElement);
13
+ if ((globalThis as any).__WAKU_SSR_ENABLED__) {
14
+ hydrateRoot(document.getElementById('root')!, rootElement);
15
+ } else {
16
+ createRoot(document.getElementById('root')!).render(rootElement);
17
+ }
@@ -9,7 +9,7 @@
9
9
  "noUncheckedIndexedAccess": true,
10
10
  "exactOptionalPropertyTypes": true,
11
11
  "jsx": "react-jsx",
12
- "outDir": "./dist",
13
- "rootDir": "./src"
12
+ "rootDir": "./src",
13
+ "outDir": "./dist"
14
14
  }
15
15
  }
@@ -0,0 +1,13 @@
1
+ import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
2
+ /// Async Server Component
3
+ /// <reference types="react/experimental" />
4
+ import { Suspense } from 'react';
5
+ import { Counter } from './Counter.js';
6
+ const App = ({ name }) => {
7
+ return (_jsxs("div", { style: { border: '3px red dashed', margin: '1em', padding: '1em' }, children: [_jsxs("h1", { children: ["Hello ", name, "!!"] }), _jsx("h3", { children: "This is a server component." }), _jsx(Suspense, { fallback: "Pending...", children: _jsx(ServerMessage, {}) }), _jsx(Counter, {})] }));
8
+ };
9
+ const ServerMessage = async () => {
10
+ await new Promise((resolve) => setTimeout(resolve, 2000));
11
+ return _jsx("p", { children: "Hello from server!" });
12
+ };
13
+ export default App;