Skip to content

Commit

Permalink
Add a Broccoli plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
karellm committed May 30, 2018
1 parent 54bb38a commit 9e34f76
Show file tree
Hide file tree
Showing 19 changed files with 4,853 additions and 476 deletions.
35 changes: 32 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,17 @@ Save the package to your devDependencies:

```
yarn add -D i18next-parser@next
npm install --save-dev i18next-parser
npm install --save-dev i18next-parser@next
```

[Gulp](http://gulpjs.com/) defines itself as the streaming build system. Put simply, it is like Grunt, but performant and elegant.

```javascript
const i18next = require('i18next-parser');
const i18nextParser = require('i18next-parser').gulp;

gulp.task('i18next', function() {
gulp.src('app/**')
.pipe(new i18next({
.pipe(new i18nextParser({
locales: ['en', 'de'],
output: 'locales'
}))
Expand All @@ -67,6 +67,35 @@ gulp.task('i18next', function() {

**IMPORTANT**: `output` is required to know where to read the catalog from. You might think that `gulp.dest()` is enough though it does not inform the transform where to read the existing catalog from.

### Broccoli

Save the package to your devDependencies:

```
yarn add -D i18next-parser@next
npm install --save-dev i18next-parser@next
```

[Broccoli.js](https://github.com/broccolijs/broccoli) defines itself as a fast, reliable asset pipeline, supporting constant-time rebuilds and compact build definitions.

```javascript

const Funnel = require('broccoli-funnel')
const i18nextParser = require('i18next-parser').broccoli;

const appRoot = 'broccoli'

let i18n = new Funnel(appRoot, {
files: ['handlebars.hbs', 'javascript.js'],
annotation: 'i18next-parser'
})

i18n = new i18nextParser([i18n], {
output: 'broccoli/locales'
})

module.exports = i18n
```

## Options

Expand Down
2 changes: 1 addition & 1 deletion bin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

var colors = require('colors')
var fs = require('fs')
var i18nTransform = require('../dist')
var i18nTransform = require('../dist/transform')
var path = require('path')
var pkg = require('../package.json')
var program = require('commander')
Expand Down
60 changes: 60 additions & 0 deletions dist/broccoli.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
'use strict';Object.defineProperty(exports, "__esModule", { value: true });var _createClass = function () {function defineProperties(target, props) {for (var i = 0; i < props.length; i++) {var descriptor = props[i];descriptor.enumerable = descriptor.enumerable || false;descriptor.configurable = true;if ("value" in descriptor) descriptor.writable = true;Object.defineProperty(target, descriptor.key, descriptor);}}return function (Constructor, protoProps, staticProps) {if (protoProps) defineProperties(Constructor.prototype, protoProps);if (staticProps) defineProperties(Constructor, staticProps);return Constructor;};}();var _colors = require('colors');var _colors2 = _interopRequireDefault(_colors);
var _fsExtra = require('fs-extra');var _fsExtra2 = _interopRequireDefault(_fsExtra);
var _path = require('path');var _path2 = _interopRequireDefault(_path);
var _broccoliPlugin = require('broccoli-plugin');var _broccoliPlugin2 = _interopRequireDefault(_broccoliPlugin);
var _transform = require('../dist/transform');var _transform2 = _interopRequireDefault(_transform);
var _rsvp = require('rsvp');var _rsvp2 = _interopRequireDefault(_rsvp);
var _gulpSort = require('gulp-sort');var _gulpSort2 = _interopRequireDefault(_gulpSort);
var _vinylFs = require('vinyl-fs');var _vinylFs2 = _interopRequireDefault(_vinylFs);function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };}function _classCallCheck(instance, Constructor) {if (!(instance instanceof Constructor)) {throw new TypeError("Cannot call a class as a function");}}function _possibleConstructorReturn(self, call) {if (!self) {throw new ReferenceError("this hasn't been initialised - super() hasn't been called");}return call && (typeof call === "object" || typeof call === "function") ? call : self;}function _inherits(subClass, superClass) {if (typeof superClass !== "function" && superClass !== null) {throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);}subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } });if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass;}

var Promise = _rsvp2.default.Promise;var

i18nextParser = function (_Plugin) {_inherits(i18nextParser, _Plugin);
function i18nextParser(inputNodes) {var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};_classCallCheck(this, i18nextParser);var _this = _possibleConstructorReturn(this, (i18nextParser.__proto__ || Object.getPrototypeOf(i18nextParser)).apply(this,
arguments));
_this.options = options;return _this;
}_createClass(i18nextParser, [{ key: 'build', value: function build()

{var _this2 = this;
var outputPath = this.outputPath;
return new Promise(function (resolve, reject) {
var files = [];
var count = 0;

_vinylFs2.default.src(_this2.inputPaths.map(function (x) {return x + '/**/*.{js,hbs}';})).
pipe((0, _gulpSort2.default)()).
pipe(
new _transform2.default(_this2.options).
on('reading', function (file) {
if (!this.options.silent) {
console.log(' [read] '.green + file.path);
}
count++;
}).
on('data', function (file) {
files.push(
_fsExtra2.default.outputFile(file.path, file.contents));

if (!this.options.silent) {
console.log(' [write] '.green + file.path);
}
}).
on('error', function (message, region) {
if (typeof region === 'string') {
message += ': ' + region.trim();
}
console.log(' [error] '.red + message);
}).
on('finish', function () {
if (!this.options.silent) {
console.log();
}
console.log(' Stats: '.yellow + count + ' files were parsed');

Promise.all(files).then(function () {
resolve(files);
});
}));

});
} }]);return i18nextParser;}(_broccoliPlugin2.default);exports.default = i18nextParser;module.exports = exports['default'];
232 changes: 4 additions & 228 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 9e34f76

Please sign in to comment.