Skip to content

Commit

Permalink
Cb 5988 plugin template (#3136)
Browse files Browse the repository at this point in the history
* CB-5988 generate plugin template

* CB-5988 add add plugin script

* CB-5988 review fixes

---------

Co-authored-by: mr-anton-t <[email protected]>
Co-authored-by: sergeyteleshev <[email protected]>
  • Loading branch information
3 people authored Dec 24, 2024
1 parent 78aafaf commit 398f9b7
Show file tree
Hide file tree
Showing 11 changed files with 464 additions and 3 deletions.
8 changes: 8 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,14 @@
"options": {
"cwd": "${workspaceFolder}/webapp"
}
},
{
"label": "Add Custom Plugin",
"type": "shell",
"command": "yarn run add-plugin",
"options": {
"cwd": "${workspaceFolder}/webapp/packages"
}
}
],
"inputs": [
Expand Down
1 change: 1 addition & 0 deletions webapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"lint": "eslint --ext .ts,.tsx",
"validate-dependencies": "core-cli-validate-dependencies './packages/*/'",
"update-ts-references": "yarn run clean && typescript-resolve-references './packages/*/'",
"add-plugin": "core-cli-add-plugin",
"prebuild": "lerna run gql:gen --stream --parallel",
"prepare": "cd .. && husky ./webapp/.husky",
"postinstall": "husky"
Expand Down
7 changes: 7 additions & 0 deletions webapp/packages/core-cli/_templates/plugin/new/index.ts.ejs.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
to: <%= name %>/src/index.ts
---
import { <%= h.changeCase.camel(name) %>Manifest } from './manifest.js';

export default <%= h.changeCase.camel(name) %>Manifest;
export { <%= h.changeCase.camel(name) %>Manifest };
12 changes: 12 additions & 0 deletions webapp/packages/core-cli/_templates/plugin/new/manifest.ts.ejs.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
to: <%= name %>/src/manifest.ts
---
import type { PluginManifest } from '@cloudbeaver/core-di';

export const <%= h.changeCase.camel(name) %>Manifest: PluginManifest = {
info: {
name: '<%= h.changeCase.sentence(name) %>',
},

providers: [() => import('./<%= h.changeCase.pascal(name) %>ServiceBootstrap.js').then(m => m.<%= h.changeCase.pascal(name) %>ServiceBootstrap)],
};
31 changes: 31 additions & 0 deletions webapp/packages/core-cli/_templates/plugin/new/package.json.ejs.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
to: <%= name %>/package.json
---
{
"name": "@cloudbeaver/<%= name %>",
"type": "module",
"sideEffects": [
"src/**/*.css",
"src/**/*.scss",
"public/**/*"
],
"version": "0.1.0",
"description": "",
"license": "Apache-2.0",
"main": "dist/index.js",
"scripts": {
"build": "tsc -b",
"clean": "rimraf --glob dist",
"lint": "eslint ./src/ --ext .ts,.tsx",
"test": "core-cli-test",
"validate-dependencies": "core-cli-validate-dependencies",
"update-ts-references": "yarn run clean && typescript-resolve-references"
},
"dependencies": {
"@cloudbeaver/core-di": "^0"
},
"peerDependencies": {},
"devDependencies": {
"typescript": "^5"
}
}
15 changes: 15 additions & 0 deletions webapp/packages/core-cli/_templates/plugin/new/prompt.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* CloudBeaver - Cloud Database Manager
* Copyright (C) 2020-2024 DBeaver Corp and others
*
* Licensed under the Apache License, Version 2.0.
* you may not use this file except in compliance with the License.
*/

module.exports = [
{
type: 'input',
name: 'name',
message: 'What is the name of your plugin?',
},
];
15 changes: 15 additions & 0 deletions webapp/packages/core-cli/_templates/plugin/new/service.ts.ejs.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
to: <%= name %>/src/<%= h.changeCase.pascal(name) %>ServiceBootstrap.ts
---
import { Bootstrap, injectable } from '@cloudbeaver/core-di';

@injectable()
export class <%= h.changeCase.pascal(name) %>ServiceBootstrap extends Bootstrap {
constructor() {
super();
}

override register() {
console.log('<%= h.changeCase.no(name) %> is registered');
}
}
29 changes: 29 additions & 0 deletions webapp/packages/core-cli/_templates/plugin/new/tsconfig.json.ejs.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
to: <%= name %>/tsconfig.json
---
<% isEE = cwd.includes('cloudbeaver-ee'); %>
{
"extends": "<%= isEE ? '../../../../cloudbeaver/webapp/tsconfig.base.json' : '../../tsconfig.base.json' %>",
"compilerOptions": {
"rootDir": "src",
"outDir": "dist",
"tsBuildInfoFile": "dist/tsconfig.tsbuildinfo"
},
"references": [
{
"path": "<%= isEE ? '../../../../cloudbeaver/webapp/packages/core-di/tsconfig.json' : '../core-di/tsconfig.json' %>"
}
],
"include": [
"__custom_mocks__/**/*",
"src/**/*",
"src/**/*.json",
"src/**/*.css",
"src/**/*.scss"
],
"exclude": [
"**/node_modules",
"lib/**/*",
"dist/**/*"
]
}
22 changes: 22 additions & 0 deletions webapp/packages/core-cli/bin/add-plugin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env node

'use strict';
process.title = 'core-add-plugin';

const { resolve, join } = require('path');
const { runner, Logger } = require('hygen');

const templates = join(__dirname, '../_templates');
const currentDir = resolve();

runner(['plugin', 'new'], {
templates,
cwd: join(currentDir, 'packages'),
logger: new Logger(console.log.bind(console)),
debug: !!process.env.DEBUG,
exec: (action, body) => {
const opts = body && body.length > 0 ? { input: body } : {};
return require('execa').command(action, { ...opts, shell: true });
},
createPrompter: () => require('enquirer'),
}).then(({ success }) => process.exit(success ? 0 : 1));
4 changes: 4 additions & 0 deletions webapp/packages/core-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"core-cli-test": "./bin/test.js",
"core-cli-analyzer": "./bin/analyzer.js",
"core-cli-validate-dependencies": "./bin/validate-dependencies.js",
"core-cli-add-plugin": "./bin/add-plugin.js",
"typescript-resolve-references": "./bin/typescript-resolve-references.js"
},
"engines": {
Expand Down Expand Up @@ -55,10 +56,13 @@
"@swc/core": "^1",
"@swc/jest": "^0",
"@types/madge": "^5",
"enquirer": "^2.4.1",
"esbuild-loader": "^4.2.2",
"execa": "^9.5.2",
"fake-indexeddb": "^6",
"glob": "^11",
"http-proxy": "^1",
"hygen": "^6.2.11",
"jest": "^29",
"jest-environment-jsdom": "^29",
"madge": "^8",
Expand Down
Loading

0 comments on commit 398f9b7

Please sign in to comment.