Skip to content

Commit

Permalink
- Feature ignore (1.1.0)
Browse files Browse the repository at this point in the history
MayconCardoso committed Apr 28, 2020

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 8a21756 commit 0a2d512
Showing 4 changed files with 29 additions and 6 deletions.
2 changes: 1 addition & 1 deletion library/build.gradle
Original file line number Diff line number Diff line change
@@ -33,7 +33,7 @@ ext {
siteUrl = 'https://github.com/MayconCardoso/ArchitectureBoilerplateGenerator'
gitUrl = 'https://github.com/MayconCardoso/ArchitectureBoilerplateGenerator.git'

libraryVersion = '1.0.4'
libraryVersion = '1.1.0'

developerId = 'mayconcardoso'
developerName = 'Maycon Cardoso'
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@ import com.mctech.architecture.generator.context.FeatureContext
import com.mctech.architecture.generator.path.ModuleDefaultLayers
import com.mctech.architecture.generator.settings.FeatureSettings
import com.mctech.architecture.generator.settings.GlobalSettings
import com.mctech.architecture.generator.strategy.FileDuplicatedStrategy
import com.mctech.architecture.generator.templates.data.api.RetrofitAPITemplate
import com.mctech.architecture.generator.templates.data.datasource.DataSourceInterfaceTemplate
import com.mctech.architecture.generator.templates.data.datasource.LocalDataSourceTemplate
@@ -106,6 +107,14 @@ class FeatureGenerator(val settings: FeatureSettings, featureName: FeatureName)
// Set context
FeatureContext.featureGenerator = this

// Need to ignore feature
if(
settings.featureDuplicatedStrategy is FileDuplicatedStrategy.Ignore
&& AddFeatureOnSettingsFileTemplate.containsFeature()
){
return
}

// Generate files
domainEntityTemplateGenerator.generate()
domainServiceGenerator.generate()
@@ -126,7 +135,7 @@ class FeatureGenerator(val settings: FeatureSettings, featureName: FeatureName)


// Create final templates of the feature module.
AddFeatureOnSettingsFileTemplate().generate()
AddFeatureOnSettingsFileTemplate.generate()
AndroidManifestTemplate(featureModulePath).generate()
StringTemplate(featureModulePath).generate()

Original file line number Diff line number Diff line change
@@ -19,6 +19,11 @@ data class FeatureSettings(
*/
var fileDuplicatedStrategy: FileDuplicatedStrategy = FileDuplicatedStrategy.Ignore,

/**
* The duplicate feature strategy. It says the generator how handle when a feature that is being generated already exists.
*/
var featureDuplicatedStrategy: FileDuplicatedStrategy = FileDuplicatedStrategy.Ignore,

/**
* When true the generator will create all of the use cases with @Inject annotation on the constructor.
* So basically all of the UseCases will be auto-injectable by dagger.
Original file line number Diff line number Diff line change
@@ -10,15 +10,20 @@ import com.mctech.architecture.generator.templates.Template
/**
* @author MAYCON CARDOSO on 2019-12-02.
*/
open class AddFeatureOnSettingsFileTemplate : Template() {
object AddFeatureOnSettingsFileTemplate : Template() {

private val moduleName by lazy {
"include ':features:feature-${featureSegment()}'"
}
private val linesOfFile by lazy {
readFile(this).toMutableList()
}

override fun getPath(): String {
return baseProjectPath + "settings.gradle"
}

override fun generate() {
val linesOfFile = readFile(this).toMutableList()

val moduleName = "include ':features:feature-${featureSegment()}'"
// Add new module on the of the file.
if (linesOfFile.contains(moduleName).not()) {
linesOfFile.add(moduleName)
@@ -31,4 +36,8 @@ open class AddFeatureOnSettingsFileTemplate : Template() {
}
}
}

fun containsFeature() : Boolean {
return linesOfFile.contains(moduleName)
}
}

0 comments on commit 0a2d512

Please sign in to comment.