atticoos / gulp-ng-config Goto Github PK
View Code? Open in Web Editor NEW:wrench: Create AngularJS constants from a JSON config file
License: MIT License
:wrench: Create AngularJS constants from a JSON config file
License: MIT License
A part of the strings on this file are written in single quotes and the other part is written in double quotes and it breaks JSHint validation.
Example:
angular.module('foo.config', [])
.constant('foo', "bar");
gulp.src('config/local.json')
.pipe(extend('config/defaults.json'))
.pipe(ngConfig('config-module'))
.pipe(gulp.dest("app/"));
I use gulp-extend because I need to extend defaults.json with local.json AND THEN pipe it into ngConfig.
However, the output file created is:
app/config/defaults.js
Whereas I need it to output
app/config.js
Can we please get more control over the file name (it's not necessarily the same as the json file name)
and well as not creating the extra config folder (since gulp.dest is already specified it should output there directly).
If options.environment
was set to non existing key in configuration json, then plugin will silently fail and give back unexpected config value, that includes all existing environments. See https://github.com/ajwhite/gulp-ng-config/blob/develop/gulp-ng-config.js#L65
It would be better to throw an error, so that build could exit with non-zero code if incorrect environment was specified. Alternatively this can be made optional, so that it throws only if options.thrownOnBadEnviroment
or something like that. is set.
What do you think about it?
Option to generate angular config file with values instead constants.
angular.module('myApp.config', [])
.value('string', "my string");
I am trying to implement a configuration basically just like the Nested configuration example, with some environmental variables and some general ones.
So, with this:
{
"version": "0.1.0",
"env": {
"local": {
"EnvironmentConfig": {
"api": "http://localhost/"
}
},
"production": {
"EnvironmentConfig": {
"api": "https://api.production.com/"
}
}
}
}
gulpNgConfig('myApp.config', {
environment: 'env.production'
})
I was hoping I could get this:
angular.module('myApp.config', [])
.constant('EnvironmentConfig', {"api": "https://api.production.com/"})
.constant("version", "v0.1.0");
But I only get the environmental variable. So what is the point of having the nested environment or how can I get the non environmental variables to be added too?
options.pretty
isn't currently in the readme
i have "lodash": "~4.0.0"
and "gulp-ng-config": "^1.3.1"
created a task
gulp.task('env', function () {
gulp.src(path.join(conf.paths.src, 'env.json'))
.pipe($.ngConfig('app', {
createModule: false,
wrap: true
}))
.pipe(gulp.dest(path.join(conf.paths.src, '/app/')));
});
but when i run gulp env;
it gives error
/opt/baffle-manager/WebUI/node_modules/gulp-ng-config/gulp-ng-config.js:83
if (!_.contains(VALID_TYPES, configuration.type)) {
^
TypeError: _.contains is not a function
at DestroyableTransform._transform (/opt/my-project/WebUI/node_modules/gulp-ng-config/gulp-ng-config.js:83:12)
at DestroyableTransform.Transform._read (/opt/my-project/WebUI/node_modules/through2/node_modules/readable-stream/lib/_stream_transform.js:159:10)
at DestroyableTransform.Transform._write (/opt/my-project/WebUI/node_modules/through2/node_modules/readable-stream/lib/_stream_transform.js:147:83)
at doWrite (/opt/my-project/WebUI/node_modules/through2/node_modules/readable-stream/lib/_stream_writable.js:313:64)
at writeOrBuffer (/opt/my-project/WebUI/node_modules/through2/node_modules/readable-stream/lib/_stream_writable.js:302:5)
at DestroyableTransform.Writable.write (/opt/my-project/WebUI/node_modules/through2/node_modules/readable-stream/lib/_stream_writat DestroyableTransform._transform (/opt/my-project/WebUI/node_modules/gulp-ng-config/gulp-ng-config.js:83:12)
at DestroyableTransform.Transform._read (/opt/my-project/WebUI/node_modules/through2/node_modules/readable-stream/lib/_stream_transform.js:159:10)
at DestroyableTransform.Transform._write (/opt/my-project/WebUI/node_modules/through2/node_modules/readable-stream/lib/_stream_transform.js:147:83)
at doWrite (/opt/my-project/WebUI/node_modules/through2/node_modules/readable-stream/lib/_stream_writable.js:313:64)
at writeOrBuffer (/opt/my-project/WebUI/node_modules/through2/node_modules/readable-stream/lib/_stream_writable.js:302:5)
at DestroyableTransform.Writable.write (/opt/my-project/WebUI/node_modules/through2/node_modules/readable-stream/lib/_stream_writable.js:241:11)
at write (/opt/my-project/WebUI/node_modules/vinyl-fs/node_modules/readable-stream/lib/_stream_readable.js:623:24)
at flow (/opt/my-project/WebUI/node_modules/vinyl-fs/node_modules/readable-stream/lib/_stream_readable.js:632:7)
at DestroyableTransform.pipeOnReadable (/opt/my-project/WebUI/node_modules/vinyl-fs/node_modules/readable-stream/lib/_stream_readable.js:664:5)
at emitNone (events.js:86:13)
at DestroyableTransform.emit (events.js:185:7)
at emitReadable_ (/opt/my-project/WebUI/node_modules/vinyl-fs/node_modules/readable-stream/lib/_stream_readable.js:448:10)
at emitReadable (/opt/my-project/WebUI/node_modules/vinyl-fs/node_modules/readable-stream/lib/_stream_readable.js:444:5)
at readableAddChunk (/opt/my-project/WebUI/node_modules/vinyl-fs/node_modules/readable-stream/lib/_stream_readable.js:187:9)
at DestroyableTransform.Readable.push (/opt/my-project/WebUI/node_modules/vinyl-fs/node_modules/readable-stream/lib/_stream_readable.js:149:10)
at DestroyableTransform.Transform.push (/opt/my-project/WebUI/node_modules/vinyl-fs/node_modules/readable-stream/lib/_stream_transform.js:145:32)
I would like to provide default values for my config in the gulpfile. These values might be overridden by the config.json (or config.yml). At the moment the constants option only provides to extend or override the values of the config file, not vice versa. Do you think, this is a good idea?
BTW: Nice plugin. Thanks for your work.
Hey,
First, thank you for this module, it looks great!
Are you planning to release the version 1.3 ?
Thanks
"development": {
"string": "my string",
"integer": 12345,
"object": {"one": 2, "three": ["four"]},
"array": ["one", 2, {"three": "four"}, [5, "six"]]
},
"staging": {
"string": "my string",
"integer": 12345,
"object": {"one": 2, "three": ["four"]},
"array": ["one", 2, {"three": "four"}, [5, "six"]]
},
"production": {
"string": "my string",
"integer": 12345,
"object": {"one": 2, "three": ["four"]},
"array": ["one", 2, {"three": "four"}, [5, "six"]]
}
The package gulp-ng-config in npm doesn't accept environment configuration like "env.production", for example. I think that this happen because npm's package may not be up to date.
the 1.2.1 version contains this:
// select the environment in the configuration
if (configuration.environment && jsonObj.hasOwnProperty(configuration.environment)) {
jsonObj = jsonObj[configuration.environment];
}
Multiple node versions have been added to travis, however each one will report to coveralls during after_scripts
. This really only needs to happen once.
The empty array causes the following error:
[$injector:modulerr]
Is there away to override the empty array? If I remove it, the error disappears.
I see that currently it just supports config from json file, it will be better to have it support yaml file as well.
TypeError: First argument needs to be a number, array or string.
at new Buffer (buffer.js:188:15)
at DestroyableTransform._transform (.../node_modules/gulp-ng-config/gulp-ng-config.js:69:21)
I have the following custom wrapper:
wrap: '\'use strict\'\n\nimport angular from \'angular\'\n\nexport default <%= module %>\n .name\n'
the expected output is:
'use strict'
import angular from 'angular'
export default angular.module("sisaApp.config", [])
.constant("environment", "development")
.name
but I get this:
'use strict'
import angular from 'angular'
export default angular.module("sisaApp.config", [])
.constant("environment", "development");
.name
the ;
screws up with my code. I don't use ;
because I follow standardjs.
Hello,
I installed gulp-ng-config with the command "npm install gulp-ng-config; bower install".
When i run "gulp test", i got:
ReferenceError: Can't find variable: require
at bower_components/gulp-ng-config/gulp-ng-config.js:3
Any ideas ?
Finish up the left over test, and clean up the logic branches in #27
Getting some weird issues with JSCS on its latest version. Need to reevaluate a few things before bringing back. Discovered in #6
There should be a way to override the module created or used instead of relying on the file name.
So if we have a file and module called config that we want to add some environment variables to we can create a file called config.env.js and add the defined variables to the config module.
It would be great. 😄
I wish to change the generated file name, e.g. to index.js, is this possible? I don't want to call the json file index.json
Hi,
In some cases this doesn't work:
angular.module('myApp.config')
.constant('random', "value");
You have to do this:
angular.module('myApp.config', [])
.constant('random', "value");
It could be better to generate, by default, the empty array []
to avoid issues.
And for enhancement, make an option to populate this argument. I don't need this feature at the moment by the way. But I really need the empty array added by your Gulp plugin. :)
Bests
Would be good to have ability to use with ES6/CommonJS modules;
import angular from 'angular';
angular.constant(...)
the use case i'm thinking of is pass a command line param to gulp and pass that directly to the plugin
gulpNgConfig('myApp.config', {
constants: {
apiUrl: argv.apiUrl
}
});
this would be especially nice since it allows you to avoid putting the value of your constants in source control, which is what drew me to this in the first place.
my workaround for the time being will be to create a json file that is just {}
All constants now is a single line, but it's little bit hard to track changes in config if it little more deeper:
Json file:
{
"ACTIONS": {
"list": {
"click": {
"description": "just a click",
"params": {
"some": null,
"another": false
}
}
...
}
What we have now:
.constant('ACTIONS', {"list":{"click":{"description": "just a click","params":{"some": null,"another": false}}}})
What i'm expext:
.constant('ACTIONS', {
"list": {
"click": {
"description": "just a click",
"params": {
"some": null,
"another": false
}
},
Hi,
config.json:
{
"Blog.Config": {
"base_url": "http://localhost/angularjs/",
"api_endpoint": "http://api.domain.net"
}
}
gulpfile.js
gulp.task('config', function () {
return gulp
.src('app/config.json')
.pipe(ngconfig('Blog'))
.pipe(gulp.dest('app'));
});
Gives me:
config.js
angular.module('Blog')
.constant('Blog.Config', {"base_url":"http://localhost/angularjs/","api_endpoint":"http://api.domain.net"});
It's OK, but:
gulp.task('config_prod', function () {
return gulp
.src('app/config.json')
.pipe(ngconfig('Blog', {
'Blog.Config': {
api_endpoint: 'http://api.domain.com'
}
}))
.pipe(gulp.dest('app'));
});
Gives me:
config.js
angular.module('Blog')
.constant('Blog.Config', {"api_endpoint":"http://api.domain.com"});
base_url
is removed. Why? v0.1.3 is used.
Bests
A short javascript comment should be included at the top of the output file, to let developers know it's a auto generated and shouldn't be tampered with.
I would like to send a PR in to add 'use strict'
in WRAP_TEMPLATE for linters. Should I add it as an option or add it as part of the WRAP_TEMPLATE
string?
gulp-util is now deprecated. I don't see any direct use of it here so it looks to be in use by one/more dependencies.
Details can be seen here - https://medium.com/gulpjs/gulp-util-ca3b1f9f9ac5
I'm using the constants option to inject build info into Angular (latest commit SHA, branch, tag...) and I'm also using environment dependent configurations.
config.json
{
"prod": {},
"dev": {}
}
And in gulpFile.js:
gulp
.src(appPath + '/config.json')
.pipe(gulpNgConfig('app.config', {
environment: args.environment,
constants: {
environment: args.environment,
buildInfo: buildInfo
}
}))
.pipe(gulp.dest(appPath));
Right now, the environment dependent configs win over constants and the generated config omits "environment" and "buildInfo". I've figured out what the issue was and it was a very simple fix. Creating a PR for it.
my config.json file with multiple environments:
{
"local": {
"EnvironmentConfig": {
"api": "http://localhost/"
}
},
"production": {
"EnvironmentConfig": {
"api": "https://api.production.com/"
}
}
}
Usage of the plugin:
gulpNgConfig('myApp.config', {
environment: 'production'
})
Expected output:
angular.module('myApp.config', [])
.constant('EnvironmentConfig', {"api": "https://api.production.com/"});
But my output configFile.js:
angular.module("todoApp.config", [])
.constant("local", {"EnvironmentConfig":{"api":"http://localhost/"}})
.constant("production", {"EnvironmentConfig":{"api":"https://api.production.com/"}});
What's wrong?
todo.zip
It's usually better to have things wrapped in IIFE
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.