|
| 1 | +module.exports = function (grunt) { |
| 2 | + require('load-grunt-tasks')(grunt); |
| 3 | + require('time-grunt')(grunt); |
| 4 | + require('grunt-karma')(grunt); |
| 5 | + |
| 6 | + //cant load this with require |
| 7 | + grunt.loadNpmTasks('grunt-contrib-jshint'); |
| 8 | + |
| 9 | + if (grunt.option('target') && !grunt.file.isDir(grunt.option('target'))) { |
| 10 | + grunt.fail.warn('The --target option specified is not a valid directory'); |
| 11 | + } |
| 12 | + |
| 13 | + grunt.initConfig({ |
| 14 | + pkg: grunt.file.readJSON('package.json'), |
| 15 | + dest: grunt.option('target') || 'dist', |
| 16 | + basePath: 'src/RJP.MultiUrlPicker/App_Plugins/RJP.MultiUrlPicker', |
| 17 | + |
| 18 | + watch: { |
| 19 | + options: { |
| 20 | + atBegin: true |
| 21 | + }, |
| 22 | + |
| 23 | + testControllers: { |
| 24 | + files: [ |
| 25 | + '<%= basePath %>/**/*.js', |
| 26 | + 'src/RJP.MultiUrlPicker/test/specs/**/*.spec.js' |
| 27 | + ], |
| 28 | + tasks: ['jshint', 'test'] |
| 29 | + }, |
| 30 | + }, |
| 31 | + |
| 32 | + copy: { |
| 33 | + nuget: { |
| 34 | + expand: true, |
| 35 | + cwd: '<%= basePath %>', |
| 36 | + src: '<%= basePath %>', |
| 37 | + dest: 'tmp/nuget/content/' |
| 38 | + }, |
| 39 | + |
| 40 | + umbraco: { |
| 41 | + expand: true, |
| 42 | + cwd: '<%= basePath %>/', |
| 43 | + src: '<%= basePath %>', |
| 44 | + dest: 'tmp/umbraco/' |
| 45 | + }, |
| 46 | + |
| 47 | + testAssets: { |
| 48 | + expand: true, |
| 49 | + cwd: '<%= dest %>', |
| 50 | + src: ['js/umbraco.*.js', 'lib/**/*.js'], |
| 51 | + dest: 'src/RJP.MultiUrlPicker/test/assets/' |
| 52 | + } |
| 53 | + }, |
| 54 | + |
| 55 | + template: { |
| 56 | + nuspec: { |
| 57 | + options: { |
| 58 | + data: { |
| 59 | + name: '<%= pkg.name %>', |
| 60 | + version: '<%= pkg.version %>', |
| 61 | + author: '<%= pkg.author.name %>', |
| 62 | + description: '<%= pkg.description %>' |
| 63 | + } |
| 64 | + }, |
| 65 | + files: { |
| 66 | + 'tmp/nuget/<%%= pkg.name %>.nuspec': 'package.nuspec' |
| 67 | + } |
| 68 | + } |
| 69 | + }, |
| 70 | + |
| 71 | + mkdir: { |
| 72 | + pkg: { |
| 73 | + options: { |
| 74 | + create: ['pkg/nuget', 'pkg/umbraco'] |
| 75 | + }, |
| 76 | + }, |
| 77 | + }, |
| 78 | + |
| 79 | + nugetpack: { |
| 80 | + dist: { |
| 81 | + src: 'tmp/nuget/<%= pkg.name %>.nuspec', |
| 82 | + dest: 'pkg/nuget/' |
| 83 | + } |
| 84 | + }, |
| 85 | + |
| 86 | + umbracoPackage: { |
| 87 | + options: { |
| 88 | + name: '<%= pkg.name %>', |
| 89 | + version: '<%= pkg.version %>', |
| 90 | + url: '<%= pkg.url %>', |
| 91 | + license: '<%= pkg.license %>', |
| 92 | + licenseUrl: '<%= pkg.licenseUrl %>', |
| 93 | + author: '<%= pkg.author %>', |
| 94 | + authorUrl: '<%= pkg.authorUrl %>', |
| 95 | + manifest: 'config/package.xml', |
| 96 | + readme: 'config/readme.txt', |
| 97 | + sourceDir: 'tmp/umbraco', |
| 98 | + outputDir: 'pkg/umbraco', |
| 99 | + } |
| 100 | + }, |
| 101 | + |
| 102 | + clean: { |
| 103 | + dist: '<%= dest %>', |
| 104 | + test: 'src/RJP.MultiUrlPicker/test/assets' |
| 105 | + }, |
| 106 | + |
| 107 | + karma: { |
| 108 | + unit: { |
| 109 | + configFile: 'src/RJP.MultiUrlPicker/test/karma.conf.js' |
| 110 | + } |
| 111 | + }, |
| 112 | + |
| 113 | + jshint: { |
| 114 | + dev: { |
| 115 | + files: { |
| 116 | + src: ['<%= basePath %>/**/*.js'] |
| 117 | + }, |
| 118 | + options: { |
| 119 | + curly: true, |
| 120 | + eqeqeq: true, |
| 121 | + immed: true, |
| 122 | + latedef: true, |
| 123 | + newcap: true, |
| 124 | + noarg: true, |
| 125 | + sub: true, |
| 126 | + boss: true, |
| 127 | + eqnull: true, |
| 128 | + //NOTE: we need to use eval sometimes so ignore it |
| 129 | + evil: true, |
| 130 | + //NOTE: we need to check for strings such as "javascript:" so don't throw errors regarding those |
| 131 | + scripturl: true, |
| 132 | + //NOTE: we ignore tabs vs spaces because enforcing that causes lots of errors depending on the text editor being used |
| 133 | + smarttabs: true, |
| 134 | + globals: {} |
| 135 | + } |
| 136 | + } |
| 137 | + } |
| 138 | + }); |
| 139 | + |
| 140 | + grunt.registerTask('default', ['jshint']); |
| 141 | + grunt.registerTask('nuget', ['clean', 'default', 'copy:nuget', 'template:nuspec', 'mkdir:pkg', 'nugetpack']); |
| 142 | + grunt.registerTask('package', ['clean', 'default', 'copy:umbraco', 'mkdir:pkg', 'umbracoPackage']); |
| 143 | + |
| 144 | + grunt.registerTask('test', 'Clean, copy test assets, test', function () { |
| 145 | + var assetsDir = grunt.config.get('dest'); |
| 146 | + //copies over umbraco assets from --target, this must point at the /umbraco/ directory |
| 147 | + if (assetsDir !== 'dist') { |
| 148 | + grunt.task.run(['clean:test', 'copy:testAssets', 'karma']); |
| 149 | + } else if (grunt.file.isDir('src/RJP.MultiUrlPicker/test/assets/js/')) { |
| 150 | + grunt.log.oklns('Test assets found, running tests'); |
| 151 | + grunt.task.run(['karma']); |
| 152 | + } else { |
| 153 | + grunt.log.errorlns('Tests assets not found, skipping tests. Run with --target option to copy assets.'); |
| 154 | + } |
| 155 | + }); |
| 156 | +}; |
0 commit comments