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

Fixed mock-lang-js tech #100

Merged
merged 1 commit into from
Aug 4, 2015
Merged
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
30 changes: 13 additions & 17 deletions lib/techs/mock-lang-js.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
var vfs = require('enb/lib/fs/async-fs');
var vfs = require('enb/lib/fs/async-fs'),
File = require('enb-source-map/lib/file'),
EOL = require('os').EOL;

module.exports = require('enb/lib/build-flow').create()
.name('mock-lang-js.js')
.target('target', '?.js')
.useSourceFilename('source', '?.lang.js')
.builder(function (source) {
return vfs.read(source, 'utf8')
.then(function (content) {
var mock = [
.builder(function (sourceFilename) {
return vfs.read(sourceFilename, 'utf8')
.then(function (contents) {
var withSourceMaps = true,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Используется в одном месте. Просто передать true?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

В одном месте, просто чтобы читалось лучше.

file = new File(this._target, withSourceMaps),
mock = [
';(function(global, bem_) {',
' global.BEM = bem_;',
' var i18n = bem_.I18N = function(keyset, key, param) {',
Expand All @@ -21,20 +25,12 @@ module.exports = require('enb/lib/build-flow').create()
' i18n.key = function(key) { return key }',
' i18n.lang = function() { return }',
'}(this, typeof BEM === \'undefined\' ? {} : BEM));'
].join('\n'),
mapIndex = content.lastIndexOf('//# sourceMappingURL='),
map;
].join(EOL);

// if there is a #sourceMappingURL pragma append
// the mock before it so the source map will be
// valid. We can't insert it in the beginning because
// source map locations will point to the wrong lines.
if (mapIndex !== -1) {
map = content.substring(mapIndex);
content = content.substring(0, mapIndex);
}
file.write(mock);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Этот вызов пишет в файл или просто кудато в память складывает?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

В память инстанса. Если потом позвать file.render() сформируется строка, которую можно будет записать в файл.

file.writeFileContent(sourceFilename, contents);

return [content, mock, map].join('\n');
return file.render();
});
})
.createTech();