Skip to content

Passing grunt-prompt config to load-grunt-config #168

@yuepywu

Description

@yuepywu

Hi, i am now using the load-grunt-config with grunt-prompt to distribute to developers to work on some front-end tasks especially components based development, it's great for every tasks i can slice using load-grunt-config.

However i would like have a command-line based interface for developer to select their components to develop, so i chose grunt-prompt to achieve that but i got some problem to pass the developer selected component options to the data object in load-grunt-config.

This is the Gruntfile.js, I have defined a component field in the data object.

module.exports = function(grunt) {

    var path = require('path');

    require('load-grunt-config')(grunt, {
        configPath: path.join(process.cwd(), 'tasks'),
        data: {
		component: ''
	}
    });

};

Here is the tree of tasks.

tasks/

├── aliases.js
├── execute.js
├── prompt.js
├── pug.js

This will run prompt then execute tasks.

aliases.js

module.exports = function (grunt) {
	
	return {
		default: [
			'prompt',
			'execute'
		],
...

Developer selected a component and store to grunt.config.

prompt.js

return {
	default: {
		options: {
			questions: [
				{
					// Top Menu Options
					config: 'component',
...

The execute.js is able to print the selected component option after running prompt.js.

execute.js

module.exports = function (grunt) {

	grunt.registerTask('execute', '', function () {

		console.log(grunt.config('component')); // able to print the selected component option

		console.log('Executing procedure...');
...

I am trying to get the grunt.template work in pug.js, i noticed that load-grunt-config have a data object for this case, but it's already initiated before running prompt.js, so the following <%= component %> is undefined, any suggestion to solve this case?

pug.js

module.exports = function (grunt) {

	return {
		dev_component: {
			files: [{
				expand: true,
				cwd: 'src/component/<%= component %>/',
...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions