import R from "ramda"
import {initialAuthenticate, runServer, publishBlock} from "./utils"
import {isAuthenticated} from "./services/github"
import {start} from "./wizard"

const entry = async () => {
  initialAuthenticate()
  await R.cond([
    [() => process.env.WM_SANDBOX_MODE === `server`, runServer],
    [
      () => process.env.WM_SANDBOX_MODE === `server-editor`,
      R.pipe(R.partial(runServer, [{type: `editor-version`}])),
    ],
    [() => isAuthenticated && process.env.WM_SANDBOX_MODE === `publish`, publishBlock],
    [R.T, start],
  ])()
}

entry()
  .then(() => {
    // process.exit(0)
  })
  .catch((error) => {
    console.log(error)
    process.exit(42)
  })
