ics-builder 4.4.10 → 4.4.11

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.
Files changed (85) hide show
  1. package/package.json +1 -1
  2. package/{dist/src → src}/index.js +0 -0
  3. package/.prettierignore +0 -1
  4. package/.prettierrc +0 -7
  5. package/.vscode/launch.json +0 -15
  6. package/.vscode/settings.json +0 -6
  7. package/Dockerfile +0 -32
  8. package/build/modules.yaml +0 -7
  9. package/build.template.yml +0 -51
  10. package/dist/jest.config.js +0 -4
  11. package/dist/package.json +0 -76
  12. package/dist/src/services/source/assets/hostList.yml +0 -12
  13. package/dist/src/services/source/assets/sourceList.yml +0 -50
  14. package/src/app.ts +0 -64
  15. package/src/builder/api/csprojFile.ts +0 -15
  16. package/src/builder/api/dotnetApiBuilder.ts +0 -145
  17. package/src/builder/api/net5Builder.ts +0 -181
  18. package/src/builder/api/webConfigFile.ts +0 -11
  19. package/src/builder/api/xmlFile.ts +0 -24
  20. package/src/builder/baseBuilder.ts +0 -71
  21. package/src/builder/data/dataBuilder.ts +0 -28
  22. package/src/builder/db/dbBuilder.ts +0 -167
  23. package/src/builder/e2e/e2eBuilder.ts +0 -23
  24. package/src/builder/schema/schemaBuilder.ts +0 -156
  25. package/src/builder/ui/customUiBuilder.ts +0 -50
  26. package/src/builder/ui/webpackUiBuilder.ts +0 -497
  27. package/src/builder/uiDependency/dependencyBuilder.ts +0 -38
  28. package/src/builder/winservice/winserviceBuilder.ts +0 -11
  29. package/src/dotnetUtils.ts +0 -41
  30. package/src/exceptions/BuilderException.ts +0 -7
  31. package/src/index.ts +0 -34
  32. package/src/services/buildManager.ts +0 -151
  33. package/src/services/commandManager.ts +0 -78
  34. package/src/services/configManager.ts +0 -82
  35. package/src/services/packageManager.ts +0 -180
  36. package/src/services/packageStructure/legacyPackageStructureManager.ts +0 -34
  37. package/src/services/packageStructure/packageStructureManager.ts +0 -75
  38. package/src/services/packageStructure/structureUtils.ts +0 -66
  39. package/src/services/source/loadPackages.ts +0 -18
  40. package/src/services/source/loaders/baseLoader.ts +0 -28
  41. package/src/services/source/loaders/gitScmProvider.ts +0 -73
  42. package/src/services/source/loaders/hgScmProvider.ts +0 -63
  43. package/src/services/source/sourceManager.ts +0 -95
  44. package/src/services/testManager.ts +0 -27
  45. package/src/testRunners/apiTestRunner.ts +0 -68
  46. package/src/testRunners/baseTestRunner.ts +0 -19
  47. package/src/testRunners/uiTestRunner.ts +0 -8
  48. package/src/utils.ts +0 -228
  49. package/test/sourceManager.test.ts +0 -17
  50. package/tsconfig.json +0 -18
  51. package/wallaby.js +0 -14
  52. /package/{dist/src → src}/app.js +0 -0
  53. /package/{dist/src → src}/builder/api/csprojFile.js +0 -0
  54. /package/{dist/src → src}/builder/api/dotnetApiBuilder.js +0 -0
  55. /package/{dist/src → src}/builder/api/net5Builder.js +0 -0
  56. /package/{dist/src → src}/builder/api/webConfigFile.js +0 -0
  57. /package/{dist/src → src}/builder/api/xmlFile.js +0 -0
  58. /package/{dist/src → src}/builder/baseBuilder.js +0 -0
  59. /package/{dist/src → src}/builder/data/dataBuilder.js +0 -0
  60. /package/{dist/src → src}/builder/db/dbBuilder.js +0 -0
  61. /package/{dist/src → src}/builder/e2e/e2eBuilder.js +0 -0
  62. /package/{dist/src → src}/builder/schema/schemaBuilder.js +0 -0
  63. /package/{dist/src → src}/builder/ui/customUiBuilder.js +0 -0
  64. /package/{dist/src → src}/builder/ui/webpackUiBuilder.js +0 -0
  65. /package/{dist/src → src}/builder/uiDependency/dependencyBuilder.js +0 -0
  66. /package/{dist/src → src}/builder/winservice/winserviceBuilder.js +0 -0
  67. /package/{dist/src → src}/dotnetUtils.js +0 -0
  68. /package/{dist/src → src}/exceptions/BuilderException.js +0 -0
  69. /package/{dist/src → src}/services/buildManager.js +0 -0
  70. /package/{dist/src → src}/services/commandManager.js +0 -0
  71. /package/{dist/src → src}/services/configManager.js +0 -0
  72. /package/{dist/src → src}/services/packageManager.js +0 -0
  73. /package/{dist/src → src}/services/packageStructure/legacyPackageStructureManager.js +0 -0
  74. /package/{dist/src → src}/services/packageStructure/packageStructureManager.js +0 -0
  75. /package/{dist/src → src}/services/packageStructure/structureUtils.js +0 -0
  76. /package/{dist/src → src}/services/source/loadPackages.js +0 -0
  77. /package/{dist/src → src}/services/source/loaders/baseLoader.js +0 -0
  78. /package/{dist/src → src}/services/source/loaders/gitScmProvider.js +0 -0
  79. /package/{dist/src → src}/services/source/loaders/hgScmProvider.js +0 -0
  80. /package/{dist/src → src}/services/source/sourceManager.js +0 -0
  81. /package/{dist/src → src}/services/testManager.js +0 -0
  82. /package/{dist/src → src}/testRunners/apiTestRunner.js +0 -0
  83. /package/{dist/src → src}/testRunners/baseTestRunner.js +0 -0
  84. /package/{dist/src → src}/testRunners/uiTestRunner.js +0 -0
  85. /package/{dist/src → src}/utils.js +0 -0
