-
-
Save pilwon/1d054ed00350f5fea401 to your computer and use it in GitHub Desktop.
mixed mode glslify workaround via npm postinstall script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// It runs two glsl files used in `webgl-shaders/index.js` through | |
// the same version of glslify transform function used in the current | |
// mixed mode project, then replaces the `webgl-shaders/index.js` with | |
// the bundles in the same format browserify would have exported as. | |
// | |
// npm install bluebird | |
// add {scripts: {postinstall: "node npm-postinstall"}} to package.json | |
// npm run postinstall (or npm install again) | |
var childProcess = require('child_process'); | |
var fs = require('fs'); | |
var path = require('path'); | |
var util = require('util'); | |
var Promise = require('bluebird'); | |
var BASE_DIR = path.resolve(__dirname, '../node_modules/famous/webgl-shaders'); | |
function bundle(file) { | |
return new Promise(function (resolve, reject) { | |
var command = util.format( | |
'%s %s', | |
path.resolve(BASE_DIR, '../node_modules/.bin/glslify'), | |
path.resolve(BASE_DIR, file) | |
); | |
childProcess.exec(command, function (err, stdout, stderr) { | |
if (err) {return reject(err);} | |
if (stderr) {console.error(stderr);} | |
resolve(stdout); | |
}); | |
}); | |
} | |
Promise.props({ | |
vertex: bundle('VertexShader.glsl'), | |
fragment: bundle('FragmentShader.glsl') | |
}).then(function (result) { | |
var filePath = path.resolve(BASE_DIR, 'index.js'); | |
var code = 'module.exports = ' + JSON.stringify(result, null, 2) + ';'; | |
return Promise.promisify(fs.writeFile)(filePath, code); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment