UNPKG

direct-dev

Version:
26 lines (20 loc) 1.32 kB
'use strict'; /** [sandbox](https://github.com/direct-adv-interfaces/direct-dev/TECHS.md#sandbox) */ var util = require('util'); var require2 = require('../utils/require2'); var vow = require2('enb/node_modules/vow', 'vow'); var vowFs = require2('enb/node_modules/vow-fs', 'vow-fs'); var BlockFilter = require('../utils/block-filter'); module.exports = require('enb/lib/build-flow').create().name('sandbox').target('target', '?.sandbox.js').defineOption('filter').useFileList('sandbox.js').builder(function (paths) { var node = this.node; var filter = this.getOption('filter', BlockFilter.empty); return vow.all(paths.filter(filter.enb).map(function (file) { return vowFs.read(file.fullname, 'utf8').then(function (data) { var filename = node.relativePath(file.fullname), src = util.format('(function(window) {' + 'var module = { exports: {} }, exports = module.exports; %s;' + '!window.SANDBOX && (window.SANDBOX = {});' + '!window.SANDBOX.blocks && (window.SANDBOX.blocks = []);' + 'window.SANDBOX.blocks.push(module.exports);' + '})(window);', data); return '/* begin: ' + filename + ' *' + '/\n' + src + '\n/* end: ' + filename + ' *' + '/'; }); })).then(function (contents) { return contents.join('\n'); }); }).createTech();