@@ -1,181 +0,0 @@
1
- import * as path from "path";
2
- import * as shell from "shelljs";
3
-
4
- import { Module, Package } from "src/services/configManager";
5
- import { BaseBuilder, BuilderConfig } from "../baseBuilder";
6
- import { Logger, Utils } from "../../utils";
7
- import { DotnetUtils } from "../../dotnetUtils";
8
- import { packageStructureManager } from "../../services/packageStructure/packageStructureManager";
9
- import { CsprojFile } from "./csprojFile";
10
- import { WebConfigFile } from "./webConfigFile";
11
-
12
- export class Net5ApiBuilder extends BaseBuilder {
13
- private buildApiFolder: string;
14
- private modules = new Array<ApiModuleInfo>();
15
- private allProjects: string[] = [];
16
- private emptyModulesWithConfig: Map<string, string> = new Map<string, string>();
17
-
18
- private configFile = "appsettings.json";
19
-
20
- constructor(config: BuilderConfig) {
21
- super(config);
22
- this.buildApiFolder = path.join(this.config.paths.build, "api");
23
-
24
- shell.config.silent = true;
25
- }
26
-
27
- run(): void | Promise<void> {
28
- this.config.packages.forEach(pkg => {
29
- this.collectModuleInfo(pkg);
30
- });
31
-
32
- // cleanup
33
- this.allProjects.forEach(p => {
34
- this.clearCache(path.dirname(p));
35
- })
36
-
37
- this._build()
38
- }
39
-
40
- private _build() {
41
- if (this.modules.length == 0)
42
- {
43
- Logger.warn("Api layer not found, skipping.");
44
- return;
45
- }
46
-
47
- let configuration = this.config.api?.configuration || "Debug";
48
- this._buildProjects(configuration);
49
- this._buildSolutions(configuration);
50
- }
51
-
52
- private _buildProjects(configuration: string)
53
- {
54
- let coreModule = this.modules.find(m => m.isCoreModule) ?? this.modules[0];
55
- let slnName = "Mdt";
56
- let slnDir = path.dirname(coreModule.buildFile.path);
57
- let tempSlnPath = path.join(slnDir, slnName + ".sln");
58
- let projects = this.modules.map(m => m.buildFile).filter(f => f.type == ApiModuleBuildFileType.Project);
59
-
60
- try {
61
- DotnetUtils.createTempSln(slnDir, slnName);
62
- for(let p of projects)
63
- {
64
- let csproj = new CsprojFile(p.path);
65
- csproj.setPublishPath(p.outputPath);
66
- csproj.save(p.path);
67
- }
68
- DotnetUtils.addProjectsToSln(tempSlnPath, projects.map(p => p.path));
69
- DotnetUtils.restoreNugetPackages(tempSlnPath);
70
- DotnetUtils.publish(tempSlnPath, configuration);
71
- let webConfigFilePath = path.join(coreModule.buildFile.outputPath, "web.config");
72
- let webConfigFile = new WebConfigFile(webConfigFilePath);
73
- webConfigFile.addDotnetProcessPath();
74
- webConfigFile.save();
75
-
76
- projects.filter(p => p.path != coreModule.buildFile.path).forEach(p => {
77
- let projectDir = path.dirname(p.path);
78
- this.copyModuleConfig(projectDir, p.outputPath, this.configFile);
79
- });
80
- this.emptyModulesWithConfig.forEach((val, key) => {
81
- this.copyModuleConfig(val, path.join(this.buildApiFolder, "modules", key), this.configFile);
82
- });
83
- } finally {
84
- Utils.deleteFile(tempSlnPath);
85
- }
86
- }
87
-
88
- private _buildSolutions(configuration: string)
89
- {
90
- let solutions = this.modules.map(m => m.buildFile).filter(f => f.type == ApiModuleBuildFileType.Solution);
91
- if (solutions.length == 0) return;
92
- Logger.info(`building additional solutions`);
93
- solutions.forEach(solution => {
94
- DotnetUtils.restoreNugetPackages(solution.path);
95
- DotnetUtils.publish(solution.path, configuration, solution.outputPath);
96
- })
97
- }
98
-
99
- private collectModuleInfo(pkg: Package): void {
100
- packageStructureManager.getModuleSourcePaths(pkg, "api", this.config).forEach(({ moduleName, sourcePath }) => {
101
- this.writeModulesProjects(pkg.name, pkg.modules.find(m => m.name == moduleName), sourcePath);
102
- });
103
- }
104
-
105
- private writeModulesProjects(packageName: string, module: Module, modulePath: string): void {
106
- let moduleConfig = this.parsePackageInfoLegacy(path.join(modulePath, "module.yml"));
107
-
108
- if (moduleConfig?.api?.project) {
109
- let csprojPath = path.join(modulePath, moduleConfig.api.project);
110
- if (!Utils.ensurePath(csprojPath)) {
111
- Logger.error(`${csprojPath} does not exist`);
112
- return;
113
- }
114
- this.modules.push(new ApiModuleInfo(packageName, module, csprojPath, this.buildApiFolder))
115
- } else {
116
- let files = shell.ls(path.join(modulePath, "*.sln"));
117
- if (files.length) {
118
- this.modules.push(new ApiModuleInfo(packageName, module, files[0], this.buildApiFolder));
119
- } else {
120
- files = shell.ls(path.join(modulePath, "*.csproj"));
121
- if (files.length) {
122
- this.modules.push(new ApiModuleInfo(packageName, module, files[0], this.buildApiFolder))
123
- } else {
124
- Logger.warn(`Module ${module.name} does not have .csproj file and will be skipped`);
125
- let configFile = path.join(modulePath, this.configFile);
126
- if (Utils.ensurePath(configFile))
127
- this.emptyModulesWithConfig.set(packageName + "." + module.name, modulePath);
128
- return;
129
- }
130
- }
131
- }
132
-
133
- this.addProjectFiles(modulePath);
134
- }
135
-
136
- private addProjectFiles(modulePath: string): void {
137
- let files = shell.ls(path.join(modulePath, "*.csproj"), path.join(modulePath, "*", "*.csproj"));
138
- files.forEach(f => {
139
- this.allProjects.push(f);
140
- })
141
- }
142
-
143
- private clearCache(folderPath: string): void {
144
- Utils.deleteAllFoldersRecursively(folderPath, "bin");
145
- Utils.deleteAllFoldersRecursively(folderPath, "obj");
146
- }
147
- }
148
-
149
- class ApiModuleInfo {
150
- package: string;
151
- module: Module;
152
- buildFile: ApiModuleBuildFile;
153
- isCoreModule: boolean;
154
-
155
- constructor(pkg: string, module: Module, buildFilePath: string, buildApiFolder: string) {
156
- this.package = pkg;
157
- this.module = module;
158
- this.isCoreModule = module.name == "_core" && pkg == "mdt";
159
- let outputPath = this.isCoreModule
160
- ? buildApiFolder
161
- : path.join(buildApiFolder, "modules", Utils.getFileName(buildFilePath));
162
- this.buildFile = new ApiModuleBuildFile(buildFilePath, outputPath);
163
- }
164
- }
165
-
166
- class ApiModuleBuildFile {
167
- path: string;
168
- type: ApiModuleBuildFileType;
169
- outputPath: string;
170
-
171
- constructor(path: string, outputPath: string) {
172
- this.path = path;
173
- this.outputPath = outputPath;
174
- this.type = path.endsWith(".csproj") ? ApiModuleBuildFileType.Project : ApiModuleBuildFileType.Solution;
175
- }
176
- }
177
-
178
- enum ApiModuleBuildFileType {
179
- Project,
180
- Solution
181
- }
@@ -1,11 +0,0 @@
1
- import { XmlFile } from "./xmlFile";
2
-
3
- export class WebConfigFile extends XmlFile {
4
- addDotnetProcessPath() {
5
- if (!this._xmlObj) this._readFile();
6
- let aspNetCoreSectionOptions = this._xmlObj.configuration.location["system.webServer"].aspNetCore.$;
7
- aspNetCoreSectionOptions.processPath = "dotnet";
8
- aspNetCoreSectionOptions.arguments = ".\\Mdt.WebApi.dll";
9
- aspNetCoreSectionOptions.stdoutLogEnabled = "false";
10
- }
11
- }
@@ -1,24 +0,0 @@
1
- import * as xml2js from "xml2js";
2
- import * as fs from "fs";
3
-
4
- export class XmlFile {
5
- protected _xmlObj;
6
-
7
- constructor(private _path: string) {
8
-
9
- }
10
-
11
- protected _readFile(): void {
12
- let file = fs.readFileSync(this._path);
13
- xml2js.parseString(file, { explicitArray: false }, (err, result) => {
14
- if (err) throw new Error(`Error while parsing xml file ${this._path}:\n${err.message}`);
15
- this._xmlObj = result
16
- });
17
- }
18
-
19
- save(path: string = null): void {
20
- let builder = new xml2js.Builder();
21
- let xml = builder.buildObject(this._xmlObj);
22
- fs.writeFileSync(path ?? this._path, xml);
23
- }
24
- }
@@ -1,71 +0,0 @@
1
- import * as yaml from "yamljs";
2
- import * as fs from "fs";
3
- import * as path from "path";
4
-
5
- import { Config, Package, PackageInfoLegacy } from "../services/configManager";
6
- import { Utils, Logger } from "../utils";
7
- import { Run } from "../services/commandManager";
8
- import { PackageManager } from "../services/packageManager";
9
-
10
- export interface BuildOptions {
11
- ui?: { mode: string };
12
- multiple?: boolean;
13
- }
14
-
15
- type PartialConfig = Pick<Config, "version" | "paths" | "api" | "ui">;
16
-
17
- export interface BuilderConfig extends PartialConfig {
18
- packages: Array<Package>;
19
- options: BuildOptions;
20
- }
21
-
22
- export abstract class BaseBuilder implements Run {
23
- protected config: BuilderConfig;
24
- protected packageManager: PackageManager;
25
-
26
- constructor(config: BuilderConfig) {
27
- this.config = config;
28
- this.packageManager = PackageManager.getInstance();
29
- Logger.info(`using ${this.constructor.name}`);
30
- }
31
-
32
- abstract run(): void | Promise<void>;
33
-
34
- protected parsePackageInfoLegacy(path: string): PackageInfoLegacy {
35
- return Utils.ensurePath(path) ? <PackageInfoLegacy>yaml.load(path) : {};
36
- }
37
-
38
- protected writeBuildInfo(targetPath: string, object: any, mode: "yml" | "json"): void {
39
- fs.writeFileSync(
40
- targetPath.replace(new RegExp(`.${mode.replace("yml", "ya?ml")}$`), "").concat(`.${mode}`),
41
- mode === "json" ? JSON.stringify(object, null, "\t") : yaml.stringify(object)
42
- );
43
- }
44
-
45
- protected runTests(configPath: string) {
46
- if (Utils.ensurePath(configPath)) {
47
- Logger.info(`Found test config at path ${configPath}, start running tests.`);
48
- const { stdout, stderr, code } = Utils.exec("npx --no-install jest --collectCoverage", {
49
- cwd: path.dirname(configPath),
50
- silent: true
51
- });
52
- if (code) {
53
- let message = `Tests failed\n${stderr}`;
54
- if (this.config.options.ui.mode === "prod") Logger.error(message);
55
- Logger.warn(message);
56
- } else Logger.info(`Tests successfully passed. Coverage report: \n${stdout}`);
57
- }
58
- }
59
-
60
- protected copyModuleConfig(
61
- sourceDir: string,
62
- targetDir: string,
63
- configFileName: string,
64
- newConfigFileName?: string
65
- ): void {
66
- let moduleConfigFile = path.join(sourceDir, configFileName);
67
- if (Utils.ensurePath(moduleConfigFile)) {
68
- Utils.copyFile(moduleConfigFile, path.join(targetDir, newConfigFileName ?? configFileName));
69
- }
70
- }
71
- }
@@ -1,28 +0,0 @@
1
- import * as path from "path";
2
-
3
- import { BaseBuilder, BuilderConfig } from "../baseBuilder";
4
- import { Utils } from "../../utils";
5
- import { packageStructureManager } from "../../services/packageStructure/packageStructureManager";
6
-
7
- export class DataBuilder extends BaseBuilder {
8
- constructor(config: BuilderConfig) {
9
- super(config);
10
- }
11
-
12
- run(): void | Promise<void> {
13
- const dataName = "data";
14
- let targetDir = path.join(this.config.paths.build, dataName);
15
- Utils.prepareDir(targetDir);
16
-
17
- this.config.packages.forEach(pkg => {
18
- packageStructureManager.getModuleSourcePaths(pkg, dataName, this.config).forEach(({moduleName, sourcePath}) => {
19
- let moduleDestinationDir = path.join(targetDir, pkg.name.concat(".", moduleName));
20
-
21
- Utils.copyAllFilesByPattern(sourcePath, moduleDestinationDir, "*.{yaml,yml}");
22
- Utils.copyAllFolders(sourcePath, moduleDestinationDir);
23
- });
24
- });
25
-
26
- Utils.removeEmptyFolders(targetDir);
27
- }
28
- }
@@ -1,167 +0,0 @@
1
- import * as path from "path";
2
- import * as glob from "glob";
3
- import * as xml2js from "xml2js";
4
- import * as yaml from "yamljs";
5
- import * as fs from "fs";
6
-
7
- import { BaseBuilder, BuilderConfig } from "../baseBuilder";
8
- import { Utils, Logger } from "../../utils";
9
- import { packageStructureManager } from "../../services/packageStructure/packageStructureManager";
10
-
11
- export class DbBuilder extends BaseBuilder {
12
- constructor(config: BuilderConfig) {
13
- super(config);
14
- }
15
-
16
- run(): void {
17
- let targetDir = path.join(this.config.paths.build, "db");
18
- Utils.prepareDir(targetDir);
19
-
20
- this.config.packages.forEach(pkg => {
21
- packageStructureManager.getModuleSourcePaths(pkg, "db", this.config).forEach(({moduleName, sourcePath}) => {
22
- let moduleDestinationDir = path.join(targetDir, pkg.name.concat(".", moduleName));
23
-
24
- let filesToConvert = glob.sync(path.join(sourcePath, "data", "**/*.{yml,json}"));
25
- this.convertToXml(filesToConvert, moduleName, path.join(moduleDestinationDir, "data"));
26
-
27
- Utils.copyAllFilesByPattern(
28
- path.join(sourcePath, "data"),
29
- path.join(moduleDestinationDir, "data"),
30
- "**/*.xml"
31
- );
32
- Utils.copyAllFilesByPattern(
33
- path.join(sourcePath, "scripts"),
34
- path.join(moduleDestinationDir, "scripts"),
35
- "**/*.sql"
36
- );
37
- Utils.copyAllFilesByPattern(
38
- path.join(sourcePath, "updates"),
39
- path.join(moduleDestinationDir, "updates"),
40
- "**/*.sql"
41
- );
42
-
43
- let otherUpdatesDirs = fs.readdirSync(sourcePath, { withFileTypes: true })
44
- .filter(d => d.isDirectory())
45
- .map(d => d.name)
46
- .filter(d => d.startsWith("updates."));
47
-
48
- for (let updateDir of otherUpdatesDirs) {
49
- Utils.copyAllFilesByPattern(
50
- path.join(sourcePath, updateDir),
51
- path.join(moduleDestinationDir, updateDir),
52
- "**/*.sql"
53
- );
54
- }
55
-
56
- let otherScriptsDirs = fs.readdirSync(sourcePath, { withFileTypes: true })
57
- .filter(d => d.isDirectory())
58
- .map(d => d.name)
59
- .filter(d => d.startsWith("scripts."));
60
-
61
- for (let scriptDir of otherScriptsDirs) {
62
- Utils.copyAllFilesByPattern(
63
- path.join(sourcePath, scriptDir),
64
- path.join(moduleDestinationDir, scriptDir),
65
- "**/*.sql"
66
- );
67
- }
68
-
69
- if (Utils.ensurePath(moduleDestinationDir)) {
70
- let scriptsPath = path.join(sourcePath, "scripts");
71
- this.GenerateOrderFile(scriptsPath, moduleDestinationDir + "/scripts");
72
-
73
- for (let scriptDir of otherScriptsDirs) {
74
- let otherScriptPath = path.join(sourcePath, scriptDir);
75
- this.GenerateOrderFile(otherScriptPath, moduleDestinationDir + "/" + scriptDir);
76
- }
77
- }
78
- });
79
- });
80
- }
81
-
82
- private GenerateOrderFile(scriptsPath: string, destinationScriptsPath: string)
83
- {
84
- let order = new Array<string>();
85
- let files = new Array<string>();
86
- let dependencies = {};
87
- let dirs = ["view*", "function*", "procedure*", "trigger*", "index*"];
88
-
89
- dirs.forEach(dir => {
90
- files = files.concat(glob.sync(path.join(scriptsPath, dir, "**/*.sql")));
91
- });
92
-
93
- for (var i = 0; i < files.length; i++) files[i] = files[i].replace(/\//g, path.sep);
94
-
95
- let reorder = function (file: string, parent?: string) {
96
- if (file == parent) throw "Circular dependencies! " + parent;
97
-
98
- let deps = dependencies[file];
99
-
100
- deps &&
101
- deps.forEach(dep => {
102
- dep = path.resolve(scriptsPath, dep);
103
- if (files.indexOf(dep) != -1) reorder(dep, parent || file);
104
- });
105
-
106
- if (!parent || order.indexOf(parent) > order.indexOf(file)) return;
107
-
108
- order.splice(order.indexOf(file), 1);
109
- order.splice(order.indexOf(parent), 0, file);
110
- };
111
-
112
- files.forEach(file => {
113
- let deps = (dependencies[file] = []);
114
- let data = fs.readFileSync(file).toString();
115
- data.split("\n").forEach(line => {
116
- var m = line.replace(/^\uFEFF/, "").match(/^--\s*\$dep\s+(.+?)\s*$/);
117
- if (m) {
118
- deps.push(m[1]);
119
- }
120
- });
121
- order.push(file);
122
- });
123
- // reorder
124
- files.forEach(file => {
125
- reorder(file);
126
- });
127
-
128
- if (order.length)
129
- fs.writeFileSync(
130
- destinationScriptsPath + "/order.txt",
131
- order
132
- .map(function (f) {
133
- return path.relative(scriptsPath, f);
134
- })
135
- .join("\n")
136
- );
137
- }
138
-
139
- private convertToXml(paths: Array<string>, module: string, destinationDir: string): void {
140
- paths.forEach(p => {
141
- let obj = null;
142
- let content = fs.readFileSync(p, "utf8").replace(/^\uFEFF/, "");
143
-
144
- try {
145
- switch (path.extname(p)) {
146
- case ".yml":
147
- obj = yaml.parse(content);
148
- break;
149
- case ".json":
150
- obj = JSON.parse(content);
151
- break;
152
- }
153
- } catch (ex) {
154
- Logger.error(`Error parsing file ${p}\n`, ex);
155
- }
156
-
157
- if (obj instanceof Array) obj = { root: obj };
158
-
159
- let xmlBuilder = new xml2js.Builder();
160
- let xml = xmlBuilder.buildObject(obj);
161
- let fileName = path.basename(p).replace(path.extname(p), ".xml");
162
-
163
- Utils.ensureFolder(destinationDir);
164
- fs.writeFileSync(path.join(destinationDir, fileName), xml);
165
- });
166
- }
167
- }
@@ -1,23 +0,0 @@
1
- import * as path from "path";
2
-
3
- import { BaseBuilder, BuilderConfig } from "../baseBuilder";
4
- import { Utils } from "../../utils";
5
-
6
- export class E2EBuilder extends BaseBuilder {
7
- constructor(config: BuilderConfig) {
8
- super(config);
9
- }
10
-
11
- run(): void | Promise<void> {
12
- this.config.packages.forEach(pkg => {
13
- let sourceDir = path.join(this.config.paths.source, pkg.name, "e2e");
14
- if (Utils.ensurePath(sourceDir)) {
15
- let targetDir = path.join(this.config.paths.build, "e2e", pkg.name);
16
- Utils.copyFolder(sourceDir, targetDir);
17
- let hgFolder = path.join(targetDir, ".hg");
18
- Utils.clearFolder(hgFolder);
19
- Utils.removeEmptyFolders(targetDir);
20
- }
21
- });
22
- }
23
- }
@@ -1,156 +0,0 @@
1
- import { BaseBuilder, BuilderConfig } from "../baseBuilder";
2
- import { Utils, Logger } from "../../utils";
3
- import * as Path from "path";
4
- import * as fs from "fs";
5
- import * as TJS from "typescript-json-schema";
6
-
7
- interface schemaFile {
8
- path: string;
9
- schemaName: string;
10
- }
11
-
12
- const tempInterfaceExt = "Ext";
13
-
14
- export class SchemaBuilder extends BaseBuilder {
15
- constructor(config: BuilderConfig) {
16
- super(config);
17
- }
18
-
19
- run(): void | Promise<void> {
20
- this.config.packages.forEach(pkg => {
21
- if (!pkg.isLegacy) return;
22
- Logger.info(`Generating schema for ${pkg.name}...`)
23
- let sourcePath = Path.join(this.config.paths.source, pkg.name, "ui");
24
- if (!Utils.ensurePath(sourcePath) || !pkg.modules) return;
25
- if (this.config.options.multiple) {
26
- pkg.modules.forEach(module => {
27
- let modulePath = Path.join(sourcePath, module.name);
28
- if (!Utils.ensurePath(modulePath)) return;
29
- let schemaFiles = this._findInterfaces(modulePath);
30
- this._createSchemaFiles(sourcePath, modulePath, schemaFiles);
31
- });
32
- } else {
33
- let interfaces = new Map<string, schemaFile[]>()
34
- pkg.modules.forEach(module => {
35
- let modulePath = Path.join(sourcePath, module.name);
36
- if (!Utils.ensurePath(modulePath)) return;
37
- let schemaFiles = this._findInterfaces(modulePath);
38
- for (let file of schemaFiles) {
39
- if (!interfaces.has(file.schemaName)) interfaces.set(file.schemaName, []);
40
- interfaces.get(file.schemaName).push(file);
41
- }
42
- });
43
- this._createSchemaFile(sourcePath, interfaces);
44
- }
45
- });
46
- }
47
-
48
- private _findInterfaces(path: string): schemaFile[] {
49
- let interfacePaths: schemaFile[] = [];
50
- let files = fs.readdirSync(path);
51
- files.forEach(file => {
52
- let filePath = Path.join(path, file);
53
- let stat = fs.statSync(filePath);
54
- if (stat.isDirectory()) {
55
- interfacePaths.push(...this._findInterfaces(filePath));
56
- } else {
57
- let regex = /(.*)\.schema\.ts$/.exec(file);
58
- if (regex) interfacePaths.push({ path: filePath, schemaName: regex[1] });
59
- }
60
- });
61
- return interfacePaths;
62
- }
63
-
64
- private _createSchemaFiles(path: string, modulePath: string, schemaFiles: schemaFile[]): void {
65
- if (schemaFiles.length === 0) return;
66
- this._createSchema(path, modulePath, schemaFiles.map(f => f.path), schemaFiles.map(f => f.schemaName));
67
- }
68
-
69
- private _createSchemaFile(path: string, interfaces: Map<string, schemaFile[]>): void {
70
- let symbolsPath: string[] = [];
71
- let tempFiles: string[] = [];
72
- let symbols: string[] = [];
73
- let extSymbols: string[] = [];
74
- interfaces.forEach((interf, name) => {
75
- if (interf.length > 1) {
76
- let tempFile = this._createTempFile(path, name, interf);
77
- symbolsPath.push(tempFile);
78
- tempFiles.push(tempFile);
79
- extSymbols.push(interf[0].schemaName + tempInterfaceExt)
80
- } else {
81
- symbolsPath.push(interf[0].path);
82
- symbols.push(interf[0].schemaName);
83
- }
84
- });
85
-
86
- this._createSchema(path, path, symbolsPath, symbols, extSymbols);
87
- this._deleteTempFiles(tempFiles);
88
- }
89
-
90
- private _createSchema(sourcePath: string, schemaPath: string, symbolsPath: string[], symbolsName: string[], extSymbolsName?: string[]) {
91
- const settings: TJS.PartialArgs = {
92
- ignoreErrors: true,
93
- validationKeywords: ["markdownDescription", "defaultSnippets", "title"],
94
- required: true,
95
- excludePrivate: true
96
- };
97
- const tsConfigPath = Path.join(sourcePath, "tsconfig.json");
98
- if (!Utils.ensurePath(tsConfigPath)) {
99
- Logger.info(`File ${tsConfigPath} not found. Skipping...`);
100
- return;
101
- }
102
- logger.disableLogger();
103
- const program = TJS.programFromConfig(tsConfigPath, symbolsPath);
104
- const generator = TJS.buildGenerator(program, settings);
105
- let schema = generator.getSchemaForSymbols(extSymbolsName ? symbolsName.concat(extSymbolsName) : symbolsName);
106
- if (extSymbolsName && schema.definitions) {
107
- extSymbolsName.forEach(symbol => {
108
- schema.definitions[symbol.slice(0, symbol.length - tempInterfaceExt.length)] = schema.definitions[symbol];
109
- delete schema.definitions[symbol];
110
- })
111
- let orderedDefinitions = Object.keys(schema.definitions).sort().reduce((obj, key) => {obj[key] = schema.definitions[key]; return obj}, {});
112
- schema.definitions = orderedDefinitions;
113
- }
114
- logger.enableLogger();
115
- Utils.ensureFolder(schemaPath);
116
- fs.writeFileSync(Path.join(schemaPath, "json-schema.json"), JSON.stringify(schema, null, 4));
117
- }
118
-
119
- private _createTempFile(path: string, schemaName: string, schemaFiles: schemaFile[]): string {
120
- if (!schemaFiles || schemaFiles.length == 0) return null;
121
- let fileContent = schemaFiles.map((schemaFile, idx) => {
122
- return `import {${schemaName} as ${schemaName + idx}} from "${schemaFile.path.replace(/\\/g, "\\\\").replace(/\.ts$/g,"")}"`;
123
- }).join("\n");
124
- fileContent += `\ninterface ${schemaName + tempInterfaceExt} extends ${schemaFiles.map((f, idx) => schemaName + idx).join(", ")} {}`;
125
- let tempFilePath = Path.join(path, `tempSchema${schemaName}.ts`);
126
- fs.writeFileSync(tempFilePath, fileContent, {encoding: "utf8"});
127
- return tempFilePath;
128
- }
129
-
130
- private _deleteTempFiles(paths: string[]): void {
131
- paths.forEach(path => fs.unlinkSync(path));
132
- }
133
- }
134
-
135
- let logger = function()
136
- {
137
- let oldConsoleLog = null;
138
- let oldConsoleWarn = null
139
- let pub = {enableLogger: null, disableLogger: null};
140
-
141
- pub.enableLogger = function enableLogger()
142
- {
143
- if(oldConsoleLog != null) console.log = oldConsoleLog;
144
- if(oldConsoleWarn != null) console.warn = oldConsoleWarn;
145
- };
146
-
147
- pub.disableLogger = function disableLogger()
148
- {
149
- oldConsoleLog = console.log;
150
- oldConsoleWarn = console.warn;
151
- console.log = function() {};
152
- console.warn = function() {};
153
- };
154
-
155
- return pub;
156
- }();