HardHat [ for Win & Mac ]

December 14, 2022 · View on GitHub

github-actions-build github-actions-release sonar-reliability sonar-security sonar-maintainability license

HardHat

HardHat was created to simplify and automate tasks related to Android development with help of ToolBox and Colorify libraries.

Previously had created the same app making a Batch (for Windows) and a Bash (for macOS) scripts to make the task, maintain both of them is a hard task to do, but now with .Net Core can use and share the same code on both Operating Systems.

I don't like repetitive tasks and make a build is one of them... yuck!

Why we need automation?

The Code is Dark and Full of Errors! Console is your friend ... don't be afraid!


Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.

Prerequisites

What things do you need to install?

It's recommended install it using a Package Manager.

OSInstructions
winChocolatey
macBrew and SDK Man

Installing

Follow these steps to install on your local machine

Clone HardHat from GitHub on recommended path. Using this command on terminal:

OSCommand
wingit clone -b win https://github.com/deinsoftware/hardhat.git "D:\Applications\HardHat"
macgit clone -b mac https://github.com/deinsoftware/hardhat.git ~/Applications/HardHat/

Environment Variables

Environment variables are, in short, variables that describe the environment in which programs run in.

Please verify that you have been configured all correctly. Paths in descriptions are examples (recommended) but use your own paths.

Environment for Windows

vardescription
ANDROID_SDK_ROOTC:\Android\android-sdk
ANDROID_HOME%ANDROID_SDK_ROOT%
ANDROID_NDK_HOME%ANDROID_SDK_ROOT%\ndk-bundle
ANDROID_BT_VERSION28.0.3
ANDROID_PROPERTIESD:\Applications\Android\Properties
CHOCO_HOMEC:\ProgramData\chocolatey
CODE_HOMEC:\Program Files\Microsoft VS Code
GIT_HOMEC:\Program Files\Git
GRADLE_HOME%CHOCO_HOME%
LFS_HOMEC:\Program Files\Git LFS
JAVA_HOMEC:\Program Files\Java\jdk1.8.0_221
MYSQL_HOMEC:\tools\mysql\mysql-5.7.18-winx64
NPM_HOMEC:\Program Files\nodejs
VPN_HOMEC:\Program Files (x86)\CheckPoint\Endpoint Connect
SIGCHECK_HOME%CHOCO_HOME%
SONAR_QUBE_HOMED:\Applications\Sonar\Qube
SONAR_SCANNER_HOME%CHOCO_HOME%\lib\sonarqube-scanner.portable\tools\sonar-scanner-3.3.0.1492-windows
TASK_PROJECTD:\Applications\Task
PATH%ANDROID_SDK_ROOT%\build-tools\%ANDROID_BT_VERSION%;
%ANDROID_SDK_ROOT%\platform-tools;
%ANDROID_SDK_ROOT%\platform-tools\bin;
%ANDROID_SDK_ROOT%\tools;
%CODE_HOME%\bin;
%GIT_HOME%\cmd;
%GRADLE_HOME%\bin;
%JAVA_HOME%\bin;
%LFS_HOME%\bin;
%MYSQL_HOME%\bin;
%NPM_HOME%;
%SIGCHECK_HOME%\bin;
%SONAR_QUBE_HOME%\bin\windows-x86-64;
%SONAR_SCANNER_HOME%\bin;
C:\ProgramData\Oracle\Java\javapath;

On Windows need replace ANDROID_BT_VERSION manually with your Android SDK Build Tool version (recommended use the last one).

Where are environment variables? In the System Properties window, click on the Advanced tab, then click the Environment Variables button near the bottom of that tab. In the Environment Variables window, highlight the Path variable in the "System variables" section and click the Edit button.

Environment for macOS

export ANDROID_SDK_ROOT="/usr/local/share/android-sdk"
export ANDROID_HOME="$ANDROID_SDK_ROOT"
export ANDROID_NDK_HOME="$ANDROID_SDK_ROOT/ndk-bundle"
export ANDROID_BT_VERSION="$(ls -tr $ANDROID_SDK_ROOT/build-tools | sort | tail -1)"
export ANDROID_PROPERTIES="~/Applications/Android/Properties"
export GIT_HOME="/usr/local/bin/git"
export GRADLE_HOME="/usr/local/bin/gradle"
export JAVA_HOME="$(/usr/libexec/java_home -v 1.8)"
export POSTGRESQL_HOME="/usr/local/opt/postgresql"
export SONAR_QUBE_HOME="~/Applications/Sonar/Qube"
export SONAR_SCANNER_HOME="~/Applications/Sonar/Scanner"
export TASK_PROJECT="~/Applications/Task"

