Source

tools/hooks/useEnvironmentCheck.ts

/**
 * @typedef
 */
type EnvironmentCheckReturn = {
    /**
     * Whether we are currently in Production mode
     */
    prod: boolean
    /**
     * Whether we are currently in Development mode
     */
    dev: boolean
}

//TODO: JSDOC this hook
/**
 * Custom hook for providing the environment value for the current app context.
 *
 * The hook doesn't take any parameters and returns a set of booleans representing
 * which environment state we are in.
 *
 * The hook checks the `process.env.NODE_ENV` value to determine what the current environment is.
 *
 * Currently only two environments are supported: `prod` and `dev`
 *
 * ### Hook Usage
 *
 * #### Checking the current environment
 * ```
 * const {dev, prod} = useEnvironmentCheck()
 *
 * ...
 *
 * if (dev) console.log("we are in dev mode")
 * ```
 *
 * ### IMPORTANT NOTE
 *
 * The environment refers to Node's build environment, not JCU's app environment. This means that things on
 * [apps-test.jcu.edu.au]() are **PRODUCTION** when using this hook, because they are built and deployed using the
 * production flag in node.
 *
 * @category Hooks
 * @module useEnvironmentCheck
 * @return {EnvironmentCheckReturn}
 */
export function useEnvironmentCheck() : EnvironmentCheckReturn {

    let prod = process.env?.NODE_ENV === 'production'
    let dev = process.env?.NODE_ENV === 'development'

    return {prod, dev}
}