From 84958b75b8a1603fc23d1c73f90af6dc83e0f522 Mon Sep 17 00:00:00 2001 From: awinogradov Date: Sat, 6 May 2017 17:41:57 +0300 Subject: [PATCH] per level naming --- package.json | 1 + src/index.js | 9 ++++++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 8f84037..131658b 100644 --- a/package.json +++ b/package.json @@ -34,6 +34,7 @@ "@bem/import-notation": "^1.0.0", "@bem/naming": "^2.0.0-3", "babel-template": "^6.23.0", + "bem-config": "^3.2.3", "log-symbols": "^1.0.2", "required-path": "^1.0.1" }, diff --git a/src/index.js b/src/index.js index 9605533..2348e3e 100644 --- a/src/index.js +++ b/src/index.js @@ -5,6 +5,7 @@ const fs = require('fs'), BemEntityName = require('@bem/entity-name'), bemFs = require('@bem/fs-scheme')(), bemImport = require('@bem/import-notation'), + bemConfig = require('bem-config')(), requiredPath = require('required-path'), template = require('babel-template'), logSymbols = require('log-symbols'), @@ -15,7 +16,9 @@ module.exports = function({ types: t }) { return { visitor: { CallExpression(p, { opts, file: { opts: { filename } } }) { - const { naming, levels, techs=['js'] } = opts, + const { naming, techs=['js'] } = opts, + levelsMap = bemConfig.levelMapSync() || opts.levels, + levels = Array.isArray(levelsMap) ? levelsMap : Object.keys(levelsMap), techMap = techs.reduce((acc, tech) => { acc[tech] || (acc[tech] = [tech]); return acc; @@ -56,14 +59,14 @@ return { }, []) // find path for every entity and check it existance .map(bemCell => { - const entityPath = path.resolve(bemFs.path(bemCell, namingOptions)); + const localNamingOpts = levelsMap[bemCell.layer].naming || namingOptions; + const entityPath = path.resolve(bemFs.path(bemCell, localNamingOpts)); // BemFile return { cell : bemCell, exist : fs.existsSync(entityPath), // prepare path for require cause relative returns us string that we couldn't require path : requiredPath(path.relative(path.dirname(filename), entityPath)) - }; });