Skip to content

Commit

Permalink
display standalone pipes, directives and dialogs; closes #28
Browse files Browse the repository at this point in the history
  • Loading branch information
DenysVuika committed Jun 12, 2023
1 parent 861d64d commit 197f81c
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 41 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,6 @@ The format of the output is similar to the following example:
"angular": {
"module": 149,
"component": 415,
"component_standalone": 23,
"directive": 58,
"service": 181,
"pipe": 23,
Expand Down
24 changes: 9 additions & 15 deletions src/assets/html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,14 @@
`;
}

function LinkRow({ caption, url }) {
function LinkRow({ caption, url, standalone }) {
return html`
<a class="panel-block">
${url
? html`<a href="${url}" target="_blank">${caption}</a>`
: html`<span>${caption}</span>`
}
${standalone && html`<span class="tag is-success ml-2">standalone</span>`}
</a>
`;
}
Expand Down Expand Up @@ -353,13 +354,12 @@
new Chart(ctx, {
type: 'bar',
data: {
labels: ['Module', 'Component', 'Component (std)', 'Directive', 'Service', 'Pipe', 'Dialog'],
labels: ['Module', 'Component', 'Directive', 'Service', 'Pipe', 'Dialog'],
datasets: [{
label: '# of elements',
data: [
angular.module,
angular.component,
angular.component_standalone,
angular.directive,
angular.service,
angular.pipe,
Expand All @@ -368,7 +368,7 @@
backgroundColor: [
'rgba(255, 99, 132, 0.2)',
'rgba(255, 159, 64, 0.2)',
'rgba(255, 205, 86, 0.2)',
// 'rgba(255, 205, 86, 0.2)',
'rgba(75, 192, 192, 0.2)',
'rgba(54, 162, 235, 0.2)',
'rgba(153, 102, 255, 0.2)',
Expand All @@ -377,7 +377,7 @@
borderColor: [
'rgb(255, 99, 132)',
'rgb(255, 159, 64)',
'rgb(255, 205, 86)',
// 'rgb(255, 205, 86)',
'rgb(75, 192, 192)',
'rgb(54, 162, 235)',
'rgb(153, 102, 255)',
Expand Down Expand Up @@ -448,19 +448,13 @@
${activeTab === 2 && html`
${components.map(entry => html`
<a class="panel-block">
${entry.url
? html`<a href="${entry.url}" target="_blank">${entry.path}</a>`
: html`<span>${entry.path}</span>`
}
${entry.standalone && html`<span class="tag is-success ml-2">standalone</span>`}
</a>
<${LinkRow} caption="${entry.path}" url="${entry.url}" standalone="${entry.standalone}"/>
`)}
`}
${activeTab === 3 && html`
${directives.map(entry => html`
<${LinkRow} caption="${entry.path}" url="${entry.url}"/>
<${LinkRow} caption="${entry.path}" url="${entry.url}" standalone="${entry.standalone}"/>
`)}
`}
Expand All @@ -472,13 +466,13 @@
${activeTab === 5 && html`
${pipes.map(entry => html`
<${LinkRow} caption="${entry.path}" url="${entry.url}"/>
<${LinkRow} caption="${entry.path}" url="${entry.url}" standalone="${entry.standalone}"/>
`)}
`}
${activeTab === 6 && html`
${dialogs.map(entry => html`
<${LinkRow} caption="${entry.path}" url="${entry.url}"/>
<${LinkRow} caption="${entry.path}" url="${entry.url}" standalone="${entry.standalone}"/>
`)}
`}
</div>
Expand Down
61 changes: 36 additions & 25 deletions src/inspectors/angular.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,18 @@ pub struct AngularComponent {
standalone: bool,
}

#[derive(Serialize, Deserialize)]
pub struct AngularPipe {
path: String,
standalone: bool,
}

#[derive(Serialize, Deserialize)]
pub struct AngularDirective {
path: String,
standalone: bool,
}

#[derive(Serialize, Deserialize)]
pub struct AngularEntity {
path: String,
Expand All @@ -22,10 +34,10 @@ pub struct AngularInspector {
framework: Option<String>,
modules: Vec<AngularEntity>,
components: Vec<AngularComponent>,
directives: Vec<AngularEntity>,
directives: Vec<AngularDirective>,
services: Vec<AngularEntity>,
pipes: Vec<AngularEntity>,
dialogs: Vec<AngularEntity>,
pipes: Vec<AngularPipe>,
dialogs: Vec<AngularComponent>,
}

impl AngularInspector {
Expand All @@ -46,7 +58,7 @@ impl AngularInspector {
// https://rustexp.lpil.uk/
lazy_static! {
static ref NAME_REGEX: Regex =
Regex::new(r#"@(?:Component|Directive|Injectable)\((?P<metadata>[^\)]+)\)"#)
Regex::new(r#"@(?:Component|Directive|Pipe|Injectable)\((?P<metadata>[^\)]+)\)"#)
.unwrap();
}

Expand Down Expand Up @@ -115,13 +127,13 @@ impl FileInspector for AngularInspector {

fn inspect_file(&mut self, options: &FileInspectorOptions, _output: &mut Map<String, Value>) {
let workspace_path = options.relative_path.display().to_string();
let content = options.read_content();

if workspace_path.ends_with(".module.ts") {
self.modules.push(AngularEntity {
path: workspace_path,
});
} else if workspace_path.ends_with(".component.ts") {
let content = options.read_content();
if content.contains("@Component(") {
let standalone = AngularInspector::is_standalone(&content);
self.components.push(AngularComponent {
Expand All @@ -130,20 +142,30 @@ impl FileInspector for AngularInspector {
});
}
} else if workspace_path.ends_with(".directive.ts") {
self.directives.push(AngularEntity {
path: workspace_path,
});
if content.contains("@Directive(") {
let standalone = AngularInspector::is_standalone(&content);
self.directives.push(AngularDirective {
path: workspace_path,
standalone,
});
}
} else if workspace_path.ends_with(".service.ts") {
self.services.push(AngularEntity {
path: workspace_path,
});
} else if workspace_path.ends_with(".pipe.ts") {
self.pipes.push(AngularEntity {
path: workspace_path,
});
} else if workspace_path.ends_with(".dialog.ts") {
self.dialogs.push(AngularEntity {
if content.contains("@Pipe(") {
let standalone = AngularInspector::is_standalone(&content);
self.pipes.push(AngularPipe {
path: workspace_path,
standalone,
});
}
} else if workspace_path.ends_with(".dialog.ts") && content.contains("@Component(") {
let standalone = AngularInspector::is_standalone(&content);
self.dialogs.push(AngularComponent {
path: workspace_path,
standalone,
});
}
}
Expand All @@ -170,16 +192,9 @@ impl FileInspector for AngularInspector {
.as_object_mut()
.unwrap();

let standalone_components = self
.components
.iter()
.filter(|entry| entry.standalone)
.count();

stats.entry("angular").or_insert(json!({
"module": self.modules.len(),
"component": self.components.len(),
"component_standalone": standalone_components,
"directive": self.directives.len(),
"service": self.services.len(),
"pipe": self.pipes.len(),
Expand All @@ -189,11 +204,7 @@ impl FileInspector for AngularInspector {
println!("Angular");
println!(" ├── Framework: {}", framework);
println!(" ├── Module: {}", self.modules.len());
println!(
" ├── Component: {} (standalone: {})",
self.components.len(),
standalone_components
);
println!(" ├── Component: {}", self.components.len());
println!(" ├── Directive: {}", self.directives.len());
println!(" ├── Service: {}", self.services.len());
println!(" ├── Pipe: {}", self.pipes.len());
Expand Down

0 comments on commit 197f81c

Please sign in to comment.