【问题标题】:Automating coffeescript compilation with Jenkins使用 Jenkins 自动编译咖啡脚本
【发布时间】:2013-02-04 20:21:57
【问题描述】:

我为我的一个项目在 windows 盒子上设置了 jenkins CI 服务器。其中有一部分是用 Coffeescript 编写的。以前这部分没有循环到构建过程中。现在需要。

我还没有看到任何 jenkins 的咖啡脚本插件,或者谷歌关于在 jenkins 中构建咖啡脚本的主题。

我正在寻找设置 jenkins 构建以包含咖啡编译步骤的最简单方法。最好通过 jenkins 上的插件,而不是在盒子上手动安装程序。

目前coffeescript是通过这样的命令编译的

coffee --lint --watch --output "C:\repositories\martha\trunk\bb\app\bin\js/" --compile "C:/repositories/martha/trunk/bb/app/src/"

在开发框上的 Node.js 命令提示符中

我还注意到 Jenkins 有一个 node.js 插件,您可以在其中在构建步骤中运行脚本。我不相信我可以通过 node.js 脚本而不是命令行使用命令 npm install -g coffee-scriptcoffee --compile。虽然我希望我错了。

目前我看到的最好的选择是在盒子上安装node.js,使用npm安装coffee脚本,然后运行批处理脚本作为构建步骤。虽然我愿意追求这个,但我希望在盒子上减少手动安装,以方便在更多项目中使用咖啡脚本。

这是我最好的选择吗?

值得一提的是,虽然我使用 node.js 编译咖啡脚本,但 node.js 本身及其功能对我来说还是很新的。

【问题讨论】:

    标签: node.js jenkins coffeescript continuous-integration


    【解决方案1】:

    一种可能的解决方案是使用extras/coffee-script.js 中提供的脚本运行编译器。您必须使用 JDK 7 或最新的 Rhino(JDK 6 将无法使用)。这是一个简单的CoffeeScript compiler in Java的链接

    【讨论】:

    • 我认为我可能可以将 extras/coffee-script.js 作为 node.js 脚本运行。
    【解决方案2】:

    我会推荐

    a) 在 jenkins 上安装 nodejs 插件 + grunt -> Jenkins integration with Grunt

    b) 对优秀的指令进行投票 :)

    c) 然后使用grunt编译coffee脚本,这也意味着你也可以轻松地在本地编译coffee脚本!!

    grunt 指令 -> http://gruntjs.com/

    咕噜咖啡脚本说明 -> https://github.com/gruntjs/grunt-contrib-coffee

    基本上你需要一个像这样的 Gruntfile.js

    module.exports = function(grunt) {
        // Project configuration.
        grunt.initConfig({
            pkg : grunt.file.readJSON('package.json'),
            coffee: {
                compile: {
                    files: {
                        'path/to/result.js': 'path/to/source.coffee', // 1:1 compile
                        'path/to/another.js': ['path/to/sources/*.coffee', 'path/to/more/*.coffee'] // compile and concat into single file
                    }
                }
            }
        });
        grunt.loadNpmTasks('grunt-contrib-coffee');
        grunt.registerTask('default', ['grunt-contrib-coffee']);
    };
    

    那么对于 jenkins shell 任务,你只需要这个,运行 grunt 和咖啡脚本

    npm update
    grunt
    

    【讨论】:

      猜你喜欢
      • 2012-07-23
      • 2011-06-30
      • 1970-01-01
      • 1970-01-01
      • 2013-06-26
      • 2014-06-04
      • 2012-01-25
      • 2014-02-04
      • 2021-05-03
      相关资源
      最近更新 更多