Created
October 1, 2015 21:45
-
-
Save JiLiZART/2ad77c30a5132cc47ee3 to your computer and use it in GitHub Desktop.
client BH
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 characters
var enbBemTechs = require('enb-bem-techs'), | |
borschikTech = require('enb-borschik/techs/borschik'), | |
fs = require('fs'), | |
path = require('path'), | |
techs = enbBemTechs, | |
provide = require('enb/techs/file-provider'); | |
// php | |
// process.env.YENV = 'production'; | |
enbBhPhp = require('enb-bh-php'); | |
//wpPhp = require('./techs/wp-php.js'); | |
isProd = process.env.YENV === 'production'; | |
module.exports = function (config) { | |
config.nodes('*.pages/*', function (nodeConfig) { | |
// Создаем директории для merged-бандлов (1) | |
['desktop','touch-pad', 'touch-phone'].forEach(function (platform) { | |
var node = path.join(platform + '.pages', 'merged'); | |
if (!fs.existsSync(node)) { | |
fs.mkdirSync(node); | |
} | |
}); | |
var node = path.basename(nodeConfig.getPath()); | |
if (node !== 'merged') { | |
nodeConfig.addTechs([ | |
// essential | |
[require('enb/techs/file-provider'), { target: '?.bemdecl.js' }], | |
[enbBemTechs.files], | |
[enbBemTechs.deps], | |
//[enbBemTechs.bemjsonToBemdecl], | |
// ie.css | |
[require('enb/techs/css'), { | |
target: '?.ie.css', | |
sourceSuffixes: ['css', 'ie.css'] | |
}], | |
// ie9.css | |
[require('enb/techs/css'), { | |
target: '?.ie9.css', | |
sourceSuffixes: ['css', 'ie9.css'] | |
}], | |
// node.js | |
/*[require('enb-diverse-js/techs/node-js'), { target: '?.pre.node.js' }], | |
[require('enb-modules/techs/prepend-modules'), { | |
source: '?.pre.node.js', | |
target: '?.node.js' | |
}],*/ | |
// browser.js | |
[require('enb-diverse-js/techs/browser-js'), { target: '?.browser.js' }], | |
[require('enb/techs/file-merge'), { | |
target: '?.pre.js', | |
sources: ['?.browser.bh.js', '?.browser.js'] | |
}], | |
[require('enb-modules/techs/prepend-modules'), { | |
source: '?.pre.js', | |
target: '?.js' | |
}], | |
// css | |
[require('enb-stylus/techs/css-stylus'), { target: '?.noprefix.css' }], | |
// bh | |
/*[require('enb-bh/techs/bh-server'), { | |
jsAttrName: 'data-bem', | |
jsAttrScheme: 'json' | |
}],*/ | |
[require('./techs/wp-php.js')], | |
// client bh | |
[enbBemTechs.depsByTechToBemdecl, { | |
target: '?.bh.bemdecl.js', | |
sourceTech: 'js', | |
destTech: 'bemhtml' | |
}], | |
[enbBemTechs.deps, { | |
target: '?.bh.deps.js', | |
bemdeclFile: '?.bh.bemdecl.js' | |
}], | |
[enbBemTechs.files, { | |
depsFile: '?.bh.deps.js', | |
filesTarget: '?.bh.files', | |
dirsTarget: '?.bh.dirs' | |
}], | |
[require('enb-bh/techs/bh-client-module'), { | |
target: '?.browser.bh.js', | |
filesTarget: '?.bh.files', | |
jsAttrName: 'data-bem', | |
jsAttrScheme: 'json', | |
mimic: 'BEMHTML' | |
}], | |
// html | |
//[require('enb-bh/techs/html-from-bemjson')], | |
[enbBhPhp.bhPhp, { | |
phpBootstrap: "../../vendor/bem/bh/index.php", | |
devMode: process.env.BHPHP_ENV === 'development', | |
jsAttrName: "data-bem", | |
jsAttrScheme: "json" | |
}], | |
//[enbBhPhp.bemjsonToHtml], | |
// borschik | |
[borschikTech, { sourceTarget: '?.css', destTarget: '_?.css', tech: 'cleancss', freeze: true, minify: isProd }], | |
[borschikTech, { sourceTarget: '?.ie.css', destTarget: '_?.ie.css', freeze: true, minify: isProd }], | |
[borschikTech, { sourceTarget: '?.ie9.css', destTarget: '_?.ie9.css', freeze: true, minify: isProd }], | |
[borschikTech, { sourceTarget: '?.js', destTarget: '_?.js', freeze: true, minify: isProd }], | |
[borschikTech, { sourceTarget: '?.bh.js', destTarget: '_?.bh.js', freeze: true, minify: isProd }] | |
]); | |
nodeConfig.addTargets([ | |
'_?.css', | |
'_?.ie.css', | |
'_?.ie9.css', | |
//'?.node.js', | |
'_?.js', | |
'?.bh.php', | |
'?.wp.php', | |
//'_?.bh.js', | |
//'?.html' | |
]); | |
} | |
}); | |
config.nodes('*desktop.pages/*', function (nodeConfig) { | |
nodeConfig.addTechs([ | |
// essential | |
[enbBemTechs.levels, { levels: getDesktops(config) }], | |
// autoprefixer | |
[require('enb-autoprefixer/techs/css-autoprefixer'), { | |
browserSupport: ['last 2 versions', 'ie 10', 'ff 24', 'opera 12.16'], | |
sourceTarget: '?.noprefix.css' | |
}] | |
]); | |
}); | |
config.nodes('*admin.pages/*', function (nodeConfig) { | |
nodeConfig.addTechs([ | |
// essential | |
[enbBemTechs.levels, { levels: getAdmin(config) }], | |
// autoprefixer | |
[require('enb-autoprefixer/techs/css-autoprefixer'), { | |
browserSupport: ['last 2 versions', 'ie 10', 'ff 24', 'opera 12.16'], | |
sourceTarget: '?.noprefix.css' | |
}] | |
]); | |
}); | |
config.nodes('editor', function (nodeConfig) { | |
nodeConfig.addTechs([ | |
// essential | |
[enbBemTechs.levels, { | |
levels: [ | |
'common.blocks', | |
'desktop.blocks' | |
] | |
}], | |
[require('enb/techs/file-provider'), { target: '?.bemdecl.js' }], | |
[enbBemTechs.deps], | |
[enbBemTechs.files], | |
// css | |
[require('enb-stylus/techs/css-stylus'), { | |
target: '?.noprefix.css' | |
}], | |
[require('enb-autoprefixer/techs/css-autoprefixer'), { | |
browserSupport: ['last 2 versions', 'ie 10', 'ff 24', 'opera 12.16'], | |
sourceTarget: '?.noprefix.css' | |
}], | |
[borschikTech, { sourceTarget: '?.css', destTarget: '?.min.css', tech: 'cleancss', freeze: true, minify: true}], | |
]); | |
nodeConfig.addTargets([ | |
'?.min.css', | |
]); | |
}); | |
// Настраиваем сборку merged-бандла | |
config.nodes('*.pages/merged', function (nodeConfig) { | |
var dir = path.dirname(nodeConfig.getPath()), | |
bundles = fs.readdirSync(dir), | |
bemdeclFiles = []; | |
// Копируем BEMDECL-файлы в merged-бандл (3) | |
bundles.forEach(function (bundle) { | |
if (bundle === 'merged') return; | |
var node = path.join(dir, bundle), | |
target = bundle + '.bemdecl.js'; | |
nodeConfig.addTech([techs.provideBemdecl, { | |
node: node, | |
target: target | |
}]); | |
bemdeclFiles.push(target); | |
}); | |
// Объединяем скопированные BEMDECL-файлы (4) | |
nodeConfig.addTech([techs.mergeBemdecl, { sources: bemdeclFiles }]); | |
// Обычная сборка бандла (5) | |
nodeConfig.addTechs([ | |
//[techs.levels, { levels: ['desktop.blocks'] }], | |
[techs.deps], | |
[techs.files], | |
[require('./techs/wp-php.js')] | |
]); | |
nodeConfig.addTargets(['?.wp.php']); | |
}); | |
config.nodes('*touch-pad.pages/*', function (nodeConfig) { | |
nodeConfig.addTechs([ | |
// essential | |
[enbBemTechs.levels, { levels: getTouchPads(config) }], | |
// autoprefixer | |
[require('enb-autoprefixer/techs/css-autoprefixer'), { | |
browserSupport: ['android 4', 'ios 5'], | |
sourceTarget: '?.noprefix.css' | |
}] | |
]); | |
}); | |
config.nodes('*touch-phone.pages/*', function (nodeConfig) { | |
nodeConfig.addTechs([ | |
// essential | |
[enbBemTechs.levels, { levels: getTouchPhones(config) }], | |
// autoprefixer | |
[require('enb-autoprefixer/techs/css-autoprefixer'), { | |
browserSupport: ['android 4', 'ios 6', 'ie 10'], | |
sourceTarget: '?.noprefix.css' | |
}] | |
]); | |
}); | |
}; | |
function getDesktops(config) { | |
return [ | |
{ path: 'libs/bem-core/common.blocks', check: false }, | |
{ path: 'libs/bem-core-php/common.blocks', check: false }, | |
{ path: 'libs/bem-core/desktop.blocks', check: false }, | |
{ path: 'libs/bem-core-php/desktop.blocks', check: false }, | |
{ path: 'libs/bem-components/common.blocks', check: false }, | |
{ path: 'libs/bem-components-php/common.blocks', check: false }, | |
{ path: 'libs/bem-components/design/common.blocks', check: false }, | |
{ path: 'libs/bem-components/desktop.blocks', check: false }, | |
{ path: 'libs/bem-components/design/desktop.blocks', check: false }, | |
{ path: 'libs/bem-social/common.blocks', check: false }, | |
{ path: 'libs/bem-social/design/common.blocks', check: false }, | |
{ path: 'libs/bem-social/desktop.blocks', check: false }, | |
{ path: 'libs/bem-scrollspy/common.blocks', check: false }, | |
{ path: 'libs/bem-forms/common.blocks', check: false }, | |
{ path: 'libs/bem-forms/desktop.blocks', check: false }, | |
{ path: 'libs/bem-forms/design/common.blocks', check: false }, | |
{ path: 'libs/bem-forms/design/desktop.blocks', check: false }, | |
{ path: 'libs/constructor-blocks', check: false }, | |
{ path: 'libs/bem-grid/common.blocks', check: false }, | |
'common.blocks', | |
'desktop.blocks' | |
].map(function (level) { | |
return config.resolvePath(level); | |
}); | |
} | |
function getAdmin(config) { | |
return [ | |
{ path: 'libs/bem-core/common.blocks', check: false }, | |
{ path: 'libs/bem-core-php/common.blocks', check: false }, | |
{ path: 'libs/bem-core/desktop.blocks', check: false }, | |
{ path: 'libs/bem-core-php/desktop.blocks', check: false }, | |
{ path: 'libs/bem-components/common.blocks', check: false }, | |
{ path: 'libs/bem-components-php/common.blocks', check: false }, | |
{ path: 'libs/bem-components/design/common.blocks', check: false }, | |
{ path: 'libs/bem-components/desktop.blocks', check: false }, | |
{ path: 'libs/bem-components/design/desktop.blocks', check: false }, | |
'common.blocks', | |
'admin.blocks' | |
].map(function (level) { | |
return config.resolvePath(level); | |
}); | |
} | |
function getTouchPads(config) { | |
return [ | |
{ path: 'libs/bem-core/common.blocks', check: false }, | |
{ path: 'libs/bem-core-php/common.blocks', check: false }, | |
{ path: 'libs/bem-core/desktop.blocks', check: false }, | |
{ path: 'libs/bem-core-php/desktop.blocks', check: false }, | |
{ path: 'libs/bem-components/common.blocks', check: false }, | |
{ path: 'libs/bem-components-php/common.blocks', check: false }, | |
{ path: 'libs/bem-components/design/common.blocks', check: false }, | |
{ path: 'libs/bem-components/desktop.blocks', check: false }, | |
{ path: 'libs/bem-components/design/desktop.blocks', check: false }, | |
{ path: 'libs/bem-social/common.blocks', check: false }, | |
{ path: 'libs/bem-social/design/common.blocks', check: false }, | |
{ path: 'libs/bem-social/desktop.blocks', check: false }, | |
{ path: 'libs/bem-scrollspy/common.blocks', check: false }, | |
{ path: 'libs/bem-forms/common.blocks', check: false }, | |
{ path: 'libs/bem-forms/desktop.blocks', check: false }, | |
{ path: 'libs/bem-forms/design/common.blocks', check: false }, | |
{ path: 'libs/bem-forms/design/desktop.blocks', check: false }, | |
{ path: 'libs/constructor-blocks', check: false }, | |
{ path: 'libs/bem-grid/common.blocks', check: false }, | |
'common.blocks', | |
'touch.blocks', | |
'touch-pad.blocks' | |
].map(function (level) { | |
return config.resolvePath(level); | |
}); | |
} | |
function getTouchPhones(config) { | |
return [ | |
{ path: 'libs/bem-core/common.blocks', check: false }, | |
{ path: 'libs/bem-core-php/common.blocks', check: false }, | |
{ path: 'libs/bem-core/desktop.blocks', check: false }, | |
{ path: 'libs/bem-core-php/desktop.blocks', check: false }, | |
{ path: 'libs/bem-components/common.blocks', check: false }, | |
{ path: 'libs/bem-components-php/common.blocks', check: false }, | |
{ path: 'libs/bem-components/design/common.blocks', check: false }, | |
{ path: 'libs/bem-components/desktop.blocks', check: false }, | |
{ path: 'libs/bem-components/design/desktop.blocks', check: false }, | |
{ path: 'libs/bem-social/common.blocks', check: false }, | |
{ path: 'libs/bem-social/design/common.blocks', check: false }, | |
{ path: 'libs/bem-social/desktop.blocks', check: false }, | |
{ path: 'libs/bem-scrollspy/common.blocks', check: false }, | |
{ path: 'libs/bem-forms/common.blocks', check: false }, | |
{ path: 'libs/bem-forms/desktop.blocks', check: false }, | |
{ path: 'libs/bem-forms/design/common.blocks', check: false }, | |
{ path: 'libs/bem-forms/design/desktop.blocks', check: false }, | |
{ path: 'libs/constructor-blocks', check: false }, | |
{ path: 'libs/bem-grid/common.blocks', check: false }, | |
'common.blocks', | |
'touch.blocks', | |
'touch-phone.blocks' | |
].map(function (level) { | |
return config.resolvePath(level); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment