2015-09-11 16:42:11 +02:00
|
|
|
#!/usr/bin/env node
|
|
|
|
|
|
|
|
var fs = require('fs');
|
|
|
|
var path = require('path');
|
|
|
|
var glob = require('glob');
|
|
|
|
|
|
|
|
var args = require('optimist').argv;
|
|
|
|
|
|
|
|
var header = args.h || args.header;
|
|
|
|
|
2015-11-30 18:33:04 +01:00
|
|
|
var componenetsDir = path.join('src', 'components');
|
2015-09-15 14:34:36 +02:00
|
|
|
|
2015-11-30 18:33:04 +01:00
|
|
|
var componentIndex = path.join('src', 'component-index.js');
|
2015-09-11 16:42:11 +02:00
|
|
|
|
2015-11-30 18:33:04 +01:00
|
|
|
var packageJson = JSON.parse(fs.readFileSync('./package.json'));
|
2015-09-11 16:42:11 +02:00
|
|
|
|
2015-11-30 18:33:04 +01:00
|
|
|
var strm = fs.createWriteStream(componentIndex);
|
2015-09-11 16:42:11 +02:00
|
|
|
|
|
|
|
if (header) {
|
|
|
|
strm.write(fs.readFileSync(header));
|
|
|
|
strm.write('\n');
|
|
|
|
}
|
|
|
|
|
|
|
|
strm.write("/*\n");
|
|
|
|
strm.write(" * THIS FILE IS AUTO-GENERATED\n");
|
|
|
|
strm.write(" * You can edit it you like, but your changes will be overwritten,\n");
|
|
|
|
strm.write(" * so you'd just be trying to swim upstream like a salmon.\n");
|
|
|
|
strm.write(" * You are not a salmon.\n");
|
|
|
|
strm.write(" */\n\n");
|
|
|
|
|
2015-11-30 18:33:04 +01:00
|
|
|
if (packageJson['matrix-react-parent']) {
|
|
|
|
strm.write("module.exports.components = require('"+packageJson['matrix-react-parent']+"/lib/component-index').components;\n\n");
|
|
|
|
} else {
|
|
|
|
strm.write("module.exports.components = {};\n");
|
|
|
|
}
|
2015-09-11 16:42:11 +02:00
|
|
|
|
2015-11-30 18:33:04 +01:00
|
|
|
var files = glob.sync('**/*.js', {cwd: componenetsDir});
|
2015-09-11 16:42:11 +02:00
|
|
|
for (var i = 0; i < files.length; ++i) {
|
|
|
|
var file = files[i].replace('.js', '');
|
2015-11-30 18:33:04 +01:00
|
|
|
|
2015-09-11 16:42:11 +02:00
|
|
|
var module = (file.replace(/\//g, '.'));
|
|
|
|
|
2015-11-30 18:33:04 +01:00
|
|
|
strm.write("module.exports.components['"+module+"'] = require('./components/"+file+"');");
|
|
|
|
strm.write('\n');
|
2015-09-11 16:42:11 +02:00
|
|
|
strm.uncork();
|
|
|
|
}
|
2015-09-15 14:34:36 +02:00
|
|
|
|
2015-11-30 18:33:04 +01:00
|
|
|
// Temporary Vector transition
|
|
|
|
var vectorViewsPath = path.join('src', 'skins', 'vector', 'views');
|
|
|
|
if (fs.existsSync(vectorViewsPath)) {
|
|
|
|
strm.write('\n');
|
|
|
|
strm.write('// Old, unported Vector views:\n');
|
|
|
|
var files = glob.sync('**/*.js', {cwd: vectorViewsPath});
|
|
|
|
for (var i = 0; i < files.length; ++i) {
|
|
|
|
var file = files[i].replace('.js', '');
|
|
|
|
|
|
|
|
var module = (file.replace(/\//g, '.'));
|
|
|
|
|
|
|
|
strm.write("module.exports.components['"+module+"'] = require('./skins/vector/views/"+file+"');");
|
|
|
|
strm.write('\n');
|
|
|
|
strm.uncork();
|
|
|
|
}
|
2015-09-15 14:34:36 +02:00
|
|
|
}
|
|
|
|
|
2015-09-11 16:42:11 +02:00
|
|
|
strm.end();
|
|
|
|
|