@expressots/cli 1.7.1 → 1.8.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 (72) hide show
  1. package/README.md +8 -0
  2. package/bin/@types/config.d.ts +39 -39
  3. package/bin/@types/config.js +2 -2
  4. package/bin/@types/index.d.ts +1 -1
  5. package/bin/@types/index.js +17 -17
  6. package/bin/app.container.d.ts +1 -1
  7. package/bin/app.container.js +8 -8
  8. package/bin/cli.d.ts +2 -2
  9. package/bin/cli.js +38 -38
  10. package/bin/commands/__tests__/project.commands.spec.d.ts +1 -0
  11. package/bin/commands/__tests__/project.commands.spec.js +8 -0
  12. package/bin/commands/project.commands.d.ts +8 -8
  13. package/bin/commands/project.commands.js +137 -136
  14. package/bin/generate/cli.d.ts +4 -4
  15. package/bin/generate/cli.js +66 -66
  16. package/bin/generate/form.d.ts +20 -20
  17. package/bin/generate/form.js +30 -30
  18. package/bin/generate/index.d.ts +1 -1
  19. package/bin/generate/index.js +17 -17
  20. package/bin/generate/utils/command-utils.d.ts +123 -123
  21. package/bin/generate/utils/command-utils.js +314 -310
  22. package/bin/generate/utils/nonopininated-cmd.d.ts +9 -9
  23. package/bin/generate/utils/nonopininated-cmd.js +248 -248
  24. package/bin/generate/utils/opinionated-cmd.d.ts +11 -11
  25. package/bin/generate/utils/opinionated-cmd.js +481 -480
  26. package/bin/help/cli.d.ts +4 -4
  27. package/bin/help/cli.js +15 -15
  28. package/bin/help/form.d.ts +2 -2
  29. package/bin/help/form.js +28 -28
  30. package/bin/help/index.d.ts +1 -1
  31. package/bin/help/index.js +17 -2
  32. package/bin/index.d.ts +6 -4
  33. package/bin/index.js +22 -20
  34. package/bin/info/cli.d.ts +4 -4
  35. package/bin/info/cli.js +15 -15
  36. package/bin/info/form.d.ts +2 -2
  37. package/bin/info/form.js +36 -36
  38. package/bin/info/index.d.ts +1 -1
  39. package/bin/info/index.js +17 -17
  40. package/bin/new/cli.d.ts +4 -4
  41. package/bin/new/cli.js +51 -51
  42. package/bin/new/form.d.ts +2 -2
  43. package/bin/new/form.js +235 -213
  44. package/bin/new/index.d.ts +1 -1
  45. package/bin/new/index.js +17 -17
  46. package/bin/providers/cli.d.ts +4 -4
  47. package/bin/providers/cli.js +43 -38
  48. package/bin/providers/external/external.provider.d.ts +2 -0
  49. package/bin/providers/external/external.provider.js +49 -0
  50. package/bin/providers/index.d.ts +1 -1
  51. package/bin/providers/index.js +17 -17
  52. package/bin/providers/prisma/prisma.provider.d.ts +2 -2
  53. package/bin/providers/prisma/prisma.provider.js +272 -270
  54. package/bin/types.d.ts +1 -1
  55. package/bin/types.js +17 -17
  56. package/bin/utils/add-controller-to-module.d.ts +1 -1
  57. package/bin/utils/add-controller-to-module.js +46 -46
  58. package/bin/utils/add-module-to-container.d.ts +3 -3
  59. package/bin/utils/add-module-to-container.js +129 -129
  60. package/bin/utils/center-text.d.ts +2 -2
  61. package/bin/utils/center-text.js +10 -10
  62. package/bin/utils/cli-ui.d.ts +3 -3
  63. package/bin/utils/cli-ui.js +19 -19
  64. package/bin/utils/compiler.d.ts +15 -15
  65. package/bin/utils/compiler.js +93 -93
  66. package/bin/utils/find-folder.d.ts +5 -5
  67. package/bin/utils/find-folder.js +37 -37
  68. package/bin/utils/index.d.ts +1 -1
  69. package/bin/utils/index.js +17 -17
  70. package/bin/utils/verify-file-exists.d.ts +2 -2
  71. package/bin/utils/verify-file-exists.js +30 -30
  72. package/package.json +31 -28
