Skip to content

Commit 661d9a7

Browse files
committed
Merge pull request #2 from ValeryIvanov/refactor
lots of new features
2 parents 6701215 + 9202299 commit 661d9a7

File tree

11 files changed

+786
-170
lines changed

11 files changed

+786
-170
lines changed

.travis.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
language: node_js
2+
node_js:
3+
- "0.10"
4+
- "0.11"
5+
- "0.12"
6+
- "iojs"

README.md

Lines changed: 146 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,146 @@
1-
# gulp-props2json
2-
A Gulp plugin to convert Java .properties to JSON
1+
#[gulp](https://github.com/gulpjs/gulp)-props2json
2+
3+
[![npm version](https://badge.fury.io/js/gulp-props2json.svg)](http://badge.fury.io/js/gulp-props2json)
4+
[![Build Status](https://travis-ci.org/ValeryIvanov/gulp-props2json.svg?branch=master)](https://travis-ci.org/ValeryIvanov/gulp-props2json)
5+
[![Dependency Status](https://david-dm.org/ValeryIvanov/gulp-props2json.svg)](https://david-dm.org/ValeryIvanov/gulp-props2json)
6+
7+
> A [Gulp](https://github.com/gulpjs/gulp) plugin to convert [Java .properties](http://en.wikipedia.org/wiki/.properties) to [JSON](http://en.wikipedia.org/wiki/JSON)
8+
9+
10+
## Install
11+
12+
```sh
13+
npm install --save-dev gulp-props2json
14+
```
15+
16+
## Usage
17+
18+
Add this to your `gulpfile.js`:
19+
20+
```js
21+
var props2json = require('gulp-props2json');
22+
23+
// Generate a .json file
24+
gulp.src('./src/*.properties')
25+
.pipe(props2json())
26+
.pipe(gulp.dest('./dist/'))
27+
28+
// Generate a .js file
29+
gulp.src('./src/*.properties')
30+
.pipe(props({ outputType: 'js' }))
31+
.pipe(gulp.dest('./dist/'))
32+
```
33+
34+
35+
## API
36+
37+
### props2json([options])
38+
39+
40+
#### options.outputType
41+
42+
Type: `String`
43+
44+
Default: `json`
45+
46+
Convert properties to `.js` or `.json` format.
47+
48+
**Note**: To force a `.js` output set this option `js` (without dot).
49+
50+
51+
#### options.namespace
52+
53+
Type: `String`
54+
55+
Default: `null` for `.json` output and `props` for `.js` output
56+
57+
The namespace to use when defining properties. Javascript reserved words cannot be used here.
58+
Invalid identifiers will be adjusted to be valid, and a warning will be printed in the console.
59+
60+
61+
#### options.minify
62+
63+
Type: `Boolean`
64+
65+
Default: `true`
66+
67+
By default content `.js` and `.json` content is minified.
68+
If `.json` output is generated and minification is turned off and no space is defined, then indentation with 2 spaces is used.
69+
This can be overridden with space option.
70+
[JSON.stringify](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#The_space_argument)
71+
72+
73+
#### options.complexTypes
74+
75+
Type: `Boolean`
76+
77+
Default: `false`
78+
79+
By default every property value is treated as `String`. This option will try to convert every value to `JSON`.
80+
For example (`String`) `"true"` value will be (`Boolean`) `true`.
81+
[JSON.parse](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse)
82+
83+
84+
#### options.nestedProps
85+
86+
Type: `Boolean`
87+
88+
Default: `false`
89+
90+
By default every property key will be treated as it is. But nesting is possible to create complex object.
91+
If this option is turned on, then dot will be used as nesting delimiter. Nesting delimiter can be overridden with `nestingDelimiter` option.
92+
93+
94+
#### options.nestingDelimiter
95+
96+
Type: `String`
97+
98+
Default: `.`
99+
100+
Nesting delimiter to be used with `nestedProps` option.
101+
102+
103+
#### options.appendExt
104+
105+
Type: `Boolean`
106+
107+
Default: `false`
108+
109+
Append the extension (`.js` or `.json`) instead of replacing it.
110+
111+
_Useful if the property files does not have an extension._
112+
113+
114+
#### options.space
115+
116+
Type: `Number` or `String`
117+
118+
Default: `null`
119+
120+
Control spacing in the resulting output. It has the same usage as for [JSON.stringify](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify)
121+
122+
_The option is used only when `.json` output is generated._
123+
124+
125+
#### options.replacer
126+
127+
Type: `Function` or `Array`
128+
129+
Default: `null`
130+
131+
Further transform the resulting output. It has the same usage as for [JSON.stringify](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify)
132+
133+
_The option is used only when `.json` output is generated._
134+
135+
136+
## Errors
137+
138+
`gulp-props2json` emits an 'error' event if something goes wrong.
139+
140+
To handle errors across your entire pipeline, see the
141+
[gulp](https://github.com/gulpjs/gulp/blob/master/docs/recipes/combining-streams-to-handle-errors.md#combining-streams-to-handle-errors) documentation.
142+
143+
144+
## License
145+
146+
MIT © [Valery Ivanov](https://github.com/ValeryIvanov/)

gulpfile.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
var gulp = require('gulp');
2+
var mocha = require('gulp-mocha');
3+
var gutil = require('gulp-util');
4+
var istanbul = require('gulp-istanbul');
5+
6+
gulp.task('mocha', function() {
7+
return gulp.src(['test/*.js'], { read: false })
8+
.pipe(mocha({ reporter: 'list' }))
9+
.on('error', gutil.log);
10+
});
11+
12+
gulp.task('watch-mocha', function() {
13+
gulp.watch(['index.js', 'test/**'], ['mocha']);
14+
});
15+
16+
gulp.task('test', function (cb) {
17+
gulp.src(['index.js'])
18+
.pipe(istanbul()) // Covering files
19+
.pipe(istanbul.hookRequire()) // Force `require` to return covered files
20+
.on('finish', function () {
21+
gulp.src(['test/*.js'])
22+
.pipe(mocha())
23+
.pipe(istanbul.writeReports()) // Creating the reports after tests ran
24+
.pipe(istanbul.enforceThresholds({ thresholds: { global: 90 } })) // Enforce a coverage of at least 90%
25+
.on('end', cb);
26+
});
27+
});

0 commit comments

Comments
 (0)