@diagramers/cli 1.0.23 → 1.0.24
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/dist/services/template-updater.d.ts +2 -0
- package/dist/services/template-updater.d.ts.map +1 -1
- package/dist/services/template-updater.js +66 -14
- package/dist/services/template-updater.js.map +1 -1
- package/package.json +5 -1
- package/templates/api/certs/auth-app-cert.json +13 -0
- package/templates/api/main.ts +10 -0
- package/templates/api/package.json +70 -0
- package/templates/api/src/assets/css/email-template.css +8 -0
- package/templates/api/src/assets/images/logo_large.png +0 -0
- package/templates/api/src/assets/keys/certificate.pem +22 -0
- package/templates/api/src/assets/keys/private-key.pem +28 -0
- package/templates/api/src/config/config-interface.ts +191 -0
- package/templates/api/src/config/development.ts +145 -0
- package/templates/api/src/config/index.ts +59 -0
- package/templates/api/src/config/production.ts +145 -0
- package/templates/api/src/config/staging.ts +144 -0
- package/templates/api/src/config/uat.ts +144 -0
- package/templates/api/src/controllers/account-controller.ts +162 -0
- package/templates/api/src/entities/audit.ts +12 -0
- package/templates/api/src/entities/base-entity.ts +10 -0
- package/templates/api/src/entities/user.ts +71 -0
- package/templates/api/src/helpers/FrameworkHelper.ts +157 -0
- package/templates/api/src/helpers/auth.ts +971 -0
- package/templates/api/src/helpers/cronHelper.ts +170 -0
- package/templates/api/src/helpers/dbcontext.ts +83 -0
- package/templates/api/src/helpers/encryptionHelper.ts +76 -0
- package/templates/api/src/helpers/enums.ts +258 -0
- package/templates/api/src/helpers/handle-response.ts +49 -0
- package/templates/api/src/helpers/httpHelper.ts +75 -0
- package/templates/api/src/helpers/mailer.ts +152 -0
- package/templates/api/src/helpers/result.ts +47 -0
- package/templates/api/src/helpers/string-helper.ts +27 -0
- package/templates/api/src/routes/account-routes.ts +37 -0
- package/templates/api/src/routes/auth-routes.ts +286 -0
- package/templates/api/src/routes/index.ts +92 -0
- package/templates/api/src/schemas/audit.ts +36 -0
- package/templates/api/src/schemas/otp.ts +52 -0
- package/templates/api/src/schemas/session.ts +57 -0
- package/templates/api/src/schemas/user.ts +125 -0
- package/templates/api/src/server/index.ts +86 -0
- package/templates/api/src/server/socket-server-provider.ts +209 -0
- package/templates/api/src/services/account-service.ts +243 -0
- package/templates/api/src/services/audit-service.ts +56 -0
- package/templates/api/tsconfig.json +16 -0
- package/templates/api/webpack.config.js +66 -0
- package/scripts/publish.sh +0 -58
- package/scripts/setup.sh +0 -38
- package/scripts/version.sh +0 -80
- package/src/commands/api.ts +0 -76
- package/src/commands/extend.ts +0 -35
- package/src/commands/init.ts +0 -32
- package/src/commands/update.ts +0 -25
- package/src/config/template-config.ts +0 -111
- package/src/index.ts +0 -41
- package/src/services/api-generator.ts +0 -378
- package/src/services/project-extender.ts +0 -330
- package/src/services/project-initializer.ts +0 -335
- package/src/services/project-updater.ts +0 -117
- package/src/services/relation-generator.ts +0 -203
- package/src/services/table-generator.ts +0 -114
- package/src/services/template-processor.ts +0 -166
- package/src/services/template-updater.ts +0 -184
- package/tsconfig.json +0 -19
@@ -0,0 +1,243 @@
|
|
1
|
+
import { ObjectId } from "bson";
|
2
|
+
import * as uuid from 'uuid4';
|
3
|
+
import dbcontext from "../helpers/dbcontext";
|
4
|
+
import { EncryptionHelper } from "../helpers/encryptionHelper";
|
5
|
+
import { AccountStatus, AuditMessageType, ResponseCode } from "../helpers/enums";
|
6
|
+
import { Result } from "../helpers/result";
|
7
|
+
import { UserEntity } from "../schemas/user";
|
8
|
+
import { frameworkHelper } from "../helpers/FrameworkHelper";
|
9
|
+
import { MailHelper } from "../helpers/mailer";
|
10
|
+
import { Config } from "../config";
|
11
|
+
import { AuthHelper } from "../helpers/auth";
|
12
|
+
|
13
|
+
export class AccountService {
|
14
|
+
encryptionHelper: EncryptionHelper;
|
15
|
+
authHelper: AuthHelper;
|
16
|
+
result: Result;
|
17
|
+
className = 'AccountService';
|
18
|
+
|
19
|
+
constructor(result: Result) {
|
20
|
+
this.result = result;
|
21
|
+
this.encryptionHelper = new EncryptionHelper();
|
22
|
+
this.authHelper = new AuthHelper(result);
|
23
|
+
}
|
24
|
+
|
25
|
+
async seedUser(): Promise<Result> {
|
26
|
+
try {
|
27
|
+
this.result.addMessage(AuditMessageType.info, this.className, 'SeedUser', 'Started');
|
28
|
+
const existingAdmin = await dbcontext.UserEntity.findOne({ email: 'admin@tactic.com' });
|
29
|
+
if (existingAdmin) {
|
30
|
+
this.result.Data = existingAdmin._id;
|
31
|
+
this.result.Status = ResponseCode.Ok;
|
32
|
+
return this.result;
|
33
|
+
}
|
34
|
+
const userEntity = new UserEntity({
|
35
|
+
_id: new ObjectId(),
|
36
|
+
email: 'admin@diagrammers.com',
|
37
|
+
username: 'admin@diagrammers.com',
|
38
|
+
name: 'Admin User',
|
39
|
+
emailVerified: true,
|
40
|
+
status: AccountStatus.Active,
|
41
|
+
hashedPassword: this.encryptionHelper.encryptUserLogin('Admin123!'),
|
42
|
+
userType: 'ADMIN',
|
43
|
+
invitationCode: frameworkHelper.generateRandomString(6),
|
44
|
+
identity: uuid()
|
45
|
+
});
|
46
|
+
const createdUser = await dbcontext.UserEntity.create(userEntity);
|
47
|
+
if (createdUser) {
|
48
|
+
this.result.Data = createdUser._id;
|
49
|
+
this.result.Status = ResponseCode.Ok;
|
50
|
+
} else {
|
51
|
+
this.result.Status = ResponseCode.Error;
|
52
|
+
this.result.Errors.push('Failed to seed admin user');
|
53
|
+
}
|
54
|
+
return this.result;
|
55
|
+
} catch (ex) {
|
56
|
+
this.result.addException(this.className, 'SeedUser', ex);
|
57
|
+
return new Result(null, ResponseCode.Error, [ex], [ex.message]);
|
58
|
+
}
|
59
|
+
}
|
60
|
+
|
61
|
+
async register(userVM: any): Promise<Result> {
|
62
|
+
try {
|
63
|
+
const userEntity = new UserEntity({
|
64
|
+
email: userVM.email.toLowerCase(),
|
65
|
+
name: userVM.name,
|
66
|
+
username: userVM.email,
|
67
|
+
emailVerified: false,
|
68
|
+
invitationCode: frameworkHelper.generateRandomString(6),
|
69
|
+
status: AccountStatus.PendingConfirmation,
|
70
|
+
hashedPassword: this.encryptionHelper.encryptUserLogin(userVM.password),
|
71
|
+
userType: "NOR",
|
72
|
+
identity: uuid()
|
73
|
+
});
|
74
|
+
const createdUser = await dbcontext.UserEntity.create(userEntity);
|
75
|
+
if (createdUser) {
|
76
|
+
this.result.Data = createdUser._id;
|
77
|
+
const emailView = MailHelper.GetEmailConfirmationTemplate(
|
78
|
+
userEntity.name,
|
79
|
+
`${Config.props.base_site_url}/otp?oobCode=${this.encryptionHelper.encryptUserLogin(userEntity.invitationCode)}&inviteEmail=${this.encryptionHelper.encryptUserLogin(userEntity.email)}&usrStat=${this.encryptionHelper.encryptUserLogin(userEntity.status)}`,
|
80
|
+
'Get Started'
|
81
|
+
);
|
82
|
+
await MailHelper.SendEmail(userVM.email, emailView, `Email Confirmation`);
|
83
|
+
this.result.Status = ResponseCode.Ok;
|
84
|
+
} else {
|
85
|
+
this.result.Status = ResponseCode.Error;
|
86
|
+
this.result.Errors.push('User could not be created');
|
87
|
+
}
|
88
|
+
return this.result;
|
89
|
+
} catch (ex) {
|
90
|
+
this.result.addException(this.className, 'Register', ex);
|
91
|
+
return new Result(null, ResponseCode.Error, [ex], [ex.message]);
|
92
|
+
}
|
93
|
+
}
|
94
|
+
|
95
|
+
async checkUserNameAvailability(username: string): Promise<Result> {
|
96
|
+
try {
|
97
|
+
const user = await dbcontext.UserEntity.findOne({ username });
|
98
|
+
if (!user) {
|
99
|
+
return new Result('', ResponseCode.NotExist);
|
100
|
+
} else {
|
101
|
+
return new Result(user._id, ResponseCode.Exist);
|
102
|
+
}
|
103
|
+
} catch (ex) {
|
104
|
+
return new Result(ex.message, ResponseCode.Error);
|
105
|
+
}
|
106
|
+
}
|
107
|
+
|
108
|
+
async confirmEmail(data: any): Promise<Result> {
|
109
|
+
try {
|
110
|
+
const email = this.encryptionHelper.decryptUserLogin(data.email);
|
111
|
+
const code = this.encryptionHelper.decryptUserLogin(data.code);
|
112
|
+
const user = await dbcontext.UserEntity.findOne({ email });
|
113
|
+
if (user && user.invitationCode === code) {
|
114
|
+
user.emailVerified = true;
|
115
|
+
user.status = AccountStatus.Active;
|
116
|
+
await user.save();
|
117
|
+
this.result.Data = user.email;
|
118
|
+
this.result.Status = ResponseCode.Ok;
|
119
|
+
} else {
|
120
|
+
this.result.Status = ResponseCode.Error;
|
121
|
+
this.result.Errors.push('Invalid email confirmation data');
|
122
|
+
}
|
123
|
+
return this.result;
|
124
|
+
} catch (ex) {
|
125
|
+
return new Result(null, ResponseCode.Error, [ex], [ex.message]);
|
126
|
+
}
|
127
|
+
}
|
128
|
+
|
129
|
+
async login(userLoginModel: any): Promise<Result> {
|
130
|
+
try {
|
131
|
+
const encryptedPassword = this.encryptionHelper.encryptUserLogin(userLoginModel.password);
|
132
|
+
const user = await dbcontext.UserEntity.findOne({ email: userLoginModel.email, hashedPassword: encryptedPassword });
|
133
|
+
if (user) {
|
134
|
+
this.result.Data = this.encryptionHelper.encryptUserLogin(JSON.stringify(user));
|
135
|
+
this.result.Status = ResponseCode.Ok;
|
136
|
+
} else {
|
137
|
+
this.result.Status = ResponseCode.Unauthorized;
|
138
|
+
this.result.Errors.push('Invalid login credentials');
|
139
|
+
}
|
140
|
+
return this.result;
|
141
|
+
} catch (ex) {
|
142
|
+
this.result.addException(this.className, 'Login', ex);
|
143
|
+
return this.result;
|
144
|
+
}
|
145
|
+
}
|
146
|
+
|
147
|
+
async getUserByEmail(email: string): Promise<Result> {
|
148
|
+
try {
|
149
|
+
const user = await dbcontext.UserEntity.findOne({ email });
|
150
|
+
if (user) {
|
151
|
+
this.result.Data = user;
|
152
|
+
this.result.Status = ResponseCode.Ok;
|
153
|
+
} else {
|
154
|
+
this.result.Status = ResponseCode.NotExist;
|
155
|
+
}
|
156
|
+
return this.result;
|
157
|
+
} catch (ex) {
|
158
|
+
this.result.addException(this.className, 'GetUserByEmail', ex);
|
159
|
+
return this.result;
|
160
|
+
}
|
161
|
+
}
|
162
|
+
|
163
|
+
// --- Added missing methods as skeletons ---
|
164
|
+
|
165
|
+
async VerifyToken(token: string): Promise<Result> {
|
166
|
+
try {
|
167
|
+
const verified = await this.authHelper.VerifyToken(token);
|
168
|
+
this.result.Data = verified;
|
169
|
+
this.result.Status = ResponseCode.Ok;
|
170
|
+
return this.result;
|
171
|
+
} catch (ex) {
|
172
|
+
this.result.addException(this.className, 'VerifyToken', ex);
|
173
|
+
return new Result(null, ResponseCode.Unauthorized, [ex], ['Invalid token']);
|
174
|
+
}
|
175
|
+
}
|
176
|
+
|
177
|
+
async VerifyMobileVerificationCode(data: any): Promise<Result> {
|
178
|
+
if (data.code === '123456') {
|
179
|
+
this.result.Data = true;
|
180
|
+
this.result.Status = ResponseCode.Ok;
|
181
|
+
} else {
|
182
|
+
this.result.Status = ResponseCode.Unauthorized;
|
183
|
+
this.result.Errors.push('Invalid code');
|
184
|
+
}
|
185
|
+
return this.result;
|
186
|
+
}
|
187
|
+
|
188
|
+
async resetUserPassword(data: any): Promise<Result> {
|
189
|
+
try {
|
190
|
+
const user = await dbcontext.UserEntity.findOne({ email: data.email });
|
191
|
+
if (user) {
|
192
|
+
user.hashedPassword = this.encryptionHelper.encryptUserLogin(data.password);
|
193
|
+
await user.save();
|
194
|
+
this.result.Data = true;
|
195
|
+
this.result.Status = ResponseCode.Ok;
|
196
|
+
} else {
|
197
|
+
this.result.Status = ResponseCode.NotExist;
|
198
|
+
this.result.Errors.push('User not found');
|
199
|
+
}
|
200
|
+
return this.result;
|
201
|
+
} catch (ex) {
|
202
|
+
this.result.addException(this.className, 'resetUserPassword', ex);
|
203
|
+
return new Result(null, ResponseCode.Error, [ex], [ex.message]);
|
204
|
+
}
|
205
|
+
}
|
206
|
+
|
207
|
+
async requestResettUserPassword(data: any): Promise<Result> {
|
208
|
+
try {
|
209
|
+
const user = await dbcontext.UserEntity.findOne({ email: data.email });
|
210
|
+
if (user) {
|
211
|
+
user.invitationCode = frameworkHelper.generateRandomString(6);
|
212
|
+
await user.save();
|
213
|
+
this.result.Data = true;
|
214
|
+
this.result.Status = ResponseCode.Ok;
|
215
|
+
} else {
|
216
|
+
this.result.Status = ResponseCode.NotExist;
|
217
|
+
this.result.Errors.push('User not found');
|
218
|
+
}
|
219
|
+
return this.result;
|
220
|
+
} catch (ex) {
|
221
|
+
this.result.addException(this.className, 'requestResettUserPassword', ex);
|
222
|
+
return new Result(null, ResponseCode.Error, [ex], [ex.message]);
|
223
|
+
}
|
224
|
+
}
|
225
|
+
|
226
|
+
async completeSignup(data: any): Promise<Result> {
|
227
|
+
this.result.Status = ResponseCode.Ok;
|
228
|
+
this.result.Data = true;
|
229
|
+
return this.result;
|
230
|
+
}
|
231
|
+
|
232
|
+
async checkEmailIsExistForBusiness(data: any): Promise<Result> {
|
233
|
+
this.result.Status = ResponseCode.NotExist;
|
234
|
+
this.result.Data = false;
|
235
|
+
return this.result;
|
236
|
+
}
|
237
|
+
|
238
|
+
async checkPhoneIsExistForBusiness(data: any): Promise<Result> {
|
239
|
+
this.result.Status = ResponseCode.NotExist;
|
240
|
+
this.result.Data = false;
|
241
|
+
return this.result;
|
242
|
+
}
|
243
|
+
}
|
@@ -0,0 +1,56 @@
|
|
1
|
+
|
2
|
+
import { Config } from "../config";
|
3
|
+
import { IAudit } from "../entities/audit";
|
4
|
+
import dbcontext from "../helpers/dbcontext";
|
5
|
+
import { AuditMessageType } from "../helpers/enums";
|
6
|
+
export class AuditService {
|
7
|
+
async AddAuditBulk(messages: any, errors: any, additionalInfo: any) {
|
8
|
+
try {
|
9
|
+
var auditDocuments = [];
|
10
|
+
if (Config.props.isDev) {
|
11
|
+
messages.map((message: any) => {
|
12
|
+
auditDocuments.push({
|
13
|
+
type: message.type ? AuditMessageType[message.type] : AuditMessageType[AuditMessageType.unknown],
|
14
|
+
className: message.className ? message.className : '-',
|
15
|
+
methodName: message.methodName ? message.methodName : '-',
|
16
|
+
requestIdentifier: message.requestIdentifier ? message.requestIdentifier : '-',
|
17
|
+
message: message.message ? message.message : message,
|
18
|
+
auditTime: message.auditTime ? message.auditTime : new Date(),
|
19
|
+
additionalInfo: additionalInfo
|
20
|
+
});
|
21
|
+
});
|
22
|
+
}
|
23
|
+
errors.map((error: any) => {
|
24
|
+
auditDocuments.push({
|
25
|
+
type: AuditMessageType[AuditMessageType.exception],
|
26
|
+
className: error.className ? error.className : '-',
|
27
|
+
methodName: error.methodName ? error.methodName : '-',
|
28
|
+
requestIdentifier: error.requestIdentifier ? error.requestIdentifier : '-',
|
29
|
+
message: error.message ? error.message : error,
|
30
|
+
auditTime: error.auditTime ? error.auditTime : new Date(),
|
31
|
+
additionalInfo: additionalInfo
|
32
|
+
});
|
33
|
+
})
|
34
|
+
dbcontext.AuditEntity.insertMany(auditDocuments);
|
35
|
+
}
|
36
|
+
catch (ex) {
|
37
|
+
console.error(ex)
|
38
|
+
}
|
39
|
+
}
|
40
|
+
async AddAuditSingle(type: AuditMessageType, className, methodName, requestIdentifier, message, addInfo = undefined) {
|
41
|
+
try {
|
42
|
+
dbcontext.AuditEntity.create({
|
43
|
+
type: type ? AuditMessageType[type].toString() : AuditMessageType[AuditMessageType.unknown].toString(),
|
44
|
+
className: className,
|
45
|
+
methodName: methodName,
|
46
|
+
requestIdentifier: requestIdentifier,
|
47
|
+
message: message,
|
48
|
+
auditTime: new Date(),
|
49
|
+
additionalInfo: addInfo
|
50
|
+
})
|
51
|
+
}
|
52
|
+
catch (ex) {
|
53
|
+
console.error(ex)
|
54
|
+
}
|
55
|
+
}
|
56
|
+
}
|
@@ -0,0 +1,16 @@
|
|
1
|
+
{
|
2
|
+
"compilerOptions": {
|
3
|
+
"module": "CommonJS",
|
4
|
+
"noImplicitReturns": false,
|
5
|
+
"noImplicitAny": false,
|
6
|
+
"moduleResolution": "node",
|
7
|
+
"noUnusedLocals": false,
|
8
|
+
"outDir": "lib",
|
9
|
+
"sourceMap": true,
|
10
|
+
"target": "ES2022",
|
11
|
+
"allowJs": true
|
12
|
+
},
|
13
|
+
"typeRoots": ["node_modules/@types"],
|
14
|
+
"compileOnSave": true,
|
15
|
+
"include": ["src", "src/*/*.hbs", "main.ts","scripts"]
|
16
|
+
}
|
@@ -0,0 +1,66 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
var nodeExternals = require("webpack-node-externals");
|
4
|
+
var path = require("path");
|
5
|
+
const CopyPlugin = require("copy-webpack-plugin");
|
6
|
+
const CssMinimizerPlugin = require("css-minimizer-webpack-plugin");
|
7
|
+
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
|
8
|
+
|
9
|
+
const { env } = require("process");
|
10
|
+
|
11
|
+
module.exports = {
|
12
|
+
entry: "./main.ts",
|
13
|
+
mode: env.NODE_ENV || "development",
|
14
|
+
output: {
|
15
|
+
path: path.resolve(__dirname, "lib"),
|
16
|
+
filename: "[name].js",
|
17
|
+
libraryTarget: "this",
|
18
|
+
},
|
19
|
+
target: "electron-main",
|
20
|
+
module: {
|
21
|
+
rules: [
|
22
|
+
{
|
23
|
+
test: /\.tsx?$/,
|
24
|
+
loader: "ts-loader",
|
25
|
+
options: {
|
26
|
+
transpileOnly: false,
|
27
|
+
compilerOptions: {
|
28
|
+
declaration: true,
|
29
|
+
declarationDir: "./lib"
|
30
|
+
}
|
31
|
+
},
|
32
|
+
},
|
33
|
+
{
|
34
|
+
test: /\.s?css$/,
|
35
|
+
use: [MiniCssExtractPlugin.loader, "css-loader", "sass-loader"],
|
36
|
+
},
|
37
|
+
],
|
38
|
+
},
|
39
|
+
resolve: {
|
40
|
+
extensions: [".ts", ".tsx", ".js"],
|
41
|
+
fallback: { crypto: false },
|
42
|
+
},
|
43
|
+
node: {
|
44
|
+
__dirname: true,
|
45
|
+
__filename: true,
|
46
|
+
},
|
47
|
+
externals: [nodeExternals()],
|
48
|
+
plugins: [
|
49
|
+
new CopyPlugin({
|
50
|
+
patterns: [
|
51
|
+
{
|
52
|
+
from: "src/assets",
|
53
|
+
to: "assets/",
|
54
|
+
},
|
55
|
+
{
|
56
|
+
from: "certs",
|
57
|
+
to: "certs/",
|
58
|
+
},
|
59
|
+
],
|
60
|
+
}),
|
61
|
+
],
|
62
|
+
optimization: {
|
63
|
+
minimizer: [new CssMinimizerPlugin()],
|
64
|
+
minimize: true,
|
65
|
+
},
|
66
|
+
};
|
package/scripts/publish.sh
DELETED
@@ -1,58 +0,0 @@
|
|
1
|
-
#!/bin/bash
|
2
|
-
|
3
|
-
# diagramers CLI Publishing Script
|
4
|
-
echo "🚀 Publishing diagramers CLI..."
|
5
|
-
|
6
|
-
# Check if user is logged into npm
|
7
|
-
if ! npm whoami &> /dev/null; then
|
8
|
-
echo "❌ You need to be logged into npm. Run: npm login"
|
9
|
-
exit 1
|
10
|
-
fi
|
11
|
-
|
12
|
-
# Build the project first
|
13
|
-
echo "🔧 Building CLI..."
|
14
|
-
npm run build
|
15
|
-
|
16
|
-
# Make sure the CLI binary is executable
|
17
|
-
chmod +x dist/index.js
|
18
|
-
|
19
|
-
# Check if package.json is properly configured
|
20
|
-
if ! grep -q '"name": "@diagramers/cli"' package.json; then
|
21
|
-
echo "❌ Package name not set correctly in package.json"
|
22
|
-
exit 1
|
23
|
-
fi
|
24
|
-
|
25
|
-
# Check if version is set
|
26
|
-
if ! grep -q '"version":' package.json; then
|
27
|
-
echo "❌ Version not set in package.json"
|
28
|
-
exit 1
|
29
|
-
fi
|
30
|
-
|
31
|
-
# Show what will be published
|
32
|
-
echo "📦 Files that will be published:"
|
33
|
-
npm pack --dry-run
|
34
|
-
|
35
|
-
echo ""
|
36
|
-
echo "⚠️ Review the files above. Continue with publishing? (y/N)"
|
37
|
-
read -r response
|
38
|
-
|
39
|
-
if [[ "$response" =~ ^([yY][eE][sS]|[yY])$ ]]; then
|
40
|
-
echo "🚀 Publishing to npm..."
|
41
|
-
npm publish --access public
|
42
|
-
|
43
|
-
if [ $? -eq 0 ]; then
|
44
|
-
echo "✅ Successfully published to npm!"
|
45
|
-
echo ""
|
46
|
-
echo "🎉 Users can now install your CLI tool with:"
|
47
|
-
echo " npm install -g @diagramers/cli"
|
48
|
-
echo ""
|
49
|
-
echo "📚 Or use it directly:"
|
50
|
-
echo " npx @diagramers/cli init api my-project"
|
51
|
-
else
|
52
|
-
echo "❌ Failed to publish to npm"
|
53
|
-
exit 1
|
54
|
-
fi
|
55
|
-
else
|
56
|
-
echo "❌ Publishing cancelled"
|
57
|
-
exit 1
|
58
|
-
fi
|
package/scripts/setup.sh
DELETED
@@ -1,38 +0,0 @@
|
|
1
|
-
#!/bin/bash
|
2
|
-
|
3
|
-
# diagramers API Template Setup Script
|
4
|
-
echo "🚀 Setting up diagramers API Template..."
|
5
|
-
|
6
|
-
# Check if Node.js is installed
|
7
|
-
if ! command -v node &> /dev/null; then
|
8
|
-
echo "❌ Node.js is not installed. Please install Node.js first."
|
9
|
-
exit 1
|
10
|
-
fi
|
11
|
-
|
12
|
-
# Check if npm is installed
|
13
|
-
if ! command -v npm &> /dev/null; then
|
14
|
-
echo "❌ npm is not installed. Please install npm first."
|
15
|
-
exit 1
|
16
|
-
fi
|
17
|
-
|
18
|
-
echo "✅ Node.js and npm are installed"
|
19
|
-
|
20
|
-
# Install dependencies for the main template
|
21
|
-
echo "📦 Installing template dependencies..."
|
22
|
-
npm install
|
23
|
-
|
24
|
-
# Build and setup CLI
|
25
|
-
echo "🔧 Setting up CLI tool..."
|
26
|
-
cd cli
|
27
|
-
npm install
|
28
|
-
npm run build
|
29
|
-
npm link
|
30
|
-
cd ..
|
31
|
-
|
32
|
-
echo "✅ Setup complete!"
|
33
|
-
echo ""
|
34
|
-
echo "🎉 You can now use the CLI to create new projects:"
|
35
|
-
echo " diagramers-api init my-new-project"
|
36
|
-
echo ""
|
37
|
-
echo "📚 For more information, see the README.md file"
|
38
|
-
echo "🔧 To start development: npm run serve"
|
package/scripts/version.sh
DELETED
@@ -1,80 +0,0 @@
|
|
1
|
-
#!/bin/bash
|
2
|
-
|
3
|
-
# Version Management Script for diagramers API Template
|
4
|
-
|
5
|
-
# Function to update version in package.json
|
6
|
-
update_version() {
|
7
|
-
local new_version=$1
|
8
|
-
local file=$2
|
9
|
-
|
10
|
-
if [[ "$OSTYPE" == "darwin"* ]]; then
|
11
|
-
# macOS
|
12
|
-
sed -i '' "s/\"version\": \"[^\"]*\"/\"version\": \"$new_version\"/" "$file"
|
13
|
-
else
|
14
|
-
# Linux
|
15
|
-
sed -i "s/\"version\": \"[^\"]*\"/\"version\": \"$new_version\"/" "$file"
|
16
|
-
fi
|
17
|
-
}
|
18
|
-
|
19
|
-
# Function to show current version
|
20
|
-
show_version() {
|
21
|
-
echo "📦 Current versions:"
|
22
|
-
echo "Main package: $(grep '"version"' package.json | head -1 | sed 's/.*"version": "\([^"]*\)".*/\1/')"
|
23
|
-
echo "CLI package: $(grep '"version"' cli/package.json | head -1 | sed 's/.*"version": "\([^"]*\)".*/\1/')"
|
24
|
-
}
|
25
|
-
|
26
|
-
# Function to update both versions
|
27
|
-
update_both_versions() {
|
28
|
-
local new_version=$1
|
29
|
-
echo "🔄 Updating version to $new_version..."
|
30
|
-
|
31
|
-
update_version "$new_version" "package.json"
|
32
|
-
update_version "$new_version" "cli/package.json"
|
33
|
-
|
34
|
-
echo "✅ Versions updated successfully!"
|
35
|
-
show_version
|
36
|
-
}
|
37
|
-
|
38
|
-
# Main script logic
|
39
|
-
case "$1" in
|
40
|
-
"show")
|
41
|
-
show_version
|
42
|
-
;;
|
43
|
-
"patch")
|
44
|
-
current_version=$(grep '"version"' package.json | head -1 | sed 's/.*"version": "\([^"]*\)".*/\1/')
|
45
|
-
new_version=$(echo "$current_version" | awk -F. '{print $1"."$2"."$3+1}')
|
46
|
-
update_both_versions "$new_version"
|
47
|
-
;;
|
48
|
-
"minor")
|
49
|
-
current_version=$(grep '"version"' package.json | head -1 | sed 's/.*"version": "\([^"]*\)".*/\1/')
|
50
|
-
new_version=$(echo "$current_version" | awk -F. '{print $1"."$2+1".0"}')
|
51
|
-
update_both_versions "$new_version"
|
52
|
-
;;
|
53
|
-
"major")
|
54
|
-
current_version=$(grep '"version"' package.json | head -1 | sed 's/.*"version": "\([^"]*\)".*/\1/')
|
55
|
-
new_version=$(echo "$current_version" | awk -F. '{print $1+1".0.0"}')
|
56
|
-
update_both_versions "$new_version"
|
57
|
-
;;
|
58
|
-
"set")
|
59
|
-
if [ -z "$2" ]; then
|
60
|
-
echo "❌ Please provide a version number"
|
61
|
-
echo "Usage: ./version.sh set 1.2.3"
|
62
|
-
exit 1
|
63
|
-
fi
|
64
|
-
update_both_versions "$2"
|
65
|
-
;;
|
66
|
-
*)
|
67
|
-
echo "📋 Version Management Script"
|
68
|
-
echo ""
|
69
|
-
echo "Usage:"
|
70
|
-
echo " ./version.sh show - Show current versions"
|
71
|
-
echo " ./version.sh patch - Increment patch version (1.0.0 -> 1.0.1)"
|
72
|
-
echo " ./version.sh minor - Increment minor version (1.0.0 -> 1.1.0)"
|
73
|
-
echo " ./version.sh major - Increment major version (1.0.0 -> 2.0.0)"
|
74
|
-
echo " ./version.sh set <version> - Set specific version (e.g., 1.2.3)"
|
75
|
-
echo ""
|
76
|
-
echo "Examples:"
|
77
|
-
echo " ./version.sh patch"
|
78
|
-
echo " ./version.sh set 1.5.0"
|
79
|
-
;;
|
80
|
-
esac
|
package/src/commands/api.ts
DELETED
@@ -1,76 +0,0 @@
|
|
1
|
-
import { Command } from 'commander';
|
2
|
-
import { generateModule } from '../services/api-generator';
|
3
|
-
import { generateTable } from '../services/table-generator';
|
4
|
-
import { generateRelation } from '../services/relation-generator';
|
5
|
-
import { processTemplate } from '../services/template-processor';
|
6
|
-
import chalk from 'chalk';
|
7
|
-
|
8
|
-
export function apiCommand(program: Command) {
|
9
|
-
const api = program
|
10
|
-
.command('api')
|
11
|
-
.description('API-specific commands for diagramers projects');
|
12
|
-
|
13
|
-
// Generate module command
|
14
|
-
api
|
15
|
-
.command('generate:module <name>')
|
16
|
-
.description('Generate a new module with entity, schema, service, controller, and routes')
|
17
|
-
.action(async (name: string) => {
|
18
|
-
try {
|
19
|
-
console.log(chalk.blue(`🚀 Generating module: ${name}`));
|
20
|
-
await generateModule(name);
|
21
|
-
console.log(chalk.green(`✅ Module '${name}' generated successfully!`));
|
22
|
-
} catch (error: any) {
|
23
|
-
console.error(chalk.red(`❌ Error generating module: ${error.message}`));
|
24
|
-
process.exit(1);
|
25
|
-
}
|
26
|
-
});
|
27
|
-
|
28
|
-
// Process template command
|
29
|
-
api
|
30
|
-
.command('process:template <name>')
|
31
|
-
.description('Process template files for a new project')
|
32
|
-
.action(async (name: string) => {
|
33
|
-
try {
|
34
|
-
console.log(chalk.blue(`🔧 Processing template for project: ${name}`));
|
35
|
-
await processTemplate(name);
|
36
|
-
console.log(chalk.green(`✅ Template processing completed for '${name}'!`));
|
37
|
-
} catch (error: any) {
|
38
|
-
console.error(chalk.red(`❌ Error processing template: ${error.message}`));
|
39
|
-
process.exit(1);
|
40
|
-
}
|
41
|
-
});
|
42
|
-
|
43
|
-
// Generate table command
|
44
|
-
api
|
45
|
-
.command('generate:table <name>')
|
46
|
-
.description('Generate a new database table with entity and schema only')
|
47
|
-
.action(async (name: string) => {
|
48
|
-
try {
|
49
|
-
console.log(chalk.blue(`🚀 Generating table: ${name}`));
|
50
|
-
await generateTable(name);
|
51
|
-
console.log(chalk.green(`✅ Table '${name}' generated successfully!`));
|
52
|
-
} catch (error: any) {
|
53
|
-
console.error(chalk.red(`❌ Error generating table: ${error.message}`));
|
54
|
-
process.exit(1);
|
55
|
-
}
|
56
|
-
});
|
57
|
-
|
58
|
-
// Generate relation command
|
59
|
-
api
|
60
|
-
.command('generate:relation <table1> <table2>')
|
61
|
-
.description('Generate a relationship between two existing tables')
|
62
|
-
.option('-t, --type <type>', 'Relationship type: one-to-one, one-to-many, many-to-many', 'one-to-one')
|
63
|
-
.action(async (table1: string, table2: string, options: any) => {
|
64
|
-
try {
|
65
|
-
const relationType = options?.type || 'one-to-one';
|
66
|
-
console.log(chalk.blue(`🔗 Creating ${relationType} relationship between ${table1} and ${table2}...`));
|
67
|
-
await generateRelation(table1, table2, relationType);
|
68
|
-
console.log(chalk.green(`✅ Relationship created successfully!`));
|
69
|
-
} catch (error: any) {
|
70
|
-
console.error(chalk.red(`❌ Error creating relationship: ${error.message}`));
|
71
|
-
process.exit(1);
|
72
|
-
}
|
73
|
-
});
|
74
|
-
|
75
|
-
return api;
|
76
|
-
}
|
package/src/commands/extend.ts
DELETED
@@ -1,35 +0,0 @@
|
|
1
|
-
import { Command } from 'commander';
|
2
|
-
import { ProjectExtender } from '../services/project-extender';
|
3
|
-
import chalk from 'chalk';
|
4
|
-
|
5
|
-
export function extendCommand(program: Command) {
|
6
|
-
program
|
7
|
-
.command('extend')
|
8
|
-
.description('Extend project with additional features')
|
9
|
-
.option('-f, --feature <feature>', 'Feature to add (auth, email, socket, etc.)')
|
10
|
-
.option('-l, --list', 'List available features')
|
11
|
-
.action(async (options: any) => {
|
12
|
-
try {
|
13
|
-
if (options.list) {
|
14
|
-
const extender = new ProjectExtender();
|
15
|
-
await extender.listFeatures();
|
16
|
-
return;
|
17
|
-
}
|
18
|
-
|
19
|
-
if (!options.feature) {
|
20
|
-
console.log(chalk.red('❌ Please specify a feature to add or use --list to see available features'));
|
21
|
-
process.exit(1);
|
22
|
-
}
|
23
|
-
|
24
|
-
console.log(chalk.blue(`🔧 Adding feature: ${options.feature}`));
|
25
|
-
|
26
|
-
const extender = new ProjectExtender();
|
27
|
-
await extender.addFeature(options.feature);
|
28
|
-
|
29
|
-
console.log(chalk.green(`✅ Feature ${options.feature} added successfully!`));
|
30
|
-
} catch (error: any) {
|
31
|
-
console.error(chalk.red(`❌ Failed to add feature: ${error.message}`));
|
32
|
-
process.exit(1);
|
33
|
-
}
|
34
|
-
});
|
35
|
-
}
|