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

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

  •  01-07-2022
  •  | 
  •  

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?

有帮助吗?

解决方案

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

其他提示

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
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top