Search code examples
node.jsyeomanecmascript-6babeljsyeoman-generator

Yeoman generator with Babel flow


I've decided to rewrite my generator from ES5 syntax to ES6. But I faced the issue with transpiling generator on pre-publish.

Issue: As we know Yeoman generators have templates folder where different files is located. When Babel is traspiling all the generators sources via babel src --out-dir generators it skips the templates files or breaks the traspiling with error.

My Attepmts: I was trying to make something like babel src --out-dir generators && cp -rn src/ generators/ but I don't like this solution.

Question: How can I make old structure generators/sub-generators but in ES6 syntax, not in ES5.

Thanks.

UPD: I'm hoping that Yeoman has something like Mocha has --require babelhook.js.


Solution

  • I've found the solution for this case.

    First of all, I've created src folder where generator sources in ES6 syntax is located. Structure of this folder is the same as in usual ES5 generator.

    When I want to compile these sources I just need to copy them and compile in generators folders.

    So I've written the following scripts in package.json;

    "scripts": {
      "clean": "rm -rf ./generators",
      "compile": "npm run clean && cp -r src/ generators/ && babel src --out-dir generators",
      "prepublish": "npm run compile",
      "test": "istanbul cover _mocha"
    }
    

    And last thing that I've done is add ignore field in .babelrc file. So I'm sure that templates will be just copied but not traspiled.

    {
      "stage": 0,
      "ignore": [
        "app/templates",
      ]
    }