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

Commit

Permalink
feat: add code for alizer npm package (#27)
Browse files Browse the repository at this point in the history
* add js project

Signed-off-by: Luca Stocchi <lstocchi@redhat.com>

* update README

Signed-off-by: Luca Stocchi <lstocchi@redhat.com>

* remove hardcoded path

Signed-off-by: Luca Stocchi <lstocchi@redhat.com>

* add tests

Signed-off-by: Luca Stocchi <lstocchi@redhat.com>

* add step in CI workflow for js

Signed-off-by: Luca Stocchi <lstocchi@redhat.com>

* fix js workflow

Signed-off-by: Luca Stocchi <lstocchi@redhat.com>
  • Loading branch information
lstocchi authored Jul 2, 2021
1 parent 7678de7 commit 565736c
Show file tree
Hide file tree
Showing 95 changed files with 9,095 additions and 11 deletions.
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:

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

0 comments on commit 565736c

Please sign in to comment.