How to use the react-tools/vendor/fbtransform/visitors.getAllVisitors function in react-tools

To help you get started, we’ve selected a few react-tools examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Khan / react-components / prepublish.js View on Github external
'use strict';

const fs = require('fs');
const visitors = require('react-tools/vendor/fbtransform/visitors');
const jstransform = require('jstransform');

const visitorList = visitors.getAllVisitors();

const getJsName = function(filename) {
    const dot = filename.lastIndexOf(".");
    const baseName = filename.substring(0, dot);
    return baseName + ".js";
};

// perform es6 / jsx tranforms on all files and simultaneously copy them to the
// top level.
const files = fs.readdirSync('js');
for (let i = 0; i < files.length; i++) {
    const src = 'js/' + files[i];
    const dest = getJsName(files[i]);

    const js = fs.readFileSync(src, {encoding: 'utf8'});
    let transformed = jstransform.transform(visitorList, js).code;