1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 | 'use strict';
|
10 |
|
11 | var extendGruntPlugin = require('extend-grunt-plugin');
|
12 | var packpath = require('packpath');
|
13 | var path = require('path');
|
14 | var _ = require('lodash');
|
15 |
|
16 | module.exports = function (grunt) {
|
17 |
|
18 | grunt.registerMultiTask('appcJs', 'Linting and style checks for Appcelerator JavaScript', function (lintOnly) {
|
19 | var that = this;
|
20 | var source = this.data;
|
21 | if (this.data.src) {
|
22 | source = this.data.src;
|
23 | }
|
24 |
|
25 | initializeJscsPlugin();
|
26 | initializeJshintPlugin();
|
27 | if(lintOnly) {
|
28 | grunt.task.run('jshint:src', 'jscs:src');
|
29 | } else {
|
30 | initializeContinuePlugin();
|
31 | initializeRetirePlugin();
|
32 | grunt.task.run('jshint:src', 'jscs:src', 'continue:on', 'retire', 'continue:off');
|
33 |
|
34 | }
|
35 |
|
36 |
|
37 |
|
38 | |
39 |
|
40 |
|
41 |
|
42 |
|
43 | function initializeJscsPlugin() {
|
44 |
|
45 | var optionsJscs = {
|
46 | src: source,
|
47 | options: _.omit(that.options({
|
48 | config: path.join(__dirname, '..', '.jscsrc'),
|
49 | reporter: require('jscs-stylish').path,
|
50 | }), 'globals')
|
51 | };
|
52 |
|
53 | var jscs = require('grunt-jscs/tasks/jscs');
|
54 | extendGruntPlugin(grunt, jscs, {
|
55 | 'jscs.src' : optionsJscs
|
56 | });
|
57 | }
|
58 |
|
59 | |
60 |
|
61 |
|
62 |
|
63 |
|
64 | function initializeJshintPlugin() {
|
65 | var jsHintConfig = {
|
66 | browser: true,
|
67 | curly: true,
|
68 | eqeqeq: true,
|
69 | eqnull: true,
|
70 | expr: true,
|
71 | immed: true,
|
72 | indent: 4,
|
73 | latedef: false,
|
74 | newcap: true,
|
75 | noarg: true,
|
76 | nonew: true,
|
77 | undef: true,
|
78 | unused: false,
|
79 | trailing: true,
|
80 | loopfunc: true,
|
81 | proto: true,
|
82 | node: true,
|
83 | '-W104': true,
|
84 | '-W068': true,
|
85 | globals: {
|
86 | after : false,
|
87 | afterEach : false,
|
88 | before : false,
|
89 | beforeEach : false,
|
90 | describe : false,
|
91 | it : false,
|
92 | Titanium : false,
|
93 | Ti : false
|
94 | }
|
95 | };
|
96 |
|
97 | var optionsJsHint = {
|
98 | src: source,
|
99 | options: _.omit(_.merge(that.options(),
|
100 | {reporter: require('jshint-stylish')},
|
101 | jsHintConfig), 'fix')
|
102 | };
|
103 |
|
104 | var jshint = require('grunt-contrib-jshint/tasks/jshint');
|
105 | extendGruntPlugin(grunt, jshint, {
|
106 | 'jshint.src' : optionsJsHint
|
107 | });
|
108 | }
|
109 |
|
110 | |
111 |
|
112 |
|
113 |
|
114 |
|
115 |
|
116 |
|
117 |
|
118 | function initializeRetirePlugin() {
|
119 | var optionsRetire = {
|
120 | js: source,
|
121 | node: ['.'],
|
122 | options: {
|
123 | packageOnly: false
|
124 | }
|
125 | };
|
126 |
|
127 | var retire = require('grunt-retire/tasks/retire');
|
128 | retire(grunt);
|
129 | grunt.config.set('retire', optionsRetire);
|
130 | }
|
131 |
|
132 | |
133 |
|
134 |
|
135 |
|
136 |
|
137 |
|
138 |
|
139 |
|
140 |
|
141 | function initializeContinuePlugin() {
|
142 | var gruntContinue = require('grunt-continue/tasks/continue');
|
143 | gruntContinue(grunt);
|
144 | }
|
145 | });
|
146 |
|
147 | };
|