123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348 |
- const webpack = require("webpack");
- const ExtractTextPlugin = require("extract-text-webpack-plugin");
- const HtmlWebpackPlugin = require("html-webpack-plugin");
- const Inliner = require("web-resource-inliner");
- module.exports = function (grunt) {
- grunt.file.defaultEncoding = "utf8";
- grunt.file.preserveBOM = false;
- // Tasks
- grunt.registerTask("dev",
- "A persistent task which creates a development build whenever source files are modified.",
- ["clean:dev", "webpack:webDev"]);
- grunt.registerTask("node",
- "Compiles CyberChef into a single NodeJS module.",
- ["clean:node", "webpack:node", "chmod:build"]);
- grunt.registerTask("test",
- "A task which runs all the tests in test/tests.",
- ["clean:test", "webpack:tests", "execute:test"]);
- grunt.registerTask("docs",
- "Compiles documentation in the /docs directory.",
- ["clean:docs", "jsdoc", "chmod:docs"]);
- grunt.registerTask("prod",
- "Creates a production-ready build. Use the --msg flag to add a compile message.",
- ["eslint", "clean:prod", "webpack:webProd", "inline", "chmod"]);
- grunt.registerTask("default",
- "Lints the code base",
- ["eslint", "exec:repoSize"]);
- grunt.registerTask("inline",
- "Compiles a production build of CyberChef into a single, portable web page.",
- runInliner);
- grunt.registerTask("doc", "docs");
- grunt.registerTask("tests", "test");
- grunt.registerTask("lint", "eslint");
- // Load tasks provided by each plugin
- grunt.loadNpmTasks("grunt-eslint");
- grunt.loadNpmTasks("grunt-webpack");
- grunt.loadNpmTasks("grunt-jsdoc");
- grunt.loadNpmTasks("grunt-contrib-clean");
- grunt.loadNpmTasks("grunt-contrib-copy");
- grunt.loadNpmTasks("grunt-chmod");
- grunt.loadNpmTasks("grunt-exec");
- grunt.loadNpmTasks("grunt-execute");
- grunt.loadNpmTasks("grunt-accessibility");
- // Project configuration
- const compileTime = grunt.template.today("dd/mm/yyyy HH:MM:ss") + " UTC",
- banner = "/**\n" +
- "* CyberChef - The Cyber Swiss Army Knife\n" +
- "*\n" +
- "* @copyright Crown Copyright 2016\n" +
- "* @license Apache-2.0\n" +
- "*\n" +
- "* Copyright 2016 Crown Copyright\n" +
- "*\n" +
- '* Licensed under the Apache License, Version 2.0 (the "License");\n' +
- "* you may not use this file except in compliance with the License.\n" +
- "* You may obtain a copy of the License at\n" +
- "*\n" +
- "* http://www.apache.org/licenses/LICENSE-2.0\n" +
- "*\n" +
- "* Unless required by applicable law or agreed to in writing, software\n" +
- '* distributed under the License is distributed on an "AS IS" BASIS,\n' +
- "* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n" +
- "* See the License for the specific language governing permissions and\n" +
- "* limitations under the License.\n" +
- "*/\n";
- /**
- * Compiles a production build of CyberChef into a single, portable web page.
- */
- function runInliner() {
- const done = this.async();
- Inliner.html({
- relativeTo: "build/prod/",
- fileContent: grunt.file.read("build/prod/cyberchef.htm"),
- images: true,
- svgs: true,
- scripts: true,
- links: true,
- strict: true
- }, function(error, result) {
- if (error) {
- if (error instanceof Error) {
- done(error);
- } else {
- done(new Error(error));
- }
- } else {
- grunt.file.write("build/prod/cyberchef.htm", result);
- done(true);
- }
- });
- }
- grunt.initConfig({
- clean: {
- dev: ["build/dev/*"],
- prod: ["build/prod/*"],
- test: ["build/test/*"],
- node: ["build/node/*"],
- docs: ["docs/*", "!docs/*.conf.json", "!docs/*.ico"],
- },
- eslint: {
- options: {
- configFile: "./.eslintrc.json"
- },
- configs: ["Gruntfile.js"],
- core: ["src/core/**/*.js", "!src/core/lib/**/*"],
- web: ["src/web/**/*.js"],
- node: ["src/node/**/*.js"],
- tests: ["test/**/*.js"],
- },
- jsdoc: {
- options: {
- destination: "docs",
- template: "node_modules/ink-docstrap/template",
- recurse: true,
- readme: "./README.md",
- configure: "docs/jsdoc.conf.json"
- },
- all: {
- src: [
- "src/**/*.js",
- "!src/core/lib/**/*",
- ],
- }
- },
- accessibility: {
- options: {
- accessibilityLevel: "WCAG2A",
- verbose: false,
- ignore: [
- "WCAG2A.Principle1.Guideline1_3.1_3_1.H42.2"
- ]
- },
- test: {
- src: ["build/**/*.html"]
- }
- },
- webpack: {
- options: {
- plugins: [
- new webpack.ProvidePlugin({
- $: "jquery",
- jQuery: "jquery",
- moment: "moment-timezone"
- }),
- new webpack.BannerPlugin({
- banner: banner,
- raw: true,
- entryOnly: true
- }),
- new webpack.DefinePlugin({
- COMPILE_TIME: JSON.stringify(compileTime),
- COMPILE_MSG: JSON.stringify(grunt.option("compile-msg") || grunt.option("msg") || "")
- }),
- new ExtractTextPlugin("styles.css"),
- ],
- resolve: {
- alias: {
- jquery: "jquery/src/jquery"
- }
- },
- module: {
- rules: [
- {
- test: /\.js$/,
- exclude: /node_modules/,
- loader: "babel-loader?compact=false"
- },
- {
- test: /\.css$/,
- use: ExtractTextPlugin.extract({
- use: "css-loader?minimize"
- })
- },
- {
- test: /\.less$/,
- use: ExtractTextPlugin.extract({
- use: [
- { loader: "css-loader?minimize" },
- { loader: "less-loader" }
- ]
- })
- },
- {
- test: /\.(ico|eot|ttf|woff|woff2)$/,
- loader: "url-loader",
- options: {
- limit: 10000
- }
- },
- { // First party images are saved as files to be cached
- test: /\.(png|jpg|gif|svg)$/,
- exclude: /node_modules/,
- loader: "file-loader",
- options: {
- name: "images/[name].[ext]"
- }
- },
- { // Third party images are inlined
- test: /\.(png|jpg|gif|svg)$/,
- exclude: /web\/static/,
- loader: "url-loader",
- options: {
- limit: 10000
- }
- },
- ]
- },
- stats: {
- children: false,
- warningsFilter: /source-map/
- }
- },
- webDev: {
- target: "web",
- entry: "./src/web/index.js",
- output: {
- filename: "scripts.js",
- path: __dirname + "/build/dev"
- },
- plugins: [
- new HtmlWebpackPlugin({
- filename: "index.html",
- template: "./src/web/html/index.html",
- compileTime: compileTime
- })
- ],
- watch: true
- },
- webProd: {
- target: "web",
- entry: "./src/web/index.js",
- output: {
- filename: "scripts.js",
- path: __dirname + "/build/prod"
- },
- plugins: [
- new webpack.optimize.UglifyJsPlugin({
- compress: {
- "screw_ie8": true,
- "dead_code": true,
- "unused": true,
- "warnings": false
- },
- comments: false,
- }),
- new HtmlWebpackPlugin({ // Main version
- filename: "index.html",
- template: "./src/web/html/index.html",
- compileTime: compileTime,
- minify: {
- removeComments: true,
- collapseWhitespace: true,
- minifyJS: true,
- minifyCSS: true
- }
- }),
- new HtmlWebpackPlugin({ // Inline version
- filename: "cyberchef.htm",
- template: "./src/web/html/index.html",
- compileTime: compileTime,
- inline: true,
- minify: {
- removeComments: true,
- collapseWhitespace: true,
- minifyJS: true,
- minifyCSS: true
- }
- }),
- ]
- },
- tests: {
- target: "node",
- entry: "./test/index.js",
- output: {
- filename: "index.js",
- path: __dirname + "/build/test"
- }
- },
- node: {
- target: "node",
- entry: "./src/node/index.js",
- output: {
- filename: "CyberChef.js",
- path: __dirname + "/build/node",
- library: "CyberChef",
- libraryTarget: "commonjs2"
- }
- }
- },
- copy: {
- ghPages: {
- options: {
- process: function (content) {
- // Add Google Analytics code to index.html
- content = content.replace("</body></html>",
- grunt.file.read("src/web/static/ga.html") + "</body></html>");
- return grunt.template.process(content);
- }
- },
- src: "build/prod/index.html",
- dest: "build/prod/index.html"
- }
- },
- chmod: {
- build: {
- options: {
- mode: "755",
- },
- src: ["build/**/*", "build/"]
- },
- docs: {
- options: {
- mode: "755",
- },
- src: ["docs/**/*", "docs/"]
- }
- },
- exec: {
- repoSize: {
- command: [
- "git ls-files | wc -l | xargs printf '\n%b\ttracked files\n'",
- "du -hs | egrep -o '^[^\t]*' | xargs printf '%b\trepository size\n'"
- ].join(";"),
- stderr: false
- },
- cleanGit: {
- command: "git gc --prune=now --aggressive"
- },
- },
- execute: {
- test: "build/test/index.js"
- },
- });
- };
|