type command (Powershell) throws 'A positional parameter cannot be found that accepts argument' error

StackOverflow https://stackoverflow.com/questions/19668881

  •  01-07-2022
  •  | 
  •  

Frage

I'm trying to use 'uglifyjs' in order to minify all of my javascript files into one '.js' file in order to get the karma ng-scenario e2e testing to function properly. However when I input this

type My.js MyLogon.js MyMenu.js Common\directives\BaseDirectives.js Common\factories\BaseFactories.js Module\AccountConfirmationModule.js Module\AccountModule.js Module\ApplicationModule.js Module\ApplicationRoleModule.js Module\HeaderModule.js Module\Index.js Module\LogOnModule.js Module\PasswordModule.js Module\QAModule.js Module\UsernameModule.js > files.min.js | uglifyjs -o files.min.js

I get the following error

Get-Content : A positional parameter cannot be found that accepts argument 'MyLogon.js'. At line:1 char:5

What am I doing wrong?

War es hilfreich?

Lösung

The type command in Cmd shell supports typing multiple files at the same time. File names are just space separated. In Powershell, type is an alias for Get-Content. It supports multiple source files, but doesn't use space separation. An array is needed, as specified by the -Path parameter that supports a String array:

man type    
Get-Content [-Path] <string[]> [-Credential <PSCredential>] ...

Try passing the cmdlet an array of file names. Like so,

type @("My.js", "MyLogon.js", "MyMenu.js")  | uglifyjs -o files.min.js

Andere Tipps

In powershell, a list is separated by comma, not space

type file1, file2, file3

If all the files are in the curent folder and there are no other *.js files:

if (test-path files.min.js) { remove-item files.min.js }
gci *.js | foreach{ type $_ >> files.min.js }
uglifyjs -o files.min.js

If this is not the case, the list can be set up this way:

$files = ("My.js", "MyLogon.js", "MyMenu.js", "Common\directives\BaseDirectives.js", "Common\factories\BaseFactories.js", "Module\AccountConfirmationModule.js", "Module\AccountModule.js", "Module\ApplicationModule.js", "Module\ApplicationRoleModule.js", "Module\HeaderModule.js", "Module\Index.js", "Module\LogOnModule.js", "Module\PasswordModule.js", "Module\QAModule.js", "Module\UsernameModule.js")
if (test-path files.min.js) { remove-item files.min.js }
$files | foreach{ type $_ >> files.min.js }
uglifyjs -o files.min.js
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top