export PATH="/opt/local/bin:/opt/local/sbin:/usr/local/sbin:$PATH"
export PATH="$ANDROID_SDK_ROOT/bin:$PATH"
export PATH="$ANDROID_SDK_ROOT/build-tools/$ANDROID_BT_VERSION:$PATH"
export PATH="$ANDROID_SDK_ROOT/platform-tools:$PATH"
export PATH="$ANDROID_SDK_ROOT/tools:$PATH"
export PATH="$ANDROID_NDK_HOME/:$PATH"
export PATH="$SONAR_QUBE_HOME/bin/macosx-universal-64:$PATH"
export PATH="$SONAR_SCANNER_HOME/bin:$PATH"

export PATH="$POSTGRESQL_HOME/bin:$PATH"
export LDFLAGS="-L$POSTGRESQL_HOME/lib"
export CPPFLAGS="-I$POSTGRESQL_HOME/include"

alias hh="sh ~/Applications/HardHat/mac.sh"
alias x="exit"
alias sb="source ~/.bash_profile"

On macOS ANDROID_BT_VERSION automatically take the last Android SDK Build Tool version. But you can modify it and choose the version that you want. Skip GRADLE_HOME and JAVA_HOME if you install these libraries with SDKMan.

With HardHat alias, you can open it the application directly from a terminal window using the command hh and RETURN key.

Where are environment variables? First, one thing to recognize about OS X is that it is built on Unix. This is where the .bash_profile comes in. When you start the Terminal app in OS X you get a bash shell by default. The bash shell comes from Unix and when it loads it runs the .bash_profile script. You can modify this script for your user to change your settings. This file is located at: ~/.bash_profile

Highly recommend auto-close option in combination with exit alias. It can be a useful combination to finish and close those unused terminals. Even to exit HardHat and close automatically his terminal window.

Recommended terminal configurations on macOS? Open a terminal window, go to 'Preference > Profiles. Auto close terminal on exit: Inside 'Shell' tab, select "Close if the shell exited cleanly" on "When the shell exits" option. Enable Numpad keys: Inside 'Advance' tab, deselect (turn off) "Allow VT100 application keypad mode" option.

Back to menu


Usage

Keep calm, you are almost done. Review these final steps and enjoy life, no more tedious and repetitive tasks stealing your precious time.

Permissions

macOS users need add execute permission over some files. Open a terminal on installation path ~/Applications/HardHat/recommended and run this commands:

  • chmod +x mac.sh
  • chmod +x mac.command
  • chmod +x cmd.sh
  • chmod +x HardHat

Run

In order to run HardHat open a terminal and run this command:

OSPathCommand
win"D:\Applications\HardHat"win.bat
mac~/Applications/HardHat/sh mac.sh

Start Menu Icon

It's not mandatory but it's highly recommend create and Start Menu icon. This instructions only works with recommended path.

Star Menu for Windows

Use this commands on terminal (as Admin) to add an icon on your start menu:

:: Make Dir
md "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Android"
:: Copy Shortcut
cd /d "D:\Applications\HardHat\"
xcopy "HardHat.lnk" "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Android"

Open star menu and over the Android section you will can see the link. Remember mark with 'pin to start' option if you are using Win10.

Star Menu for macOS

Copy the icon.png content on the Clipboard. One way to do this is to open the picture in Preview, choose Edit > Select All, then choose Edit > Copy or press Command-C.

Select mac.command file, then choose File > Get Info. At the top of the Info window, click the picture of the icon to select it, then choose Edit > Paste or press Command-V.

Select mac.command file, then choose File > Make Alias or press Command-L name it as Hard Hat (with blank space between).

Just drag and drop Hard Hat (alias shortcut) to your Dock or Desktop.

Keyboard Shortcuts

Choose the desired letter combination and let HardHat work for you.

Project

