{"id":14973423,"url":"https://github.com/guzart/gulp-ng-constant","last_synced_at":"2025-04-07T11:09:02.722Z","repository":{"id":14853082,"uuid":"17576255","full_name":"guzart/gulp-ng-constant","owner":"guzart","description":"Gulp plugin for dynamic generation of angular constant modules.","archived":false,"fork":false,"pushed_at":"2019-11-07T17:20:10.000Z","size":62,"stargazers_count":109,"open_issues_count":17,"forks_count":26,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-31T10:04:17.182Z","etag":null,"topics":["angular1","gulp-plugins","gulpfile"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"RiotGamesCookbooks/artifact-cookbook","license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/guzart.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-03-09T23:19:25.000Z","updated_at":"2021-02-04T14:24:14.000Z","dependencies_parsed_at":"2022-07-16T03:16:12.379Z","dependency_job_id":null,"html_url":"https://github.com/guzart/gulp-ng-constant","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/guzart%2Fgulp-ng-constant","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/guzart%2Fgulp-ng-constant/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/guzart%2Fgulp-ng-constant/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/guzart%2Fgulp-ng-constant/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/guzart","download_url":"https://codeload.github.com/guzart/gulp-ng-constant/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247640465,"owners_count":20971557,"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":["angular1","gulp-plugins","gulpfile"],"created_at":"2024-09-24T13:48:41.860Z","updated_at":"2025-04-07T11:09:02.695Z","avatar_url":"https://github.com/guzart.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"gulp-ng-constant\n================\n\n[![License](http://img.shields.io/badge/license-MIT-green.svg?style=flat)](https://npmjs.org/package/gulp-ng-constant)\n[![NPM version](http://img.shields.io/npm/dm/gulp-ng-constant.svg?style=flat)](https://npmjs.org/package/gulp-ng-constant)\n[![NPM version](http://img.shields.io/npm/v/gulp-ng-constant.svg?style=flat)](https://npmjs.org/package/gulp-ng-constant)  \n[![Build Status](https://travis-ci.org/guzart/gulp-ng-constant.svg)](https://travis-ci.org/guzart/gulp-ng-constant)\n[![Code Climate](https://codeclimate.com/github/guzart/gulp-ng-constant/badges/gpa.svg)](https://codeclimate.com/github/guzart/gulp-ng-constant)\n[![Dependency Status](https://gemnasium.com/guzart/gulp-ng-constant.svg)](https://gemnasium.com/guzart/gulp-ng-constant)\n\n## Information\n\n\u003ctable\u003e\n\u003ctr\u003e\n\u003ctd\u003ePackage\u003c/td\u003e\u003ctd\u003egulp-ng-constant\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd\u003eDescription\u003c/td\u003e\n\u003ctd\u003ePlugin for dynamic generation of angular constant modules.\u003cbr\u003e\nBased of \u003ca href=\"https://github.com/werk85/grunt-ng-constant\"\u003egrunt-ng-constant\u003c/a\u003e\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd\u003eNode Version\u003c/td\u003e\n\u003ctd\u003e\u003e= 0.10\u003c/td\u003e\n\u003c/tr\u003e\n\u003c/table\u003e\n\n## Index\n\n1. [Usage](#usage)\n  * [Configuration in gulpfile.js](#configuration-in-gulpfilejs)\n  * [Configuration in config.json](#configuration-in-configjson)\n2. [Options](#options)\n  * [name](#optionsname)\n  * [stream](#optionsstream)\n  * [constants](#optionsconstants)\n  * [merge](#optionsmerge)\n  * [deps](#optionsdeps)\n  * [wrap](#optionswrap)\n  * [wrapHeader](#optionswrapheader)\n  * [wrapFooter](#optionswrapfooter)\n  * [space](#optionsspace)\n  * [template](#optionstemplate)\n  * [templatePath](#optionstemplatepath)\n  * [indent](#optionsindent)\n3. [Examples](#examples)\n  * [Multiple Environments](#multiple-environments)\n  * [Stream](#stream)\n  * [YAML](#yaml)\n  * [ECMAScript 2015 (ES6)](#ecmascript-2015-es6)\n4. [Special Thanks](#special-thanks)\n\n## Usage\n\n### Configuration in `gulpfile.js`\n\n_**gulpfile.js**_\n\n```javascript\nvar ngConstant = require('gulp-ng-constant');\n\ngulp.task('config', function () {\n  gulp.src('app/config.json')\n    .pipe(ngConstant({\n      name: 'my.module.config',\n      deps: ['ngAnimate'],\n      constants: { myPropCnt: 'hola!' },\n      wrap: 'amd',\n    }))\n    // Writes config.js to dist/ folder\n    .pipe(gulp.dest('dist'));\n});\n```\n\n_**app/config.json**_\n```json\n{\n  \"myFirstCnt\": true,\n  \"mySecondCnt\": { \"hello\": \"world\" }\n}\n```\n\n_**dist/config.js**_ _(output)_\n\n```javascript\ndefine([\"require\", \"exports\"], function(require, exports) {\n  return angular.module(\"my.module.config\", [\"ngAnimate\"])\n    .constant(\"myFirstCnt\", true)\n    .constant(\"mySecondCnt\", { \"hello\": \"world\" })\n    .constant(\"myPropCnt\", \"hola!\");\n});\n```\n\n### Configuration in `config.json`\n\n_**gulpfile.js**_\n\n```javascript\nvar ngConstant = require('gulp-ng-constant');\n\ngulp.task('config', function () {\n  gulp.src('app/config.json')\n    .pipe(ngConstant())\n    // Writes config.js to dist/ folder\n    .pipe(gulp.dest('dist'));\n});\n```\n\n\n_**app/config.json**_\n\n```json\n{\n  \"name\": \"my.module.config\",\n  \"deps\": [\"ngAnimate\"],\n  \"wrap\": \"commonjs\",\n  \"constants\": {\n    \"myFirstCnt\": true,\n    \"mySecondCnt\": { \"hello\": \"world\" }\n  }\n}\n```\n\n_**dist/config.js**_ _(output)_\n\n```javascript\nmodule.exports = angular.module(\"my.module.config\", [\"ngAnimate\"])\n    .constant(\"myFirstCnt\", true)\n    .constant(\"mySecondCnt\", { \"hello\": \"world\" })\n    .constant(\"myPropCnt\", \"hola!\");\n```\n\n## Options\n\n#### options.name\n\nType: `string`  \nDefault: `filename` or `\"ngConstants\"`  \nOverrides: `json.name`  \n_optional_\n\nThe module name.\nThis property will override any `name` property defined in the input `json` file. The default name when used as a transform stream (i.e. regular plugin) is the passed file name. When [options.stream](#optionsstream) is `true` the default name is `\"ngConstants\"`.\n\n#### options.stream\n\nType: `boolean`  \nDefault: `false`  \n_optional_\n\nIf true it returns a new gulp stream, which can then be piped other gulp plugins\n([Example](#stream)).\n\n#### options.constants\n\nType: `Object | string`  \nDefault: `undefined`  \nExtends/Overrides: `json.constants`  \n\nConstants to defined in the module.\nCan be a `JSON` string or an `Object`.\nThis property extends the one defined in the input `json` file. If there are\nproperties with the same name, this properties will override the ones from the\ninput `json` file.\n\n#### options.merge\n\nType: `boolean`  \nDefault: `false`  \n_optional_  \n\nThis applies to constants of the Object type.\nIf true the constants of type Object from the input file and the constants\nfrom the configuration will be merged.\n\n#### options.deps\n\nType: `array\u003cstring\u003e|boolean`  \nDefault: `[]`  \nOverrides: `json.deps`  \n_optional_\n\nAn array that specifies the default dependencies a module should have. To add the constants to an existing module, you can set it to `false`.\nThis property will override any `deps` property defined in the input `json` file.\n\n#### options.wrap\n\nType: `boolean|string`  \nDefault: `'es6'`  \nAvailable: `[false, 'amd', 'commonjs', 'es6']`  \n_optional_\n\nA boolean to active or deactive the automatic wrapping.\nA string who will wrap the result of file, use the\n`\u003c%= __ngModule %\u003e` variable to indicate where to put the generated\nmodule content.\nA string with 'amd' that wraps the module as an AMD module,\ncompatible with RequireJS\n\n#### options.wrapHeader\n\nType: `string`  \nDefault: `null`  \n_optional_\n\nA string that is prepended to the wrapper.\n\n#### options.wrapFooter\n\nType: `string`  \nDefault: `null`  \n_optional_\n\nA string that is appended to the wrapper.\n\n#### options.space\n\nType: `string`  \nDefault: `null`  \n_optional_\n\nA string that defines how the JSON.stringify method will prettify your code, e.g. `'\\t'`, `' '`\n\n#### options.template\n\nType: `string`  \nDefault: _content of [tpls/constant.tpl.ejs](https://github.com/guzart/gulp-ng-constant/blob/master/tpls/constant.tpl.ejs)_  \n_optional_\n\nEJS template to apply when creating the output configuration file. The following variables\nare passed to the template during render:\n\n  * `moduleName`: the module name (`string`)\n  * `deps`: the module dependencies (`array\u003cstring\u003e`)\n  * `constants`: the module constants (`array\u003ccontantObj\u003e`)\n    * where a `constantObj` is an object with a `name` and a `value`, both `strings`.\n\n#### options.templatePath\n\nType: `string`  \nDefault: `'tpls/constant.tpl.ejs'`  \n_optional_\n\nLocation of a custom template file for creating the output configuration file. Defaults to the provided constants template file if none provided.\n\n#### options.indent\n\nType: `string`  \nDefault: `''` (empty string)  \n_optional_\n\nA string that is used to indent the `.constant()` lines in the generated file. Useful only for\nformatting the output file.\n\n## Examples\n\n### Multiple Environments\n\n_**config.json**_\n```json\n{\n  \"development\": { \"greeting\": \"Sup!\" },\n  \"production\": { \"greeting\": \"Hello\" }\n}\n```\n\n_**gulpfile.js**_\n```javascript\nvar gulp = require('gulp');\nvar ngConstant = require('gulp-ng-constant');\n\ngulp.task('constants', function () {\n  var myConfig = require('./config.json');\n  var envConfig = myConfig[process.env];\n  return ngConstant({\n      constants: envConfig,\n      stream: true\n    })\n    .pipe(gulp.dest('dist'));\n});\n\n```\n\n### Stream\n\n```javascript\nvar gulp = require('gulp');\nvar ngConstant = require('gulp-ng-constant');\nvar uglify = require('gulp-uglify');\n\ngulp.task('constants', function () {\n  var constants = { hello: 'world' };\n  return ngConstant({\n      constants: constants,\n      stream: true\n    })\n    .pipe(uglify())  \n    .pipe(gulp.dest('dist'));\n});\n```\n\n### YAML\n\nJust write your configuration in a YAML file and pipe it to the plugin.\n\n_**config.yml**_\n```yaml\ngreeting: Merry Christmas!\nseasons:\n  - Winter\n  - Spring\n  - Summer\n  - Fall\n```\n\n_**gulpfile.js**_\n```javascript\nvar gulp = require('gulp');\nvar ngConstant = require('gulp-ng-constant');\n\ngulp.task('constants', function () {\n  gulp.src('app/config.yml')\n    .pipe(ngConstant())\n    .pipe(gulp.dest('dist'));\n});\n```\n\n### ECMAScript 2015 (ES6)\n\n_**envs.json**_\n```json\n{\n  \"development\": {\n    \"ENV\": {\n        \"KEY\": \"secret\",\n        \"API_URL\": \"http://localhost/\"\n    }\n  },\n  \"production\": {\n    \"ENV\": {\n        \"KEY\": \"superSecret\",\n        \"API_URL\": \"http://example.com/\"\n    }\n  }\n}\n```\n\n_**gulpfile.babel.js**_\n```javascript\nimport gulp     from 'gulp';\nimport rename   from 'gulp-rename';\nimport ngConstant from 'gulp-ng-constant';\n\ngulp.task('constants', function () {\n  var myConfig = require('./envs.json');\n  var envConfig = myConfig[process.env];\n  return ngConstant({\n      name: \"app.env\",\n      constants: envConfig,\n      stream: true,\n      wrap: \"es6\"\n    })\n    .pipe(rename('env.js'))\n    .pipe(gulp.dest('dist'));\n});\n\n```\n\n_**app.js**_\n```javascript\n'use strict';\n\nimport angular from 'angular';\nimport env from 'env';\n\nlet app = angular.module('app', [env.name])\n    .factory('someRepository', function($http, ENV) {\n        //Just to illustrate\n        $http.get(ENV.API_URL);\n    });\n\n\nexport default app;\n\n```\n\n## Special Thanks\n\n@alexeygolev, @sabudaye, @ojacquemart, @lukehorvat, @rimian, @andidev, @dotDeeka, @LoicMahieu, @vladimirgamalian\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fguzart%2Fgulp-ng-constant","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fguzart%2Fgulp-ng-constant","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fguzart%2Fgulp-ng-constant/lists"}