@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.
- package/README.md +8 -0
- package/bin/@types/config.d.ts +39 -39
- package/bin/@types/config.js +2 -2
- package/bin/@types/index.d.ts +1 -1
- package/bin/@types/index.js +17 -17
- package/bin/app.container.d.ts +1 -1
- package/bin/app.container.js +8 -8
- package/bin/cli.d.ts +2 -2
- package/bin/cli.js +38 -38
- package/bin/commands/__tests__/project.commands.spec.d.ts +1 -0
- package/bin/commands/__tests__/project.commands.spec.js +8 -0
- package/bin/commands/project.commands.d.ts +8 -8
- package/bin/commands/project.commands.js +137 -136
- package/bin/generate/cli.d.ts +4 -4
- package/bin/generate/cli.js +66 -66
- package/bin/generate/form.d.ts +20 -20
- package/bin/generate/form.js +30 -30
- package/bin/generate/index.d.ts +1 -1
- package/bin/generate/index.js +17 -17
- package/bin/generate/utils/command-utils.d.ts +123 -123
- package/bin/generate/utils/command-utils.js +314 -310
- package/bin/generate/utils/nonopininated-cmd.d.ts +9 -9
- package/bin/generate/utils/nonopininated-cmd.js +248 -248
- package/bin/generate/utils/opinionated-cmd.d.ts +11 -11
- package/bin/generate/utils/opinionated-cmd.js +481 -480
- package/bin/help/cli.d.ts +4 -4
- package/bin/help/cli.js +15 -15
- package/bin/help/form.d.ts +2 -2
- package/bin/help/form.js +28 -28
- package/bin/help/index.d.ts +1 -1
- package/bin/help/index.js +17 -2
- package/bin/index.d.ts +6 -4
- package/bin/index.js +22 -20
- package/bin/info/cli.d.ts +4 -4
- package/bin/info/cli.js +15 -15
- package/bin/info/form.d.ts +2 -2
- package/bin/info/form.js +36 -36
- package/bin/info/index.d.ts +1 -1
- package/bin/info/index.js +17 -17
- package/bin/new/cli.d.ts +4 -4
- package/bin/new/cli.js +51 -51
- package/bin/new/form.d.ts +2 -2
- package/bin/new/form.js +235 -213
- package/bin/new/index.d.ts +1 -1
- package/bin/new/index.js +17 -17
- package/bin/providers/cli.d.ts +4 -4
- package/bin/providers/cli.js +43 -38
- package/bin/providers/external/external.provider.d.ts +2 -0
- package/bin/providers/external/external.provider.js +49 -0
- package/bin/providers/index.d.ts +1 -1
- package/bin/providers/index.js +17 -17
- package/bin/providers/prisma/prisma.provider.d.ts +2 -2
- package/bin/providers/prisma/prisma.provider.js +272 -270
- package/bin/types.d.ts +1 -1
- package/bin/types.js +17 -17
- package/bin/utils/add-controller-to-module.d.ts +1 -1
- package/bin/utils/add-controller-to-module.js +46 -46
- package/bin/utils/add-module-to-container.d.ts +3 -3
- package/bin/utils/add-module-to-container.js +129 -129
- package/bin/utils/center-text.d.ts +2 -2
- package/bin/utils/center-text.js +10 -10
- package/bin/utils/cli-ui.d.ts +3 -3
- package/bin/utils/cli-ui.js +19 -19
- package/bin/utils/compiler.d.ts +15 -15
- package/bin/utils/compiler.js +93 -93
- package/bin/utils/find-folder.d.ts +5 -5
- package/bin/utils/find-folder.js +37 -37
- package/bin/utils/index.d.ts +1 -1
- package/bin/utils/index.js +17 -17
- package/bin/utils/verify-file-exists.d.ts +2 -2
- package/bin/utils/verify-file-exists.js +30 -30
- 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
|
-
|
|
18
|
-
|
|
19
|
-
{ name: "
|
|
20
|
-
{ name: "
|
|
21
|
-
{ name: "
|
|
22
|
-
{ name: "
|
|
23
|
-
{ name: "
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
"
|
|
162
|
-
"
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
const
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
const
|
|
195
|
-
const
|
|
196
|
-
const
|
|
197
|
-
|
|
198
|
-
node_fs_1.default.writeFileSync(node_path_1.default.join(repositoryDir, "base-repository.
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
console.log("
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
const
|
|
215
|
-
const
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
});
|
|
219
|
-
console.log(chalk_1.default.
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
console.log(chalk_1.default.bold.green("
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
console.error(chalk_1.default.bold.red("
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
const
|
|
247
|
-
const
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
const
|
|
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>;
|