UNPKG

aws-sdk-js-codemod

Version:

Collection of codemod scripts that help update AWS SDK for JavaScript APIs

83 lines (82 loc) 3.88 kB
#!/usr/bin/env node "use strict"; /* * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: MIT-0 * * Permission is hereby granted, free of charge, to any person obtaining a copy of this * software and associated documentation files (the "Software"), to deal in the Software * without restriction, including without limitation the rights to use, copy, modify, * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to * permit persons to whom the Software is furnished to do so. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); // Most of the code from here is from bin/jscodeshift.js // It's kept that way so that users can reuse jscodeshift options. // @ts-nocheck const node_path_1 = __importDefault(require("node:path")); const Runner_1 = __importDefault(require("jscodeshift/dist/Runner")); const utils_1 = require("./utils"); const args = process.argv; const transforms = (0, utils_1.getTransforms)(); if (args[2] === "--help" || args[2] === "-h") { process.stdout.write((0, utils_1.getHelpParagraph)(transforms)); } const disclaimerLines = [ "╔════════════════════════════════════════════════════════╗", "║ Please review the code change thoroughly for required ║", "║ functionality before deploying it to production. ║", "║ ║", "║ If the transformation is not complete or is incorrect, ║", "║ please report the issue on GitHub. ║", "╚════════════════════════════════════════════════════════╝", "", ]; const parser = (0, utils_1.getJsCodeshiftParser)(); let options; let positionalArguments; try { ({ options, positionalArguments } = parser.parse()); if (positionalArguments.length === 0 && !options.stdin) { process.stderr.write("Error: You have to provide at least one file/directory to transform." + "\n\n---\n\n" + parser.getHelpText()); process.exit(1); } } catch (e) { const exitCode = e.exitCode === undefined ? 1 : e.exitCode; (exitCode ? process.stderr : process.stdout).write(e.message); process.exit(exitCode); } const { transform } = options; if (transforms.map(({ name }) => name).includes(transform)) { const supressDisclaimer = process.env.AWS_SDK_JS_CODEMOD_SUPRESS_WARNING; if (!supressDisclaimer || !supressDisclaimer === "1") { console.warn(disclaimerLines.map((line) => `\n${line}`).join("")); } options.transform = (0, utils_1.getUpdatedTransformFile)(transform); } function run(paths, options) { Runner_1.default.run(/^https?/.test(options.transform) ? options.transform : node_path_1.default.resolve(options.transform), paths, options); } if (options.stdin) { let buffer = ""; process.stdin.on("data", (data) => { buffer += data; }); process.stdin.on("end", () => run(buffer.split("\n"), options)); } else { run(positionalArguments, options); }