const fs = require("fs")
const path = require("path")
const ora = require("ora")
const { execSync } = require("child_process")

const BUILD_DIR = path.resolve("build/packages")
const EXAMPLES_DIR = path.resolve("examples")

function listDirs(dir) {
  return fs
    .readdirSync(dir)
    .filter(dirname => fs.lstatSync(path.join(dir, dirname)).isDirectory())
}

function linkDependencies(example) {
  const spinner = ora("Linking " + example)
  const dependencies = packages.map(name => `@lingui/${name}`).join(" ")
  execSync("yalc link " + dependencies, {
    cwd: path.join(EXAMPLES_DIR, example)
  })
  spinner.succeed()
}

function linkPackage(packageName) {
  execSync("yalc publish", { cwd: path.join(BUILD_DIR, packageName) })
}

const packages = listDirs(BUILD_DIR)
const examples = listDirs(EXAMPLES_DIR)

packages.forEach(linkPackage)
examples.forEach(linkDependencies)

@@ -51,35 +51,8 @@
 h%22)%0A
-const ora = require(%22ora%22)%0A
 cons
@@ -375,23 +375,15 @@
 cons
-t spinner = ora
+ole.log
 (%22Li
@@ -567,28 +567,8 @@
  %7D)%0A
-  spinner.succeed()%0A
 %7D%0A%0Af

remove ora from setup script for intergration tests