1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | var fs = require("fs");
|
4 | var Context_1 = require("./Context");
|
5 | var ApexFile = (function () {
|
6 | function ApexFile(fileName, filePath) {
|
7 | this.errors = new Array();
|
8 | this.fileName = fileName;
|
9 | this.filePath = filePath;
|
10 | this.analyze(this.loadFile());
|
11 | }
|
12 | ApexFile.prototype.loadFile = function () {
|
13 | try {
|
14 | var fileToRead = fs.readFileSync(this.filePath, 'utf-8');
|
15 | return fileToRead;
|
16 | }
|
17 | catch (e) {
|
18 | console.error("❗️ File '" + this.filePath + "' couldn't be read.");
|
19 | }
|
20 | return '';
|
21 | };
|
22 | ApexFile.prototype.analyze = function (fileAsString) {
|
23 | fileAsString = this.replaceStrings(fileAsString);
|
24 | this.mainContext = new Context_1.Context(fileAsString.split('\n'));
|
25 | };
|
26 | ApexFile.prototype.replaceStrings = function (fileAsString) {
|
27 | return fileAsString.replace(/'.{1,}'/g, '');
|
28 | };
|
29 | ApexFile.prototype.getName = function () {
|
30 | return this.fileName;
|
31 | };
|
32 | ApexFile.prototype.printReport = function () {
|
33 | this.errors = this.mainContext.getErrors();
|
34 | if (this.errors.length > 0 && process.exitCode != -1) {
|
35 | process.exitCode = -1;
|
36 | }
|
37 | if (this.errors.length == 0) {
|
38 | console.log(this.fileName + ' ✅ No errors found.');
|
39 | }
|
40 | else {
|
41 | console.log('\n' + this.fileName + ':\n');
|
42 | this.errors.forEach(function (error) {
|
43 | console.log('\t❌ ' + error);
|
44 | });
|
45 | console.log('\n');
|
46 | }
|
47 | };
|
48 | return ApexFile;
|
49 | }());
|
50 | exports.ApexFile = ApexFile;
|