1 | ;
|
2 | /*
|
3 | * manuscript
|
4 | * http://github.com/typesettin/manuscript
|
5 | *
|
6 | * Copyright (c) 2014 Yaw Joseph Etse. All rights reserved.
|
7 | */
|
8 |
|
9 | var path = require('path');
|
10 |
|
11 | module.exports = function (grunt) {
|
12 | grunt.initConfig({
|
13 | jsbeautifier: {
|
14 | files: ['<%= jshint.all %>'],
|
15 | options: {
|
16 | config: '.jsbeautify'
|
17 | }
|
18 | },
|
19 | simplemocha: {
|
20 | options: {
|
21 | globals: ['should', 'navigator'],
|
22 | timeout: 3000,
|
23 | ignoreLeaks: false,
|
24 | ui: 'bdd',
|
25 | reporter: 'spec'
|
26 | },
|
27 | all: {
|
28 | src: 'test/**/*.js'
|
29 | }
|
30 | },
|
31 | jshint: {
|
32 | options: {
|
33 | jshintrc: '.jshintrc'
|
34 | },
|
35 | all: [
|
36 | 'Gruntfile.js',
|
37 | 'index.js',
|
38 | 'app/**/*.js',
|
39 | '!app/doc/**/*.js',
|
40 | 'test/**/*.js',
|
41 | 'package.json',
|
42 | 'config/**/*.js',
|
43 | 'content/extensions/node_modules/**/index.js',
|
44 | 'content/extensions/node_modules/**/contoller/**/*.js',
|
45 | 'content/extensions/node_modules/**/resources/*.js',
|
46 | '!content/extensions/node_modules/**/node_modules/**/*.js'
|
47 | ]
|
48 | },
|
49 | jsdoc: {
|
50 | dist: {
|
51 | src: ['app/lib/*.js', 'test/*.js'],
|
52 | options: {
|
53 | destination: 'app/doc/html',
|
54 | configure: 'app/config/jsdoc.json'
|
55 | }
|
56 | }
|
57 | },
|
58 | browserify: {
|
59 | dist: {
|
60 | files: [{
|
61 | expand: true,
|
62 | cwd: 'content/extensions/node_modules',
|
63 | src: ['**/resources/js/*_src.js'],
|
64 | dest: 'content/extensions/node_modules',
|
65 | rename: function (dest, src) {
|
66 | var finallocation = path.join(dest, src);
|
67 | finallocation = finallocation.replace('_src', '_build');
|
68 | finallocation = finallocation.replace('resources', 'public');
|
69 | finallocation = path.resolve(finallocation);
|
70 | return finallocation;
|
71 | }
|
72 | }],
|
73 | options: {}
|
74 | }
|
75 | },
|
76 | uglify: {
|
77 | options: {
|
78 | sourceMap: true,
|
79 | compress: {
|
80 | drop_console: false
|
81 | }
|
82 | },
|
83 | all: {
|
84 | files: [{
|
85 | expand: true,
|
86 | cwd: 'content/extensions/node_modules',
|
87 | src: ['**/public/js/*_build.js'],
|
88 | dest: 'content/extensions/node_modules',
|
89 | rename: function (dest, src) {
|
90 | var finallocation = path.join(dest, src);
|
91 | finallocation = finallocation.replace('_build', '.min');
|
92 | finallocation = path.resolve(finallocation);
|
93 | return finallocation;
|
94 | }
|
95 | }]
|
96 | }
|
97 | },
|
98 | less: {
|
99 | development: {
|
100 | options: {
|
101 | sourceMap: true,
|
102 | yuicompress: true,
|
103 | compress: true
|
104 | },
|
105 | files: {
|
106 | 'public/styles/default/periodic.css': ['public/styles/default/periodic.less']
|
107 | }
|
108 | }
|
109 | },
|
110 | copy: {
|
111 | main: {
|
112 | files: [{
|
113 | expand: true,
|
114 | cwd: 'content/extensions/node_modules',
|
115 | src: ['**/public/**/*.*', '!**/node_modules/**/*.*'],
|
116 | // src: ['**/public/**/*.*', '!**/public/**/*_build.js', '!**/node_modules/**/*.*'],
|
117 | dest: 'public/extensions/',
|
118 | rename: function (dest, src) {
|
119 | var finallocation = path.join(dest, src.replace('public', ''));
|
120 | // finallocation = finallocation;
|
121 | finallocation = path.resolve(finallocation);
|
122 | // console.log("dest", dest, "src", src, "finallocation", finallocation);
|
123 | return finallocation;
|
124 | }
|
125 | }]
|
126 | }
|
127 | },
|
128 |
|
129 | /*
|
130 | cssmin: {
|
131 | combine: {
|
132 | files: {
|
133 | 'public/styles/manuscript.min.css': ['public/styles/manuscript.css']
|
134 | }
|
135 | }
|
136 | },
|
137 | imagemin: { // Task
|
138 | dynamic: { // Another target
|
139 | options: { // Target options
|
140 | optimizationLevel: 7
|
141 | },
|
142 | files: [{
|
143 | expand: true, // Enable dynamic expansion
|
144 | cwd: 'src/', // Src matches are relative to this path
|
145 | src: ['**\/*.{png,jpg,gif}'], // Actual patterns to match
|
146 | dest: 'dist/' // Destination path prefix
|
147 | }]
|
148 | }
|
149 | },
|
150 | copy: {
|
151 | vendor_fonts: {
|
152 | files: [
|
153 | // includes files within path
|
154 | {
|
155 | expand: true,
|
156 | cwd: 'app/vendor/',
|
157 | src: ['**\/*'],
|
158 | dest: 'dist/vendor/'
|
159 | }, {
|
160 | expand: true,
|
161 | cwd: 'app/fonts/',
|
162 | src: ['**\/*'],
|
163 | dest: 'dist/fonts/'
|
164 | }
|
165 | ]
|
166 | },
|
167 | spec: {
|
168 | expand: true,
|
169 | cwd: 'app/scripts',
|
170 | nonull: true,
|
171 | src: ['**\/*.js', '!bundle.js'],
|
172 | dest: 'test/unit/',
|
173 | filter: function (filepath) { //look in test/unit to see if spec already exists. Return TRUE to make new file (files does not exist)
|
174 | var dest = path.join(
|
175 | grunt.config('copy.spec.dest'),
|
176 | path.basename(filepath, '.js') + '_spec.js'
|
177 | );
|
178 | var doesFileExist = grunt.file.exists(dest);
|
179 | return !(doesFileExist);
|
180 | },
|
181 | rename: function (dest, src) {
|
182 | var src_spec = path.basename(src, '.js') + "_spec.js"
|
183 | return dest + src_spec;
|
184 | },
|
185 | options: {
|
186 | process: function (content, srcpath) { //between copy
|
187 | console.log("STARTING Replace", " ", srcpath);
|
188 | var varName = path.basename(srcpath, '.js');
|
189 | var require = "var " + varName + " = " + "require('" + '../../' + srcpath + "');";
|
190 | return require;
|
191 | }
|
192 | }
|
193 | }
|
194 | },
|
195 | plato: {
|
196 | lint: {
|
197 | options: {
|
198 | jshint: grunt.file.readJSON('.jshintrc'),
|
199 | dir: "reports",
|
200 | title: grunt.file.readJSON('package.json').name,
|
201 | complexity: {
|
202 | minmi: true,
|
203 | forin: true,
|
204 | logicalor: false
|
205 | }
|
206 | },
|
207 | files: {
|
208 | 'reports': ['app/scripts/**\/*.js']
|
209 | }
|
210 | },
|
211 | },
|
212 | mocha_istanbul: {
|
213 | coverage: {
|
214 | src: 'test/unit',
|
215 | options: {
|
216 | check: {
|
217 | lines: 75,
|
218 | statements: 75,
|
219 | branches: 75,
|
220 | functions: 75
|
221 | },
|
222 | mask: '*.js',
|
223 | instrument: ['test'],
|
224 | coverageFolder: "reports/coverage",
|
225 | reporter: "html-cov",
|
226 | ui: 'bdd',
|
227 | root: 'app/scripts/',
|
228 | print: 'summary',
|
229 | excludes: ['node_modules', 'dist']
|
230 | }
|
231 | }
|
232 | },
|
233 | casperjs: {
|
234 | options: {
|
235 | async: {
|
236 | parrallel: true
|
237 | }
|
238 | },
|
239 | files: {
|
240 | src: ['test/intergration/**\/*.js']
|
241 | }
|
242 | },
|
243 | */
|
244 | watch: {
|
245 | options: {
|
246 | interrupt: true
|
247 | },
|
248 | css: {
|
249 | files: ['public/stylesheets/**/*.less'],
|
250 | tasks: ['newer:less']
|
251 | },
|
252 | js: {
|
253 | files: ['<%= jshint.all %>', 'content/extensions/node_modules/**/resources/**/*.js'],
|
254 | tasks: ['newer:simplemocha:all', 'newer:jshint:all', 'newer:jsbeautifier', 'newer:browserify', 'newer:uglify:all', 'newer:copy:main']
|
255 | }
|
256 | }
|
257 | });
|
258 |
|
259 | // Loading dependencies
|
260 | for (var key in grunt.file.readJSON('package.json').devDependencies) {
|
261 | if (key.indexOf('grunt') === 0 && key !== 'grunt') {
|
262 | grunt.loadNpmTasks(key);
|
263 | }
|
264 | }
|
265 |
|
266 | grunt.registerTask('default', ['lint', 'browserify', 'doc', 'cssmin', 'uglify', 'test', 'less']);
|
267 | };
|