[Feature] Could the create command be separated into two commands, one for app and one for lib?
See original GitHub issueIs your feature request related to a problem? Please describe. A clear and concise description of what the problem is. Ex. I’m always frustrated when […]
No.
Describe the idea you’d like A clear and concise description of what you want to happen.
I would like to see nx g @nxrocks/nx-flutter:create <app-folder> separated into:
nx g @nxrocks/nx-flutter:app <app-name> [–directory=<directory-name>] nx g @nxrocks/nx-flutter:lib <lib-name> [–directory=<directory-name>]
; and allowing them to be integrated into the nx dependecy graph mechanism. Flutter has applications, modules, packages, and plugins, so there is a natural separation between apps and libs as far as the flutter cli is concerned.
Describe alternatives you’ve considered A clear and concise description of any alternative solutions or features you’ve considered.
The scaffolding schema could be easily split into two schemas, one for app and one for lib. Since you are defering to the flutter cli in both cases it should as easy as changing the schematic’s schema and allowing only for certain cli arguments in each case. This line:
const projectType = ProjectType.Application;
should become:
const projectType = ProjectType.Library;
in the library case.
Additional context Add any other context or screenshots about the feature request here.
There is of course the issue of imports. I think to fully appreciate the nx tool for code sharing, you ought to be able to import a flutter lib in a flutter app. But because nx is a node.js tool I am also thinking there would have to be some integration with the dart language to be able to excute npm build
or npm test
at the root directory and have your flutter app pull it’s dependencies and compile. This is just an idea, since I think nx + flutter would be a really cool setup for a web, mobile, desktop, AND node.js backend and run the whole show from 1 repo.
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (1 by maintainers)
Hi @tinesoft,
I like the idea of making the existing comand smarter, rather than splitting 1 command into 2 commands. What you describe is definately a better approach.
I have given some thought about how you would integrate with
dep-graph
(note: this insight comes from using the nx tool and so is basically my assumptions about how nx works, not from analysis of the code, and is specific to my experience which is nx with TypeScript/Angular).So, for the imports, the nx tool is making use of the TypeScript compiler’s path mapping feature. So if you were to do something similar with Flutter, I think I would start looking at the Dart compiler and seeing if there were any similar features, like mapped imports, with which you could integrate with nx via a node package (I am thinking something like the node equivalent of a polyfill).
With
dep-graph
it seems to me nx is aware of the TypeScript mapped imports, and the user defined project structure (apps, libs and tools) then by analyzing the code and the tsconfig is able to construct the dep graph using the mapped imports. I have also noticed implicit dependencies are noted in the root levelnx.json
, but other user defined dependencies (ex. importing a lib into an app) are not present. So the logic ofdep-graph
must be something like: recurse directories of all the apps, libs, and tools, look for mapped imports, and construct the graph, then add implicit dependencies fromnx.json
.SO, it would be ideal if nx would allow you to add dependencies to the
nx.json
(maybe this already exists) to support cross language projects. And it was was easy as amending thenx.json
to alter thedep-graph
. The nx algorithm could still do it’s thing and look for mapped imports, and then in step where it is looking for “implicitDependencies”, also look for “explicitDependencies”, and add those in last.I was a bit hesitant to make this request, because as I wrote I started to realize that there was only so much you could do as a plugin, you kind of have to play by the existing rules. But I think the ideal plugin would allow you to create 2 apps and 1 lib and let both apps import the lib. If this is not possible, then perhaps after some more research this can become a feature request to Nx for better multi-language support, or to Dart for mapped imports. I also need to do more research. Thanks for sharing your plugin though, very cool, much appreciated.
🎉 This issue has been resolved in version @nxrocks/nx-flutter-v2.0.0 🎉
The release is available on:
Your semantic-release bot 📦🚀