我們正着手在Angular 2應用中進行國際化/本地化,我希望能夠編寫一些腳本來完成各種任務,例如生成翻譯源文件,構建和/或者用來自特定語言的翻譯來爲應用程序提供服務。從腳本文件而不是從CLI運行Angular CLI腳本?本地化/國際化
與其將腳本寫入package.json文件中,我希望能夠在腳本/目錄中的單獨文件中捕獲腳本,並且package.json文件中的腳本將指向這些腳本。
例如,我想採取這樣的事情在package.json
:
"scripts": {
//other irrelevant scripts
"generateXLF": "ng-xi18n --i18nFormat=xlf --outFile=./src/locale/baseFile/messages.xlf",
//other irrelevant scripts
},
,而是有這樣的事情:
"scripts": {
//other irrelevant scripts
"generateXLF": "node ./build/scripts/locale/generateXLF.js"
//other irrelevant scripts
},
或代替這樣的:
"scripts": {
//other irrelevant scripts
"serveLocale": : "./node_modules/.bin/ngc --i18nFile=./src/locale/languages/($someLocaleIPassIn)/messages.($someLocaleIPassIn).xlf --locale=($someLocaleIPassIn) --i18nFormat=xlf",
//other irrelevant scripts
},
取而代之的是:
"scripts": {
//other irrelevant scripts
"serveLocale": : "node ./build/scripts/locale/serveLocale.js $someLocaleIPassIn"
//other irrelevant scripts
},
基本上我需要做到以下幾點:可封裝,我通常將不得不與角度CLI一噸的標誌運行/執行命令
- 編寫腳本。即我怎樣才能運行「ng服務」腳本文件與一堆旗幟?
- 可以傳遞參數給這些腳本
目前我的存在方式的一部分。例如,在我的generateXLF.js
文件目前我只是想經營ng serve
,不帶參數或標誌,就像這樣:
var ngServe = require('@angular/cli/commands/serve');
new ngServe.default();
,但我不斷收到此錯誤:
C:\Projects\MyProject\StyleGuide\node_modules\@angular\cli\ember-cli\lib\models\command.js:77
this.isWithinProject = this.project.isEmberCLIProject();
^
TypeError: Cannot read property 'isEmberCLIProject' of undefined
at Class.init (C:\Projects\MyProject\StyleGuide\node_modules\@angular\cli\ember-cli\lib\models\command.js:77:40)
at Class.superWrapper [as init] (C:\Projects\MyProject\StyleGuide\node_modules\core-object\lib\assign-properties.js:34:20)
at Class.CoreObject (C:\Projects\MyProject\StyleGuide\node_modules\core-object\core-object.js:9:15)
at Class (C:\Projects\MyProject\StyleGuide\node_modules\core-object\core-object.js:21:5)
at Class (C:\Projects\MyProject\StyleGuide\node_modules\core-object\core-object.js:21:5)
at C:\Projects\MyProject\StyleGuide\build\scripts\locale\generateXLF.js:32:5
at Object.<anonymous> (C:\Projects\MyProject\StyleGuide\build\scripts\locale\generateXLF.js:37:3)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
Process finished with exit code 1
ng serve
作品就好了當我從CLI運行它時,而不是當我嘗試從腳本運行它時。我猜不知道我需要設置腳本文件來知道我的.angular-cli.json
文件和我的package.json
文件在哪裏,並且使用這些文件中的信息來使ng serve
正確地從腳本文件運行。但我可能完全錯誤,爲什麼它失敗。
TLDR:如何成功運行腳本文件中帶有標誌的Angular CLI腳本?如何選擇我已經通過的參數?
真棒!這節省了我大量的觀察和學習。 – gye