Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Action type that trigger shell command #417

Open
michal-bella opened this issue Feb 9, 2024 · 2 comments
Open

Action type that trigger shell command #417

michal-bella opened this issue Feb 9, 2024 · 2 comments

Comments

@michal-bella
Copy link

Hello, can you add action type that trigger shell command? For example I want to achive during generating my code I want to trigger npm install "some-package". It would be nice to have this type of action.

{ type: 'command', command: 'npm install @some-package' // or any other command }

@JulSeb42
Copy link

Hey, have you found a solution for this?

@fabiobiondi
Copy link

fabiobiondi commented Jul 13, 2024

I use child_process:

const { exec } = require('child_process');

// ...

plop.setActionType('runCommand', function (answers, config, plop) {
    return new Promise((resolve, reject) => {
      exec(config.command, (error, stdout, stderr) => {
        if (error) {
          console.error(`Errore: ${error.message}`);
          reject(error);
        }
        if (stderr) {
          console.error(`Stderr: ${stderr}`);
          reject(new Error(stderr));
        }
        console.log(`Risultato: ${stdout}`);
        resolve(stdout);
      });
    });
  });
actions: [
  // ...
   {
      type: 'runCommand',
      command: 'npm run [COMMAND]',
    }
]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants