Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
12 changes: 6 additions & 6 deletions src/commands/devops-plugin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 <gsDevOpsPlugin> in the <gsDevopsPluginsDir> directory
spawnSync("npm", ["i", `${gsDevOpsPlugin}`], {
spawnSync("pnpm", ["add", `${gsDevOpsPlugin}`], {
cwd: gsDevopsPluginsDir,
stdio: "inherit",
});
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -149,7 +149,7 @@ const remove = program
]);

// uninstallDevOpsPlugin(answer.gsDevOpsPlugin)
spawnSync("npm", ["uninstall", `${answer.gsDevOpsPlugin}`], {
spawnSync("pnpm", ["remove", `${answer.gsDevOpsPlugin}`], {
cwd: gsDevopsPluginsDir,
stdio: "inherit",
});
Expand Down Expand Up @@ -195,7 +195,7 @@ const update = program
]);

// npm install <gsDevOpsPlugin> in the <gsDevopsPluginsDir> directory
spawnSync("npm", ["install", `${answer.gsDevOpsPlugin}@latest`], {
spawnSync("pnpm", ["add", `${answer.gsDevOpsPlugin}@latest`], {
cwd: gsDevopsPluginsDir,
stdio: "inherit",
});
Expand Down
83 changes: 34 additions & 49 deletions src/commands/otel/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void>((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<void>((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 {
Expand Down Expand Up @@ -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<void>((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<void>((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

Expand Down
78 changes: 19 additions & 59 deletions src/commands/plugin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -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...");
Expand All @@ -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<void>((resolve, reject) => {
const { exec } = require('child_process');

Expand Down Expand Up @@ -237,26 +219,24 @@ 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}`));
return;
}

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;
}
Expand Down Expand Up @@ -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",
Expand All @@ -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);
}
}
Expand Down Expand Up @@ -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",
Expand All @@ -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);
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
});
}
Expand All @@ -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",
});
}
Expand Down Expand Up @@ -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
Expand All @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
Loading