{"id":29118838,"url":"https://github.com/atticoos/gulp-ng-config","last_synced_at":"2026-03-10T12:32:28.977Z","repository":{"id":19761726,"uuid":"23019377","full_name":"atticoos/gulp-ng-config","owner":"atticoos","description":":wrench: Create AngularJS constants from a JSON config file","archived":false,"fork":false,"pushed_at":"2021-03-07T19:55:13.000Z","size":108,"stargazers_count":173,"open_issues_count":10,"forks_count":35,"subscribers_count":3,"default_branch":"develop","last_synced_at":"2025-06-10T14:50:46.051Z","etag":null,"topics":["angular","javascript","json"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/atticoos.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-08-16T14:18:35.000Z","updated_at":"2024-07-31T22:51:21.000Z","dependencies_parsed_at":"2022-08-25T01:31:14.875Z","dependency_job_id":null,"html_url":"https://github.com/atticoos/gulp-ng-config","commit_stats":null,"previous_names":["ajwhite/gulp-ng-config"],"tags_count":19,"template":false,"template_full_name":null,"purl":"pkg:github/atticoos/gulp-ng-config","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/atticoos%2Fgulp-ng-config","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/atticoos%2Fgulp-ng-config/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/atticoos%2Fgulp-ng-config/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/atticoos%2Fgulp-ng-config/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/atticoos","download_url":"https://codeload.github.com/atticoos/gulp-ng-config/tar.gz/refs/heads/develop","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/atticoos%2Fgulp-ng-config/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262598176,"owners_count":23334670,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["angular","javascript","json"],"created_at":"2025-06-29T13:05:28.257Z","updated_at":"2025-12-12T03:02:19.024Z","avatar_url":"https://github.com/atticoos.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# gulp-ng-config\n\n[![License](http://img.shields.io/badge/license-MIT-blue.svg?style=flat)](https://npmjs.org/package/gulp-ng-config)\n[![NPM version](http://img.shields.io/npm/v/gulp-ng-config.svg?style=flat)](https://npmjs.org/package/gulp-ng-config)\n[![NPM version](http://img.shields.io/npm/dm/gulp-ng-config.svg?style=flat)](https://npmjs.org/package/gulp-ng-config)\n[![Build Status](http://img.shields.io/travis/ajwhite/gulp-ng-config.svg?style=flat)](http://travis-ci.org/ajwhite/gulp-ng-config)\n[![Coverage Status](https://coveralls.io/repos/ajwhite/gulp-ng-config/badge.svg?branch=develop\u0026service=github)](https://coveralls.io/github/ajwhite/gulp-ng-config?branch=develop)\n[![Code Climate](https://codeclimate.com/github/ajwhite/gulp-ng-config/badges/gpa.svg)](https://codeclimate.com/github/ajwhite/gulp-ng-config)\n[![Dependency Status](http://img.shields.io/gemnasium/ajwhite/gulp-ng-config.svg?style=flat)](https://gemnasium.com/ajwhite/gulp-ng-config)\n\n[![NPM](https://nodei.co/npm/gulp-ng-config.png?downloads=true\u0026downloadRank=true\u0026stars=true)](https://nodei.co/npm/gulp-ng-config/)\n\nIt's often useful to generate a file of constants, usually as environment variables, for your Angular apps.\nThis Gulp plugin will allow you to provide an object of properties and will generate an Angular module of constants.\n\n## To Install:\n`npm install gulp-ng-config`\n\n## How it works\nIt's pretty simple:\n`gulpNgConfig(moduleName)`\n\n\n## Example Usage\nWe start with our task. Our source file is a JSON file containing our configuration. We will pipe this through `gulpNgConfig` and out will come an angular module of constants.\n```javascript\nvar gulp = require('gulp');\nvar gulpNgConfig = require('gulp-ng-config');\n\ngulp.task('test', function () {\n  gulp.src('configFile.json')\n  .pipe(gulpNgConfig('myApp.config'))\n  .pipe(gulp.dest('.'))\n});\n```\nAssume that `configFile.json` contains:\n```json\n{\n  \"string\": \"my string\",\n  \"integer\": 12345,\n  \"object\": {\"one\": 2, \"three\": [\"four\"]},\n  \"array\": [\"one\", 2, {\"three\": \"four\"}, [5, \"six\"]]\n}\n```\nRunning `gulp test` will take `configFile.json` and produce `configFile.js` with the following content:\n\n```js\nangular.module('myApp.config', [])\n.constant('string', \"my string\")\n.constant('integer', 12345)\n.constant('object', {\"one\":2,\"three\":[\"four\"]})\n.constant('array', [\"one\",2,{\"three\":\"four\"},[5,\"six\"]]);\n```\nWe now can include this configuration module in our main app and access the constants\n```js\nangular.module('myApp', ['myApp.config']).run(function (string) {\n  console.log(\"The string constant!\", string) // outputs \"my string\"\n});\n```\n\n\n## Configuration\nCurrently there are a few configurable options to control the output of your configuration file:\n- [options.environment](#options.environment)\n- [options.constants](#options.constants)\n- [options.createModule](#options.createModule)\n- [options.type](#options.type)\n- [options.wrap](#options.wrap)\n- [options.parser](#options.parser)\n- [options.pretty](#options.pretty)\n- [options.keys](#options.keys),\n- [options.templateFilePath](#options.templateFilePath)\n\n### \u003ca id=\"options.environment\"\u003e\u003c/a\u003eoptions.environment\nType: `String` Optional\n\nIf your configuration contains multiple environments, you can supply the key you want the plugin to load from your configuration file.\n\nExample `config.json` file with multiple environments:\n```json\n{\n  \"local\": {\n    \"EnvironmentConfig\": {\n      \"api\": \"http://localhost/\"\n    }\n  },\n  \"production\": {\n    \"EnvironmentConfig\": {\n      \"api\": \"https://api.production.com/\"\n    }\n  }\n}\n```\n\nUsage of the plugin:\n```js\ngulpNgConfig('myApp.config', {\n  environment: 'production'\n})\n```\n\nExpected output:\n```js\nangular.module('myApp.config', [])\n.constant('EnvironmentConfig', {\"api\": \"https://api.production.com/\"});\n```\n\n#### Nested Environment\nIf the configuration is nested it can be accessed by the namespace, for example\n```json\n{\n  \"version\": \"0.1.0\",\n  \"env\": {\n    \"local\": {\n      \"EnvironmentConfig\": {\n        \"api\": \"http://localhost/\"\n      }\n    },\n    \"production\": {\n      \"EnvironmentConfig\": {\n        \"api\": \"https://api.production.com/\"\n      }\n    }\n  }\n}\n```\n\nUsage of the plugin:\n```js\ngulpNgConfig('myApp.config', {\n  environment: 'env.production'\n})\n```\n\nExpected output:\n```js\nangular.module('myApp.config', [])\n.constant('EnvironmentConfig', {\"api\": \"https://api.production.com/\"});\n```\n\n#### Multiple Environment keys\nMultiple environment keys can be supplied in an array, for example for global and environmental constants\n```json\n{\n  \"global\": {\n    \"version\": \"0.1.0\"\n   },\n  \"env\": {\n    \"local\": {\n      \"EnvironmentConfig\": {\n        \"api\": \"http://localhost/\"\n      }\n    },\n    \"production\": {\n      \"EnvironmentConfig\": {\n        \"api\": \"https://api.production.com/\"\n      }\n    }\n  }\n}\n```\n\nUsage of the plugin:\n```js\ngulpNgConfig('myApp.config', {\n  environment: ['env.production', 'global']\n})\n```\n\nExpected output:\n```js\nangular.module('myApp.config', [])\n.constant('EnvironmentConfig', {\"api\": \"https://api.production.com/\"});\n.constant('version', '0.1.0');\n```\n\n### \u003ca id=\"options.constants\"\u003e\u003c/a\u003eoptions.constants\nType: `Object` Optional\n\nYou can also override properties from your json file or add more by including them in the gulp tasks:\n```javascript\ngulpNgConfig('myApp.config', {\n  constants: {\n    string: 'overridden',\n    random: 'value'\n  }\n});\n```\nGenerating `configFile.js`\n```js\nangular.module('myApp.config', [])\n.constant('string', \"overridden\")\n.constant('integer', 12345)\n.constant('object', {\"one\":2,\"three\":[\"four\"]})\n.constant('array', [\"one\",2,{\"three\":\"four\"},[5,\"six\"]])\n.constant('random', \"value\");\n\n```\n\n### \u003ca id=\"options.type\"\u003e\u003c/a\u003eoptions.type\nType: `String` Default value: `'constant'` Optional\n\nThis allows configuring the type of service that is created -- a `constant` or a `value`. By default, a `constant` is created, but a `value` can be overridden. Possible types:\n\n- `'constant'`\n- `'value'`\n\n```javascript\ngulpNgConfig('myApp.config', {\n  type: 'value'\n});\n```\n\nThis will produce `configFile.js` with a `value` service.\n```javascript\nangular.module('myApp.config', [])\n.value('..', '..');\n```\n\n### \u003ca id=\"options.createModule\"\u003e\u003c/a\u003eoptions.createModule\nType: `Boolean` Default value: `true` Optional\n\nBy default, a new module is created with the name supplied. You can access an existing module, rather than creating one, by setting `createModule` to false.\n```javascript\ngulpNgConfig('myApp.config', {\n  createModule: false\n});\n```\n\nThis will produce `configFile.js` with an existing angular module\n```javascript\nangular.module('myApp.config')\n.constant('..', '..');\n```\n\n### \u003ca id=\"options.wrap\"\u003e\u003c/a\u003eoptions.wrap\nType: `Boolean` or `String` Default value: `false` Optional\n\nPresets:\n- `ES6`\n- `ES2015`\n\nWrap the configuration module in an IIFE or your own wrapper.\n\n```js\ngulpNgConfig('myApp.config', {\n  wrap: true\n})\n```\n\nWill produce an IIFE wrapper for your configuration module:\n```javascript\n(function () {\n  return angular.module('myApp.config') // [] has been removed\n  .constant('..', '..');\n})();\n```\n\nYou can provide a custom wrapper. Provide any string you want, just make sure to include `\u003c%= module %\u003e` for where you want to embed the angular module.\n```js\ngulpNgConfig('myApp.config', {\n  wrap: 'define([\"angular\"], function () {\\n return \u003c%= module %\u003e \\n});'\n});\n```\n\nThe reuslting file will contain:\n```js\ndefine([\"angular\"], function () {\n return angular.module('myApp.config', [])\n.constant('..', '..');\n});\n```\n\n### \u003ca id=\"options.parser\"\u003e\u003c/a\u003eoptions.parser\nType: `String` Default value: 'json' Optional\n\nBy default, json file is used to generate the module. You can provide yml file to generate the module. Just set `parser` to `'yml'` or `'yaml'`. If your file type is yml and you have not defined `parser`, your file will still be parsed and js be generated correctly.\nFor example, you have a `config.yml` file,\n```yml\nstring: my string\ninteger: 12345\nobject:\n  one: 2\n  three:\n    - four\n```\n\n```javascript\ngulp.src(\"config.yml\")\n.pipe(gulpNgConfig('myApp.config', {\n  parser: 'yml'\n}));\n```\n\nGenerating,\n```js\nangular.module('myApp.config', [])\n.constant('string', \"my string\")\n.constant('integer', 12345)\n.constant('object', {\"one\":2,\"three\":[\"four\"]});\n```\n\n### \u003ca id=\"options.pretty\"\u003e\u003c/a\u003eoptions.pretty\nType: `Number|Boolean` Default value: `false` Optional\n\nThis allows `JSON.stringify` to produce a `pretty` formatted output string.\n\n```js\ngulp.src('config.json')\n.pipe(gulpNgConfig('myApp.config', {\n  pretty: true // or 2, 4, etc -- all representing the number of spaces to indent\n}));\n```\n\nWill output a formatted `JSON` object in the constants, instead of inline.\n```js\nangular.module(\"gulp-ng-config\", [])\n.constant(\"one\", {\n  \"two\": \"three\"\n});\n```\n\n### \u003ca id=\"options.keys\"\u003e\u003c/a\u003eoptions.keys\nType: `Array` Optional\n\nIf you only want some of the keys from the object imported, you can supply the keys you want the plugin to load.\n\nExample `config.json` file with unwanted keys:\n```json\n{\n  \"version\": \"0.0.1\",\n  \"wanted key\": \"wanted value\",\n  \"unwanted key\": \"unwanted value\"\n}\n```\n\nUsage of the plugin:\n```js\ngulpNgConfig(\"myApp.config\", {\n  keys: [\"version\", \"wanted key\"]\n})\n```\n\nExpected output:\n```js\nangular.module(\"myApp.config\", [])\n.constant(\"version\", \"0.0.1\")\n.constant(\"wanted key\", \"wanted value\");\n```\n\n### \u003ca id=\"options.templateFilePath\"\u003e\u003c/a\u003eoptions.templateFilePath\nType: `String` Optional\n\nThis allows the developer to provide a custom output template.\n\nSample template:\n`angularConfigTemplate.html`\n```html\nvar foo = 'bar';\n\nangular.module(\"\u003c%= moduleName %\u003e\"\u003c% if (createModule) { %\u003e, []\u003c% } %\u003e)\u003c% _.forEach(constants, function (constant) { %\u003e\n.\u003c%= type %\u003e(\"\u003c%= constant.name %\u003e\", \u003c%= constant.value %\u003e)\u003c% }); %\u003e;\n```\n\nConfiguration:\n```json\n{\n  \"Foo\": \"bar\"\n}\n```\n\nGulp task:\n```js\ngulp.src('config.json')\n.pipe(gulpNgConfig('myApp.config', {\n  templateFilePath: path.normalize(path.join(__dirname, 'templateFilePath.html'))\n}));\n```\n\nSample output:\n```js\nvar foo = 'bar';\n\nangular.module('myApp.config', [])\n.constant('Foo', 'bar');\n```\n\n## Additional Usages\n\n### Without a json/yaml file on disk\nUse `buffer-to-vinyl` to create and stream a vinyl file into `gulp-ng-config`. Now config values can come from environment variables, command-line arguments or anywhere else.\n\n```js\nvar b2v = require('buffer-to-vinyl');\nvar gulpNgConfig = require('gulp-ng-config');\n\ngulp.task('make-config', function() {\n  var json = JSON.stringify({\n    // your config here\n  });\n\n  return b2v.stream(new Buffer(json), 'config.js')\n    .pipe(gulpNgConfig('myApp.config'))\n    .pipe(gulp.dest('build'));\n});\n```\n\n### ES6/ES2015\nAn ES6/ES2015 template can be generated by passing `wrap: true` as a configuration to the plugin\n\n## Contributing\nContributions, issues, suggestions, and all other remarks are welcomed. To run locally just fork \u0026amp; clone the project and run `npm install`. Before submitting a Pull Request, make sure that your changes pass `gulp test`, and if you are introducing or changing a feature, that you add/update any tests involved.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fatticoos%2Fgulp-ng-config","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fatticoos%2Fgulp-ng-config","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fatticoos%2Fgulp-ng-config/lists"}