diff --git a/package.json b/package.json index e962550..28125bf 100755 --- a/package.json +++ b/package.json @@ -36,7 +36,6 @@ "js-yaml": "^4.1.0", "lodash": "^4.17.21", "mocha": "^10.2.0", - "ora": "^8.2.0", "path": "^0.12.7", "pino-pretty": "^10.2.0", "proxyquire": "^2.1.3", diff --git a/src/commands/devops-plugin/index.ts b/src/commands/devops-plugin/index.ts index 2bb5dba..573e645 100644 --- a/src/commands/devops-plugin/index.ts +++ b/src/commands/devops-plugin/index.ts @@ -18,11 +18,11 @@ const installAction = async (gsDevOpsPlugin: string) => { } if (!existsSync(path.join(gsDevopsPluginsDir, "package.json"))) { - spawnSync("npm", ["init", "--yes"], { cwd: gsDevopsPluginsDir }); + spawnSync("pnpm", ["init"], { cwd: gsDevopsPluginsDir, stdio: 'ignore' }); } // npm install in the directory - spawnSync("npm", ["i", `${gsDevOpsPlugin}`], { + spawnSync("pnpm", ["add", `${gsDevOpsPlugin}`], { cwd: gsDevopsPluginsDir, stdio: "inherit", }); @@ -69,8 +69,8 @@ const list = program } else { // fetch the list of packages, maybe from the plugins repository let npmSearch = spawnSync( - "npm", - ["search", `@godspeedsystems/devops-plugin`, "--json"], + "pnpm", + ["search", "--json", `@godspeedsystems/devops-plugin`], { encoding: "utf-8" } ); let availablePlugins: @@ -149,7 +149,7 @@ const remove = program ]); // uninstallDevOpsPlugin(answer.gsDevOpsPlugin) - spawnSync("npm", ["uninstall", `${answer.gsDevOpsPlugin}`], { + spawnSync("pnpm", ["remove", `${answer.gsDevOpsPlugin}`], { cwd: gsDevopsPluginsDir, stdio: "inherit", }); @@ -195,7 +195,7 @@ const update = program ]); // npm install in the directory - spawnSync("npm", ["install", `${answer.gsDevOpsPlugin}@latest`], { + spawnSync("pnpm", ["add", `${answer.gsDevOpsPlugin}@latest`], { cwd: gsDevopsPluginsDir, stdio: "inherit", }); diff --git a/src/commands/otel/index.ts b/src/commands/otel/index.ts index 4326f53..9b2cf43 100644 --- a/src/commands/otel/index.ts +++ b/src/commands/otel/index.ts @@ -3,41 +3,29 @@ import spawnSync from "cross-spawn"; import path from "path"; import { readFile, writeFile } from "fs/promises" import fs from "fs"; -import ora from 'ora'; -// const projectDirPath = path.resolve(process.cwd(), projectName); - const program = new Command(); -const spinner = ora({ - text: 'Installing packages... ', - spinner: { - frames: ['šŸŒ ', 'šŸŒŽ ', 'šŸŒ ', '🌐 ', 'šŸŒ‘ ', 'šŸŒ’ ', 'šŸŒ“ ', 'šŸŒ” '], - interval: 180, - }, -}); const enableAction = async () => { // install that package - async function installtracing(tracing:any) { - try { - spinner.start(); - - const child = spawnSync('npm', ['install', `${tracing}`, '--quiet', '--no-warnings', '--silent', '--progress=false'], { - stdio: 'inherit', - }); - - await new Promise((resolve) => { - child.on('close', () => { - resolve(); - }); + async function installtracing(tracing: string) { + console.log(`Installing ${tracing}...`); + try { + const child = spawnSync('pnpm', ['add', tracing, '--reporter=silent'], { + stdio: 'inherit', + }); + + await new Promise((resolve) => { + child.on('close', () => { + resolve(); }); - - spinner.stop(); - console.log('\notel installed successfully!'); - } catch (error:any) { - spinner.stop(); - console.error('Error during installation:', error.message); - } + }); + + console.log('\nOpenTelemetry installed successfully!'); + } catch (error: any) { + console.error('Error during installation:', error.message); + throw error; } + } // Call the installPlugin function try { @@ -67,28 +55,25 @@ const enableAction = async () => { const disableAction = async () => { // uninstall that package - async function uninstalltracing(tracing:any) { - try { - spinner.start(); - - // Use spawnCommand instead of spawnSync - const child = spawnSync('npm', ['uninstall', `${tracing}`, '--quiet', '--no-warnings', '--silent', '--progress=false'], { - stdio: 'inherit', // Redirect output - }); - - await new Promise((resolve) => { - child.on('close', () => { - resolve(); - }); + async function uninstalltracing(tracing: string) { + console.log(`Uninstalling ${tracing}...`); + try { + const child = spawnSync('pnpm', ['remove', tracing], { + stdio: 'inherit', + }); + + await new Promise((resolve) => { + child.on('close', () => { + resolve(); }); - - spinner.stop(); - console.log('\notel uninstalled successfully!'); - } catch (error:any) { - spinner.stop(); - console.error('Error during uninstallation:', error.message); - } + }); + + console.log('\nOpenTelemetry uninstalled successfully!'); + } catch (error: any) { + console.error('Error during uninstallation:', error.message); + throw error; } + } // Call the uninstallPlugin function diff --git a/src/commands/plugin/index.ts b/src/commands/plugin/index.ts index ff16195..21000fa 100644 --- a/src/commands/plugin/index.ts +++ b/src/commands/plugin/index.ts @@ -13,7 +13,6 @@ import inquirer from "inquirer"; import * as yaml from "js-yaml"; import { cwd } from "process"; import chalk from "chalk"; -import ora from "ora"; const pluginsFilePath = path.resolve(__dirname, '../../../pluginsList.json'); if (!fs.existsSync(pluginsFilePath)) { @@ -176,14 +175,7 @@ export default EventSource; } const addAction = async (pluginsList: string[]) => { - const spinner = ora({ - text: "Installing plugins... ", - spinner: { - frames: ["šŸŒ ", "šŸŒŽ ", "šŸŒ ", "🌐 ", "šŸŒ‘ ", "šŸŒ’ ", "šŸŒ“ ", "šŸŒ” "], - interval: 180, - }, - }); - + console.log('Searching for plugin...'); async function installPlugin(pluginsList: string[]) { try { console.log("Starting plugin installation..."); @@ -193,19 +185,9 @@ const addAction = async (pluginsList: string[]) => { const packageManager = hasPnpm ? "pnpm" : "npm"; console.log(`Using package manager: ${packageManager}`); - - spinner.text = `Installing plugins with ${packageManager}...`; - spinner.start(); - + console.log(`Installing plugins with ${packageManager}...`); const startTime = Date.now(); - let dots = 0; - const intervalId = setInterval(() => { - dots = (dots + 1) % 4; - const elapsed = Math.floor((Date.now() - startTime) / 1000); - spinner.text = `Installing plugins with ${packageManager}${'.'.repeat(dots)} (${elapsed}s elapsed)`; - }, 1000); - return new Promise((resolve, reject) => { const { exec } = require('child_process'); @@ -237,10 +219,8 @@ const addAction = async (pluginsList: string[]) => { }); childProcess.on('exit', (code: number) => { - clearInterval(intervalId); - if (code !== 0) { - spinner.stop(); + console.error(`Installation failed with exit code: ${code}`); console.error("Error output:", stderrData || "No error output"); reject(new Error(`Process exited with code ${code}`)); @@ -248,15 +228,15 @@ const addAction = async (pluginsList: string[]) => { } const totalTime = ((Date.now() - startTime) / 1000).toFixed(1); - spinner.stop(); - console.log(`\nPlugins installed successfully in ${totalTime}s!`); + + console.log(`\nāœ“ All plugins installed successfully in ${totalTime}s!`); console.log(`Installed plugins: ${pluginsList.join(', ')}`); console.log(chalk.cyan.bold("Happy coding with Godspeed! šŸš€šŸŽ‰\n")); resolve(); }); }); } catch (error: any) { - spinner.stop(); + console.error("Error during installation:", error.message); throw error; } @@ -525,26 +505,16 @@ const add = program }); const removeAction = async (pluginsList: string[]) => { - const spinner = ora({ - text: "Uninstalling plugins... ", - spinner: { - frames: ["šŸŒ ", "šŸŒŽ ", "šŸŒ ", "🌐 ", "šŸŒ‘ ", "šŸŒ’ ", "šŸŒ“ ", "šŸŒ” "], - interval: 180, - }, - }); async function uninstallPlugin(pluginsList: string[]) { try { - spinner.start(); - + console.log("Uninstalling plugins..."); + const child = spawnSync( - "npm", + "pnpm", [ - "uninstall", + "remove", ...pluginsList, - "--quiet", - "--no-warnings", - "--silent", - "--progress=false", + "--reporter=silent" ], { stdio: "inherit", @@ -557,11 +527,11 @@ const removeAction = async (pluginsList: string[]) => { }); }); - spinner.stop(); + console.log("\nPlugins uninstalled successfully!"); console.log(chalk.cyan.bold("Happy coding with Godspeed! šŸš€šŸŽ‰\n")); } catch (error: any) { - spinner.stop(); + console.error("Error during installation:", error.message); } } @@ -742,26 +712,16 @@ const update = program return; } - const spinner = ora({ - text: "Updating plugins... ", - spinner: { - frames: ["šŸŒ ", "šŸŒŽ ", "šŸŒ ", "🌐 ", "šŸŒ‘ ", "šŸŒ’ ", "šŸŒ“ ", "šŸŒ” "], - interval: 180, - }, - }); async function updatePlugin(pluginsList: string[]) { try { - spinner.start(); - + console.log("Updating plugins..."); + const child = spawnSync( - "npm", + "pnpm", [ "update", ...pluginsList, - "--quiet", - "--no-warnings", - "--silent", - "--progress=false", + "--reporter=silent" ], { stdio: "inherit", @@ -774,11 +734,11 @@ const update = program }); }); - spinner.stop(); + console.log("\nPlugins updated successfully!"); console.log(chalk.cyan.bold("Happy coding with Godspeed! šŸš€šŸŽ‰\n")); } catch (error: any) { - spinner.stop(); + console.error("Error during updation:", error.message); } } diff --git a/src/index.ts b/src/index.ts index 2ce1634..35f2116 100755 --- a/src/index.ts +++ b/src/index.ts @@ -211,7 +211,7 @@ const updateServicesJson = async (add = true) => { .description("run godspeed development server.") .action(async () => { if (await isAGodspeedProject()) { - spawnSync("npm", ["run", "dev"], { + spawnSync("pnpm", ["run", "dev"], { stdio: "inherit", }); } @@ -222,7 +222,7 @@ const updateServicesJson = async (add = true) => { .description(`clean the previous build.`) .action(async (options) => { if (isAGodspeedProject()) { - spawnSync("npm", ["run", "clean"], { + spawnSync("pnpm", ["run", "clean"], { stdio: "inherit", }); } @@ -253,7 +253,7 @@ const updateServicesJson = async (add = true) => { ) .action(async () => { if (isAGodspeedProject()) { - spawnSync("npm", ["run", "gen-crud-api"], { stdio: "inherit" }); + spawnSync("pnpm", ["run", "gen-crud-api"], { stdio: "inherit" }); } }); program @@ -271,7 +271,7 @@ const updateServicesJson = async (add = true) => { .description("build the godspeed project. create a production build.") .action(async (options) => { if (await isAGodspeedProject()) { - spawnSync("npm", ["run", "build"], { + spawnSync("pnpm", ["run", "build"], { stdio: "inherit", env: { // NODE_ENV: "production", @@ -285,7 +285,7 @@ const updateServicesJson = async (add = true) => { .description("preview the production build.") .action(async (options) => { if (await isAGodspeedProject()) { - spawnSync("npm", ["run", "preview"], { + spawnSync("pnpm", ["run", "preview"], { stdio: "inherit", env: { // NODE_ENV: "production", @@ -352,7 +352,7 @@ const updateServicesJson = async (add = true) => { .description("build and preview the production build in watch mode.") .action(async (options) => { if (await isAGodspeedProject()) { - spawnSync("npm", ["run", "serve"], { + spawnSync("pnpm", ["run", "serve"], { stdio: "inherit", env: { // NODE_ENV: "production", diff --git a/src/utils/index.ts b/src/utils/index.ts index 7a59a54..a8cdad2 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -10,7 +10,6 @@ import simpleGit from "simple-git"; import chalk from "chalk"; import { spawnSync } from "child_process"; import spawnCommand from "cross-spawn"; -import ora from "ora"; import { yamlLoader as loadYaml, generateSwaggerJSON, @@ -252,35 +251,27 @@ export const installDependencies = async ( projectDirPath: string, projectName: string ) => { - const spinner = ora({ - spinner: { - frames: ["šŸŒ ", "šŸŒŽ ", "šŸŒ ", "🌐 ", "šŸŒ‘ ", "šŸŒ’ ", "šŸŒ“ ", "šŸŒ” "], - interval: 180, - }, - }).start("checking package managers..."); - try { // Check if pnpm is already available const hasPnpm = await checkCommandExists("pnpm"); + let packageManager = "npm"; // If pnpm is not available, try to use corepack if (!hasPnpm) { - const hasCorepack = await checkCommandExists("corepack"); - - if (hasCorepack) { - spinner.text = "setting up pnpm via corepack..."; + try { + console.log("Setting up pnpm via corepack..."); await enableCorepackAndPnpm(); - } else { - spinner.text = "falling back to npm (slower)..."; + if (await checkCommandExists("pnpm")) { + packageManager = "pnpm"; + } + } catch (error) { + console.log("Falling back to npm (slower)..."); } + } else { + packageManager = "pnpm"; } - // Choose the best available package manager - const packageManager = (await checkCommandExists("pnpm")) ? "pnpm" : "npm"; - - spinner.text = `installing dependencies with ${packageManager}...`; - spinner.stop(); - + console.log(`Installing dependencies with ${packageManager}...`); const installArgs = packageManager === "pnpm" ? ["install"]