Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to prepend and append sources #124

Merged
merged 2 commits into from
Mar 31, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,8 @@ module.exports = function (config) {
* *String[]* `referenceDirSuffixes` — суффиксы папок технологий с эталонами. По умолчанию — `['tmpl-specs']`.
* *String[] | Boolean* `langs` —  использование `BEM.I18N` в шаблонах. Если указать массив языков, то необходимо будет создавать эталоны на каждый из перечисленных языков. Например `10-name.ru.bemjson.js` , `10-name.en.bemjson.js`.
Если использовать значение `langs: true`, то эталоны по языкам писать не нужно. В код собранных шаблонов будет всталенно только ядро BEM.I18N, без кейсетов. По умолчанию — `false`.
* *String[]* `prependFiles` — опция позволяет указать набор файлов для подмешивания в начало тестируемых шаблонов.
* *String[]* `appendFiles` — опция позволяет указать набор файлов для подмешивания в конец тестируемых шаблонов.
* *Object* `engines` —  опция определяет какие ENB-технологии следует использовать для сборки шаблонов. Обязательная опция.
- *String* `tech` — путь к ENB-технологии;
- *Object* `options` — опции для ENB-технологии;
Expand Down
2 changes: 1 addition & 1 deletion lib/assets/tmpl-spec.jst
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ function loadTemplate(file, exportName) {
return { apply: function() { return e.stack; } };
}
}
function reRequire(file, exportName) {
function reRequire(file) {
file = require.resolve(file);
clearRequire(file);
return require(file);
Expand Down
31 changes: 23 additions & 8 deletions lib/node-configurator.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ exports.configure = function (config, options) {
config.nodes(pattern, function (nodeConfig) {
var langs = options.langs,
engines = options.engines,
prependFiles = [].concat(options.prependFiles).filter(Boolean),
appendFiles = [].concat(options.appendFiles).filter(Boolean),
coverageEngines = options.coverage.engines,
engineTargets = [],
specTargets = [],
Expand Down Expand Up @@ -70,17 +72,23 @@ exports.configure = function (config, options) {
[files]
]);

// Add engines' techs
// Provide prepending and appending files if any.
prependFiles.concat(appendFiles)
.forEach(function (filepath) {
nodeConfig.addTech([provide, { target: filepath }]);
});

// Add engines' techs and set needsCoverage flag
engines.forEach(function (engine) {
engine.hasOwnProperty('needsCoverage') || (engine.needsCoverage = _.contains(coverageEngines, engine.name));
nodeConfig.addTech([engine.tech, engine.options]);
});

// For each lang including no-lang (false) and mock-lang (true)
(Array.isArray(langs) ? langs : [langs && 'lang']).forEach(function (lang) {
var suffix = '.' + lang + '.js',
isMock = lang === 'lang',
isReal = lang && !isMock;
(Array.isArray(langs) ? langs : [langs && 'mock']).forEach(function (lang) {
var isMock = lang === 'mock',
isReal = !isMock && typeof lang === 'string',
suffix = '.' + (lang || 'merged') + '.js';

// Keyset and lang file for real langs:
isReal && nodeConfig.addTechs([
Expand All @@ -95,14 +103,21 @@ exports.configure = function (config, options) {

engines.forEach(function (engine) {
var target = engine.target,
destTarget = target;
destTarget = target,
sources = []
.concat(prependFiles)
.concat(lang && ('?.lang' + suffix))
.concat(target)
.concat(appendFiles)
.filter(Boolean);

// Skip block for `langs: false`
if (lang) {
// or if we don't need prepending/appending files.
if (lang || sources.length > 1) {
destTarget = target.replace('.js', suffix);

nodeConfig.addTech([mergeFile, {
sources: ['?.lang' + suffix, target],
sources: sources,
target: destTarget,
sourcemap: true
}]);
Expand Down
4 changes: 4 additions & 0 deletions lib/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ module.exports = function (helper, commonOpts) {
}),
langs: options.langs,
mockI18N: options.mockI18N,
prependFiles: options.prependFiles,
appendFiles: options.appendFiles,
engines: _.map(engines, function (engine, name) {
var techPath = engine.tech,
tech = require(techPath),
Expand Down Expand Up @@ -174,6 +176,8 @@ module.exports = function (helper, commonOpts) {
sourceLevels: options.sourceLevels,
langs: options.langs,
mockI18N: options.mockI18N,
prependFiles: options.prependFiles,
appendFiles: options.appendFiles,
engines: options.engines,
saveHtml: options.saveHtml,
coverage: options.coverage,
Expand Down