2016-07-29 40 views
1

我有一個shell命令./node_modules/cordova/bin/cordova,它可以從項目根目錄訪問。從Grunt任務運行一個項目文件夾內的shell命令

我也有一組配置文件爲Grunt位於./config文件夾。

現在我試圖從任務運行科爾多瓦,想使用它作爲一個別名,所以在Gruntfile.js我有這樣的:

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

})

然後,從任務我運行它是這樣的:

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

結果我得到這個錯誤:

'.' is not recognized as an internal or external command,

如果我更換

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

cordovaCommand: 'node_modules/cordova/bin/cordova' 

然後,我看到這個錯誤:

'node_modules' is not recognized as an internal or external command,

所以,我想這可能是一些相對路徑和咕嚕如何與他們?在哪裏可以解決這個問題,因爲我需要使用cordova的本地安裝,而不是全局的。

+1

不,如果你使用完整路徑它的工作? – fedorqui

+0

如果我使用運行全局安裝的cordova的'cordova create <%= mobileAppProjectDir%>',它可以工作,但如果我將它運行爲'./node_modules/cordova/bin/cordova create <%= mobileAppProjectDir %>' –

+0

也許試試用這個:https://github.com/csantanapr/grunt-cordovacli。 – johnborges

回答

0

你可以嘗試完全在運行時解決的路徑,這樣,有沒有相對路徑:

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'), 

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