-
Notifications
You must be signed in to change notification settings - Fork 47
/
gruntfile.js
170 lines (157 loc) · 4.66 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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
var lrSnippet = require('grunt-contrib-livereload/lib/utils').livereloadSnippet;
var serveStatic = require('serve-static');
var fs = require('fs')
const path = require('path')
const config = require('./motley.config.json')
var mountFolder = function (connect, dir) {
return serveStatic(require('path').resolve(dir));
};
const getPartials = () => {
const commonComponents = fs.readdirSync('./examples/components')
.filter(filename => filename.split('.').pop() === 'hbs')
.map(filename => filename.split('.')[0])
.reduce((acc, filename) => {
acc[filename] = path.join('./examples/components', filename + '.hbs')
return acc;
}, {})
const applicationComponents = config.applications.map(m => {
if (!fs.existsSync(`./examples/components/${m}`)) {
fs.mkdirSync(`./examples/components/${m}`)
}
return fs.readdirSync(`./examples/components/${m}`)
.filter(filename => filename.split('.').pop() === 'hbs')
.map(filename => filename.split('.')[0])
.reduce((acc, filename) => {
acc[filename] = path.join(`./examples/components/${m}`, filename + '.hbs')
return acc;
}, {})
})
.reduce((acc, application) => Object.assign(acc, application), {})
return Object.assign(commonComponents, applicationComponents)
}
const getFiles = () => {
const commonViews = fs.readdirSync(`./examples/views`)
.filter(filename => filename.split('.').pop() === 'hbs')
.map(filename => filename.split('.')[0])
.reduce((acc, filename) => {
acc[path.join('./examples/html', filename + '.html')] = path.join('./examples/views', filename + '.hbs')
return acc;
}, {})
const applicationViews = config.applications.map(m => {
if (!fs.existsSync(`./examples/views/${m}`)) {
fs.mkdirSync(`./examples/views/${m}`)
}
return fs.readdirSync(`./examples/views/${m}`)
.filter(filename => filename.split('.').pop() === 'hbs')
.map(filename => filename.split('.')[0])
.reduce((acc, filename) => {
acc[path.join('./examples/html', filename + '.html')] = path.join(`./examples/views/${m}`, filename + '.hbs')
return acc;
}, {})
})
.reduce((acc, application) => Object.assign(acc, application), {})
return Object.assign(commonViews, applicationViews)
}
const getAppScssFiles = () => {
const appScssfiles = { 'examples/public/stylesheets/style.css': 'sass/styles/app.scss' }
config.applications.map(app => {
appScssfiles[`examples/public/stylesheets/${app}.css`] = `sass/styles/applications/${app}/app.scss`
})
return appScssfiles
}
module.exports = function (grunt) {
grunt.loadNpmTasks('grunt-contrib-clean');
require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks);
grunt.initConfig({
sass: {
dist: {
files: getAppScssFiles()
}
},
hbs: {
public: {
options: {
layout: './examples/views/layouts/default.hbs',
partials: getPartials(),
},
files: getFiles()
}
},
watch: {
static: {
files: ['public/**/*'],
options: {
livereload: true
}
},
hbs: {
files: ['examples/views/**/*.hbs', 'examples/components/**/*.hbs'],
tasks: ['hbs'],
options: {
livereload: true
}
},
source: {
files: ['sass/**/**/*.scss'],
tasks: ['sass'],
options: {
livereload: true
}
}
},
connect: {
options: {
port: 9000,
hostname: '0.0.0.0'
},
livereload: {
options: {
middleware: function (connect) {
return [
//lrSnippet,
mountFolder(connect, './examples/public'),
mountFolder(connect, './examples/html')
];
}
}
}
},
open: {
server: {
url: 'http://localhost:9000'
}
},
clean: [
'dist',
'live',
'examples/html',
'examples/public/stylesheets/'
],
createFolders: {
applications: config.applications
}
});
grunt.registerTask('createFolders', 'Creating application folders', function (target) {
const { applications } = grunt.config.get().createFolders
applications.map(m => {
grunt.file.mkdir(`examples/views/${m}`)
grunt.file.mkdir(`examples/components/${m}`)
})
})
grunt.registerTask('server', function (target) {
grunt.task.run([
'createFolders',
'hbs',
'sass',
'connect',
'open',
'watch'
]);
});
grunt.registerTask('build', function (target) {
grunt.task.run([
'hbs',
'sass'
]);
});
};