Skip to content
Open
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
5 changes: 4 additions & 1 deletion bin/supported
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
#!/usr/bin/env node
'use strict';
const ora = require('ora');
const { setUpHTMLOutput } = require('../lib/html-report');

(async function main(cli) {
if (cli.input.length === 0) {
cli.showHelp(1);
} else {
const isInSupportWindow = require('../lib/project');
const [projectPath] = cli.input;
let [projectPath] = cli.input;

const spinner = ora('working').start();
let result;
Expand All @@ -30,6 +31,8 @@ const ora = require('ora');
2,
),
);
} else {
setUpHTMLOutput(result, projectPath);
}
}
})(require('meow')(require('../lib/help'), {}));
94 changes: 94 additions & 0 deletions lib/html-report.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
'use strict';

const fs = require('fs');
const terminalLink = require('terminal-link');
const path = require('path');

function setUpHTMLOutput(supportResult, projectPath) {
const { projectName } = supportResult;
delete supportResult.projectName;
let resultPath = `${projectPath}/supported`;
fs.mkdirSync(resultPath);
let indexHtml = `${resultPath}/index.html`;
fs.writeFileSync(indexHtml, writeToHtml(projectName, supportResult), 'utf-8');
fs.copyFileSync('vendor/jput.min.js', `${resultPath}/jput.min.js`);
fs.copyFileSync('vendor/jquery.js', `${resultPath}/jquery.js`);
fs.writeFileSync(`${resultPath}/result.json`, JSON.stringify(
{ ...supportResult, project: { name: projectName, path: projectPath, type: 'node_module' } },
null,
2,
));
const link = terminalLink(path.resolve(indexHtml), path.resolve(indexHtml));
console.log(`Visit ${link} to see the result`);
}

function writeToHtml(projectName, supportResult) {
return `<html>
<script src="./jquery.js"></script>
<script src="./jput.min.js"></script>
<script>
let data = ${JSON.stringify(supportResult)};
$(document).ready(function(){
jPut.result.data = data.supportChecks;
});
function filterResult(ev) {
let selected = ev.target.value;
let filteredList = data.supportChecks;
if (ev.target.value !== 'all') {
let selectedFilter = ev.target.value == "true";
filteredList = data.supportChecks.filter(ele => ele.isSupported == selectedFilter);
}
jPut.result.clear();
jPut.result.data = filteredList;
}
</script>
<style>
.supported {
background-color: limegreen;
}
.not-supported {
background-color: #F08080;
}
table {
margin: auto;
}
td {
padding: 4px;
}
.top {
width: 50%;
margin: auto;
}
</style>
<div class="top">
<h1>Support for ${projectName}</h1>
<select name="support" id="support" onchange="filterResult(event);">
<option value="all">All</option>
<option value="true">Supported</option>
<option value="false">Not supported</option>

</select>
</div>
<table border="1">
<thead>
<tr>
<td>isSupported</td>
<td>Name </td>
<td>Resolved Version</td>
<td>Message</td>
</tr>
</thead>
<tbody jput="result" jput-jsondata='[]'>
<tr class="{{json.isSupported == true ? 'supported': 'not-supported'}}">
<td>{{json.isSupported}}</td>
<td>{{json.name}}</td>
<td>{{json.resolvedVersion}}</td>
<td>{{json.message ? json.message : ""}}</td>
</tr>
</tbody>
</table>
</html>
`
}

module.exports = { writeToHtml, setUpHTMLOutput };
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"eslint-plugin-mocha": "^8.0.0",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^3.1.4",
"fs-extra": "^9.1.0",
"get-bin-path": "^5.1.0",
"koa": "^2.13.0",
"koa-logger": "^3.2.1",
Expand Down
37 changes: 33 additions & 4 deletions tests/cli-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,17 @@

const { expect } = require('chai');
const execa = require('execa');
const fs = require('fs-extra');
const { getBinPath } = require('get-bin-path');
const registries = require('./registries');

