Created
July 8, 2015 19:54
-
-
Save zxqx/0396a97ee87d4bae1b87 to your computer and use it in GitHub Desktop.
Revisions
-
zxqx created this gist
Jul 8, 2015 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,35 @@ 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!'); }); });