Skip to content
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

Merged
merged 5 commits into from
Feb 6, 2018
Merged

feat(schematics): add initial schematics utils #9451

merged 5 commits into from
Feb 6, 2018

Conversation

amcdnl
Copy link
Contributor

@amcdnl amcdnl commented Jan 18, 2018

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.

@amcdnl amcdnl self-assigned this Jan 18, 2018
@amcdnl amcdnl requested a review from jelbourn January 18, 2018 02:46
@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Jan 18, 2018
@josephperrott
Copy link
Member

@amcdnl can you add /schematics/* to the CODEOWNERS file?

@jelbourn jelbourn requested a review from devversion January 18, 2018 22:24
@@ -0,0 +1,18 @@
// By default, collection.json is a Loose-format JSON5 format, which means it's loaded using a
Copy link
Member

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?

Copy link
Contributor Author

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

Copy link
Member

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
Copy link
Member

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?

Copy link
Contributor Author

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?

Copy link
Member

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

@@ -0,0 +1,3 @@
export const materialVersion = '^5.0.1';
export const cdkVersion = '^5.0.1';
export const angularVersion = '5.0.1';
Copy link
Member

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[] {
Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Member

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.

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';
Copy link
Member

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)

/**
* Import and add module to root app module.
*/
export function addToRootModule(host: Tree, moduleName: string, src: string) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addModuleImportToRootModule?

/**
* Import and add module to specific module path.
*/
export function addToModule(host: Tree, modulePath: string, moduleName: string, src: string) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addModuleImportToModule?

/**
* Gets the app index.html file
*/
export function getIndexPath(host: Tree) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getIndexHtmlPath?

@@ -0,0 +1,25 @@
import * as path from 'path';
Copy link
Member

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

/**
* Create a base app used for testing.
*/
export function baseApp() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

createTestApp?

@amcdnl
Copy link
Contributor Author

amcdnl commented Jan 18, 2018

@jelbourn - addressed feedback.

*/
export function getHeadTag(host: Tree, src: string) {
const document = parse5.parse(src,
{ locationInfo: true }) as parse5.AST.Default.Document;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Omit spaces in braces

const src = buffer.toString();
if (src.indexOf(link) === -1) {
const node = getHeadTag(host, src);
const chng = new InsertChange(indexPath, node.position, link);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

chng -> insertion?

}

/**
* Adds a link to the index.html head tag
Copy link
Member

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.
Copy link
Member

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.
Copy link
Member

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
Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Member

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

Copy link
Member

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.

Copy link
Member

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.

@amcdnl
Copy link
Contributor Author

amcdnl commented Jan 21, 2018

@jelbourn - updated per feedback.

/**
* Import and add module to specific module path.
* @param host the tree we are updating
* @param modulePath src location of the module
Copy link
Member

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
Copy link
Member

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

@amcdnl
Copy link
Contributor Author

amcdnl commented Jan 26, 2018

@jelbourn - re: private __location, I agree, but the docs don't indicate that to be true: http://inikulin.github.io/parse5/interfaces/options.parseroptions.html#locationinfo

@jelbourn
Copy link
Member

@amcdnl just needs an entry in CODEOWNERS and it's good to go

@amcdnl
Copy link
Contributor Author

amcdnl commented Feb 4, 2018

@CaerusKaru correct me if im wrong but that is for creating/querying/manipulating elements. I need a DOM AST parser.

@jelbourn - Good to go.

@CaerusKaru
Copy link
Member

@amcdnl You can initialize a Domino Document object with HTML input; it then constructs the AST from the input.

@jelbourn jelbourn added pr: lgtm action: merge The PR is ready for merge by the caretaker labels Feb 5, 2018
@mmalerba mmalerba merged commit 673d56e into master Feb 6, 2018
mmalerba pushed a commit that referenced this pull request Feb 8, 2018
* feat(schematics): add initial schematics utils

* chore: nit

* chore: pr feedback

* chore: pr feedback

* chore: add code owner
@amcdnl amcdnl deleted the schematics branch February 10, 2018 15:14
mmalerba added a commit that referenced this pull request Feb 12, 2018
@mmalerba mmalerba added the target: minor This PR is targeted for the next minor release label Feb 12, 2018
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 8, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker cla: yes PR author has agreed to Google's Contributor License Agreement target: minor This PR is targeted for the next minor release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants