@abaplint/cli 2.93.6 → 2.93.9

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.
@@ -1,209 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.run = exports.GENERIC_ERROR = void 0;
4
- const fs = require("fs");
5
- const os = require("os");
6
- const path = require("path");
7
- const ProgressBar = require("progress");
8
- const childProcess = require("child_process");
9
- const JSON5 = require("json5");
10
- const core_1 = require("@abaplint/core");
11
- const _format_1 = require("./formatters/_format");
12
- const file_operations_1 = require("./file_operations");
13
- const apack_dependency_provider_1 = require("./apack_dependency_provider");
14
- const fixes_1 = require("./fixes");
15
- const rename_1 = require("./rename");
16
- exports.GENERIC_ERROR = "generic_error";
17
- class Progress {
18
- set(total, _text) {
19
- this.bar = new ProgressBar(":percent - :elapseds - :text", { total, renderThrottle: 100 });
20
- }
21
- async tick(text) {
22
- this.bar.tick({ text });
23
- this.bar.render();
24
- }
25
- tickSync(text) {
26
- this.bar.tick({ text });
27
- this.bar.render();
28
- }
29
- }
30
- function loadConfig(filename) {
31
- // possible cases:
32
- // a) nothing specified, using abaplint.json from cwd
33
- // b) nothing specified, no abaplint.json in cwd
34
- // c) specified and found
35
- // d) specified and not found => use default
36
- // e) supplied but a directory => use default
37
- let f = "";
38
- if (filename === undefined) {
39
- f = process.cwd() + path.sep + "abaplint.json";
40
- if (fs.existsSync(f) === false) {
41
- f = process.cwd() + path.sep + "abaplint.jsonc";
42
- }
43
- if (fs.existsSync(f) === false) {
44
- f = process.cwd() + path.sep + "abaplint.json5";
45
- }
46
- if (fs.existsSync(f) === false) {
47
- process.stderr.write("Using default config\n");
48
- return { config: core_1.Config.getDefault(), base: "." };
49
- }
50
- }
51
- else {
52
- if (fs.existsSync(filename) === false) {
53
- process.stderr.write("ERROR: Specified abaplint configuration file does not exist, using default config\n");
54
- return { config: core_1.Config.getDefault(), base: "." };
55
- }
56
- else if (fs.statSync(filename).isDirectory() === true) {
57
- process.stderr.write("Supply filename, not directory, using default config\n");
58
- return { config: core_1.Config.getDefault(), base: "." };
59
- }
60
- f = filename;
61
- }
62
- // evil hack to get JSON5 working
63
- if (JSON5.parse === undefined) {
64
- // @ts-ignore
65
- JSON5.parse = JSON5.default.parse;
66
- }
67
- process.stderr.write("Using config: " + f + "\n");
68
- const json = fs.readFileSync(f, "utf8");
69
- const parsed = JSON5.parse(json);
70
- const vers = core_1.Version;
71
- if (Object.keys(core_1.Version).some(v => vers[v] === parsed.syntax.version) === false) {
72
- throw "Error: Unknown version in abaplint.json";
73
- }
74
- return {
75
- config: new core_1.Config(json),
76
- base: path.dirname(f) === process.cwd() ? "." : path.dirname(f),
77
- };
78
- }
79
- async function loadDependencies(config, compress, bar, base) {
80
- let files = [];
81
- const deps = config.get().dependencies || [];
82
- const useApack = config.get().global.useApackDependencies;
83
- if (useApack) {
84
- const apackPath = path.join(base, ".apack-manifest.xml");
85
- if (fs.existsSync(apackPath)) {
86
- const apackManifest = fs.readFileSync(apackPath, "utf8");
87
- deps.push(...apack_dependency_provider_1.ApackDependencyProvider.fromManifest(apackManifest));
88
- }
89
- }
90
- if (!deps) {
91
- return [];
92
- }
93
- for (const d of deps) {
94
- if (d.folder) {
95
- const g = base + d.folder + d.files;
96
- const names = file_operations_1.FileOperations.loadFileNames(g, false);
97
- if (names.length > 0) {
98
- process.stderr.write("Using dependency from: " + g + "\n");
99
- files = files.concat(await file_operations_1.FileOperations.loadFiles(compress, names, bar));
100
- continue;
101
- }
102
- }
103
- if (d.url) {
104
- process.stderr.write("Clone: " + d.url + "\n");
105
- const dir = fs.mkdtempSync(path.join(os.tmpdir(), "abaplint-"));
106
- childProcess.execSync("git clone --quiet --depth 1 " + d.url + " .", { cwd: dir, stdio: "inherit" });
107
- const names = file_operations_1.FileOperations.loadFileNames(dir + d.files);
108
- files = files.concat(await file_operations_1.FileOperations.loadFiles(compress, names, bar));
109
- file_operations_1.FileOperations.deleteFolderRecursive(dir);
110
- }
111
- }
112
- return files;
113
- }
114
- function displayHelp() {
115
- // follow https://docopt.org conventions,
116
- return "Usage:\n" +
117
- " abaplint [<abaplint.json> -f <format> -c --outformat <format> --outfile <file> --fix] \n" +
118
- " abaplint -h | --help show this help\n" +
119
- " abaplint -v | --version show version\n" +
120
- " abaplint -d | --default show default configuration\n" +
121
- "\n" +
122
- "Options:\n" +
123
- " -f, --format <format> output format (standard, total, json, summary, junit, codeframe)\n" +
124
- " --outformat <format> output format, use in combination with outfile\n" +
125
- " --outfile <file> output issues to file in format\n" +
126
- " --fix apply quick fixes to files\n" +
127
- " --rename rename object according to rules in abaplint.json\n" +
128
- " -p output performance information\n" +
129
- " -c compress files in memory\n";
130
- }
131
- function out(issues, length, arg) {
132
- const output = _format_1.Formatter.format(issues, arg.format, length);
133
- if (arg.outFormat && arg.outFile) {
134
- const fileContents = _format_1.Formatter.format(issues, arg.outFormat, length);
135
- fs.writeFileSync(arg.outFile, fileContents, "utf-8");
136
- }
137
- return output;
138
- }
139
- async function run(arg) {
140
- var _a, _b;
141
- // evil hack to get JSON5 working
142
- if (JSON5.parse === undefined) {
143
- // @ts-ignore
144
- JSON5.parse = JSON5.default.parse;
145
- }
146
- if (JSON5.stringify === undefined) {
147
- // @ts-ignore
148
- JSON5.stringify = JSON5.default.stringify;
149
- }
150
- let output = "";
151
- let issues = [];
152
- let reg = undefined;
153
- const progress = new Progress();
154
- if (arg.showHelp === true) {
155
- output = output + displayHelp();
156
- }
157
- else if (arg.showVersion === true) {
158
- output = output + core_1.Registry.abaplintVersion() + "\n";
159
- }
160
- else if (arg.outputDefaultConfig === true) {
161
- output = output + JSON.stringify(core_1.Config.getDefault().get(), undefined, 2) + "\n";
162
- }
163
- else {
164
- process.stderr.write("abaplint " + core_1.Registry.abaplintVersion() + "\n");
165
- let loaded = [];
166
- let deps = [];
167
- const { config, base } = loadConfig(arg.configFilename);
168
- try {
169
- if (config.get().global.files === undefined) {
170
- throw "Error: Update abaplint configuration file to latest format";
171
- }
172
- const files = file_operations_1.FileOperations.loadFileNames(base + config.get().global.files);
173
- loaded = await file_operations_1.FileOperations.loadFiles(arg.compress, files, progress);
174
- deps = await loadDependencies(config, arg.compress, progress, base);
175
- reg = new core_1.Registry(config);
176
- reg.addDependencies(deps);
177
- reg.addFiles(loaded); // if the object exists in repo, it should take precedence over deps
178
- await reg.parseAsync({ progress, outputPerformance: arg.parsingPerformance });
179
- if (arg.runFix !== true) {
180
- issues = issues.concat(reg.findIssues({ progress, outputPerformance: arg.parsingPerformance }));
181
- }
182
- }
183
- catch (error) {
184
- const file = new core_1.MemoryFile("generic", "dummy");
185
- const message = error.toString() + " " + ((_b = (_a = error.stack) === null || _a === void 0 ? void 0 : _a.split("\n")[1]) === null || _b === void 0 ? void 0 : _b.trim());
186
- const issue = core_1.Issue.atPosition(file, new core_1.Position(1, 1), message, exports.GENERIC_ERROR);
187
- issues = [issue];
188
- }
189
- let extra = "";
190
- if (arg.runFix === true && reg) {
191
- await new fixes_1.ApplyFixes().applyFixes(reg, fs);
192
- issues = [...reg.findIssues()]; // used in exercism ABAP test runner
193
- extra = "Fixes applied";
194
- }
195
- else if (arg.runRename === true && reg) {
196
- if (issues.length === 0) {
197
- new rename_1.Rename(reg).run(config, base);
198
- extra = "Renames applied";
199
- }
200
- else {
201
- extra = "Renames NOT applied, issues found";
202
- }
203
- }
204
- output = out(issues, loaded.length, arg) + extra;
205
- }
206
- return { output, issues, reg };
207
- }
208
- exports.run = run;
209
- //# sourceMappingURL=index.js.map
@@ -1,98 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Rename = void 0;
4
- const abaplint = require("@abaplint/core");
5
- const path = require("path");
6
- const fs = require("fs");
7
- const file_operations_1 = require("./file_operations");
8
- class Rename {
9
- constructor(reg) {
10
- this.deletedFiles = [];
11
- this.addedFiles = [];
12
- this.reg = reg;
13
- }
14
- run(config, base) {
15
- const rconfig = config.get().rename;
16
- if (rconfig === undefined) {
17
- return;
18
- }
19
- this.skip(rconfig);
20
- this.rename(rconfig);
21
- if (rconfig.output === undefined || rconfig.output === "") {
22
- // write changes inline
23
- this.deletedFiles.forEach(f => {
24
- console.log("rm " + f);
25
- fs.rmSync(f);
26
- });
27
- this.addedFiles.forEach(f => {
28
- console.log("write " + f.getFilename());
29
- fs.writeFileSync(f.getFilename(), f.getRaw());
30
- });
31
- }
32
- else {
33
- // output full registry contents to output folder
34
- this.write(rconfig, base);
35
- }
36
- }
37
- ////////////////////////
38
- write(rconfig, base) {
39
- const outputFolder = base + path.sep + rconfig.output;
40
- console.log("Base: " + base);
41
- console.log("Output folder: " + outputFolder);
42
- file_operations_1.FileOperations.deleteFolderRecursive(outputFolder);
43
- for (const o of this.reg.getObjects()) {
44
- if (this.reg.isDependency(o) === true) {
45
- continue;
46
- }
47
- for (const f of o.getFiles()) {
48
- const n = outputFolder + f.getFilename().replace(base, "");
49
- console.log("Write " + n);
50
- fs.mkdirSync(path.dirname(n), { recursive: true });
51
- fs.writeFileSync(n, f.getRaw());
52
- }
53
- }
54
- }
55
- rename(rconfig) {
56
- const renamer = new abaplint.Rename(this.reg);
57
- for (const o of this.reg.getObjects()) {
58
- if (this.reg.isDependency(o) === true) {
59
- continue;
60
- }
61
- for (const p of rconfig.patterns || []) {
62
- if (!(o.getType().match(p.type))) {
63
- continue;
64
- }
65
- const regex = new RegExp(p.oldName, "i");
66
- const match = regex.exec(o.getName());
67
- if (!match) {
68
- continue;
69
- }
70
- o.getFiles().forEach(f => this.deletedFiles.push(f.getFilename()));
71
- const newStr = o.getName().replace(regex, p.newName);
72
- console.log("Renaming " + o.getName().padEnd(30, " ") + " -> " + newStr);
73
- renamer.rename(o.getType(), o.getName(), newStr);
74
- const newObject = this.reg.getObject(o.getType(), newStr);
75
- newObject === null || newObject === void 0 ? void 0 : newObject.getFiles().forEach(f => this.addedFiles.push(f));
76
- }
77
- }
78
- }
79
- skip(rconfig) {
80
- if (rconfig.skip) {
81
- for (const s of rconfig.skip) {
82
- const all = [];
83
- for (const f of this.reg.getFiles()) {
84
- all.push(f);
85
- }
86
- for (const n of all) {
87
- if (n.getFilename().match(s)) {
88
- console.log(n.getFilename() + " skipped");
89
- this.reg.removeFile(n);
90
- }
91
- }
92
- }
93
- this.reg.parse();
94
- }
95
- }
96
- }
97
- exports.Rename = Rename;
98
- //# sourceMappingURL=rename.js.map