|
diff --git .bem/make.js .bem/make.js |
|
index d43902e..ce19b1b 100644 |
|
--- .bem/make.js |
|
+++ .bem/make.js |
|
@@ -23,7 +23,9 @@ MAKE.decl('BundleNode', { |
|
'bemdecl.js', |
|
'deps.js', |
|
'bemhtml', |
|
+ 'bemtree', |
|
'browser.js+bemhtml', |
|
+ 'node.js', |
|
'stylus', |
|
'css', |
|
'html' |
|
@@ -80,3 +82,12 @@ MAKE.decl('AutoprefixerNode', { |
|
} |
|
|
|
}); |
|
+ |
|
+MAKE.decl('BundlesLevelNode', { |
|
+ buildMergedBundle: function() { |
|
+ return true; |
|
+ }, |
|
+ mergedBundleName: function() { |
|
+ return 'all'; |
|
+ } |
|
+}); |
|
diff --git .gitignore .gitignore |
|
index 6ad680f..b646988 100644 |
|
--- .gitignore |
|
+++ .gitignore |
|
@@ -11,6 +11,7 @@ npm-debug.log |
|
.enb/tmp/ |
|
*bundles*/*/*.* |
|
!*bundles*/*/*.bemjson.js |
|
+!*bundles*/server/*.bemdecl.js |
|
!*bundles*/.bem/* |
|
*pages*/*/*.* |
|
!*pages*/*/*.bemjson.js |
|
diff --git bower.json bower.json |
|
index 046fc03..7861077 100644 |
|
--- bower.json |
|
+++ bower.json |
|
@@ -9,8 +9,8 @@ |
|
"libs" |
|
], |
|
"dependencies": { |
|
- "bem-core": "v2.3.0", |
|
- "bem-components": "3b41cd9d817f51b94bead414409a099913509299" |
|
+ "bem-core": "v2.4.0", |
|
+ "bem-components": "6818e1000a3563f35e2279d069c456c2d027f40e" |
|
}, |
|
"resolutions": { |
|
"bem-core": "v2.3.0" |
|
diff --git common.blocks/server/server.deps.js common.blocks/server/server.deps.js |
|
new file mode 100644 |
|
index 0000000..f6bf64b |
|
--- /dev/null |
|
+++ common.blocks/server/server.deps.js |
|
@@ -0,0 +1,6 @@ |
|
+({ |
|
+ shouldDeps : [ |
|
+ 'i-bem', |
|
+ 'vow' |
|
+ ] |
|
+}) |
|
diff --git common.blocks/server/server.node.js common.blocks/server/server.node.js |
|
new file mode 100644 |
|
index 0000000..0d5172e |
|
--- /dev/null |
|
+++ common.blocks/server/server.node.js |
|
@@ -0,0 +1,11 @@ |
|
+/* global modules:false */ |
|
+modules.define('server', ['BEMTREE', 'BEMHTML'], function(provide, BEMTREE, BEMHTML) { |
|
+ |
|
+provide(function(request, response) { |
|
+ BEMTREE.apply({ block : 'page' }).then(function(bemjson) { |
|
+ response.end(BEMHTML.apply(bemjson)); |
|
+ }) |
|
+}); |
|
+ |
|
+}); |
|
+ |
|
diff --git desktop.bundles/server/server.bemdecl.js desktop.bundles/server/server.bemdecl.js |
|
new file mode 100644 |
|
index 0000000..4f58e6f |
|
--- /dev/null |
|
+++ desktop.bundles/server/server.bemdecl.js |
|
@@ -0,0 +1,3 @@ |
|
+exports.deps = [ |
|
+ 'server' |
|
+]; |
|
diff --git index.js index.js |
|
new file mode 100644 |
|
index 0000000..a983d05 |
|
--- /dev/null |
|
+++ index.js |
|
@@ -0,0 +1,54 @@ |
|
+var BEM = require('bem'), |
|
+ HTTP = require('http'), |
|
+ VM = require('vm'), |
|
+ FS = require('fs'), |
|
+ PATH = require('path'), |
|
+ vmCtx = VM.createContext({ |
|
+ require : vmRequire, |
|
+ console : console, |
|
+ modules : require('./libs/bem-core/node_modules/ym/modules.js'), |
|
+ process : process, |
|
+ setImmediate : setImmediate |
|
+ }), |
|
+ techPaths = ['node', 'bemtree', 'bemhtml'].map(function(tech) { |
|
+ return 'desktop.bundles/all/all.' + tech + '.js' |
|
+ }), |
|
+ PORT = process.argv[2] || 8080; |
|
+ |
|
+var server = HTTP.createServer(function(request, response) { // TODO: express |
|
+ if(request.url.match(/\.(css|js)$/)) { |
|
+ response.end(FS.readFileSync('./' + request.url)); |
|
+ } else { |
|
+ BEM.api.make({}, { targets : techPaths }) |
|
+ .then(function() { |
|
+ require('bem/lib/level').resetLevelsCache(); |
|
+ try { |
|
+ techPaths.forEach(function(techPath) { vmRequire(techPath); }); |
|
+ } catch(e) { |
|
+ response.end(e) |
|
+ } |
|
+ |
|
+ vmCtx.modules.require(['server'], function(server) { |
|
+ server(request, response); |
|
+ }); |
|
+ }); |
|
+ } |
|
+}); |
|
+ |
|
+server.listen(PORT); |
|
+console.log('Start at http://localhost:' + PORT); |
|
+ |
|
+function vmRequire(path) { |
|
+ path[0] === '.' && vmRequire._path && |
|
+ (path = PATH.resolve(PATH.dirname(vmRequire._path), path)); |
|
+ var prevPath = vmRequire._path; |
|
+ vmRequire._path = path; |
|
+ |
|
+ try { |
|
+ VM.runInContext(FS.readFileSync(path, 'utf-8'), vmCtx, path); // TODO: use file mtime |
|
+ } catch(e) { |
|
+ console.log('Error in ' + path +':\n' + e); |
|
+ } |
|
+ |
|
+ vmRequire._path = prevPath; |
|
+} |