combinationaction
pSelect a project inside path.dir/bsn/prd path (see Setup > Path Variables section) that starts with flt folder name. This project required to have an android.prj folder inside.
pfSelect an APK file generated inside selected project on android.bld path with android.ext extension name (see Setup > Android Variables section).
poOpen selected project in File Explorer.
po-bOpen Android build path from selected project in File Explorer.
peOpen selected project on Editor. (see Usage > Configuration > Other Variable section).
piInstall selected file on an Android device.
ppShow path and full path about selected file. Copy this paths to clipboard.
pvShow full information, values, signature and hash about selected file.
Editor
combinationactionpath
pe>aAndroid Studio. *project/android
pe>cVisual Studio Code.project
pe>sSublime Text 3.project
pe>wWeb Storm. *project
pe>xXcodeproject/ios

* Requires enable Tools -> Create Command-line Launcher and works only for Linux / macOS.

Path
combinationaction
pp>pCopy project path to clipboard.
pp>fCopy file path to clipboard.
pp>mCopy mapping file path to clipboard.
pp>dDuplicate and rename selected file.
pp>cCompress selected file.

Git

combinationaction
gShow current GIT branch.
gdDiscard files. Launch reset command over selected project.
gpPull files. Launch pull command over selected project.
gcClean files. Launch clean command over selected project and delete unversioned files over selected project.
gd+pDiscard and Pull files over selected project.
gr+pClean and Pull files over selected project.
goDiscard, Clean and Pull (x2) files over selected project.

Task

combinationaction
tTask paths, Server and Log configuration.
twLaunch gulp watch command over selected project to TASK_PROJECT.
tmLaunch gulp make command over selected project to TASK_PROJECT.
toMake a copy of project files (with an additional backup) and launch gulp obfuscate command over selected project to TASK_PROJECT. Lite type by default.
to-lLaunch gulp obfuscate --type lite command on selected files.
to-cLaunch gulp obfuscate --type complete command on all JS and CSS files.
trRevert original files to selected project.
ttLaunch gulp test command over selected project to TASK_PROJECT. Start server according to previous configuration.
tsLaunch gulp server command over selected project to TASK_PROJECT. Start server according to previous configuration.
tkRun kill gulp command.
tlLaunch gulp log command over selected project to TASK_PROJECT.

See Environment Variables section for TASK_PROJECT configuration.

Path Configuration
combinationaction
t>pwWeb Server path with configurations.
t>plLog path with configurations.
t>peExtension name for configurations.
Server (Web/Log) Configuration
combinationaction
t>siInternal Path inside server configuration.
t>scConfiguration file with web server configuration.
t>sfFlavor.
t>snNumber.
t>ssSync Browser on save.
t>spOpen shortcut in browser at start.
Quick Server Configuration
combinationoptionvalue
t>f:dFlavordev
t>f:qFlavorqa
t>f:rFlavordrc
t>f:mFlavormnto
t>f:vFlavorvsrv
t>f:pFlavorprod
t>n:1Number1
t>n:2Number2
t>n:3Number3
t>n:4Number4
t>n:5Number5
t>n:8Number8
t>n:8Number9
t>n:8Number10
t>n:8Number11
Test Server Configuration
combinationaction
t>tsSync Browser on save.
t>tcCoverage Path inside server configuration.

Build

combinationaction
bConfigure your build type, flavor and dimensions.
b>tType shortcut inside build configuration. This value can be empty.
b>dDimension shortcut inside build configuration. This value can be empty.
b>fFlavor shortcut inside build configuration. This value can be empty.
b>mMode shortcut inside build configuration. This value can be empty.
biInstall NPM packages configured on packages.json.
bpCopy pre-configured files inside ANDROID_PROPERTIES (see Environment Variables section) folder and copy inside android.prj folder in selected project (see Setup > Android Variables section).
bcMake clean project with gradle command line.
bc-cMake cleanBuildCache project with gradle command line.
bgMake build project with gradle command line.

If you have some pre-configured files to be copied to the project path, add it on the ANDROID_PROPERTIES path (see Environment Variables section) inside a Business folder. Files like:

  • local.properties
  • gradle.properties
  • keystore/development.properties
  • keystore/production.properties
