GithubHelp home page GithubHelp logo

guzart / gulp-ng-constant Goto Github PK

View Code? Open in Web Editor NEW
109.0 3.0 26.0 62 KB

Gulp plugin for dynamic generation of angular constant modules.

License: MIT License

JavaScript 92.49% HTML 7.51%
gulpfile gulp-plugins angular1

gulp-ng-constant's Issues

Removing module dependencies via configuration

I want to remove dependency injection array passed in to module completely....right now I get a blank dependency array. Is there some value I can pass like in grunt deps: false to completely remove angular.module('modulename', [ ]) to be angular.module('modulename')?

Error after upgrading to 2.0.0-1

The following error only happens in the new version:

[10:25:46] Starting 'config'...
[10:25:46] 'config' errored after 17 ms
[10:25:46] ReferenceError in plugin 'gulp-tslint-log'
Message:
    wrapHeader is not defined
Details:
    fileName: ngConstants.json

The previous version (1.1.0) works fine!

My Gulp task:

gulp.task('config', () => {
  const myConfig = require(`./${appConfig.app}/scripts/config/config.json`);
  const envConfig = myConfig[environment];
  return ngConstant({
      constants: envConfig,
      name: 'MyAngularApp',
      deps: false,
      stream: true
    })
    .pipe(rename('app-config.js'))
    .pipe(gulp.dest(`${appConfig.app}/scripts/config`));
});

Setting a custom filename for the outputted file via options?

Hi there,

I am currently using the gulp-ng-constant module as follows:

ngConstants = require('gulp-ng-constant');

gulp.task('create-version-file', [], function () {
    var constants = { version: '1.0.0' };
    return ngConstant({
        constants: constants,
        wrap: false,
        deps: [],
        stream: true,
        name: 'myapp.version'
      })
        .pipe(gulp.dest('dist'))
});

However, doing so, creates an Angular constants file named ngConstants.js. Forcing a filename in gulp.dest by specifying a full path, as in gulp.dest('dist/version.js') creates a directory called version.js (which contains the generated ngConstants.js file) inside the dist directory.

No option seems to exist to specify the filename of the generated constants file. Is it so, or am I missing something in the docs?

Thanks in advance!

Group under one single constant name.

Hi,

I didn't find the possibility to group under one single constant name.

Example

Given an object like:

{
"person": "samir",
"age": 99
}
I wanted to get this:

angular.module("conf", [])
.constant("CONFIG", {
"person": "samir",
"age": 99
});
but instead got this:

angular.module("conf", [])
.constant("person", "samir")
.constant"age", 99);
Using an optional parameter we can simply group the whole object under a user defined constant.

Let me know if you think this feature makes sense and I'll write the tests and update README to include an example (I just added the option explanation for now).

Lint warnings/errors on generated constant module

While dependency injecting a generated constant module, I get the following lint errors/warnings

  line 2  col 3   Missing "use strict" statement.
  line 2  col 37  Strings must use singlequote.

I'm aware that I can create own template files to avoid these lint entries but I think it would be a good idea if this could work directly.

Use better defaults that match modern style

  • Better es6 template #34
  • Use a different JSON.stringify that outputs the constants values (single quotes) #24 #26
  • Add strict template for angular 1? #36
  • Add path option to extract the values from a given path
  • Add environment variable that internally uses path

configuration question

Hi there,
great plugin!

Qq what is the right way to set up devel & production config.js.
I ended up having two gulp tasks and two config.json files.
How would you do it? When I look at grunt-ng-constant there seams to be a different way to do this.

Thank you!

Please upload newest build to npm - Parsing .yml files

Hi,

I'm trying to parse config saved in .yml file. But unfortunately, I'm still getting errors like
'SyntaxError: Unexpected token a'

Here's the code causing this:
var data = file.isNull() ? {} : JSON.parse(file.contents); (index.js, line 47)

After a quick research, I found out that the following commit should fix it:
adca6bd

So it turns out there's obsolete version on the npm. Could you please upload newest build?

file name as constant name

I have clean config.json without constant names. Only parameters. I don't want to see constant name in my config. Add parameter "constantName" or "nameFromFile" to ng-constant

Adding an object constant

Hi can you advise if it is possible to add object constants and the best practice for adding these .
This technique tends to be used for injecting third party objects that are assigned to the global.

e.g.

.constants("moment",moment)

If I try this in gulp I get a reference error moment is undefined.
I can add this manually and have no issues and works as expected but would like to add as part of the build process if possible.
Thanks

merge constants from files in the stream

from @intellix comment on #6

I'm trying to have 2 configs merged so I can have global configuration and environment specific ones like:

config-global.json {
    ENV: {
        name: 'MyApp'
    }
}
config-dev.json {
    ENV: {
        apiEndpoint: 'localhost'     
    }
}

to create:

config.js {
    ENV: {
        name: 'MyApp'
        apiEndpoint: 'localhost'
    }
}

so that the following will get the constants from config/global.json and extend or override them with config/dev.json:

gulp
  .src([ 'config/global.json', 'config/dev.json' ])
  .pipe($.ngConstant({
    name: 'config'
  }))
  .pipe(gulp.dest('src/app'));

Replace deprecated dependency gulp-util

Replace deprecated dependency gulp-util

gulp-util has been deprecated recently. Continuing to use this dependency may prevent the use of your library with the latest release of Gulp 4 so it is important to replace gulp-util.

The README.md lists alternatives for all the components so a simple replacement should be enough.

