UNPKG

yini-cli

Version:

CLI for parsing and validating YINI config files: type-safe values, nested sections, comments, minimal syntax noise, and optional strict mode.

54 lines (53 loc) 2.35 kB
const localNodeEnv = (process.env.NODE_ENV || 'production'); const localAppEnv = (process.env.APP_ENV || 'production'); // export const initEnvs = () => { // const localNodeEnv = (process.env.NODE_ENV || 'production') as TNodeEnv // const localAppEnv = (process.env?.APP_ENV || 'production') as TAppEnv // return { localNodeEnv, localAppEnv } // } // const { localNodeEnv, localAppEnv } = initEnvs() /** Are we running in the environment "development"? Will be based on the (global) environment variable process.env.NODE_ENV. */ export const isDevEnv = () => localNodeEnv === 'development'; /** Are we running in the environment "production"? Will be based on the (global) environment variable process.env.NODE_ENV. */ export const isProdEnv = () => localNodeEnv === 'production'; /** Are we running in the environment "test"? Will be based on the (global) variable process.env.NODE_ENV. */ export const isTestEnv = () => localNodeEnv === 'test'; /** Will be based on the local argument when this process was launched. * @returns True if the DEV flag is set. * @example npm run start -- isDev=1 * @example node dist/index.js isDev=1 */ export const isDev = () => { const len = process.argv.length; // NOTE: We will start with index 2, since the first element will be // execPath. The second element will be the path to the // JavaScript file being executed. for (let i = 2; i < len; i++) { const val = process.argv[i] || ''; if (val.toLowerCase() === 'isdev=1' || val.toLowerCase() === 'isdev=true') { return true; } } return false; }; /** Will be based on the local argument when this process was launched. * @returns True if the DEBUG flag is set. * @example npm run start -- isDebug=1 * @example node dist/index.js isDebug=1 */ export const isDebug = () => { const len = process.argv.length; // NOTE: We will start with index 2, since the first element will be // execPath. The second element will be the path to the // JavaScript file being executed. for (let i = 2; i < len; i++) { const val = process.argv[i] || ''; if (val.toLowerCase() === 'isdebug=1' || val.toLowerCase() === 'isdebug=true') { return true; } } return false; }; export { localNodeEnv, localAppEnv };