繁体   English   中英

从Grunt任务运行项目文件夹内的shell命令

[英]Run a shell command that is inside a project folder from Grunt task

我有一个shell命令./node_modules/cordova/bin/cordova ,可以从项目根目录访问。

我还有一组Grunt的配置文件,它们位于./config文件夹中。

现在我正在尝试从任务中运行cordova并希望将其用作别名,所以在Gruntfile.js中我有这样的:

grunt.initConfig({
    buildDir: 'build/interim_builds',
    publishDir: 'build/publish',
    cordovaCommand: './node_modules/cordova/bin/cordova',
    ...

})

然后,从一个任务我运行它像这样:

mobileApp_create: {
    cmd: '<%= cordovaCommand %> create <%= mobileAppProjectDir %>'
}

结果我得到了这个错误:

'' 不被视为内部或外部命令,

如果我更换

cordovaCommand: './node_modules/cordova/bin/cordova'

cordovaCommand: 'node_modules/cordova/bin/cordova'

然后我看到这个错误:

'node_modules'未被识别为内部或外部命令,

那么,我想它可能是相对路径以及Grunt如何与它们一起工作的东西? 我在哪里可以解决这个问题,因为我需要使用cordova的本地安装,而不是全局安装。

您可以尝试在运行时完全解析路径,这样就没有相对路径:

var path = require('path');

module.exports = function(grunt) {

  grunt.initConfig({
    buildDir: 'build/interim_builds',
    publishDir: 'build/publish',
    cordovaCommand: path.resolve('./node_modules/cordova/bin/cordova'),

    // ...
  });
  // ...
};

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM