Giter VIP home page Giter VIP logo

grunt-php-set-constant's Introduction

grunt-php-set-constant

+---------------------------------------------+
|                                             |
| Current version is Grunt 0.4.0 compatible.  |
| Version 0.0.14+ is Grunt 0.4.0 compatible.  |
|                                             |
| Version 0.0.12 is Grunt 0.3.17 compatible.  |
|                                             |
+---------------------------------------------+

(version 0.0.13 seems to be missing from npm)

Description

Set a constant in a php file to the value indicated.

This is a multi task.

This supports single or double quotes. Heredoc and nowdoc within the define are not supported. String constants are supported as are numbers, constants, and booleans. The quote marks will be maintained. So you can add quotes to transform from and initial number to a string. But, currently, you cannot transform a string to a number, etc. Grunt templates are supported in the config value field.

You can use one type of quote inside another, but escaping quotes is not supported.

So the following will work:

define('ENV','other "env"');

Usage

Example usage within grunt init:

    setPHPConstant: {
        stage: {
            constant    : 'ENV',
            value       : 'stage-<%= grunt.template.today("yyyy-mm-dd") %>',
            file        : 'temp/myfile.php'
        }
    }

The above would change the source of temp/myfile.php. It would change something like

define('ENV', 'blah');

to

define('ENV', 'staging-2012-11-30');

(Depending on actual date)

Installation and Use

To use this package put it as a dependency in your package.json, and then run npm install.

Then load the grunt task in your grunt.js

grunt.loadNpmTasks('grunt-php-set-constant');

Tests

Tests can be run from the grunt-php-set-constant directory using:

npm install
npm test

You can inspect the sample output created. The tests can be run by either cloning the git repo or from this module's directory inside the node_modules folder of your project.

Contributors

TODO:

  • use regex back references for quotes

Changelog

  • 0.0.15 - 2013 07 10
  • 0.0.14 - 2013 07 10
  • 0.0.13 - 2013 02 22 - Adding Grunt 0.4.0 compatibility
  • 0.0.12 - 2013 01 25 - Ability to have an empty string for value. Ability to put one type of quote in another. Issues #1, and #5
  • 0.0.11 - 2012 11 29 - Adding grunt templating to value

NPM package

grunt-php-set-constant's People

Contributors

oroce avatar pajtai avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

serialworm oroce

grunt-php-set-constant's Issues

Allow specify constant type

value: '<%= pkg.version %>' will results in Parse error: syntax error, unexpected T_DNUMBER in php;

if I use value: '"<%= pkg.version %>"' (ie. putting quote inside), then it works initially, on next update it insert another pair of quotes which breaks it.

It would be a better to just let user specify the type of variable? so the tool know whether to wrap it in quotes or not.

Support for class constants

Support for class constants in addition to constants declared using define()

I would like to use the following in my Gruntfile.js

grunt.initConfig({
setPHPConstant: {
      example: {
          constant    : 'TEST',
          value       : 'stage-<%= grunt.template.today("yyyy-mm-dd") %>',
          file        : 'test.php'
      }
  },
});

to update the following code in test.php

class A {
  const TEST = 'replace this';
}

Grunt 0.4 Release

I'm posting this issue to let you know that we will be publishing Grunt 0.4 on Monday, February 18th.

If your plugin is not already Grunt 0.4 compatible, would you please consider updating it? For an overview of what's changed, please see our migration guide.

If you'd like to develop against the final version of Grunt before Monday, please specify "grunt": "0.4.0rc8" as a devDependency in your project. After Monday's release, you'll be able to use "grunt": "~0.4.0" to actually publish your plugin. If you depend on any plugins from the grunt-contrib series, please see our list of release candidates for compatible versions. All of these will be updated to final status when Grunt 0.4 is published.

Also, in an effort to reduce duplication of effort and fragmentation in the developer community, could you review the grunt-contrib series of plugins to see if any of your functionality overlaps significantly with them? Grunt-contrib is community maintained with 40+ contributors—we'd love to discuss any additions you'd like to make.

Finally, we're working on a new task format that doesn't depend on Grunt: it's called node-task. Once this is complete, there will be one more conversion, and then we'll never ask you to upgrade your plugins to support our changes again. Until that happens, thanks for bearing with us!

If you have any questions about how to proceed, please respond here, or join us in #grunt on irc.freenode.net.

Thanks, we really appreciate your work!

Regex doesn't allow other type of quote within quoted string

For example

define('ENV','other "env"');

would not work as expected... There are several other problems with the regex relating to mixing quote mark types.

Update the regex to us \1 style back back references to store the type of regex we are inside, and remember to check for escaped quote marks of that type and ignore them.

Empty constant value doesn't get updated

For example

define("CACHE_BUSTING_REVISION", "");

Task used

grunt.initConfig({
    setPHPConstant: {
        stage: {
            constant: 'CACHE_BUSTING_REVISION',
            value: '<%= grunt.template.today("yyyymmddhh") %>',
            file: 'config/application.inc.php'
        }
    }
});

grunt.loadNpmTasks('grunt-php-set-constant');

grunt.registerTask('cachebust', 'setPHPConstant');

Line isn't updated when running grunt task.

It works when I set the initial value to 0 tho, so I can deal with that, but would be great if it would work with an empty string!

Thanks for the work by the way, extremely useful!

If constant value is left blank, the substitution of the value does not take place.

Example:
When trying to swap out value for DB_USER I noticed a problem if the constant is left empty. This code works:

File value

define('DB_USER', 'temp_user');

Grunt config

setPHPConstant : {

                DB_USER : {
                    constant : 'DB_USER',
                    value    : 'real_value',
                    file     : {path to file}
                }

Changing the define from:

define('DB_USER', 'temp_user');

to:

define('DB_USER', '');

Will result in the task not adding the 'real_value' of the constant.

Tab ignored while setting up value

The plugin does its job very well. The only issue I am facing is related to the removal of the tab before the constant when the constant is indented.

image

Can you please let me know if I am doing something wrong at my end or is it a known issue?

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.