[英]npm run script < was unexpected
I recently read an article about generating a changelog and I wanted to integrate it in a package.json script.我最近阅读了一篇关于生成变更日志的文章,我想将它集成到 package.json 脚本中。
I changed the script from the article a bit with the proper project name and to export the output to CHANGELOG.md我使用正确的项目名称稍微更改了文章中的脚本并将输出导出到 CHANGELOG.md
"scripts": {
"generateChangelog": "git log --pretty=format:'<li> <a href=\"http://git.egt-interactive.com/frontend-games/temporary-test-project/commit/%H\">view commit •</a> %s</li> ' --reverse > CHANGELOG.md"
},
But when I run it I have the following error:但是当我运行它时,我有以下错误:
< was unexpected at this time. npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! temporary-test-project@1.0.0 generateChangelog: `git log --pretty=format:'<li> <a href="http://git.egt-interactive.com/frontend-games/temporary-test-project/commit/%H">view commit •</a> %s</li> ' --reverse > CHANGELOG.md` npm ERR! Exit status 1
I think it's something with the escaping, but I can't find it.我认为这与逃避有关,但我找不到。
Would be glad for some help.很高兴能得到一些帮助。 Thanks in advance
提前致谢
EDIT编辑
I am working on windows and by default, I am using Powershell, but I tried to run npm run generateChangelog
script with cmd too ( both failed )我在 Windows 上工作,默认情况下,我使用的是 Powershell,但我也尝试使用 cmd 运行
npm run generateChangelog
脚本(都失败了)
However, if I run the same git log...
command directly in the shell it works:但是,如果我直接在 shell 中运行相同的
git log...
命令,它会起作用:
git log --pretty=format:'<li> <a href=\"http://git.egt-interactive.com/frontend-games/temporary-test-project/commit/%H\">view commit •</a> %s</li> ' --reverse > CHANGELOG.md`
I think it's something with the escaping, but I can't find it.
我认为这与逃避有关,但我找不到。
Yes, you're correct it's an escaping issue.是的,你是对的,这是一个逃避问题。
Change your script named generateChangelog
in the scripts
section of your package.json to the following:将package.json的
scripts
部分中名为generateChangelog
的scripts
更改为以下内容:
"scripts": {
"generateChangelog": "git log --pretty=format:\"<li> <a href=\\\"http://git.egt-interactive.com/frontend-games/temporary-test-project/commit/%H\\\">view commit •</a> %s</li> \" --reverse > CHANGELOG.md"
},
Note the changes:注意变化:
The single quotes ( '
) have been replaced with JSON escaped double quotes ( \\"
)单引号 (
'
) 已替换为 JSON 转义双引号 ( \\"
)
The JSON escaped double quotes ( \\"
) have been replaced with ( \\\\\\"
) JSON 转义双引号 (
\\"
) 已替换为 ( \\\\\\"
)
git log --pretty=format:\"<li> <a href=\\\"http://git.egt-interactive.com/frontend-games/temporary-test-project/commit/%H\\\">view commit •</a> %s</li>\" --reverse > CHANGELOG.md
^^ ^^^^ ^^^^ ^^
Running $ npm run generateChangelog
should now run successfully via:运行
$ npm run generateChangelog
现在应该通过以下方式成功运行:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.