@@ -1,265 +1,267 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.prismaProvider = void 0;
7
- const chalk_1 = __importDefault(require("chalk"));
8
- const inquirer_1 = __importDefault(require("inquirer"));
9
- const node_child_process_1 = require("node:child_process");
10
- const node_fs_1 = __importDefault(require("node:fs"));
11
- const cli_ui_1 = require("../../utils/cli-ui");
12
- const node_path_1 = __importDefault(require("node:path"));
13
- const node_process_1 = require("node:process");
14
- const compiler_1 = __importDefault(require("../../utils/compiler"));
15
- const find_folder_1 = require("../../utils/find-folder");
16
- const prismaProvider = async (version, providerVersion) => {
17
- var _a;
18
- const choices = [
19
- { name: "CockroachDB", value: "cockroachdb" },
20
- { name: "Microsoft SQL Server", value: "sqlserver" },
21
- { name: "MongoDB", value: "mongodb" },
22
- { name: "MySQL", value: "mysql" },
23
- { name: "PostgreSQL", value: "postgresql" },
24
- { name: "SQLite", value: "sqlite" },
25
- ];
26
- const drivers = {
27
- PostgreSQL: "pg",
28
- MySQL: "mysql2",
29
- SQLite: "sqlite3",
30
- "Microsoft SQL Server": "mssql",
31
- MongoDB: "mongodb",
32
- CockroachDB: "pg",
33
- };
34
- const answerPt1 = await inquirer_1.default.prompt([
35
- {
36
- type: "input",
37
- name: "prismaClientVersion",
38
- message: "Type the prisma client version (default=latest):",
39
- default: "latest",
40
- transformer: (input) => {
41
- return chalk_1.default.yellow(chalk_1.default.bold(input));
42
- },
43
- },
44
- {
45
- type: "input",
46
- name: "schemaName",
47
- message: "Type the schema name (default=schema):",
48
- default: "schema",
49
- transformer: (input) => {
50
- return chalk_1.default.yellow(chalk_1.default.bold(input));
51
- },
52
- },
53
- {
54
- type: "input",
55
- name: "schemaPath",
56
- message: "Where do you want to save your prisma schema (default=./):",
57
- default: ".",
58
- transformer: (input) => {
59
- return chalk_1.default.yellow(chalk_1.default.bold(input));
60
- },
61
- },
62
- {
63
- type: "list",
64
- name: "databaseName",
65
- message: "Select your database:",
66
- choices: choices.map((choice) => choice.name),
67
- },
68
- ]);
69
- const answerPt2 = await inquirer_1.default.prompt([
70
- {
71
- type: "confirm",
72
- name: "installDriver",
73
- message: `Do you want to install the latest recommended database driver for ${answerPt1.databaseName}?`,
74
- default: true,
75
- },
76
- {
77
- type: "confirm",
78
- name: "baseRepository",
79
- message: "Do you want to add BaseRepository Pattern in this project?\nthis will replace the existing BaseRepository and BaseRespositoryInterface if it exists.",
80
- default: true,
81
- },
82
- {
83
- type: "confirm",
84
- name: "confirm",
85
- message: "Do you want to add prisma provider in this project?",
86
- default: true,
87
- },
88
- ]);
89
- const answer = Object.assign(Object.assign({}, answerPt1), answerPt2);
90
- if (answer.confirm) {
91
- // Find which package manager the user has used to install the desired prisma version
92
- const packageManager = node_fs_1.default.existsSync("package-lock.json" || "yarn.lock" || "pnpm-lock.yaml")
93
- ? "npm"
94
- : node_fs_1.default.existsSync("yarn.lock")
95
- ? "yarn"
96
- : node_fs_1.default.existsSync("pnpm-lock.yaml")
97
- ? "pnpm"
98
- : null;
99
- if (packageManager) {
100
- // Install prisma in the project
101
- console.log(`Installing prisma with ${packageManager}...`);
102
- await execProcess({
103
- commandArg: packageManager,
104
- args: ["add", `prisma@${providerVersion}`, "-D"],
105
- directory: process.cwd(),
106
- });
107
- // Install Prisma Client
108
- console.log(`Installing Prisma Client with ${packageManager}...`);
109
- await execProcess({
110
- commandArg: packageManager,
111
- args: ["add", `@prisma/client@${answer.prismaClientVersion}`],
112
- directory: process.cwd(),
113
- });
114
- if (answer.installDriver) {
115
- // Install database driver
116
- console.log(`Installing the latest recommended database driver for ${answer.databaseName}: ${drivers[answer.databaseName]} ...`);
117
- await execProcess({
118
- commandArg: packageManager,
119
- args: ["add", drivers[answer.databaseName]],
120
- directory: process.cwd(),
121
- });
122
- }
123
- // Install @expressots/prisma in the project
124
- console.log(`Installing @expressots/prisma with ${packageManager}...`);
125
- await execProcess({
126
- commandArg: packageManager,
127
- args: ["add", `@expressots/prisma@${version}`],
128
- directory: process.cwd(),
129
- });
130
- }
131
- else {
132
- (0, cli_ui_1.printError)(`Could not find a package manager installed in this project.\nPlease install prisma and @expressots/prisma manually.`, "prisma");
133
- process.exit(1);
134
- }
135
- // Map choices to find the corresponding value
136
- answer.databaseName = (_a = choices.find((choice) => choice.name === answer.databaseName)) === null || _a === void 0 ? void 0 : _a.value;
137
- // Init prisma
138
- console.log(`Initializing prisma...`);
139
- const prismaFolder = (0, find_folder_1.hasFolder)(process.cwd(), ["node_modules", ".git"]);
140
- if (prismaFolder.found) {
141
- const prismaEnquirer = await inquirer_1.default.prompt([
142
- {
143
- type: "confirm",
144
- name: "confirm",
145
- message: "Prisma is already initialized. Do you want to override it?",
146
- default: true,
147
- },
148
- ]);
149
- if ((prismaEnquirer === null || prismaEnquirer === void 0 ? void 0 : prismaEnquirer.confirm) === false) {
150
- console.log(chalk_1.default.red("Prisma init aborted!"));
151
- return;
152
- }
153
- node_fs_1.default.rmSync(prismaFolder.path, {
154
- recursive: true,
155
- force: true,
156
- });
157
- }
158
- await execProcess({
159
- commandArg: "npx",
160
- args: [
161
- "prisma",
162
- "init",
163
- "--datasource-provider",
164
- answer.databaseName,
165
- ],
166
- directory: process.cwd(),
167
- });
168
- const oldFileName = node_path_1.default.join(process.cwd(), "/prisma/schema.prisma");
169
- const newFileName = node_path_1.default.join(process.cwd(), `/prisma/${answer.schemaName}.prisma`);
170
- node_fs_1.default.renameSync(oldFileName, newFileName);
171
- // Move the folder to the destination
172
- const schemaPath = node_path_1.default.join(process.cwd(), `${answer.schemaPath}/prisma/${answer.schemaName}.prisma`);
173
- if (!node_fs_1.default.existsSync(schemaPath)) {
174
- node_fs_1.default.mkdirSync(node_path_1.default.join(process.cwd(), `${answer.schemaPath}/prisma`), { recursive: true });
175
- }
176
- node_fs_1.default.renameSync(newFileName, schemaPath);
177
- // Remove the source folder
178
- if (newFileName !== schemaPath) {
179
- node_fs_1.default.rmSync(node_path_1.default.join(process.cwd(), "/prisma"), { recursive: true });
180
- }
181
- // Add prisma to package.json
182
- prismaPackage(answer);
183
- if (answer.baseRepository) {
184
- const { opinionated, sourceRoot } = await compiler_1.default.loadConfig();
185
- let folderMatch = "";
186
- if (opinionated) {
187
- folderMatch = "repositories";
188
- }
189
- else {
190
- folderMatch = "";
191
- }
192
- const repositoryDir = `${sourceRoot}/${folderMatch}`;
193
- console.log(`Generating BaseRepository Pattern...`);
194
- const baseRepositoryInterfaceTplPath = node_path_1.default.join(__dirname, "./templates/base-repository.interface.tpl");
195
- const baseRepositoryTplPath = node_path_1.default.join(__dirname, "./templates/base-repository.tpl");
196
- const baseRepositoryInterfaceTemplate = node_fs_1.default.readFileSync(baseRepositoryInterfaceTplPath, "utf8");
197
- const baseRepositoryTemplate = node_fs_1.default.readFileSync(baseRepositoryTplPath, "utf8");
198
- node_fs_1.default.writeFileSync(node_path_1.default.join(repositoryDir, "base-repository.interface.ts"), baseRepositoryInterfaceTemplate);
199
- node_fs_1.default.writeFileSync(node_path_1.default.join(repositoryDir, "base-repository.ts"), baseRepositoryTemplate);
200
- }
201
- // Install @expressots/prisma in the project
202
- console.log(`Mapping configurations to expressots.config...`);
203
- await addProviderConfigInExpressotsConfig(answer.schemaName, `${answer.schemaPath}/prisma`);
204
- console.log("Now configure your database connection in the project.");
205
- console.log(chalk_1.default.green("\nšŸ‘ Prisma provider added successfully!"));
206
- }
207
- else {
208
- console.log(chalk_1.default.red("Prisma provider not added!"));
209
- }
210
- };
211
- exports.prismaProvider = prismaProvider;
212
- async function execProcess({ commandArg, args, directory, }) {
213
- return new Promise((resolve, reject) => {
214
- const isWindows = process.platform === "win32";
215
- const command = isWindows ? `${commandArg}.cmd` : commandArg;
216
- const installProcess = (0, node_child_process_1.spawn)(command, args, {
217
- cwd: directory,
218
- });
219
- console.log(chalk_1.default.bold.blue(`Executing: ${command} ${args.join(" ")}`));
220
- console.log(chalk_1.default.yellow("---------------------------------------"));
221
- installProcess.stdout.on("data", (data) => {
222
- console.log(chalk_1.default.green(data.toString().trim())); // Display regular messages in green
223
- });
224
- installProcess.stderr.on("data", (data) => {
225
- console.error(chalk_1.default.red(data.toString().trim())); // Display error messages in red
226
- });
227
- installProcess.on("close", (code) => {
228
- if (code === 0) {
229
- console.log(chalk_1.default.bold.green("---------------------------------------"));
230
- console.log(chalk_1.default.bold.green("Installation Done!"));
231
- resolve("Installation Done!");
232
- }
233
- else {
234
- console.error(chalk_1.default.bold.red("---------------------------------------"));
235
- console.error(chalk_1.default.bold.red(`Command ${command} ${args.join(" ")} exited with code ${code}`));
236
- reject(new Error(`Command ${command} ${args.join(" ")} exited with code ${code}`));
237
- (0, node_process_1.exit)(1);
238
- }
239
- });
240
- });
241
- }
242
- function prismaPackage(answer) {
243
- // Get the absolute path of the input directory parameter
244
- const absDirPath = node_path_1.default.resolve(process.cwd());
245
- // Load the package.json file
246
- const packageJsonPath = node_path_1.default.join(absDirPath, "package.json");
247
- const fileContents = node_fs_1.default.readFileSync(packageJsonPath, "utf-8");
248
- const packageJson = JSON.parse(fileContents);
249
- // Add the Prisma configuration to the package.json
250
- packageJson.prisma = {
251
- schema: `${answer.schemaPath}/prisma/${answer.schemaName}.prisma`,
252
- };
253
- // Add the Prisma script to the package.json
254
- packageJson.scripts = Object.assign(Object.assign({}, packageJson.scripts), { prisma: "npx @expressots/prisma codegen" });
255
- // Save the package.json file
256
- node_fs_1.default.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2));
257
- }
258
- async function addProviderConfigInExpressotsConfig(schemaName, schemaPath) {
259
- const absDirPath = node_path_1.default.resolve(process.cwd());
260
- const expressotsConfigPath = node_path_1.default.join(absDirPath, "expressots.config.ts");
261
- let fileContents = node_fs_1.default.readFileSync(expressotsConfigPath, "utf-8");
262
- const config = await compiler_1.default.loadConfig();
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.prismaProvider = void 0;
7
+ const chalk_1 = __importDefault(require("chalk"));
8
+ const inquirer_1 = __importDefault(require("inquirer"));
9
+ const node_child_process_1 = require("node:child_process");
10
+ const node_fs_1 = __importDefault(require("node:fs"));
11
+ const cli_ui_1 = require("../../utils/cli-ui");
12
+ const node_path_1 = __importDefault(require("node:path"));
13
+ const node_process_1 = require("node:process");
14
+ const compiler_1 = __importDefault(require("../../utils/compiler"));
15
+ const find_folder_1 = require("../../utils/find-folder");
16
+ const prismaProvider = async (version, providerVersion) => {
17
+ const choices = [
18
+ { name: "CockroachDB", value: "cockroachdb" },
19
+ { name: "Microsoft SQL Server", value: "sqlserver" },
20
+ { name: "MongoDB", value: "mongodb" },
21
+ { name: "MySQL", value: "mysql" },
22
+ { name: "PostgreSQL", value: "postgresql" },
23
+ { name: "SQLite", value: "sqlite" },
24
+ ];
25
+ const drivers = {
26
+ PostgreSQL: "pg",
27
+ MySQL: "mysql2",
28
+ SQLite: "sqlite3",
29
+ "Microsoft SQL Server": "mssql",
30
+ MongoDB: "mongodb",
31
+ CockroachDB: "pg",
32
+ };
33
+ const answerPt1 = await inquirer_1.default.prompt([
34
+ {
35
+ type: "input",
36
+ name: "prismaClientVersion",
37
+ message: "Type the prisma client version (default=latest):",
38
+ default: "latest",
39
+ transformer: (input) => {
40
+ return chalk_1.default.yellow(chalk_1.default.bold(input));
41
+ },
42
+ },
43
+ {
44
+ type: "input",
45
+ name: "schemaName",
46
+ message: "Type the schema name (default=schema):",
47
+ default: "schema",
48
+ transformer: (input) => {
49
+ return chalk_1.default.yellow(chalk_1.default.bold(input));
50
+ },
51
+ },
52
+ {
53
+ type: "input",
54
+ name: "schemaPath",
55
+ message: "Where do you want to save your prisma schema (default=./):",
56
+ default: ".",
57
+ transformer: (input) => {
58
+ return chalk_1.default.yellow(chalk_1.default.bold(input));
59
+ },
60
+ },
61
+ {
62
+ type: "list",
63
+ name: "databaseName",
64
+ message: "Select your database:",
65
+ choices: choices.map((choice) => choice.name),
66
+ },
67
+ ]);
68
+ const answerPt2 = await inquirer_1.default.prompt([
69
+ {
70
+ type: "confirm",
71
+ name: "installDriver",
72
+ message: `Do you want to install the latest recommended database driver for ${answerPt1.databaseName}?`,
73
+ default: true,
74
+ },
75
+ {
76
+ type: "confirm",
77
+ name: "baseRepository",
78
+ message: "Do you want to add BaseRepository Pattern in this project?\nthis will replace the existing BaseRepository and BaseRespositoryInterface if it exists.",
79
+ default: true,
80
+ },
81
+ {
82
+ type: "confirm",
83
+ name: "confirm",
84
+ message: "Do you want to add prisma provider in this project?",
85
+ default: true,
86
+ },
87
+ ]);
88
+ const answer = { ...answerPt1, ...answerPt2 };
89
+ if (answer.confirm) {
90
+ // Find which package manager the user has used to install the desired prisma version
91
+ const packageManager = node_fs_1.default.existsSync("package-lock.json" || "yarn.lock" || "pnpm-lock.yaml")
92
+ ? "npm"
93
+ : node_fs_1.default.existsSync("yarn.lock")
94
+ ? "yarn"
95
+ : node_fs_1.default.existsSync("pnpm-lock.yaml")
96
+ ? "pnpm"
97
+ : null;
98
+ if (packageManager) {
99
+ // Install prisma in the project
100
+ console.log(`Installing prisma with ${packageManager}...`);
101
+ await execProcess({
102
+ commandArg: packageManager,
103
+ args: ["add", `prisma@${providerVersion}`, "-D"],
104
+ directory: process.cwd(),
105
+ });
106
+ // Install Prisma Client
107
+ console.log(`Installing Prisma Client with ${packageManager}...`);
108
+ await execProcess({
109
+ commandArg: packageManager,
110
+ args: ["add", `@prisma/client@${answer.prismaClientVersion}`],
111
+ directory: process.cwd(),
112
+ });
113
+ if (answer.installDriver) {
114
+ // Install database driver
115
+ console.log(`Installing the latest recommended database driver for ${answer.databaseName}: ${drivers[answer.databaseName]} ...`);
116
+ await execProcess({
117
+ commandArg: packageManager,
118
+ args: ["add", drivers[answer.databaseName]],
119
+ directory: process.cwd(),
120
+ });
121
+ }
122
+ // Install @expressots/prisma in the project
123
+ console.log(`Installing @expressots/prisma with ${packageManager}...`);
124
+ await execProcess({
125
+ commandArg: packageManager,
126
+ args: ["add", `@expressots/prisma@${version}`],
127
+ directory: process.cwd(),
128
+ });
129
+ }
130
+ else {
131
+ (0, cli_ui_1.printError)(`Could not find a package manager installed in this project.\nPlease install prisma and @expressots/prisma manually.`, "prisma");
132
+ process.exit(1);
133
+ }
134
+ // Map choices to find the corresponding value
135
+ answer.databaseName = choices.find((choice) => choice.name === answer.databaseName)?.value;
136
+ // Init prisma
137
+ console.log(`Initializing prisma...`);
138
+ const prismaFolder = (0, find_folder_1.hasFolder)(process.cwd(), ["node_modules", ".git"]);
139
+ if (prismaFolder.found) {
140
+ const prismaEnquirer = await inquirer_1.default.prompt([
141
+ {
142
+ type: "confirm",
143
+ name: "confirm",
144
+ message: "Prisma is already initialized. Do you want to override it?",
145
+ default: true,
146
+ },
147
+ ]);
148
+ if (prismaEnquirer?.confirm === false) {
149
+ console.log(chalk_1.default.red("Prisma init aborted!"));
150
+ return;
151
+ }
152
+ node_fs_1.default.rmSync(prismaFolder.path, {
153
+ recursive: true,
154
+ force: true,
155
+ });
156
+ }
157
+ await execProcess({
158
+ commandArg: "npx",
159
+ args: [
160
+ "prisma",
161
+ "init",
162
+ "--datasource-provider",
163
+ answer.databaseName,
164
+ ],
165
+ directory: process.cwd(),
166
+ });
167
+ const oldFileName = node_path_1.default.join(process.cwd(), "/prisma/schema.prisma");
168
+ const newFileName = node_path_1.default.join(process.cwd(), `/prisma/${answer.schemaName}.prisma`);
169
+ node_fs_1.default.renameSync(oldFileName, newFileName);
170
+ // Move the folder to the destination
171
+ const schemaPath = node_path_1.default.join(process.cwd(), `${answer.schemaPath}/prisma/${answer.schemaName}.prisma`);
172
+ if (!node_fs_1.default.existsSync(schemaPath)) {
173
+ node_fs_1.default.mkdirSync(node_path_1.default.join(process.cwd(), `${answer.schemaPath}/prisma`), { recursive: true });
174
+ }
175
+ node_fs_1.default.renameSync(newFileName, schemaPath);
176
+ // Remove the source folder
177
+ if (newFileName !== schemaPath) {
178
+ node_fs_1.default.rmSync(node_path_1.default.join(process.cwd(), "/prisma"), { recursive: true });
179
+ }
180
+ // Add prisma to package.json
181
+ prismaPackage(answer);
182
+ if (answer.baseRepository) {
183
+ const { opinionated, sourceRoot } = await compiler_1.default.loadConfig();
184
+ let folderMatch = "";
185
+ if (opinionated) {
186
+ folderMatch = "repositories";
187
+ }
188
+ else {
189
+ folderMatch = "";
190
+ }
191
+ const repositoryDir = `${sourceRoot}/${folderMatch}`;
192
+ console.log(`Generating BaseRepository Pattern...`);
193
+ const baseRepositoryInterfaceTplPath = node_path_1.default.join(__dirname, "./templates/base-repository.interface.tpl");
194
+ const baseRepositoryTplPath = node_path_1.default.join(__dirname, "./templates/base-repository.tpl");
195
+ const baseRepositoryInterfaceTemplate = node_fs_1.default.readFileSync(baseRepositoryInterfaceTplPath, "utf8");
196
+ const baseRepositoryTemplate = node_fs_1.default.readFileSync(baseRepositoryTplPath, "utf8");
197
+ node_fs_1.default.writeFileSync(node_path_1.default.join(repositoryDir, "base-repository.interface.ts"), baseRepositoryInterfaceTemplate);
198
+ node_fs_1.default.writeFileSync(node_path_1.default.join(repositoryDir, "base-repository.ts"), baseRepositoryTemplate);
199
+ }
200
+ // Install @expressots/prisma in the project
201
+ console.log(`Mapping configurations to expressots.config...`);
202
+ await addProviderConfigInExpressotsConfig(answer.schemaName, `${answer.schemaPath}/prisma`);
203
+ console.log("Now configure your database connection in the project.");
204
+ console.log(chalk_1.default.green("\nšŸ‘ Prisma provider added successfully!"));
205
+ }
206
+ else {
207
+ console.log(chalk_1.default.red("Prisma provider not added!"));
208
+ }
209
+ };
210
+ exports.prismaProvider = prismaProvider;
211
+ async function execProcess({ commandArg, args, directory, }) {
212
+ return new Promise((resolve, reject) => {
213
+ const isWindows = process.platform === "win32";
214
+ const command = isWindows ? `${commandArg}.cmd` : commandArg;
215
+ const installProcess = (0, node_child_process_1.spawn)(command, args, {
216
+ cwd: directory,
217
+ });
218
+ console.log(chalk_1.default.bold.blue(`Executing: ${command} ${args.join(" ")}`));
219
+ console.log(chalk_1.default.yellow("---------------------------------------"));
220
+ installProcess.stdout.on("data", (data) => {
221
+ console.log(chalk_1.default.green(data.toString().trim())); // Display regular messages in green
222
+ });
223
+ installProcess.stderr.on("data", (data) => {
224
+ console.error(chalk_1.default.red(data.toString().trim())); // Display error messages in red
225
+ });
226
+ installProcess.on("close", (code) => {
227
+ if (code === 0) {
228
+ console.log(chalk_1.default.bold.green("---------------------------------------"));
229
+ console.log(chalk_1.default.bold.green("Installation Done!"));
230
+ resolve("Installation Done!");
231
+ }
232
+ else {
233
+ console.error(chalk_1.default.bold.red("---------------------------------------"));
234
+ console.error(chalk_1.default.bold.red(`Command ${command} ${args.join(" ")} exited with code ${code}`));
235
+ reject(new Error(`Command ${command} ${args.join(" ")} exited with code ${code}`));
236
+ (0, node_process_1.exit)(1);
237
+ }
238
+ });
239
+ });
240
+ }
241
+ function prismaPackage(answer) {
242
+ // Get the absolute path of the input directory parameter
243
+ const absDirPath = node_path_1.default.resolve(process.cwd());
244
+ // Load the package.json file
245
+ const packageJsonPath = node_path_1.default.join(absDirPath, "package.json");
246
+ const fileContents = node_fs_1.default.readFileSync(packageJsonPath, "utf-8");
247
+ const packageJson = JSON.parse(fileContents);
248
+ // Add the Prisma configuration to the package.json
249
+ packageJson.prisma = {
250
+ schema: `${answer.schemaPath}/prisma/${answer.schemaName}.prisma`,
251
+ };
252
+ // Add the Prisma script to the package.json
253
+ packageJson.scripts = {
254
+ ...packageJson.scripts,
255
+ prisma: "npx @expressots/prisma codegen",
256
+ };
257
+ // Save the package.json file
258
+ node_fs_1.default.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2));
259
+ }
260
+ async function addProviderConfigInExpressotsConfig(schemaName, schemaPath) {
261
+ const absDirPath = node_path_1.default.resolve(process.cwd());
262
+ const expressotsConfigPath = node_path_1.default.join(absDirPath, "expressots.config.ts");
263
+ let fileContents = node_fs_1.default.readFileSync(expressotsConfigPath, "utf-8");
264
+ const config = await compiler_1.default.loadConfig();
263
265
  const providersObject = `opinionated: ${config.opinionated},\n\tproviders: {
264
266
  prisma: {
265
267
  schemaName: "${schemaName}",
@@ -267,11 +269,11 @@ async function addProviderConfigInExpressotsConfig(schemaName, schemaPath) {
267
269
  entitiesPath: "entities",
268
270
  entityNamePattern: "entity",
269
271
  },
270
- },`;
271
- if (config.providers) {
272
- // delete the providers object until the last closing curly brace
273
- fileContents = fileContents.replace(/\n([\s]*?)providers: {([\s\S]*?)};/, "\n};");
274
- }
275
- const newFileContents = fileContents.replace(/opinionated: (.*)/, providersObject);
276
- node_fs_1.default.writeFileSync(expressotsConfigPath, newFileContents);
277
- }
272
+ },`;
273
+ if (config.providers) {
274
+ // delete the providers object until the last closing curly brace
275
+ fileContents = fileContents.replace(/\n([\s]*?)providers: {([\s\S]*?)};/, "\n};");
276
+ }
277
+ const newFileContents = fileContents.replace(/opinionated: (.*)/, providersObject);
278
+ node_fs_1.default.writeFileSync(expressotsConfigPath, newFileContents);
279
+ }
package/bin/types.d.ts CHANGED
@@ -1 +1 @@
1
- export * from "./@types";
1
+ export * from "./@types";
package/bin/types.js CHANGED
@@ -1,17 +1,17 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./@types"), exports);
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./@types"), exports);
@@ -1 +1 @@
1
- export declare function addControllerToModule(filePath: string, controllerName: string, controllerPath: string): Promise<void>;
1
+ export declare function addControllerToModule(filePath: string, controllerName: string, controllerPath: string): Promise<void>;