Skip to content

Commit

Permalink
chore: better tests for JavaScript and Vue, also ESLint is now option…
Browse files Browse the repository at this point in the history
…al to install
  • Loading branch information
Kocal committed Feb 26, 2019
1 parent 44378e1 commit 286e19f
Show file tree
Hide file tree
Showing 23 changed files with 537 additions and 3,459 deletions.
10 changes: 9 additions & 1 deletion docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,15 @@
## Installation

```bash
$ yarn add --dev @yproximite/yprox-cli 'eslint@>=5.0.0' 'vue-template-compiler@>=2.0.0'
$ yarn add --dev @yproximite/yprox-cli 'vue-template-compiler@>=2.0.0'
```

### Linting JavaScript

If you plan to use yProx-CLI to lint your JavaScript, you need to install ESLint too:

```bash
$ yarn add --dev 'eslint@>=5.0.0'
```

### Linting CSS and Sass
Expand Down
12 changes: 9 additions & 3 deletions lib/commands/lint/linters/js.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CLIEngine } from 'eslint';
import API from '../../../API';
import { isPackageInstalled } from '../../../utils/package';

export default (api: API, args: CLIArgs, files: string[]): Promise<any> => {
const config = {
Expand All @@ -8,9 +8,15 @@ export default (api: API, args: CLIArgs, files: string[]): Promise<any> => {
extensions: api.projectOptions.eslint.extensions,
};

api.logger.log(`js (lint) :: linting ${JSON.stringify(files, null, 2)}`);

return new Promise((resolve, reject) => {
if (!isPackageInstalled('eslint', api)) {
api.logger.info('Linting JavaScript requires to install "eslint" dependency.');
return resolve();
}

const { CLIEngine } = require('eslint');
api.logger.log(`js (lint) :: linting ${JSON.stringify(files, null, 2)}`);

const engine = new CLIEngine(config);
const report = engine.executeOnFiles(files);
const formatter = engine.getFormatter('codeframe');
Expand Down
3 changes: 2 additions & 1 deletion lib/utils/entry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ export function getEntryName(entry: Entry) {
return entry.name || entry.destFile || entry.concat || entry.src.join(', ');
}

export function readEntries(api: API, args: CLIArgs) {
export function readEntries(api: API, args: CLIArgs): Entry[] {
let entries: Entry[] = [];

if (typeof api.projectOptions.assets === 'undefined') {
api.logger.error('No assets have been configured.');
api.logger.error('See the documentation (https://yprox-cli.netlify.com/configuration.html#configuration) to know to do it!');
process.exit(1);
// @ts-ignore
return;
}

Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@
"@types/rollup-plugin-json": "^3.0.1",
"@types/stylelint": "^9.4.1",
"babel-core": "^7.0.0-bridge.0",
"eslint": "^5.11.0",
"fs-extra": "^7.0.1",
"husky": "^1.3.1",
"jest": "^23.6.0",
Expand Down
21 changes: 21 additions & 0 deletions test/fixtures/javascript/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"private": true,
"yproxCli": {
"buble": {
"objectAssign": true
},
"assets": {
"app": [
{
"handler": "js",
"src": [
"src/hello-world.js",
"src/es6.js"
],
"dest": "dist",
"concat": "scripts.js"
}
]
}
}
}
16 changes: 16 additions & 0 deletions test/fixtures/javascript/src/es6.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const constant = 'abc';
console.log(`The constant value: ${constant}`);

let arr = [1, 2, 3];
arr = [...arr];

let obj = { a: '1', b: '2', c: '3' };
obj = { ...obj };

const myFunction = (arg1, arg2, ...otherArgs) => {
console.log({
arg1,
arg2,
otherArgs,
});
};
1 change: 1 addition & 0 deletions test/fixtures/javascript/src/hello-world.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log('Hello world from!');;
1 change: 0 additions & 1 deletion test/fixtures/modern-project/.eslintignore

This file was deleted.

10 changes: 0 additions & 10 deletions test/fixtures/modern-project/.eslintrc

This file was deleted.

5 changes: 0 additions & 5 deletions test/fixtures/modern-project/.stylelintrc

This file was deleted.

44 changes: 0 additions & 44 deletions test/fixtures/modern-project/package.json

This file was deleted.

1 change: 0 additions & 1 deletion test/fixtures/modern-project/src/js/bar.js

This file was deleted.

4 changes: 0 additions & 4 deletions test/fixtures/modern-project/src/js/foo.js

This file was deleted.

Loading

0 comments on commit 286e19f

Please sign in to comment.