Skip to content

Commit

Permalink
Merge pull request #37 from pipelinit/fix/vue-stack
Browse files Browse the repository at this point in the history
fix: adjust html stack vue identification
  • Loading branch information
oesgalha authored Sep 22, 2021
2 parents 408deeb + aec266a commit 8f0cdb5
Show file tree
Hide file tree
Showing 9 changed files with 98 additions and 16 deletions.
23 changes: 23 additions & 0 deletions core/plugins/stack/html/frameworks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { IntrospectFn } from "../../../types.ts";
import { introspect as instrospectVue } from "./vue.ts";

// deno-lint-ignore no-empty-interface
interface Vue {}

export type Frameworks = {
vue?: Vue;
};

export const introspect: IntrospectFn<Frameworks> = async (context) => {
const logger = context.getLogger("html");
const frameworks: Frameworks = {};
logger.debug("detecting linter");

const isVue = await instrospectVue(context);
if (isVue) {
logger.debug("detected Vue.Js");
frameworks.vue = {};
}

return frameworks;
};
17 changes: 13 additions & 4 deletions core/plugins/stack/html/mod.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ import { assertEquals, context, deepMerge } from "../../../tests/mod.ts";

import { introspector } from "./mod.ts";

const fakeContext = () => {
const fakeContext = (
{
isVue = false,
} = {},
) => {
return deepMerge(
context,
{
Expand All @@ -13,6 +17,9 @@ const fakeContext = () => {
if (glob === "**/.eslintrc.{js,cjs,yaml,yml,json}") {
return true;
}
if (glob === "**/*.vue" && isVue) {
return true;
}
return false;
},
each: async function* (glob: string): AsyncIterableIterator<FileEntry> {
Expand Down Expand Up @@ -61,7 +68,7 @@ const fakeContext = () => {

Deno.test("Plugins > Html has stylelint and eslint configured", async () => {
const result = await introspector.introspect(
fakeContext(),
fakeContext({ isVue: true }),
);

assertEquals(result, {
Expand All @@ -77,12 +84,13 @@ Deno.test("Plugins > Html has stylelint and eslint configured", async () => {
styleLint: { name: "stylelint" },
},
formatters: { prettier: { name: "prettier", hasIgnoreFile: false } },
frameworks: { vue: {} },
});
});

Deno.test("Plugins > Html has stylelint and eslint configured", async () => {
Deno.test("Plugins > Html has stylelint and eslint configured and not Vue", async () => {
const result = await introspector.introspect(
fakeContext(),
fakeContext({ isVue: false }),
);

assertEquals(result, {
Expand All @@ -98,5 +106,6 @@ Deno.test("Plugins > Html has stylelint and eslint configured", async () => {
styleLint: { name: "stylelint" },
},
formatters: { prettier: { name: "prettier", hasIgnoreFile: false } },
frameworks: {},
});
});
15 changes: 15 additions & 0 deletions core/plugins/stack/html/mod.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import { Introspector } from "../../../types.ts";
import { Formatters, introspect as introspectFormatter } from "./formatters.ts";
import { introspect as introspectLinter, Linters } from "./linters.ts";
import {
Frameworks,
introspect as introspectFrameworks,
} from "./frameworks.ts";

import {
introspect as introspectRuntime,
Runtime,
Expand Down Expand Up @@ -37,6 +42,10 @@ export default interface HtmlProject {
* Which formatter the project uses, if any
*/
formatters: Formatters;
/**
* Which framework the project uses, if any
*/
frameworks: Frameworks;
}

export const introspector: Introspector<HtmlProject> = {
Expand All @@ -59,6 +68,7 @@ export const introspector: Introspector<HtmlProject> = {
formatters: {
deno: {},
},
frameworks: {},
};
}

Expand All @@ -71,11 +81,16 @@ export const introspector: Introspector<HtmlProject> = {
logger.debug(`detecting linters for html`);
const formatters = await introspectFormatter(context);

// Check if project frameworks
logger.debug(`detecting web frameworks`);
const frameworks = await introspectFrameworks(context);

return {
runtime,
packageManager,
linters,
formatters,
frameworks,
};
},
};
6 changes: 6 additions & 0 deletions core/plugins/stack/html/vue.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { IntrospectFn } from "../../../types.ts";

export const introspect: IntrospectFn<boolean> = async (context) => {
// Search for any .vue file
return await context.files.includes("**/*.vue");
};
22 changes: 22 additions & 0 deletions core/plugins/stack/python/frameworks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { IntrospectFn } from "../../../types.ts";
import { introspect as instrospectDjango } from "./django.ts";

// deno-lint-ignore no-empty-interface
interface Django {}

export type Frameworks = {
django?: Django;
};

export const introspect: IntrospectFn<Frameworks> = async (context) => {
const frameworks: Frameworks = {};
const logger = context.getLogger("python");

const isDjango = await instrospectDjango(context);
if (isDjango) {
logger.debug("detected Django");
frameworks.django = {};
}

return frameworks;
};
6 changes: 4 additions & 2 deletions core/plugins/stack/python/mod.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ Deno.test("Plugins > Check if python version and django project is identified",

assertEquals(result, {
version: "3.6",
isDjango: true,
frameworks: {
django: {},
},
});
});

Expand All @@ -60,6 +62,6 @@ Deno.test("Plugins > Check if python version and a non-django-project", async ()

assertEquals(result, {
version: "3.6",
isDjango: false,
frameworks: {},
});
});
21 changes: 13 additions & 8 deletions core/plugins/stack/python/mod.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { Introspector } from "../../../types.ts";
import { introspect as introspectVersion } from "./version.ts";
import { introspect as introspectDjango } from "./django.ts";
import {
Frameworks,
introspect as introspectFrameworks,
} from "./frameworks.ts";

/**
* Introspected information about a project with Python
Expand All @@ -11,9 +14,9 @@ export default interface PythonProject {
*/
version?: string;
/**
* If is a Django project
* List of possible project frameworks
*/
isDjango?: boolean;
frameworks?: Frameworks;
}

export const introspector: Introspector<PythonProject | undefined> = {
Expand All @@ -32,14 +35,16 @@ export const introspector: Introspector<PythonProject | undefined> = {
}
logger.debug(`detected version ${version}`);

// Django
const django = await introspectDjango(context);
if (django) {
logger.debug("detected Django project");
// Search python frameworks
logger.debug("detecting frameworks");
const frameworks = await introspectFrameworks(context);
if (frameworks === undefined) {
logger.debug("didn't detect any know python framework");
}

return {
version: version,
isDjango: django,
frameworks: frameworks,
};
},
};
2 changes: 1 addition & 1 deletion core/templates/github/html/lint.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<% if (it.runtime.name === "node" && it.linters) { -%>
<% if (it.runtime.name === "node" && it.linters && it.frameworks.vue) { -%>
name: Lint Vue
on:
pull_request:
Expand Down
2 changes: 1 addition & 1 deletion core/templates/github/python/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
python -m pip install --upgrade pip
pip install pytest
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
<%_ if (it.django) { %>
<%_ if (it.frameworks.django) { %>
- name: Run Tests
run: |
python manage.py test
Expand Down

0 comments on commit 8f0cdb5

Please sign in to comment.