/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements. See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership. The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License. You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied. See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

//To build dist/thrift.js, dist/thrift.min.js and doc/*
//run grunt at the command line in this directory.
//Prerequisites:
// Node Setup -   nodejs.org
// Grunt Setup -  npm install  //reads the ./package.json and installs project dependencies
// Run grunt -    npx grunt  // uses project-local installed version of grunt (from package.json)

module.exports = function (grunt) {
  "use strict";

  grunt.initConfig({
    pkg: grunt.file.readJSON("package.json"),
    concat: {
      options: {
        separator: ";",
      },
      dist: {
        src: ["src/**/*.js"],
        dest: "dist/<%= pkg.name %>.js",
      },
    },
    shell: {
      InstallThriftJS: {
        command:
          "mkdir -p test/build/ts/lib; cp ../js/src/thrift.js test/build/ts/thrift.js",
      },
      InstallThriftNodeJSDep: {
        command: "cd ../..; npm install",
      },
      InstallTestLibs: {
        command: "cd test; ant download_jslibs",
      },
      ThriftGen: {
        command: [
          "mkdir -p test/gen-js",
          "../../compiler/cpp/thrift -gen js:ts --out test/gen-js ../../test/v0.16/ThriftTest.thrift",
          "mkdir -p test/gen-nodejs",
          "../../compiler/cpp/thrift -gen js:node,ts --out test/gen-nodejs ../../test/v0.16/ThriftTest.thrift",
        ].join(" && "),
      },
      ThriftBrowserifyNodeInt64: {
        command: [
          "./node_modules/browserify/bin/cmd.js ./node_modules/node-int64/Int64.js -s Int64 -o test/build/js/lib/Int64.js",
          "./node_modules/browserify/bin/cmd.js ../nodejs/lib/thrift/int64_util.js -s Int64Util -o test/build/js/lib/Int64Util.js",
          "./node_modules/browserify/bin/cmd.js ./node_modules/json-int64/index.js -s JSONInt64 -o test/build/js/lib/JSONInt64.js",
        ].join(" && "),
      },
      ThriftGenInt64: {
        command:
          "../../compiler/cpp/thrift -gen js:ts -o test ../../test/Int64Test.thrift",
      },
      ThriftTestServer: {
        options: {
          async: true,
          execOptions: {
            cwd: "./test",
            env: { NODE_PATH: "../../nodejs/lib:../../../node_modules" },
          },
        },
        command: "node server_http.js",
      },
      BuildTS: {
        options: {
          execOptions: {
            cwd: "./test",
          },
        },
        command:
          "../node_modules/typescript/bin/tsc --listFiles --outDir build/ts",
      },
      BrowserifyCompiledTS: {
        command: [
          "./node_modules/browserify/bin/cmd.js test/build/ts/test.js -o test/build/ts/lib/test.js --standalone test",
          "./node_modules/browserify/bin/cmd.js test/build/ts/test-int64.js -o test/build/ts/lib/test-int64.js --standalone testInt64",
        ].join(" && "),
      },
      InstallGeneratedCode: {
        command: [
          "mkdir -p test/build/ts",
          "cp -r test/gen-js test/build/ts",
        ].join(" && "),
      },
    },
    qunit: {
      ThriftJS: {
        options: {
          urls: ["http://localhost:8089/test.html"],
          puppeteer: {
            headless: true,
            args: ["--no-sandbox"],
          },
        },
      },
      ThriftJS_Int64: {
        options: {
          urls: ["http://localhost:8089/test-int64.html"],
          puppeteer: {
            headless: true,
            args: ["--no-sandbox"],
            ignoreHTTPSErrors: true,
          },
        },
      },
    },
    jshint: {
      // The main Thrift library file. not es6 yet :(
      lib: {
        src: ["../js/src/**/*.js"],
      },
      // The test files use es6
      test: {
        src: ["Gruntfile.js", "test/*.js"],
        options: {
          esversion: 6,
        },
      },
      gen_js_code: {
        src: ["test/gen-js/*.js"],
      },
      gen_node_code: {
        src: ["test/gen-nodejs/*.js"],
        options: {
          node: true,
        },
      },
    },
  });

  grunt.loadNpmTasks("grunt-contrib-jshint");
  grunt.loadNpmTasks("grunt-contrib-qunit");
  grunt.loadNpmTasks("grunt-shell-spawn");

  grunt.registerTask(
    "wait",
    "Wait just one second for the server to start",
    function () {
      var done = this.async();
      setTimeout(function () {
        done(true);
      }, 1000);
    },
  );

  grunt.registerTask("installAndGenerate", [
    "shell:InstallThriftJS",
    "shell:InstallThriftNodeJSDep",
    "shell:ThriftGen",
    "shell:ThriftBrowserifyNodeInt64",
    "shell:ThriftGenInt64",
    "shell:InstallTestLibs",
    "shell:BuildTS",
    "shell:InstallGeneratedCode",
    "shell:BrowserifyCompiledTS",
  ]);

  grunt.registerTask("test", [
    "installAndGenerate",
    "jshint",
    "shell:ThriftTestServer",
    "wait",
    "qunit:ThriftJS",
    "qunit:ThriftJS_Int64",
    "shell:ThriftTestServer:kill",
  ]);
  grunt.registerTask("default", ["test"]);
};
