-
Notifications
You must be signed in to change notification settings - Fork 173
/
Copy pathGruntfile.js
82 lines (76 loc) · 2.13 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
const path = require('path');
const webpackConfig = require('./webpack.config.js');
module.exports = function () {
// Project configuration
this.initConfig({
pkg: this.file.readJSON('package.json'),
// Browser build of NoFlo
webpack: {
build: webpackConfig,
},
sharedstylecomponent: {
'elements/the-graph-styles.js': [
'node_modules/the-graph/themes/the-graph-dark.css',
'node_modules/the-graph/themes/the-graph-light.css',
],
'elements/codemirror-styles.js': [
'node_modules/codemirror/addon/lint/lint.css',
'node_modules/codemirror/lib/codemirror.css',
'node_modules/codemirror/theme/mdn-like.css',
'css/codemirror-noflo.css',
],
},
});
// Grunt plugins used for building
this.loadNpmTasks('grunt-webpack');
// Our local tasks
const grunt = this;
this.registerMultiTask('sharedstylecomponent', 'Combine CSS files into a Polymer shared style element', function () {
const sources = this.data.map((file) => grunt.file.read(file));
const template = `\
/**
* Generated from <%= files %>
*/
const $_documentContainer = document.createElement('template');
$_documentContainer.innerHTML = \`
<dom-module id="<%= id %>">
<template>
<style>
<%= sources %>
</style>
</template>
</dom-module>\`;
document.head.appendChild($_documentContainer.content);
`;
const id = path.basename(this.target, path.extname(this.target));
const result = grunt.template.process(template, {
data: {
id,
files: this.data.map((f) => path.basename(f)).join(', '),
sources: sources.join('\n'),
},
});
grunt.file.write(this.target, result);
return grunt.log.writeln(`Generated ${this.target} from ${this.data.join(', ')}`);
});
this.registerTask('build_noflo', [
'webpack',
]);
this.registerTask('build_polymer', [
'sharedstylecomponent',
]);
this.registerTask('build', [
'build_polymer',
'build_noflo',
]);
this.registerTask('rebuild', [
'nuke',
'build',
]);
this.registerTask('default', [
'build',
]);
this.registerTask('pages', [
'build',
]);
};