bmd-extension 1.6.3
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/.vscode/launch.json +14 -0
- package/.vscode/settings.json +1 -0
- package/CHANGELOG.md +9 -0
- package/DEPLOY.md +4 -0
- package/README.md +17 -0
- package/README_PRIVATE.md +1 -0
- package/build.sh +5 -0
- package/logo.png +0 -0
- package/media/dark/add.svg +40 -0
- package/media/dark/block.svg +1 -0
- package/media/dark/checklist-1.svg +1 -0
- package/media/dark/checklist.svg +1 -0
- package/media/dark/control.svg +1 -0
- package/media/dark/create.svg +1 -0
- package/media/dark/delete-1.svg +1 -0
- package/media/dark/delete.svg +1 -0
- package/media/dark/deploy-1.svg +2 -0
- package/media/dark/deploy.svg +2 -0
- package/media/dark/documents.svg +66 -0
- package/media/dark/earth.svg +68 -0
- package/media/dark/exe.svg +15 -0
- package/media/dark/export.svg +1 -0
- package/media/dark/function.svg +1 -0
- package/media/dark/game-controller.svg +77 -0
- package/media/dark/get.svg +1 -0
- package/media/dark/id-card.svg +59 -0
- package/media/dark/identity.svg +81 -0
- package/media/dark/import.svg +1 -0
- package/media/dark/information.svg +1 -0
- package/media/dark/interface.svg +1 -0
- package/media/dark/layout.svg +41 -0
- package/media/dark/leaf.svg +54 -0
- package/media/dark/list.svg +13 -0
- package/media/dark/logo.svg +249 -0
- package/media/dark/mockup.svg +1 -0
- package/media/dark/needle.svg +1 -0
- package/media/dark/pass.svg +46 -0
- package/media/dark/plus.svg +1 -0
- package/media/dark/post.svg +1 -0
- package/media/dark/quit.svg +1 -0
- package/media/dark/rocket.svg +28 -0
- package/media/dark/service.svg +1 -0
- package/media/dark/settings.svg +98 -0
- package/media/dark/social.svg +1 -0
- package/media/dark/spaceship-1.svg +1 -0
- package/media/dark/spaceship-2.svg +1 -0
- package/media/dark/spaceship.svg +1 -0
- package/media/dark/support.svg +88 -0
- package/media/dark/transfer.svg +1 -0
- package/media/dark/transform.svg +92 -0
- package/media/dark/update.svg +45 -0
- package/media/dark/upload-1.svg +1 -0
- package/media/dark/upload.svg +41 -0
- package/media/dark/vaccine.svg +1 -0
- package/media/dark/vr-gaming.svg +1 -0
- package/media/light/add.svg +40 -0
- package/media/light/block.svg +1 -0
- package/media/light/checklist-1.svg +1 -0
- package/media/light/checklist.svg +1 -0
- package/media/light/control.svg +1 -0
- package/media/light/create.svg +1 -0
- package/media/light/delete-1.svg +1 -0
- package/media/light/delete.svg +1 -0
- package/media/light/deploy-1.svg +2 -0
- package/media/light/deploy.svg +2 -0
- package/media/light/documents.svg +66 -0
- package/media/light/earth.svg +68 -0
- package/media/light/exe.svg +15 -0
- package/media/light/export.svg +1 -0
- package/media/light/function.svg +1 -0
- package/media/light/game-controller.svg +77 -0
- package/media/light/get.svg +1 -0
- package/media/light/id-card.svg +59 -0
- package/media/light/identity.svg +81 -0
- package/media/light/import.svg +1 -0
- package/media/light/information.svg +1 -0
- package/media/light/interface.svg +1 -0
- package/media/light/layout.svg +41 -0
- package/media/light/leaf.svg +54 -0
- package/media/light/list.svg +13 -0
- package/media/light/logo.svg +249 -0
- package/media/light/mockup.svg +1 -0
- package/media/light/needle.svg +1 -0
- package/media/light/pass.svg +46 -0
- package/media/light/plus.svg +1 -0
- package/media/light/post.svg +1 -0
- package/media/light/quit.svg +1 -0
- package/media/light/rocket.svg +28 -0
- package/media/light/service.svg +1 -0
- package/media/light/settings.svg +98 -0
- package/media/light/social.svg +1 -0
- package/media/light/spaceship-1.svg +1 -0
- package/media/light/spaceship-2.svg +1 -0
- package/media/light/spaceship.svg +1 -0
- package/media/light/support.svg +88 -0
- package/media/light/transfer.svg +1 -0
- package/media/light/transform.svg +92 -0
- package/media/light/update.svg +45 -0
- package/media/light/upload-1.svg +1 -0
- package/media/light/upload.svg +41 -0
- package/media/light/vaccine.svg +1 -0
- package/media/light/vr-gaming.svg +1 -0
- package/package-lock.json +6430 -0
- package/package.json +540 -0
- package/snippets-tsr.json +512 -0
- package/snippets.json +761 -0
- package/src/API.ts +14 -0
- package/src/FsProvider.ts +105 -0
- package/src/Request.ts +24 -0
- package/src/assets/api/api.txt +27 -0
- package/src/assets/configuration/AdminConfigurationController.ts.txt +72 -0
- package/src/assets/configuration/Configuration.ts.txt +37 -0
- package/src/assets/configuration/ConfigurationService.ts.txt +26 -0
- package/src/assets/contentDefine/AdminContentDefineController.ts.txt +91 -0
- package/src/assets/contentDefine/ContentDefine.ts.txt +45 -0
- package/src/assets/contentDefine/ContentDefineService.ts.txt +19 -0
- package/src/assets/contentDefine/CustomerContentDefineController.ts.txt +34 -0
- package/src/assets/controller/controller.txt +46 -0
- package/src/assets/controller/controllerResource.txt +103 -0
- package/src/assets/entity/entity.txt +22 -0
- package/src/assets/entity-request/entity-request.txt +18 -0
- package/src/assets/init/.env.example.txt +37 -0
- package/src/assets/init/.env.production.txt +37 -0
- package/src/assets/init/.gitignore.txt +8 -0
- package/src/assets/init/config.ts.txt +55 -0
- package/src/assets/init/deploy.sh.txt +46 -0
- package/src/assets/init/package-lock.json.txt +4184 -0
- package/src/assets/init/package.json.txt +79 -0
- package/src/assets/init/src/Server.ts.txt +167 -0
- package/src/assets/init/src/controllers/admin/AuthController.ts.txt +96 -0
- package/src/assets/init/src/controllers/admin/CustomerController.ts.txt +107 -0
- package/src/assets/init/src/controllers/admin/RoleController.ts.txt +143 -0
- package/src/assets/init/src/controllers/admin/StaffController.ts.txt +192 -0
- package/src/assets/init/src/controllers/customer/AuthController.ts.txt +170 -0
- package/src/assets/init/src/controllers/customer/CustomerController.ts.txt +32 -0
- package/src/assets/init/src/core/entity/CoreEntity.ts.txt +70 -0
- package/src/assets/init/src/core/services/CoreService.ts.txt +21 -0
- package/src/assets/init/src/entity/Customer.ts.txt +68 -0
- package/src/assets/init/src/entity/Permission.ts.txt +29 -0
- package/src/assets/init/src/entity/Role.ts.txt +36 -0
- package/src/assets/init/src/entity/Staff.ts.txt +54 -0
- package/src/assets/init/src/entity-request/CustomerInsert.ts.txt +42 -0
- package/src/assets/init/src/entity-request/CustomerUpdate.ts.txt +40 -0
- package/src/assets/init/src/entity-request/PermissionImport.ts.txt +12 -0
- package/src/assets/init/src/entity-request/StaffUpdate.ts.txt +33 -0
- package/src/assets/init/src/index.ts.txt +13 -0
- package/src/assets/init/src/middleware/auth/Verification.ts.txt +16 -0
- package/src/assets/init/src/middleware/auth/VerificationJWT.ts.txt +16 -0
- package/src/assets/init/src/middleware/auth/strategy/AuthStrategy.ts.txt +5 -0
- package/src/assets/init/src/middleware/auth/strategy/JWT.ts.txt +147 -0
- package/src/assets/init/src/middleware/error/handleError.ts.txt +22 -0
- package/src/assets/init/src/middleware/error/handleNotFound.ts.txt +7 -0
- package/src/assets/init/src/middleware/response/CustomSendResponse.ts.txt +35 -0
- package/src/assets/init/src/middleware/response/responseAPI.ts.txt +76 -0
- package/src/assets/init/src/middleware/validator/Validator.ts.txt +103 -0
- package/src/assets/init/src/services/CustomerService.ts.txt +79 -0
- package/src/assets/init/src/services/InitService.ts.txt +11 -0
- package/src/assets/init/src/services/MailService.ts.txt +271 -0
- package/src/assets/init/src/services/RoleService.ts.txt +66 -0
- package/src/assets/init/src/services/StaffService.ts.txt +104 -0
- package/src/assets/init/src/ssl/certificate-ca.crt +0 -0
- package/src/assets/init/src/ssl/certificate.crt +0 -0
- package/src/assets/init/src/ssl/private.key +0 -0
- package/src/assets/init/src/types/express.d.ts.txt +97 -0
- package/src/assets/init/src/util/expo.ts.txt +53 -0
- package/src/assets/init/src/util/helper.ts.txt +321 -0
- package/src/assets/init/src/util/language.ts.txt +8 -0
- package/src/assets/init/src/util/logger.ts.txt +47 -0
- package/src/assets/init/src/util/mailer.ts.txt +32 -0
- package/src/assets/init/src/util/password.ts.txt +13 -0
- package/src/assets/init/tsconfig.json.txt +26 -0
- package/src/assets/service/service.txt +34 -0
- package/src/constant.ts +83 -0
- package/src/extension.ts +459 -0
- package/src/provider/codeAction/controller/addPathParams.ts +65 -0
- package/src/provider/codeAction/controller/addTokenParam.ts +43 -0
- package/src/provider/codeAction/controller/addValidation.ts +47 -0
- package/src/provider/codeAction/controller/codeAction.ts +34 -0
- package/src/provider/codeAction/controller/util.ts +48 -0
- package/src/provider/codeAction/entity/codeAction.ts +48 -0
- package/src/provider/codeAction/entity/handleBuilder.ts +87 -0
- package/src/provider/codeAction/entity/handleFunction.ts +487 -0
- package/src/provider/codeAction/entity/handleProperty.ts +32 -0
- package/src/provider/codeAction/entity/handleRelation.ts +72 -0
- package/src/provider/codeAction/entity/helper.ts +132 -0
- package/src/provider/codeAction/entity-request/codeAction.ts +178 -0
- package/src/provider/codeAction/enum/codeAction.ts +95 -0
- package/src/provider/codeAction/service/codeAction.ts +232 -0
- package/src/provider/completion/CompletionProvider.ts +108 -0
- package/src/provider/errorChecking/checkHeaderToken.ts +60 -0
- package/src/provider/errorChecking/checkPathParam.ts +64 -0
- package/src/provider/errorChecking/checkRequired.ts +56 -0
- package/src/provider/errorChecking/errorChecking.ts +35 -0
- package/src/provider/errorChecking/util.ts +56 -0
- package/src/provider/treeDataProvider/Dependency.ts +26 -0
- package/src/provider/treeDataProvider/TreeProviderCommand.ts +60 -0
- package/src/provider/treeDataProvider/TreeProviderProject.ts +65 -0
- package/src/provider/treeDataProvider/api/createApi.ts +106 -0
- package/src/provider/treeDataProvider/controller/command/createController.ts +99 -0
- package/src/provider/treeDataProvider/controller/command/handleMethod.ts +363 -0
- package/src/provider/treeDataProvider/controller/treeData.ts +81 -0
- package/src/provider/treeDataProvider/deploy/command/handleDeploy.ts +70 -0
- package/src/provider/treeDataProvider/deploy/treeData.ts +21 -0
- package/src/provider/treeDataProvider/entity/command/addProperty.ts +144 -0
- package/src/provider/treeDataProvider/entity/command/addRelation.ts +125 -0
- package/src/provider/treeDataProvider/entity/command/createEntity.ts +53 -0
- package/src/provider/treeDataProvider/entity/command/createEntityRequest.ts +65 -0
- package/src/provider/treeDataProvider/entity/command/exportInterface.ts +130 -0
- package/src/provider/treeDataProvider/entity/treeData.ts +49 -0
- package/src/provider/treeDataProvider/module/command/configuration.ts +34 -0
- package/src/provider/treeDataProvider/module/command/contentDefine.ts +36 -0
- package/src/provider/treeDataProvider/module/command/initProject.ts +155 -0
- package/src/provider/treeDataProvider/module/treeData.ts +28 -0
- package/src/provider/treeDataProvider/project/command/addEnum.ts +0 -0
- package/src/provider/treeDataProvider/project/command/addProjectName.ts +23 -0
- package/src/provider/treeDataProvider/project/command/getProjectDetails.ts +284 -0
- package/src/provider/treeDataProvider/project/treeData.ts +28 -0
- package/src/provider/treeDataProvider/service/command/createService.ts +70 -0
- package/src/provider/treeDataProvider/service/command/handleConstructor.ts +134 -0
- package/src/provider/treeDataProvider/service/treeData.ts +25 -0
- package/src/types/project.d.ts +7 -0
- package/src/util.ts +145 -0
- package/src/utils/Password.ts +19 -0
- package/tsconfig.json +18 -0
- package/tslint.json +15 -0
- package/vsc-extension-quickstart.md +42 -0
@@ -0,0 +1,81 @@
|
|
1
|
+
import * as vscode from 'vscode';
|
2
|
+
import { ItemCommand } from "../TreeProviderCommand";
|
3
|
+
import { BMDCommand, ControllerAction } from "../../../constant";
|
4
|
+
import { Dependency } from "../Dependency";
|
5
|
+
|
6
|
+
const controllerCommands: ItemCommand[] = [
|
7
|
+
{
|
8
|
+
id: BMDCommand.CreateController,
|
9
|
+
title: 'CONTROLLER',
|
10
|
+
icon: 'add'
|
11
|
+
}, {
|
12
|
+
id: BMDCommand.CreateControllerResource,
|
13
|
+
title: 'CONTROLLER RESOURCE',
|
14
|
+
icon: 'add'
|
15
|
+
},
|
16
|
+
{
|
17
|
+
id: ControllerAction.Get,
|
18
|
+
title: 'GET',
|
19
|
+
icon: 'get'
|
20
|
+
},
|
21
|
+
{
|
22
|
+
id: ControllerAction.Post,
|
23
|
+
title: 'POST',
|
24
|
+
icon: 'post'
|
25
|
+
},
|
26
|
+
{
|
27
|
+
id: ControllerAction.GetListAll,
|
28
|
+
title: 'GET (ALL)',
|
29
|
+
icon: 'list'
|
30
|
+
},
|
31
|
+
{
|
32
|
+
id: ControllerAction.GetListPagination,
|
33
|
+
title: 'GET (PAGINATION)',
|
34
|
+
icon: 'list'
|
35
|
+
},
|
36
|
+
{
|
37
|
+
id: ControllerAction.CreateItem,
|
38
|
+
title: 'CREATE (ENTITY)',
|
39
|
+
icon: 'create'
|
40
|
+
},
|
41
|
+
{
|
42
|
+
id: ControllerAction.CreateItemEntityRequest,
|
43
|
+
title: 'CREATE (ENTITY REQUEST)',
|
44
|
+
icon: 'create'
|
45
|
+
},
|
46
|
+
{
|
47
|
+
id: ControllerAction.UpdateItem,
|
48
|
+
title: 'UPDATE',
|
49
|
+
icon: 'update'
|
50
|
+
},
|
51
|
+
{
|
52
|
+
id: ControllerAction.DeleteItemByBlock,
|
53
|
+
title: 'DELETE (BLOCK)',
|
54
|
+
icon: 'quit'
|
55
|
+
},
|
56
|
+
{
|
57
|
+
id: ControllerAction.DeleteItemByRemove,
|
58
|
+
title: 'DELETE (REMOVE)',
|
59
|
+
icon: 'quit'
|
60
|
+
},
|
61
|
+
{
|
62
|
+
id: ControllerAction.Upload,
|
63
|
+
title: 'UPLOAD (NORMAL)',
|
64
|
+
icon: 'upload'
|
65
|
+
},
|
66
|
+
{
|
67
|
+
id: ControllerAction.UploadResize,
|
68
|
+
title: 'UPLOAD (RESIZE)',
|
69
|
+
icon: 'upload'
|
70
|
+
},
|
71
|
+
]
|
72
|
+
|
73
|
+
export const controllerDependencies = controllerCommands.map(c => {
|
74
|
+
return new Dependency(
|
75
|
+
c.title,
|
76
|
+
vscode.TreeItemCollapsibleState.None,
|
77
|
+
undefined,
|
78
|
+
c.id,
|
79
|
+
c.icon ? c.icon : 'none'
|
80
|
+
);
|
81
|
+
})
|
@@ -0,0 +1,70 @@
|
|
1
|
+
import * as vscode from 'vscode';
|
2
|
+
import { FSProvider } from '../../../../FsProvider';
|
3
|
+
import { Password } from '../../../../utils/Password';
|
4
|
+
|
5
|
+
let NEXT_TERM_ID = 1
|
6
|
+
|
7
|
+
export async function handleDeploy() {
|
8
|
+
console.log('=== run handleDeploy ===')
|
9
|
+
vscode.window.showInformationMessage(`=== STARTING DEPLOY ===`);
|
10
|
+
const password = Password.getProjectPassword();
|
11
|
+
let settingFile = 'src/settings.json';
|
12
|
+
let version = '';
|
13
|
+
|
14
|
+
//get version
|
15
|
+
if (!FSProvider.checkExist(settingFile)) {
|
16
|
+
return vscode.window.showInformationMessage(`Deploy: Không tìm thấy settings.json`);
|
17
|
+
} else {
|
18
|
+
try {
|
19
|
+
const content = FSProvider.getContentInFile(settingFile);
|
20
|
+
if (!content) {
|
21
|
+
return vscode.window.showInformationMessage(`Deploy: File settings.json rỗng!`);
|
22
|
+
}
|
23
|
+
|
24
|
+
let object: any = {}
|
25
|
+
try {
|
26
|
+
object = JSON.parse(content);
|
27
|
+
|
28
|
+
version = object.version;
|
29
|
+
} catch (error) {
|
30
|
+
return vscode.window.showInformationMessage(`Deploy: Lỗi khi lấy cấu hình từ settings.json!`);
|
31
|
+
}
|
32
|
+
} catch (error) {
|
33
|
+
vscode.window.showInformationMessage(`Deploy: Lỗi khi đọc file cấu hình settings.json!`);
|
34
|
+
return;
|
35
|
+
}
|
36
|
+
}
|
37
|
+
//
|
38
|
+
|
39
|
+
//execute cmd
|
40
|
+
try {
|
41
|
+
const terminal = vscode.window.createTerminal(`Select deploy #${NEXT_TERM_ID++}`);
|
42
|
+
terminal.show();
|
43
|
+
terminal.sendText(`bmd-deploy -p ${password} -vc ${version}`, true);
|
44
|
+
} catch (error) {
|
45
|
+
if (error instanceof Error) {
|
46
|
+
vscode.window.showInformationMessage(`Deploy lỗi: ${error.message}`);
|
47
|
+
}
|
48
|
+
}
|
49
|
+
|
50
|
+
}
|
51
|
+
|
52
|
+
|
53
|
+
|
54
|
+
function isNotReplaceLink(file: string) {
|
55
|
+
const fileContent = FSProvider.getContentInFile(file)
|
56
|
+
return fileContent.includes('{{link}}')
|
57
|
+
}
|
58
|
+
|
59
|
+
export async function runDev() {
|
60
|
+
console.log('runDev:', runDev)
|
61
|
+
const terminal = vscode.window.createTerminal(`Development`);
|
62
|
+
terminal.show()
|
63
|
+
terminal.sendText(`npm run dev`, true);
|
64
|
+
}
|
65
|
+
|
66
|
+
export async function runStart() {
|
67
|
+
const terminal = vscode.window.createTerminal(`Development`);
|
68
|
+
terminal.show()
|
69
|
+
terminal.sendText(`npm run start`, true);
|
70
|
+
}
|
@@ -0,0 +1,21 @@
|
|
1
|
+
import { Deploy } from "../../../constant";
|
2
|
+
import { Dependency } from "../Dependency";
|
3
|
+
import * as vscode from 'vscode';
|
4
|
+
|
5
|
+
const deployCommand = [
|
6
|
+
{
|
7
|
+
id: Deploy.Deploy,
|
8
|
+
title: 'Deploy V2',
|
9
|
+
icon: 'spaceship'
|
10
|
+
},
|
11
|
+
]
|
12
|
+
|
13
|
+
export const deployDependencies = deployCommand.map(c => {
|
14
|
+
return new Dependency(
|
15
|
+
c.title,
|
16
|
+
vscode.TreeItemCollapsibleState.None,
|
17
|
+
undefined,
|
18
|
+
c.id,
|
19
|
+
c.icon ? c.icon : 'none'
|
20
|
+
);
|
21
|
+
})
|
@@ -0,0 +1,144 @@
|
|
1
|
+
import * as vscode from 'vscode';
|
2
|
+
import { PropertyType } from "../../../../constant";
|
3
|
+
import { getFullTextType } from '../../../../util';
|
4
|
+
|
5
|
+
export async function addProperty(document: vscode.TextDocument | undefined) {
|
6
|
+
let template = ''
|
7
|
+
|
8
|
+
const type = await vscode.window.showQuickPick([
|
9
|
+
PropertyType.String,
|
10
|
+
PropertyType.Number,
|
11
|
+
PropertyType.Boolean,
|
12
|
+
PropertyType.Text,
|
13
|
+
PropertyType.Double,
|
14
|
+
PropertyType.BalanceColumn,
|
15
|
+
PropertyType.IsBlockColumn,
|
16
|
+
PropertyType.TypeColumn,
|
17
|
+
PropertyType.StatusColumn,
|
18
|
+
PropertyType.IsDeleteColumn,
|
19
|
+
], { ignoreFocusOut: true })
|
20
|
+
|
21
|
+
const edit = new vscode.WorkspaceEdit();
|
22
|
+
|
23
|
+
if (!document || !document.uri) {
|
24
|
+
document = vscode.window.activeTextEditor?.document
|
25
|
+
}
|
26
|
+
|
27
|
+
if (!document) {
|
28
|
+
return vscode.window.showInformationMessage("Cancel: Can not find open document to insert")
|
29
|
+
}
|
30
|
+
|
31
|
+
for (let index = 0; index < document.lineCount; index++) {
|
32
|
+
const line = document.lineAt(index)
|
33
|
+
|
34
|
+
if (line.text.includes('RELATIONS')) {
|
35
|
+
let lineInsertIndex = index - 2
|
36
|
+
switch (type) {
|
37
|
+
case PropertyType.String:
|
38
|
+
case PropertyType.Number:
|
39
|
+
case PropertyType.Boolean:
|
40
|
+
case PropertyType.Double:
|
41
|
+
case PropertyType.Text:
|
42
|
+
template = await generateProperty(type)
|
43
|
+
if (!template) return
|
44
|
+
edit.insert(document.uri, new vscode.Position(lineInsertIndex, 0), template);
|
45
|
+
break
|
46
|
+
|
47
|
+
case PropertyType.BalanceColumn:
|
48
|
+
edit.insert(document.uri, new vscode.Position(lineInsertIndex, 0), `
|
49
|
+
@Column({ default: 0, width: 20 })
|
50
|
+
@Property()
|
51
|
+
balance: number;
|
52
|
+
`);
|
53
|
+
break
|
54
|
+
|
55
|
+
case PropertyType.IsBlockColumn:
|
56
|
+
edit.insert(document.uri, new vscode.Position(lineInsertIndex, 0), `
|
57
|
+
@Column({ default: false })
|
58
|
+
@Property()
|
59
|
+
isBlock: boolean
|
60
|
+
`);
|
61
|
+
break
|
62
|
+
|
63
|
+
case PropertyType.IsDeleteColumn:
|
64
|
+
edit.insert(document.uri, new vscode.Position(lineInsertIndex, 0), `
|
65
|
+
@Column({ default: false, select: false })
|
66
|
+
@Property()
|
67
|
+
isDeleted: boolean
|
68
|
+
`);
|
69
|
+
break
|
70
|
+
|
71
|
+
case PropertyType.StatusColumn:
|
72
|
+
edit.insert(document.uri, new vscode.Position(lineInsertIndex, 0), `
|
73
|
+
@Column({ default: '' })
|
74
|
+
@Property()
|
75
|
+
status: string
|
76
|
+
`);
|
77
|
+
break
|
78
|
+
|
79
|
+
case PropertyType.TypeColumn:
|
80
|
+
edit.insert(document.uri, new vscode.Position(lineInsertIndex, 0), `
|
81
|
+
@Column({ default: '' })
|
82
|
+
@Property()
|
83
|
+
type: string
|
84
|
+
`);
|
85
|
+
break
|
86
|
+
|
87
|
+
default:
|
88
|
+
break;
|
89
|
+
}
|
90
|
+
}
|
91
|
+
}
|
92
|
+
|
93
|
+
vscode.workspace.applyEdit(edit)
|
94
|
+
}
|
95
|
+
|
96
|
+
async function generateProperty(propertyType: PropertyType) {
|
97
|
+
const inputName = await vscode.window.showInputBox({
|
98
|
+
placeHolder: 'Enter property name: ',
|
99
|
+
ignoreFocusOut: true
|
100
|
+
})
|
101
|
+
if (!inputName) return ''
|
102
|
+
|
103
|
+
const fullTextType = getFullTextType(inputName)
|
104
|
+
|
105
|
+
switch (propertyType) {
|
106
|
+
case PropertyType.String:
|
107
|
+
return `
|
108
|
+
@Column({ default: '' })
|
109
|
+
@Property()
|
110
|
+
${fullTextType.camelCase}: string
|
111
|
+
`
|
112
|
+
|
113
|
+
case PropertyType.Number:
|
114
|
+
return `
|
115
|
+
@Column({ default: 0 })
|
116
|
+
@Property()
|
117
|
+
${fullTextType.camelCase}: number
|
118
|
+
`
|
119
|
+
|
120
|
+
case PropertyType.Boolean:
|
121
|
+
return `
|
122
|
+
@Column({ default: false })
|
123
|
+
@Property()
|
124
|
+
${fullTextType.camelCase}: boolean
|
125
|
+
`
|
126
|
+
|
127
|
+
case PropertyType.Double:
|
128
|
+
return `
|
129
|
+
@Column("double", { default: 0 })
|
130
|
+
@Property()
|
131
|
+
${fullTextType.camelCase}: number
|
132
|
+
`
|
133
|
+
|
134
|
+
case PropertyType.Text:
|
135
|
+
return `
|
136
|
+
@Column('text', { nullable: true })
|
137
|
+
@Property()
|
138
|
+
${fullTextType.camelCase}: string;
|
139
|
+
`
|
140
|
+
|
141
|
+
default:
|
142
|
+
return ''
|
143
|
+
}
|
144
|
+
}
|
@@ -0,0 +1,125 @@
|
|
1
|
+
import * as vscode from 'vscode';
|
2
|
+
import { EntityAction } from '../../../../constant';
|
3
|
+
import { FSProvider } from '../../../../FsProvider';
|
4
|
+
import { getFullTextType } from '../../../../util';
|
5
|
+
|
6
|
+
export async function insertEntityAction(
|
7
|
+
typeFunc: EntityAction, document: vscode.TextDocument | undefined
|
8
|
+
): Promise<void> {
|
9
|
+
const edit = new vscode.WorkspaceEdit();
|
10
|
+
let entity = 'Entity'
|
11
|
+
let template = ''
|
12
|
+
|
13
|
+
if (!document || !document.uri) {
|
14
|
+
document = vscode.window.activeTextEditor?.document
|
15
|
+
}
|
16
|
+
|
17
|
+
if (!document) {
|
18
|
+
vscode.window.showInformationMessage("Cancel: Can not find open document to insert")
|
19
|
+
return
|
20
|
+
}
|
21
|
+
|
22
|
+
for (let index = 0; index < document.lineCount; index++) {
|
23
|
+
const line = document.lineAt(index)
|
24
|
+
if (line.text.includes('CoreEntity') && line.text.includes('class')) {
|
25
|
+
let words = line.text.split(' ')
|
26
|
+
for (let index = 0; index < words.length; index++) {
|
27
|
+
const word = words[index];
|
28
|
+
if (word == 'class') {
|
29
|
+
entity = words[index + 1]
|
30
|
+
}
|
31
|
+
}
|
32
|
+
}
|
33
|
+
|
34
|
+
if (line.text.includes('METHODS')) {
|
35
|
+
let lineInsertIndex = index - 2
|
36
|
+
switch (typeFunc) {
|
37
|
+
case EntityAction.OneToMany:
|
38
|
+
template = await generateRelations(entity, EntityAction.OneToMany)
|
39
|
+
if (!template) return
|
40
|
+
edit.insert(document.uri, new vscode.Position(lineInsertIndex, 0), template);
|
41
|
+
break
|
42
|
+
|
43
|
+
case EntityAction.ManyToOne:
|
44
|
+
template = await generateRelations(entity, EntityAction.ManyToOne)
|
45
|
+
if (!template) return
|
46
|
+
edit.insert(document.uri, new vscode.Position(lineInsertIndex, 0), template);
|
47
|
+
break
|
48
|
+
|
49
|
+
case EntityAction.ManyToMany:
|
50
|
+
template = await generateRelations(entity, EntityAction.ManyToMany)
|
51
|
+
if (!template) return
|
52
|
+
edit.insert(document.uri, new vscode.Position(lineInsertIndex, 0), template);
|
53
|
+
break
|
54
|
+
|
55
|
+
case EntityAction.OneToOne:
|
56
|
+
template = await generateRelations(entity, EntityAction.OneToOne)
|
57
|
+
if (!template) return
|
58
|
+
edit.insert(document.uri, new vscode.Position(lineInsertIndex, 0), template);
|
59
|
+
break
|
60
|
+
|
61
|
+
default:
|
62
|
+
break;
|
63
|
+
}
|
64
|
+
}
|
65
|
+
}
|
66
|
+
|
67
|
+
vscode.workspace.applyEdit(edit)
|
68
|
+
}
|
69
|
+
|
70
|
+
async function generateRelations(name1: string, relation: EntityAction) {
|
71
|
+
const entities = FSProvider.getAllFileInFolder('/src/entity')
|
72
|
+
let name2 = await vscode.window.showQuickPick(entities, {
|
73
|
+
placeHolder: 'Select entity',
|
74
|
+
ignoreFocusOut: true
|
75
|
+
})
|
76
|
+
if (!name2) return ''
|
77
|
+
|
78
|
+
let injectString1 = ''
|
79
|
+
|
80
|
+
switch (relation) {
|
81
|
+
case EntityAction.OneToMany:
|
82
|
+
injectString1 = `
|
83
|
+
@OneToMany(type => {{cap2}}, {{camel2}}s => {{camel2}}s.{{camel1}})
|
84
|
+
{{camel2}}s: {{cap2}}[];
|
85
|
+
`
|
86
|
+
break;
|
87
|
+
|
88
|
+
case EntityAction.ManyToOne:
|
89
|
+
injectString1 = `
|
90
|
+
@ManyToOne(type => {{cap2}}, {{camel2}} => {{camel2}}.{{camel1}}s)
|
91
|
+
{{camel2}}: {{cap2}};
|
92
|
+
`
|
93
|
+
break;
|
94
|
+
|
95
|
+
case EntityAction.ManyToMany:
|
96
|
+
injectString1 = `
|
97
|
+
@ManyToMany(type => {{cap2}}, {{camel2}}s => {{camel2}}s.{{camel1}}s)
|
98
|
+
{{camel2}}s: {{cap2}}[];
|
99
|
+
`
|
100
|
+
break;
|
101
|
+
|
102
|
+
case EntityAction.OneToOne:
|
103
|
+
injectString1 = `
|
104
|
+
@OneToOne(type => {{cap2}}, {{camel2}} => {{camel2}}.{{camel1}})
|
105
|
+
{{camel2}}: {{cap2}};
|
106
|
+
`
|
107
|
+
break;
|
108
|
+
}
|
109
|
+
|
110
|
+
const nameTextTypes1 = getFullTextType(name1)
|
111
|
+
const nameTextTypes2 = getFullTextType(name2)
|
112
|
+
|
113
|
+
injectString1 = injectString1.replace(/{{camel1}}/g, nameTextTypes1.camelCase);
|
114
|
+
injectString1 = injectString1.replace(/{{camel2}}/g, nameTextTypes2.camelCase);
|
115
|
+
injectString1 = injectString1.replace(/{{cap1}}/g, nameTextTypes1.classifyCase);
|
116
|
+
injectString1 = injectString1.replace(/{{cap2}}/g, nameTextTypes2.classifyCase);
|
117
|
+
|
118
|
+
if (injectString1.includes('ys')) {
|
119
|
+
injectString1 = injectString1.replace(/ys/g, 'ies');
|
120
|
+
}
|
121
|
+
if (injectString1.includes('sss')) {
|
122
|
+
injectString1 = injectString1.replace(/sss/g, 'sses');
|
123
|
+
}
|
124
|
+
return injectString1
|
125
|
+
}
|
@@ -0,0 +1,53 @@
|
|
1
|
+
import { FSProvider } from "../../../../FsProvider"
|
2
|
+
import * as vscode from 'vscode';
|
3
|
+
import { getFullTextType } from "../../../../util";
|
4
|
+
import { Confirmation } from "../../../../constant";
|
5
|
+
import { Uri, commands } from "vscode";
|
6
|
+
|
7
|
+
export async function createEntity(fsPath: string) {
|
8
|
+
if (!FSProvider.isValidStructure()) {
|
9
|
+
return vscode.window.showInformationMessage("Cancel!. Wrong project's structure.");
|
10
|
+
}
|
11
|
+
|
12
|
+
if (fsPath != undefined && !fsPath.includes('entity')) {
|
13
|
+
return vscode.window.showInformationMessage("Please select 'entity' folder")
|
14
|
+
}
|
15
|
+
|
16
|
+
let entity = await vscode.window.showInputBox({
|
17
|
+
placeHolder: "Enter entity name: ",
|
18
|
+
ignoreFocusOut: true
|
19
|
+
})
|
20
|
+
if (!entity) {
|
21
|
+
return vscode.window.showInformationMessage("Cancel!. Do not input entity name.");
|
22
|
+
}
|
23
|
+
|
24
|
+
const entityTextTypes = getFullTextType(entity)
|
25
|
+
|
26
|
+
const distPath = `src/entity/${entityTextTypes.classifyCase}.ts`
|
27
|
+
if (FSProvider.checkExist(distPath)) {
|
28
|
+
const confirm = await vscode.window.showQuickPick(
|
29
|
+
[Confirmation.Yes, Confirmation.No],
|
30
|
+
{
|
31
|
+
placeHolder: "This file already exist in this folder. Do you want to replace it.",
|
32
|
+
ignoreFocusOut: true
|
33
|
+
}
|
34
|
+
)
|
35
|
+
if (!confirm || confirm == Confirmation.No) {
|
36
|
+
return vscode.window.showInformationMessage("Cancel: add ENTITY.");
|
37
|
+
}
|
38
|
+
}
|
39
|
+
|
40
|
+
FSProvider.copyAndReplaceFile(
|
41
|
+
'entity/entity.txt',
|
42
|
+
distPath,
|
43
|
+
[
|
44
|
+
{ regex: /{{snake}}/g, value: entityTextTypes.snakeCase },
|
45
|
+
{ regex: /{{classify}}/g, value: entityTextTypes.classifyCase },
|
46
|
+
{ regex: /{{camel}}/g, value: entityTextTypes.camelCase }
|
47
|
+
])
|
48
|
+
|
49
|
+
let uri = Uri.file(FSProvider.getFullPath(distPath))
|
50
|
+
await commands.executeCommand('vscode.openFolder', uri)
|
51
|
+
|
52
|
+
return vscode.window.showInformationMessage("Create ENTITY successfully!");
|
53
|
+
}
|
@@ -0,0 +1,65 @@
|
|
1
|
+
import { FSProvider } from "../../../../FsProvider"
|
2
|
+
import * as vscode from 'vscode';
|
3
|
+
import { getFullTextType } from "../../../../util";
|
4
|
+
import { Confirmation, TypeRequest } from "../../../../constant";
|
5
|
+
import { Uri, commands } from "vscode";
|
6
|
+
|
7
|
+
export async function createEntityRequest(fsPath: string) {
|
8
|
+
if (!FSProvider.isValidStructure()) {
|
9
|
+
return vscode.window.showInformationMessage("Cancel!. Wrong project's structure.");
|
10
|
+
}
|
11
|
+
|
12
|
+
if (fsPath != undefined && !fsPath.includes('entity-request')) {
|
13
|
+
return vscode.window.showInformationMessage("Please select 'entity' folder")
|
14
|
+
}
|
15
|
+
|
16
|
+
const entities = FSProvider.getAllFileInFolder('/src/entity')
|
17
|
+
|
18
|
+
const entity = await vscode.window.showQuickPick(
|
19
|
+
[...entities],
|
20
|
+
{ ignoreFocusOut: true }
|
21
|
+
)
|
22
|
+
if (!entity) {
|
23
|
+
return vscode.window.showInformationMessage('Cancel! Do not select entity')
|
24
|
+
}
|
25
|
+
|
26
|
+
const type = await vscode.window.showQuickPick(
|
27
|
+
[TypeRequest.Insert, TypeRequest.Update],
|
28
|
+
{ ignoreFocusOut: true }
|
29
|
+
)
|
30
|
+
if (!type) {
|
31
|
+
return vscode.window.showInformationMessage('Cancel! Do not select type entity request')
|
32
|
+
}
|
33
|
+
|
34
|
+
const entityRequestTextTypes = getFullTextType(entity + type)
|
35
|
+
const entityTextTypes = getFullTextType(entity)
|
36
|
+
|
37
|
+
const distPath = `src/entity-request/${entityRequestTextTypes.classifyCase}.ts`
|
38
|
+
if (FSProvider.checkExist(distPath)) {
|
39
|
+
const confirm = await vscode.window.showQuickPick(
|
40
|
+
[Confirmation.Yes, Confirmation.No],
|
41
|
+
{
|
42
|
+
placeHolder: "This file already exist in this folder. Do you want to replace it.",
|
43
|
+
ignoreFocusOut: true
|
44
|
+
}
|
45
|
+
)
|
46
|
+
if (!confirm || confirm == Confirmation.No) {
|
47
|
+
return vscode.window.showInformationMessage("Cancel: add ENTITY REQUEST.");
|
48
|
+
}
|
49
|
+
}
|
50
|
+
|
51
|
+
FSProvider.copyAndReplaceFile(
|
52
|
+
'entity-request/entity-request.txt',
|
53
|
+
distPath,
|
54
|
+
[
|
55
|
+
{ regex: /{{snake}}/g, value: entityTextTypes.snakeCase },
|
56
|
+
{ regex: /{{classify}}/g, value: entityTextTypes.classifyCase },
|
57
|
+
{ regex: /{{classifyRaw}}/g, value: entityRequestTextTypes.classifyCase },
|
58
|
+
{ regex: /{{camel}}/g, value: entityTextTypes.camelCase }
|
59
|
+
])
|
60
|
+
|
61
|
+
let uri = Uri.file(FSProvider.getFullPath(distPath))
|
62
|
+
await commands.executeCommand('vscode.openFolder', uri)
|
63
|
+
|
64
|
+
return vscode.window.showInformationMessage("Create ENTITY REQUEST successfully!");
|
65
|
+
}
|
@@ -0,0 +1,130 @@
|
|
1
|
+
import * as vscode from 'vscode';
|
2
|
+
import { API } from '../../../../API';
|
3
|
+
import { FSProvider } from '../../../../FsProvider';
|
4
|
+
import { Request } from '../../../../Request';
|
5
|
+
|
6
|
+
export async function createInterface(document: vscode.TextDocument | any, range: vscode.Range) {
|
7
|
+
const entities = FSProvider.getAllFileInFolder('/src/entity')
|
8
|
+
|
9
|
+
vscode.window.withProgress({
|
10
|
+
location: vscode.ProgressLocation.Notification,
|
11
|
+
title: "Uploading interface: ",
|
12
|
+
cancellable: true
|
13
|
+
}, async (progress, token) => {
|
14
|
+
|
15
|
+
token.onCancellationRequested(() => {
|
16
|
+
// console.log("User canceled the long running operation");
|
17
|
+
});
|
18
|
+
|
19
|
+
progress.report({ increment: 0 });
|
20
|
+
|
21
|
+
for (let index = 0; index < entities.length; index++) {
|
22
|
+
const entity = entities[index];
|
23
|
+
|
24
|
+
const linesProperty = getPropertyLinesEntity(entity, true)
|
25
|
+
let line = ``
|
26
|
+
linesProperty.map((l, i) => {
|
27
|
+
i == linesProperty.length - 1 ? line += `${l}` : line += `${l} \n`
|
28
|
+
})
|
29
|
+
|
30
|
+
let template = `
|
31
|
+
export interface ${entity} {
|
32
|
+
${line}
|
33
|
+
}
|
34
|
+
`
|
35
|
+
// let doc = await vscode.workspace.openTextDocument({ content: template, language: 'typescript' }); // calls back into the provider
|
36
|
+
// await vscode.window.showTextDocument(doc, { preview: false, viewColumn: vscode.ViewColumn.Beside });
|
37
|
+
|
38
|
+
const folders = vscode.workspace.workspaceFolders
|
39
|
+
if (!folders?.length) return
|
40
|
+
|
41
|
+
const projectName = folders[0].name
|
42
|
+
|
43
|
+
console.log(`template "${entity}"`, template);
|
44
|
+
|
45
|
+
|
46
|
+
const response = await Request.post(API.Interface.post, {
|
47
|
+
name: entity,
|
48
|
+
project: projectName,
|
49
|
+
body: template
|
50
|
+
})
|
51
|
+
|
52
|
+
if (response) {
|
53
|
+
progress.report({ increment: 100 / entities.length, message: `${entity}` });
|
54
|
+
}
|
55
|
+
|
56
|
+
}
|
57
|
+
});
|
58
|
+
|
59
|
+
const p = new Promise(resolve => resolve(''));
|
60
|
+
return p;
|
61
|
+
}
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
function getEntityFromFilename(filename: string) {
|
66
|
+
const words = filename.split('/')
|
67
|
+
const fileWithExtension = words[words.length - 1]
|
68
|
+
return fileWithExtension.replace('.ts', '')
|
69
|
+
}
|
70
|
+
|
71
|
+
function getPropertyLinesEntity(name: string, getComment: boolean = false): any[] {
|
72
|
+
const lines = FSProvider.getLinesDocumentInFile(`src/entity/${name}.ts`).filter(e => e)
|
73
|
+
if (!lines.length) return []
|
74
|
+
const properties = [];
|
75
|
+
let currentIndex = null;
|
76
|
+
|
77
|
+
for (let index = 0; index < lines.length; index++) {
|
78
|
+
const line = lines[index];
|
79
|
+
|
80
|
+
if (shouldGetComment(getComment, line)) {
|
81
|
+
properties.push(line)
|
82
|
+
}
|
83
|
+
|
84
|
+
if (currentIndex == null && line.includes('@') && !line.includes('@Entity')) {
|
85
|
+
currentIndex = index;
|
86
|
+
}
|
87
|
+
|
88
|
+
|
89
|
+
else if (!line.includes('@') && currentIndex !== null && line.includes(':')) {
|
90
|
+
let lineProperty = line.replace(';', '')
|
91
|
+
properties.push(`${lineProperty}`)
|
92
|
+
currentIndex = null;
|
93
|
+
}
|
94
|
+
}
|
95
|
+
const propertiesInCore = getPropertyLinesEntityCore()
|
96
|
+
return [...propertiesInCore, ...properties]
|
97
|
+
}
|
98
|
+
|
99
|
+
function shouldGetComment(getComment: boolean, line: string) {
|
100
|
+
return getComment &&
|
101
|
+
line.startsWith('//') &&
|
102
|
+
line.includes('//') &&
|
103
|
+
!line.includes('@') &&
|
104
|
+
!line.includes('IMPORT') &&
|
105
|
+
!line.includes('PROPERTIES') &&
|
106
|
+
!line.includes('RELATIONS') &&
|
107
|
+
!line.includes('METHODS') &&
|
108
|
+
!line.includes('END') &&
|
109
|
+
!line.includes(':')
|
110
|
+
}
|
111
|
+
|
112
|
+
function getPropertyLinesEntityCore(): any[] {
|
113
|
+
const lines = FSProvider.getLinesDocumentInFile(`src/core/entity/CoreEntity.ts`)
|
114
|
+
if (!lines.length) return []
|
115
|
+
const properties = []
|
116
|
+
for (let index = 0; index < lines.length; index++) {
|
117
|
+
const line = lines[index];
|
118
|
+
if (line.includes('@Column') || line.includes('@PrimaryGeneratedColumn')) {
|
119
|
+
let lineProperty = lines[index + 1]
|
120
|
+
|
121
|
+
if (lineProperty.includes('JsonProperty') || lineProperty.includes('Property')) {
|
122
|
+
lineProperty = lines[index + 2]
|
123
|
+
}
|
124
|
+
|
125
|
+
lineProperty = lineProperty.replace(';', '')
|
126
|
+
properties.push(`${lineProperty}`)
|
127
|
+
}
|
128
|
+
}
|
129
|
+
return properties
|
130
|
+
}
|