create-egg 3.0.0 → 4.0.1-beta.0

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 (86) hide show
  1. package/README.md +55 -16
  2. package/dist/cli.d.ts +1 -0
  3. package/dist/cli.js +11 -0
  4. package/dist/index.d.ts +4 -0
  5. package/dist/index.js +254 -0
  6. package/dist/templates/egg3-simple-js/.eslintignore +1 -0
  7. package/dist/templates/egg3-simple-js/.eslintrc +4 -0
  8. package/dist/templates/egg3-simple-js/.vscode/launch.json +26 -0
  9. package/dist/templates/egg3-simple-js/README.md +31 -0
  10. package/dist/templates/egg3-simple-js/_.gitignore +15 -0
  11. package/dist/templates/egg3-simple-js/app/controller/home.js +10 -0
  12. package/dist/templates/egg3-simple-js/app/router.js +7 -0
  13. package/dist/templates/egg3-simple-js/config/config.default.js +28 -0
  14. package/dist/templates/egg3-simple-js/config/plugin.js +7 -0
  15. package/dist/templates/egg3-simple-js/package.json +38 -0
  16. package/dist/templates/egg3-simple-js/test/app/controller/home.test.js +20 -0
  17. package/dist/templates/egg3-simple-ts/.eslintignore +3 -0
  18. package/dist/templates/egg3-simple-ts/.eslintrc +6 -0
  19. package/dist/templates/egg3-simple-ts/README.md +33 -0
  20. package/dist/templates/egg3-simple-ts/_.gitignore +20 -0
  21. package/dist/templates/egg3-simple-ts/app/controller/home.ts +8 -0
  22. package/dist/templates/egg3-simple-ts/app/router.ts +7 -0
  23. package/dist/templates/egg3-simple-ts/app/service/Test.ts +14 -0
  24. package/dist/templates/egg3-simple-ts/config/config.default.ts +23 -0
  25. package/dist/templates/egg3-simple-ts/config/config.local.ts +6 -0
  26. package/dist/templates/egg3-simple-ts/config/config.prod.ts +6 -0
  27. package/dist/templates/egg3-simple-ts/config/plugin.ts +11 -0
  28. package/dist/templates/egg3-simple-ts/package.json +45 -0
  29. package/dist/templates/egg3-simple-ts/test/app/controller/home.test.ts +9 -0
  30. package/dist/templates/egg3-simple-ts/test/app/service/Test.test.ts +16 -0
  31. package/dist/templates/egg3-simple-ts/tsconfig.json +4 -0
  32. package/dist/templates/egg3-simple-ts/typings/index.d.ts +3 -0
  33. package/dist/templates/egg3-tegg/.vscode/launch.json +26 -0
  34. package/dist/templates/egg3-tegg/README.md +33 -0
  35. package/dist/templates/egg3-tegg/_.gitignore +21 -0
  36. package/dist/templates/egg3-tegg/app/module/bar/controller/home.ts +24 -0
  37. package/dist/templates/egg3-tegg/app/module/bar/controller/user.ts +24 -0
  38. package/dist/templates/egg3-tegg/app/module/bar/package.json +6 -0
  39. package/dist/templates/egg3-tegg/app/module/foo/index.ts +1 -0
  40. package/dist/templates/egg3-tegg/app/module/foo/package.json +6 -0
  41. package/dist/templates/egg3-tegg/app/module/foo/service/HelloService.ts +19 -0
  42. package/dist/templates/egg3-tegg/config/config.default.ts +30 -0
  43. package/dist/templates/egg3-tegg/config/config.local.ts +6 -0
  44. package/dist/templates/egg3-tegg/config/config.prod.ts +6 -0
  45. package/dist/templates/egg3-tegg/config/config.unittest.ts +6 -0
  46. package/dist/templates/egg3-tegg/config/plugin.ts +34 -0
  47. package/dist/templates/egg3-tegg/package.json +58 -0
  48. package/dist/templates/egg3-tegg/test/app/module/bar/controller/home.test.ts +11 -0
  49. package/dist/templates/egg3-tegg/test/app/module/bar/controller/user.test.ts +14 -0
  50. package/dist/templates/egg3-tegg/test/app/module/foo/service/HelloService.test.ts +14 -0
  51. package/dist/templates/egg3-tegg/tsconfig.json +13 -0
  52. package/dist/templates/simple-ts/README.md +33 -0
  53. package/dist/templates/simple-ts/_.gitignore +20 -0
  54. package/dist/templates/simple-ts/app/controller/home.ts +8 -0
  55. package/dist/templates/simple-ts/app/router.ts +7 -0
  56. package/dist/templates/simple-ts/app/service/Test.ts +14 -0
  57. package/dist/templates/simple-ts/config/config.default.ts +23 -0
  58. package/dist/templates/simple-ts/config/config.local.ts +6 -0
  59. package/dist/templates/simple-ts/config/config.prod.ts +6 -0
  60. package/dist/templates/simple-ts/config/plugin.ts +11 -0
  61. package/dist/templates/simple-ts/package.json +51 -0
  62. package/dist/templates/simple-ts/test/app/controller/home.test.ts +8 -0
  63. package/dist/templates/simple-ts/test/app/service/Test.test.ts +9 -0
  64. package/dist/templates/simple-ts/tsconfig.json +10 -0
  65. package/dist/templates/simple-ts/typings/index.d.ts +3 -0
  66. package/dist/templates/tegg/.vscode/launch.json +26 -0
  67. package/dist/templates/tegg/README.md +33 -0
  68. package/dist/templates/tegg/_.gitignore +21 -0
  69. package/dist/templates/tegg/app/module/bar/controller/home.ts +24 -0
  70. package/dist/templates/tegg/app/module/bar/controller/user.ts +24 -0
  71. package/dist/templates/tegg/app/module/bar/package.json +6 -0
  72. package/dist/templates/tegg/app/module/foo/index.ts +1 -0
  73. package/dist/templates/tegg/app/module/foo/package.json +6 -0
  74. package/dist/templates/tegg/app/module/foo/service/HelloService.ts +19 -0
  75. package/dist/templates/tegg/config/config.default.ts +30 -0
  76. package/dist/templates/tegg/config/config.local.ts +6 -0
  77. package/dist/templates/tegg/config/config.prod.ts +6 -0
  78. package/dist/templates/tegg/config/config.unittest.ts +6 -0
  79. package/dist/templates/tegg/config/plugin.ts +34 -0
  80. package/dist/templates/tegg/package.json +58 -0
  81. package/dist/templates/tegg/test/app/module/bar/controller/home.test.ts +8 -0
  82. package/dist/templates/tegg/test/app/module/bar/controller/user.test.ts +11 -0
  83. package/dist/templates/tegg/test/app/module/foo/service/HelloService.test.ts +9 -0
  84. package/dist/templates/tegg/tsconfig.json +13 -0
  85. package/package.json +38 -29
  86. package/bin/create-egg.js +0 -3
