Skip to content
Open
Show file tree
Hide file tree
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
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,14 @@ _optional_

Location of a custom template file for creating the output configuration file. Defaults to the provided constants template file if none provided.

#### options.constantName

Type: `string`
Default: `undefined`
_optional_

Option to group object under one constant name, instead of creating a new constant object for each root key / value entry.

## Examples

### Multiple Environments
Expand Down Expand Up @@ -302,11 +310,11 @@ gulp.task('constants', function () {
_**envs.json**_
```json
{
"development": {
"development": {
"ENV": {
"KEY": "secret",
"API_URL": "http://localhost/"
}
}
},
"production": {
"ENV": {
Expand Down
10 changes: 9 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ var defaults = {
stream: false,
wrap: false,
template: undefined,
templatePath: TEMPLATE_PATH
templatePath: TEMPLATE_PATH,
constantName: undefined
};

function ngConstantPlugin(opts) {
Expand All @@ -48,6 +49,13 @@ function ngConstantPlugin(opts) {
try {
var data = file.isNull() ? {} : yaml.safeLoad(file.contents);

// Group constant under user defined constant name.
if (options.constantName) {
var tempData = data;
data = {};
data[options.constantName] = tempData;
}

// Create the module string
var result = _.template(template)({
moduleName: getModuleName(data, options, file),
Expand Down