-
Notifications
You must be signed in to change notification settings - Fork 6.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(schematics): add initial schematics utils #9451
Conversation
@amcdnl can you add |
schematics/collection.json
Outdated
@@ -0,0 +1,18 @@ | |||
// By default, collection.json is a Loose-format JSON5 format, which means it's loaded using a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add comment at the top that explains what this file is for / does?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Technically, json is not supposed to have comments. ;P
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It has comments already?
|
||
# schematics | ||
/schematics/**/*.js | ||
/schematics/**/*.map |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason not to put this under src
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would you like to move all the code under src?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nah, just curious; we can move them if we ever need to
schematics/utils/lib-versions.ts
Outdated
@@ -0,0 +1,3 @@ | |||
export const materialVersion = '^5.0.1'; | |||
export const cdkVersion = '^5.0.1'; | |||
export const angularVersion = '5.0.1'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why 5.0.1
instead of 5.0.0
?
* @param max The maximum number of items to return. | ||
* @return all nodes of kind, or [] if none is found | ||
*/ | ||
export function findNodes(node: ts.Node, kind: ts.SyntaxKind, max = Infinity): ts.Node[] { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Brocco @hansl will these functions (and other utils in the PR) be a part of the public schematics API? It's a pretty large amount of code that schematic creators are needing to copy now. Is this just a temporary thing we can get rid of eventually, or do we need to own this code forever?
@amcdnl is there anything that you needed to customize in these utils?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope, these are straight copies from that repo.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I chatted w/ Hans and these utils are eventually going to be a standalone thing, so in the meantime we can just treat them as an external library that happens to live in our source.
schematics/utils/ast.ts
Outdated
import { getAppModulePath } from './devkit-utils/ng-ast-utils'; | ||
import { InsertChange } from './devkit-utils/change'; | ||
import { getConfig, getAppFromConfig } from './devkit-utils/config'; | ||
import { normalize } from '@angular-devkit/core'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Omit spaces in braces (WebStorm can be configured for this, not sure about VS Code)
(here and elsewhere)
schematics/utils/ast.ts
Outdated
/** | ||
* Import and add module to root app module. | ||
*/ | ||
export function addToRootModule(host: Tree, moduleName: string, src: string) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
addModuleImportToRootModule
?
schematics/utils/ast.ts
Outdated
/** | ||
* Import and add module to specific module path. | ||
*/ | ||
export function addToModule(host: Tree, modulePath: string, moduleName: string, src: string) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
addModuleImportToModule
?
schematics/utils/ast.ts
Outdated
/** | ||
* Gets the app index.html file | ||
*/ | ||
export function getIndexPath(host: Tree) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getIndexHtmlPath
?
schematics/utils/testing.ts
Outdated
@@ -0,0 +1,25 @@ | |||
import * as path from 'path'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can do
import {join} from 'path';
We do this in most of our other tooling
schematics/utils/testing.ts
Outdated
/** | ||
* Create a base app used for testing. | ||
*/ | ||
export function baseApp() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
createTestApp
?
@jelbourn - addressed feedback. |
schematics/utils/html.ts
Outdated
*/ | ||
export function getHeadTag(host: Tree, src: string) { | ||
const document = parse5.parse(src, | ||
{ locationInfo: true }) as parse5.AST.Default.Document; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Omit spaces in braces
schematics/utils/html.ts
Outdated
const src = buffer.toString(); | ||
if (src.indexOf(link) === -1) { | ||
const node = getHeadTag(host, src); | ||
const chng = new InsertChange(indexPath, node.position, link); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
chng
-> insertion
?
schematics/utils/html.ts
Outdated
} | ||
|
||
/** | ||
* Adds a link to the index.html head tag |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add @param
JsDoc? (specifically it's not clear what link
should look like)
import {InsertChange} from './devkit-utils/change'; | ||
|
||
/** | ||
* Parses the index.html file to get the HEAD tag position. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add @param
JsDoc?
} | ||
|
||
/** | ||
* Import and add module to specific module path. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add @param
JsDoc? This will help disambiguate which module mouldePath
and moduleName
are referring to
} | ||
|
||
return { | ||
position: head.__location.startTag.endOffset |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does this need to use a __
-prefixed member?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unsure, this is just what the object looks like.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is typically meant to communicate a private API; there might be a alternate public way to access this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason you're using parse5 over domino? Domino might provide a more natural interface here since it more closely mirrors the DOM than parse5.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is a good point, especially since Angular Universal has moved to Domino. For now we can continue with this, though, since our use of it is pretty minor.
@jelbourn - updated per feedback. |
schematics/utils/ast.ts
Outdated
/** | ||
* Import and add module to specific module path. | ||
* @param host the tree we are updating | ||
* @param modulePath src location of the module |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Location of which module?
} | ||
|
||
return { | ||
position: head.__location.startTag.endOffset |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is typically meant to communicate a private API; there might be a alternate public way to access this
@jelbourn - re: private |
@amcdnl just needs an entry in |
@CaerusKaru correct me if im wrong but that is for creating/querying/manipulating elements. I need a DOM AST parser. @jelbourn - Good to go. |
@amcdnl You can initialize a Domino Document object with HTML input; it then constructs the AST from the input. |
* feat(schematics): add initial schematics utils * chore: nit * chore: pr feedback * chore: pr feedback * chore: add code owner
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
This PR lays the foundation for schematics. #8975
The schematics will come in separate PRs resembling https://github.com/amcdnl/material-schematics which represent demos from https://github.com/amcdnl/material-example-schematics.