CapCa CapCa - 3 years ago 157
Git Question

How to use ES6 and ES7 in my Gruntfile

I would like to use ES6 and ES7 in my Gruntfile. The reason is that I would like to write a task, which includes the git-repository module. As you can see from the documentation, the module is only available in ES6 and ES7 and I would like to integrate this module as easy as possible. Is there a way that I can use ES6 and ES7 also in my Gruntfile - somthing like

babel grunt
? Unfortunately, I did not find anything on Google and therefore I hope that you can help me.

Thank you in advance! :-)

Answer Source

Usually you may want to use a build tool to transpile, so this is a 'who will build a build tool' problem.

It isn't usual for public package on NPM to be available only in or ES6 with feature set that is not supported by Node. git-repository isn't exception. It surely has transpiled code in the package and can be used without Babel.

Because the package was transpiled with babel-plugin-transform-runtime, it requires babel-polyfill to work.

Documentation uses async...await only as an example because it suits the workflow. async functions use promises, in ES5/ES6 it would be

require('babel-polyfill');'./example', { init: true })
.then(repo =>
  repo.setRemote('origin', '')
  .then(() => repo.add('--all .'))
  .then(() => repo.commit('Commit message'))

co is excellent alternative to async...await for Node ES6 feature set that requires no transpiler.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download