g.raphael
Version:
An npm package of g.raphael
25 lines (21 loc) • 771 B
JavaScript
var fs = require('fs')
fs.readdirSync('.').forEach(function(file) {
if (!file.match(/^g\..*\.js$/)) { return }
if (file.match(/-min\.js$/)) { return }
var newFileName,
code = fs.readFileSync(file).toString()
if (file == 'g.raphael.js') {
newFileName = 'index.js'
code = 'var Raphael = require("./node_modules/raphael");\n' + code + '\nmodule.exports = Raphael'
} else {
var exports = code.match(/Raphael\.fn\.g\.\w+ \=/g)
code = 'Raphael = require("./index.js")\n' + code
exports.forEach(function(match) {
var name = match.match(/(\w+) =/)[1]
code = code.replace(match, 'module.exports.' + name + ' = ' + match)
})
var filePrefixLength = 'g.'.length
newFileName = file.substr(filePrefixLength)
}
fs.writeFileSync(newFileName, code)
})