'use strict';

const tools = require('../../scripts/utils/tools');
const path = require('path');

const composerpath = path.resolve(process.cwd(), '../myapp-web-rest/');

Promise.resolve()
  .then(() => {
    tools.logTitle(`COMPOSER`);
    return tools.runScript('composer install', composerpath);
  })
  .then(() => { // composer install
    tools.logTitle(`CREATE DB`);
    return tools.runScript('php bin/console doctrine:database:create --if-not-exists', composerpath);
  })
  .then(() => { // Create a new DB
    tools.logTitle(`CREATE TABLE`);
    return tools.runScript('php bin/console doctrine:schema:update --force', composerpath);
  })
  .then(() => { // Create a new table
    tools.logTitle(`RUN SYMFONY`);
    return tools.runScript('php bin/console server:run', composerpath)
  })
  .then(() => { // Run symfony
    resolve();
  })
  .catch((err) => {
    console.log(err);
    process.exit(1);
    reject();
});


