forked from emmetio/emmet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gruntfile.js
100 lines (86 loc) · 2.46 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
module.exports = function(grunt) {
var fs = require('fs');
var path = require('path');
var ciu = require('./lib/assets/caniuse');
function getOptimizedCIU(file) {
var content = readFile(file);
return JSON.stringify(ciu.optimize(content));
}
function readFile(name) {
return fs.readFileSync(name, {encoding: 'utf8'});
}
var rjsStart = '(function (root, factory) {' +
'if (typeof define === \'function\' && define.amd) {' +
'define(factory);' +
'} else {' +
'root.emmet = factory();' +
'}' +
'}(this, function () {';
var rjsEnd = 'var _emmet = require("emmet");' +
'_emmet.require = require;' +
'_emmet.define = define;' +
'return _emmet;}));';
var rjsSnippets = 'var resources = require("assets/resources");' +
'resources.setVocabulary(' + readFile('./lib/snippets.json') + ', "system");';
var rjsCanIUse = 'var caniuse = require("assets/caniuse");' +
'caniuse.load(' + getOptimizedCIU('./lib/caniuse.json') + ', true);';
var rjsOpt = {
baseUrl: './lib',
paths: {
lodash: '../node_modules/lodash/lodash'
},
rawText: {
'fs': 'define({});',
'path': 'define({});'
},
include: ['./emmet'],
name: 'vendor/almond',
optimize: 'none',
out: './dist/emmet.js',
wrap: {
start: rjsStart,
end: rjsEnd
}
};
function merge(obj) {
var args = Array.prototype.slice.call(arguments, 1), c;
while (c = args.shift()) {
Object.keys(c).forEach(function(k) {
obj[k] = c[k];
});
}
return obj;
}
function rjsConfig(opt) {
return {options: merge({}, rjsOpt, opt)};
}
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
requirejs: {
// "App" version of Emmet: does not include snippets.json and caniuse.json,
// assuming that it should be loaded by app controller
app: rjsConfig({out: './dist/emmet-app.js',}),
// "Full" version of Emmet: ad-hoc bundle, mostly used by
// browser plugins simply by including single <script> tag
// with full Emmet version (minified version is also available)
full: rjsConfig({
wrap: {
start: rjsStart,
end: rjsSnippets + rjsCanIUse + rjsEnd
}
})
},
uglify: {
full: {
src: ['./dist/emmet.js'],
dest: './dist/emmet-min.js'
}
}
});
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-requirejs');
grunt.registerTask('app', ['requirejs:app']);
grunt.registerTask('full', ['requirejs:full', 'uglify:full']);
grunt.registerTask('default', ['app', 'full']);
};