Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
yuepywu opened this issue Jun 8, 2017 · 1 comment
Open

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

yuepywu opened this issue Jun 8, 2017 · 1 comment

Comments

@yuepywu
Copy link

yuepywu commented Jun 8, 2017

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 %>/',
...
@SolomoN-ua
Copy link
Collaborator

Hi @yuepywu, not quite sure that it would be easy to implement such scenario. The only visible option for me right now is to perform prompting before grunt execution, in this case you will have everything that you need before load-grunt-config initialisation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants