webextension-polyfill/Gruntfile.js

110 lines
2.8 KiB
JavaScript
Raw Normal View History

2016-10-07 01:20:37 +00:00
/* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* vim: set sts=2 sw=2 et tw=80: */
"use strict";
/* eslint-env commonjs */
const LICENSE = `/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */`;
2016-11-22 15:46:39 +00:00
const MINIFIED_FILE_FOOTER = `\n\n// <%= pkg.name %> v.<%= pkg.version %> (<%= pkg.homepage %>)\n\n${LICENSE}`;
2016-10-07 01:20:37 +00:00
module.exports = function(grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON("package.json"),
coveralls: {
all: {
src: "coverage/lcov.info",
},
},
2016-10-07 01:20:37 +00:00
eslint: {
src: ["src/browser-polyfill.js", "Gruntfile.js"],
2016-10-11 11:52:44 +00:00
test: ["test/**/*.js"],
2016-10-07 01:20:37 +00:00
},
replace: {
dist: {
options: {
patterns: [
{
match: /\{\/\* include\("(.*?)"\) \*\/\}/,
2016-10-07 01:20:37 +00:00
replacement: (match, filename) => {
return grunt.file.read(filename)
.replace(/\n$/, "")
.replace(/^[^{]/gm, " $&");
2016-10-07 01:20:37 +00:00
},
},
{
json: {
"package_name": "<%= pkg.name %>",
"version": "<%= pkg.version %>",
"timestamp": "<%= grunt.template.today() %>",
},
},
],
},
files: [
{
expand: true,
flatten: true,
src: ["src/browser-polyfill.js"],
2016-10-07 01:20:37 +00:00
dest: "dist/",
},
],
},
},
2016-11-22 15:46:39 +00:00
babel: {
minify: {
2016-10-07 01:20:37 +00:00
options: {
2016-11-22 15:46:39 +00:00
babelrc: false,
comments: false,
presets: ["babili"],
sourceMap: true,
},
files: {
"dist/browser-polyfill.min.js": "dist/browser-polyfill.js",
2016-10-07 01:20:37 +00:00
},
},
umd: {
options: {
babelrc: false,
comments: true,
plugins: [
["transform-es2015-modules-umd", {
globals: {
"webextension-polyfill": "browser",
},
exactGlobals: true,
}],
],
sourceMap: true,
moduleId: "webextension-polyfill",
},
files: {
"dist/browser-polyfill.js": "dist/browser-polyfill.js",
},
},
2016-10-07 01:20:37 +00:00
},
2016-11-22 15:46:39 +00:00
concat: {
license: {
src: "dist/browser-polyfill.min.js",
dest: "dist/browser-polyfill.min.js",
options: {footer: MINIFIED_FILE_FOOTER},
2016-10-07 01:20:37 +00:00
},
},
});
grunt.loadNpmTasks("gruntify-eslint");
grunt.loadNpmTasks("grunt-replace");
grunt.loadNpmTasks("grunt-coveralls");
2016-11-22 15:46:39 +00:00
grunt.loadNpmTasks("grunt-contrib-concat");
grunt.loadNpmTasks("grunt-babel");
2016-10-07 01:20:37 +00:00
grunt.registerTask("default", ["eslint", "replace", "babel:umd", "babel:minify", "concat:license"]);
2016-10-07 01:20:37 +00:00
};