diff --git a/lib/create.js b/lib/create.js index be8a098..75269ca 100644 --- a/lib/create.js +++ b/lib/create.js @@ -1,13 +1,16 @@ -'use strict'; - -var prepareEntityData = require('./prepare-entity-data'), - createEntity = require('./create-entity'), - template = require('./template'); +const getEntityData = require('./get-entity-data'); +const getPath = require('./get-path'); +const template = require('./template'); +const createEntity = require('./create-entity'); module.exports = function create(entities, levels, techs, options) { - var createRes = prepareEntityData(entities, levels, techs, options); + var entityData = getEntityData(entities, levels, techs, options); - return Promise.all(createRes.map(item => - template.apply(item).then(tmpl => createEntity(item.path, tmpl, item.levelOptions)) - )); + return Promise.all(entityData.map(item => + template.apply(item) + .then(content => + createEntity(getPath(item), content, item.levelOptions) + ) + ) + ); }; diff --git a/lib/prepare-entity-data.js b/lib/get-entity-data.js similarity index 86% rename from lib/prepare-entity-data.js rename to lib/get-entity-data.js index 11e399b..a187c8e 100644 --- a/lib/prepare-entity-data.js +++ b/lib/get-entity-data.js @@ -3,9 +3,7 @@ var path = require('path'), bemNaming = require('@bem/naming'), BemEntityName = require('@bem/entity-name'), - BemCell = require('@bem/cell'), braceExpansion = require('brace-expansion'), - scheme = require('@bem/fs-scheme'), uniq = require('uniq'), bemConfig = require('bem-config'); @@ -60,8 +58,6 @@ module.exports = function prepareEntityData(entities, levels, techs, options) { var rootDir = config.rootSync() || cwd, level = path.resolve(rootDir, relLevel), levelOptions = config.levelSync(level) || {}, - levelScheme = levelOptions.scheme, - buildPath = scheme(levelScheme).path, currentTechs = uniq([].concat(levelOptions.techs || [], techs)), entity; @@ -85,21 +81,17 @@ module.exports = function prepareEntityData(entities, levels, techs, options) { })); return currentTechs.map(function(tech) { - var pathToFile = buildPath( - new BemCell({ entity: entity, tech: tech }), - levelOptions.schemeOptions || levelOptions), - absPathToFile = path.join(path.resolve(level), pathToFile); - if (options.forceRewrite) { levelOptions.forceRewrite = options.forceRewrite; } return { - path: absPathToFile, + config: config, levelOptions: levelOptions, tech: tech, options: options, - entity: entity + entity: entity, + level: level }; }); }); diff --git a/lib/get-path.js b/lib/get-path.js new file mode 100644 index 0000000..196a92a --- /dev/null +++ b/lib/get-path.js @@ -0,0 +1,16 @@ +const path = require('path'); +const scheme = require('@bem/fs-scheme'); +const BemCell = require('@bem/cell'); + +module.exports = function getPath(item) { + const levelOptions = item.config.levelSync(item.level) || {}; + const levelScheme = levelOptions.scheme; + const buildPath = scheme(levelScheme).path; + const pathToFile = buildPath( + new BemCell({ entity: item.entity, tech: item.tech }), + item.levelOptions.schemeOptions || item.levelOptions + ); + const absolutePath = path.join(path.resolve(item.level), pathToFile); + + return absolutePath; +}; diff --git a/test/test.js b/test/test.js index a594224..6a56435 100644 --- a/test/test.js +++ b/test/test.js @@ -8,7 +8,6 @@ const create = require('..'); const naming = require('@bem/naming'); const EOL = require('os').EOL; const assert = require('assert'); -const stream = require('stream'); const tmpDir = path.join(__dirname, 'tmp'); const initialCwd = process.cwd(); @@ -798,20 +797,5 @@ describe('bem-tools-create', () => { }]) ); }); - - it('should support custom content with pipe', () => { - const content = 'Some piped testing content'; - const srcStream = new stream.Readable(); - srcStream.push(content); - srcStream.push(null); - - return testEntityHelper([{ block: 'b' }], [tmpDir], ['css'], - { fileContent: srcStream }, [{ - name: path.join(tmpDir, 'b', 'b.css'), - content: content - }] - ); - }); - }); }); diff --git a/test/test1.js b/test/test1.js index 61b51c5..f2b62f4 100644 --- a/test/test1.js +++ b/test/test1.js @@ -3,12 +3,13 @@ const path = require('path'); const mkdirp = require('mkdirp'); const assert = require('assert'); -const prepareEntityData = require('../lib/prepare-entity-data'); +const getEntityData = require('../lib/get-entity-data'); +const getPath = require('../lib/get-path'); const tmpDir = process.cwd(); function testEntityHelper(entities, levels, techs, options, expected) { - const actualPaths = prepareEntityData(entities, levels, techs, options) - .map(item => item.path) + const actualPaths = getEntityData(entities, levels, techs, options) + .map(getPath) .sort(); const expectdPaths = expected .map(item => item.path)