1 | #
|
---|
2 | # * grunt-svninfo
|
---|
3 | # * https://github.com/liqweed/grunt-svninfo
|
---|
4 | # *
|
---|
5 | # * Copyright (c) 2013 liqweed
|
---|
6 | # * Licensed under the MIT license.
|
---|
7 | #
|
---|
8 | #
|
---|
9 | # require("child_process").spawn("svn",["info"],{cwd:"./test/fixtures/svninfo"}).stdout.on('data',function(data){ console.log(data.toString()); });
|
---|
10 |
|
---|
11 | "use strict"
|
---|
12 | module.exports = (grunt) ->
|
---|
13 |
|
---|
14 | # Please see the Grunt documentation for more information regarding task
|
---|
15 | # creation: http://gruntjs.com/creating-tasks
|
---|
16 | grunt.registerTask 'svninfo', 'Get Subversion info from a working copy and populate grunt.config with the data', (output, argsKey) ->
|
---|
17 | done = @async()
|
---|
18 | options = @options
|
---|
19 | cwd: '.'
|
---|
20 | output: 'svninfo'
|
---|
21 | options.output = output if output
|
---|
22 | args = options[argsKey or 'args']
|
---|
23 |
|
---|
24 | grunt.verbose.writeln("svninfo start: output - ", options.output, ", args - ", args)
|
---|
25 |
|
---|
26 | grunt.util.spawn
|
---|
27 | cmd: 'svn'
|
---|
28 | args: if args then ['info'].concat(args) else ['info']
|
---|
29 | opts: options
|
---|
30 | , (err, result) ->
|
---|
31 | if err
|
---|
32 | grunt.log.warn err
|
---|
33 | return done()
|
---|
34 | info = {}
|
---|
35 | # Split SVN info by lines:
|
---|
36 | result.stdout.split('\n').forEach (line) ->
|
---|
37 | lineParts =line.split(': ')
|
---|
38 | if lineParts.length == 2
|
---|
39 | # Populate info object
|
---|
40 | info[lineParts[0]] = lineParts[1].trim()
|
---|
41 |
|
---|
42 | # Populate grunt.config with nicely parsed object:
|
---|
43 | grunt.config.set options.output,
|
---|
44 | rev: info['Revision']
|
---|
45 | url: info['URL']
|
---|
46 | last:
|
---|
47 | rev: info['Last Changed Rev']
|
---|
48 | author: info['Last Changed Author']
|
---|
49 | date: info['Last Changed Date']
|
---|
50 | repository:
|
---|
51 | root: info['Repository Root']
|
---|
52 | id: info['Repository UUID']
|
---|
53 |
|
---|
54 | grunt.log.writeln "SVN info fetched (rev: #{grunt.config.get(options.output + '.rev')})"
|
---|
55 | done()
|
---|