package/README.md CHANGED
@@ -1,38 +1,77 @@
1
1
  # create-egg
2
2
 
3
3
  [![NPM version][npm-image]][npm-url]
4
- [![Node.js CI](https://github.com/eggjs/create-egg/actions/workflows/nodejs.yml/badge.svg)](https://github.com/eggjs/create-egg/actions/workflows/nodejs.yml)
5
- [![Test coverage][codecov-image]][codecov-url]
6
4
  [![NPM download][download-image]][download-url]
7
5
 
8
6
  [npm-image]: https://img.shields.io/npm/v/create-egg.svg?style=flat-square
9
7
  [npm-url]: https://npmjs.org/package/create-egg
10
- [codecov-image]: https://codecov.io/gh/eggjs/create-egg/branch/master/graph/badge.svg
11
- [codecov-url]: https://codecov.io/gh/eggjs/create-egg
12
8
  [download-image]: https://img.shields.io/npm/dm/create-egg.svg?style=flat-square
13
9
  [download-url]: https://npmjs.org/package/create-egg
14
10
 
15
- Alias for [egg-init](https://github.com/eggjs/egg-init), so you could use `npm init egg showcase`.
11
+ > Fork and refactor from [create-vite](https://github.com/vitejs/vite/tree/main/packages/create-vite)
16
12
 
17
- Thanks to `npm init` feature introduced at npm@6, see [npm-init](https://docs.npmjs.com/cli/init) for more details.
13
+ ## Scaffolding Your First Egg.js Project
18
14
 
19
- ## Usage
15
+ > **Compatibility Note:**
16
+ > Egg.js requires [Node.js](https://nodejs.org/) version 20.19+. However, some templates require a higher Node.js version to work, please upgrade if your package manager warns about it.
17
+
18
+ With NPM:
20
19
 
21
20
  ```bash
22
- npm init egg showcase
23
- npm init egg showcase --type=simple
21
+ npm create egg@latest
24
22
  ```
25
23
 
26
- [MIT](LICENSE)
24
+ With Yarn:
27
25
 
28
- <!-- GITCONTRIBUTOR_START -->
26
+ ```bash
27
+ yarn create egg
28
+ ```
29
29
 
30
- ## Contributors
30
+ With PNPM:
31
+
32
+ ```bash
33
+ pnpm create egg
34
+ ```
31
35
 
32
- |[<img src="https://avatars.githubusercontent.com/u/227713?v=4" width="100px;"/><br/><sub><b>atian25</b></sub>](https://github.com/atian25)<br/>|[<img src="https://avatars.githubusercontent.com/u/3297859?v=4" width="100px;"/><br/><sub><b>sinchang</b></sub>](https://github.com/sinchang)<br/>|[<img src="https://avatars.githubusercontent.com/u/156269?v=4" width="100px;"/><br/><sub><b>fengmk2</b></sub>](https://github.com/fengmk2)<br/>|[<img src="https://avatars.githubusercontent.com/u/106730421?v=4" width="100px;"/><br/><sub><b>jasonjiicloud</b></sub>](https://github.com/jasonjiicloud)<br/>|
33
- | :---: | :---: | :---: | :---: |
36
+ Then follow the prompts!
37
+
38
+ You can also directly specify the project name and the template you want to use via additional command line options. For example, to scaffold a Egg.js + TypeScript project, run:
39
+
40
+ ```bash
41
+ # npm 7+
42
+ npm create egg@latest my-egg-app -- --template tegg
43
+
44
+ # yarn
45
+ yarn create egg my-egg-app --template tegg
46
+
47
+ # pnpm
48
+ pnpm create egg my-egg-app --template tegg
49
+ ```
34
50
 
51
+ Currently supported template presets include:
35
52
 
36
- This project follows the git-contributor [spec](https://github.com/xudafeng/git-contributor), auto updated at `Tue Nov 28 2023 13:41:55 GMT+0800`.
53
+ - `tegg`
54
+ - `egg3-tegg`
55
+ - `egg3-simple-js`
37
56
 
38
- <!-- GITCONTRIBUTOR_END -->
57
+ You can use `.` for the project name to scaffold in the current directory.
58
+
59
+ ## Community Templates
60
+
61
+ Check out Awesome Egg.js for [community maintained templates](https://github.com/eggjs/awesome-egg#boilerplates) that include other tools or target different frameworks. You can use a tool like [degit](https://github.com/Rich-Harris/degit) to scaffold your project with one of the templates.
62
+
63
+ ```bash
64
+ npx degit user/project my-project
65
+ cd my-project
66
+
67
+ npm install
68
+ npm run dev
69
+ ```
70
+
71
+ If the project uses `main` as the default branch, suffix the project repo with `#main`
72
+
73
+ ```bash
74
+ npx degit user/project#main my-project
75
+ ```
76
+
77
+ [MIT](LICENSE)
package/dist/cli.d.ts ADDED
@@ -0,0 +1 @@
1
+ export { };
package/dist/cli.js ADDED
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env node
2
+ import { init } from "./index.js";
3
+
4
+ //#region src/cli.ts
5
+ init().catch((err) => {
6
+ console.error("create egg failed", err);
7
+ process.exit(1);
8
+ });
9
+
10
+ //#endregion
11
+ export { };
@@ -0,0 +1,4 @@
1
+ //#region src/index.d.ts
2
+ declare function init(): Promise<void>;
3
+ //#endregion
4
+ export { init };
package/dist/index.js ADDED
@@ -0,0 +1,254 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+ import spawn from "cross-spawn";
4
+ import mri from "mri";
5
+ import * as prompts from "@clack/prompts";
6
+ import colors from "picocolors";
7
+
8
+ //#region src/index.ts
9
+ const { blue, blueBright, green, greenBright, yellow } = colors;
10
+ const argv = mri(process.argv.slice(2), {
11
+ alias: {
12
+ h: "help",
13
+ t: "template"
14
+ },
15
+ boolean: ["help", "overwrite"],
16
+ string: ["template"]
17
+ });
18
+ const cwd = process.cwd();
19
+ const helpMessage = `\
20
+ Usage: create-egg [OPTION]... [DIRECTORY]
21
+
22
+ Create a new Egg.js project.
23
+ With no arguments, start the CLI in interactive mode.
24
+
25
+ Options:
26
+ -t, --template NAME use a specific template
27
+
28
+ Available templates:
29
+ ${green("tegg")} egg@4 with tegg module
30
+ ${blue("simple-ts")} egg@4 with vanilla TypeScript
31
+ ${green("egg3-tegg")} egg@3 with tegg module
32
+ ${blue("egg3-simple-ts")} egg@3 with vanilla TypeScript
33
+ ${yellow("egg3-simple-js")} egg@3 with vanilla JavaScript
34
+ `;
35
+ const TEMPLATES = [
36
+ {
37
+ name: "tegg",
38
+ display: "Tegg starter, egg@4 with tegg module",
39
+ color: green
40
+ },
41
+ {
42
+ name: "simple-ts",
43
+ display: "Simple starter, egg@4 with vanilla TypeScript",
44
+ color: blue
45
+ },
46
+ {
47
+ name: "egg3-tegg",
48
+ display: "Tegg starter, egg@3 with tegg module",
49
+ color: green
50
+ },
51
+ {
52
+ name: "egg3-simple-ts",
53
+ display: "Simple starter, egg@3 with vanilla TypeScript",
54
+ color: blue
55
+ },
56
+ {
57
+ name: "egg3-simple-js",
58
+ display: "Simple starter, egg@3 with vanilla JavaScript",
59
+ color: yellow
60
+ }
61
+ ];
62
+ const defaultTargetDir = "egg-project";
63
+ async function init() {
64
+ const argTargetDir = argv._[0] ? formatTargetDir(String(argv._[0])) : void 0;
65
+ const argTemplate = argv.template;
66
+ const argOverwrite = argv.overwrite;
67
+ if (argv.help) {
68
+ console.log(helpMessage);
69
+ return;
70
+ }
71
+ const pkgInfo = pkgFromUserAgent(process.env.npm_config_user_agent);
72
+ const cancel = () => prompts.cancel("Operation cancelled");
73
+ prompts.intro(`${greenBright("Egg.js")} - Born to build better enterprise application and framework`);
74
+ let targetDir = argTargetDir;
75
+ if (!targetDir) {
76
+ const projectName = await prompts.text({
77
+ message: "Project name:",
78
+ defaultValue: defaultTargetDir,
79
+ placeholder: defaultTargetDir,
80
+ validate: (value) => {
81
+ return value.length === 0 || formatTargetDir(value).length > 0 ? void 0 : "Invalid project name";
82
+ }
83
+ });
84
+ if (prompts.isCancel(projectName)) return cancel();
85
+ targetDir = formatTargetDir(projectName);
86
+ }
87
+ if (fs.existsSync(targetDir) && !isEmpty(targetDir)) {
88
+ const overwrite = argOverwrite ? "yes" : await prompts.select({
89
+ message: (targetDir === "." ? "Current directory" : `Target directory "${targetDir}"`) + ` is not empty. Please choose how to proceed:`,
90
+ options: [
91
+ {
92
+ label: "Cancel operation",
93
+ value: "no"
94
+ },
95
+ {
96
+ label: "Remove existing files and continue",
97
+ value: "yes"
98
+ },
99
+ {
100
+ label: "Ignore files and continue",
101
+ value: "ignore"
102
+ }
103
+ ]
104
+ });
105
+ if (prompts.isCancel(overwrite)) return cancel();
106
+ switch (overwrite) {
107
+ case "yes":
108
+ emptyDir(targetDir);
109
+ break;
110
+ case "no":
111
+ cancel();
112
+ return;
113
+ }
114
+ }
115
+ let packageName = path.basename(path.resolve(targetDir));
116
+ if (!isValidPackageName(packageName)) {
117
+ const packageNameResult = await prompts.text({
118
+ message: "Package name:",
119
+ defaultValue: toValidPackageName(packageName),
120
+ placeholder: toValidPackageName(packageName),
121
+ validate(dir) {
122
+ if (!isValidPackageName(dir)) return "Invalid package.json name";
123
+ }
124
+ });
125
+ if (prompts.isCancel(packageNameResult)) return cancel();
126
+ packageName = packageNameResult;
127
+ }
128
+ let template = argTemplate;
129
+ let hasInvalidArgTemplate = false;
130
+ if (argTemplate && !TEMPLATES.some((t) => t.name === argTemplate)) {
131
+ template = void 0;
132
+ hasInvalidArgTemplate = true;
133
+ }
134
+ if (!template) {
135
+ const selectedTemplate = await prompts.select({
136
+ message: hasInvalidArgTemplate ? `"${argTemplate}" isn't a valid template. Please choose from below: ` : "Select a template:",
137
+ options: TEMPLATES.map((template$1) => {
138
+ const templateColor = template$1.color;
139
+ return {
140
+ label: templateColor(template$1.display || template$1.name),
141
+ value: template$1.name
142
+ };
143
+ })
144
+ });
145
+ if (prompts.isCancel(selectedTemplate)) return cancel();
146
+ template = selectedTemplate;
147
+ }
148
+ const root = path.join(cwd, targetDir);
149
+ fs.mkdirSync(root, { recursive: true });
150
+ const pkgManager = pkgInfo ? pkgInfo.name : "npm";
151
+ const { customCommand } = TEMPLATES.find((t) => t.name === template) ?? {};
152
+ if (customCommand) {
153
+ const [command, ...args] = getFullCustomCommand(customCommand, pkgInfo).split(" ");
154
+ const replacedArgs = args.map((arg) => arg.replace("TARGET_DIR", () => targetDir));
155
+ const { status } = spawn.sync(command, replacedArgs, { stdio: "inherit" });
156
+ process.exit(status ?? 0);
157
+ }
158
+ prompts.log.step(`Scaffolding project with ${blueBright(template)} in ${root}...`);
159
+ const templateDir = path.join(import.meta.dirname, `templates/${template}`);
160
+ const write = (file, content) => {
161
+ const targetPath = path.join(root, file.startsWith("_") ? file.slice(1) : file);
162
+ if (content) fs.writeFileSync(targetPath, content);
163
+ else copy(path.join(templateDir, file), targetPath);
164
+ };
165
+ const files = fs.readdirSync(templateDir);
166
+ for (const file of files.filter((f) => f !== "package.json")) write(file);
167
+ let pkgJsonContent = fs.readFileSync(path.join(templateDir, `package.json`), "utf-8");
168
+ pkgJsonContent = pkgJsonContent.replaceAll("{{name}}", packageName);
169
+ const pkg = JSON.parse(pkgJsonContent);
170
+ if (pkgInfo) pkg.packageManager = `${pkgInfo.name}@${pkgInfo.version}`;
171
+ write("package.json", JSON.stringify(pkg, null, 2) + "\n");
172
+ const cdProjectName = path.relative(cwd, root);
173
+ if (await prompts.confirm({
174
+ message: "Initialize git repository?",
175
+ initialValue: true
176
+ })) {
177
+ spawn.sync("git", ["init", cdProjectName], { stdio: "pipe" });
178
+ prompts.log.success("Git repository initialized");
179
+ }
180
+ let doneMessage = "";
181
+ doneMessage += `Done. Now run:\n`;
182
+ if (root !== cwd) doneMessage += `\n cd ${cdProjectName.includes(" ") ? `"${cdProjectName}"` : cdProjectName}`;
183
+ switch (pkgManager) {
184
+ case "yarn":
185
+ doneMessage += "\n yarn";
186
+ doneMessage += "\n yarn dev";
187
+ break;
188
+ default:
189
+ doneMessage += `\n ${pkgManager} install`;
190
+ doneMessage += `\n ${pkgManager} run dev`;
191
+ break;
192
+ }
193
+ prompts.outro(greenBright(doneMessage));
194
+ }
195
+ function formatTargetDir(targetDir) {
196
+ return targetDir.trim().replace(/\/+$/g, "");
197
+ }
198
+ function copy(src, dest) {
199
+ if (fs.statSync(src).isDirectory()) copyDir(src, dest);
200
+ else fs.copyFileSync(src, dest);
201
+ }
202
+ function isValidPackageName(projectName) {
203
+ return /^(?:@[a-z\d\-*~][a-z\d\-*._~]*\/)?[a-z\d\-~][a-z\d\-._~]*$/.test(projectName);
204
+ }
205
+ function toValidPackageName(projectName) {
206
+ return projectName.trim().toLowerCase().replace(/\s+/g, "-").replace(/^[._]/, "").replace(/[^a-z\d\-~]+/g, "-");
207
+ }
208
+ function copyDir(srcDir, destDir) {
209
+ fs.mkdirSync(destDir, { recursive: true });
210
+ for (const file of fs.readdirSync(srcDir)) {
211
+ const srcFile = path.resolve(srcDir, file);
212
+ const destFile = path.resolve(destDir, file);
213
+ copy(srcFile, destFile);
214
+ }
215
+ }
216
+ function isEmpty(path$1) {
217
+ const files = fs.readdirSync(path$1);
218
+ return files.length === 0 || files.length === 1 && files[0] === ".git";
219
+ }
220
+ function emptyDir(dir) {
221
+ if (!fs.existsSync(dir)) return;
222
+ for (const file of fs.readdirSync(dir)) {
223
+ if (file === ".git") continue;
224
+ fs.rmSync(path.resolve(dir, file), {
225
+ recursive: true,
226
+ force: true
227
+ });
228
+ }
229
+ }
230
+ function pkgFromUserAgent(userAgent) {
231
+ if (!userAgent) return void 0;
232
+ const pkgSpecArr = userAgent.split(" ")[0].split("/");
233
+ return {
234
+ name: pkgSpecArr[0],
235
+ version: pkgSpecArr[1]
236
+ };
237
+ }
238
+ function getFullCustomCommand(customCommand, pkgInfo) {
239
+ const pkgManager = pkgInfo ? pkgInfo.name : "npm";
240
+ const isYarn1 = pkgManager === "yarn" && pkgInfo?.version.startsWith("1.");
241
+ return customCommand.replace(/^npm create (?:-- )?/, () => {
242
+ if (pkgManager === "bun") return "bun x create-";
243
+ if (pkgManager === "pnpm") return "pnpm create ";
244
+ return customCommand.startsWith("npm create -- ") ? `${pkgManager} create -- ` : `${pkgManager} create `;
245
+ }).replace("@latest", () => isYarn1 ? "" : "@latest").replace(/^npm exec/, () => {
246
+ if (pkgManager === "pnpm") return "pnpm dlx";
247
+ if (pkgManager === "yarn" && !isYarn1) return "yarn dlx";
248
+ if (pkgManager === "bun") return "bun x";
249
+ return "npm exec";
250
+ });
251
+ }
252
+
253
+ //#endregion
254
+ export { init };
@@ -0,0 +1 @@
1
+ coverage
@@ -0,0 +1,4 @@
1
+ {
2
+ "extends": "eslint-config-egg",
3
+ "root": true
4
+ }
@@ -0,0 +1,26 @@
1
+ {
2
+ // Use IntelliSense to learn about possible attributes.
3
+ // Hover to view descriptions of existing attributes.
4
+ // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5
+ "version": "0.2.0",
6
+ "configurations": [
7
+ {
8
+ "type": "node",
9
+ "request": "launch",
10
+ "name": "Egg Debug",
11
+ "runtimeExecutable": "npm",
12
+ "runtimeArgs": ["run", "dev", "--", "--inspect-brk"],
13
+ "console": "integratedTerminal",
14
+ "restart": true,
15
+ "autoAttachChildProcesses": true
16
+ },
17
+ {
18
+ "type": "node",
19
+ "request": "launch",
20
+ "name": "Egg Test",
21
+ "runtimeExecutable": "npm",
22
+ "runtimeArgs": ["run", "test:local", "--", "--inspect-brk"],
23
+ "autoAttachChildProcesses": true
24
+ }
25
+ ]
26
+ }
@@ -0,0 +1,31 @@
1
+ # hello Egg.js
2
+
3
+ hello Egg.js
4
+
5
+ ## QuickStart
6
+
7
+ <!-- add docs here for user -->
8
+
9
+ see [egg v3 docs][egg@3] for more detail.
10
+
11
+ ### Development
12
+
13
+ ```bash
14
+ npm i
15
+ npm run dev
16
+ open http://localhost:7001/
17
+ ```
18
+
19
+ ### Deploy
20
+
21
+ ```bash
22
+ npm start
23
+ npm stop
24
+ ```
25
+
26
+ ### npm scripts
27
+
28
+ - Use `npm run lint` to check code style.
29
+ - Use `npm test` to run unit test.
30
+
31
+ [egg@3]: https://v3.eggjs.org/
@@ -0,0 +1,15 @@
1
+ logs/
2
+ npm-debug.log
3
+ yarn-error.log
4
+ node_modules/
5
+ *-lock.json
6
+ *-lock.yaml
7
+ yarn.lock
8
+ coverage/
9
+ .idea/
10
+ run/
11
+ .DS_Store
12
+ *.sw*
13
+ *.un~
14
+ typings/
15
+ .nyc_output/
@@ -0,0 +1,10 @@
1
+ const { Controller } = require('egg');
2
+
3
+ class HomeController extends Controller {
4
+ async index() {
5
+ const { ctx } = this;
6
+ ctx.body = 'hi, egg';
7
+ }
8
+ }
9
+
10
+ module.exports = HomeController;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * @param {Egg.Application} app - egg application
3
+ */
4
+ module.exports = app => {
5
+ const { router, controller } = app;
6
+ router.get('/', controller.home.index);
7
+ };
@@ -0,0 +1,28 @@
1
+ /* eslint valid-jsdoc: "off" */
2
+
3
+ /**
4
+ * @param {Egg.EggAppInfo} appInfo app info
5
+ */
6
+ module.exports = appInfo => {
7
+ /**
8
+ * built-in config
9
+ * @type {Egg.EggAppConfig}
10
+ **/
11
+ const config = (exports = {});
12
+
13
+ // use for cookie sign key, should change to your own and keep security
14
+ config.keys = appInfo.name + '_{{keys}}';
15
+
16
+ // add your middleware config here
17
+ config.middleware = [];
18
+
19
+ // add your user config here
20
+ const userConfig = {
21
+ // myAppName: 'egg',
22
+ };
23
+
24
+ return {
25
+ ...config,
26
+ ...userConfig,
27
+ };
28
+ };
@@ -0,0 +1,7 @@
1
+ /** @type Egg.EggPlugin */
2
+ module.exports = {
3
+ // had enabled by egg
4
+ // static: {
5
+ // enable: true,
6
+ // }
7
+ };
@@ -0,0 +1,38 @@
1
+ {
2
+ "name": "{{name}}",
3
+ "version": "1.0.0",
4
+ "description": "hello Egg.js",
5
+ "private": true,
6
+ "egg": {
7
+ "declarations": true
8
+ },
9
+ "dependencies": {
10
+ "egg": "^3.17.5",
11
+ "egg-scripts": "2"
12
+ },
13
+ "devDependencies": {
14
+ "egg-bin": "6",
15
+ "egg-mock": "5",
16
+ "eslint": "8",
17
+ "eslint-config-egg": "13"
18
+ },
19
+ "engines": {
20
+ "node": ">=18.0.0"
21
+ },
22
+ "scripts": {
23
+ "start": "egg-scripts start --daemon --title=egg-server-{{name}}",
24
+ "stop": "egg-scripts stop --title=egg-server-{{name}}",
25
+ "dev": "egg-bin dev",
26
+ "test": "npm run lint -- --fix && npm run test:local",
27
+ "test:local": "egg-bin test",
28
+ "cov": "egg-bin cov",
29
+ "lint": "eslint .",
30
+ "ci": "npm run lint && npm run cov"
31
+ },
32
+ "repository": {
33
+ "type": "git",
34
+ "url": ""
35
+ },
36
+ "author": "{{author}}",
37
+ "license": "MIT"
38
+ }
@@ -0,0 +1,20 @@
1
+ const { strict: assert } = require('node:assert');
2
+ const path = require('node:path');
3
+ const { statSync } = require('node:fs');
4
+ const { app } = require('egg-mock/bootstrap');
5
+
6
+ describe('test/app/controller/home.test.js', () => {
7
+ it('should assert', async () => {
8
+ const pkg = require('../../../package.json');
9
+ assert(app.config.keys.startsWith(pkg.name));
10
+ });
11
+
12
+ it('should typings exists', async () => {
13
+ const typings = path.join(__dirname, '../../../typings');
14
+ assert(statSync(typings));
15
+ });
16
+
17
+ it('should GET /', async () => {
18
+ return app.httpRequest().get('/').expect('hi, egg').expect(200);
19
+ });
20
+ });
@@ -0,0 +1,3 @@
1
+ **/*.d.ts
2
+ node_modules/
3
+ coverage
@@ -0,0 +1,6 @@
1
+ {
2
+ "extends": "eslint-config-egg/typescript",
3
+ "parserOptions": {
4
+ "project": "./tsconfig.json"
5
+ }
6
+ }
@@ -0,0 +1,33 @@
1
+ # hackernews-async-ts
2
+
3
+ [Hacker News](https://news.ycombinator.com/) showcase using typescript && egg
4
+
5
+ ## QuickStart
6
+
7
+ ### Development
8
+
9
+ ```bash
10
+ $ npm i
11
+ $ npm run dev
12
+ $ open http://localhost:7001/
13
+ ```
14
+
15
+ Don't tsc compile at development mode, if you had run `tsc` then you need to `npm run clean` before `npm run dev`.
16
+
17
+ ### Deploy
18
+
19
+ ```bash
20
+ $ npm run tsc
21
+ $ npm start
22
+ ```
23
+
24
+ ### Npm Scripts
25
+
26
+ - Use `npm run lint` to check code style
27
+ - Use `npm test` to run unit test
28
+ - se `npm run clean` to clean compiled js at development mode once
29
+
30
+ ### Requirement
31
+
32
+ - Node.js 8.x
33
+ - Typescript 2.8+
@@ -0,0 +1,20 @@
1
+ logs/
2
+ npm-debug.log
3
+ node_modules/
4
+ coverage/
5
+ .idea/
6
+ run/
7
+ logs/
8
+ .DS_Store
9
+ .vscode
10
+ *.swp
11
+ *.lock
12
+ *.js
13
+ !.autod.conf.js
14
+
15
+ app/**/*.js
16
+ test/**/*.js
17
+ config/**/*.js
18
+ app/**/*.map
19
+ test/**/*.map
20
+ config/**/*.map
@@ -0,0 +1,8 @@
1
+ import { Controller } from 'egg';
2
+
3
+ export default class HomeController extends Controller {
4
+ public async index() {
5
+ const { ctx } = this;
6
+ ctx.body = await ctx.service.test.sayHi('egg');
7
+ }
8
+ }
@@ -0,0 +1,7 @@
1
+ import { Application } from 'egg';
2
+
3
+ export default (app: Application) => {
4
+ const { controller, router } = app;
5
+
6
+ router.get('/', controller.home.index);
7
+ };
@@ -0,0 +1,14 @@
1
+ import { Service } from 'egg';
2
+
3
+ /**
4
+ * Test Service
5
+ */
6
+ export default class Test extends Service {
7
+ /**
8
+ * sayHi to you
9
+ * @param name - your name
10
+ */
11
+ public async sayHi(name: string) {
12
+ return `hi, ${name}, TypeScript`;
13
+ }
14
+ }