如何从grunt任务函数运行terminal命令

我试图根据我的Gruntfile.js的函数来移动我的应用程序目录中的一些图标。 有可能做这样的事吗? 我已经尝试了以下(进入开发或暂存文件夹,并将所有文件复制到以前的目录),但cound't得到它的工作。 提前致谢。

 grunt.registerTask('setAppIcon', 'Task that sets the app icon', function(environment) { if (environment.toLowerCase() == "development") { grunt.task.run(['exec:command:cd app/lib/extras/res/icon/ios/dev && cp -a . ../']); } else if (environment.toLowerCase() == "staging") { grunt.task.run(['exec:command:cd app/lib/extras/res/icon/ios/staging && cp -a . ../']); } }); 

我find了一个解决scheme,我结束了使用shelljs 。

我所要做的只是进入我的应用程序的根目录,运行下面的shell命令来安装npm: npm install -g shelljs并修改我的脚本,使其看起来像这样

 // Script to have environment specific icon grunt.registerTask('setAppIcon', 'Task that sets the app icon', function() { var env = grunt.option('env'); var shell = require('shelljs'); if (env.toLowerCase() === "development") { shell.exec('cd app/lib/extras/res/icon/ios/dev && cp -a . ../'); } else if (env.toLowerCase() === "staging") { shell.exec('cd app/lib/extras/res/icon/ios/staging && cp -a . ../'); } else if (env.toLowerCase() === "production") { shell.exec('cd app/lib/extras/res/icon/ios/prod && cp -a . ../'); } });