使用 Yeoman 将变量注入到具有 <%= variable %> 的 JSON 文件中,但不输出变量

Injecting variables with Yeoman into a JSON file with <%= variable %> but not outputting the variable

我正在按照 the docs 中所述进行设置以替换文件中的值:

prompting() {
      return this.prompt([{
        type    : 'input',
        name    : 'name',
        message : 'Your project name',
        default : this.appname // Default to current folder name
      }, {
        type    : 'input',
        name    : 'chaincodeTitle',
        message : 'Chaincode folder name'
      }]).then((answers) => {
        this.log('app name', answers.name);
        this.props = answers;
      });
    }


// Creates all the files and directories from a hyperledger project template source
    writing() {  

      this.fs.copyTpl(
        this.templatePath('sdm/artifacts/local/config.json'),
        this.destinationPath('./' + this.props.name + 'hyperledger/local' + '/config.json'),
        {props: this.props.name}
      );     
    }

这是我在 JSON 文件中放置标签的位置:

{
    "host": "localhost",
    "port": "3000",
    "logLevel": "INFO",
    "channelCfgTxn": "../../../artifacts/local/channel/mychannel.tx",
    "chaincodeId": "MikeGcc",
    "CC_SRC_PATH": "../../../app/chaincode",
    "chaincodePath": "<%= props %>",
    "chaincodeVersion": "v0",
    "queryFunction": "getVersion",
    "keyValueStore": "/sim/fabric-client-kvs-local",
    "chaincodeName": "<%= props %>",
    "jwt_expiretime": "360000",
    "client": "http://localhost:4200/",
    "registerSupplierRoute": "register-supplier/"
}

但是当我 运行 我的 yeoman 生成器时,yeoman 似乎没有检测到它自己的标签并且正在输出字符串:<%= props %>

所以我在完成时收到以下错误:

info: [packager/Golang.js]: packaging GOLANG from <%= props %>
events.js:183
      throw er; // Unhandled 'error' event
      ^

Error: ENOENT: no such file or directory, lstat '/home/mike/mikehyperledger/app/chaincode/src/<%= props %>'

这两天一直困扰着我。任何熟悉 Yeoman 的人可能知道这里发生了什么?

问题是这个命令在写入块中,这是一个写入的承诺,并且该块中的所有命令都是异步发生的。

为了解决这个问题,我不得不在写作之外创建一个名为 "end()" 的块,并将我的 fsCopyTpl 插入其中,如下所示:

   end() {  

      this.fs.copyTpl(
        this.templatePath('sdm/artifacts/local/config.json'),
        this.destinationPath('./' + this.props.name + 'hyperledger/local' + '/config.json'),
        {props: this.props.name}
      );     
    }