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

Piping commands? #130

Open
favna opened this issue Jan 7, 2021 · 0 comments
Open

Piping commands? #130

favna opened this issue Jan 7, 2021 · 0 comments

Comments

@favna
Copy link

favna commented Jan 7, 2021

Given the following PowerShell command

Get-ChildItem -Path $env:USERPROFILE\Documents\development -Filter node_modules -Directory -Recurse | Remove-Item -Force -Recurse

This would remove all node_modules folders in development, recursing into subdirectories.

How would I best write this in node-powershell? I can do it with

addCommand(`Get-ChildItem -Path $env:USERPROFILE\Documents\development -Filter node_modules -Directory -Recurse | Remove-Item -Force -Recurse`)

But I would prefer to be able to do it with something like

const ps = new shell({
	executionPolicy: 'Bypass',
	noProfile: true
});

await ps.addCommand('Get-ChildItem');

await ps.addParameters([
	{ Path: '$env:USERPROFILE\Documents\development' },
	{ Filter: 'node_modules' },
	{ Directory: '' },
	{ Recurse: '' }
]);

// Adds ` | Remove-Item`
await ps.addPipedCommand('Remove-Item');

// Adding parameters to `Remove-Item`
await ps.addParameters([
	{ Force: '' },
	{ Recurse: '' }
]);
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

1 participant