UNPKG

2.32 kBMarkdownView Raw
1[![Build Status](https://travis-ci.org/Polymer/polymer-analyzer.svg?branch=master)](https://travis-ci.org/Polymer/polymer-analyzer)
2[![NPM version](http://img.shields.io/npm/v/polymer-analyzer.svg)](https://www.npmjs.com/package/polymer-analyzer)
3
4# Polymer Analyzer
5
6A static analysis framework for Web Components.
7
8## Install
9
10```
11npm install polymer-analyzer
12```
13
14## Usage
15```js
16const {Analyzer, FsUrlLoader, PackageUrlResolver} = require('polymer-analyzer');
17
18const rootDir = process.cwd();
19const analyzer = new Analyzer({
20 urlLoader: new FsUrlLoader(rootDir),
21 urlResolver: new PackageUrlResolver({ packageDir: rootDir }),
22});
23
24// This path is relative to the root dir
25analyzer.analyze(['my-element.html']).then((analysis) => {
26 // Print the name of every property on paper-button, and where it was
27 // inherited from.
28 const [paperButton] = analysis.getFeatures(
29 {kind: 'element', id: 'paper-button', externalPackages: true});
30 if (paperButton) {
31 for (const [name, property] of paperButton.properties) {
32 let message = `${name}`;
33 if (property.inheritedFrom) {
34 message += ` inherited from ${property.inheritedFrom}`;
35 } else {
36 message += ` was defined directly on paper-button`;
37 }
38 console.log(message);
39 }
40 } else {
41 console.log(`my-element.html didn't define or import paper-button.`);
42 }
43});
44```
45
46## What's it used for?
47
48* [webcomponents.org](https://webcomponents.org) - discovery, demos, and docs for web components
49* [polymer-linter](https://github.com/Polymer/polymer-linter) - lints the web
50* [polymer-build](https://github.com/Polymer/polymer-build) - performs HTML-aware buildtime optimization
51* [polymer-editor-service](https://github.com/Polymer/polymer-editor-service) - IDE plugin, provides live as-you-type help
52
53## Developing
54
55Polymer Analyzer is supported on Node LTS and stable. It is written
56in TypeScript. All development dependencies are installed via npm.
57
58```sh
59npm install
60npm test
61```
62
63Or watch the source for changes, and run tests each time a file is modified:
64
65```sh
66npm run test:watch
67```
68
69## Looking for Hydrolysis?
70
71Hydrolysis has been renamed to Polymer Analyzer for version 2. You can find the
72hydrolysis source on the
73[`hydrolysis-1.x`](https://github.com/Polymer/polymer-analyzer/tree/hydrolysis-1.x)
74branch.