create-arkos 2.0.0-next.2 → 2.0.0-next.21
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.
- package/README.md +178 -150
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/dist/utils/project-config-inquirer.js +93 -74
- package/dist/utils/project-config-inquirer.js.map +1 -1
- package/dist/utils/template-compiler.js +16 -11
- package/dist/utils/template-compiler.js.map +1 -1
- package/package.json +15 -14
- package/templates/basic/.env.hbs +5 -1
- package/templates/basic/.gitignore.hbs +2 -0
- package/templates/basic/README.md.hbs +2 -4
- package/templates/basic/arkos.config.ts.hbs +16 -3
- package/templates/basic/jsconfig.json.hbs +3 -13
- package/templates/basic/package.json.hbs +33 -18
- package/templates/basic/prisma/schema/__tests__/user-role.prisma.hbs.test.ts +2 -2
- package/templates/basic/prisma/schema/__tests__/user.prisma.hbs.test.ts +2 -2
- package/templates/basic/prisma/schema/auth-permission.prisma.hbs +3 -9
- package/templates/basic/prisma/schema/auth-role.prisma.hbs +2 -2
- package/templates/basic/prisma/schema/schema.prisma.hbs +2 -3
- package/templates/basic/prisma/schema/user-permission.prisma.hbs +18 -0
- package/templates/basic/prisma/schema/user.prisma.hbs +4 -2
- package/templates/basic/prisma.config.ts.hbs +11 -0
- package/templates/basic/public/favicon.ico +0 -0
- package/templates/basic/src/app.ts.hbs +9 -7
- package/templates/basic/src/modules/auth/auth.policy.ts.hbs +1 -1
- package/templates/basic/src/modules/auth/auth.router.ts.hbs +72 -7
- package/templates/basic/src/modules/auth/dtos/login.dto.ts.hbs +1 -1
- package/templates/basic/src/modules/auth/dtos/signup.dto.ts.hbs +1 -1
- package/templates/basic/src/modules/auth/dtos/update-me.dto.ts.hbs +1 -1
- package/templates/basic/src/modules/auth/dtos/update-password.dto.ts.hbs +1 -1
- package/templates/basic/src/modules/auth-permission/auth-permission.router.ts.hbs +39 -7
- package/templates/basic/src/modules/auth-permission/auth-permission.service.ts.hbs +4 -6
- package/templates/basic/src/modules/auth-permission/dtos/create-auth-permission.dto.ts.hbs +7 -10
- package/templates/basic/src/modules/auth-permission/dtos/{query-auth-role.dto.ts.hbs → query-auth-permission.dto.ts.hbs} +1 -1
- package/templates/basic/src/modules/auth-permission/dtos/update-auth-permission.dto.ts.hbs +19 -4
- package/templates/basic/src/modules/auth-role/auth-role.router.ts.hbs +38 -6
- package/templates/basic/src/modules/auth-role/auth-role.service.ts.hbs +4 -6
- package/templates/basic/src/modules/auth-role/dtos/create-auth-role.dto.ts.hbs +3 -8
- package/templates/basic/src/modules/auth-role/dtos/query-auth-role.dto.ts.hbs +1 -1
- package/templates/basic/src/modules/auth-role/dtos/update-auth-role.dto.ts.hbs +3 -6
- package/templates/basic/src/modules/file-upload/file-upload.router.ts.hbs +28 -8
- package/templates/basic/src/modules/user/dtos/create-user.dto.ts.hbs +5 -5
- package/templates/basic/src/modules/user/dtos/update-user.dto.ts.hbs +5 -5
- package/templates/basic/src/modules/user/user.router.ts.hbs +91 -7
- package/templates/basic/src/modules/user/user.service.ts.hbs +4 -6
- package/templates/basic/src/router.ts.hbs +2 -2
- package/templates/basic/src/server.ts.hbs +8 -0
- package/templates/basic/src/utils/prisma/index.ts.hbs +48 -2
- package/templates/basic/src/utils/validation/api-actions.ts.hbs +2 -2
- package/templates/basic/tsconfig.json.hbs +6 -13
- package/templates/basic/src/loadables.ts.hbs +0 -29
- package/templates/basic/src/modules/auth/auth.route-hook.ts.hbs +0 -66
- package/templates/basic/src/modules/auth-permission/auth-permission.route-hook.ts.hbs +0 -35
- package/templates/basic/src/modules/auth-role/auth-role.route-hook.ts.hbs +0 -35
- package/templates/basic/src/modules/file-upload/file-upload.route-hook.ts.hbs +0 -23
- package/templates/basic/src/modules/user/user.route-hook.ts.hbs +0 -88
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import path from "path";
|
|
2
2
|
import inquirer from "inquirer";
|
|
3
3
|
import chalk from "chalk";
|
|
4
|
+
import { detectPackageManagerFromUserAgent } from "./helpers/npm.helpers.js";
|
|
4
5
|
class ProjectConfigInquirer {
|
|
5
6
|
config;
|
|
6
7
|
constructor() {
|
|
7
|
-
this.config = {
|
|
8
|
+
this.config = {
|
|
9
|
+
packageManager: detectPackageManagerFromUserAgent(),
|
|
10
|
+
};
|
|
8
11
|
}
|
|
9
12
|
async run() {
|
|
10
13
|
await this.promptProjectName();
|
|
@@ -13,6 +16,7 @@ class ProjectConfigInquirer {
|
|
|
13
16
|
await this.promptValidation();
|
|
14
17
|
await this.promptAuthentication();
|
|
15
18
|
await this.promptStrictRouting();
|
|
19
|
+
await this.promptEntryPoint();
|
|
16
20
|
if (this.config.projectName === ".") {
|
|
17
21
|
this.config.projectName = path.basename(process.cwd());
|
|
18
22
|
this.config.projectPath = path.resolve(process.cwd());
|
|
@@ -21,6 +25,9 @@ class ProjectConfigInquirer {
|
|
|
21
25
|
this.config.projectPath = path.resolve(process.cwd(), this.config.projectName);
|
|
22
26
|
if (process?.argv?.includes?.("--advanced"))
|
|
23
27
|
this.config.advanced = true;
|
|
28
|
+
if (this.config.prisma.defaultDatabaseUrl)
|
|
29
|
+
this.config.prisma.defaultDatabaseUrl =
|
|
30
|
+
this.config.prisma.defaultDatabaseUrl.replaceAll("{{projectName}}", this.config.projectName);
|
|
24
31
|
return this.config;
|
|
25
32
|
}
|
|
26
33
|
async promptProjectName() {
|
|
@@ -77,7 +84,7 @@ class ProjectConfigInquirer {
|
|
|
77
84
|
type: "confirm",
|
|
78
85
|
name: "typescript",
|
|
79
86
|
message: `Would you like to use ${chalk.cyan("TypeScript")}?`,
|
|
80
|
-
default:
|
|
87
|
+
default: true,
|
|
81
88
|
},
|
|
82
89
|
]);
|
|
83
90
|
this.config.typescript = typescript;
|
|
@@ -95,126 +102,125 @@ class ProjectConfigInquirer {
|
|
|
95
102
|
"sqlite",
|
|
96
103
|
"sqlserver",
|
|
97
104
|
"cockroachdb",
|
|
105
|
+
"none",
|
|
98
106
|
],
|
|
99
107
|
},
|
|
100
108
|
]);
|
|
101
109
|
let idDatabaseType;
|
|
102
|
-
let
|
|
110
|
+
let defaultDatabaseUrl;
|
|
103
111
|
switch (prismaProvider) {
|
|
104
112
|
case "mongodb":
|
|
105
113
|
idDatabaseType = '@id @default(auto()) @map("_id") @db.ObjectId';
|
|
106
|
-
|
|
114
|
+
defaultDatabaseUrl = `mongodb://localhost:27017/{{projectName}}`;
|
|
107
115
|
break;
|
|
108
116
|
case "sqlite":
|
|
109
117
|
idDatabaseType = "@id @default(cuid())";
|
|
110
|
-
|
|
118
|
+
defaultDatabaseUrl = "file:../../file.db";
|
|
111
119
|
break;
|
|
112
120
|
case "mysql":
|
|
113
121
|
idDatabaseType = "@id @default(uuid())";
|
|
114
|
-
|
|
122
|
+
defaultDatabaseUrl = `mysql://username:password@localhost:3306/{{projectName}}`;
|
|
115
123
|
break;
|
|
116
124
|
case "postgresql":
|
|
117
125
|
idDatabaseType = "@id @default(uuid())";
|
|
118
|
-
|
|
126
|
+
defaultDatabaseUrl = `postgresql://username:password@localhost:5432/{{projectName}}`;
|
|
119
127
|
break;
|
|
120
128
|
case "sqlserver":
|
|
121
129
|
idDatabaseType = "@id @default(uuid())";
|
|
122
|
-
|
|
130
|
+
defaultDatabaseUrl = `sqlserver://localhost:1433;database={{projectName}};username=sa;password=password;encrypt=DANGER_PLAINTEXT`;
|
|
123
131
|
break;
|
|
124
132
|
case "cockroachdb":
|
|
125
133
|
idDatabaseType = "@id @default(uuid())";
|
|
126
|
-
|
|
134
|
+
defaultDatabaseUrl = `postgresql://username:password@localhost:26257/{{projectName}}?sslmode=require`;
|
|
127
135
|
break;
|
|
128
136
|
default:
|
|
129
137
|
idDatabaseType = "@id @default(uuid())";
|
|
130
|
-
|
|
138
|
+
defaultDatabaseUrl = `postgresql://username:password@localhost:5432/{{projectName}}`;
|
|
131
139
|
}
|
|
132
140
|
this.config.prisma = {
|
|
133
141
|
provider: prismaProvider,
|
|
134
|
-
idDatabaseType
|
|
135
|
-
|
|
142
|
+
idDatabaseType,
|
|
143
|
+
defaultDatabaseUrl,
|
|
136
144
|
};
|
|
137
145
|
}
|
|
138
146
|
async promptValidation() {
|
|
139
|
-
const
|
|
147
|
+
const choices = this.config.typescript
|
|
148
|
+
? ["zod", "class-validator", "none"]
|
|
149
|
+
: ["zod", "none"];
|
|
150
|
+
const { validationType } = await inquirer.prompt([
|
|
140
151
|
{
|
|
141
|
-
type: "
|
|
142
|
-
name: "
|
|
143
|
-
message: `
|
|
144
|
-
|
|
152
|
+
type: "list",
|
|
153
|
+
name: "validationType",
|
|
154
|
+
message: `Which ${chalk.cyan("Validation")} library would you like to use?`,
|
|
155
|
+
choices,
|
|
156
|
+
default: "zod",
|
|
145
157
|
},
|
|
146
158
|
]);
|
|
147
|
-
if (
|
|
148
|
-
let validationTypeResponse = { validationType: "zod" };
|
|
149
|
-
if (this.config.typescript)
|
|
150
|
-
validationTypeResponse = await inquirer.prompt([
|
|
151
|
-
{
|
|
152
|
-
type: "list",
|
|
153
|
-
name: "validationType",
|
|
154
|
-
message: "Choose validation library:",
|
|
155
|
-
choices: ["zod", "class-validator"],
|
|
156
|
-
},
|
|
157
|
-
]);
|
|
158
|
-
else {
|
|
159
|
-
console.info(chalk.bold(`${chalk.greenBright("?")} Validation library set to zod (class-validator is not supported on JavaScript):`), chalk.cyan("zod"));
|
|
160
|
-
}
|
|
159
|
+
if (validationType !== "none") {
|
|
161
160
|
this.config.validation = {
|
|
162
|
-
type:
|
|
161
|
+
type: validationType,
|
|
163
162
|
};
|
|
164
163
|
}
|
|
165
|
-
else if (!this.config.typescript) {
|
|
166
|
-
}
|
|
167
164
|
}
|
|
168
165
|
async promptAuthentication() {
|
|
169
|
-
|
|
166
|
+
if (this.config.prisma.provider === "none") {
|
|
167
|
+
console.info(`${chalk.green("! ")}${chalk.bold("Skipping authentication setup as it requires prisma.")}`);
|
|
168
|
+
this.config.authentication = {
|
|
169
|
+
type: "none",
|
|
170
|
+
};
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
const { authenticationType } = await inquirer.prompt([
|
|
170
174
|
{
|
|
171
|
-
type: "
|
|
172
|
-
name: "
|
|
173
|
-
message: `
|
|
174
|
-
|
|
175
|
+
type: "list",
|
|
176
|
+
name: "authenticationType",
|
|
177
|
+
message: `Which ${chalk.cyan("Authentication")} mode would you like to use?`,
|
|
178
|
+
choices: ["static", "dynamic", "none"],
|
|
179
|
+
default: "static",
|
|
175
180
|
},
|
|
176
181
|
]);
|
|
177
|
-
if (
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
182
|
+
if (authenticationType === "none") {
|
|
183
|
+
this.config.authentication = { type: "none", multipleRoles: false };
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
const { usernameField } = await inquirer.prompt([
|
|
187
|
+
{
|
|
188
|
+
type: "input",
|
|
189
|
+
name: "usernameField",
|
|
190
|
+
message: "Enter the Prisma field name to use as the login username:",
|
|
191
|
+
default: "email",
|
|
192
|
+
validate: (input) => {
|
|
193
|
+
if (!input || input.length === 0)
|
|
194
|
+
return "Field name cannot be empty";
|
|
195
|
+
if (!/^[a-z][a-zA-Z0-9]*$/.test(input))
|
|
196
|
+
return "Must be a valid Prisma field name (camelCase, starts with lowercase, letters and numbers only)";
|
|
197
|
+
return true;
|
|
184
198
|
},
|
|
185
|
-
|
|
186
|
-
|
|
199
|
+
},
|
|
200
|
+
]);
|
|
201
|
+
this.config.authentication = {
|
|
202
|
+
type: authenticationType,
|
|
203
|
+
usernameField,
|
|
204
|
+
multipleRoles: false,
|
|
205
|
+
};
|
|
206
|
+
if (authenticationType !== "static" ||
|
|
207
|
+
(authenticationType == "static" &&
|
|
208
|
+
this.config.prisma.provider !== "sqlite")) {
|
|
209
|
+
const { multipleRoles } = await inquirer.prompt([
|
|
187
210
|
{
|
|
188
|
-
type: "
|
|
189
|
-
name: "
|
|
190
|
-
|
|
191
|
-
|
|
211
|
+
type: "confirm",
|
|
212
|
+
name: "multipleRoles",
|
|
213
|
+
default: true,
|
|
214
|
+
message: `Would you like to use authentication with ${chalk.cyan("Multiple Roles")}?`,
|
|
192
215
|
},
|
|
193
216
|
]);
|
|
194
217
|
this.config.authentication = {
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
multipleRoles: false,
|
|
218
|
+
...this.config.authentication,
|
|
219
|
+
multipleRoles,
|
|
198
220
|
};
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
const { multipleRoles } = await inquirer.prompt([
|
|
203
|
-
{
|
|
204
|
-
type: "confirm",
|
|
205
|
-
name: "multipleRoles",
|
|
206
|
-
default: true,
|
|
207
|
-
message: `Would you like to use authentication with ${chalk.cyan("Multiple Roles")}?`,
|
|
208
|
-
},
|
|
209
|
-
]);
|
|
210
|
-
this.config.authentication = {
|
|
211
|
-
...this.config.authentication,
|
|
212
|
-
multipleRoles,
|
|
213
|
-
};
|
|
214
|
-
}
|
|
215
|
-
else if (this.config.prisma.provider === "sqlite") {
|
|
216
|
-
console.info(`Skipping multiple roles option because it is not supported with sqlite prisma provider and static authentication mode.`);
|
|
217
|
-
}
|
|
221
|
+
}
|
|
222
|
+
else if (this.config.prisma.provider === "sqlite") {
|
|
223
|
+
console.info(`${chalk.green("! ")}${chalk.bold("Skipping multiple roles option because it is not supported with sqlite prisma provider and static authentication mode.")}`);
|
|
218
224
|
}
|
|
219
225
|
}
|
|
220
226
|
async promptStrictRouting() {
|
|
@@ -230,6 +236,19 @@ class ProjectConfigInquirer {
|
|
|
230
236
|
strict: strictRouting,
|
|
231
237
|
};
|
|
232
238
|
}
|
|
239
|
+
async promptEntryPoint() {
|
|
240
|
+
const ext = this.config.typescript ? "ts" : "js";
|
|
241
|
+
const { entryPoint } = await inquirer.prompt([
|
|
242
|
+
{
|
|
243
|
+
type: "list",
|
|
244
|
+
name: "entryPoint",
|
|
245
|
+
message: `Which ${chalk.cyan("Entry Point")} would you like to use?`,
|
|
246
|
+
choices: [`src/app.${ext}`, `src/server.${ext}`],
|
|
247
|
+
default: `src/app.${ext}`,
|
|
248
|
+
},
|
|
249
|
+
]);
|
|
250
|
+
this.config.entryPoint = entryPoint.replace(`.${ext}`, "");
|
|
251
|
+
}
|
|
233
252
|
}
|
|
234
253
|
const projectConfigInquirer = new ProjectConfigInquirer();
|
|
235
254
|
export default projectConfigInquirer;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"project-config-inquirer.js","sourceRoot":"","sources":["../../src/utils/project-config-inquirer.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,QAAQ,MAAM,UAAU,CAAC;AAChC,OAAO,KAAK,MAAM,OAAO,CAAC;AAgC1B,MAAM,qBAAqB;IACjB,MAAM,CAAgB;IAE9B;QACE,IAAI,CAAC,MAAM,GAAG,EAAmB,CAAC;IACpC,CAAC;IAED,KAAK,CAAC,GAAG;QACP,MAAM,IAAI,CAAC,iBAAiB,EAAE,CAAC;QAC/B,MAAM,IAAI,CAAC,gBAAgB,EAAE,CAAC;QAC9B,MAAM,IAAI,CAAC,oBAAoB,EAAE,CAAC;QAClC,MAAM,IAAI,CAAC,gBAAgB,EAAE,CAAC;QAC9B,MAAM,IAAI,CAAC,oBAAoB,EAAE,CAAC;QAClC,MAAM,IAAI,CAAC,mBAAmB,EAAE,CAAC;QAEjC,IAAI,IAAI,CAAC,MAAM,CAAC,WAAW,KAAK,GAAG,EAAE;YACnC,IAAI,CAAC,MAAM,CAAC,WAAW,GAAG,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;YACvD,IAAI,CAAC,MAAM,CAAC,WAAW,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;SACvD;;YACC,IAAI,CAAC,MAAM,CAAC,WAAW,GAAG,IAAI,CAAC,OAAO,CACpC,OAAO,CAAC,GAAG,EAAE,EACb,IAAI,CAAC,MAAM,CAA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AG,MAAM,QAAQ,CAAC,MAAM,CAAC;YAC9C;gBACE,IAAI,EAAE,SAAS;gBACf,IAAI,EAAE,eAAe;gBACrB,OAAO,EAAE,yBAAyB,KAAK,CAAC,IAAI,CAAC,gBAAgB,CAAC,GAAG;gBACjE,OAAO,EAAE,KAAK;aACf;SACF,CAAC,CAAC;QACH,IAAI,CAAC,MAAM,CAAC,OAAO,GAAG;YACpB,MAAM,EAAE,aAAa;SACtB,CAAC;IACJ,CAAC;CACF;AAED,MAAM,qBAAqB,GAAG,IAAI,qBAAqB,EAAE,CAAC;AAE1D,eAAe,qBAAqB,CAAC","sourcesContent":["import path from \"path\";\nimport inquirer from \"inquirer\";\nimport chalk from \"chalk\";\n\nexport interface ProjectConfig {\n projectName: string;\n argProjectName?: string;\n typescript: boolean;\n validation?: {\n type?: \"zod\" | \"class-validator\";\n };\n authentication?: {\n type?: \"static\" | \"dynamic\" | \"define later\";\n usernameField?: \"username\" | \"email\" | \"custom\";\n multipleRoles: boolean;\n };\n prisma: {\n provider:\n | \"postgresql\"\n | \"mysql\"\n | \"sqlite\"\n | \"sqlserver\"\n | \"cockroachdb\"\n | \"mongodb\";\n idDatabaseType: string;\n defaultDBurl: string;\n };\n projectPath: string;\n routing?: {\n strict?: boolean;\n };\n advanced?: boolean;\n}\n\nclass ProjectConfigInquirer {\n private config: ProjectConfig;\n\n constructor() {\n this.config = {} as ProjectConfig;\n }\n\n async run() {\n await this.promptProjectName();\n await this.promptTypescript();\n await this.promptPrismaProvider();\n await this.promptValidation();\n await this.promptAuthentication();\n await this.promptStrictRouting();\n\n if (this.config.projectName === \".\") {\n this.config.projectName = path.basename(process.cwd());\n this.config.projectPath = path.resolve(process.cwd());\n } else\n this.config.projectPath = path.resolve(\n process.cwd(),\n this.config.projectName\n );\n\n if (process?.argv?.includes?.(\"--advanced\")) this.config.advanced = true;\n\n return this.config;\n }\n\n private async promptProjectName() {\n let projectName = process?.argv?.[2];\n this.config.argProjectName = process?.argv?.[2];\n\n if (!projectName) {\n const result = await inquirer.prompt([\n {\n type: \"input\",\n name: \"projectName\",\n message: \"What is the name of your project?\",\n default: \"my-arkos-project\",\n validate: this.validateProjectName,\n },\n ]);\n projectName = result.projectName;\n } else {\n // Validate the project name from command line args\n const validation = this.validateProjectName(projectName);\n if (validation !== true) {\n console.error(chalk.red(`\\nError: ${validation}`));\n process.exit(1);\n }\n }\n\n this.config.projectName = projectName;\n }\n\n private validateProjectName(input: string): boolean | string {\n if (input === \".\") return true;\n\n if (!input || input.length === 0) {\n return \"Project name cannot be empty\";\n }\n\n if (!/^[a-zA-Z0-9_-]+$/.test(input)) {\n return \"Project name can only contain letters, numbers, hyphens, and underscores\";\n }\n\n if (!/^[a-zA-Z0-9]/.test(input)) {\n return \"Project name must start with a letter or number\";\n }\n\n if (!/[a-zA-Z0-9]$/.test(input)) {\n return \"Project name must end with a letter or number\";\n }\n\n if (input.length > 50) {\n return \"Project name must be 50 characters or less\";\n }\n\n const reservedNames = [\"node_modules\"];\n if (reservedNames.includes(input.toLowerCase())) {\n return \"Project name cannot be a reserved name\";\n }\n\n return true;\n }\n\n private async promptTypescript() {\n const { typescript } = await inquirer.prompt([\n {\n type: \"confirm\",\n name: \"typescript\",\n message: `Would you like to use ${chalk.cyan(\"TypeScript\")}?`,\n default: false,\n },\n ]);\n this.config.typescript = typescript;\n }\n\n private async promptPrismaProvider() {\n const { prismaProvider } = await inquirer.prompt([\n {\n type: \"list\",\n name: \"prismaProvider\",\n message: `What db provider will be used for ${chalk.cyan(\"Prisma\")}?`,\n choices: [\n \"postgresql\",\n \"mongodb\",\n \"mysql\",\n \"sqlite\",\n \"sqlserver\",\n \"cockroachdb\",\n ],\n },\n ]);\n\n // Set the correct idDatabaseType based on provider\n let idDatabaseType: string;\n let defaultDBurl: string;\n\n switch (prismaProvider) {\n case \"mongodb\":\n idDatabaseType = '@id @default(auto()) @map(\"_id\") @db.ObjectId';\n defaultDBurl = `mongodb://localhost:27017/${this.config.projectName}`;\n break;\n case \"sqlite\":\n idDatabaseType = \"@id @default(cuid())\";\n defaultDBurl = \"file:../../file.db\";\n break;\n case \"mysql\":\n idDatabaseType = \"@id @default(uuid())\";\n defaultDBurl = `mysql://username:password@localhost:3306/${this.config.projectName}`;\n break;\n case \"postgresql\":\n idDatabaseType = \"@id @default(uuid())\";\n defaultDBurl = `postgresql://username:password@localhost:5432/${this.config.projectName}`;\n break;\n case \"sqlserver\":\n idDatabaseType = \"@id @default(uuid())\";\n defaultDBurl = `sqlserver://localhost:1433;database=${this.config.projectName};username=sa;password=password;encrypt=DANGER_PLAINTEXT`;\n break;\n case \"cockroachdb\":\n idDatabaseType = \"@id @default(uuid())\";\n defaultDBurl = `postgresql://username:password@localhost:26257/${this.config.projectName}?sslmode=require`;\n break;\n default:\n idDatabaseType = \"@id @default(uuid())\";\n defaultDBurl = `postgresql://username:password@localhost:5432/${this.config.projectName}`;\n }\n\n this.config.prisma = {\n provider: prismaProvider,\n idDatabaseType: idDatabaseType,\n defaultDBurl: defaultDBurl,\n };\n }\n\n private async promptValidation() {\n const { useValidation } = await inquirer.prompt([\n {\n type: \"confirm\",\n name: \"useValidation\",\n message: `Would you like to set up ${chalk.cyan(\"Validation\")}?`,\n default: true,\n },\n ]);\n\n if (useValidation) {\n let validationTypeResponse: {\n validationType: \"zod\" | \"class-validator\";\n } = { validationType: \"zod\" };\n\n if (this.config.typescript)\n validationTypeResponse = await inquirer.prompt([\n {\n type: \"list\",\n name: \"validationType\",\n message: \"Choose validation library:\",\n choices: [\"zod\", \"class-validator\"],\n },\n ]);\n else {\n console.info(\n chalk.bold(\n `${chalk.greenBright(\"?\")} Validation library set to zod (class-validator is not supported on JavaScript):`\n ),\n chalk.cyan(\"zod\")\n );\n }\n this.config.validation = {\n type: validationTypeResponse.validationType,\n };\n } else if (!this.config.typescript) {\n }\n }\n\n private async promptAuthentication() {\n const { useAuthentication } = await inquirer.prompt([\n {\n type: \"confirm\",\n name: \"useAuthentication\",\n message: `Would you like to set up ${chalk.cyan(\"Authentication\")}?`,\n default: true,\n },\n ]);\n\n if (useAuthentication) {\n const { authenticationType } = await inquirer.prompt([\n {\n type: \"list\",\n name: \"authenticationType\",\n message: \"Choose authentication type:\",\n choices: [\"static\", \"dynamic\"],\n },\n ]);\n\n const { usernameField } = await inquirer.prompt([\n {\n type: \"list\",\n name: \"usernameField\",\n message: \"Choose default username field for login:\",\n choices: [\"email\", \"username\", \"define later\"],\n },\n ]);\n\n this.config.authentication = {\n type: authenticationType,\n usernameField:\n usernameField === \"define later\" ? \"custom\" : usernameField,\n multipleRoles: false,\n };\n\n if (\n authenticationType !== \"define later\" &&\n this.config.prisma.provider !== \"sqlite\" &&\n authenticationType !== \"static\"\n ) {\n const { multipleRoles } = await inquirer.prompt([\n {\n type: \"confirm\",\n name: \"multipleRoles\",\n default: true,\n message: `Would you like to use authentication with ${chalk.cyan(\"Multiple Roles\")}?`,\n },\n ]);\n\n this.config.authentication = {\n ...this.config.authentication,\n multipleRoles,\n };\n } else if (this.config.prisma.provider === \"sqlite\") {\n console.info(\n `Skipping multiple roles option because it is not supported with sqlite prisma provider and static authentication mode.`\n );\n }\n }\n }\n\n private async promptStrictRouting() {\n const { strictRouting } = await inquirer.prompt([\n {\n type: \"confirm\",\n name: \"strictRouting\",\n message: `Would you like to use ${chalk.cyan(\"Strict Routing\")}?`,\n default: false,\n },\n ]);\n this.config.routing = {\n strict: strictRouting,\n };\n }\n}\n\nconst projectConfigInquirer = new ProjectConfigInquirer();\n\nexport default projectConfigInquirer;\n"]}
|
|
1
|
+
{"version":3,"file":"project-config-inquirer.js","sourceRoot":"","sources":["../../src/utils/project-config-inquirer.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,QAAQ,MAAM,UAAU,CAAC;AAChC,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,iCAAiC,EAAE,MAAM,uBAAuB,CAAC;AAmC1E,MAAM,qBAAqB;IACjB,MAAM,CAAg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a;SACtB,CAAC;IACJ,CAAC;IAEO,KAAK,CAAC,gBAAgB;QAC5B,MAAM,GAAG,GAAG,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC;QACjD,MAAM,EAAE,UAAU,EAAE,GAAG,MAAM,QAAQ,CAAC,MAAM,CAAC;YAC3C;gBACE,IAAI,EAAE,MAAM;gBACZ,IAAI,EAAE,YAAY;gBAClB,OAAO,EAAE,SAAS,KAAK,CAAC,IAAI,CAAC,aAAa,CAAC,yBAAyB;gBACpE,OAAO,EAAE,CAAC,WAAW,GAAG,EAAE,EAAE,cAAc,GAAG,EAAE,CAAC;gBAChD,OAAO,EAAE,WAAW,GAAG,EAAE;aAC1B;SACF,CAAC,CAAC;QAEH,IAAI,CAAC,MAAM,CAAC,UAAU,GAAG,UAAU,CAAC,OAAO,CAAC,IAAI,GAAG,EAAE,EAAE,EAAE,CAAC,CAAC;IAC7D,CAAC;CACF;AAED,MAAM,qBAAqB,GAAG,IAAI,qBAAqB,EAAE,CAAC;AAE1D,eAAe,qBAAqB,CAAC","sourcesContent":["import path from \"path\";\nimport inquirer from \"inquirer\";\nimport chalk from \"chalk\";\nimport { detectPackageManagerFromUserAgent } from \"./helpers/npm.helpers\";\n\nexport interface ProjectConfig {\n projectName: string;\n argProjectName?: string;\n typescript: boolean;\n validation?: {\n type?: \"zod\" | \"class-validator\";\n };\n authentication?: {\n type?: \"static\" | \"dynamic\" | \"none\";\n usernameField?: string;\n multipleRoles?: boolean;\n };\n prisma: {\n provider:\n | \"postgresql\"\n | \"mysql\"\n | \"sqlite\"\n | \"sqlserver\"\n | \"cockroachdb\"\n | \"mongodb\"\n | \"none\";\n idDatabaseType: string;\n defaultDatabaseUrl: string;\n };\n projectPath: string;\n routing?: {\n strict?: boolean;\n };\n advanced?: boolean;\n entryPoint: \"src/app\" | \"src/server\";\n packageManager: string;\n}\n\nclass ProjectConfigInquirer {\n private config: ProjectConfig;\n\n constructor() {\n this.config = {\n packageManager: detectPackageManagerFromUserAgent(),\n } as ProjectConfig;\n }\n\n async run() {\n await this.promptProjectName();\n await this.promptTypescript();\n await this.promptPrismaProvider();\n await this.promptValidation();\n await this.promptAuthentication();\n await this.promptStrictRouting();\n await this.promptEntryPoint();\n\n if (this.config.projectName === \".\") {\n this.config.projectName = path.basename(process.cwd());\n this.config.projectPath = path.resolve(process.cwd());\n } else\n this.config.projectPath = path.resolve(\n process.cwd(),\n this.config.projectName\n );\n\n if (process?.argv?.includes?.(\"--advanced\")) this.config.advanced = true;\n if (this.config.prisma.defaultDatabaseUrl)\n this.config.prisma.defaultDatabaseUrl =\n this.config.prisma.defaultDatabaseUrl.replaceAll(\n \"{{projectName}}\",\n this.config.projectName\n );\n\n return this.config;\n }\n\n private async promptProjectName() {\n let projectName = process?.argv?.[2];\n this.config.argProjectName = process?.argv?.[2];\n\n if (!projectName) {\n const result = await inquirer.prompt([\n {\n type: \"input\",\n name: \"projectName\",\n message: \"What is the name of your project?\",\n default: \"my-arkos-project\",\n validate: this.validateProjectName,\n },\n ]);\n projectName = result.projectName;\n } else {\n const validation = this.validateProjectName(projectName);\n if (validation !== true) {\n console.error(chalk.red(`\\nError: ${validation}`));\n process.exit(1);\n }\n }\n\n this.config.projectName = projectName;\n }\n\n private validateProjectName(input: string): boolean | string {\n if (input === \".\") return true;\n\n if (!input || input.length === 0) {\n return \"Project name cannot be empty\";\n }\n\n if (!/^[a-zA-Z0-9_-]+$/.test(input)) {\n return \"Project name can only contain letters, numbers, hyphens, and underscores\";\n }\n\n if (!/^[a-zA-Z0-9]/.test(input)) {\n return \"Project name must start with a letter or number\";\n }\n\n if (!/[a-zA-Z0-9]$/.test(input)) {\n return \"Project name must end with a letter or number\";\n }\n\n if (input.length > 50) {\n return \"Project name must be 50 characters or less\";\n }\n\n const reservedNames = [\"node_modules\"];\n if (reservedNames.includes(input.toLowerCase())) {\n return \"Project name cannot be a reserved name\";\n }\n\n return true;\n }\n\n private async promptTypescript() {\n const { typescript } = await inquirer.prompt([\n {\n type: \"confirm\",\n name: \"typescript\",\n message: `Would you like to use ${chalk.cyan(\"TypeScript\")}?`,\n default: true,\n },\n ]);\n this.config.typescript = typescript;\n }\n\n private async promptPrismaProvider() {\n const { prismaProvider } = await inquirer.prompt([\n {\n type: \"list\",\n name: \"prismaProvider\",\n message: `What db provider will be used for ${chalk.cyan(\"Prisma\")}?`,\n choices: [\n \"postgresql\",\n \"mongodb\",\n \"mysql\",\n \"sqlite\",\n \"sqlserver\",\n \"cockroachdb\",\n \"none\",\n ],\n },\n ]);\n\n let idDatabaseType: string;\n let defaultDatabaseUrl: string;\n\n switch (prismaProvider) {\n case \"mongodb\":\n idDatabaseType = '@id @default(auto()) @map(\"_id\") @db.ObjectId';\n defaultDatabaseUrl = `mongodb://localhost:27017/{{projectName}}`;\n break;\n case \"sqlite\":\n idDatabaseType = \"@id @default(cuid())\";\n defaultDatabaseUrl = \"file:../../file.db\";\n break;\n case \"mysql\":\n idDatabaseType = \"@id @default(uuid())\";\n defaultDatabaseUrl = `mysql://username:password@localhost:3306/{{projectName}}`;\n break;\n case \"postgresql\":\n idDatabaseType = \"@id @default(uuid())\";\n defaultDatabaseUrl = `postgresql://username:password@localhost:5432/{{projectName}}`;\n break;\n case \"sqlserver\":\n idDatabaseType = \"@id @default(uuid())\";\n defaultDatabaseUrl = `sqlserver://localhost:1433;database={{projectName}};username=sa;password=password;encrypt=DANGER_PLAINTEXT`;\n break;\n case \"cockroachdb\":\n idDatabaseType = \"@id @default(uuid())\";\n defaultDatabaseUrl = `postgresql://username:password@localhost:26257/{{projectName}}?sslmode=require`;\n break;\n default:\n idDatabaseType = \"@id @default(uuid())\";\n defaultDatabaseUrl = `postgresql://username:password@localhost:5432/{{projectName}}`;\n }\n\n this.config.prisma = {\n provider: prismaProvider,\n idDatabaseType,\n defaultDatabaseUrl,\n };\n }\n\n private async promptValidation() {\n const choices = this.config.typescript\n ? [\"zod\", \"class-validator\", \"none\"]\n : [\"zod\", \"none\"];\n\n const { validationType } = await inquirer.prompt([\n {\n type: \"list\",\n name: \"validationType\",\n message: `Which ${chalk.cyan(\"Validation\")} library would you like to use?`,\n choices,\n default: \"zod\",\n },\n ]);\n\n if (validationType !== \"none\") {\n this.config.validation = {\n type: validationType as \"zod\" | \"class-validator\",\n };\n }\n // validation stays undefined when \"none\" is chosen — matches original behaviour\n }\n\n private async promptAuthentication() {\n if (this.config.prisma.provider === \"none\") {\n console.info(\n `${chalk.green(\"! \")}${chalk.bold(\"Skipping authentication setup as it requires prisma.\")}`\n );\n this.config.authentication = {\n type: \"none\",\n };\n return;\n }\n\n const { authenticationType } = await inquirer.prompt([\n {\n type: \"list\",\n name: \"authenticationType\",\n message: `Which ${chalk.cyan(\"Authentication\")} mode would you like to use?`,\n choices: [\"static\", \"dynamic\", \"none\"],\n default: \"static\",\n },\n ]);\n\n if (authenticationType === \"none\") {\n this.config.authentication = { type: \"none\", multipleRoles: false };\n return;\n }\n\n const { usernameField } = await inquirer.prompt([\n {\n type: \"input\",\n name: \"usernameField\",\n message: \"Enter the Prisma field name to use as the login username:\",\n default: \"email\",\n validate: (input: string) => {\n if (!input || input.length === 0) return \"Field name cannot be empty\";\n if (!/^[a-z][a-zA-Z0-9]*$/.test(input))\n return \"Must be a valid Prisma field name (camelCase, starts with lowercase, letters and numbers only)\";\n return true;\n },\n },\n ]);\n\n this.config.authentication = {\n type: authenticationType as \"static\" | \"dynamic\",\n usernameField,\n multipleRoles: false,\n };\n\n if (\n authenticationType !== \"static\" ||\n (authenticationType == \"static\" &&\n this.config.prisma.provider !== \"sqlite\")\n ) {\n const { multipleRoles } = await inquirer.prompt([\n {\n type: \"confirm\",\n name: \"multipleRoles\",\n default: true,\n message: `Would you like to use authentication with ${chalk.cyan(\"Multiple Roles\")}?`,\n },\n ]);\n\n this.config.authentication = {\n ...this.config.authentication,\n multipleRoles,\n };\n } else if (this.config.prisma.provider === \"sqlite\") {\n console.info(\n `${chalk.green(\"! \")}${chalk.bold(\"Skipping multiple roles option because it is not supported with sqlite prisma provider and static authentication mode.\")}`\n );\n }\n }\n\n private async promptStrictRouting() {\n const { strictRouting } = await inquirer.prompt([\n {\n type: \"confirm\",\n name: \"strictRouting\",\n message: `Would you like to use ${chalk.cyan(\"Strict Routing\")}?`,\n default: false,\n },\n ]);\n this.config.routing = {\n strict: strictRouting,\n };\n }\n\n private async promptEntryPoint() {\n const ext = this.config.typescript ? \"ts\" : \"js\";\n const { entryPoint } = await inquirer.prompt([\n {\n type: \"list\",\n name: \"entryPoint\",\n message: `Which ${chalk.cyan(\"Entry Point\")} would you like to use?`,\n choices: [`src/app.${ext}`, `src/server.${ext}`],\n default: `src/app.${ext}`,\n },\n ]);\n\n this.config.entryPoint = entryPoint.replace(`.${ext}`, \"\");\n }\n}\n\nconst projectConfigInquirer = new ProjectConfigInquirer();\n\nexport default projectConfigInquirer;\n"]}
|
|
@@ -12,11 +12,7 @@ class TemplateCompiler {
|
|
|
12
12
|
"auth-permission.prisma.hbs",
|
|
13
13
|
"auth-role.prisma.hbs",
|
|
14
14
|
"user-role.prisma.hbs",
|
|
15
|
-
|
|
16
|
-
const userDtoFiles = [
|
|
17
|
-
"create-user.dto.ts.hbs",
|
|
18
|
-
"update-user.dto.ts.hbs",
|
|
19
|
-
"query-user.dto.ts.hbs",
|
|
15
|
+
"user-permission.prisma.hbs",
|
|
20
16
|
];
|
|
21
17
|
const sharedAuthDtoFiles = [
|
|
22
18
|
"login.dto.ts.hbs",
|
|
@@ -32,31 +28,33 @@ class TemplateCompiler {
|
|
|
32
28
|
"update-auth-role.dto.ts.hbs",
|
|
33
29
|
"query-auth-role.dto.ts.hbs",
|
|
34
30
|
];
|
|
31
|
+
const userDtoFiles = [
|
|
32
|
+
"create-user.dto.ts.hbs",
|
|
33
|
+
"update-user.dto.ts.hbs",
|
|
34
|
+
"query-user.dto.ts.hbs",
|
|
35
|
+
];
|
|
35
36
|
const authModuleComponents = [
|
|
36
|
-
"auth.route-hook.ts.hbs",
|
|
37
37
|
"auth.policy.ts.hbs",
|
|
38
38
|
"auth.router.ts.hbs",
|
|
39
39
|
];
|
|
40
40
|
const authPermissionModuleComponents = [
|
|
41
41
|
"auth-permission.router.ts.hbs",
|
|
42
42
|
"auth-permission.policy.ts.hbs",
|
|
43
|
-
"auth-permission.route-hook.ts.hbs",
|
|
44
43
|
"auth-permission.service.ts.hbs",
|
|
45
44
|
];
|
|
46
45
|
const authRoleModuleComponents = [
|
|
47
46
|
"auth-role.router.ts.hbs",
|
|
48
47
|
"auth-role.policy.ts.hbs",
|
|
49
|
-
"auth-role.route-hook.ts.hbs",
|
|
50
48
|
"auth-role.service.ts.hbs",
|
|
51
49
|
];
|
|
52
50
|
const userModuleComponents = [
|
|
53
|
-
"user.route-hook.ts.hbs",
|
|
54
51
|
"user.service.ts.hbs",
|
|
55
52
|
"user.router.ts.hbs",
|
|
56
53
|
"user.policy.ts.hbs",
|
|
57
54
|
];
|
|
58
|
-
if (
|
|
59
|
-
|
|
55
|
+
if (config.prisma?.provider === "none")
|
|
56
|
+
files.push(...authSharedPrismaFiles, ...dynamicAuthPrismaFiles, "schema.prisma.hbs", ...sharedAuthDtoFiles, ...dynamicAuthDtoFiles, ...userModuleComponents, ...authModuleComponents, ...authPermissionModuleComponents, ...authRoleModuleComponents, ...userDtoFiles, "file-upload.auth.ts.hbs");
|
|
57
|
+
if (!config.authentication?.type || config.authentication?.type === "none")
|
|
60
58
|
files.push(...authSharedPrismaFiles, ...dynamicAuthPrismaFiles, ...sharedAuthDtoFiles, ...dynamicAuthDtoFiles, ...userModuleComponents, ...authModuleComponents, ...authPermissionModuleComponents, ...authRoleModuleComponents, ...userDtoFiles, "file-upload.policy.ts.hbs");
|
|
61
59
|
if (config.authentication?.type === "static")
|
|
62
60
|
files.push(...dynamicAuthPrismaFiles, ...dynamicAuthDtoFiles, ...authPermissionModuleComponents, ...authRoleModuleComponents);
|
|
@@ -66,6 +64,8 @@ class TemplateCompiler {
|
|
|
66
64
|
files.push(...["tsconfig.json.hbs"]);
|
|
67
65
|
if (config?.typescript)
|
|
68
66
|
files.push(...["jsconfig.json.hbs"]);
|
|
67
|
+
if (config.entryPoint === "src/app")
|
|
68
|
+
files.push("server.ts.hbs");
|
|
69
69
|
return files;
|
|
70
70
|
}
|
|
71
71
|
async compile(templatesDir, config) {
|
|
@@ -95,6 +95,11 @@ class TemplateCompiler {
|
|
|
95
95
|
fs.mkdirSync(path.dirname(outputPath), { recursive: true });
|
|
96
96
|
fs.writeFileSync(outputPath, content);
|
|
97
97
|
}
|
|
98
|
+
else {
|
|
99
|
+
const outputPath = path.join(outputDir, relativePath);
|
|
100
|
+
fs.mkdirSync(path.dirname(outputPath), { recursive: true });
|
|
101
|
+
fs.copyFileSync(fullPath, outputPath);
|
|
102
|
+
}
|
|
98
103
|
});
|
|
99
104
|
}
|
|
100
105
|
processTemplates(templatesDir);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"template-compiler.js","sourceRoot":"","sources":["../../src/utils/template-compiler.ts"],"names":[],"mappings":"AACA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,UAAU,MAAM,YAAY,CAAC;AAEpC,MAAM,gBAAgB;IACpB,KAAK,CAAC,iCAAiC,CAAC,MAAqB;QAC3D,OAAO,CAAC,CAAC,MAAM,CAAC,cAAc,CAAC;IACjC,CAAC;IAED,gBAAgB,CAAC,MAAqB;QACpC,MAAM,KAAK,GAAa,EAAE,CAAC;QAC3B,MAAM,qBAAqB,GAAG,CAAC,iBAAiB,CAAC,CAAC;QAElD,MAAM,sBAAsB,GAAG;YAC7B,4BAA4B;YAC5B,sBAAsB;YACtB,sBAAsB;
|
|
1
|
+
{"version":3,"file":"template-compiler.js","sourceRoot":"","sources":["../../src/utils/template-compiler.ts"],"names":[],"mappings":"AACA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,MAAM,IAAI,CAAC;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AC,CACjC,CAAC;oBACF,IAAI,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC;wBACjC,UAAU,GAAG,IAAI,CAAC,IAAI,CACpB,SAAS,EACT,YAAY,CAAC,OAAO,CAAC,SAAS,EAAE,GAAG,CAAC,CACrC,CAAC;oBAEJ,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;oBAC5D,EAAE,CAAC,aAAa,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;iBACvC;qBAAM;oBACL,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,YAAY,CAAC,CAAC;oBACtD,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;oBAC5D,EAAE,CAAC,YAAY,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC;iBACvC;YACH,CAAC,CAAC,CAAC;QACL,CAAC;QAED,gBAAgB,CAAC,YAAY,CAAC,CAAC;IACjC,CAAC;CACF;AAED,MAAM,gBAAgB,GAAG,IAAI,gBAAgB,EAAE,CAAC;AAEhD,eAAe,gBAAgB,CAAC","sourcesContent":["import { ProjectConfig } from \"./project-config-inquirer\";\nimport path from \"path\";\nimport fs from \"fs\";\nimport handlebars from \"handlebars\";\n\nclass TemplateCompiler {\n async canCompileAuthenticationTemplates(config: ProjectConfig) {\n return !!config.authentication;\n }\n\n filesToBeSkipped(config: ProjectConfig) {\n const files: string[] = [];\n const authSharedPrismaFiles = [\"user.prisma.hbs\"];\n\n const dynamicAuthPrismaFiles = [\n \"auth-permission.prisma.hbs\",\n \"auth-role.prisma.hbs\",\n \"user-role.prisma.hbs\",\n \"user-permission.prisma.hbs\",\n ];\n\n const sharedAuthDtoFiles = [\n \"login.dto.ts.hbs\",\n \"signup.dto.ts.hbs\",\n \"update-password.dto.ts.hbs\",\n \"update-me.dto.ts.hbs\",\n ];\n\n const dynamicAuthDtoFiles = [\n \"create-auth-permission.dto.ts.hbs\",\n \"update-auth-permission.dto.ts.hbs\",\n \"query-auth-permission.dto.ts.hbs\",\n \"create-auth-role.dto.ts.hbs\",\n \"update-auth-role.dto.ts.hbs\",\n \"query-auth-role.dto.ts.hbs\",\n ];\n\n const userDtoFiles = [\n \"create-user.dto.ts.hbs\",\n \"update-user.dto.ts.hbs\",\n \"query-user.dto.ts.hbs\",\n ];\n\n const authModuleComponents = [\n \"auth.policy.ts.hbs\",\n \"auth.router.ts.hbs\",\n ];\n\n const authPermissionModuleComponents = [\n \"auth-permission.router.ts.hbs\",\n \"auth-permission.policy.ts.hbs\",\n \"auth-permission.service.ts.hbs\",\n ];\n\n const authRoleModuleComponents = [\n \"auth-role.router.ts.hbs\",\n \"auth-role.policy.ts.hbs\",\n \"auth-role.service.ts.hbs\",\n ];\n\n const userModuleComponents = [\n \"user.service.ts.hbs\",\n \"user.router.ts.hbs\",\n \"user.policy.ts.hbs\",\n ];\n\n if (config.prisma?.provider === \"none\")\n files.push(\n ...authSharedPrismaFiles,\n ...dynamicAuthPrismaFiles,\n \"schema.prisma.hbs\",\n ...sharedAuthDtoFiles,\n ...dynamicAuthDtoFiles,\n ...userModuleComponents,\n ...authModuleComponents,\n ...authPermissionModuleComponents,\n ...authRoleModuleComponents,\n ...userDtoFiles,\n \"file-upload.auth.ts.hbs\",\n );\n\n if (!config.authentication?.type || config.authentication?.type === \"none\")\n files.push(\n ...authSharedPrismaFiles,\n ...dynamicAuthPrismaFiles,\n ...sharedAuthDtoFiles,\n ...dynamicAuthDtoFiles,\n ...userModuleComponents,\n ...authModuleComponents,\n ...authPermissionModuleComponents,\n ...authRoleModuleComponents,\n ...userDtoFiles,\n \"file-upload.policy.ts.hbs\"\n );\n\n if (config.authentication?.type === \"static\")\n files.push(\n ...dynamicAuthPrismaFiles,\n ...dynamicAuthDtoFiles,\n ...authPermissionModuleComponents,\n ...authRoleModuleComponents\n );\n\n // Ignore all DTOs when no validation library is selected\n if (!config.validation?.type)\n files.push(\n ...sharedAuthDtoFiles,\n ...dynamicAuthDtoFiles,\n ...userDtoFiles\n );\n\n // Ignoring typescript related files when typescript false\n if (!config.typescript) files.push(...[\"tsconfig.json.hbs\"]);\n\n // Ignoring javascript related files when typescript true\n if (config?.typescript) files.push(...[\"jsconfig.json.hbs\"]);\n\n if (config.entryPoint === \"src/app\") files.push(\"server.ts.hbs\");\n\n return files;\n }\n /**\n * Compiles the Arkos.js project with handlebars templates\n *\n * @param templatesDir {string} templates location\n * @param config {ProjectConfig} the project configuration\n * @returns void\n * */\n async compile(templatesDir: string, config: ProjectConfig) {\n const outputDir = config.projectPath;\n const isTypescript = config.typescript;\n const filesToBeSkipped = this.filesToBeSkipped(config);\n\n function processTemplates(dir: string, relativeDir = \"\") {\n fs.readdirSync(dir, { withFileTypes: true }).forEach(async (dirent) => {\n if (\n filesToBeSkipped.includes(dirent.name) ||\n dirent.name === \"__tests__\" ||\n dirent.name?.includes(\".test.ts\")\n )\n return;\n\n const fullPath = path.join(dir, dirent.name);\n const relativePath = path.join(relativeDir, dirent.name);\n\n if (dirent.isDirectory()) {\n processTemplates(fullPath, relativePath);\n } else if (dirent.name.endsWith(\".hbs\")) {\n const templatePath = fullPath;\n const template = handlebars.compile(\n fs.readFileSync(templatePath, \"utf8\")\n );\n\n let arkosCurrentVersion = \"{{arkosCurrentVersion}}\";\n\n const content = template({ ...config, arkosCurrentVersion });\n const ext = isTypescript ? \".ts\" : \".js\";\n\n let outputPath = path.join(\n outputDir,\n relativePath.replace(\".hbs\", \"\")\n );\n if (dirent.name.endsWith(\".ts.hbs\"))\n outputPath = path.join(\n outputDir,\n relativePath.replace(\".ts.hbs\", ext)\n );\n\n fs.mkdirSync(path.dirname(outputPath), { recursive: true });\n fs.writeFileSync(outputPath, content);\n } else {\n const outputPath = path.join(outputDir, relativePath);\n fs.mkdirSync(path.dirname(outputPath), { recursive: true });\n fs.copyFileSync(fullPath, outputPath);\n }\n });\n }\n\n processTemplates(templatesDir);\n }\n}\n\nconst templateCompiler = new TemplateCompiler();\n\nexport default templateCompiler;\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-arkos",
|
|
3
|
-
"version": "2.0.0-next.
|
|
3
|
+
"version": "2.0.0-next.21",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "CLI for creating Arkos.js projects, see docs at www.arkosjs.com",
|
|
6
6
|
"bin": {
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
},
|
|
9
9
|
"scripts": {
|
|
10
10
|
"test": "vitest --coverage",
|
|
11
|
-
"build": "rimraf dist && tsc",
|
|
11
|
+
"build": "npx rimraf dist && tsc",
|
|
12
12
|
"dev": "ts-node src/index.ts",
|
|
13
13
|
"postbuia": "ts-node scripts/postbuild/index.ts",
|
|
14
14
|
"postbuild": "npx tsx scripts/postbuild/fix-esm-imports.ts",
|
|
@@ -26,22 +26,23 @@
|
|
|
26
26
|
"bugs": {
|
|
27
27
|
"url": "https://github.com/uanela/arkos/issues"
|
|
28
28
|
},
|
|
29
|
-
"homepage": "https://www.arkosjs.com/docs/cli/
|
|
29
|
+
"homepage": "https://www.arkosjs.com/docs/tooling/cli/overviewcreate-arkos",
|
|
30
30
|
"files": ["dist", "templates", "cli.js", "README.md"],
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"@types/inquirer": "
|
|
33
|
-
"@types/node": "
|
|
32
|
+
"@types/inquirer": "8.1.0",
|
|
33
|
+
"@types/node": "16.18.126",
|
|
34
34
|
"@vitest/coverage-v8": "3.2.4",
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
"
|
|
35
|
+
"rimraf": "6.1.3",
|
|
36
|
+
"ts-node": "10.9.2",
|
|
37
|
+
"tsx": "4.21.0",
|
|
38
|
+
"typescript": "4.9.5",
|
|
39
|
+
"vitest": "3.2.4"
|
|
39
40
|
},
|
|
40
41
|
"dependencies": {
|
|
41
|
-
"@clack/prompts": "
|
|
42
|
-
"@inquirer/prompts": "
|
|
43
|
-
"chalk": "
|
|
44
|
-
"handlebars": "
|
|
45
|
-
"inquirer": "
|
|
42
|
+
"@clack/prompts": "0.11.0",
|
|
43
|
+
"@inquirer/prompts": "7.6.0",
|
|
44
|
+
"chalk": "5.4.1",
|
|
45
|
+
"handlebars": "4.7.8",
|
|
46
|
+
"inquirer": "8.2.6"
|
|
46
47
|
}
|
|
47
48
|
}
|
package/templates/basic/.env.hbs
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
|
+
{{#if (neq prisma.provider "none")}}
|
|
1
2
|
# Database connection
|
|
2
|
-
DATABASE_URL={{prisma.
|
|
3
|
+
DATABASE_URL={{prisma.defaultDatabaseUrl}}
|
|
4
|
+
{{/if}}
|
|
3
5
|
|
|
6
|
+
{{#if (neq authentication.type "none")}}
|
|
4
7
|
# JWT secrets
|
|
5
8
|
# JWT_SECRET=
|
|
6
9
|
# JWT_EXPIRES_IN=30d
|
|
10
|
+
{{/if}}
|
|
7
11
|
|
|
8
12
|
# Server configuration
|
|
9
13
|
PORT=8000
|
|
@@ -1,13 +1,11 @@
|
|
|
1
|
-
This is
|
|
1
|
+
This is an [Arkos.js](https://arkosjs.com) project scaffolded with [`create-arkos`](https://arkosjs.com/docs/tooling/create-arkos).
|
|
2
2
|
|
|
3
3
|
## Getting Started
|
|
4
4
|
|
|
5
5
|
First, run the development server:
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
|
-
|
|
9
|
-
# or
|
|
10
|
-
npm run dev
|
|
8
|
+
{{packageManager}} run dev
|
|
11
9
|
```
|
|
12
10
|
|
|
13
11
|
- Visit [http://localhost:8000/api/docs](http://localhost:8000/api/docs) with your browser to see the swagger api documentation.
|
|
@@ -6,7 +6,12 @@ const arkosConfig = defineConfig({
|
|
|
6
6
|
prisma: {
|
|
7
7
|
instance: prisma
|
|
8
8
|
},
|
|
9
|
-
{{#if
|
|
9
|
+
{{#if (eq entryPoint "src/server")}}
|
|
10
|
+
source: {
|
|
11
|
+
entryPoint: "{{entryPoint}}{{#if typescript}}.ts{{else}}.js{{/if}}"
|
|
12
|
+
},
|
|
13
|
+
{{/if}}
|
|
14
|
+
{{#if (neq authentication.type "none")}}
|
|
10
15
|
authentication: {
|
|
11
16
|
mode: '{{authentication.type}}',
|
|
12
17
|
login: {
|
|
@@ -30,10 +35,18 @@ const arkosConfig = defineConfig({
|
|
|
30
35
|
strict: false,
|
|
31
36
|
},
|
|
32
37
|
middlewares: {
|
|
33
|
-
cors: {
|
|
34
|
-
|
|
38
|
+
cors: {},
|
|
39
|
+
},
|
|
40
|
+
{{#if (eq prisma.provider "none")}}
|
|
41
|
+
warnings: {
|
|
42
|
+
suppress: {
|
|
43
|
+
prisma: {
|
|
44
|
+
noInstanceFound: true,
|
|
45
|
+
noSchemaFound: true,
|
|
46
|
+
},
|
|
35
47
|
},
|
|
36
48
|
}
|
|
49
|
+
{{/if}}
|
|
37
50
|
})
|
|
38
51
|
|
|
39
52
|
export default arkosConfig
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"compilerOptions": {
|
|
3
|
-
"target": "
|
|
4
|
-
"module": "
|
|
3
|
+
"target": "es2022",
|
|
4
|
+
"module": "es2022",
|
|
5
5
|
"moduleResolution": "bundler",
|
|
6
6
|
"rootDir": ".",
|
|
7
7
|
"baseUrl": ".",
|
|
@@ -20,15 +20,5 @@
|
|
|
20
20
|
}
|
|
21
21
|
},
|
|
22
22
|
"include": ["src/**/*.js", "src/**/*.jsx", "packages/**/*.js", "arkos.config.js"],
|
|
23
|
-
"exclude": [
|
|
24
|
-
"**/node_modules",
|
|
25
|
-
"node_modules",
|
|
26
|
-
".build",
|
|
27
|
-
"build",
|
|
28
|
-
"temp",
|
|
29
|
-
"dist",
|
|
30
|
-
"uploads",
|
|
31
|
-
"src/**/__tests__/**",
|
|
32
|
-
"src/**/*.test.js"
|
|
33
|
-
]
|
|
23
|
+
"exclude": ["node_modules", ".build", "src/**/__tests__/**", "src/**/*.test", "src/**/*.spec", "build", "dist", "uploads", "src/generated", ".arkos"]
|
|
34
24
|
}
|