const shell = require('shelljs');
const addCheckMark = require('./helpers/checkmark.js');

if (!shell.which('git')) {
  shell.echo('Sorry, this script requires git');
  shell.exit(1);
}

if (!shell.test('-e', 'internals/templates')) {
  shell.echo('The example is deleted already.');
  shell.exit(1);
}

process.stdout.write('Cleanup started...');


// Cleanup components/
// shell.rm('-rf', 'src/components/*');

// Handle containers/
shell.rm('-rf', 'src/containers');
shell.mv('internals/templates/containers', 'app');

// Handle tests/
shell.mv('internals/templates/tests', 'app');

// Handle translations/
shell.rm('-rf', 'src/translations');
shell.mv('internals/templates/translations', 'app');

// Handle utils/
shell.rm('-rf', 'src/utils');
shell.mv('internals/templates/utils', 'app');

// Replace the files in the root app/ folder
shell.cp('internals/templates/app.js', 'src/app.js');
shell.cp('internals/templates/global-styles.js', 'src/global-styles.js');
// shell.cp('internals/templates/i18n.js', 'src/i18n.js');
shell.cp('internals/templates/index.html', 'src/index.html');
shell.cp('internals/templates/reducers.js', 'src/reducers.js');
shell.cp('internals/templates/configureStore.js', 'src/configureStore.js');

shell.rm('-rf', 'internals/templates');

addCheckMark();

if (
  shell.exec('git add . --all && git commit -qm "Remove default example"')
    .code !== 0
) {
  shell.echo('\nError: Git commit failed');
  shell.exit(1);
}

shell.echo('\nCleanup done. Happy Coding!!!');
