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

Adding option to group constants under one constant name. See issue #38. #35

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
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