Skip to content

Commit

Permalink
Merge pull request #257 from RabotaRu/dev-for-plugin
Browse files Browse the repository at this point in the history
Dev for plugin
  • Loading branch information
rpiontik authored Apr 1, 2023
2 parents d436740 + e19a892 commit eee2063
Show file tree
Hide file tree
Showing 37 changed files with 4,056 additions and 2,357 deletions.
15 changes: 15 additions & 0 deletions config.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
declare var DochubVsCodeExt: {
rootManifest: string,
settings: {
isEnterprise: boolean, // Признак использования фронта в плагине как Enterprise портала
render: {
external: boolean,
mode: string,
Expand All @@ -11,6 +12,20 @@ declare var DochubVsCodeExt: {
}
};

// eslint-disable-next-line no-var
declare var DocHubIDEACodeExt: {
rootManifest: string, // Корневой манифест (с чего начинается загрузка)
settings: {
isEnterprise: boolean, // Признак использования фронта в плагине как Enterprise портала
render: {
external: boolean, // Признак рендера на внешнем сервере
mode: string, // Режим рендера ELK / Smetana / GraphVis
request_type: string, // Тип запросов к сервер рендеринга POST / GET
server: string // Сервер рендеринга
}
}
};

declare const vscode: {
postMessage: ({
command,
Expand Down
5,569 changes: 3,638 additions & 1,931 deletions package-lock.json

Large diffs are not rendered by default.

9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,9 @@
"@babel/eslint-parser": "7.19.1",
"@babel/preset-env": "7.20.2",
"@babel/preset-typescript": "7.18.6",
"babel-plugin-transform-import-meta": "2.2.0",
"@effortlessmotion/html-webpack-inline-source-plugin": "1.0.3",
"@types/jest": "29.5.0",
"@types/jest": "29.4.1",
"@typescript-eslint/eslint-plugin": "5.46.1",
"@typescript-eslint/parser": "5.46.1",
"@vue/cli-plugin-babel": "5.0.8",
Expand All @@ -77,8 +78,8 @@
"fake-indexeddb": "4.0.1",
"generator-code": "1.7.1",
"html-webpack-plugin": "5.5.0",
"jest": "29.5.0",
"jest-environment-jsdom": "29.5.0",
"jest": "29.4.1",
"jest-environment-jsdom": "29.4.1",
"md5": "2.3.0",
"nodemon": "2.0.20",
"postcss-loader": "2.1.6",
Expand Down Expand Up @@ -106,5 +107,5 @@
"engines": {
"npm": ">=8.1.0",
"node": ">=16.0.0"
}
}
}
22 changes: 22 additions & 0 deletions src/frontend/bootstrap.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import env from '@front/helpers/env';
import {plugins} from '@front/plugins/initializer.js';

const beforeInit = (processEnv) => {
env.dochub = processEnv ?? {};
import(/* webpackMode: "eager" */ '@front/plugins/api');
};

const init = async() => {
const { default: app } = await import(/* webpackMode: "eager" */ './index');
return app;
};

const afterInit = () => {
plugins.pull();
};

export {
beforeInit,
init,
afterInit
};
4 changes: 3 additions & 1 deletion src/frontend/components/Main.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@

<script>
import env from '@front/helpers/env';
export default {
name: 'MainPage',
data() {
return {};
},
computed: {
path() {
return '/docs/' + (process.env.VUE_APP_DOCHUB_ROOT_DOCUMENT || 'dochub.welcome');
return '/docs/' + (env.rootDocument|| 'dochub.welcome');
}
}
};
Expand Down
4 changes: 1 addition & 3 deletions src/frontend/components/Schema/PlantUML.vue
Original file line number Diff line number Diff line change
Expand Up @@ -260,9 +260,7 @@
this.isLoading = true;
this.$nextTick(() => {
const request = window.$PAPI?.settings?.render?.external === false
? window.$PAPI.renderPlantUML(this.uml)
: plantUML.prepareRequest(this.uml);
const request = plantUML.prepareRequest(this.uml);
request.then((response) => {
this.svg = response.data.toString();
Expand Down
3 changes: 2 additions & 1 deletion src/frontend/components/Schema/Schema.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import requests from '@front/helpers/requests';
import uri from '@front/helpers/uri';
import copyToClipboard from '@front/helpers/clipboard';
import env from '@front/helpers/env';
import PlantUML from './PlantUML';
Expand Down Expand Up @@ -63,7 +64,7 @@
}
const renderCore = (
process.env.VUE_APP_DOCHUB_RENDER_CORE ||
env.renderCore ||
window.$PAPI?.settings?.render?.mode || ''
).toLowerCase();
Expand Down
15 changes: 13 additions & 2 deletions src/frontend/components/Tools/Image.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
<template>
<img v-bind:src="data" style="max-width:100%">
<div>
<v-alert v-if="error" color="warning">
Здесь должна быть картинка, но что-то пошло не так.<br>
Проверьте, что ресурс доступен, а CORS политики настроены верно.<br>
<br>
Ошибка:<br>
{{ error }}
</v-alert>
<img v-else v-bind:src="data" style="max-width:100%">
</div>
</template>

<script>
Expand All @@ -13,6 +22,7 @@
},
data() {
return {
error: null,
data: null
};
},
Expand All @@ -25,7 +35,8 @@
requests.request(url.toString(), undefined, { responseType: 'arraybuffer' })
.then((response) => {
this.data = URL.createObjectURL(new Blob([response.data], { type: response.headers['content-type']}));
});
})
.catch((e) => this.error = e);
}
}
};
Expand Down
41 changes: 10 additions & 31 deletions src/frontend/config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import consts from '@front/consts';
import env from '@front/helpers/env';
import {Plugins} from '@front/helpers/env';

