UNPKG

@rushstack/lockfile-explorer

Version:

Rush Lockfile Explorer: The UI for solving version conflicts quickly in a large monorepo

45 lines 2.48 kB
"use strict"; // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.InitAction = void 0; const node_path_1 = __importDefault(require("node:path")); const ts_command_line_1 = require("@rushstack/ts-command-line"); const terminal_1 = require("@rushstack/terminal"); const rush_sdk_1 = require("@rushstack/rush-sdk"); const node_core_library_1 = require("@rushstack/node-core-library"); const common_1 = require("../../../constants/common"); class InitAction extends ts_command_line_1.CommandLineAction { constructor(parser) { super({ actionName: 'init', summary: `Create a new ${common_1.LOCKFILE_LINT_JSON_FILENAME} config file`, documentation: `This command initializes a new ${common_1.LOCKFILE_LINT_JSON_FILENAME} config file.` + ` The created template file includes source code comments that document the settings.` }); this._terminal = parser.globalTerminal; } async onExecuteAsync() { const rushConfiguration = rush_sdk_1.RushConfiguration.tryLoadFromDefaultLocation(); if (!rushConfiguration) { throw new Error('The "lockfile-explorer check" must be executed in a folder that is under a Rush workspace folder'); } const inputFilePath = node_path_1.default.resolve(__dirname, '../../../assets/lint-init/lockfile-lint-template.json'); const outputFilePath = node_path_1.default.resolve(rushConfiguration.commonFolder, 'config', common_1.LOCKFILE_EXPLORER_FOLDERNAME, common_1.LOCKFILE_LINT_JSON_FILENAME); if (await node_core_library_1.FileSystem.existsAsync(outputFilePath)) { this._terminal.writeError('The output file already exists:'); this._terminal.writeLine('\n ' + outputFilePath + '\n'); throw new Error('Unable to write output file'); } this._terminal.writeLine(terminal_1.Colorize.green('Writing file: ') + outputFilePath); await node_core_library_1.FileSystem.copyFileAsync({ sourcePath: inputFilePath, destinationPath: outputFilePath }); } } exports.InitAction = InitAction; //# sourceMappingURL=InitAction.js.map