1 | /* |
---|
2 | * grunt-git-deploy |
---|
3 | * https://github.com/iclanzan/grunt-git-deploy |
---|
4 | * |
---|
5 | * Copyright (c) 2013 Sorin Iclanzan |
---|
6 | * Licensed under the MIT license. |
---|
7 | */ |
---|
8 | |
---|
9 | 'use strict'; |
---|
10 | |
---|
11 | module.exports = function(grunt) { |
---|
12 | |
---|
13 | grunt.registerMultiTask('init_repo', 'Initialize a git repository in a directory.', function() { |
---|
14 | var dest = this.files[0].dest; |
---|
15 | |
---|
16 | if (!grunt.file.exists(dest)) { |
---|
17 | grunt.file.mkdir(dest); |
---|
18 | } |
---|
19 | |
---|
20 | else if (!grunt.file.isDir(dest)) { |
---|
21 | grunt.fail.warn('A source directory is needed.'); |
---|
22 | return false; |
---|
23 | } |
---|
24 | |
---|
25 | var done = this.async(); |
---|
26 | |
---|
27 | grunt.util.spawn({ |
---|
28 | cmd: 'git', |
---|
29 | args: ['init'], |
---|
30 | opts: {cwd: dest} |
---|
31 | }, done); |
---|
32 | }); |
---|
33 | |
---|
34 | // Project configuration. |
---|
35 | grunt.initConfig({ |
---|
36 | |
---|
37 | // Before generating any new files, remove any previously-created files. |
---|
38 | clean: { |
---|
39 | tests: ['tmp'] |
---|
40 | }, |
---|
41 | |
---|
42 | init_repo: { |
---|
43 | main: { |
---|
44 | dest: 'tmp/repo' |
---|
45 | } |
---|
46 | }, |
---|
47 | |
---|
48 | copy: { |
---|
49 | first: { |
---|
50 | expand: true, |
---|
51 | cwd: 'test/fixtures/first', |
---|
52 | src: '**/**', |
---|
53 | dest: 'tmp/src/' |
---|
54 | }, |
---|
55 | second: { |
---|
56 | expand: true, |
---|
57 | cwd: 'test/fixtures/second', |
---|
58 | src: '**/**', |
---|
59 | dest: 'tmp/src/' |
---|
60 | }, |
---|
61 | }, |
---|
62 | |
---|
63 | // Configuration to be run (and then tested). |
---|
64 | git_deploy: { |
---|
65 | default_options: { |
---|
66 | options: { |
---|
67 | url: '../repo' |
---|
68 | }, |
---|
69 | src: 'tmp/src' |
---|
70 | } |
---|
71 | }, |
---|
72 | |
---|
73 | // Unit tests. |
---|
74 | nodeunit: { |
---|
75 | tests: ['test/*_test.js'] |
---|
76 | } |
---|
77 | |
---|
78 | }); |
---|
79 | |
---|
80 | // Actually load this plugin's task(s). |
---|
81 | grunt.loadTasks('tasks'); |
---|
82 | |
---|
83 | // These plugins provide necessary tasks. |
---|
84 | grunt.loadNpmTasks('grunt-contrib-clean'); |
---|
85 | grunt.loadNpmTasks('grunt-contrib-copy'); |
---|
86 | grunt.loadNpmTasks('grunt-contrib-nodeunit'); |
---|
87 | |
---|
88 | // Whenever the "test" task is run, first clean the "tmp" dir, then run this |
---|
89 | // plugin's task(s), then test the result. |
---|
90 | grunt.registerTask('test', ['clean', 'init_repo', 'copy:first', 'git_deploy', 'copy:second', 'git_deploy', 'nodeunit']); |
---|
91 | |
---|
92 | // By default, run all tests. |
---|
93 | grunt.registerTask('default', ['test']); |
---|
94 | |
---|
95 | }; |
---|