-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGruntfile.js
More file actions
126 lines (105 loc) · 3.66 KB
/
Gruntfile.js
File metadata and controls
126 lines (105 loc) · 3.66 KB
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
/*jslint node: true */
'use strict';
let fs = require('fs');
let path = require('path');
//
// allJSPackages is the global array of npm-publishable packages in this monorepo.
// This is all folders inside the /packages folder that start with the prefix
// "basic-".
const JS_PACKAGE_FOLDER = 'js-packages';
//const POLYMER_PACKAGE_FOLDER = 'polymer-packages';
const allJSPackages = fs.readdirSync(JS_PACKAGE_FOLDER).filter(fileName => {
let filePath = path.join(JS_PACKAGE_FOLDER, fileName);
let stat = fs.statSync(filePath);
return stat && stat.isDirectory() && fileName.startsWith('js-');
});
//
// Build the global buildList object for use in browserify:components
//
function buildBuildList() {
let srcFiles = allJSPackages.map(pkg => {
return 'js-packages/' + pkg + '/src/*.js';
});
let obj = {
'build/js-web-components.js': srcFiles
};
allJSPackages.forEach(pkg => {
obj['js-packages/' + pkg + '/dist/' + pkg + '.js'] = ['js-packages/' + pkg + '/src/*.js'];
});
// Special cases: dist gets built from the es5globals file.
obj['js-packages/js-component-mixins/dist/js-component-mixins.js'] = 'js-packages/js-component-mixins/es5globals.js';
return obj;
}
const buildList = buildBuildList();
module.exports = function(grunt) {
grunt.loadNpmTasks('grunt-browserify');
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-contrib-connect');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-shell');
grunt.initConfig({
clean: {
build: 'build'
},
browserify: {
options: {
browserifyOptions: {
debug: true
}
},
buildFiles: {
files: buildList
},
watch: {
files: buildList,
options: {
keepAlive: true,
watch: true
}
}
},
jshint: {
all: [
'Gruntfile.js',
'js-packages/**/*.js',
'!js-packages/**/dist/*',
'!js-packages/**/lib/*'
],
options: {
jshintrc: true
}
}
});
//
// Default task - prints to the console the tasks that are available to be run from the command line
//
grunt.registerTask('default', function () {
grunt.log.writeln('grunt commands this project supports:\n');
grunt.log.writeln(' grunt build (builds consolidated basic-web-components.js, all package distributions, all documentation, and all tests)');
grunt.log.writeln(' grunt lint (runs jshint on all .js files)');
grunt.log.writeln(' grunt watch (builds and watches changes to project files)');
});
//
// The build task is callable from the command line and executes the browserify:buildFiles task
// defined in the Grunt config. This task builds ES5 transpiled files written to each package's
// dist folder. A developer who uses "npm install" on that package can import the resulting
// JavaScript file(s) from the package's dist folder without the need for Babel in an ES5
// ecosystem.
//
// Note that this task also builds each package's README.md file via the docs task.
//
// This task makes use of the buildList global array.
//
grunt.registerTask('build', ['browserify:buildFiles', 'jshint']);
//
// The lint task is callable from the command line and executes the jshint task defined
// in the Grunt config. This task looks for JavaScript warnings/errors.
//
grunt.registerTask('lint', ['jshint']);
//
// The watch task is callable from the command line and executes the browserify:watch task
// defined in the Grunt config. This task performs a build and then watches for changes
// for instant update during development.
//
grunt.registerTask('watch', ['browserify:watch']);
};