该任务仅在 grunt 自定义任务中针对最后一个值执行
the task is getting executed for last value only in grunt custom task
在执行 grunt 自定义任务时我正在迭代一个循环,在循环内我正在调用一个 grunt 任务,同时调用我使用当前循环值为任务设置值但是当循环执行头韵时它设置数组的最后一个值总是。
var productionUrl = "http://www.abc.de";
var phantomPagesPath = {
"index": "/index.php",
"search": "/Suche?searchString=test",
"warenkorb": "/warenkorb",
"product": "/4-ecksofa",
"cms": "/content/25-service",
"category": "/bestellung",
"pageNotFound": "/404"
};
grunt.initConfig({`phantomas: {
prod: {
options: {
options: {
'timeout': 30
},
buildUi: true
}
}
}`});`
grunt.registerTask('fantomas', 'Custome Phantomas task', function () {
var done = this.async();
var pageUrl = '';
var location = '';
for (var page in phantomPagesPath) {
pageUrl = '';
location = '';
if (phantomPagesPath.hasOwnProperty(page)) {
pageUrl = productionUrl + phantomPagesPath[page];
location = './public/phantomas/' + page + "/";
console.log("process started for: " + pageUrl);
console.log("location: " + location);
grunt.config.set('phantomas.options.url', pageUrl);
grunt.config.set('phantomas.options.indexPath', location);
grunt.task.run('phantomas');
}
}
done();
});
现在输出我得到
进程已启动:http://www.abc.de/index.php
位置:./public/phantomas/index/
进程已启动:http://www.abc.de/Suche?searchString=test
位置:./public/phantomas/search/
进程已启动:http://www.abc.de/warenkorb
位置:./public/phantomas/warenkorb/
进程已启动:http://www.abc.de/4-ecksofa
位置:./public/phantomas/product/
进程已启动:http://www.abc.de/content/25-service
位置:./public/phantomas/cms/
进程已启动:http://www.abc.de/bestellung
位置:./public/phantomas/category/
进程已启动:http://www.abc.de/404
位置:./public/phantomas/pageNotFound/
运行"phantomas:prod"(幻象)任务
PHANTOMAS 执行已开始。
正在对所有条目数执行任务,但为任务发送的数据是循环 "pageNotFound"、
中的最后一个条目
我的意思是这个过程工作了 7 次,但在每个过程中,它都采用循环的最后一个值。
经过大量搜索后,我想出了解决方案,尽管调用了
grunt.task.run('phantomas');
在foreach循环内,应该在循环外调用,即任务只执行一次。因此,为此,我们需要在我执行以下代码的任务中增加 make tasks/target:
grunt.loadNpmTasks('grunt-phantomas');
var phantomPagesPath = {
"index": "/index.php",
"search": "/Suche?searchString=test",
"warenkorb": "/warenkorb",
"product": "/4-ecksofa",
"cms": "/content/25-service",
"category": "/bestellung",
"pageNotFound": "/404"
};
grunt.initConfig({
phantomas: {
//For Executing this task run: grunt fantomas
},
});
// Register customer task for phantomas
grunt.registerTask('fantomas', 'Custome Phantomas task', function () {
var done = this.async();
var pageUrl = '';
var location = '';
for (var page in phantomPagesPath) {
pageUrl = productionUrl + phantomPagesPath[page];
location = './public/phantomas/' + page + "/";
grunt.config.set('phantomas.'+page+'.options.url', pageUrl);
grunt.config.set('phantomas.'+page+'.options.indexPath', location);
grunt.config.set('phantomas.'+page+'.options.buildUi', true);
grunt.config.set('phantomas.'+page+'.options.options.timeout', 30);
var pageUrl = '';
var location = '';
}
grunt.task.run('phantomas');
done();
});
现在运行
grunt fantomas
在执行 grunt 自定义任务时我正在迭代一个循环,在循环内我正在调用一个 grunt 任务,同时调用我使用当前循环值为任务设置值但是当循环执行头韵时它设置数组的最后一个值总是。
var productionUrl = "http://www.abc.de";
var phantomPagesPath = {
"index": "/index.php",
"search": "/Suche?searchString=test",
"warenkorb": "/warenkorb",
"product": "/4-ecksofa",
"cms": "/content/25-service",
"category": "/bestellung",
"pageNotFound": "/404"
};
grunt.initConfig({`phantomas: {
prod: {
options: {
options: {
'timeout': 30
},
buildUi: true
}
}
}`});`
grunt.registerTask('fantomas', 'Custome Phantomas task', function () {
var done = this.async();
var pageUrl = '';
var location = '';
for (var page in phantomPagesPath) {
pageUrl = '';
location = '';
if (phantomPagesPath.hasOwnProperty(page)) {
pageUrl = productionUrl + phantomPagesPath[page];
location = './public/phantomas/' + page + "/";
console.log("process started for: " + pageUrl);
console.log("location: " + location);
grunt.config.set('phantomas.options.url', pageUrl);
grunt.config.set('phantomas.options.indexPath', location);
grunt.task.run('phantomas');
}
}
done();
});
现在输出我得到
进程已启动:http://www.abc.de/index.php 位置:./public/phantomas/index/
进程已启动:http://www.abc.de/Suche?searchString=test 位置:./public/phantomas/search/
进程已启动:http://www.abc.de/warenkorb 位置:./public/phantomas/warenkorb/
进程已启动:http://www.abc.de/4-ecksofa 位置:./public/phantomas/product/
进程已启动:http://www.abc.de/content/25-service 位置:./public/phantomas/cms/
进程已启动:http://www.abc.de/bestellung 位置:./public/phantomas/category/
进程已启动:http://www.abc.de/404 位置:./public/phantomas/pageNotFound/
运行"phantomas:prod"(幻象)任务 PHANTOMAS 执行已开始。
正在对所有条目数执行任务,但为任务发送的数据是循环 "pageNotFound"、
中的最后一个条目我的意思是这个过程工作了 7 次,但在每个过程中,它都采用循环的最后一个值。
经过大量搜索后,我想出了解决方案,尽管调用了
grunt.task.run('phantomas');
在foreach循环内,应该在循环外调用,即任务只执行一次。因此,为此,我们需要在我执行以下代码的任务中增加 make tasks/target:
grunt.loadNpmTasks('grunt-phantomas');
var phantomPagesPath = {
"index": "/index.php",
"search": "/Suche?searchString=test",
"warenkorb": "/warenkorb",
"product": "/4-ecksofa",
"cms": "/content/25-service",
"category": "/bestellung",
"pageNotFound": "/404"
};
grunt.initConfig({
phantomas: {
//For Executing this task run: grunt fantomas
},
});
// Register customer task for phantomas
grunt.registerTask('fantomas', 'Custome Phantomas task', function () {
var done = this.async();
var pageUrl = '';
var location = '';
for (var page in phantomPagesPath) {
pageUrl = productionUrl + phantomPagesPath[page];
location = './public/phantomas/' + page + "/";
grunt.config.set('phantomas.'+page+'.options.url', pageUrl);
grunt.config.set('phantomas.'+page+'.options.indexPath', location);
grunt.config.set('phantomas.'+page+'.options.buildUi', true);
grunt.config.set('phantomas.'+page+'.options.options.timeout', 30);
var pageUrl = '';
var location = '';
}
grunt.task.run('phantomas');
done();
});
现在运行
grunt fantomas