1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.module = void 0;
|
4 | const tslib_1 = require("tslib");
|
5 | const inversify_1 = require("inversify");
|
6 | const base_1 = require("./base");
|
7 | const cached_file_system_1 = require("../services/cached-file-system");
|
8 | const ymir_1 = require("@fimbul/ymir");
|
9 | const utils_1 = require("../utils");
|
10 | const path = require("path");
|
11 | let SaveCommandRunner = class SaveCommandRunner extends base_1.AbstractCommandRunner {
|
12 | constructor(fs, logger, directories, options) {
|
13 | super();
|
14 | this.fs = fs;
|
15 | this.logger = logger;
|
16 | this.directories = directories;
|
17 | this.options = options;
|
18 | }
|
19 | run({ command: _command, ...config }) {
|
20 | const newContent = utils_1.format({
|
21 | ...this.options,
|
22 | ...config,
|
23 | cache: config.cache || undefined,
|
24 | fix: config.fix || undefined,
|
25 | reportUselessDirectives: config.reportUselessDirectives || undefined,
|
26 | references: config.references || undefined,
|
27 | }, "yaml" );
|
28 | const filePath = path.join(this.directories.getCurrentDirectory(), '.fimbullinter.yaml');
|
29 | if (newContent.trim() === '{}') {
|
30 | try {
|
31 | this.fs.remove(filePath);
|
32 | this.logger.log("Removed '.fimbullinter.yaml'.");
|
33 | }
|
34 | catch { }
|
35 | }
|
36 | else {
|
37 | this.fs.writeFile(filePath, newContent);
|
38 | this.logger.log("Updated '.fimbullinter.yaml'.");
|
39 | }
|
40 | return true;
|
41 | }
|
42 | };
|
43 | SaveCommandRunner = tslib_1.__decorate([
|
44 | inversify_1.injectable(),
|
45 | tslib_1.__metadata("design:paramtypes", [cached_file_system_1.CachedFileSystem,
|
46 | ymir_1.MessageHandler,
|
47 | ymir_1.DirectoryService,
|
48 | ymir_1.GlobalOptions])
|
49 | ], SaveCommandRunner);
|
50 | exports.module = new inversify_1.ContainerModule((bind) => {
|
51 | bind(base_1.AbstractCommandRunner).to(SaveCommandRunner);
|
52 | });
|
53 |
|
\ | No newline at end of file |