UNPKG

1.99 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.module = void 0;
4const tslib_1 = require("tslib");
5const inversify_1 = require("inversify");
6const base_1 = require("./base");
7const cached_file_system_1 = require("../services/cached-file-system");
8const ymir_1 = require("@fimbul/ymir");
9const utils_1 = require("../utils");
10const path = require("path");
11let 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" /* 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};
43SaveCommandRunner = 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);
50exports.module = new inversify_1.ContainerModule((bind) => {
51 bind(base_1.AbstractCommandRunner).to(SaveCommandRunner);
52});
53//# sourceMappingURL=save.js.map
\No newline at end of file