forked from spencermountain/compromise
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGruntfile.js
executable file
·149 lines (140 loc) · 4.12 KB
/
Gruntfile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
// build script for the client-side file
module.exports = function(grunt) {
// TODO - LOCALIZATION NOT DONE YET! [redaktor fork changes]
var lang = 'en';
var C = {
banner: {
max: '/*! <%= pkg.name %> <%= pkg.version %> by @spencermountain <%= grunt.template.today("yyyy-mm-dd") %> <%= pkg.license%> */\n',
min: ' /*nlp_comprimise by @spencermountain in 2015*/\n'
},
path: {
data: './src/data/',
parents: './src/parents/',
methods: './src/methods/',
main: './client_side/nlp.js',
zip: './client_side/nlp.zip.js',
min: './client_side/nlp.min.js'
}
};
C.path.nls = C.path.data+lang+'/';
/*
-b or --beautify — output indented code; when passed, additional options control the beautifier:
-i N or --indent N — indentation level (number of spaces)
-q or --quote-keys — quote keys in literal objects (by default, only keys that cannot be identifier names will be quotes).
*/
// generate all language dependent data modules first ...
require(C.path.data+'_build')();
// use minimized files for uglify
/*
var filesCompressed = files.map(function(p) {
var zipP = p.replace('.js', '.min.js');
return (grunt.file.exists(zipP)) ? zipP : p;
});
*/
// project configuration ...
grunt.initConfig({
pkg: grunt.file.readJSON('./package.json'),
/*
concat: {
options: {
banner: (C.banner.max + 'var nlp = (function() {\n'),
process: function(src, filepath) {
// remove node.js only and trailing whitespace
return src.replace(/^.*\/\/::NODE::[\s\S]*?.*[\s\S]*?\/\/::.*?$/gm, '').replace(/[ \t]+$/gm, '');
},
footer: "\nreturn nlp;\n})()"
},
dist: {
src: files,
dest: C.path.main,
nonull: true
},
zip: {
src: filesCompressed,
dest: C.path.zip,
nonull: true
}
},
*/
browserify:{
client: {
src: './index.js',
dest: './client_side/nlp.js',
options:{
standalone: true
}
}
},
browserifyZipped:{
client: {
src: './index.min.js',
dest: './client_side/nlp.js',
options:{
standalone: true
}
}
},
uglify: {
do :{
src: [C.path.zip],
dest: C.path.min
},
options: {
preserveComments: false,
mangle: true,
banner: C.banner.min,
compress: {
drop_console: true,
dead_code: true,
properties: true,
unused: true,
warnings: true
}
}
},
jscs: {
all: [C.path.main],
options: {
requireCurlyBraces: true,
disallowMixedSpacesAndTabs: true,
disallowEmptyBlocks: true,
disallowFunctionDeclarations: true,
disallowImplicitTypeConversion: ['numeric', 'boolean', 'binary', 'string'],
requireAnonymousFunctions: true,
requireOperatorBeforeLineBreak: true,
disallowTrailingWhitespace: true
//disallowTrailingComma:true
}
},
jshint: {
options: {
globals: {
module: true,
require: true,
exports: true
},
boss:true, // double equals
asi: true, //semicolons
sub: true, //dot notation
devel: true //console.log
},
afterconcat: [C.path.main]
}
});
// Load the plugins
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-jscs');
grunt.registerTask('cleanup', 'Remove compressed files. They were concat and minimized in nlp.min.js', function() {
var minStr = '.min.js';
filesCompressed.forEach(function(p){
// delete "zipped" data modules (concated for now)
if (p.indexOf(C.path.nls) > -1 && (p.length-minStr.length) === p.indexOf(minStr)) grunt.file.delete(p);
});
// delete "zipped" concat file (minimized now)
//grunt.file.delete(C.path.zip);
grunt.log.writeln('File'['white'], './client_side/nlp.min.js'['cyan'], 'was created before. Now tidy. '['white']).ok();
});
grunt.registerTask('default', ['concat', 'jscs', /*'jshint',*/ 'uglify', 'cleanup']);
};