@ftisindia/create-app 0.1.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 (151) hide show
  1. package/LICENSE +144 -0
  2. package/bin/index.mjs +2 -0
  3. package/package.json +36 -0
  4. package/src/copy.mjs +45 -0
  5. package/src/log.mjs +23 -0
  6. package/src/main.mjs +221 -0
  7. package/src/run.mjs +52 -0
  8. package/src/substitute.mjs +40 -0
  9. package/template/.env.example +36 -0
  10. package/template/.github/workflows/ci.yml +36 -0
  11. package/template/.husky/pre-commit +1 -0
  12. package/template/README.md +146 -0
  13. package/template/_editorconfig +8 -0
  14. package/template/_gitignore +7 -0
  15. package/template/_nvmrc +1 -0
  16. package/template/_package.json +107 -0
  17. package/template/_prettierignore +5 -0
  18. package/template/_prettierrc +6 -0
  19. package/template/docs/API_REFERENCE.md +123 -0
  20. package/template/docs/GETTING_STARTED.md +65 -0
  21. package/template/docs/MODULE_COMPLETION_CHECKLIST.md +40 -0
  22. package/template/docs/OAUTH.md +46 -0
  23. package/template/docs/SAMPLE_MODULE.md +23 -0
  24. package/template/docs/api.http +269 -0
  25. package/template/eslint.config.mjs +51 -0
  26. package/template/nest-cli.json +8 -0
  27. package/template/prisma/migrations/20260530000000_init/migration.sql +248 -0
  28. package/template/prisma/schema.prisma +299 -0
  29. package/template/prisma/seed.ts +44 -0
  30. package/template/scripts/db-create.mjs +126 -0
  31. package/template/scripts/gen-module.mjs +217 -0
  32. package/template/scripts/seed-test-user-org.ts +264 -0
  33. package/template/scripts/setup-local.mjs +224 -0
  34. package/template/scripts/test-db.mjs +69 -0
  35. package/template/src/app.module.ts +58 -0
  36. package/template/src/common/decorators/.gitkeep +1 -0
  37. package/template/src/common/dto/error-response.dto.ts +17 -0
  38. package/template/src/common/dto/membership-response.dto.ts +51 -0
  39. package/template/src/common/dto/mutation-response.dto.ts +11 -0
  40. package/template/src/common/dto/role-summary.dto.ts +18 -0
  41. package/template/src/common/dto/user-summary.dto.ts +23 -0
  42. package/template/src/common/enums/.gitkeep +1 -0
  43. package/template/src/common/filters/.gitkeep +1 -0
  44. package/template/src/common/filters/http-exception.filter.ts +78 -0
  45. package/template/src/common/guards/.gitkeep +1 -0
  46. package/template/src/common/interceptors/.gitkeep +1 -0
  47. package/template/src/common/pipes/.gitkeep +1 -0
  48. package/template/src/common/swagger/api-error-responses.ts +54 -0
  49. package/template/src/common/types/.gitkeep +1 -0
  50. package/template/src/config/app.config.ts +7 -0
  51. package/template/src/config/auth.config.ts +33 -0
  52. package/template/src/config/database.config.ts +6 -0
  53. package/template/src/config/env.validation.ts +131 -0
  54. package/template/src/config/index.ts +5 -0
  55. package/template/src/config/rbac.config.ts +6 -0
  56. package/template/src/database/prisma/prisma-transaction.ts +22 -0
  57. package/template/src/database/prisma/prisma.module.ts +9 -0
  58. package/template/src/database/prisma/prisma.service.ts +16 -0
  59. package/template/src/main.ts +42 -0
  60. package/template/src/modules/access-control/access-control.module.ts +24 -0
  61. package/template/src/modules/access-control/application/route-registry.validator.ts +289 -0
  62. package/template/src/modules/access-control/application/services/ability.factory.ts +28 -0
  63. package/template/src/modules/access-control/application/services/access-control.service.ts +478 -0
  64. package/template/src/modules/access-control/application/services/permission.guard.ts +77 -0
  65. package/template/src/modules/access-control/application/services/rbac-cache.service.ts +148 -0
  66. package/template/src/modules/access-control/dto/access-control-response.dto.ts +79 -0
  67. package/template/src/modules/access-control/dto/create-role.dto.ts +18 -0
  68. package/template/src/modules/access-control/dto/update-role-permissions.dto.ts +23 -0
  69. package/template/src/modules/access-control/dto/update-role.dto.ts +19 -0
  70. package/template/src/modules/access-control/presentation/access-control.controller.ts +157 -0
  71. package/template/src/modules/access-control/presentation/permissions.decorator.ts +8 -0
  72. package/template/src/modules/access-control/presentation/public.decorator.ts +7 -0
  73. package/template/src/modules/access-control/types/permission-key.ts +37 -0
  74. package/template/src/modules/access-control/types/rbac-context.ts +11 -0
  75. package/template/src/modules/access-control/types/route-permission-registry.ts +129 -0
  76. package/template/src/modules/audit/application/services/audit.service.ts +97 -0
  77. package/template/src/modules/audit/audit.module.ts +13 -0
  78. package/template/src/modules/audit/dto/audit-response.dto.ts +75 -0
  79. package/template/src/modules/audit/dto/list-audit-logs-query.dto.ts +75 -0
  80. package/template/src/modules/audit/presentation/audit.controller.ts +37 -0
  81. package/template/src/modules/auth/application/services/auth.service.ts +509 -0
  82. package/template/src/modules/auth/application/services/password.service.ts +15 -0
  83. package/template/src/modules/auth/application/services/token.service.ts +95 -0
  84. package/template/src/modules/auth/auth.module.ts +73 -0
  85. package/template/src/modules/auth/dto/auth-response.dto.ts +29 -0
  86. package/template/src/modules/auth/dto/login.dto.ts +15 -0
  87. package/template/src/modules/auth/dto/logout.dto.ts +3 -0
  88. package/template/src/modules/auth/dto/oauth-exchange.dto.ts +15 -0
  89. package/template/src/modules/auth/dto/refresh-token.dto.ts +14 -0
  90. package/template/src/modules/auth/dto/signup.dto.ts +27 -0
  91. package/template/src/modules/auth/infrastructure/passport/google-auth.guard.ts +27 -0
  92. package/template/src/modules/auth/infrastructure/passport/google.strategy.ts +56 -0
  93. package/template/src/modules/auth/infrastructure/passport/jwt-auth.guard.ts +5 -0
  94. package/template/src/modules/auth/infrastructure/passport/jwt.strategy.ts +43 -0
  95. package/template/src/modules/auth/presentation/auth.controller.ts +148 -0
  96. package/template/src/modules/auth/presentation/current-user.decorator.ts +11 -0
  97. package/template/src/modules/auth/presentation/google-oauth-exception.filter.ts +33 -0
  98. package/template/src/modules/auth/types/authenticated-user.ts +7 -0
  99. package/template/src/modules/auth/types/google-auth-profile.ts +6 -0
  100. package/template/src/modules/auth/types/jwt-payload.ts +5 -0
  101. package/template/src/modules/health/dto/health-response.dto.ts +9 -0
  102. package/template/src/modules/health/health.module.ts +7 -0
  103. package/template/src/modules/health/presentation/health.controller.ts +33 -0
  104. package/template/src/modules/invitations/application/services/invitations.service.ts +967 -0
  105. package/template/src/modules/invitations/dto/accept-invitation.dto.ts +24 -0
  106. package/template/src/modules/invitations/dto/create-invitation.dto.ts +100 -0
  107. package/template/src/modules/invitations/dto/invitation-response.dto.ts +108 -0
  108. package/template/src/modules/invitations/dto/invitation-token.dto.ts +15 -0
  109. package/template/src/modules/invitations/invitations.module.ts +12 -0
  110. package/template/src/modules/invitations/presentation/invitations.controller.ts +149 -0
  111. package/template/src/modules/memberships/application/services/memberships.service.ts +455 -0
  112. package/template/src/modules/memberships/dto/transfer-owner.dto.ts +11 -0
  113. package/template/src/modules/memberships/dto/update-billing-contact.dto.ts +8 -0
  114. package/template/src/modules/memberships/dto/update-membership-owner.dto.ts +8 -0
  115. package/template/src/modules/memberships/dto/update-membership-role.dto.ts +11 -0
  116. package/template/src/modules/memberships/dto/update-membership-status.dto.ts +9 -0
  117. package/template/src/modules/memberships/memberships.module.ts +12 -0
  118. package/template/src/modules/memberships/presentation/memberships.controller.ts +193 -0
  119. package/template/src/modules/organisations/application/services/organisations.service.ts +147 -0
  120. package/template/src/modules/organisations/dto/create-organisation.dto.ts +32 -0
  121. package/template/src/modules/organisations/dto/organisation-response.dto.ts +62 -0
  122. package/template/src/modules/organisations/infrastructure/repositories/organisations.repository.ts +24 -0
  123. package/template/src/modules/organisations/organisations.module.ts +12 -0
  124. package/template/src/modules/organisations/presentation/organisations.controller.ts +37 -0
  125. package/template/src/modules/organisations/types/default-organisation-data.ts +18 -0
  126. package/template/src/modules/platform-admin/.gitkeep +1 -0
  127. package/template/src/modules/request-context/application/services/request-context.service.ts +79 -0
  128. package/template/src/modules/request-context/presentation/org-scope.guard.ts +26 -0
  129. package/template/src/modules/request-context/presentation/request-context.interceptor.ts +26 -0
  130. package/template/src/modules/request-context/presentation/request-context.middleware.ts +31 -0
  131. package/template/src/modules/request-context/request-context.module.ts +25 -0
  132. package/template/src/modules/request-context/types/request-context.ts +29 -0
  133. package/template/src/modules/sample/application/services/sample.service.ts +67 -0
  134. package/template/src/modules/sample/dto/sample-echo.dto.ts +10 -0
  135. package/template/src/modules/sample/dto/sample-response.dto.ts +41 -0
  136. package/template/src/modules/sample/presentation/sample.controller.ts +63 -0
  137. package/template/src/modules/sample/sample.module.ts +11 -0
  138. package/template/src/modules/settings/application/services/settings.service.ts +139 -0
  139. package/template/src/modules/settings/dto/setting-response.dto.ts +27 -0
  140. package/template/src/modules/settings/dto/update-setting.dto.ts +16 -0
  141. package/template/src/modules/settings/presentation/settings.controller.ts +66 -0
  142. package/template/src/modules/settings/settings.module.ts +12 -0
  143. package/template/src/modules/settings/types/setting-definitions.ts +104 -0
  144. package/template/src/modules/users/.gitkeep +1 -0
  145. package/template/test/.gitkeep +1 -0
  146. package/template/test/jest-e2e.json +9 -0
  147. package/template/test/permission.guard.spec.ts +22 -0
  148. package/template/test/route-registry.validator.spec.ts +90 -0
  149. package/template/test/security.e2e-spec.ts +102 -0
  150. package/template/tsconfig.build.json +4 -0
  151. package/template/tsconfig.json +18 -0
