Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
mvp folder structure generator
#!/bin/bash
# generate mvp folders and classes for screens component
###############
##screen name
PARENT_FOLDER=$1
###############
##activity name
ACTIVITY_NAME=$2
###############
##package
PROJECT_NAME=$3
###############
##help
if [ "$1" == "-h" ]; then
echo -e "Usage: mvp-folder PARENT_FOLDER ACTIVITY_NAME PROJECT_NAME\n\t\t PARENT_FOLDER - screen name\n\t\t ACTIVITY_NAME - activity name\n\t\t PROJECT_NAME - project name"
exit 0
fi
#########################
##generate folders
mkdir -p ${PARENT_FOLDER}/di/
mkdir -p ${PARENT_FOLDER}/model/entity
mkdir -p ${PARENT_FOLDER}/model/interfaces
mkdir -p ${PARENT_FOLDER}/presenter/interfaces
mkdir -p ${PARENT_FOLDER}/view/delegate
mkdir -p ${PARENT_FOLDER}/view/activity
mkdir -p ${PARENT_FOLDER}/view/adapter
mkdir -p ${PARENT_FOLDER}/view/fragment
#########################
##generate classes
###############
##model class
echo "package com.${PROJECT_NAME}.screens.${PARENT_FOLDER}.model;
import com.${PROJECT_NAME}.screens.${PARENT_FOLDER}.model.interfaces.I${ACTIVITY_NAME}Model;
public class ${ACTIVITY_NAME}Model implements I${ACTIVITY_NAME}Model{
}" >>${PARENT_FOLDER}/model/"${ACTIVITY_NAME}Model.java"
###############
##presenter class
echo "package com.${PROJECT_NAME}.screens.${PARENT_FOLDER}.presenter;
import com.${PROJECT_NAME}.screens.${PARENT_FOLDER}.presenter.interfaces.I${ACTIVITY_NAME}Presenter;
public class ${ACTIVITY_NAME}Presenter implements I${ACTIVITY_NAME}Presenter{
}" >>${PARENT_FOLDER}/presenter/"${ACTIVITY_NAME}Presenter.java"
###############
##di class
echo "package com.${PROJECT_NAME}.screens.${PARENT_FOLDER}.di;
import dagger.Module;
@Module
public abstract class ${ACTIVITY_NAME}Module {
}" >>${PARENT_FOLDER}/di/"${ACTIVITY_NAME}Module.java"
#########################
##generate interfaces
###############
##model interface
echo "package com.${PROJECT_NAME}.screens.${PARENT_FOLDER}.model.interfaces;
public interface I${ACTIVITY_NAME}Model{
}" >>${PARENT_FOLDER}/model/interfaces/"I${ACTIVITY_NAME}Model.java"
###############
##presenter interface
echo "package com.${PROJECT_NAME}.screens.${PARENT_FOLDER}.presenter.interfaces;
public interface I${ACTIVITY_NAME}Presenter{
}" >>${PARENT_FOLDER}/presenter/interfaces/"I${ACTIVITY_NAME}Presenter.java"
###############
##view interface
echo "package com.${PROJECT_NAME}.screens.${PARENT_FOLDER}.view.delegate;
public interface I${ACTIVITY_NAME}ViewDelegate{
}" >>${PARENT_FOLDER}/view/delegate/"I${ACTIVITY_NAME}ViewDelegate.java"

MVP folder structure generator

Step 1.

Create the file mvp-folder-generator.sh into home/username/utils/scripts.

Step 2.

Open .bashrc form ~.

Step 3.

At the end of the .bashrc file add:

# alias mvp folder generator
alias mvp-folder=/home/username/utils/scripts/mvp-folder-generator.sh

Step 4.

Restart bash. (close and open new terminal)

Use mvp-folder PARENT_FOLDER ACTIVITY_NAME PROJECT_NAME to generate the folder structure.

TODO:

  • template files
  • activity flag
  • fragment flag
  • custom package name
  • generate activity
  • generate fragment
  • generate modules
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment