sindresorhus / grunt-shell

Run shell commands
MIT License
949 stars 126 forks source link

Use grunt variable within STDIN #62

Closed gizburdt closed 10 years ago

gizburdt commented 10 years ago

Hi,

I would like to run this command: wp core config --dbname=<%= wp.config.db.name %> --dbuser=<%= wp.config.db.user %> --dbpass=<%= wp.config.db.password %> --extra-php <<< "define(\'WP_CONTENT_DIR\', dirname(__FILE__) . \'/../wp-content\');\n define(\'WP_CONTENT_URL\', \'<%= project.url =>\');"

The top three will work. Grunt will convert the variable <%= wp.config.db.name %> to the value of the options. But when I'm in STDIN (because of --extra-php), then Grunt won't convert the value, but just echoes <%= project.url =>

How can I get grunt to echo the value of the variable?

Thanks!

sindresorhus commented 10 years ago

You can use the callback option to handle it yourself. Just process stdout through http://gruntjs.com/api/grunt.template

gizburdt commented 10 years ago

Hi,

I tried multiple things, but I can't get it to work. This is my current code:

wp_config: {
                command: 'php wp-cli.phar core config --dbname=<%= wp.config.db.name %>  --dbuser=<%= wp.config.db.user %> --dbpass=<%= wp.config.db.password %> --dbhost=<%= wp.config.db.host %> --dbprefix=<%= wp.config.db.prefix %> --dbcharset=<%= wp.config.db.charset %> --locale=<%= wp.config.wp.lang %> --extra-php <<PHP ',
                options: {
                    stdout: true,
                    callback: function( err, stdout, stderr, cb ) {
                        return "define('WP_CONTENT_DIR', dirname(__FILE__) . '/../wp-content');\ndefine('WP_CONTENT_URL', '" + grunt.config( 'project.url' ) + "')\nPHP";
                        cb();
                    }
                }
            },

The file is created, but the --extra-php is not handled and the task gets kind of stuck..