-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgruntfile.js
95 lines (80 loc) · 2.69 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
module.exports = function (grunt) {
var path = require("path");
grunt.initConfig({
pkg: grunt.file.readJSON("package.json"),
dust: {
options: {
name: function (data) {
var fileName = data.file.src[0];
fileName = fileName.replace("/", "_");
fileName = fileName.replace(path.extname(fileName), "");
return "app_" + fileName.toLowerCase();
}
},
build: {
expand: true,
cwd: "./views",
src: "**/*.html",
dest: "./compiledTemplates",
ext: ".js",
filter: "isFile"
}
},
concat: {
options: {
separator: "\n",
},
dist: {
src: "./compiledTemplates/*.js",
dest: "./js/ui-templates.js",
}
},
jsbeautifier: {
files: ["./*.html"]
},
less: {
development: {
options: {
paths: ["./styles"]
},
files: {
"./styles/styles.css": "./styles/styles.less"
}
}
},
watch: {
templates: {
files: ["./views/**/*.html"],
tasks: ["dust", "dust-static-templates", "concat", "jsbeautifier"],
options: {
event: ["all"]
}
},
styles: {
files: ["./styles/**/*.less"],
tasks: ["less"],
options: {
event: ["all"]
}
}
}
});
grunt.registerTask("dust-static-templates", "Compiles static files", function () {
var fs = require("fs");
var dust = require("dustjs-linkedin");
var compiledTemplate = dust.compile(fs.readFileSync("./views/master.html", "utf8"), "app_views_master");
dust.loadSource(compiledTemplate);
compiledTemplate = dust.compile(fs.readFileSync("./views/index.html", "utf8"), "app_views_index");
dust.loadSource(compiledTemplate);
dust.render("app_views_index", {}, function (err, text) {
fs.writeFileSync("./index.html", text);
});
});
grunt.loadNpmTasks("grunt-contrib-watch");
grunt.loadNpmTasks("grunt-contrib-concat");
grunt.loadNpmTasks("grunt-dustjs-linkedin");
grunt.loadNpmTasks('grunt-jsbeautifier');
grunt.loadNpmTasks("grunt-contrib-less");
grunt.registerTask("default", ["dust", "concat"]);
grunt.registerTask("develop", ["watch"]);
};