Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
@skava/bs / src / scripts / utils.ts
Size: Mime:
import { execSync } from 'child_process'
import colors from 'colors/safe'
import { config } from '@skava/di'
import { resolveToRoot } from '../config/resolveToRoot'

const appRootDir = config.get('appRootDir')
let erroring = false

// @lint scripts
// eslint-disable-next-line
function log(options) {
  const { message, notify } = options
  const title = options.title.toUpperCase()
  const level = options.level || 'info'
  const msg = `==> ${title} -> ${message}`

  if (notify) {
    // same error, no spam popups
    if (erroring !== message) {
      // prevents spam notifications for warnings
      if (level === 'error' && message.toLowerCase().includes('error')) {
        erroring = message
        // console.log({ [title]: message })
        // notifier.notify({
        //   title,
        //   message,
        // })
      }
      // onsole.log({ [title]: message })
      // notifier.notify({
      //   title,
      //   message,
      // })
    }
    if (level !== 'error') {
      console.log({ [title]: message })
      // notifier.notify({
      //   title,
      //   message,
      // })
    }
  }

  switch (level) {
    case 'warn':
      console.log(colors.yellow(msg))
      break
    case 'error':
      console.log(colors.bgRed.white(msg))
      break
    case 'info':
    default:
      console.log(colors.green(msg))
  }
}

function exec(command: string): void {
  execSync(command, { stdio: 'inherit', cwd: appRootDir })
}

function toDefaultBuildPath() {
  // @todo make sure perf outweighs
  // assumption is the extra HMR files add overhead
  // but deleting the current output file may add bigger overhead
  // @todo probably use jet-fs to delete all matching glob except (index|main).js
  const buildOutputPath = resolveToRoot(process.env.BUILD_CONFIG_OUTPUT_PATH)
  return buildOutputPath
}

function deleteDist(buildOutputPath = toDefaultBuildPath()) {
  // First clear the build output dir.
  try {
    exec(`yarn run rimraf ${buildOutputPath}`)
  } catch (subprocessException) {
    console.log({ subprocessException })
  }
}

export { deleteDist, exec, log }