package/LICENSE ADDED
@@ -0,0 +1,144 @@
1
+ Copyright (c) 2026 ftisindia.com
2
+
3
+ This software is licensed under the PolyForm Noncommercial License 1.0.0, the full
4
+ text of which appears below. You may use, copy, modify, and distribute this software
5
+ for any NONCOMMERCIAL purpose at no cost, subject to those terms.
6
+
7
+ COMMERCIAL USE REQUIRES A SEPARATE COMMERCIAL LICENSE.
8
+ To obtain a commercial license, contact ftisindia.com (https://ftisindia.com).
9
+
10
+ Required Notice: Copyright ftisindia.com (https://ftisindia.com)
11
+
12
+ ----------------------------------------------------------------------
13
+
14
+ # PolyForm Noncommercial License 1.0.0
15
+
16
+ <https://polyformproject.org/licenses/noncommercial/1.0.0>
17
+
18
+ ## Acceptance
19
+
20
+ In order to get any license under these terms, you must agree
21
+ to them as both strict obligations and conditions to all
22
+ your licenses.
23
+
24
+ ## Copyright License
25
+
26
+ The licensor grants you a copyright license for the
27
+ software to do everything you might do with the software
28
+ that would otherwise infringe the licensor's copyright
29
+ in it for any permitted purpose. However, you may
30
+ only distribute the software according to [Distribution
31
+ License](#distribution-license) and make changes or new works
32
+ based on the software according to [Changes and New Works
33
+ License](#changes-and-new-works-license).
34
+
35
+ ## Distribution License
36
+
37
+ The licensor grants you an additional copyright license
38
+ to distribute copies of the software. Your license
39
+ to distribute covers distributing the software with
40
+ changes and new works permitted by [Changes and New Works
41
+ License](#changes-and-new-works-license).
42
+
43
+ ## Notices
44
+
45
+ You must ensure that anyone who gets a copy of any part of
46
+ the software from you also gets a copy of these terms or the
47
+ URL for them above, as well as copies of any plain-text lines
48
+ beginning with `Required Notice:` that the licensor provided
49
+ with the software. For example:
50
+
51
+ > Required Notice: Copyright ftisindia.com (https://ftisindia.com)
52
+
53
+ ## Changes and New Works License
54
+
55
+ The licensor grants you an additional copyright license to
56
+ make changes and new works based on the software for any
57
+ permitted purpose.
58
+
59
+ ## Patent License
60
+
61
+ The licensor grants you a patent license for the software that
62
+ covers patent claims the licensor can license, or becomes able
63
+ to license, that you would infringe by using the software.
64
+
65
+ ## Noncommercial Purposes
66
+
67
+ Any noncommercial purpose is a permitted purpose.
68
+
69
+ ## Personal Uses
70
+
71
+ Personal use for research, experiment, and testing for
72
+ the benefit of public knowledge, personal study, private
73
+ entertainment, hobby projects, amateur pursuits, or religious
74
+ observance, without any anticipated commercial application,
75
+ is use for a permitted purpose.
76
+
77
+ ## Noncommercial Organizations
78
+
79
+ Use by any charitable organization, educational institution,
80
+ public research organization, public safety or health
81
+ organization, environmental protection organization,
82
+ or government institution is use for a permitted purpose
83
+ regardless of the source of funding or obligations resulting
84
+ from the funding.
85
+
86
+ ## Fair Use
87
+
88
+ You may have "fair use" rights for the software under the
89
+ law. These terms do not limit them.
90
+
91
+ ## No Other Rights
92
+
93
+ These terms do not allow you to sublicense or transfer any of
94
+ your licenses to anyone else, or prevent the licensor from
95
+ granting licenses to anyone else. These terms do not imply
96
+ any other licenses.
97
+
98
+ ## Patent Defense
99
+
100
+ If you make any written claim that the software infringes or
101
+ contributes to infringement of any patent, your patent license
102
+ for the software granted under these terms ends immediately. If
103
+ your company makes such a claim, your patent license ends
104
+ immediately for work on behalf of your company.
105
+
106
+ ## Violations
107
+
108
+ The first time you are notified in writing that you have
109
+ violated any of these terms, or done anything with the software
110
+ not covered by your licenses, your licenses can nonetheless
111
+ continue if you come into full compliance with these terms,
112
+ and take practical steps to correct past violations, within
113
+ 32 days of receiving notice. Otherwise, all your licenses
114
+ end immediately.
115
+
116
+ ## No Liability
117
+
118
+ ***As far as the law allows, the software comes as is, without
119
+ any warranty or condition, and the licensor will not be liable
120
+ to you for any damages arising out of these terms or the use
121
+ or nature of the software, under any kind of legal claim.***
122
+
123
+ ## Definitions
124
+
125
+ The **licensor** is the individual or entity offering these
126
+ terms, and the **software** is the software the licensor makes
127
+ available under these terms.
128
+
129
+ **You** refers to the individual or entity agreeing to these
130
+ terms.
131
+
132
+ **Your company** is any legal entity, sole proprietorship,
133
+ or other kind of organization that you work for, plus all
134
+ organizations that have control over, are under the control of,
135
+ or are under common control with that organization. **Control**
136
+ means ownership of substantially all the assets of an entity,
137
+ or the power to direct its management and policies by vote,
138
+ contract, or otherwise. Control can be direct or indirect.
139
+
140
+ **Your licenses** are all the licenses granted to you for the
141
+ software under these terms.
142
+
143
+ **Use** means anything you do with the software requiring one
144
+ of your licenses.
package/bin/index.mjs ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ import '../src/main.mjs';
package/package.json ADDED
@@ -0,0 +1,36 @@
1
+ {
2
+ "name": "@ftisindia/create-app",
3
+ "version": "0.1.0",
4
+ "description": "One-command scaffolder for the Phase 1 NestJS foundation starter.",
5
+ "type": "module",
6
+ "bin": {
7
+ "ftis-nest": "bin/index.mjs"
8
+ },
9
+ "files": [
10
+ "bin",
11
+ "src",
12
+ "template",
13
+ "LICENSE"
14
+ ],
15
+ "engines": {
16
+ "node": ">=20"
17
+ },
18
+ "author": "ftisindia.com",
19
+ "license": "PolyForm-Noncommercial-1.0.0",
20
+ "homepage": "https://ftisindia.com",
21
+ "repository": {
22
+ "type": "git",
23
+ "url": "git+https://github.com/ftisindia/starter-package.git"
24
+ },
25
+ "bugs": {
26
+ "url": "https://github.com/ftisindia/starter-package/issues"
27
+ },
28
+ "publishConfig": {
29
+ "access": "public"
30
+ },
31
+ "scripts": {
32
+ "prepack": "node ../../scripts/sync-template.mjs",
33
+ "prepublishOnly": "node ../../scripts/sync-template.mjs"
34
+ },
35
+ "dependencies": {}
36
+ }
package/src/copy.mjs ADDED
@@ -0,0 +1,45 @@
1
+ import { copyFile, mkdir, readdir } from "node:fs/promises";
2
+ import { join } from "node:path";
3
+
4
+ function targetName(name) {
5
+ if (name === "_package.json") {
6
+ return "package.json";
7
+ }
8
+
9
+ if (name === "_gitignore") {
10
+ return ".gitignore";
11
+ }
12
+
13
+ if (name.startsWith("_")) {
14
+ return `.${name.slice(1)}`;
15
+ }
16
+
17
+ return name;
18
+ }
19
+
20
+ async function copyDirectory(sourceDir, targetDir) {
21
+ await mkdir(targetDir, { recursive: true });
22
+
23
+ const entries = await readdir(sourceDir, { withFileTypes: true });
24
+ for (const entry of entries) {
25
+ if (entry.name === "node_modules") {
26
+ continue;
27
+ }
28
+
29
+ const source = join(sourceDir, entry.name);
30
+ const target = join(targetDir, targetName(entry.name));
31
+
32
+ if (entry.isDirectory()) {
33
+ await copyDirectory(source, target);
34
+ continue;
35
+ }
36
+
37
+ if (entry.isFile()) {
38
+ await copyFile(source, target);
39
+ }
40
+ }
41
+ }
42
+
43
+ export async function copyTemplate(templateDir, targetDir) {
44
+ await copyDirectory(templateDir, targetDir);
45
+ }
package/src/log.mjs ADDED
@@ -0,0 +1,23 @@
1
+ const enabled = process.stdout.isTTY && process.env.NO_COLOR === undefined;
2
+
3
+ function color(code, message) {
4
+ return enabled ? `\u001B[${code}m${message}\u001B[0m` : message;
5
+ }
6
+
7
+ export const log = {
8
+ step(message) {
9
+ console.log(color(36, `> ${message}`));
10
+ },
11
+ success(message) {
12
+ console.log(color(32, `✓ ${message}`));
13
+ },
14
+ warn(message) {
15
+ console.warn(color(33, `! ${message}`));
16
+ },
17
+ error(message) {
18
+ console.error(color(31, `✖ ${message}`));
19
+ },
20
+ plain(message = "") {
21
+ console.log(message);
22
+ },
23
+ };
package/src/main.mjs ADDED
@@ -0,0 +1,221 @@
1
+ import { copyFile, mkdir, readdir, stat } from "node:fs/promises";
2
+ import { basename, resolve } from "node:path";
3
+ import { parseArgs } from "node:util";
4
+ import { fileURLToPath } from "node:url";
5
+ import { copyTemplate } from "./copy.mjs";
6
+ import { log } from "./log.mjs";
7
+ import { run } from "./run.mjs";
8
+ import { substituteProjectName } from "./substitute.mjs";
9
+
10
+ const NAME_PATTERN = /^[a-z0-9][a-z0-9-_]*$/;
11
+ const SUPPORTED_PACKAGE_MANAGERS = new Set(["npm", "pnpm", "yarn"]);
12
+
13
+ function printHelp() {
14
+ log.plain(`ftis-nest — @ftisindia/create-app
15
+
16
+ Usage:
17
+ npx @ftisindia/create-app <project-name|.> [options]
18
+ ftis-nest <project-name|.> [options] # after: npm i -g @ftisindia/create-app
19
+
20
+ Options:
21
+ --no-install Copy files only; skip npm install and prisma generate
22
+ --no-git Skip git init/add/commit
23
+ --pm <name> Package manager to use: npm, pnpm, or yarn
24
+ --help Show this help
25
+ `);
26
+ }
27
+
28
+ function assertSupportedNode() {
29
+ const major = Number(process.versions.node.split(".")[0]);
30
+ if (major < 20) {
31
+ throw new Error(
32
+ `Node.js 20 or newer is required. Current version: ${process.version}`,
33
+ );
34
+ }
35
+ }
36
+
37
+ async function exists(path) {
38
+ try {
39
+ await stat(path);
40
+ return true;
41
+ } catch {
42
+ return false;
43
+ }
44
+ }
45
+
46
+ async function assertTargetDirectory(targetDir) {
47
+ if (!(await exists(targetDir))) {
48
+ await mkdir(targetDir, { recursive: true });
49
+ return;
50
+ }
51
+
52
+ const entries = await readdir(targetDir);
53
+ if (entries.length > 0) {
54
+ throw new Error(`Target directory is not empty: ${targetDir}`);
55
+ }
56
+ }
57
+
58
+ async function resolveTemplateDir() {
59
+ const monorepoTemplate = fileURLToPath(
60
+ new URL("../../template/", import.meta.url),
61
+ );
62
+ if (await exists(monorepoTemplate)) {
63
+ return monorepoTemplate;
64
+ }
65
+
66
+ const publishedTemplate = fileURLToPath(
67
+ new URL("../template/", import.meta.url),
68
+ );
69
+ if (await exists(publishedTemplate)) {
70
+ return publishedTemplate;
71
+ }
72
+
73
+ throw new Error("Could not find the template directory.");
74
+ }
75
+
76
+ async function initializeGitRepository(targetDir) {
77
+ const init = await run("git", ["init"], {
78
+ cwd: targetDir,
79
+ allowFailure: true,
80
+ });
81
+ if (!init.ok) {
82
+ log.warn("Skipped git initialization because git is unavailable.");
83
+ return false;
84
+ }
85
+
86
+ return true;
87
+ }
88
+
89
+ async function createInitialCommit(targetDir) {
90
+ await run("git", ["add", "-A"], { cwd: targetDir, allowFailure: true });
91
+ const commit = await run(
92
+ "git",
93
+ ["commit", "-m", "chore: initial commit from @ftisindia/create-app"],
94
+ {
95
+ cwd: targetDir,
96
+ allowFailure: true,
97
+ },
98
+ );
99
+
100
+ if (!commit.ok) {
101
+ log.warn(
102
+ "Git repository was initialized, but the initial commit was skipped.",
103
+ );
104
+ }
105
+ }
106
+
107
+ async function detectPackageManager(requested) {
108
+ if (requested) {
109
+ if (!SUPPORTED_PACKAGE_MANAGERS.has(requested)) {
110
+ throw new Error("--pm must be one of npm, pnpm, or yarn.");
111
+ }
112
+
113
+ return requested;
114
+ }
115
+
116
+ const userAgent = process.env.npm_config_user_agent ?? "";
117
+ if (userAgent.startsWith("pnpm/")) {
118
+ return "pnpm";
119
+ }
120
+
121
+ if (userAgent.startsWith("yarn/")) {
122
+ return "yarn";
123
+ }
124
+
125
+ return "npm";
126
+ }
127
+
128
+ function installCommand(packageManager) {
129
+ return packageManager === "npm"
130
+ ? { command: "npm", args: ["install"] }
131
+ : { command: packageManager, args: ["install"] };
132
+ }
133
+
134
+ function prismaGenerateCommand(packageManager) {
135
+ if (packageManager === "npm") {
136
+ return { command: "npx", args: ["--yes", "prisma", "generate"] };
137
+ }
138
+
139
+ if (packageManager === "pnpm") {
140
+ return { command: "pnpm", args: ["exec", "prisma", "generate"] };
141
+ }
142
+
143
+ return { command: "yarn", args: ["prisma", "generate"] };
144
+ }
145
+
146
+ async function main() {
147
+ assertSupportedNode();
148
+
149
+ const { values, positionals } = parseArgs({
150
+ allowPositionals: true,
151
+ options: {
152
+ help: { type: "boolean", default: false },
153
+ "no-install": { type: "boolean", default: false },
154
+ "no-git": { type: "boolean", default: false },
155
+ pm: { type: "string" },
156
+ },
157
+ });
158
+
159
+ if (values.help || positionals.length === 0) {
160
+ printHelp();
161
+ process.exit(values.help ? 0 : 1);
162
+ }
163
+
164
+ const rawProjectName = positionals[0];
165
+ const targetDir =
166
+ rawProjectName === "."
167
+ ? process.cwd()
168
+ : resolve(process.cwd(), rawProjectName);
169
+ const projectName = basename(targetDir);
170
+ if (!NAME_PATTERN.test(projectName)) {
171
+ throw new Error(
172
+ "Invalid project name. Use lowercase letters, numbers, hyphens, or underscores; start with a letter or number.",
173
+ );
174
+ }
175
+
176
+ const templateDir = await resolveTemplateDir();
177
+ const packageManager = await detectPackageManager(values.pm);
178
+
179
+ log.step(`Using template: ${templateDir}`);
180
+ await assertTargetDirectory(targetDir);
181
+
182
+ log.step(`Creating ${projectName}`);
183
+ await copyTemplate(templateDir, targetDir);
184
+ await substituteProjectName(targetDir, projectName);
185
+ await copyFile(
186
+ resolve(targetDir, ".env.example"),
187
+ resolve(targetDir, ".env"),
188
+ );
189
+
190
+ let gitInitialized = false;
191
+ if (!values["no-git"]) {
192
+ log.step("Initialising git");
193
+ gitInitialized = await initializeGitRepository(targetDir);
194
+ }
195
+
196
+ if (!values["no-install"]) {
197
+ const install = installCommand(packageManager);
198
+ log.step(`Installing dependencies with ${packageManager}`);
199
+ await run(install.command, install.args, { cwd: targetDir });
200
+
201
+ const generate = prismaGenerateCommand(packageManager);
202
+ log.step("Generating Prisma client");
203
+ await run(generate.command, generate.args, { cwd: targetDir });
204
+ }
205
+
206
+ if (gitInitialized) {
207
+ log.step("Creating initial git commit");
208
+ await createInitialCommit(targetDir);
209
+ }
210
+
211
+ log.success(`Done. Next:
212
+ ${rawProjectName === "." ? "" : `cd ${rawProjectName}\n `}Start PostgreSQL locally, or set DATABASE_URL to a reachable server.
213
+ npm run setup:local
214
+ npm run start:dev
215
+ Docs: http://localhost:3000/docs`);
216
+ }
217
+
218
+ main().catch((error) => {
219
+ log.error(error.message);
220
+ process.exit(1);
221
+ });
package/src/run.mjs ADDED
@@ -0,0 +1,52 @@
1
+ import { spawn } from "node:child_process";
2
+
3
+ function quoteWindowsArg(value) {
4
+ if (/^[a-zA-Z0-9_./:=@+-]+$/.test(value)) {
5
+ return value;
6
+ }
7
+
8
+ return `"${value.replaceAll('"', '\\"')}"`;
9
+ }
10
+
11
+ function commandForPlatform(command, args) {
12
+ if (process.platform !== "win32") {
13
+ return { command, args };
14
+ }
15
+
16
+ return {
17
+ command: process.env.ComSpec || "cmd.exe",
18
+ args: ["/d", "/s", "/c", [command, ...args].map(quoteWindowsArg).join(" ")],
19
+ };
20
+ }
21
+
22
+ export function run(command, args, options = {}) {
23
+ const { allowFailure = false, cwd = process.cwd() } = options;
24
+ const executable = commandForPlatform(command, args);
25
+
26
+ return new Promise((resolve, reject) => {
27
+ const child = spawn(executable.command, executable.args, {
28
+ cwd,
29
+ stdio: "inherit",
30
+ });
31
+
32
+ child.on("error", (error) => {
33
+ if (allowFailure) {
34
+ resolve({ ok: false, code: 1, error });
35
+ return;
36
+ }
37
+
38
+ reject(error);
39
+ });
40
+
41
+ child.on("close", (code) => {
42
+ if (code === 0 || allowFailure) {
43
+ resolve({ ok: code === 0, code });
44
+ return;
45
+ }
46
+
47
+ reject(
48
+ new Error(`${command} ${args.join(" ")} exited with code ${code}`),
49
+ );
50
+ });
51
+ });
52
+ }
@@ -0,0 +1,40 @@
1
+ import { readdir, readFile, stat, writeFile } from "node:fs/promises";
2
+ import { join } from "node:path";
3
+
4
+ const SUBSTITUTE_FILES = new Set(["package.json", "README.md"]);
5
+
6
+ async function walk(dir) {
7
+ const entries = await readdir(dir);
8
+ const files = [];
9
+
10
+ for (const entry of entries) {
11
+ const path = join(dir, entry);
12
+ const info = await stat(path);
13
+
14
+ if (info.isDirectory()) {
15
+ files.push(...(await walk(path)));
16
+ continue;
17
+ }
18
+
19
+ files.push(path);
20
+ }
21
+
22
+ return files;
23
+ }
24
+
25
+ export async function substituteProjectName(targetDir, projectName) {
26
+ const files = await walk(targetDir);
27
+
28
+ await Promise.all(
29
+ files
30
+ .filter((file) => SUBSTITUTE_FILES.has(file.split(/[\\/]/).at(-1)))
31
+ .map(async (file) => {
32
+ const original = await readFile(file, "utf8");
33
+ const updated = original.replaceAll("__PROJECT_NAME__", projectName);
34
+
35
+ if (updated !== original) {
36
+ await writeFile(file, updated);
37
+ }
38
+ }),
39
+ );
40
+ }
@@ -0,0 +1,36 @@
1
+ # Local PostgreSQL defaults. Override these if your database runs elsewhere.
2
+ DATABASE_URL=postgresql://postgres:postgres@localhost:5432/app
3
+ TEST_DATABASE_URL=postgresql://postgres:postgres@localhost:5432/app_test
4
+
5
+ JWT_SECRET=
6
+ JWT_ACCESS_EXPIRES_IN=15m
7
+ JWT_REFRESH_EXPIRES_IN=7d
8
+ JWT_ISSUER=foundation-starter
9
+ JWT_AUDIENCE=foundation-api
10
+
11
+ AUTH_EMAIL_PASSWORD_ENABLED=true
12
+ AUTH_GOOGLE_ENABLED=false
13
+ AUTH_GOOGLE_CLIENT_ID=
14
+ AUTH_GOOGLE_CLIENT_SECRET=
15
+ AUTH_GOOGLE_CALLBACK_URL=http://localhost:3000/auth/google/callback
16
+ AUTH_GOOGLE_SUCCESS_REDIRECT_URL=http://localhost:3000/auth/google/success
17
+ AUTH_GOOGLE_ERROR_REDIRECT_URL=http://localhost:3000/auth/google/error
18
+ # Required when AUTH_GOOGLE_ENABLED=true. Use at least 32 random characters.
19
+ SESSION_SECRET=
20
+ AUTH_FACEBOOK_ENABLED=false
21
+ AUTH_MOBILE_OTP_ENABLED=false
22
+ AUTH_MAGIC_LINK_ENABLED=false
23
+
24
+ RBAC_CACHE_TTL_SECONDS=60
25
+ # Path is the only supported mode in this starter phase.
26
+ ORG_CONTEXT_MODE=path
27
+
28
+ NODE_ENV=development
29
+ PORT=3000
30
+
31
+ # Optional local bootstrap values used by npm run seed:test-user-org.
32
+ TEST_USER_EMAIL=owner@example.com
33
+ TEST_USER_PASSWORD=
34
+ TEST_USER_DISPLAY_NAME=Starter Owner
35
+ TEST_ORG_NAME=Demo Organisation
36
+ TEST_ORG_SLUG=demo
@@ -0,0 +1,36 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ pull_request:
6
+
7
+ jobs:
8
+ test:
9
+ runs-on: ubuntu-latest
10
+ steps:
11
+ - uses: actions/checkout@v4
12
+ - uses: actions/setup-node@v4
13
+ with:
14
+ node-version: 20
15
+ - name: Start native PostgreSQL
16
+ run: |
17
+ sudo systemctl start postgresql.service
18
+ sudo -u postgres psql -c "ALTER USER postgres PASSWORD 'postgres';"
19
+ - name: Install dependencies
20
+ run: npm install
21
+ - name: Create databases
22
+ run: npm run db:create
23
+ - name: Validate Prisma schema
24
+ run: npx prisma validate
25
+ - name: Generate Prisma client
26
+ run: npm run prisma:generate
27
+ - name: Deploy migrations
28
+ run: npm run prisma:deploy
29
+ - name: Lint
30
+ run: npm run lint
31
+ - name: Build
32
+ run: npm run build
33
+ - name: Unit tests
34
+ run: npm test
35
+ - name: E2E tests
36
+ run: npm run test:e2e
@@ -0,0 +1 @@
1
+ npx lint-staged