Quick Build Configuration
combinationoptionvalue
b>t:aTypeassemble
b>t:bTypebundle
b>f:dFlavordev
b>f:qFlavorqa
b>f:rFlavordrc
b>f:mFlavormnto
b>f:vFlavorvsrv
b>f:pFlavorprod
b>m:dModeDebug
b>m:sModeStag
b>m:rModeRelease

Sonar

combinationaction
sSelect and show Sonar configuration.
s>pProtocol shortcut inside server configuration.
s>sServer shortcut inside server configuration.
s>sdDomain shortcut inside server configuration.
s>spPort shortcut inside server configuration.
s>iInternal Path shortcut inside server configuration.
sqStarts sonar server over SONAR_QUBE_HOME (see Environment Variables section)
ssLaunch sonar-scanner over SONAR_SCANNER_HOME (see Environment Variables section) inside selected project or his internal path.
sbOpen sonar configuration on browser.

Android Debug Bridge

combinationaction
adShow device/emulator list.
arKill and Restart ADB server.
adMake ADB launch logcat.
awMake a ADB device dis/connection over Wifi.
aw>iIP shortcut inside wireless configuration.
aw>pPort shortcut inside wireless configuration.
aw>cConnect IP shortcut inside wireless configuration.
asShow device via ADB.

Extra

combinationaction
cConfiguration.
iShow information about commands version.
eShow information about environmental variables.
xExit application, save progress and close terminal window.
!Repeat previous option.

Configuration

Choose c Configuration option on main menu and set the values.

Main Path

combinationaction
mdDevelopment path
mwChoose workspace folder inside development path.
mpProjects folder name inside workspace folder path.
mfFilter name for project listing.

Android Path

combinationaction
apAndroid folder path inside project
abBuild folder path inside android project.
aeExtension name for android application.
acHybrid folder to be processed with Tasks (Uglify & Minify).
afFilter extension name for files to be processed.

Other Variables

combinationaction
eCommand to open editor.
vVPN Site Name (only for Windows).
tTheme chooser.
lEnable or disable log on exceptions.

Recommendations

Highly recommend this file and directory structure:

Developer
├── Workspace1
│   └── Projects
│       ├── _devBranch_1
│       │   ├── android
│       │   ├── ios
│       │   └── web
│       ├── _devBranch_2
│       │   ├── android
│       │   ├── ios
│       │   └── web
│       ├── _devBranch_3
│       │   └── ...
│       ├── _devBranch_n
│       │   └── ...
│       └── _distProject
│           ├── android
│           ├── ios
│           └── web
├── Workspace2
│   └── ...
├── WorkspaceN
│   └── ...

Applications
├── Android
│   ├── Gradle
│   ├── Keystore
│   │   ├── Workspace1
│   │   │   ├── dev.jks
│   │   │   └── prd.jks
│   │   ├── Workspace1_Flavor1
│   │   │   └── ...
│   │   ├── Workspace1_Flavor2
│   │   │   └── ...
│   │   ├── Workspace2
│   │   │   └── ...
│   │   └── WorkspaceN
│   │       └── ...
│   ├── PlayStore
│   ├── SDK
│   └── Properties
│       ├── Workspace1
│       │   ├── gradle.properties
│       │   ├── local.properties
|       │   └── Keystore
│       │       ├── development.properties
│       │       └── production.properties
│       ├── Workspace1_Flavor1
│       │   └── ...
│       ├── Workspace1_Flavor2
│       │   └── ...
│       ├── Workspace2
│       │   └── ...
│       └── WorkspaceN
│           └── ...
├── Task
├── HardHat
└── Sonar
    ├── Qube
    └── Scanner

Back to menu


About

Built With

  • .Net Core - ASP.NET Core is a free and open-source web framework, and the next generation of ASP.NET, developed by Microsoft and the community.
  • VS Code - Code editing redefined.
  • SonarQube - Continuous code quality.

Contributing

Please read CONTRIBUTING for details on our code of conduct, and the process for submitting pull requests to us.

Versioning

We use SemVer for versioning. For the versions available, see the HardHat on GitHub.

Authors

See also the list of contributors who participated in this project.

Sponsors

If this project help you reduce time to develop, you can give me a cup of coffee.

GitHub Sponsors paypal

No sponsors yet! Will you be the first?

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments

  • StackOverflow: The largest online community for programmers.
  • XKCD: A web comic of romance, sarcasm, math and language... for making his font available.

Back to menu