GithubHelp home page GithubHelp logo

atticoos / gulp-ng-config Goto Github PK

View Code? Open in Web Editor NEW
174.0 4.0 35.0 108 KB

:wrench: Create AngularJS constants from a JSON config file

License: MIT License

JavaScript 98.72% HTML 1.28%
angular javascript json

gulp-ng-config's People

Contributors

atticoos avatar bryant1410 avatar dimitardanailov avatar engincancan avatar felixhorro avatar flaviokz avatar mogobruno avatar nestorbritez avatar psalaets avatar rawberg avatar repocorp avatar scic avatar se-panfilov avatar thamosio avatar vikasgarghb avatar zbennett10 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

gulp-ng-config's Issues

allow more control over output file


  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).

Throw error if non existing `options.environment` was specified

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?

Not always CONSTANTS.

Option to generate angular config file with values instead constants.

angular.module('myApp.config', [])
.value('string', "my string");

Nested configuration with both environmental and non environmental variables

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?

TypeError: _.contains is not a function issue with lodash 4.0

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)

Default config values as option to this plugin

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.

Release 1.3.0 ?

Hey,

First, thank you for this module, it looks great!

Are you planning to release the version 1.3 ?

Thanks

Filter config.json with environment value.

"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"]]
}

Nested Environment with npm

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];
}

Error after dependencies upgrade

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)

custom wrapper incorrect because of trailing colon

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.

Can't find variable: require

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 ?

Override the module name

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.

Use a different file name

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

Support second argument for module

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

ES6 template

Would be good to have ability to use with ES6/CommonJS modules;

import angular from 'angular';
angular.constant(...)

Allow for no json file (and only inline values from gulp)

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 {}

Add 'pretty' option

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
      }
    },

Override works but removes other properties

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

Add 'use strict' to IIFE wrapper

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?

Defined constants are dropped if using environment specific configurations

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.

environment: 'production'

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.