당신은 사용하여 질문을 처리 할 수
https://github.com/dylang/grunt-prompt
그것은 하나의 작업을하고 잘 할 좋은 작은 플러그인입니다. (예)
prompt: {
target: {
options: {
questions: [
{
config: 'key', // arbitrary name or config for any other grunt task
type: 'input', // list, checkbox, confirm, input, password
message: 'What is your API key?',
default: '', // default value if nothing is entered
when: function(answers) { return !grunt.file.exists('config.yml'); } // only ask this question when this function returns true
}
]
}
}
}
는 그런 다음 파일에 그 값을 기록하는 Grunt.file
기능을 사용할 수 있습니다 :
http://gruntjs.com/api/grunt.file#grunt.file.write
그것을 조율하기를 그것은 당신이 변수로 명령 줄에 입력 한 어떤 값을 넣어 사용자 지정 작업을 만들어야합니다. (예)
grunt.registerTask("my_config_task", function (arg) {
var key = arg || grunt.config('key');
grunt.file.write("config.yml", key);
});
grunt.registerTask('build', ['prompt', 'my_config_task']);
쓰기 작업은 사용자가 원하는대로 정교해야합니다. 아픈 것 같아요, grunt-bump
의 소스를 보면서
이 가능한 솔루션 중 하나 발견 ... 값을 대체하고 등등
yml
파일이나
json
객체로 구성해야합니다. 그들이하고있는 것은 JSON 객체로 설정 파일을 읽을 수 있습니다 :
가 (JSON으로) 무엇을해야 값을 교체
https://github.com/darsain/grunt-bumpup/blob/master/tasks/bumpup.js#L128
와도 캐릭터 라인 객체가있는 파일 덮어 쓰기 :
https://github.com/darsain/grunt-bumpup/blob/master/tasks/bumpup.js#153
을 잘 작동하는 것 같습니다.
AWESOME! 너는 생명의 은인이야 ... 고맙습니다! –
유일하게 이것은 단 한 번 발생해야합니다. 변수를 저장할 위치를 확인해야하며 사용자가 변수를 한 번 추가하면 변수를 묻지 않아도됩니다. –
이것은 언제 "when"속성을위한 것입니까? when : function (answers) {return! grunt.file.exists ('config.yml'); } –