UNPKG

@hypermod/cli

Version:

To download and run codemods, we provide a CLI tool called @hypermod/cli.

60 lines (53 loc) 2.65 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const path_1 = __importDefault(require("path")); const chalk_1 = __importDefault(require("chalk")); const initializer_1 = require("@hypermod/initializer"); function init(transform, preset, configOnly, targetPath = '.') { return __awaiter(this, void 0, void 0, function* () { const packageName = targetPath !== '.' ? path_1.default.basename(targetPath) : 'Hypermod'; if (configOnly) { (0, initializer_1.initConfig)(packageName, targetPath); } else { (0, initializer_1.initDirectory)(packageName, targetPath); } if (transform) (0, initializer_1.initTransform)(packageName, transform, 'version', targetPath); if (preset) (0, initializer_1.initTransform)(packageName, preset, 'preset', targetPath); if (!configOnly) { console.log(chalk_1.default.green(`🚚 New codemod package created at: ${targetPath}`)); console.log(` Inside that directory, you can run the following commands: ${chalk_1.default.blueBright('npm run dev')} Starts the Hypermod CLI ${chalk_1.default.blueBright('npm run test')} Launches the test runner in watch mode. ${chalk_1.default.blueBright('npm run validate')} Checks the validity of your \`hypermod.config.js\` file ${chalk_1.default.blueBright('npm run build')} Builds the app for production to the \`dist\` folder. Get started by running: ${chalk_1.default.blueBright(`cd ${packageName}`)} ${chalk_1.default.blueBright(`npm install`)} ${chalk_1.default.blueBright(`npm start test`)} `); return; } console.log(chalk_1.default.green(`🚚 New hypermod.config.js created at: ${targetPath}`)); }); } exports.default = init;