Skip to content

Commit

Permalink
Merge pull request #43 from Lavavarshney/main
Browse files Browse the repository at this point in the history
FEAT: Automating installation of dependencies for snippets
  • Loading branch information
PranavBarthwal authored Oct 23, 2024
2 parents a3f3541 + 0a9fae9 commit 72b6d89
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
24 changes: 23 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ import { GoogleGenerativeAI } from '@google/generative-ai';
import chalk from 'chalk';
import ora from 'ora'; // Import the ora package
import inquirer from 'inquirer'; // Import the inquirer package
import { exec } from 'child_process'
import { generateGitignore } from './gitignoreGenerator.js';
import { dependencies } from './snippetdependencies.js';
=======


const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
Expand Down Expand Up @@ -96,7 +101,24 @@ program
// Copy the snippet file content to the new file in the working directory
fs.copySync(snippetFile, newSnippetFilePath);

console.log(chalk.green(`\nSnippet "${snippetName}" has been successfully created as "${snippetName}.js" in your current directory!\n`));
console.log(
chalk.yellow("Installing the required packages for the snippet...")
);
exec(
`npm install ${dependencies[snippetName].join(" ")}`,
(err, stdout, stderr) => {
if (err) {
console.log("An Error Occured : ",err);
return;
}
console.log(stdout);
console.log(
chalk.green(
`\nSnippet "${snippetName}" has been successfully created as "${snippetName}.js" in your current directory!\n`
)
);
}
);
} catch (err) {
console.error(chalk.red('Error while generating snippet file:'), err);
}
Expand Down
7 changes: 7 additions & 0 deletions snippetdependencies.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const dependencies = {
"mongoose-con" : ['mongoose'],
"mongoose-schema" : ['mongoose'],
"multer-file-upload" : ['multer']
};
export {dependencies};

0 comments on commit 72b6d89

Please sign in to comment.