Your package is one of the most popular packages still relying on gulp-util, it would be good to publish a fixed version to npm as soon as possible.

See:

Add consumption example to documentation

This is an awesome and very, very, very useful bit of code that I'm glad to have.

Unfortunately, while the data is definitely getting exported to an AngularJS file, I have no clue how to actually consume it. I imagine someone who has already done a lot of work with Angular could get there quickly -- I am not that person. Not yet. A little bit more documentation would be... very helpful.

Overriding Values?

Hi:

I would like to have a base set of config values, and then override only certain values in an environment-specific config. I'm having hard time figuring out how to get gulp-ng-constant to do that. Can you give me a hint.

Example:
app.config.json would look like this:
{
"foo": "default",
"bar": "default"
}
app.dev.json might look like this:
{
"foo":"dev"
}

I want output to look like this
.constant("foo", "dev")
.constant("bar": "default")

I can't seem to make that work. (either app.dev.json completely overwrites app.config.json, so "bar" gets dropped, or app.config.json completely overwrites app.dev.json)

use template instead of templatepath

It would be nice if your module would use a template directly instead of the templatePath.
This would allow to define the template directly in the gulp file without the need of a template file.
Using a template in a file would still be possible as this is the same as template: JSON.parse(fs.readFileSync(templatePath))

Using a template would allow more flexibility in defining the constants.

What do you think?

New release with es6?

Hi
I've just looked at your fine package, and would like a new release where you es6-templates are included via npm. The newest release (1.1.0) does not include the es6 template/wrapper.

Do you have any plans for the next release? I would love to help if I can.

ES6 being used without wrap: es6

I am not using wrap: es6 but yet I am getting es6 syntax which breaks on my build:

var ngConstantOpt = {
    space: '  ',
    name: 'app',
    stream: true,
    constants: {
        API_BASE_URI: '/'
    }
}


function callNgConstant(constant) {
    ngConstantOpt.constants.API_BASE_URI = constant;
    return ngConstant(ngConstantOpt)
        .pipe(rename("base-uris.js"))
        .pipe(gulp.dest(baseFileAbsPath));
};

gulp.task('constants:dev', function () {
    return callNgConstant('/')
});

import angular from 'angular';

const env = angular.module("app", [])
.constant("API_BASE_URI", "/");


export default env;

Constants replaced instead of merged

I have a gulp-ng-constant task like this:

gulp.task('config', function() {
  var configPath = 'env.json';

  return gulp.src(configPath)
    .pipe($.ngConstant({
      name: 'app.env',
      constants: { env: { authPath: /profiles/authenticate/ } },
      wrap: 'commonjs'
    }))
    .pipe(gulp.dest(path.join(conf.paths.src, '/app')));
});

and an env.json file like this:

{
  "env": {
    "backend": "http://0.0.0.0:8000",
  }
}

Given those parameters, I end up with an env.js file like this:

module.exports = angular.module("app.env", [])

.constant("env", {
    "authPath": "/profiles/authenticate/"
})

;

I expected the constants in the json file to be merged rather than replaced since an extra variable isn't likely to cause problems vs. a missing variable. Agree, disagree?

Gulp signals task did not complete

Here's my code. I have many other tasks that use this same syntax, and they're working great.
For some reason I'm getting this message after I run my task:

[11:24:53] The following tasks did not complete: build, buildEnvironmentConstants
[11:24:53] Did you forget to signal async completion?

I'm trying to simplify this down to it's most basic usage so I can eliminate other problems. What's wrong here?

module.exports = (gulp, plugins, config) => {
    return function buildEnvironmentConstants(done) {
        return plugins.ngConstant({
            name: 'testname',
            constants: {},
            stream: true
        })
        .pipe(gulp.dest(config.JS_APP_BUILD_OUPUT_DIR))
    };
};

deps: false works incorrect

If I write deps: false I get module('name') without dependencies [] (as in grunt-ng-constant). It usefull if I want to use existent module

JSON as single constant

Just FYI for future users, my use case was converting a JSON dictionary into a single app constant. My flow was using a gulp module to create a json file which then is converted into Angular constant.

Thanks for providing the EJS template ability to customize the output.

angular.module("<%- moduleName %>"<% if (deps) { %>,${JSON.stringify(deps)}<% } %>)
${indent}.constant({"myDictionary": {

<% constants.forEach(function(constant) { %>
"<%- constant.name %>": ${constant.value},
<%= _.last(constants) === constant ? '' : '\n' %>

<% }) %>}});

Version 2 released as version 1.2

I don't know if this is intentional or not but it broke a build process that was looking for ngConstants.js and then couldn't find it due to the new way output filenames are done.

Add ability to disable jscs on constant file

It would be great if there was an ability to add the disable jscs check comment on the constant generated file as I follow the airbnb javascript convention of using single quotes for strings rather than double quotes (which is the standard for json).

create multiple constants under same ngModule

I have two json file en.json and np.json and I would like to create constants under same module name app.constants
gulp.task('translations', function() { gulp.src(['en.json', 'np.json']) .pipe(ngConstants({ name: 'app.constants', wrap:false, })) .pipe(concat('constants.js')) .pipe(uglify()) .pipe(gulp.dest('./dist')); });
but what I get is module is defined multiple times

angular.module("app.constants", []).constant("i18en", { NAME: "Shankar" }), angular.module("app.constants", []).constant("i18np", { NAME: "शंकर" });

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.