Cake icon indicating copy to clipboard operation
Cake copied to clipboard

Consider "Sources•Modules" rather than "Sources•Model"

Open gcox opened this issue 5 years ago • 1 comments

First, 👏thank you👏 for taking a shot at fixing the problem you're trying to solve! I'm frustrated by the tooling standing in the way of modularizing Swift codebases all day long every day. So, I really hope this tool takes off. 🎉


I may not be understanding everything (or much at all) so I'll break this up into my assumptions, my use case, and then my suggestion(s)...all based on those assumptions 😄

Assumptions

  • Everything in "Sources•Model" is compiled against all platforms in the Cakefile
  • Modules are not created for folders in "Sources•App"
  • There is currently no way to limit the platforms a specific module in "Sources•Model" is compiled against
  • The intention is for all platform-specific code to go in "Sources•App"
  • The developer is expected to create each application target (excluding the one the Cake menu app will create for you).

Use case

  • Large project, targeting iOS, macOS, tvOS, and watchOS
  • Non-trivial UI for each platform. Lots of view controllers, lots of "components" (similar to React, small reusable UI bits).

For my situation, micro modules would offer just as much benefit to my application-specific code as my domain/model code. In fact, my UI code would probably benefit even more. That is where I find myself using nested types for the sole purpose of faking namespaces more frequently than anywhere else. Nested types are fine, but I've found that Xcode/SourceKit/Something-else-in-the-tool-chain falls over after a certain depth and all I see is <<error type>> in Xcode's autocomplete dialogs.

Suggestions

  1. Add support for limiting which platforms a specific module is built for. Maybe that takes the form of a Cakefile in a module's directory, or platform-specific "Sources•Modules•[platform]" directories...which could be auto generated using the platforms setting in the root Cakefile. The goal being platform-specific-modules in a multi-platform project.
  2. Rename "Sources•Model" to "Sources•Modules"

To be clear, this is only necessary for a multi-platform project. What I'm wanting to do is already totally doable for a single-platform project.

gcox avatar Mar 05 '19 16:03 gcox

Hi, thanks for the thorough write up. I think what we should do is allow specification of the location of module hierarchies and allow multiple hierarchies. Something like:

import Cakefile

let base = moduleHeirarchies[0]  // defaults to standard base, ie. Sources/Model
base.path = "Sources/Modules"    // if you like

var iOS = ModuleHeirarchy()
iOS.path = "Sources/iOS.Modules"
iOS.platforms = [.iOS ~> 12]
iOS.dependencies = [base]
moduleHeirarchies.append(iOS)

let tvOS = ModuleHeirarchy(path: /*…*/, platforms: /*…*/, dependencies: [base])
moduleHeirarchies.append(tvOS)

This is not a trivial change, but would be pretty useful, I could already use this in several apps.

mxcl avatar Mar 06 '19 15:03 mxcl