Skip to content

Commit

Permalink
feat: create analyzer
Browse files Browse the repository at this point in the history
  • Loading branch information
toureholder committed Aug 13, 2020
0 parents commit 1990fc4
Show file tree
Hide file tree
Showing 18 changed files with 5,731 additions and 0 deletions.
114 changes: 114 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@

# Created by https://www.toptal.com/developers/gitignore/api/node
# Edit at https://www.toptal.com/developers/gitignore?templates=node

### Node ###
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# TypeScript v1 declaration files
typings/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env
.env.test

# parcel-bundler cache (https://parceljs.org/)
.cache

# Next.js build output
.next

# Nuxt.js build / generate output
.nuxt
dist

# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public

# vuepress build output
.vuepress/dist

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# TernJS port file
.tern-port

# Stores VSCode versions used for testing VSCode extensions
.vscode-test

# End of https://www.toptal.com/developers/gitignore/api/node
1 change: 1 addition & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2020 Wiz Soluções

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
133 changes: 133 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
# SYZ Analyzer

Ferramenta CLI para analisar adesão de uma aplicação ao design system SYZ.

## Uso
```bash
# Install
npm i -g @wizsolucoes/syz-analyzer

# Run
syz-analyzer
```

## Como funciona
A analizador segue os seguintes passos:
1. Busca uma lista dos components do SYZ esperados para a aplicação sob análise,
2. Procura por tags html que correspondem aos componentes SYZ,
3. Publica a porcentagem dos components do SYZ esperados que foram encontrados para um repostório de dados,
4. Opcionalmente termina seu processo com código de erro se a porcentagem estiver abaixo de um treshold especificado, o que provocaria a quebra do build em um pipeline de CI.

## Options
### `--app`
**(Required)** Nome do respositório da aplicação a ser analisada.

```sh
$ syz-analyzer --app speed-web
```

### `--src`
Caminho para a pasta do código fonte a ser analizado. Default: "src"

```sh
$ syz-analyzer --src projects/speed-web/src
```

### `--gateway`
Porcentagem dos components do SYZ esperados que devem ser encontrados nos arquivos html para evitar a quebra do build. Default: 100

```sh
$ syz-analyzer --gateway 70
```

### `--break-build`
Booleano que determina se o build de CI deve se quebrar quando o `gateway` de adesão ao SYZ não for atingido. Default: false

```sh
$ syz-analyzer --break-build
```

### Exemplo completo
```sh
$ syz-analyzer --app speed-web --src projects/speed-web/src --gateway 70 --break-build
```

## Variáveis de ambiente
Você deve prover a url base para o serviço que vá buscar a lista de componentes esperados, bem como as informações para a conexão com a conta de storage da Azure para publicação dos resultados da análise com os seguintes variáveis de ambiente:

`SYZ_ANALYSIS_STORAGE_KEY` - Chave de accesso.

`SYZ_ANALYSIS_STORAGE_ACCOUNT` - Nome da conta de storage.

`SYZ_ANALYSIS_STORAGE_TABLE` - Nome da tabela da conta de storage.

`SYZ_ANALYSIS_COMPONENT_SERVICE_URL` - URL base para o serviço que vá buscar a lista de componentes esperados.

## OpenAPI Specification do serviço de componentes

### /

#### POST
##### Description

Get list of compomonents by repository name

##### Parameters

| Name | Located in | Description | Required | Schema |
| ---- | ---------- | ----------- | -------- | ---- |
| body | body | Object with name of repository | Yes | [compomonentsListRequest](#compomonentslistrequest) |

Example value
```json
{
"repository": "speed-web"
}
```

##### Responses

| Code | Description | Schema |
| ---- | ----------- | ------ |
| 200 | OK | [ [componentObj](#componentobj) ] |

Example value
```json
[
{
"Title": "wiz-alert"
},
{
"Title": "wiz-tabs"
}
]

```

### Models

#### compomonentsListRequest

| Name | Type | Description | Required |
| ---- | ---- | ----------- | -------- |
| repository | string | | No |

Example value
```json
{
"repository": "speed-web"
}
```

#### componentObj

| Name | Type | Description | Required |
| ---- | ---- | ----------- | -------- |
| Title | string | | No |

Example value
```json
{
"Title": "wiz-alert"
}
```
52 changes: 52 additions & 0 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Starter pipeline
# Start with a minimal pipeline that you can customize to build and deploy your code.
# Add steps that build, run tests, deploy, and more:
# https://aka.ms/yaml

trigger:
batch: 'true'

pool:
vmImage: 'ubuntu-latest'

stages:
- stage: Build
jobs:
- job: Build
displayName: 'Build Solution'
condition: succeeded()
steps:
- task: Npm@1
displayName: 'Install dependencies'
inputs:
command: 'install'
- task: Npm@1
displayName: 'Test'
inputs:
command: 'custom'
verbose: false
customCommand: 'test'
- stage: Publish
condition: and(succeeded(), eq(variables['build.sourceBranch'], 'refs/heads/master'))
dependsOn: [Build]
jobs:
- job: Publish
displayName: "Publish"
condition: succeeded()
steps:
- task: Npm@1
displayName: "Install dependencies"
inputs:
command: "install"
- task: Npm@1
displayName: "Test"
inputs:
command: "custom"
verbose: false
customCommand: "test"
- task: Npm@1
displayName: "Publish"
inputs:
command: "custom"
customCommand: "publish"
customEndpoint: "npmjs"
43 changes: 43 additions & 0 deletions docs/components-list-service-openapi.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
swagger: "2.0"
info:
version: 0.0.0
title: API Configuração
schemes:
- https
consumes:
- application/json
produces:
- application/json
tags:
- name: compomonents
paths:
/:
post:
tags:
- compomonents
description: Get list of compomonents by repository name
parameters:
- in: "body"
name: "body"
description: "Object with name of repository"
required: true
schema:
$ref: "#/definitions/compomonentsListRequest"
responses:
'200':
description: OK
schema:
type: array
items:
$ref: "#/definitions/componentObj"
definitions:
compomonentsListRequest:
type: object
properties:
repository:
type: string
componentObj:
type: object
properties:
Title:
type: string
11 changes: 11 additions & 0 deletions fake-app/src/component/component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
</head>
<body>
<button class="btn">Submit</button>
</body>
</html>
Loading

0 comments on commit 1990fc4

Please sign in to comment.