let FILE_LIST = [
'/supported/index.html',
'/supported/jput.min.js',
'/supported/jquery.js',
'/supported/result.json',
]

describe('CLI', function () {
beforeEach(function () {
registries.startAll();
Expand All @@ -24,25 +32,46 @@ describe('CLI', function () {
expect(child.stdout).to.match(/supported/);
});

function checkFileExists(projectPath) {
FILE_LIST.forEach((file) => {
expect(fs.existsSync(`${projectPath}${file}`));
});
}

describe('default output', function () {
let projectPath = '';
afterEach(() => {
if (projectPath) {
fs.removeSync(`${projectPath}/supported`);
}
});

it('works against a fully supported project', async function () {
const child = await execa(await getBinPath(), [`${__dirname}/fixtures/supported-project`], {
projectPath = `${__dirname}/fixtures/supported-project`;
const child = await execa(await getBinPath(), [projectPath], {
shell: true,
reject: false,
});
expect(child.exitCode).to.eql(0);
expect(child.stderr).to.eql('- working');
expect(child.stdout).to.eql('');
expect(child.stdout).to.eql(
`Visit ${projectPath}/supported/index.html (​${projectPath}/supported/index.html​) to see the result`
);
checkFileExists(projectPath);
});

it('works against a unsupported project', async function () {
const child = await execa(await getBinPath(), [`${__dirname}/fixtures/unsupported-project`], {
projectPath = `${__dirname}/fixtures/unsupported-project`;
const child = await execa(await getBinPath(), [projectPath], {
shell: true,
reject: false,
});
expect(child.exitCode).to.eql(1);
expect(child.stderr).to.eql('- working');
expect(child.stdout).to.eql('');
expect(child.stdout).to.eql(
`Visit ${projectPath}/supported/index.html (​${projectPath}/supported/index.html​) to see the result`
);
checkFileExists(projectPath);
});
});

Expand Down
39 changes: 39 additions & 0 deletions tests/html-report-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
'use strict';

const chai = require('chai');
const { expect } = chai;
const { writeToHtml } = require('../lib/html-report');

describe('Test generated HTML', function () {
it('generates a valid html', function () {
let dataJson = {
"supportChecks": [
{
"isSupported": true,
"name": "terminal-link",
"resolvedVersion": "2.1.1"
},
{
"isSupported": true,
"name": "semver",
"resolvedVersion": "7.3.4"
},
{
"isSupported": true,
"name": "resolve-path",
"resolvedVersion": "1.4.0"
},
{
"isSupported": true,
"name": "prettier",
"resolvedVersion": "2.2.0"
}
]
};
let projectName = 'test-app';
let htmlContent = writeToHtml(projectName, dataJson);
expect(htmlContent).to.include(`<script src="./jquery.js"></script>`);
expect(htmlContent).to.include(`<script src="./jput.min.js"></script>`);
expect(htmlContent).to.include(` <h1>Support for ${projectName}</h1>`);
});
});
8 changes: 8 additions & 0 deletions vendor/jput.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions vendor/jquery.js

Large diffs are not rendered by default.

31 changes: 30 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,11 @@ astral-regex@^1.0.0:
resolved "https://registry.yarnpkg.com/astral-regex/-/astral-regex-1.0.0.tgz#6c8c3fb827dd43ee3918f27b82782ab7658a6fd9"
integrity sha512-+Ryf6g3BKoRc7jfp7ad8tM4TtMiaWvbF/1/sQcZPkkS7ag3D5nMBCe2UfOTONtAkaG0tO0ij3C5Lwmf1EiyjHg==

at-least-node@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/at-least-node/-/at-least-node-1.0.0.tgz#602cd4b46e844ad4effc92a8011a3c46e0238dc2"
integrity sha512-+q/t7Ekv1EDY2l6Gda6LLiX14rU9TV20Wa3ofeQmwPFZbOMo9DXrLbOjFaaclkXKWidIaopwAObQDqwWtGUjqg==

balanced-match@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-1.0.0.tgz#89b4d199ab2bee49de164ea02b89ce462d71b767"
Expand Down Expand Up @@ -912,6 +917,16 @@ fresh@~0.5.2:
resolved "https://registry.yarnpkg.com/fresh/-/fresh-0.5.2.tgz#3d8cadd90d976569fa835ab1f8e4b23a105605a7"
integrity sha1-PYyt2Q2XZWn6g1qx+OSyOhBWBac=

fs-extra@^9.1.0:
version "9.1.0"
resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-9.1.0.tgz#5954460c764a8da2094ba3554bf839e6b9a7c86d"
integrity sha512-hcg3ZmepS30/7BSFqRvoo3DOMQu7IjqxO5nCDt+zM9XWjb33Wg7ziNT+Qvqbuc3+gWpzO02JubVyk2G4Zvo1OQ==
dependencies:
at-least-node "^1.0.0"
graceful-fs "^4.2.0"
jsonfile "^6.0.1"
universalify "^2.0.0"

fs-minipass@^2.0.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/fs-minipass/-/fs-minipass-2.1.0.tgz#7f5036fdbf12c63c169190cbe4199c852271f9fb"
Expand Down Expand Up @@ -1002,7 +1017,7 @@ globals@^12.1.0:
dependencies:
type-fest "^0.8.1"

graceful-fs@^4.1.2:
graceful-fs@^4.1.2, graceful-fs@^4.1.6, graceful-fs@^4.2.0:
version "4.2.4"
resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.2.4.tgz#2256bde14d3632958c465ebc96dc467ca07a29fb"
integrity sha512-WjKPNJF79dtJAVniUlGGWHYGz2jWxT6VhN/4m1NdkbZ2nOsEF+cI1Edgql5zCRhs/VsQYRvrXctxktVXZUkixw==
Expand Down Expand Up @@ -1341,6 +1356,15 @@ json-stable-stringify-without-jsonify@^1.0.1:
resolved "https://registry.yarnpkg.com/json-stable-stringify-without-jsonify/-/json-stable-stringify-without-jsonify-1.0.1.tgz#9db7b59496ad3f3cfef30a75142d2d930ad72651"
integrity sha1-nbe1lJatPzz+8wp1FC0tkwrXJlE=

jsonfile@^6.0.1:
version "6.1.0"
resolved "https://registry.yarnpkg.com/jsonfile/-/jsonfile-6.1.0.tgz#bc55b2634793c679ec6403094eb13698a6ec0aae"
integrity sha512-5dgndWOriYSm5cnYaJNhalLNDKOqFwyDB/rr1E9ZsGciGvKPs8R2xYGCacuf3z6K1YKDz182fd+fY3cn3pMqXQ==
dependencies:
universalify "^2.0.0"
optionalDependencies:
graceful-fs "^4.1.6"

jsonparse@^1.3.1:
version "1.3.1"
resolved "https://registry.yarnpkg.com/jsonparse/-/jsonparse-1.3.1.tgz#3f4dae4a91fac315f71062f8521cc239f1366280"
Expand Down Expand Up @@ -2591,6 +2615,11 @@ unique-slug@^2.0.0:
dependencies:
imurmurhash "^0.1.4"

universalify@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/universalify/-/universalify-2.0.0.tgz#75a4984efedc4b08975c5aeb73f530d02df25717"
integrity sha512-hAZsKq7Yy11Zu1DE0OzWjw7nnLZmJZYTDZZyEFHZdUhV8FkH5MCfoU1XMaxXovpyW5nq5scPqq0ZDP9Zyl04oQ==

uri-js@^4.2.2:
version "4.4.0"
resolved "https://registry.yarnpkg.com/uri-js/-/uri-js-4.4.0.tgz#aa714261de793e8a82347a7bcc9ce74e86f28602"
Expand Down