#!/usr/bin/env node
var path = require('path')
var saguiPath = path.join(__dirname, '..')

console.log('ENVIRONMENT', process.env)

function exec (command, cwd) {
  // pass the parent´s stdio to the child process
  // http://stackoverflow.com/a/31104898
  require('child_process').execSync(command, { cwd: cwd, stdio: [0, 1, 2] })
}

function createTempFolder () {
  return require('tmp').dirSync().name
}

if (process.env.TEST_TYPE === 'lint_and_test_unit') {
  exec('npm run test:lint', saguiPath)
  exec('npm run test:unit', saguiPath)
}

if (process.env.TEST_TYPE === 'integration_test') {
  exec('npm run test:integration', saguiPath)
}

if (process.env.TEST_TYPE === 'test_create_project_npm') {
  // # builds Sagui before installing
  exec('npm run build', saguiPath)

  var npmProjectPath = createTempFolder()

  // # Create a new project and install Sagui
  exec('npm init -y .', npmProjectPath)
  exec('npm install --save-dev file://' + saguiPath, npmProjectPath)

  // # Run some basic scripts
  exec('npm test', npmProjectPath)
  exec('npm run test:lint', npmProjectPath)
  exec('npm run build', npmProjectPath)
  exec('npm run dist', npmProjectPath)
  exec('npm run format', npmProjectPath)
}

if (process.env.TEST_TYPE === 'test_create_project_yarn') {
  // # builds Sagui before installing
  exec('npm run build', saguiPath)

  var yarnProjectPath = createTempFolder()

  // # Create a new project and install Sagui
  exec('yarn init -y .', yarnProjectPath)
  exec('yarn add --dev file://' + saguiPath, yarnProjectPath)

  // # Run some basic scripts
  exec('yarn test', yarnProjectPath)
  exec('yarn run test:lint', yarnProjectPath)
  exec('yarn run build', yarnProjectPath)
  exec('yarn run dist', yarnProjectPath)
  exec('yarn run format', yarnProjectPath)
}

@@ -82,16 +82,124 @@
 e, '..')
+%0Avar version = require('../package.json').version%0Avar tgzFile = path.join(saguiPath, %60sagui-$%7Bversion%7D.tgz%60)
 %0A%0Aconsol
@@ -867,32 +867,51 @@
 ild', saguiPath)
+%0A  exec('npm pack')
 %0A%0A  var npmProje
@@ -1036,52 +1036,28 @@
 xec(
-'
+%60
 npm 
-install --save-dev file://' + saguiPath
+add $%7BtgzFile%7D%60
 , np
@@ -1431,24 +1431,43 @@
 , saguiPath)
+%0A  exec('npm pack')
 %0A%0A  var yarn
@@ -1591,25 +1591,25 @@
 ath)%0A  exec(
-'
+%60
 yarn add --d
@@ -1615,28 +1615,19 @@
 dev 
-file://' + saguiPath
+$%7BtgzFile%7D%60
 , ya

Use `npm pack` to create a testable package 🤴