This package consumes the following services:
Atom
Transpile code inEasily transpile code between languages within Atom in a standard way.
Transpile selected blocks of code in the editor, or else the current buffer, in which case the appropriate target grammar will automatically be applied on success.
Relevant files can also be converted directly in Tree view, but will transpile to a new adjacent file by default.
Transpiler commands are context aware to prevent unnecessary menu clutter, and are grouped into a single Transpile submenu.
Plugins
Plugin | From | To |
---|---|---|
transpile-js2coffee | JavaScript | CoffeeScript |
transpile-decaf | CoffeeScript | JavaScript |
transpile-lebab | ES5 | ES6/2015 |
transpile-cson | CSON/JSON | JSON/CSON |
transpile-pug | HTML | Pug |
API
Creating a plugin is as simple as possible. See the base example below, or the multiple existing packages for examples of how to implement your own.
// package.json
"providedServices": {
"transpile": {
"versions": {
"1.0.0": "activate"
}
}
},
This provides your transpiler as a service for this base package to build on.
# index.coffee
module.exports =
activate: ->
name: 'transpile-plugin'
from:
scopeName: 'source.coffee'
fileTypes: ['.coffee','[data-name*=coffee]','Cakefile']
to:
scopeName: 'source.js'
ext: '.js' # Optional
transpile: (source) => #, indent, editor)
{transpile} = require 'transpiler'
transpile source #, { options: indent }
Notice that the from.fileTypes
[array]
can contain either file .ext
ensions, complete file names, or a valid CSS attribute selector.
Your transpile:
method should simply return the transpiled code, and will be supplied with the source
code, along with the following [optional] arguments:
- An
indent
ation'string'
provided as a potential option to pass on to the underlying transpiler, since formatting should be preserved if possible. - The current Text
editor
{object}
instance.
Multiple transpilers can also be bundled in the same package; transpile-decaf for example provides a choice between decaf or decaffeinate, whereas transpile-cson can transpile between both CSON and JSON.
Install
apm install transpile
or search “transpile” under Packages within Atom.