Skip to content
This repository has been archived by the owner on Oct 10, 2023. It is now read-only.

feat: add code for alizer npm package #27

Merged
merged 6 commits into from
Jul 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# This workflow will build a Java project with Maven
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven

name: Java CI with Maven
name: Java/Js CI
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
build:
build-java:
Copy link
Member

Choose a reason for hiding this comment

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

Seems the name of the workflow needs to be renamed as well


runs-on: ubuntu-latest

Expand Down Expand Up @@ -50,3 +50,21 @@ jobs:
restore-keys: ${{ runner.os }}-m2
- name: Build with Maven
run: mvn -B verify -Pnative -f java

build-js:

runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v2
- name: Use Node.js
uses: actions/setup-node@v1
with:
node-version: 14
- name: Install dependencies
run: npm install
working-directory: js
- name: Build
run: npm run test
working-directory: js
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,8 @@ nb-configuration.xml

# Local environment
.env

# node
lib/
node_modules/
.npmignore
53 changes: 53 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,59 @@ alizer-cli-$version-runner analyze [-o json] <path>
alizer-cli-$version-runner devfile [-o json] [-r registry-url] <path>
```

### NPM Package

Alizer also offers a NPM package providing helpers for recognize languages/frameworks in a project. It still doesn't support devfile selection.
The syntax is the following:

```
import * as recognizer from 'language-recognizer';

.....

const languages = await recognizer.detectLanguages('my_project_folder');

.....

```

### Outputs

Quarkus project output example

```
[
{ name: 'java', builder: 'maven', frameworks: [ 'quarkus' ] },
{ name: 'gcc machine description' }
]
```

SpringBoot project output example

```
[
{ name: 'java', builder: 'maven', frameworks: [ 'springboot' ] },
{ name: 'plsql' },
{ name: 'plpgsql' },
{ name: 'sqlpl' },
{ name: 'tsql' },
{ name: 'javascript' },
{ name: 'batchfile' },
{ name: 'gcc machine description' }
]
```

Django project output example

```
[
{ name: 'python', frameworks: [ 'django' ] },
{ name: 'gcc machine description' },
{ name: 'shell' }
]
```


Contributing
============
This is an open source project open to anyone. This project welcomes contributions and suggestions!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
******************************************************************************/
package com.redhat.devtools.alizer.api;

import java.io.File;
import org.junit.Before;
import org.junit.Test;

Expand All @@ -35,56 +36,56 @@ public void testMySelf() throws IOException {

@Test
public void testJAVAMetaDevFile() throws IOException {
DevfileType devFile = recognizer.selectDevFileFromTypes("src/test/resources/projects/micronaut", devfileTypes);
DevfileType devFile = recognizer.selectDevFileFromTypes(new File("../../resources/projects/micronaut").getCanonicalPath(), devfileTypes);
assertTrue(devFile.getName().equalsIgnoreCase("java-maven"));
}

@Test
public void testQuarkus() throws IOException {
List<Language> status = recognizer.analyze("src/test/resources/projects/quarkus");
List<Language> status = recognizer.analyze(new File("../../resources/projects/quarkus").getCanonicalPath());
assertTrue(status.stream().anyMatch(lang -> lang.getName().equalsIgnoreCase("JAVA")));
}

@Test
public void testQuarkusDevFileType() throws IOException {
DevfileType devFile = recognizer.selectDevFileFromTypes("src/test/resources/projects/quarkus", devfileTypes);
DevfileType devFile = recognizer.selectDevFileFromTypes(new File("../../resources/projects/quarkus").getCanonicalPath(), devfileTypes);
assertTrue(devFile.getName().equalsIgnoreCase("java-quarkus"));
}

@Test
public void testMicronaut() throws IOException {
List<Language> status = recognizer.analyze("src/test/resources/projects/micronaut");
List<Language> status = recognizer.analyze(new File("../../resources/projects/micronaut").getCanonicalPath());
assertTrue(status.stream().anyMatch(lang -> lang.getName().equalsIgnoreCase("JAVA")));
}

@Test
public void testMicronautDevFile() throws IOException {
DevfileType devFile = recognizer.selectDevFileFromTypes("src/test/resources/projects/micronaut", devfileTypes);
DevfileType devFile = recognizer.selectDevFileFromTypes(new File("../../resources/projects/micronaut").getCanonicalPath(), devfileTypes);
assertTrue(devFile.getName().equalsIgnoreCase("java-maven"));
}

@Test
public void testNode() throws IOException {
List<Language> status = recognizer.analyze("src/test/resources/projects/nodejs-ex");
List<Language> status = recognizer.analyze(new File("../../resources/projects/nodejs-ex").getCanonicalPath());
assertTrue(status.stream().anyMatch(lang -> lang.getName().equalsIgnoreCase("JavaScript")));
}

@Test
public void testNodeDevFile() throws IOException {
DevfileType devFile = recognizer.selectDevFileFromTypes("src/test/resources/projects/nodejs-ex", devfileTypes);
DevfileType devFile = recognizer.selectDevFileFromTypes(new File("../../resources/projects/nodejs-ex").getCanonicalPath(), devfileTypes);
assertTrue(devFile.getName().equalsIgnoreCase("nodejs"));
}


@Test
public void testDjango() throws IOException {
List<Language> status = recognizer.analyze("src/test/resources/projects/django");
List<Language> status = recognizer.analyze(new File("../../resources/projects/django").getCanonicalPath());
assertTrue(status.stream().anyMatch(lang -> lang.getName().equalsIgnoreCase("Python")));
}

@Test
public void testDjangoDevFile() throws IOException {
DevfileType devFile = recognizer.selectDevFileFromTypes("src/test/resources/projects/django", devfileTypes);
DevfileType devFile = recognizer.selectDevFileFromTypes(new File("../../resources/projects/django").getCanonicalPath(), devfileTypes);
assertTrue(devFile.getName().equalsIgnoreCase("python-django"));
}
}
Loading