Skip to content

Instantly share code, notes, and snippets.

@zxqx
Created July 8, 2015 19:54
Show Gist options
  • Save zxqx/0396a97ee87d4bae1b87 to your computer and use it in GitHub Desktop.
Save zxqx/0396a97ee87d4bae1b87 to your computer and use it in GitHub Desktop.
var path = require('path');
var Promise = require('bluebird');
var uniq = require('uniq');
var fs = Promise.promisifyAll(require('fs'));
var SERVER_APP_PATH = 'src/server/app/publish';
var PREAMBLE_PATH = path.join(SERVER_APP_PATH, 'preamble.js');
var CAPSULE_BUILD_PATH = path.join(SERVER_APP_PATH, 'capsule.build.js');
var SAMPLE_CAPSULE_PATH = path.join(SERVER_APP_PATH, 'sample-capsule.json');
fs.readFileAsync(PREAMBLE_PATH)
.then(function(preamble) {
return fs.writeFileAsync(CAPSULE_BUILD_PATH, preamble);
})
.then(function() {
return fs.readFileAsync(SAMPLE_CAPSULE_PATH);
})
.then(JSON.parse)
.then(function(capsule) {
var widgets = uniq(capsule.widgets.map(function(w) {
return w.referenceId;
}));
var importStatements = '';
widgets.forEach(function(w) {
importStatements += 'import \'' + w + '\'\n';
});
return importStatements;
})
.then(function(importStatements) {
return fs.appendFileAsync(CAPSULE_BUILD_PATH, importStatements, function(err) {
console.log('done!');
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment