setup.sh
Simply setup documentation configuration for the current folder.
Synopsis
./setup.sh [-u|--upgrade] [-s|--subrepo] [-h|--help] -r|--repo-url REPO_URL
Description
This script will install/upgrade set of scripts and files to create and manage documentation rendered using mkdocs.
If directory is already using mkdocs and user does not provide
-u|--upgrade options, an error will be shown and nothing will be done.
If user does not provide REPO_URL from which download the template, i.e.
using option -r|--repo-url REPO_URL, then an error will be prompt and
the script will exit.
Options
Available options are:
-
-u,--upgrade: Upgrade the current mkdocs documentation to the latest template version. -
-s,--subrepo: Specify the current repo is a subrepo that will be merge into another main project using mkdocs-monorepo plugin. -
-r,--repo-url: URL of the repo from which the template will be downloaded. -
-h,--help: Print this help.
main()
Setup folder to be able to use mkdocs documentation templates.
Check if git is installed. Then check that folder is not already using
mkdocs documentation.
If directory already set to use mkdocs documentation, then check if user explicitly tell to upgrade and upgrade, otherwise, print a warning and exit.
If directory not already set to use mkdocs documentation, clone user provided repo to a temporary folder, copy relevant scripts, files and folders to initiliaze a documentation rendered using mkdocs.
Globals
UPGRADESUBREPOREPO_URLMKDOCS_ROOTMKDOCS_TMPMKDOCS_CLONE_ROOTSCRIPT_FULL_PATH
Arguments
| Arguments | Description |
|---|---|
-u,--upgrade |
Arguments to explicitly upgrade the documentation |
-s,--subrepo |
Specify the current repo is a subrepo that will be merge into another main project using mkdocs-monorepo plugin. |
-r,--repo-url REPO_URL |
Arguments with the URL of the repo holding the template to setup/upgrade |
Output
- Log informations
Returns
- 0 if directory is correctly configure to start writing documentation
- 1 if something when wrong during the setup of documentation
manpage()
Extract the script documentation from header and print it on stdout.
Simply extract the docstring from the header of the script, format it with some output enhancement (such as bold), print it to stdout and exit.
Globals
SCRIPT_FULL_PATHOutput
- Help manpage from header docstring on stdout
Returns
- 0, always
mkdocs_log()
Print debug message in colors depending on message severity on stderr.
Echo colored log depending on user provided message severity. Message severity are associated to following color output:
DEBUGprint in the fifth color of the terminal (usually magenta)INFOprint in the second color of the terminal (usually green)WARNINGprint in the third color of the terminal (usually yellow)ERRORprint in the third color of the terminal (usually red)If no message severity is provided, severity will automatically be set to INFO.
Globals
ZSH_VERSIONMKDOCS_DEBUG_LEVELArguments
Arguments Description $1string, message severity or message content $@string, message content Output
- Colored log informations
check_git()
Ensure command
gitexists.Simply ensure the command
gitexists.Output
- Error message if commang
gitdoes not existsReturns
- 0 if
gitcommand exists- 1 if
gitcommand does not exist
clone_mkdocs_template_repo()
Clone repo mkdocs_template to a temporary folder.
Clone the repo mkdocs_template to a temporary folder using provided URL.
Globals
REPO_URLMKDOCS_ROOTMKDOCS_CLONE_ROOTMKDOCS_TMPOutput
- Log messages
Returns
- 0 if clone of repo went right
- 1 if clone of repo went wrong
check_upgrade()
Check if user specify to upgrade mkdocs documentation.
Check if user specify to upgrade mkdocs documentation from the mkdocs_template provided as repo URL. This is done by the use of option
-u|--upgrade.If user did not explicitly specify to upgrade, print a warning else, upgrade mkdocs documentation files.
Globals
UPGRADEOutput
- Warning messages.
Returns
- 0 if upgrade went right.
- 1 if user did not specify to upgrade or if upgrade went wrong.
upgrade_mkdocs_config_file()
Handle the upgrade of mkdocs.yml file.
Depending on the type of documentation, i.e.
SUBREPOset totrueorfalse.If
SUBREPOset totrue, this will updatemkdocs.local.ymlelse will updatemkdocs.ymlif needed.Globals
MKDOCS_ROOTMKDOCS_TMPSUBREPOArguments
Arguments Description $1string, absolute path to the latest file version to be installed $2string, absolute path to the location of the installation Output
- Log message
setup_mkdocs_config_file()
Handle the configuration of mkdocs.yml file.
Depending on the type of documentation, i.e.
SUBREPOset totrueorfalse.In the first case,
SUBREPOset totrue, will generate a basicmkdocs.ymlto be included with mkdocs monorepo plugins and put the full configuration tomkdocs.local.yml. Else,SUBREPOset tofalse, write directly the full configuration tomkdocs.yml.Globals
MKDOCS_ROOTSUBREPOArguments
Arguments Description $1string, absolute path to the latest file version to be installed $2string, absolute path to the location of the installation Output
- Log message
upgrade_file()
Upgrade latest version of script and files from mkdocs_template.
Check if latest version of file is different from the old version. If yes, then move the old version to
${MKDOCS_ROOT}/.oldthen upgrade to latest version.Globals
MKDOCS_ROOTMKDOCS_TMPArguments
Arguments Description $1string, absolute path to the latest file version to be installed $2string, absolute path to the location of the installation Output
- Log messages
setup_file()
Install latest version of script and files from mkdocs_template.
Simply install file provided as argument from the mkdocs_template temporary repo to the right place in the folder currently setup to use mkdocs documentation.
Globals
MKDOCS_ROOTArguments
Arguments Description $1string, absolute path to the latest file version to be installed $2string, absolute path to the location of the installation Output
- Log messages
build_file_list()
Recursively build a list of file from provided folder
Recursively build a list of file from provided folder and store such list in a temporary bash array that must be set in parent method.
Arguments
Arguments Description $1string, absolute path to the folder which will be parsed
build_final_file_list()
Build the merged list from
templatesanduser_configfolder.If there is the same file in
user_configandtemplatesfolder, then replace the file to be installed fromtemplatesby the one inuser_config. Finally, add remaininguser_configfiles not intemplatesto the list of files to install or upgrade in a bash array set in parent method.Globals
MKDOCS_ROOT
setup_mkdocs()
Recursively install base folder and script to write mkdocs documentation.
Build the list of files and folders, recursively copy all files to their right location from the temporary cloned repo to the folder which will host the mkdocs documentation.
Globals
MKDOCS_ROOTMKDOCS_CLONE_ROOTOutput
- Log message