@scifeon/sdk 0.100.0 → 0.101.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/dist/action-target.d.ts +6 -6
- package/dist/action-target.js +10 -10
- package/dist/app/app-generator.d.ts +34 -34
- package/dist/app/app-generator.js +460 -460
- package/dist/app/app-persist.d.ts +18 -18
- package/dist/app/app-persist.js +193 -193
- package/dist/app/app-validator.d.ts +8 -8
- package/dist/app/app-validator.js +145 -145
- package/dist/app/interfaces/app-json.interface.d.ts +4 -4
- package/dist/app/interfaces/app-json.interface.js +2 -2
- package/dist/app/interfaces/app-type.enum.d.ts +5 -5
- package/dist/app/interfaces/app-type.enum.js +9 -9
- package/dist/app/interfaces/contributions/contributions-json.interface.d.ts +55 -55
- package/dist/app/interfaces/contributions/contributions-json.interface.js +2 -2
- package/dist/app/interfaces/contributions/main-menu.interface.d.ts +12 -12
- package/dist/app/interfaces/contributions/main-menu.interface.js +2 -2
- package/dist/app/interfaces/contributions/menu-item.interface.d.ts +5 -5
- package/dist/app/interfaces/contributions/menu-item.interface.js +2 -2
- package/dist/app/interfaces/contributions/page-menu-item.interface.d.ts +10 -10
- package/dist/app/interfaces/contributions/page-menu-item.interface.js +2 -2
- package/dist/app/interfaces/contributions/page-menu.interface.d.ts +9 -9
- package/dist/app/interfaces/contributions/page-menu.interface.js +2 -2
- package/dist/app/interfaces/package-json.interface.d.ts +14 -14
- package/dist/app/interfaces/package-json.interface.js +2 -2
- package/dist/app/interfaces/webpack-config.interface.d.ts +5 -5
- package/dist/app/interfaces/webpack-config.interface.js +2 -2
- package/dist/cli/commands/app/build.d.ts +4 -4
- package/dist/cli/commands/app/build.js +43 -43
- package/dist/cli/commands/app/clean.d.ts +3 -3
- package/dist/cli/commands/app/clean.js +15 -15
- package/dist/cli/commands/app/debug.d.ts +3 -3
- package/dist/cli/commands/app/debug.js +22 -22
- package/dist/cli/commands/app/e2e-test.d.ts +3 -3
- package/dist/cli/commands/app/e2e-test.js +23 -23
- package/dist/cli/commands/app/new.d.ts +6 -6
- package/dist/cli/commands/app/new.js +190 -190
- package/dist/cli/commands/app/package.d.ts +3 -3
- package/dist/cli/commands/app/package.js +10 -10
- package/dist/cli/commands/app/post-process.d.ts +8 -8
- package/dist/cli/commands/app/post-process.js +122 -122
- package/dist/cli/commands/app/scaffold.d.ts +4 -4
- package/dist/cli/commands/app/scaffold.js +19 -19
- package/dist/cli/commands/app/unit-test.d.ts +3 -3
- package/dist/cli/commands/app/unit-test.js +11 -11
- package/dist/cli/commands/app/validate.d.ts +3 -3
- package/dist/cli/commands/app/validate.js +20 -20
- package/dist/cli/commands/app/version.d.ts +3 -3
- package/dist/cli/commands/app/version.js +17 -17
- package/dist/cli/commands/app/watch.d.ts +3 -3
- package/dist/cli/commands/app/watch.js +48 -48
- package/dist/cli/commands/scifeon/download.d.ts +3 -3
- package/dist/cli/commands/scifeon/download.js +48 -48
- package/dist/cli/commands/scifeon/run.d.ts +3 -3
- package/dist/cli/commands/scifeon/run.js +41 -41
- package/dist/cli/config.d.ts +11 -11
- package/dist/cli/config.js +23 -23
- package/dist/cli/index.d.ts +9 -9
- package/dist/cli/index.js +159 -159
- package/dist/cli/webpack-runner.d.ts +1 -1
- package/dist/cli/webpack-runner.js +26 -26
- package/dist/download-utils.d.ts +3 -3
- package/dist/download-utils.js +50 -50
- package/dist/file-utils.d.ts +5 -5
- package/dist/file-utils.js +41 -41
- package/dist/html-report.d.ts +15 -15
- package/dist/html-report.js +212 -212
- package/dist/index.d.ts +2 -2
- package/dist/index.js +23 -23
- package/dist/logger.d.ts +14 -14
- package/dist/logger.js +52 -52
- package/dist/measurement-units.d.ts +5 -5
- package/dist/measurement-units.js +9 -9
- package/dist/page-types.d.ts +6 -6
- package/dist/page-types.js +10 -10
- package/dist/plugin-types.d.ts +43 -42
- package/dist/plugin-types.js +47 -46
- package/dist/unit-test-runner.d.ts +1 -1
- package/dist/unit-test-runner.js +82 -82
- package/dist/utils/test-helper.d.ts +4 -4
- package/dist/utils/test-helper.js +46 -46
- package/dist/webpack-app-config.d.ts +2 -2
- package/dist/webpack-app-config.js +248 -248
- package/dist/webpack-utils.d.ts +8 -8
- package/dist/webpack-utils.js +91 -91
- package/package.json +72 -72
- package/resources/new-app/README.md +12 -12
- package/resources/new-app/editor/.vscode/launch.json +40 -40
- package/resources/new-app/gitignore.txt +6 -6
- package/resources/new-app/typescript/src/index.html +14 -14
- package/resources/new-app/typescript/src/index.ts +32 -32
- package/resources/new-app/typescript/test/e2e/frontpage.test.ts +16 -16
- package/resources/new-app/typescript/test/e2e-config.ts +14 -14
- package/resources/new-app/typescript/test/unit/index.test.ts +7 -7
- package/resources/new-app/typescript/tsconfig.json +39 -39
- package/resources/scaffold-templates/scaffold-e2e-test.ts +19 -19
- package/resources/test/chai.js +10706 -10706
- package/resources/test/mocha.css +326 -326
- package/resources/test/mocha.js +16590 -16590
- package/resources/test/tests.html +26 -26
|
@@ -1,460 +1,460 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.AppGenerator = void 0;
|
|
4
|
-
const fs = require("fs");
|
|
5
|
-
const path = require("path");
|
|
6
|
-
const ts = require("typescript");
|
|
7
|
-
const action_target_1 = require("../action-target");
|
|
8
|
-
const file_utils_1 = require("../file-utils");
|
|
9
|
-
const page_types_1 = require("../page-types");
|
|
10
|
-
const plugin_types_1 = require("../plugin-types");
|
|
11
|
-
const app_persist_1 = require("./app-persist");
|
|
12
|
-
const app_validator_1 = require("./app-validator");
|
|
13
|
-
class AppGenerator {
|
|
14
|
-
constructor(config, appType) {
|
|
15
|
-
this.config = config;
|
|
16
|
-
this.appType = appType;
|
|
17
|
-
this.idCounter = 0;
|
|
18
|
-
this.validator = new app_validator_1.AppValidator();
|
|
19
|
-
}
|
|
20
|
-
generate() {
|
|
21
|
-
this.srcFiles = [];
|
|
22
|
-
this.tsFiles = [];
|
|
23
|
-
this.idCounter = 0;
|
|
24
|
-
for (const file of file_utils_1.FileUtils.readDirRecur(path.resolve(this.config.appPath, "src"))) {
|
|
25
|
-
const srcFile = {
|
|
26
|
-
content: fs.readFileSync(file).toString(),
|
|
27
|
-
src: this.normalizePath(file),
|
|
28
|
-
name: "",
|
|
29
|
-
};
|
|
30
|
-
srcFile.name = path.basename(srcFile.src);
|
|
31
|
-
this.srcFiles.push(srcFile);
|
|
32
|
-
if (file.endsWith(".ts")) {
|
|
33
|
-
this.tsFiles.push(srcFile);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
this.packageJson = JSON.parse(fs.readFileSync(path.resolve(this.config.appPath, "package.json")).toString());
|
|
37
|
-
this.transformPackageJson();
|
|
38
|
-
this.contributionsJson = fs.existsSync(path.resolve(this.config.appPath, "contributions.json")) ? JSON.parse(fs.readFileSync(path.resolve(this.config.appPath, "contributions.json")).toString()) : {};
|
|
39
|
-
this.contributionsJson.plugins = this.contributionsJson.plugins || [];
|
|
40
|
-
this.contributionsJson.routes = this.contributionsJson.routes || [];
|
|
41
|
-
this.addCustomElementDecorators();
|
|
42
|
-
this.addDataLoaderDecorators();
|
|
43
|
-
this.addActionDecorators();
|
|
44
|
-
this.addRouteDecorators();
|
|
45
|
-
this.addStepBuilderDecorators();
|
|
46
|
-
this.addDashboardWidgetDecorators();
|
|
47
|
-
this.addGridCardDecorators();
|
|
48
|
-
this.addElnStepSectionDecorators();
|
|
49
|
-
this.addPluginDecorators();
|
|
50
|
-
this.transformContributionsJson();
|
|
51
|
-
this.app = this.generateGenAppJson();
|
|
52
|
-
this.app.type = this.appType;
|
|
53
|
-
this.generateGenAppJs();
|
|
54
|
-
this.jsonDir = path.resolve(this.config.jsonDir, this.app.namespace, this.app.name);
|
|
55
|
-
return this.app;
|
|
56
|
-
}
|
|
57
|
-
save(force = false) {
|
|
58
|
-
new app_persist_1.AppPersist(this.config, this.javascript, this.jsonDir, this.app).save(force);
|
|
59
|
-
}
|
|
60
|
-
transformPackageJson() {
|
|
61
|
-
this.packageJson.name = this.packageJson.name.replace(/\-/g, "_").replace(/\d/g, "_").replace(/\./g, "_");
|
|
62
|
-
this.packageJson.name = this.packageJson.name.replace("@", "").replace("/", "_");
|
|
63
|
-
this.packageJson.scifeon = this.packageJson.scifeon || { contributions: { routes: [], plugins: [] } };
|
|
64
|
-
let versionFile = path.resolve("runtime", "scifeon", "VERSION");
|
|
65
|
-
if (fs.existsSync(versionFile)) {
|
|
66
|
-
const version = fs.readFileSync(versionFile).toString();
|
|
67
|
-
this.packageJson.scifeon.runtimeVersion = version;
|
|
68
|
-
}
|
|
69
|
-
else {
|
|
70
|
-
versionFile = path.resolve("runtime", "scifeon", "wwwroot", "dist", "VERSION");
|
|
71
|
-
if (fs.existsSync(versionFile)) {
|
|
72
|
-
const version = fs.readFileSync(versionFile).toString();
|
|
73
|
-
this.packageJson.scifeon.runtimeVersion = version;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
const cliPackageJsonPath = path.resolve(__dirname, "..", "..", "package.json");
|
|
77
|
-
const cliPackageJson = require(cliPackageJsonPath);
|
|
78
|
-
this.packageJson.scifeon.cliVersion = cliPackageJson.version;
|
|
79
|
-
}
|
|
80
|
-
transformContributionsJson() {
|
|
81
|
-
if (this.contributionsJson.routes) {
|
|
82
|
-
for (const route of this.contributionsJson.routes.filter(r => r.src)) {
|
|
83
|
-
const pageId = `routePage_${route.id}`;
|
|
84
|
-
this.contributionsJson.plugins.push({
|
|
85
|
-
id: pageId,
|
|
86
|
-
src: route.src,
|
|
87
|
-
type: "page",
|
|
88
|
-
chunk: route.chunk,
|
|
89
|
-
});
|
|
90
|
-
delete route.src;
|
|
91
|
-
route.pageId = pageId;
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
if (this.contributionsJson.menu) {
|
|
95
|
-
const notReservedMenus = Object.keys(this.contributionsJson.menu)
|
|
96
|
-
.filter(m => !app_validator_1.AppValidator.reservedMenus.some(rm => rm === m));
|
|
97
|
-
for (const menuKey of notReservedMenus) {
|
|
98
|
-
for (const item of this.contributionsJson.menu[menuKey].items) {
|
|
99
|
-
if (!item.src)
|
|
100
|
-
continue;
|
|
101
|
-
const pluginId = `menuPanel_${menuKey}_${item.src}`;
|
|
102
|
-
this.contributionsJson.plugins.push({
|
|
103
|
-
id: pluginId,
|
|
104
|
-
src: item.src,
|
|
105
|
-
type: "panel.menu",
|
|
106
|
-
});
|
|
107
|
-
delete item.src;
|
|
108
|
-
item.id = pluginId;
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
generateGenAppJson() {
|
|
114
|
-
this.packageJson.scifeon.scopes = this.generateScopes();
|
|
115
|
-
this.validator.validatePackageJson(this.packageJson);
|
|
116
|
-
this.validator.validateContributionsJson(this.contributionsJson, this.config.appPath);
|
|
117
|
-
this.packageJson.scifeon.contributions = this.contributionsJson;
|
|
118
|
-
return this.packageJson;
|
|
119
|
-
}
|
|
120
|
-
generateScopes() {
|
|
121
|
-
const scopes = [];
|
|
122
|
-
const keys = Object.keys(this.contributionsJson);
|
|
123
|
-
for (const key of keys) {
|
|
124
|
-
if (key === "menu") {
|
|
125
|
-
for (const menuItem of Object.keys(this.contributionsJson.menu)) {
|
|
126
|
-
scopes.push(`${key}.${menuItem}`);
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
else if (key === "plugins") {
|
|
130
|
-
for (const plugin of this.contributionsJson.plugins) {
|
|
131
|
-
if (plugin.type) {
|
|
132
|
-
plugin.types = [plugin.type];
|
|
133
|
-
}
|
|
134
|
-
plugin.types = plugin.types || [];
|
|
135
|
-
for (let type of plugin.types) {
|
|
136
|
-
type = `plugins.${type.toLowerCase()}`;
|
|
137
|
-
if (scopes.indexOf(type) === -1) {
|
|
138
|
-
scopes.push(type);
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
else {
|
|
144
|
-
scopes.push(key);
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
return scopes;
|
|
148
|
-
}
|
|
149
|
-
generateGenAppJs() {
|
|
150
|
-
const contributions = this.app.scifeon.contributions;
|
|
151
|
-
this.javascript = [];
|
|
152
|
-
if (contributions.plugins) {
|
|
153
|
-
this.javascript.push("export const plugins = [");
|
|
154
|
-
for (const plugin of contributions.plugins) {
|
|
155
|
-
this.javascript.push("{");
|
|
156
|
-
if (plugin.id) {
|
|
157
|
-
this.javascript.push(` id: '${plugin.id}',`);
|
|
158
|
-
}
|
|
159
|
-
const funcExt = fs.existsSync(`${path.resolve(this.config.appPath, plugin.src)}.ts`) ? "t" : "j";
|
|
160
|
-
if (!plugin.chunk && plugin.types.length === 1) {
|
|
161
|
-
plugin.chunk = plugin.src;
|
|
162
|
-
}
|
|
163
|
-
if (plugin.chunk) {
|
|
164
|
-
this.javascript.push(` func: () => import('../${plugin.src}.${funcExt}s' /* webpackChunkName: '${plugin.chunk}' */),`);
|
|
165
|
-
}
|
|
166
|
-
else {
|
|
167
|
-
this.javascript.push(` func: require('../${plugin.src}.${funcExt}s'),`);
|
|
168
|
-
}
|
|
169
|
-
this.javascript.push(` types: ${JSON.stringify(plugin.types.map(p => p.toLowerCase()))},`);
|
|
170
|
-
if (fs.existsSync(`${path.resolve(this.config.appPath, plugin.src)}.html`)) {
|
|
171
|
-
if (plugin.chunk) {
|
|
172
|
-
this.javascript.push(` view: () => import('../${plugin.src}.html' /* webpackChunkName: '${plugin.chunk}' */),`);
|
|
173
|
-
}
|
|
174
|
-
else {
|
|
175
|
-
this.javascript.push(` view: require('../${plugin.src}.html'),`);
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
this.javascript.push(` file: '${plugin.src}.ts',`);
|
|
179
|
-
if (plugin.chunk) {
|
|
180
|
-
this.javascript.push(` chunk: '${plugin.chunk}',`);
|
|
181
|
-
}
|
|
182
|
-
if (plugin.name) {
|
|
183
|
-
this.javascript.push(` name: '${plugin.name}',`);
|
|
184
|
-
}
|
|
185
|
-
if (plugin.description) {
|
|
186
|
-
this.javascript.push(` description: '${plugin.description}'`);
|
|
187
|
-
}
|
|
188
|
-
this.javascript.push("},");
|
|
189
|
-
}
|
|
190
|
-
this.javascript.push("];");
|
|
191
|
-
this.javascript.push("export const hot = module.hot;");
|
|
192
|
-
this.javascript.push("export const moduleId = module.id;");
|
|
193
|
-
this.javascript.push("export const modules = __webpack_require__.m;");
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
addCustomElementDecorators() {
|
|
197
|
-
const customElementRegex = /@customElement\((.*)\)/i;
|
|
198
|
-
const nameRegex = /('.*'|".*")/i;
|
|
199
|
-
for (const file of this.tsFiles) {
|
|
200
|
-
if (!this.fileIncludesDecorator(file.content, "@customElement"))
|
|
201
|
-
continue;
|
|
202
|
-
const match = customElementRegex.exec(file.content);
|
|
203
|
-
const nameMatch = nameRegex.exec(match[1]);
|
|
204
|
-
this.contributionsJson.plugins.push({
|
|
205
|
-
id: `customElement_${file.src}`,
|
|
206
|
-
src: file.src,
|
|
207
|
-
types: ["html_element"],
|
|
208
|
-
name: nameMatch[1].slice(1, -1),
|
|
209
|
-
});
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
addRouteDecorators() {
|
|
213
|
-
const routeRegex = /@scifeonRoute\s*\(\s*(\{[^]*?\})\s*\)/i;
|
|
214
|
-
for (const file of this.tsFiles) {
|
|
215
|
-
if (!this.fileIncludesDecorator(file.content, "@scifeonRoute"))
|
|
216
|
-
continue;
|
|
217
|
-
const match = routeRegex.exec(file.content);
|
|
218
|
-
const routeObject = new Function("PAGE_TYPE", `return ${match[1]}`)(page_types_1.PAGE_TYPE);
|
|
219
|
-
const route = {
|
|
220
|
-
id: file.src,
|
|
221
|
-
src: file.src,
|
|
222
|
-
route: Array.isArray(routeObject.route) ? routeObject.route : [routeObject.route],
|
|
223
|
-
title: routeObject.title,
|
|
224
|
-
roles: routeObject.roles,
|
|
225
|
-
chunk: routeObject.chunk,
|
|
226
|
-
type: routeObject.type,
|
|
227
|
-
};
|
|
228
|
-
if (route.type === page_types_1.PAGE_TYPE.DATA_ADMINISTRATION) {
|
|
229
|
-
route.roles = route.roles || [];
|
|
230
|
-
route.roles.push("admin");
|
|
231
|
-
route.roles.push("datamanager");
|
|
232
|
-
}
|
|
233
|
-
else if (route.type === page_types_1.PAGE_TYPE.ADMINISTRATION) {
|
|
234
|
-
route.roles = route.roles || [];
|
|
235
|
-
route.roles.push("admin");
|
|
236
|
-
}
|
|
237
|
-
this.contributionsJson.routes.push(route);
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
addElnStepSectionDecorators() {
|
|
241
|
-
const builderRegex = /@scifeonElnStepSection\s*\(\s*(\{[^]*?\})\s*\)/i;
|
|
242
|
-
const idRegex = /id\s*:\s*('.*'|".*")/i;
|
|
243
|
-
for (const file of this.tsFiles) {
|
|
244
|
-
if (!this.fileIncludesDecorator(file.content, "@scifeonElnStepSection"))
|
|
245
|
-
continue;
|
|
246
|
-
const match = builderRegex.exec(file.content);
|
|
247
|
-
const idMatch = idRegex.exec(match[1]);
|
|
248
|
-
const section = {
|
|
249
|
-
id: idMatch[1].slice(1, -1),
|
|
250
|
-
src: file.src,
|
|
251
|
-
type: plugin_types_1.PLUGIN_TYPE.ELN_STEP_SECTION,
|
|
252
|
-
};
|
|
253
|
-
this.contributionsJson.plugins.push(section);
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
addActionDecorators() {
|
|
257
|
-
const actionRegex = /@scifeonAction\s*\(\s*(\{[^]*?\})\s*\)/i;
|
|
258
|
-
const textRegex = /text\s*:\s*('.*'|".*")/i;
|
|
259
|
-
const titleRegex = /title\s*:\s*('.*'|".*")/i;
|
|
260
|
-
const targetRegex = /(ACTION_TARGET\.\w+)/g;
|
|
261
|
-
for (const file of this.tsFiles) {
|
|
262
|
-
if (!this.fileIncludesDecorator(file.content, "@scifeonAction"))
|
|
263
|
-
continue;
|
|
264
|
-
const match = actionRegex.exec(file.content);
|
|
265
|
-
const textMatch = textRegex.exec(match[1]);
|
|
266
|
-
const titleMatch = titleRegex.exec(match[1]);
|
|
267
|
-
const targets = [];
|
|
268
|
-
let target = targetRegex.exec(match[1]);
|
|
269
|
-
while (target) {
|
|
270
|
-
targets.push(target[1]);
|
|
271
|
-
target = targetRegex.exec(match[1]);
|
|
272
|
-
}
|
|
273
|
-
const action = {
|
|
274
|
-
id: file.src,
|
|
275
|
-
src: file.src,
|
|
276
|
-
name: textMatch !== null ? textMatch[1].slice(1, -1) : file.name,
|
|
277
|
-
description: titleMatch !== null ? titleMatch[1].slice(1, -1) : null,
|
|
278
|
-
types: new Function("ACTION_TARGET", `return ["$action." + ${targets.join(`, "$action."`)}]`)(action_target_1.ACTION_TARGET),
|
|
279
|
-
};
|
|
280
|
-
this.contributionsJson.plugins.push(action);
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
|
-
addStepBuilderDecorators() {
|
|
284
|
-
const builderRegex = /@scifeonStepBuilder\s*\(\s*(\{[^]*?\})\s*\)/i;
|
|
285
|
-
const nameRegex = /name\s*:\s*('.*'|".*")/i;
|
|
286
|
-
const idRegex = /id\s*:\s*('.*'|".*")/i;
|
|
287
|
-
const descriptionRegex = /description\s*:\s*('.*'|".*")/i;
|
|
288
|
-
const renderRegex = /render\s*:\s*('.*'|".*")/i;
|
|
289
|
-
const editRegex = /edit\s*:\s*('.*'|".*")/i;
|
|
290
|
-
const previewRegex = /preview\s*:\s*('.*'|".*")/i;
|
|
291
|
-
for (const file of this.tsFiles) {
|
|
292
|
-
if (!this.fileIncludesDecorator(file.content, "@scifeonStepBuilder"))
|
|
293
|
-
continue;
|
|
294
|
-
const match = builderRegex.exec(file.content);
|
|
295
|
-
const nameMatch = nameRegex.exec(match[1]);
|
|
296
|
-
const idMatch = idRegex.exec(match[1]);
|
|
297
|
-
const descriptionMatch = descriptionRegex.exec(match[1]);
|
|
298
|
-
const editMatch = editRegex.exec(match[1]);
|
|
299
|
-
const renderMatch = renderRegex.exec(match[1]);
|
|
300
|
-
const previewMatch = previewRegex.exec(match[1]);
|
|
301
|
-
const builder = {
|
|
302
|
-
id: idMatch[1].slice(1, -1),
|
|
303
|
-
src: file.src,
|
|
304
|
-
name: nameMatch !== null ? nameMatch[1].slice(1, -1) : file.name,
|
|
305
|
-
description: descriptionMatch !== null ? descriptionMatch[1].slice(1, -1) : null,
|
|
306
|
-
type: plugin_types_1.PLUGIN_TYPE.ELN_STEP_BUILDER,
|
|
307
|
-
};
|
|
308
|
-
this.contributionsJson.plugins.push(builder);
|
|
309
|
-
const coreScr = file.src.replace(`/${file.name}`, "");
|
|
310
|
-
if (editMatch) {
|
|
311
|
-
const edit = JSON.parse(JSON.stringify(builder));
|
|
312
|
-
edit.src = `${coreScr}/${editMatch[1].slice(1, -1)}`;
|
|
313
|
-
edit.id += ".$EDIT";
|
|
314
|
-
edit.type += ".$EDIT";
|
|
315
|
-
this.contributionsJson.plugins.push(edit);
|
|
316
|
-
}
|
|
317
|
-
if (renderMatch) {
|
|
318
|
-
const render = JSON.parse(JSON.stringify(builder));
|
|
319
|
-
render.src = `${coreScr}/${renderMatch[1].slice(1, -1)}`;
|
|
320
|
-
render.id += ".$RENDER";
|
|
321
|
-
render.type += ".$RENDER";
|
|
322
|
-
this.contributionsJson.plugins.push(render);
|
|
323
|
-
}
|
|
324
|
-
if (previewMatch) {
|
|
325
|
-
const preview = JSON.parse(JSON.stringify(builder));
|
|
326
|
-
preview.src = `${coreScr}/${previewMatch[1].slice(1, -1)}`;
|
|
327
|
-
preview.id += ".$PREVIEW";
|
|
328
|
-
preview.type += ".$PREVIEW";
|
|
329
|
-
this.contributionsJson.plugins.push(preview);
|
|
330
|
-
}
|
|
331
|
-
}
|
|
332
|
-
}
|
|
333
|
-
addDashboardWidgetDecorators() {
|
|
334
|
-
const builderRegex = /@scifeonDashboardWidget\s*\(\s*(\{[^]*?\})\s*\)/i;
|
|
335
|
-
const nameRegex = /name\s*:\s*('.*'|".*")/i;
|
|
336
|
-
const idRegex = /id\s*:\s*('.*'|".*")/i;
|
|
337
|
-
const descriptionRegex = /description\s*:\s*('.*'|".*")/i;
|
|
338
|
-
for (const file of this.tsFiles) {
|
|
339
|
-
if (!this.fileIncludesDecorator(file.content, "@scifeonDashboardWidget"))
|
|
340
|
-
continue;
|
|
341
|
-
const match = builderRegex.exec(file.content);
|
|
342
|
-
const nameMatch = nameRegex.exec(match[1]);
|
|
343
|
-
const idMatch = idRegex.exec(match[1]);
|
|
344
|
-
const descriptionMatch = descriptionRegex.exec(match[1]);
|
|
345
|
-
const dashboardWidget = {
|
|
346
|
-
id: idMatch[1].slice(1, -1),
|
|
347
|
-
src: file.src,
|
|
348
|
-
name: nameMatch !== null ? nameMatch[1].slice(1, -1) : file.name,
|
|
349
|
-
description: descriptionMatch !== null ? descriptionMatch[1].slice(1, -1) : null,
|
|
350
|
-
type: plugin_types_1.PLUGIN_TYPE.DASHBOARD_WIDGET,
|
|
351
|
-
};
|
|
352
|
-
this.contributionsJson.plugins.push(dashboardWidget);
|
|
353
|
-
const configSrc = `${file.src}-config.ts`;
|
|
354
|
-
if (fs.existsSync(path.resolve(this.config.appPath, configSrc))) {
|
|
355
|
-
const config = JSON.parse(JSON.stringify(dashboardWidget));
|
|
356
|
-
config.src = `${file.src}-config`;
|
|
357
|
-
config.id += ".$CONFIG";
|
|
358
|
-
config.type += ".$CONFIG";
|
|
359
|
-
this.contributionsJson.plugins.push(config);
|
|
360
|
-
}
|
|
361
|
-
}
|
|
362
|
-
}
|
|
363
|
-
addDataLoaderDecorators() {
|
|
364
|
-
const dlRegex = /@scifeonDataLoader\s*\(\s*(\{[^]*?\})\s*\)/i;
|
|
365
|
-
const nameRegex = /name\s*:\s*('.*'|".*")/i;
|
|
366
|
-
const descriptionRegex = /description\s*:\s*('.*'|".*")/i;
|
|
367
|
-
for (const file of this.tsFiles) {
|
|
368
|
-
if (!this.fileIncludesDecorator(file.content, "@scifeonDataLoader"))
|
|
369
|
-
continue;
|
|
370
|
-
const match = dlRegex.exec(file.content);
|
|
371
|
-
const nameMatch = nameRegex.exec(match[1]);
|
|
372
|
-
const descriptionMatch = descriptionRegex.exec(match[1]);
|
|
373
|
-
const dl = {
|
|
374
|
-
id: file.src,
|
|
375
|
-
src: file.src,
|
|
376
|
-
name: nameMatch !== null ? nameMatch[1].slice(1, -1) : file.name,
|
|
377
|
-
description: descriptionMatch !== null ? descriptionMatch[1].slice(1, -1) : null,
|
|
378
|
-
type: plugin_types_1.PLUGIN_TYPE.DATA_LOADER,
|
|
379
|
-
};
|
|
380
|
-
this.contributionsJson.plugins.push(dl);
|
|
381
|
-
}
|
|
382
|
-
}
|
|
383
|
-
addPluginDecorators() {
|
|
384
|
-
const scifeonPluginRegex = /@scifeonPlugin\s*\(\s*(\{[^]*?\})\s*\)/i;
|
|
385
|
-
const pluginTypeRegex = /(PLUGIN_TYPE\.\w+)/g;
|
|
386
|
-
const idRegex = /id\s*:\s*('.*'|".*")/i;
|
|
387
|
-
const nameRegex = /name\s*:\s*('.*'|".*")/i;
|
|
388
|
-
const descriptionRegex = /description\s*:\s*('.*'|".*")/i;
|
|
389
|
-
const chunkRegex = /chunk\s*:\s*('.*'|".*")/i;
|
|
390
|
-
for (const file of this.tsFiles) {
|
|
391
|
-
if (!this.fileIncludesDecorator(file.content, "@scifeonPlugin"))
|
|
392
|
-
continue;
|
|
393
|
-
const match = scifeonPluginRegex.exec(file.content);
|
|
394
|
-
const types = [];
|
|
395
|
-
let type = pluginTypeRegex.exec(match[1]);
|
|
396
|
-
while (type) {
|
|
397
|
-
types.push(type[1]);
|
|
398
|
-
type = pluginTypeRegex.exec(match[1]);
|
|
399
|
-
}
|
|
400
|
-
const idMatch = idRegex.exec(match[1]);
|
|
401
|
-
const id = idMatch !== null ? idMatch[1].slice(1, -1) : `${types.join("_")}_${this.idCounter++}`;
|
|
402
|
-
const nameMatch = nameRegex.exec(match[1]);
|
|
403
|
-
const descriptionMatch = descriptionRegex.exec(match[1]);
|
|
404
|
-
const chunkMatch = chunkRegex.exec(match[1]);
|
|
405
|
-
const plugin = {
|
|
406
|
-
id,
|
|
407
|
-
src: file.src,
|
|
408
|
-
types: new Function("PLUGIN_TYPE", `return [${types.join(", ")}]`)(plugin_types_1.PLUGIN_TYPE),
|
|
409
|
-
name: nameMatch !== null ? nameMatch[1].slice(1, -1) : file.name,
|
|
410
|
-
description: descriptionMatch !== null ? descriptionMatch[1].slice(1, -1) : null,
|
|
411
|
-
chunk: chunkMatch !== null ? chunkMatch[1].slice(1, -1) : null,
|
|
412
|
-
};
|
|
413
|
-
if (plugin.types.some(t => !t)) {
|
|
414
|
-
throw new Error(`A plugin type was not recognized in '${file.src}': ${types}. Maybe you need to update the SDK or change the platform branch?`);
|
|
415
|
-
}
|
|
416
|
-
this.contributionsJson.plugins.push(plugin);
|
|
417
|
-
}
|
|
418
|
-
}
|
|
419
|
-
addGridCardDecorators() {
|
|
420
|
-
const builderRegex = /@scifeonGridCard\s*\(\s*(\{[^]*?\})\s*\)/i;
|
|
421
|
-
const nameRegex = /name\s*:\s*('.*'|".*")/i;
|
|
422
|
-
const idRegex = /id\s*:\s*('.*'|".*")/i;
|
|
423
|
-
for (const file of this.tsFiles) {
|
|
424
|
-
if (!this.fileIncludesDecorator(file.content, "@scifeonGridCard"))
|
|
425
|
-
continue;
|
|
426
|
-
const match = builderRegex.exec(file.content);
|
|
427
|
-
const nameMatch = nameRegex.exec(match[1]);
|
|
428
|
-
const idMatch = idRegex.exec(match[1]);
|
|
429
|
-
const gridCard = {
|
|
430
|
-
id: idMatch[1].slice(1, -1),
|
|
431
|
-
src: file.src,
|
|
432
|
-
name: nameMatch !== null ? nameMatch[1].slice(1, -1) : file.name,
|
|
433
|
-
type: plugin_types_1.PLUGIN_TYPE.GRID_CARD,
|
|
434
|
-
};
|
|
435
|
-
this.contributionsJson.plugins.push(gridCard);
|
|
436
|
-
}
|
|
437
|
-
}
|
|
438
|
-
normalizePath(src) {
|
|
439
|
-
src = src.replace(this.config.appPath, "").replace(/\\/g, "/");
|
|
440
|
-
if (src.toLowerCase().endsWith(".ts")) {
|
|
441
|
-
src = src.substr(0, src.length - 3);
|
|
442
|
-
}
|
|
443
|
-
return src.substr(1);
|
|
444
|
-
}
|
|
445
|
-
fileIncludesDecorator(fileContent, decoratorStr) {
|
|
446
|
-
decoratorStr = decoratorStr.replace("@", "");
|
|
447
|
-
const tsFile = ts.createSourceFile("src.ts", fileContent, ts.ScriptTarget.ESNext);
|
|
448
|
-
for (const statement of tsFile.statements) {
|
|
449
|
-
if (!statement.decorators)
|
|
450
|
-
continue;
|
|
451
|
-
for (const decorator of statement.decorators) {
|
|
452
|
-
const content = decorator.expression.getText(tsFile);
|
|
453
|
-
if (content.startsWith(decoratorStr))
|
|
454
|
-
return true;
|
|
455
|
-
}
|
|
456
|
-
}
|
|
457
|
-
return false;
|
|
458
|
-
}
|
|
459
|
-
}
|
|
460
|
-
exports.AppGenerator = AppGenerator;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AppGenerator = void 0;
|
|
4
|
+
const fs = require("fs");
|
|
5
|
+
const path = require("path");
|
|
6
|
+
const ts = require("typescript");
|
|
7
|
+
const action_target_1 = require("../action-target");
|
|
8
|
+
const file_utils_1 = require("../file-utils");
|
|
9
|
+
const page_types_1 = require("../page-types");
|
|
10
|
+
const plugin_types_1 = require("../plugin-types");
|
|
11
|
+
const app_persist_1 = require("./app-persist");
|
|
12
|
+
const app_validator_1 = require("./app-validator");
|
|
13
|
+
class AppGenerator {
|
|
14
|
+
constructor(config, appType) {
|
|
15
|
+
this.config = config;
|
|
16
|
+
this.appType = appType;
|
|
17
|
+
this.idCounter = 0;
|
|
18
|
+
this.validator = new app_validator_1.AppValidator();
|
|
19
|
+
}
|
|
20
|
+
generate() {
|
|
21
|
+
this.srcFiles = [];
|
|
22
|
+
this.tsFiles = [];
|
|
23
|
+
this.idCounter = 0;
|
|
24
|
+
for (const file of file_utils_1.FileUtils.readDirRecur(path.resolve(this.config.appPath, "src"))) {
|
|
25
|
+
const srcFile = {
|
|
26
|
+
content: fs.readFileSync(file).toString(),
|
|
27
|
+
src: this.normalizePath(file),
|
|
28
|
+
name: "",
|
|
29
|
+
};
|
|
30
|
+
srcFile.name = path.basename(srcFile.src);
|
|
31
|
+
this.srcFiles.push(srcFile);
|
|
32
|
+
if (file.endsWith(".ts")) {
|
|
33
|
+
this.tsFiles.push(srcFile);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
this.packageJson = JSON.parse(fs.readFileSync(path.resolve(this.config.appPath, "package.json")).toString());
|
|
37
|
+
this.transformPackageJson();
|
|
38
|
+
this.contributionsJson = fs.existsSync(path.resolve(this.config.appPath, "contributions.json")) ? JSON.parse(fs.readFileSync(path.resolve(this.config.appPath, "contributions.json")).toString()) : {};
|
|
39
|
+
this.contributionsJson.plugins = this.contributionsJson.plugins || [];
|
|
40
|
+
this.contributionsJson.routes = this.contributionsJson.routes || [];
|
|
41
|
+
this.addCustomElementDecorators();
|
|
42
|
+
this.addDataLoaderDecorators();
|
|
43
|
+
this.addActionDecorators();
|
|
44
|
+
this.addRouteDecorators();
|
|
45
|
+
this.addStepBuilderDecorators();
|
|
46
|
+
this.addDashboardWidgetDecorators();
|
|
47
|
+
this.addGridCardDecorators();
|
|
48
|
+
this.addElnStepSectionDecorators();
|
|
49
|
+
this.addPluginDecorators();
|
|
50
|
+
this.transformContributionsJson();
|
|
51
|
+
this.app = this.generateGenAppJson();
|
|
52
|
+
this.app.type = this.appType;
|
|
53
|
+
this.generateGenAppJs();
|
|
54
|
+
this.jsonDir = path.resolve(this.config.jsonDir, this.app.namespace, this.app.name);
|
|
55
|
+
return this.app;
|
|
56
|
+
}
|
|
57
|
+
save(force = false) {
|
|
58
|
+
new app_persist_1.AppPersist(this.config, this.javascript, this.jsonDir, this.app).save(force);
|
|
59
|
+
}
|
|
60
|
+
transformPackageJson() {
|
|
61
|
+
this.packageJson.name = this.packageJson.name.replace(/\-/g, "_").replace(/\d/g, "_").replace(/\./g, "_");
|
|
62
|
+
this.packageJson.name = this.packageJson.name.replace("@", "").replace("/", "_");
|
|
63
|
+
this.packageJson.scifeon = this.packageJson.scifeon || { contributions: { routes: [], plugins: [] } };
|
|
64
|
+
let versionFile = path.resolve("runtime", "scifeon", "VERSION");
|
|
65
|
+
if (fs.existsSync(versionFile)) {
|
|
66
|
+
const version = fs.readFileSync(versionFile).toString();
|
|
67
|
+
this.packageJson.scifeon.runtimeVersion = version;
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
versionFile = path.resolve("runtime", "scifeon", "wwwroot", "dist", "VERSION");
|
|
71
|
+
if (fs.existsSync(versionFile)) {
|
|
72
|
+
const version = fs.readFileSync(versionFile).toString();
|
|
73
|
+
this.packageJson.scifeon.runtimeVersion = version;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
const cliPackageJsonPath = path.resolve(__dirname, "..", "..", "package.json");
|
|
77
|
+
const cliPackageJson = require(cliPackageJsonPath);
|
|
78
|
+
this.packageJson.scifeon.cliVersion = cliPackageJson.version;
|
|
79
|
+
}
|
|
80
|
+
transformContributionsJson() {
|
|
81
|
+
if (this.contributionsJson.routes) {
|
|
82
|
+
for (const route of this.contributionsJson.routes.filter(r => r.src)) {
|
|
83
|
+
const pageId = `routePage_${route.id}`;
|
|
84
|
+
this.contributionsJson.plugins.push({
|
|
85
|
+
id: pageId,
|
|
86
|
+
src: route.src,
|
|
87
|
+
type: "page",
|
|
88
|
+
chunk: route.chunk,
|
|
89
|
+
});
|
|
90
|
+
delete route.src;
|
|
91
|
+
route.pageId = pageId;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
if (this.contributionsJson.menu) {
|
|
95
|
+
const notReservedMenus = Object.keys(this.contributionsJson.menu)
|
|
96
|
+
.filter(m => !app_validator_1.AppValidator.reservedMenus.some(rm => rm === m));
|
|
97
|
+
for (const menuKey of notReservedMenus) {
|
|
98
|
+
for (const item of this.contributionsJson.menu[menuKey].items) {
|
|
99
|
+
if (!item.src)
|
|
100
|
+
continue;
|
|
101
|
+
const pluginId = `menuPanel_${menuKey}_${item.src}`;
|
|
102
|
+
this.contributionsJson.plugins.push({
|
|
103
|
+
id: pluginId,
|
|
104
|
+
src: item.src,
|
|
105
|
+
type: "panel.menu",
|
|
106
|
+
});
|
|
107
|
+
delete item.src;
|
|
108
|
+
item.id = pluginId;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
generateGenAppJson() {
|
|
114
|
+
this.packageJson.scifeon.scopes = this.generateScopes();
|
|
115
|
+
this.validator.validatePackageJson(this.packageJson);
|
|
116
|
+
this.validator.validateContributionsJson(this.contributionsJson, this.config.appPath);
|
|
117
|
+
this.packageJson.scifeon.contributions = this.contributionsJson;
|
|
118
|
+
return this.packageJson;
|
|
119
|
+
}
|
|
120
|
+
generateScopes() {
|
|
121
|
+
const scopes = [];
|
|
122
|
+
const keys = Object.keys(this.contributionsJson);
|
|
123
|
+
for (const key of keys) {
|
|
124
|
+
if (key === "menu") {
|
|
125
|
+
for (const menuItem of Object.keys(this.contributionsJson.menu)) {
|
|
126
|
+
scopes.push(`${key}.${menuItem}`);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
else if (key === "plugins") {
|
|
130
|
+
for (const plugin of this.contributionsJson.plugins) {
|
|
131
|
+
if (plugin.type) {
|
|
132
|
+
plugin.types = [plugin.type];
|
|
133
|
+
}
|
|
134
|
+
plugin.types = plugin.types || [];
|
|
135
|
+
for (let type of plugin.types) {
|
|
136
|
+
type = `plugins.${type.toLowerCase()}`;
|
|
137
|
+
if (scopes.indexOf(type) === -1) {
|
|
138
|
+
scopes.push(type);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
scopes.push(key);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
return scopes;
|
|
148
|
+
}
|
|
149
|
+
generateGenAppJs() {
|
|
150
|
+
const contributions = this.app.scifeon.contributions;
|
|
151
|
+
this.javascript = [];
|
|
152
|
+
if (contributions.plugins) {
|
|
153
|
+
this.javascript.push("export const plugins = [");
|
|
154
|
+
for (const plugin of contributions.plugins) {
|
|
155
|
+
this.javascript.push("{");
|
|
156
|
+
if (plugin.id) {
|
|
157
|
+
this.javascript.push(` id: '${plugin.id}',`);
|
|
158
|
+
}
|
|
159
|
+
const funcExt = fs.existsSync(`${path.resolve(this.config.appPath, plugin.src)}.ts`) ? "t" : "j";
|
|
160
|
+
if (!plugin.chunk && plugin.types.length === 1) {
|
|
161
|
+
plugin.chunk = plugin.src;
|
|
162
|
+
}
|
|
163
|
+
if (plugin.chunk) {
|
|
164
|
+
this.javascript.push(` func: () => import('../${plugin.src}.${funcExt}s' /* webpackChunkName: '${plugin.chunk}' */),`);
|
|
165
|
+
}
|
|
166
|
+
else {
|
|
167
|
+
this.javascript.push(` func: require('../${plugin.src}.${funcExt}s'),`);
|
|
168
|
+
}
|
|
169
|
+
this.javascript.push(` types: ${JSON.stringify(plugin.types.map(p => p.toLowerCase()))},`);
|
|
170
|
+
if (fs.existsSync(`${path.resolve(this.config.appPath, plugin.src)}.html`)) {
|
|
171
|
+
if (plugin.chunk) {
|
|
172
|
+
this.javascript.push(` view: () => import('../${plugin.src}.html' /* webpackChunkName: '${plugin.chunk}' */),`);
|
|
173
|
+
}
|
|
174
|
+
else {
|
|
175
|
+
this.javascript.push(` view: require('../${plugin.src}.html'),`);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
this.javascript.push(` file: '${plugin.src}.ts',`);
|
|
179
|
+
if (plugin.chunk) {
|
|
180
|
+
this.javascript.push(` chunk: '${plugin.chunk}',`);
|
|
181
|
+
}
|
|
182
|
+
if (plugin.name) {
|
|
183
|
+
this.javascript.push(` name: '${plugin.name}',`);
|
|
184
|
+
}
|
|
185
|
+
if (plugin.description) {
|
|
186
|
+
this.javascript.push(` description: '${plugin.description}'`);
|
|
187
|
+
}
|
|
188
|
+
this.javascript.push("},");
|
|
189
|
+
}
|
|
190
|
+
this.javascript.push("];");
|
|
191
|
+
this.javascript.push("export const hot = module.hot;");
|
|
192
|
+
this.javascript.push("export const moduleId = module.id;");
|
|
193
|
+
this.javascript.push("export const modules = __webpack_require__.m;");
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
addCustomElementDecorators() {
|
|
197
|
+
const customElementRegex = /@customElement\((.*)\)/i;
|
|
198
|
+
const nameRegex = /('.*'|".*")/i;
|
|
199
|
+
for (const file of this.tsFiles) {
|
|
200
|
+
if (!this.fileIncludesDecorator(file.content, "@customElement"))
|
|
201
|
+
continue;
|
|
202
|
+
const match = customElementRegex.exec(file.content);
|
|
203
|
+
const nameMatch = nameRegex.exec(match[1]);
|
|
204
|
+
this.contributionsJson.plugins.push({
|
|
205
|
+
id: `customElement_${file.src}`,
|
|
206
|
+
src: file.src,
|
|
207
|
+
types: ["html_element"],
|
|
208
|
+
name: nameMatch[1].slice(1, -1),
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
addRouteDecorators() {
|
|
213
|
+
const routeRegex = /@scifeonRoute\s*\(\s*(\{[^]*?\})\s*\)/i;
|
|
214
|
+
for (const file of this.tsFiles) {
|
|
215
|
+
if (!this.fileIncludesDecorator(file.content, "@scifeonRoute"))
|
|
216
|
+
continue;
|
|
217
|
+
const match = routeRegex.exec(file.content);
|
|
218
|
+
const routeObject = new Function("PAGE_TYPE", `return ${match[1]}`)(page_types_1.PAGE_TYPE);
|
|
219
|
+
const route = {
|
|
220
|
+
id: file.src,
|
|
221
|
+
src: file.src,
|
|
222
|
+
route: Array.isArray(routeObject.route) ? routeObject.route : [routeObject.route],
|
|
223
|
+
title: routeObject.title,
|
|
224
|
+
roles: routeObject.roles,
|
|
225
|
+
chunk: routeObject.chunk,
|
|
226
|
+
type: routeObject.type,
|
|
227
|
+
};
|
|
228
|
+
if (route.type === page_types_1.PAGE_TYPE.DATA_ADMINISTRATION) {
|
|
229
|
+
route.roles = route.roles || [];
|
|
230
|
+
route.roles.push("admin");
|
|
231
|
+
route.roles.push("datamanager");
|
|
232
|
+
}
|
|
233
|
+
else if (route.type === page_types_1.PAGE_TYPE.ADMINISTRATION) {
|
|
234
|
+
route.roles = route.roles || [];
|
|
235
|
+
route.roles.push("admin");
|
|
236
|
+
}
|
|
237
|
+
this.contributionsJson.routes.push(route);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
addElnStepSectionDecorators() {
|
|
241
|
+
const builderRegex = /@scifeonElnStepSection\s*\(\s*(\{[^]*?\})\s*\)/i;
|
|
242
|
+
const idRegex = /id\s*:\s*('.*'|".*")/i;
|
|
243
|
+
for (const file of this.tsFiles) {
|
|
244
|
+
if (!this.fileIncludesDecorator(file.content, "@scifeonElnStepSection"))
|
|
245
|
+
continue;
|
|
246
|
+
const match = builderRegex.exec(file.content);
|
|
247
|
+
const idMatch = idRegex.exec(match[1]);
|
|
248
|
+
const section = {
|
|
249
|
+
id: idMatch[1].slice(1, -1),
|
|
250
|
+
src: file.src,
|
|
251
|
+
type: plugin_types_1.PLUGIN_TYPE.ELN_STEP_SECTION,
|
|
252
|
+
};
|
|
253
|
+
this.contributionsJson.plugins.push(section);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
addActionDecorators() {
|
|
257
|
+
const actionRegex = /@scifeonAction\s*\(\s*(\{[^]*?\})\s*\)/i;
|
|
258
|
+
const textRegex = /text\s*:\s*('.*'|".*")/i;
|
|
259
|
+
const titleRegex = /title\s*:\s*('.*'|".*")/i;
|
|
260
|
+
const targetRegex = /(ACTION_TARGET\.\w+)/g;
|
|
261
|
+
for (const file of this.tsFiles) {
|
|
262
|
+
if (!this.fileIncludesDecorator(file.content, "@scifeonAction"))
|
|
263
|
+
continue;
|
|
264
|
+
const match = actionRegex.exec(file.content);
|
|
265
|
+
const textMatch = textRegex.exec(match[1]);
|
|
266
|
+
const titleMatch = titleRegex.exec(match[1]);
|
|
267
|
+
const targets = [];
|
|
268
|
+
let target = targetRegex.exec(match[1]);
|
|
269
|
+
while (target) {
|
|
270
|
+
targets.push(target[1]);
|
|
271
|
+
target = targetRegex.exec(match[1]);
|
|
272
|
+
}
|
|
273
|
+
const action = {
|
|
274
|
+
id: file.src,
|
|
275
|
+
src: file.src,
|
|
276
|
+
name: textMatch !== null ? textMatch[1].slice(1, -1) : file.name,
|
|
277
|
+
description: titleMatch !== null ? titleMatch[1].slice(1, -1) : null,
|
|
278
|
+
types: new Function("ACTION_TARGET", `return ["$action." + ${targets.join(`, "$action."`)}]`)(action_target_1.ACTION_TARGET),
|
|
279
|
+
};
|
|
280
|
+
this.contributionsJson.plugins.push(action);
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
addStepBuilderDecorators() {
|
|
284
|
+
const builderRegex = /@scifeonStepBuilder\s*\(\s*(\{[^]*?\})\s*\)/i;
|
|
285
|
+
const nameRegex = /name\s*:\s*('.*'|".*")/i;
|
|
286
|
+
const idRegex = /id\s*:\s*('.*'|".*")/i;
|
|
287
|
+
const descriptionRegex = /description\s*:\s*('.*'|".*")/i;
|
|
288
|
+
const renderRegex = /render\s*:\s*('.*'|".*")/i;
|
|
289
|
+
const editRegex = /edit\s*:\s*('.*'|".*")/i;
|
|
290
|
+
const previewRegex = /preview\s*:\s*('.*'|".*")/i;
|
|
291
|
+
for (const file of this.tsFiles) {
|
|
292
|
+
if (!this.fileIncludesDecorator(file.content, "@scifeonStepBuilder"))
|
|
293
|
+
continue;
|
|
294
|
+
const match = builderRegex.exec(file.content);
|
|
295
|
+
const nameMatch = nameRegex.exec(match[1]);
|
|
296
|
+
const idMatch = idRegex.exec(match[1]);
|
|
297
|
+
const descriptionMatch = descriptionRegex.exec(match[1]);
|
|
298
|
+
const editMatch = editRegex.exec(match[1]);
|
|
299
|
+
const renderMatch = renderRegex.exec(match[1]);
|
|
300
|
+
const previewMatch = previewRegex.exec(match[1]);
|
|
301
|
+
const builder = {
|
|
302
|
+
id: idMatch[1].slice(1, -1),
|
|
303
|
+
src: file.src,
|
|
304
|
+
name: nameMatch !== null ? nameMatch[1].slice(1, -1) : file.name,
|
|
305
|
+
description: descriptionMatch !== null ? descriptionMatch[1].slice(1, -1) : null,
|
|
306
|
+
type: plugin_types_1.PLUGIN_TYPE.ELN_STEP_BUILDER,
|
|
307
|
+
};
|
|
308
|
+
this.contributionsJson.plugins.push(builder);
|
|
309
|
+
const coreScr = file.src.replace(`/${file.name}`, "");
|
|
310
|
+
if (editMatch) {
|
|
311
|
+
const edit = JSON.parse(JSON.stringify(builder));
|
|
312
|
+
edit.src = `${coreScr}/${editMatch[1].slice(1, -1)}`;
|
|
313
|
+
edit.id += ".$EDIT";
|
|
314
|
+
edit.type += ".$EDIT";
|
|
315
|
+
this.contributionsJson.plugins.push(edit);
|
|
316
|
+
}
|
|
317
|
+
if (renderMatch) {
|
|
318
|
+
const render = JSON.parse(JSON.stringify(builder));
|
|
319
|
+
render.src = `${coreScr}/${renderMatch[1].slice(1, -1)}`;
|
|
320
|
+
render.id += ".$RENDER";
|
|
321
|
+
render.type += ".$RENDER";
|
|
322
|
+
this.contributionsJson.plugins.push(render);
|
|
323
|
+
}
|
|
324
|
+
if (previewMatch) {
|
|
325
|
+
const preview = JSON.parse(JSON.stringify(builder));
|
|
326
|
+
preview.src = `${coreScr}/${previewMatch[1].slice(1, -1)}`;
|
|
327
|
+
preview.id += ".$PREVIEW";
|
|
328
|
+
preview.type += ".$PREVIEW";
|
|
329
|
+
this.contributionsJson.plugins.push(preview);
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
addDashboardWidgetDecorators() {
|
|
334
|
+
const builderRegex = /@scifeonDashboardWidget\s*\(\s*(\{[^]*?\})\s*\)/i;
|
|
335
|
+
const nameRegex = /name\s*:\s*('.*'|".*")/i;
|
|
336
|
+
const idRegex = /id\s*:\s*('.*'|".*")/i;
|
|
337
|
+
const descriptionRegex = /description\s*:\s*('.*'|".*")/i;
|
|
338
|
+
for (const file of this.tsFiles) {
|
|
339
|
+
if (!this.fileIncludesDecorator(file.content, "@scifeonDashboardWidget"))
|
|
340
|
+
continue;
|
|
341
|
+
const match = builderRegex.exec(file.content);
|
|
342
|
+
const nameMatch = nameRegex.exec(match[1]);
|
|
343
|
+
const idMatch = idRegex.exec(match[1]);
|
|
344
|
+
const descriptionMatch = descriptionRegex.exec(match[1]);
|
|
345
|
+
const dashboardWidget = {
|
|
346
|
+
id: idMatch[1].slice(1, -1),
|
|
347
|
+
src: file.src,
|
|
348
|
+
name: nameMatch !== null ? nameMatch[1].slice(1, -1) : file.name,
|
|
349
|
+
description: descriptionMatch !== null ? descriptionMatch[1].slice(1, -1) : null,
|
|
350
|
+
type: plugin_types_1.PLUGIN_TYPE.DASHBOARD_WIDGET,
|
|
351
|
+
};
|
|
352
|
+
this.contributionsJson.plugins.push(dashboardWidget);
|
|
353
|
+
const configSrc = `${file.src}-config.ts`;
|
|
354
|
+
if (fs.existsSync(path.resolve(this.config.appPath, configSrc))) {
|
|
355
|
+
const config = JSON.parse(JSON.stringify(dashboardWidget));
|
|
356
|
+
config.src = `${file.src}-config`;
|
|
357
|
+
config.id += ".$CONFIG";
|
|
358
|
+
config.type += ".$CONFIG";
|
|
359
|
+
this.contributionsJson.plugins.push(config);
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
addDataLoaderDecorators() {
|
|
364
|
+
const dlRegex = /@scifeonDataLoader\s*\(\s*(\{[^]*?\})\s*\)/i;
|
|
365
|
+
const nameRegex = /name\s*:\s*('.*'|".*")/i;
|
|
366
|
+
const descriptionRegex = /description\s*:\s*('.*'|".*")/i;
|
|
367
|
+
for (const file of this.tsFiles) {
|
|
368
|
+
if (!this.fileIncludesDecorator(file.content, "@scifeonDataLoader"))
|
|
369
|
+
continue;
|
|
370
|
+
const match = dlRegex.exec(file.content);
|
|
371
|
+
const nameMatch = nameRegex.exec(match[1]);
|
|
372
|
+
const descriptionMatch = descriptionRegex.exec(match[1]);
|
|
373
|
+
const dl = {
|
|
374
|
+
id: file.src,
|
|
375
|
+
src: file.src,
|
|
376
|
+
name: nameMatch !== null ? nameMatch[1].slice(1, -1) : file.name,
|
|
377
|
+
description: descriptionMatch !== null ? descriptionMatch[1].slice(1, -1) : null,
|
|
378
|
+
type: plugin_types_1.PLUGIN_TYPE.DATA_LOADER,
|
|
379
|
+
};
|
|
380
|
+
this.contributionsJson.plugins.push(dl);
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
addPluginDecorators() {
|
|
384
|
+
const scifeonPluginRegex = /@scifeonPlugin\s*\(\s*(\{[^]*?\})\s*\)/i;
|
|
385
|
+
const pluginTypeRegex = /(PLUGIN_TYPE\.\w+)/g;
|
|
386
|
+
const idRegex = /id\s*:\s*('.*'|".*")/i;
|
|
387
|
+
const nameRegex = /name\s*:\s*('.*'|".*")/i;
|
|
388
|
+
const descriptionRegex = /description\s*:\s*('.*'|".*")/i;
|
|
389
|
+
const chunkRegex = /chunk\s*:\s*('.*'|".*")/i;
|
|
390
|
+
for (const file of this.tsFiles) {
|
|
391
|
+
if (!this.fileIncludesDecorator(file.content, "@scifeonPlugin"))
|
|
392
|
+
continue;
|
|
393
|
+
const match = scifeonPluginRegex.exec(file.content);
|
|
394
|
+
const types = [];
|
|
395
|
+
let type = pluginTypeRegex.exec(match[1]);
|
|
396
|
+
while (type) {
|
|
397
|
+
types.push(type[1]);
|
|
398
|
+
type = pluginTypeRegex.exec(match[1]);
|
|
399
|
+
}
|
|
400
|
+
const idMatch = idRegex.exec(match[1]);
|
|
401
|
+
const id = idMatch !== null ? idMatch[1].slice(1, -1) : `${types.join("_")}_${this.idCounter++}`;
|
|
402
|
+
const nameMatch = nameRegex.exec(match[1]);
|
|
403
|
+
const descriptionMatch = descriptionRegex.exec(match[1]);
|
|
404
|
+
const chunkMatch = chunkRegex.exec(match[1]);
|
|
405
|
+
const plugin = {
|
|
406
|
+
id,
|
|
407
|
+
src: file.src,
|
|
408
|
+
types: new Function("PLUGIN_TYPE", `return [${types.join(", ")}]`)(plugin_types_1.PLUGIN_TYPE),
|
|
409
|
+
name: nameMatch !== null ? nameMatch[1].slice(1, -1) : file.name,
|
|
410
|
+
description: descriptionMatch !== null ? descriptionMatch[1].slice(1, -1) : null,
|
|
411
|
+
chunk: chunkMatch !== null ? chunkMatch[1].slice(1, -1) : null,
|
|
412
|
+
};
|
|
413
|
+
if (plugin.types.some(t => !t)) {
|
|
414
|
+
throw new Error(`A plugin type was not recognized in '${file.src}': ${types}. Maybe you need to update the SDK or change the platform branch?`);
|
|
415
|
+
}
|
|
416
|
+
this.contributionsJson.plugins.push(plugin);
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
addGridCardDecorators() {
|
|
420
|
+
const builderRegex = /@scifeonGridCard\s*\(\s*(\{[^]*?\})\s*\)/i;
|
|
421
|
+
const nameRegex = /name\s*:\s*('.*'|".*")/i;
|
|
422
|
+
const idRegex = /id\s*:\s*('.*'|".*")/i;
|
|
423
|
+
for (const file of this.tsFiles) {
|
|
424
|
+
if (!this.fileIncludesDecorator(file.content, "@scifeonGridCard"))
|
|
425
|
+
continue;
|
|
426
|
+
const match = builderRegex.exec(file.content);
|
|
427
|
+
const nameMatch = nameRegex.exec(match[1]);
|
|
428
|
+
const idMatch = idRegex.exec(match[1]);
|
|
429
|
+
const gridCard = {
|
|
430
|
+
id: idMatch[1].slice(1, -1),
|
|
431
|
+
src: file.src,
|
|
432
|
+
name: nameMatch !== null ? nameMatch[1].slice(1, -1) : file.name,
|
|
433
|
+
type: plugin_types_1.PLUGIN_TYPE.GRID_CARD,
|
|
434
|
+
};
|
|
435
|
+
this.contributionsJson.plugins.push(gridCard);
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
normalizePath(src) {
|
|
439
|
+
src = src.replace(this.config.appPath, "").replace(/\\/g, "/");
|
|
440
|
+
if (src.toLowerCase().endsWith(".ts")) {
|
|
441
|
+
src = src.substr(0, src.length - 3);
|
|
442
|
+
}
|
|
443
|
+
return src.substr(1);
|
|
444
|
+
}
|
|
445
|
+
fileIncludesDecorator(fileContent, decoratorStr) {
|
|
446
|
+
decoratorStr = decoratorStr.replace("@", "");
|
|
447
|
+
const tsFile = ts.createSourceFile("src.ts", fileContent, ts.ScriptTarget.ESNext);
|
|
448
|
+
for (const statement of tsFile.statements) {
|
|
449
|
+
if (!statement.decorators)
|
|
450
|
+
continue;
|
|
451
|
+
for (const decorator of statement.decorators) {
|
|
452
|
+
const content = decorator.expression.getText(tsFile);
|
|
453
|
+
if (content.startsWith(decoratorStr))
|
|
454
|
+
return true;
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
return false;
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
exports.AppGenerator = AppGenerator;
|