Subversion Repositories SmartDukaan

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
14217 anikendra 1
var semver = require('semver'),
2
    f = require('util').format,
3
    files = {
4
      common: [
5
      'src/common/utils.js'
6
      ],
7
      bloodhound: [
8
      'src/bloodhound/version.js',
9
      'src/bloodhound/tokenizers.js',
10
      'src/bloodhound/lru_cache.js',
11
      'src/bloodhound/persistent_storage.js',
12
      'src/bloodhound/transport.js',
13
      'src/bloodhound/search_index.js',
14
      'src/bloodhound/options_parser.js',
15
      'src/bloodhound/bloodhound.js'
16
      ],
17
      typeahead: [
18
      'src/typeahead/html.js',
19
      'src/typeahead/css.js',
20
      'src/typeahead/event_bus.js',
21
      'src/typeahead/event_emitter.js',
22
      'src/typeahead/highlight.js',
23
      'src/typeahead/input.js',
24
      'src/typeahead/dataset.js',
25
      'src/typeahead/dropdown.js',
26
      'src/typeahead/typeahead.js',
27
      'src/typeahead/plugin.js'
28
      ]
29
    };
30
 
31
module.exports = function(grunt) {
32
  grunt.initConfig({
33
    version: grunt.file.readJSON('package.json').version,
34
 
35
    buildDir: 'dist',
36
 
37
    banner: [
38
      '/*!',
39
      ' * typeahead.js <%= version %>',
40
      ' * https://github.com/twitter/typeahead.js',
41
      ' * Copyright 2013-<%= grunt.template.today("yyyy") %> Twitter, Inc. and other contributors; Licensed MIT',
42
      ' */\n\n'
43
    ].join('\n'),
44
 
45
    uglify: {
46
      options: {
47
        banner: '<%= banner %>',
48
        enclose: { 'window.jQuery': '$' }
49
      },
50
      bloodhound: {
51
        options: {
52
          mangle: false,
53
          beautify: true,
54
          compress: false
55
        },
56
        src: files.common.concat(files.bloodhound),
57
        dest: '<%= buildDir %>/bloodhound.js'
58
      },
59
      bloodhoundMin: {
60
        options: {
61
          mangle: true,
62
          compress: true
63
        },
64
        src: files.common.concat(files.bloodhound),
65
        dest: '<%= buildDir %>/bloodhound.min.js'
66
      },
67
      typeahead: {
68
        options: {
69
          mangle: false,
70
          beautify: true,
71
          compress: false
72
        },
73
        src: files.common.concat(files.typeahead),
74
        dest: '<%= buildDir %>/typeahead.jquery.js'
75
 
76
      },
77
      typeaheadMin: {
78
        options: {
79
          mangle: true,
80
          compress: true
81
        },
82
        src: files.common.concat(files.typeahead),
83
        dest: '<%= buildDir %>/typeahead.jquery.min.js'
84
 
85
      },
86
      bundle: {
87
        options: {
88
          mangle: false,
89
          beautify: true,
90
          compress: false
91
        },
92
        src: files.common.concat(files.bloodhound, files.typeahead),
93
        dest: '<%= buildDir %>/typeahead.bundle.js'
94
 
95
      },
96
      bundlemin: {
97
        options: {
98
          mangle: true,
99
          compress: true
100
        },
101
        src: files.common.concat(files.bloodhound, files.typeahead),
102
        dest: '<%= buildDir %>/typeahead.bundle.min.js'
103
      }
104
    },
105
 
106
    sed: {
107
      version: {
108
        pattern: '%VERSION%',
109
        replacement: '<%= version %>',
110
        recursive: true,
111
        path: '<%= buildDir %>'
112
      }
113
    },
114
 
115
    jshint: {
116
      options: {
117
        jshintrc: '.jshintrc'
118
      },
119
      src: 'src/**/*.js',
120
      test: ['test/*_spec.js', 'test/integration/test.js'],
121
      gruntfile: ['Gruntfile.js']
122
    },
123
 
124
    watch: {
125
      js: {
126
        files: 'src/**/*',
127
        tasks: 'build'
128
      }
129
    },
130
 
131
    exec: {
132
      npm_publish: 'npm publish',
133
      git_is_clean: 'test -z "$(git status --porcelain)"',
134
      git_on_master: 'test $(git symbolic-ref --short -q HEAD) = master',
135
      git_add: 'git add .',
136
      git_push: 'git push && git push --tags',
137
      git_commit: {
138
        cmd: function(m) { return f('git commit -m "%s"', m); }
139
      },
140
      git_tag: {
141
        cmd: function(v) { return f('git tag v%s -am "%s"', v, v); }
142
      },
143
      publish_assets: [
144
        'cp -r <%= buildDir %> typeahead.js',
145
        'zip -r typeahead.js/typeahead.js.zip typeahead.js',
146
        'git checkout gh-pages',
147
        'rm -rf releases/latest',
148
        'cp -r typeahead.js releases/<%= version %>',
149
        'cp -r typeahead.js releases/latest',
150
        'git add releases/<%= version %> releases/latest',
151
        'sed -E -i "" \'s/v[0-9]+\\.[0-9]+\\.[0-9]+/v<%= version %>/\' index.html',
152
        'git add index.html',
153
        'git commit -m "Add assets for <%= version %>."',
154
        'git push',
155
        'git checkout -',
156
        'rm -rf typeahead.js'
157
      ].join(' && ')
158
    },
159
 
160
    clean: {
161
      dist: 'dist'
162
    },
163
 
164
    connect: {
165
      server: {
166
        options: { port: 8888, keepalive: true }
167
      }
168
    },
169
 
170
    concurrent: {
171
      options: { logConcurrentOutput: true },
172
      dev: ['server', 'watch']
173
    },
174
 
175
    step: {
176
      options: {
177
        option: false
178
      }
179
    }
180
  });
181
 
182
  grunt.registerTask('release', '#shipit', function(version) {
183
    var curVersion = grunt.config.get('version');
184
 
185
    version = semver.inc(curVersion, version) || version;
186
 
187
    if (!semver.valid(version) || semver.lte(version, curVersion)) {
188
      grunt.fatal('hey dummy, that version is no good!');
189
    }
190
 
191
    grunt.config.set('version', version);
192
 
193
    grunt.task.run([
194
      'exec:git_on_master',
195
      'exec:git_is_clean',
196
      f('step:Update to version %s?', version),
197
      f('manifests:%s', version),
198
      'build',
199
      'exec:git_add',
200
      f('exec:git_commit:%s', version),
201
      f('exec:git_tag:%s', version),
202
      'step:Push changes?',
203
      'exec:git_push',
204
      'step:Publish to npm?',
205
      'exec:npm_publish',
206
      'step:Publish assets?',
207
      'exec:publish_assets'
208
    ]);
209
  });
210
 
211
  grunt.registerTask('manifests', 'Update manifests.', function(version) {
212
    var _ = grunt.util._,
213
        pkg = grunt.file.readJSON('package.json'),
214
        bower = grunt.file.readJSON('bower.json'),
215
        jqueryPlugin = grunt.file.readJSON('typeahead.js.jquery.json');
216
 
217
    bower = JSON.stringify(_.extend(bower, {
218
      name: pkg.name,
219
      version: version
220
    }), null, 2);
221
 
222
    jqueryPlugin = JSON.stringify(_.extend(jqueryPlugin, {
223
      name: pkg.name,
224
      title: pkg.name,
225
      version: version,
226
      author: pkg.author,
227
      description: pkg.description,
228
      keywords: pkg.keywords,
229
      homepage: pkg.homepage,
230
      bugs: pkg.bugs,
231
      maintainers: pkg.contributors
232
    }), null, 2);
233
 
234
    pkg = JSON.stringify(_.extend(pkg, {
235
      version: version
236
    }), null, 2);
237
 
238
    grunt.file.write('package.json', pkg);
239
    grunt.file.write('bower.json', bower);
240
    grunt.file.write('typeahead.js.jquery.json', jqueryPlugin);
241
  });
242
 
243
  // aliases
244
  // -------
245
 
246
  grunt.registerTask('default', 'build');
247
  grunt.registerTask('build', ['uglify', 'sed:version']);
248
  grunt.registerTask('server', 'connect:server');
249
  grunt.registerTask('lint', 'jshint');
250
  grunt.registerTask('dev', 'concurrent:dev');
251
 
252
  // load tasks
253
  // ----------
254
 
255
  grunt.loadNpmTasks('grunt-sed');
256
  grunt.loadNpmTasks('grunt-exec');
257
  grunt.loadNpmTasks('grunt-step');
258
  grunt.loadNpmTasks('grunt-concurrent');
259
  grunt.loadNpmTasks('grunt-contrib-watch');
260
  grunt.loadNpmTasks('grunt-contrib-clean');
261
  grunt.loadNpmTasks('grunt-contrib-uglify');
262
  grunt.loadNpmTasks('grunt-contrib-jshint');
263
  grunt.loadNpmTasks('grunt-contrib-concat');
264
  grunt.loadNpmTasks('grunt-contrib-connect');
265
};