Expand All @@ -7,58 +6,38 @@ console.info('ENVIRONMENTS:');

const hiddenEnvs = ['VUE_APP_DOCHUB_CLIENT_SECRET'];

for(const key in process.env) {
for(const key in env.dochub) {
// eslint-disable-next-line no-console
console.info(` ${key}=`, hiddenEnvs.indexOf(key) < 0 ? JSON.stringify(process.env[key]) : '**HIDDEN**');
console.info(` ${key}=`, hiddenEnvs.indexOf(key) < 0 ? JSON.stringify(env.dochub[key]) : '**HIDDEN**');
}

const config: any = {};

if(!process.env.VUE_APP_DOCHUB_GITLAB_URL) {
if(!env.gitlabUrl) {
// eslint-disable-next-line no-console
console.warn('Not specified the URL of the GitLab (VUE_APP_DOCHUB_GITLAB_URL)');
config.oauth = false;
} else {
config.gitlab_server = process.env.VUE_APP_DOCHUB_GITLAB_URL;
config.gitlab_server = env.gitlabUrl;

if (process.env.VUE_APP_DOCHUB_PERSONAL_TOKEN) {
if (env.personalToken) {
// Персональный токен генерируемый пользователем
config.porsonalToken = process.env.VUE_APP_DOCHUB_PERSONAL_TOKEN;
config.porsonalToken = env.personalToken;
config.oauth = false;
} else {
// Секреты приложения для OAuth авторизации в GitLab
if(!process.env.VUE_APP_DOCHUB_CLIENT_SECRET)
if(!env.clientSecret)
throw 'Not specified the application secret at GitLab (VUE_APP_DOCHUB_CLIENT_SECRET)';

if(!process.env.VUE_APP_DOCHUB_APP_ID)
if(!env.appId)
throw 'Not specified the application ID at GitLab (VUE_APP_DOCHUB_APP_ID)';

config.oauth = {
'APP_ID': process.env.VUE_APP_DOCHUB_APP_ID,
'CLIENT_SECRET': process.env.VUE_APP_DOCHUB_CLIENT_SECRET,
'APP_ID': env.appId,
'CLIENT_SECRET': env.clientSecret,
'REQUESTED_SCOPES': 'read_repository+api'
};
}
}


config.root_manifest = process.env.VUE_APP_DOCHUB_ROOT_MANIFEST || 'example/root.yaml';

if (env.isPlugin(Plugins.idea)) {
if (!env.isProduction()) {
window.$PAPI = require('@idea/apimoc').default;
} else {
config.root_manifest = consts.plugin.ROOT_MANIFEST;
}
}

config.pumlServer =
window.$PAPI?.settings?.render?.server
|| process.env.VUE_APP_PLANTUML_SERVER
|| 'www.plantuml.com/plantuml/svg/';

config.pumlRequestType =
window.$PAPI?.settings?.render?.request_type
|| 'get';

export default config;
3 changes: 3 additions & 0 deletions src/frontend/consts.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ export default {
OAUTH_CALLBACK_PAGE: '/sso/gitlab/authentication',
MAIN_PAGE: '/main'
},
plantuml: {
DEFAULT_SERVER: 'www.plantuml.com/plantuml/svg/'
},
transports: {
HTTP: 'http',
GITLAB: 'gitlab'
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/helpers/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
TManifestProps
} from '@front/storage/indexedDB/types/idb.types';

import idb, { TCache } from '../storage/indexedDB';
import idb, { TCache } from '@front/storage/indexedDB';
import env from './env';

let Cache: TCache | null;
Expand Down
Loading

0 comments on commit eee2063

Please sign in to comment.