Repository navigation
Generate and manage schematic configuration files #22288
Description
Activity
- addedfeatureLabel used to distinguish feature request from other issuesLabel used to distinguish feature request from other issues
on Dec 2, 2021 We actually already offer a way to generate a blank schematic, using the schematic cli and it does add to an existing collection.
schematics blank —-name test-schematicIt’s actually also mentioned in https://angular.io/guide/schematics-authoring#creating-a-schematics-collection
Oh awesome! That's what I get for not double checking the docs. Is that mostly what you had in mind @kroeder, or was there more to it that I'm forgetting now?
Reacted by Alan Agius- addedneeds: more infoReporter must clarify the issueReporter must clarify the issue
on Dec 2, 2021 It's actually not what I have thought of. Yes, it creates a schematic project but isn't it that you often want to add schematics to an existing library? Like update schematics for angular/core
As far as I know this is not possible with the schematics cli
Here's an article I wrote about the schematics lib I wrote
https://dev.to/kroeder/set-up-your-own-angular-schematics-in-no-time-with-ngx-cli-toolkit-27ecMaybe this helps making clear what I actually, trying to achieve 🙂
Here's the link to the repo https://github.com/kroeder/ngx-cli-toolkit
Ah thanks, I think I see what you're getting at. It's not so much about making a new schematic, but more about configuring it to work with
ng add/ng generate/ng updateout of the box. I can definitely see value in that since this is usually what most users probably wanted to actually do. It also encourages more libraries to take advantage of these features and provide a better developer experience. Seems like most of the work here is around managing all the JSON files for users to simplify some of the up front configuration effort.I could imagine something like
ng generate schematicwhich would make a schematic inside an existing library and configure all the JSON files for you. Some kind of--typeflag could pick betweenng add/ng generate/ng update. That seems roughly equivalent to what you have inngx-cli-toolkitif I'm understanding this correctly. Is that more in line with what you were thinking @kroeder?Reacted by Kai RöderYes, exactly!
Now that I think about it there's probably not even the need for an
initschematic for projects.Here's a list of features that ngx-cli-toolkit already supports (or wants to support)
I already tried to use your suggestedng generate schematic --typeAPI instead of writing down the ngx-cli-toolkit commandsng addsupport- installs a couple of useful dependencies when working with schematics
init --project <name>Bootstraps everything in a project
- package.json entries
- creates a schematics folder
- adds "migration.json" as well as "collection.json"
However,
initcould be part of every other schematic with a check if a certain project already has bootstrapped schematics. If not, then run the bootstrap process before generate the actual schematics--type generate- Asks for a schematic
nameanddescription - Updates
collection.jsonautomatically - Creates a schematic script, a test file and a
schema.jsonfile withnameandpathalready part of it as this is what you need most of the time
--type update- Asks for a
name,descriptionandversion - Updates
migration.jsonautomatically - Creates schematic script and a test file
--type add- Asks if you want your package to be a
dependencyor adevDependencywhen runningng add <my-package> - Updates
collection.jsonautomatically - Creates schematic script and a test file
Future plans
Ideally this is not the end. Schematics also currently have a manual build step (see https://angular.io/guide/schematics-for-libraries#building-your-schematics)
I thought about creating a builder that automatically compiles and copies my schematic into the final
dist/my-libof my library. But since there's currently (afaik) no way to hook into e.g.ng build <my-lib>it would still be a separate step to runng run <my-lib>:build-schematicsor something like thatWhat I wanted to get rid of is things like this
"scripts": { "build": "../../node_modules/.bin/tsc -p tsconfig.schematics.json", "copy:schemas": "cp --parents schematics/*/schema.json ../../dist/my-lib/", "copy:files": "cp --parents -p schematics/*/files/** ../../dist/my-lib/", "copy:collection": "cp schematics/collection.json ../../dist/my-lib/schematics/collection.json", "postbuild": "npm run copy:schemas && npm run copy:files && npm run copy:collection" },Wrap up
I hope my thoughts can add value to this issue as I would love to have this natively supported by the angular cli! If there is anything else I can do just let me know 🙂
- changed the title
[-]Schematic to make a new schematic[/-][+]Generate and manage schematic configuration files[/+]on Dec 3, 2021 Makes sense, I can definitely see value here. I would probably prefer to leave out the "init" function and just let that transparently happen the first time any of the other
ng generate schematiccommands run, if possible. That way users don't have to think about it, understand what it's doing, or forget to run it.I agree the build story is also a bit too complicated on its own. Part of that is from the inherent complexity of needing a separate TS compilation unit, but we could probably do a better job of abstracting that. I'm wondering if we could add a new builder (or an option to the existing library builder) to also build schematics as part of
ng build, so library authors wouldn't need to worry about all these scripts.I don't want to get too carried away here just yet as I'm not a schematics expert. I'll bring it up to some others and see what they think.
Reacted by Kai RöderReacted by Kai Röder1 remaining item
- addedneeds: discussionOn the agenda for team meeting to determine next stepsOn the agenda for team meeting to determine next steps
on Dec 3, 2021 Talked to @alan-agius4 about this a bit today and he's generally on board with the idea as well. The
ng generate schematicstuff seems fairly straightforward and achievable. Replacing the build scripts with anng buildtarget/option also seems possible, but may be blocked on someng-packagrwork since it is heavily involved in the library build process and isn't very schematics-aware right now.This is definitely something we'd like to do, though realistically we probably won't get around to it anytime soon simply due to other responsibilities and priorities. For now, we should limit this work to just the
ng generate schematicstuff. I suggest leaving theng buildpart out of scope for now and we can have a separate FR for that afterwards.If anyone is interested in helping out and driving some of the implementation here we can definitely review any designs/PRs for this feature and help land them (:wink: @kroeder).
Reacted by Kai Röder- addedhelp wantedLabel noting an issue which the team is looking for contribution from the community to fixLabel noting an issue which the team is looking for contribution from the community to fixand removedneeds: discussionOn the agenda for team meeting to determine next stepsOn the agenda for team meeting to determine next steps
on Dec 6, 2021 I absolutely am interested 😄 as said on angular nation, I'd love to throw away my library if this gets adopted natively
- added a commit that references this issue
on Dec 7, 2021 - addedfeature: votes requiredFeature request which is currently still in the voting phaseFeature request which is currently still in the voting phase
on Feb 1, 2022 Just a heads up that we kicked off a community voting process for your feature request. There are 20 days until the voting process ends.
Find more details about Angular's feature request process in our documentation.
- removedfeature: votes requiredFeature request which is currently still in the voting phaseFeature request which is currently still in the voting phase
on Feb 22, 2022 Thank you for submitting your feature request! Looks like during the polling process it didn't collect a sufficient number of votes to move to the next stage.
We want to keep Angular rich and ergonomic and at the same time be mindful about its scope and learning journey. If you think your request could live outside Angular's scope, we'd encourage you to collaborate with the community on publishing it as an open source package.
You can find more details about the feature request process in our documentation.
- addedfeature: insufficient votesLabel to add when the not a sufficient number of votes or comments from unique authorsLabel to add when the not a sufficient number of votes or comments from unique authors
on Feb 22, 2022 Closing this as it did not gain sufficient community traction during the feature request process, and basic scaffolding is already supported via
schematics blank. Thank you for the feedback and discussion!
🚀 Feature request
Edit: The feature described in this comment already exists as
schematics blank, the real feature request is here.Command (mark with an
x)Description
It came up in an Angular Nation discussion today that making a new schematic is really difficult and requires a lot of steps with complex documentation. I think this came up before but I wasn't able to find an existing issue quickly.
Describe the solution you'd like
Ideally we would have something like
ng generate schematic(orschematics new) which could create a new schematic. We'll probably have to workshop how to support both creating a new collection and adding to an existing collection. This would also help improve some of the documentation, since users can get started with schematics much easily.Describe alternatives you've considered
Alternative is to just document everything and make users type everything out by hand, which is how it works today.
/cc @kroeder.