UNPKG

@sap/cf-tools

Version:
32 lines 1.39 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.saveTaskConfiguration = void 0; const fs = require("fs"); const path = require("path"); const _ = require("lodash"); const comment_json_1 = require("comment-json"); const DEFAULT_TASKS_JSON_CONTENT = { version: "2.0.0", tasks: [] }; async function getTaskJsonContentAsJsonObject(taskJsonFilePath) { try { const tasksJsonString = await fs.promises.readFile(taskJsonFilePath, { encoding: "utf8" }); const tasksJson = (0, comment_json_1.parse)(tasksJsonString); return _.assign(DEFAULT_TASKS_JSON_CONTENT, tasksJson); } catch (e) { return DEFAULT_TASKS_JSON_CONTENT; } } async function saveTaskConfiguration(wsFolderPath, configuration) { const taskJsonFilePath = path.join(wsFolderPath, ".vscode", "tasks.json"); const tasksJson = await getTaskJsonContentAsJsonObject(taskJsonFilePath); const existingTaskindex = tasksJson.tasks.findIndex((task) => task.label === configuration.label); if (existingTaskindex >= 0) { tasksJson.tasks[existingTaskindex] = configuration; } else { tasksJson.tasks.push(configuration); } await fs.promises.writeFile(taskJsonFilePath, (0, comment_json_1.stringify)(tasksJson, undefined, " ")); } exports.saveTaskConfiguration = saveTaskConfiguration; //# sourceMappingURL=task.js.map