babel-plugin-drupal-behaviors
Advanced tools
Comparing version 0.1.0 to 0.1.1
18
index.js
const template = require('babel-template'); | ||
function getRandomNumber(max) { | ||
return Math.floor(Math.random() * Math.floor(max)); | ||
} | ||
const randomNum = getRandomNumber(1000); | ||
const drupalBehavior = template(`Drupal.behaviors.NAME = {attach: function (context, settings) {BODY}};`); | ||
const drupalBehavior = template('Drupal.behaviors.behavior' + randomNum + ' = {attach: function (context, settings) {\nBODY;\n}};'); | ||
module.exports = function (babel) { | ||
@@ -20,10 +15,13 @@ const t = babel.types; | ||
this.drupalBehavior = true; | ||
// console.log(path.node.body[0].expression.callee.body.directives) | ||
function getRandomNumber(max) { | ||
return Math.floor(Math.random() * Math.floor(max)); | ||
} | ||
const randomNum = getRandomNumber(1000).toString(); | ||
const addBehavior = drupalBehavior({ | ||
NAME: t.identifier('name' + randomNum), | ||
BODY: path.node.body | ||
}); | ||
// console.log(path.get('body')) | ||
// addBehavior.expression.callee.body.directives = path.node.directives; | ||
path.replaceWith( | ||
@@ -30,0 +28,0 @@ t.program([addBehavior]) |
{ | ||
"name": "babel-plugin-drupal-behaviors", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "Babel Plugin to wrap file in a Drupal behavior", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
1731
29