forked from Khan/react-components
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprepublish.js
More file actions
27 lines (21 loc) · 833 Bytes
/
prepublish.js
File metadata and controls
27 lines (21 loc) · 833 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
'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;
transformed = transformed.replace('.jsx', '.js');
fs.writeFileSync(dest, transformed);
}