https://github.com/bbvaengineering/ember-component-analyzer
Extracts the "possibles" components that may exists in the different routes of an Ember application.
https://github.com/bbvaengineering/ember-component-analyzer
Last synced: about 1 year ago
JSON representation
Extracts the "possibles" components that may exists in the different routes of an Ember application.
- Host: GitHub
- URL: https://github.com/bbvaengineering/ember-component-analyzer
- Owner: BBVAEngineering
- License: mit
- Created: 2017-09-18T15:49:53.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2022-12-12T15:01:31.000Z (over 3 years ago)
- Last Synced: 2025-02-26T05:36:39.310Z (over 1 year ago)
- Language: JavaScript
- Size: 1.23 MB
- Stars: 2
- Watchers: 10
- Forks: 0
- Open Issues: 26
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.md
Awesome Lists containing this project
README
# ember-component-analyzer
[](https://travis-ci.org/BBVAEngineering/ember-component-analyzer)
[](https://badge.fury.io/gh/BBVAEngineering%2Fember-component-analyzer)
[](https://badge.fury.io/js/ember-component-analyzer)
[](https://david-dm.org/BBVAEngineering/ember-component-analyzer)
[](https://codecov.io/gh/BBVAEngineering/ember-component-analyzer)
[](https://greenkeeper.io/)
## Information
[](https://nodei.co/npm/ember-component-analyzer/)
### This project is an experimental dark thing O_O**
This library extracts the "possibles" components that may exists in the different routes
of an Ember application. It uses Glimmer compiler to make & read the AST trees.
The lib reads all the handlebars files to find all the components (usually names that
contains `-` for components and `.` for contextual components).
Once the "possible" components are found, it replaces all the contextual components by
its real name. This part is only possible for the application components (right now its unable to read the components
inside the `ember-addons`).
## Information
[](https://nodei.co/npm/ember-component-analyzer/)
## How to use
1. Import the lib
```js
const lib = require('ember-component-analyzer');
```
2. Process the application
```js
#!/usr/bin/env node
const { Analyzer, parse } = lib;
const analyzer = new Analyzer(process.argv.slice(2), {
// options...
});
const result = analyzer.process(); // Hell JSON
const output = parse(result); // Friendly JSON with the application data
```
3. Save the results, process or do whatever you want
## Options
The `Analyzer` class accepts an object as config. The possible attributes are:
- **families**: An object containing the different typologies of the templates
(components, helpers, routes, ...) and the `RegExp` used to recognize the type.
These families represents the attributes of the result object after parsing
the files.
Defaults to:
```javascript
{
components: /components/, // the file path contains the word "components"
default: /^((?!components).)*$/ // the file path not contains the word "components"
}
```
- **getNodeName**: This function receives an **AST node** as first argument and
it should return the component name (if valid) or `null` if you don't want
the element to appear in the report (for example a blacklisted element).
## Example
Given:
- Component `my-wrapper.hbs`:
```handlebars
{{yield (hash header=(component 'my-header'))}}
{{my-footer}}
```
- Component `my-header.hbs`:
```handlebars
{{link-to}}
```
- Route `index.hbs`:
```handlebars
{{#my-wrapper as |wrapper|}}
{{wrapper.header}}
{{/my-wrapper}}
```
Then it will generate an output (using the exported `parser`) similar to:
```json
{
"default": [{
"moduleId": "index.hbs",
"components": ["my-wrapper", "header-main", "link-to", "my-footer"]
},
"components": [{
"moduleId": "my-wrapper",
"components": ["my-footer"]
}, {
"moduleId": "my-header",
"components": ["link-to"]
}]
}
```
## Readable report?
Working on it :)

## Contributing
We're thankful to the community for contributing any improvements.
Do not forget to follow our [eslint](https://github.com/BBVAEngineering/javascript/tree/master/eslint-config-bbva) rules and make test for the new functionalities/fixes.
## Versioning
We use [SemVer](http://semver.org/) for versioning. For the versions available, see the [tags on this repository](https://github.com/BBVAEngineering/ember-storages/tags).
## Authors
See the list of [contributors](https://github.com/BBVAEngineering/ember-storages/graphs/contributors) who participated in this project.
## License
This project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md) file for details