angular / angular-cli

CLI tool for Angular
https://cli.angular.io
MIT License
26.72k stars 11.98k forks source link

[Feature Request] Schematics: Run local a schematic written in TypeScript directly (ts-node integration) #13858

Open lacolaco opened 5 years ago

lacolaco commented 5 years ago

πŸš€ Feature request

Command (mark with an x)

- [x] schematics

Description

Schematics runner can accept a JavsScript file as a factory of a schematic. To create boilerplates in my app, it seems a good solution to create local schematics. But it is not easy to get ready. Writing schematics without TypeScript's help is tough and unsafe. But schematics cannot use them. We have to do manually transpiling with tsc and executing the output JS. Very primitive and boring.

Describe the solution you'd like

If schematics runner can handle TypeScript files directly, developers are free from non-essencial jobs and the repository can keep clean.

I think ts-node/register can help it.

alan-agius4 commented 5 years ago

Hi, In general, I don't think shipping or transpile TypeScript at runtime is a good idea as it opens a whole new pandora box.

Compiling a .ts file to .js is dependent on a couple of factors which might vary from one project to another.

1) tsconfig - this can be different from one project to another and hence might cause failure of a transpilation which in another project might work. 2) tsc version, syntax that works with this current typescript version, might not be able to be compiled in the next/previous version.

Apart from that consumers of a schematic, shouldn't care if it's written in TypeScript or vanilla JavaScript and hence when compiling at runtime they might get a TypeScript error, which for them are un-actionable and irrelevant. Also, the consumers might need to install dev only dependencies which otherwise won't have too. Such as an @types/ package.

lacolaco commented 5 years ago

@alan-agius4 Shipping TS is not good, totally I agree. I've mentioned about only project local use of schematics. It's a common demand that scaffolding some application code in project local.

alan-agius4 commented 5 years ago

@lacolaco, yeah in your case, ts-node might work, however this would mean a couple of things.

1) Schematic runner would need to be aware made aware of a tsconfig file path, as otherwise ts-node might resolve an incorrect tsconfig. 2) API features which are specific only for local schematics.

lacolaco commented 5 years ago

Technically, I don't want to introduce ts-node in the CLI. I just want to run schematics with ts-node.

Currently, schematics-cli is doing many jobs. It is designed as a general reference implementation of schematics runner but technically I don't think it is easy to implement another tool equivalent to that. I think it is needed that a JavaScript API which can be used with less configuration. It wraps @angular_devkit/schematics and contains the preset "workflow" as well as CLI.

If it can be executed in Node.js script with well-abstracted easy API, I can run just ts-node run-my-schematics.ts.

lacolaco commented 5 years ago

something like schematics-cli-js maybe I need. πŸ€”

hansl commented 5 years ago

Hi @lacolaco,

This is a great feature request. Unfortunately the schematics CLI is not a priority right now, but we do accept pull requests to add features like these. I'm going to remove the need further discussion, but let us know if you can implement that we can help you answer questions.

angular-robot[bot] commented 2 years ago

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.

angular-robot[bot] commented 2 years ago

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.