gpt4 book ai didi

linux - 如何为 OS X 和 Linux 编写具有不同 shell 命令行为的 Gruntfile?

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:54:19 24 4
gpt4 key购买 nike

我有一个 Gruntfile,我打算在 OS X 和 Linux(准确地说是 Ubuntu)上使用它。我在 a grunt-shell task 中包含了一些逻辑:

shell: {
somejob_linux: {
command: [
'firstlinuxcommand',
'secondlinuxcommand'
]
},
somejob_osx: {
command: [
'firstosxcommand',
'secondosxcommand'
]
}
}

如果 Gruntfile 在 Linux 上运行,我想执行第一个目标 (somejob_linux),在 OS X 上运行 somejob_osx

有没有一种优雅的方法可以实现这一目标?或者是否有另一种选择可以让每个平台运行不同的命令或 Grunt 任务/目标?我宁愿将所有内容都保存在 Gruntfile 中,而不是仅仅为此目的调用外部脚本。

最佳答案

我不知道有什么方法可以只在配置中执行此操作,但您可以为 check the environment 创建自定义任务然后将适当的任务添加到队列中:

grunt.registerTask('detectthenrun', 'Detect the environment, then run a task', function() {
if (/linux/.test(process.platform)) {
grunt.task.run( 'somejob_linux' );
} else if (/darwin/.test(process.platform)) {
grunt.task.run( 'somejob_osx' );
}
});

关于linux - 如何为 OS X 和 Linux 编写具有不同 shell 命令行为的 Gruntfile?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27720473/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com