tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

create-command.sh (3435B)


      1 #!/bin/bash
      2 
      3 # Script to easily create a new command, including:
      4 # - a template for the main command file
      5 # - test folder and test head.js file
      6 # - a template for a first test
      7 # - all necessary build manifests
      8 
      9 if [[ -z $1 || -z $2 ]]; then
     10  echo "$0 expects two arguments:"
     11  echo "$(basename $0) command-file-name CommandName"
     12  echo " 1) The file name for the command, with '-' as separators between words"
     13  echo "    This will be the name of the folder"
     14  echo " 2) The command name being caml cased"
     15  echo "    This will be used to craft the name of the JavaScript class"
     16  exit
     17 fi
     18 
     19 if [ -e $1 ]; then
     20  echo "$1 already exists. Please use a new folder/command name."
     21 fi
     22 
     23 CMD_FOLDER=$1
     24 CMD_FILE_NAME=$1-command.js
     25 CMD_NAME=$2Command
     26 
     27 pushd `dirname $0`
     28 
     29 echo "Creating a new command called '$CMD_NAME' in $CMD_FOLDER"
     30 
     31 mkdir $CMD_FOLDER
     32 
     33 cat > $CMD_FOLDER/moz.build <<EOF
     34 # This Source Code Form is subject to the terms of the Mozilla Public
     35 # License, v. 2.0. If a copy of the MPL was not distributed with this
     36 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
     37 
     38 DevToolsModules(
     39    "$CMD_FILE_NAME",
     40 )
     41 
     42 if CONFIG["MOZ_BUILD_APP"] != "mobile/android":
     43    BROWSER_CHROME_MANIFESTS += ["tests/browser.toml"]
     44 EOF
     45 
     46 cat > $CMD_FOLDER/$CMD_FILE_NAME <<EOF
     47 /* This Source Code Form is subject to the terms of the Mozilla Public
     48 * License, v. 2.0. If a copy of the MPL was not distributed with this
     49 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     50 
     51 "use strict";
     52 
     53 /**
     54 * The $CMD_NAME ...
     55 */
     56 class $CMD_NAME {
     57  constructor({ commands, descriptorFront, watcherFront }) {
     58    this.#commands = commands;
     59  }
     60  #commands = null;
     61 
     62 }
     63 
     64 module.exports = $CMD_NAME;
     65 EOF
     66 
     67 mkdir $CMD_FOLDER/tests
     68 cat > $CMD_FOLDER/tests/browser.toml <<EOF
     69 [DEFAULT]
     70 tags = "devtools"
     71 subsuite = "devtools"
     72 support-files = [
     73  "!/devtools/client/shared/test/shared-head.js",
     74  "head.js",
     75 ]
     76 
     77 ["browser_$1.js"]
     78 EOF
     79 
     80 
     81 cat > $CMD_FOLDER/tests/head.js <<EOF
     82 /* This Source Code Form is subject to the terms of the Mozilla Public
     83 * License, v. 2.0. If a copy of the MPL was not distributed with this
     84 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     85 
     86 "use strict";
     87 
     88 /* eslint no-unused-vars: [2, {"vars": "local"}] */
     89 
     90 Services.scriptloader.loadSubScript(
     91  "chrome://mochitests/content/browser/devtools/client/shared/test/shared-head.js",
     92  this
     93 );
     94 EOF
     95 
     96 CMD_NAME_FIRST_LOWERCASE=${CMD_NAME,}
     97 cat > $CMD_FOLDER/tests/browser_$1.js <<EOF
     98 /* Any copyright is dedicated to the Public Domain.
     99   http://creativecommons.org/publicdomain/zero/1.0/ */
    100 
    101 "use strict";
    102 
    103 // Test the $CMD_NAME
    104 
    105 add_task(async function () {
    106  info("Setup the test page");
    107  const tab = await addTab("data:text/html;charset=utf-8,Test page");
    108 
    109  info("Create a target list for a tab target");
    110  const commands = await CommandsFactory.forTab(tab);
    111  await commands.targetCommand.startListening();
    112 
    113  const { $CMD_NAME_FIRST_LOWERCASE } = commands;
    114 
    115  // assertions...
    116 
    117  await commands.destroy();
    118  BrowserTestUtils.removeTab(tab);
    119 });
    120 EOF
    121 
    122 popd
    123 
    124 echo ""
    125 echo "Command created!"
    126 echo ""
    127 echo "Now:"
    128 echo " - edit moz.build to add '\"$CMD_FOLDER\",' in DIRS (this need to be kept sorted)"
    129 echo " - edit index.js to add '$CMD_NAME_FIRST_LOWERCASE: \"devtools/shared/commands/$CMD_FOLDER/$1-command\"' in Commands dictionary"
    130 echo " - edit eslint-test-paths.config.mjs to add \"devtools/shared/commands/$CMD_FOLDER/tests/\" to the extraBrowserTestPaths array"