aberlaas 2.0.0 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -3
- package/bin/{aberlaas → aberlaas.js} +1 -1
- package/commands/ci/autoRelease.js +9 -8
- package/commands/ci/index.js +10 -10
- package/commands/compress/index.js +6 -6
- package/commands/compress/png.js +5 -5
- package/commands/{init.js → init/index.js} +47 -31
- package/commands/lint/circleci.js +10 -11
- package/commands/lint/css.js +12 -10
- package/commands/lint/helpers/prettier.js +29 -0
- package/commands/lint/index.js +18 -48
- package/commands/lint/js.js +40 -51
- package/commands/lint/json.js +11 -10
- package/commands/lint/yml.js +13 -11
- package/commands/{precommit.js → precommit/index.js} +7 -7
- package/commands/readme/index.js +16 -16
- package/commands/{release.js → release/index.js} +5 -6
- package/commands/setup/autoRelease/envVars.js +9 -8
- package/commands/setup/autoRelease/index.js +12 -11
- package/commands/setup/autoRelease/privateKey.js +6 -5
- package/commands/setup/autoRelease/publicKey.js +8 -7
- package/commands/setup/circleci.js +9 -8
- package/commands/setup/github.js +6 -5
- package/commands/setup/helpers/circleci.js +6 -5
- package/commands/setup/helpers/github.js +6 -5
- package/commands/setup/helpers/npm.js +1 -1
- package/commands/setup/helpers/ssh.js +11 -10
- package/commands/setup/index.js +6 -6
- package/commands/setup/renovate.js +7 -6
- package/commands/test/index.js +84 -0
- package/configs/{eslint.js → eslint.cjs} +63 -30
- package/configs/jest/{index.js → index.cjs} +13 -10
- package/configs/jest/{testEnvironment.js → testEnvironment.cjs} +1 -1
- package/configs/jest.cjs +1 -0
- package/configs/{lintstaged.js → lintstaged.cjs} +1 -1
- package/configs/node.cjs +5 -0
- package/configs/vite/test/setupFiles/captureOutput.js +4 -0
- package/configs/vite/test/setupFiles/dedent.js +4 -0
- package/configs/vite/test/setupFiles/fit-xit-fdescribe-xdescribe.js +13 -0
- package/configs/vite/test/setupFiles/jest-extended.js +10 -0
- package/configs/vite/test/setupFiles/testName.js +9 -0
- package/configs/vite.js +25 -0
- package/helper.js +37 -39
- package/main.js +28 -22
- package/package.json +33 -21
- package/scripts/postinstall +15 -0
- package/templates/_circleci/config.yml +1 -1
- package/templates/_eslintignore.conf +1 -1
- package/templates/_eslintrc.cjs +3 -0
- package/templates/_lintstagedrc.cjs +4 -0
- package/templates/_prettierrc.cjs +4 -0
- package/templates/_stylelintrc.cjs +4 -0
- package/templates/jest.config.cjs +4 -0
- package/templates/lib/__tests__/main.js +2 -2
- package/templates/lib/main.js +1 -1
- package/templates/scripts/hooks/pre-commit +11 -0
- package/templates/vite.config.js +4 -0
- package/commands/test.js +0 -92
- package/configs/husky.js +0 -5
- package/configs/jest.js +0 -1
- package/configs/node.js +0 -3
- package/lib/configs/deprecated.js +0 -17
- package/lib/configs/eslint.js +0 -2
- package/lib/configs/husky.js +0 -2
- package/lib/configs/jest.js +0 -2
- package/lib/configs/lintstaged.js +0 -2
- package/lib/configs/prettier.js +0 -2
- package/lib/configs/stylelint.js +0 -2
- package/templates/_eslintrc.js +0 -3
- package/templates/_huskyrc.js +0 -4
- package/templates/_lintstagedrc.js +0 -4
- package/templates/_prettierrc.js +0 -4
- package/templates/_stylelintrc.js +0 -4
- package/templates/babel.config.js +0 -3
- package/templates/jest.config.js +0 -4
- package/templates/scripts/husky-precommit +0 -4
- /package/configs/jest/{jest-extended.js → jest-extended.cjs} +0 -0
- /package/configs/jest/{setupFileAfterEnv.js → setupFileAfterEnv.cjs} +0 -0
- /package/configs/jest/{sharedState.js → sharedState.cjs} +0 -0
- /package/configs/{prettier.js → prettier.cjs} +0 -0
- /package/configs/{stylelint.js → stylelint.cjs} +0 -0
package/README.md
CHANGED
|
@@ -51,7 +51,6 @@ The following table lists all the scripts added:
|
|
|
51
51
|
|
|
52
52
|
| Script | Description |
|
|
53
53
|
| -------------------------- | --------------------------------------------------------- |
|
|
54
|
-
| `yarn run husky:precommit` | Run before any commit (through Husky) |
|
|
55
54
|
| `yarn run test` | Run tests using Jest |
|
|
56
55
|
| `yarn run test:watch` | Run tests using Jest in watch mode |
|
|
57
56
|
| `yarn run ci` | Run testing and linting in CI |
|
|
@@ -111,7 +110,7 @@ describe('moduleName', () => {
|
|
|
111
110
|
|
|
112
111
|
## Precommit hooks
|
|
113
112
|
|
|
114
|
-
`aberlaas` uses `
|
|
113
|
+
`aberlaas` uses `lint-staged` to make sure all committed code
|
|
115
114
|
follows your coding standard.
|
|
116
115
|
|
|
117
116
|
All `css`, `js`, `json` and `yml` files will be checked for parsing errors
|
|
@@ -189,7 +188,7 @@ exported by the package and thus can be `require`d in userland.
|
|
|
189
188
|
extends the configuration exported in the previous files. Copying files to
|
|
190
189
|
userland allows user to change the files if they want to change the behavior.
|
|
191
190
|
|
|
192
|
-
`.eslintrc.js`, `.stylelintrc.js
|
|
191
|
+
`.eslintrc.js`, `.stylelintrc.js` and `jest.config.js` are local
|
|
193
192
|
configuration files for `aberlaas` itself. They eat their own dog food by
|
|
194
193
|
referencing the same configs as above.
|
|
195
194
|
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import release from '../release/index.js';
|
|
2
|
+
import consoleInfo from 'firost/consoleInfo.js';
|
|
3
|
+
import _ from 'golgoth/lodash.js';
|
|
4
|
+
import run from 'firost/run.js';
|
|
5
|
+
import write from 'firost/write.js';
|
|
6
|
+
import exists from 'firost/exists.js';
|
|
7
|
+
import helper from '../../helper.js';
|
|
8
|
+
|
|
9
|
+
export default {
|
|
9
10
|
/**
|
|
10
11
|
* Run a git command in the repo
|
|
11
12
|
*
|
package/commands/ci/index.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import helper from '../../helper.js';
|
|
2
|
+
import ciInfo from 'ci-info';
|
|
3
|
+
import _ from 'golgoth/lodash.js';
|
|
4
|
+
import pMap from 'golgoth/pMap.js';
|
|
5
|
+
import readJson from 'firost/readJson.js';
|
|
6
|
+
import run from 'firost/run.js';
|
|
7
|
+
import consoleInfo from 'firost/consoleInfo.js';
|
|
8
|
+
import autoRelease from './autoRelease.js';
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
export default {
|
|
11
11
|
/**
|
|
12
12
|
* Return the value of an environment variable
|
|
13
13
|
* @param {string} key Name of the variable
|
|
@@ -112,7 +112,7 @@ module.exports = {
|
|
|
112
112
|
|
|
113
113
|
await helper.yarnRun(command);
|
|
114
114
|
},
|
|
115
|
-
{ concurrency: 1 }
|
|
115
|
+
{ concurrency: 1 },
|
|
116
116
|
);
|
|
117
117
|
|
|
118
118
|
// Attempt to release the package if --auto-release is set
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import _ from 'golgoth/lodash.js';
|
|
2
|
+
import pMap from 'golgoth/pMap.js';
|
|
3
|
+
import consoleError from 'firost/consoleError.js';
|
|
4
|
+
import firostError from 'firost/error.js';
|
|
5
|
+
import helper from '../../helper.js';
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
export default {
|
|
8
8
|
types: {
|
|
9
9
|
png: './png.js',
|
|
10
10
|
},
|
package/commands/compress/png.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import lint from './index.js';
|
|
2
|
+
import run from 'firost/run.js';
|
|
3
|
+
import which from 'firost/which.js';
|
|
4
|
+
import firostError from 'firost/error.js';
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
export default {
|
|
7
7
|
/**
|
|
8
8
|
* Find the png files to compress
|
|
9
9
|
* @param {Array} userPatterns Patterns to narrow the search down
|
|
@@ -1,19 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
1
|
+
import _ from 'golgoth/lodash.js';
|
|
2
|
+
import pMapSeries from 'golgoth/pMapSeries.js';
|
|
3
|
+
import isFile from 'firost/isFile.js';
|
|
4
|
+
import copy from 'firost/copy.js';
|
|
5
|
+
import readJson from 'firost/readJson.js';
|
|
6
|
+
import writeJson from 'firost/writeJson.js';
|
|
7
|
+
import exists from 'firost/exists.js';
|
|
8
|
+
import read from 'firost/read.js';
|
|
9
|
+
import write from 'firost/write.js';
|
|
10
|
+
import run from 'firost/run.js';
|
|
11
|
+
import spinner from 'firost/spinner.js';
|
|
12
|
+
import helper from '../../helper.js';
|
|
13
|
+
import path from 'path';
|
|
14
|
+
import nodeConfig from '../../configs/node.cjs';
|
|
15
|
+
import consoleInfo from 'firost/consoleInfo.js';
|
|
16
|
+
import Gilmore from 'gilmore';
|
|
17
|
+
|
|
18
|
+
export default {
|
|
17
19
|
/**
|
|
18
20
|
* Copy a config template to the host
|
|
19
21
|
* @param {string} source Path to source file, relative to aberlaas
|
|
@@ -44,34 +46,31 @@ module.exports = {
|
|
|
44
46
|
**/
|
|
45
47
|
async addConfigFiles() {
|
|
46
48
|
// ESLint
|
|
47
|
-
await this.copyToHost('templates/_eslintrc.
|
|
49
|
+
await this.copyToHost('templates/_eslintrc.cjs', '.eslintrc.cjs');
|
|
48
50
|
await this.copyToHost('templates/_eslintignore.conf', '.eslintignore');
|
|
49
51
|
|
|
50
|
-
// Husky
|
|
51
|
-
await this.copyToHost('templates/_huskyrc.js', '.huskyrc.js');
|
|
52
|
-
|
|
53
52
|
// Lint-staged
|
|
54
|
-
await this.copyToHost('templates/_lintstagedrc.
|
|
53
|
+
await this.copyToHost('templates/_lintstagedrc.cjs', '.lintstagedrc.cjs');
|
|
55
54
|
|
|
56
|
-
//
|
|
57
|
-
await this.copyToHost('templates/
|
|
55
|
+
// Vite
|
|
56
|
+
await this.copyToHost('templates/vite.config.js', 'vite.config.js');
|
|
58
57
|
|
|
59
58
|
// Prettier
|
|
60
|
-
await this.copyToHost('templates/_prettierrc.
|
|
59
|
+
await this.copyToHost('templates/_prettierrc.cjs', '.prettierrc.cjs');
|
|
61
60
|
|
|
62
61
|
// Stylelint
|
|
63
|
-
await this.copyToHost('templates/_stylelintrc.
|
|
62
|
+
await this.copyToHost('templates/_stylelintrc.cjs', '.stylelintrc.cjs');
|
|
64
63
|
|
|
65
64
|
// Renovate
|
|
66
65
|
await this.copyToHost(
|
|
67
66
|
'templates/_github/renovate.json',
|
|
68
|
-
'.github/renovate.json'
|
|
67
|
+
'.github/renovate.json',
|
|
69
68
|
);
|
|
70
69
|
|
|
71
70
|
// CircleCI
|
|
72
71
|
await this.copyToHost(
|
|
73
72
|
'templates/_circleci/config.yml',
|
|
74
|
-
'.circleci/config.yml'
|
|
73
|
+
'.circleci/config.yml',
|
|
75
74
|
);
|
|
76
75
|
},
|
|
77
76
|
/**
|
|
@@ -95,7 +94,7 @@ module.exports = {
|
|
|
95
94
|
const newPackage = _.set(
|
|
96
95
|
_.clone(currentPackage),
|
|
97
96
|
`scripts.${scriptName}`,
|
|
98
|
-
`./${scriptPath}
|
|
97
|
+
`./${scriptPath}`,
|
|
99
98
|
);
|
|
100
99
|
await writeJson(newPackage, packagePath);
|
|
101
100
|
return true;
|
|
@@ -109,7 +108,6 @@ module.exports = {
|
|
|
109
108
|
{ key: 'ci', value: 'scripts/ci' },
|
|
110
109
|
{ key: 'lint', value: 'scripts/lint' },
|
|
111
110
|
{ key: 'lint:fix', value: 'scripts/lint-fix' },
|
|
112
|
-
{ key: 'husky:precommit', value: 'scripts/husky-precommit' },
|
|
113
111
|
{ key: 'release', value: 'scripts/release' },
|
|
114
112
|
{ key: 'test', value: 'scripts/test' },
|
|
115
113
|
{ key: 'test:watch', value: 'scripts/test-watch' },
|
|
@@ -122,6 +120,7 @@ module.exports = {
|
|
|
122
120
|
/**
|
|
123
121
|
* Update package.json with .main and .files keys to use files in ./lib
|
|
124
122
|
* directory by default
|
|
123
|
+
* TODO: Update this to use exports instead of main
|
|
125
124
|
**/
|
|
126
125
|
async setDefaultReleaseFiles() {
|
|
127
126
|
const packagePath = helper.hostPath('package.json');
|
|
@@ -135,7 +134,7 @@ module.exports = {
|
|
|
135
134
|
await this.copyToHost('templates/lib/main.js', 'lib/main.js');
|
|
136
135
|
await this.copyToHost(
|
|
137
136
|
'templates/lib/__tests__/main.js',
|
|
138
|
-
'lib/__tests__/main.js'
|
|
137
|
+
'lib/__tests__/main.js',
|
|
139
138
|
);
|
|
140
139
|
}
|
|
141
140
|
|
|
@@ -251,6 +250,20 @@ module.exports = {
|
|
|
251
250
|
// Download latest yarn version
|
|
252
251
|
await this.__run('yarn set version', { stdout: false });
|
|
253
252
|
},
|
|
253
|
+
/**
|
|
254
|
+
* Configure git hooks to use scripts/hooks instead of .git/hooks
|
|
255
|
+
**/
|
|
256
|
+
async configureGitHooks() {
|
|
257
|
+
// Copy the scripts into ./scripts/hooks
|
|
258
|
+
await this.copyToHost(
|
|
259
|
+
'./templates/scripts/hooks/pre-commit',
|
|
260
|
+
'./scripts/hooks/pre-commit',
|
|
261
|
+
);
|
|
262
|
+
|
|
263
|
+
// Configure git to use this directory for hooks
|
|
264
|
+
const repo = new Gilmore(helper.hostRoot());
|
|
265
|
+
await repo.setConfig('core.hooksPath', 'scripts/hooks');
|
|
266
|
+
},
|
|
254
267
|
/**
|
|
255
268
|
* Copy all config files and configure the scripts
|
|
256
269
|
**/
|
|
@@ -267,6 +280,9 @@ module.exports = {
|
|
|
267
280
|
progress.tick('Adding yarn scripts');
|
|
268
281
|
await this.addScripts();
|
|
269
282
|
|
|
283
|
+
progress.tick('Configuring git hooks');
|
|
284
|
+
await this.configureGitHooks();
|
|
285
|
+
|
|
270
286
|
progress.tick('Updating LICENSE');
|
|
271
287
|
await this.addLicenseFile();
|
|
272
288
|
await this.addLicenseField();
|
|
@@ -283,7 +299,7 @@ module.exports = {
|
|
|
283
299
|
progress.success('aberlaas project initialized');
|
|
284
300
|
|
|
285
301
|
this.__consoleInfo(
|
|
286
|
-
"Don't forget to run aberlaas setup after pushing your repository"
|
|
302
|
+
"Don't forget to run aberlaas setup after pushing your repository",
|
|
287
303
|
);
|
|
288
304
|
},
|
|
289
305
|
__run: run,
|
|
@@ -1,20 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const firostError = require('firost/error');
|
|
1
|
+
import helper from '../../helper.js';
|
|
2
|
+
import lintYml from './yml.js';
|
|
3
|
+
import ciInfo from 'ci-info';
|
|
4
|
+
import exists from 'firost/exists.js';
|
|
5
|
+
import run from 'firost/run.js';
|
|
6
|
+
import which from 'firost/which.js';
|
|
7
|
+
import firostError from 'firost/error.js';
|
|
9
8
|
|
|
10
|
-
|
|
9
|
+
export default {
|
|
11
10
|
configPath: '.circleci/config.yml',
|
|
12
11
|
/**
|
|
13
|
-
* Find
|
|
12
|
+
* Find all relevant files
|
|
14
13
|
* @returns {Array} Array of files
|
|
15
14
|
**/
|
|
16
15
|
async getInputFiles() {
|
|
17
|
-
return await
|
|
16
|
+
return await helper.findHostFiles([this.configPath]);
|
|
18
17
|
},
|
|
19
18
|
/**
|
|
20
19
|
* Check if the code is currently running on CircleCI
|
package/commands/lint/css.js
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import helper from '../../helper.js';
|
|
2
|
+
import { fix as prettierFix } from './helpers/prettier.js';
|
|
3
|
+
import _ from 'golgoth/lodash.js';
|
|
4
|
+
import firostError from 'firost/error.js';
|
|
5
|
+
import run from 'firost/run.js';
|
|
6
|
+
|
|
7
|
+
export default {
|
|
7
8
|
/**
|
|
8
9
|
* Find all relevant files
|
|
9
10
|
* @param {Array} userPatterns Patterns to narrow the search down
|
|
10
11
|
* @returns {Array} Array of files
|
|
11
12
|
**/
|
|
12
13
|
async getInputFiles(userPatterns) {
|
|
13
|
-
return await
|
|
14
|
+
return await helper.findHostFiles(userPatterns, ['.css']);
|
|
14
15
|
},
|
|
15
16
|
/**
|
|
16
17
|
* Lint all files and display results.
|
|
@@ -26,8 +27,8 @@ module.exports = {
|
|
|
26
27
|
|
|
27
28
|
const configFile = await helper.configFile(
|
|
28
29
|
userConfigFile,
|
|
29
|
-
'.stylelintrc.
|
|
30
|
-
'configs/stylelint.
|
|
30
|
+
'.stylelintrc.cjs',
|
|
31
|
+
'configs/stylelint.cjs',
|
|
31
32
|
);
|
|
32
33
|
const binary = await helper.which('stylelint');
|
|
33
34
|
const options = [...files, '--color', '--config', configFile];
|
|
@@ -56,10 +57,11 @@ module.exports = {
|
|
|
56
57
|
return true;
|
|
57
58
|
}
|
|
58
59
|
// Try to pretiffy as much as we can
|
|
59
|
-
await
|
|
60
|
+
await this.__prettierFix(files);
|
|
60
61
|
// Still run a lint on it so it can fail if not everything is fixed
|
|
61
62
|
await this.run(userPatterns, userConfigFile);
|
|
62
63
|
return true;
|
|
63
64
|
},
|
|
65
|
+
__prettierFix: prettierFix,
|
|
64
66
|
__run: run,
|
|
65
67
|
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import helper from '../../../helper.js';
|
|
2
|
+
import run from 'firost/run.js';
|
|
3
|
+
import firostError from 'firost/error.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Fix all files using prettier
|
|
7
|
+
* Note: Will be called by child classes
|
|
8
|
+
* Note: Prettier does not output any information as to why it failed, so
|
|
9
|
+
* we'll manually run the command on each file individually so we can catch
|
|
10
|
+
* the file that errors and display it
|
|
11
|
+
* @param {Array} inputFiles Files to auto-fix
|
|
12
|
+
**/
|
|
13
|
+
export async function fix(inputFiles) {
|
|
14
|
+
const binary = await helper.which('prettier');
|
|
15
|
+
const options = ['--write', ...inputFiles];
|
|
16
|
+
try {
|
|
17
|
+
const command = `${binary} ${options.join(' ')}`;
|
|
18
|
+
await run(command, { stdout: false });
|
|
19
|
+
} catch (err) {
|
|
20
|
+
throw firostError(
|
|
21
|
+
'LINT_ERROR_FIX_PRETTIER',
|
|
22
|
+
'Some files could not be automatically fixed.\nPlease run `yarn run lint` to further debug',
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export default {
|
|
28
|
+
fix,
|
|
29
|
+
};
|
package/commands/lint/index.js
CHANGED
|
@@ -1,18 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import _ from 'golgoth/lodash.js';
|
|
2
|
+
import pMap from 'golgoth/pMap.js';
|
|
3
|
+
import consoleError from 'firost/consoleError.js';
|
|
4
|
+
import firostError from 'firost/error.js';
|
|
5
|
+
import linterCircleCI from './circleci.js';
|
|
6
|
+
import linterCss from './css.js';
|
|
7
|
+
import linterJson from './json.js';
|
|
8
|
+
import linterJs from './js.js';
|
|
9
|
+
import linterYml from './yml.js';
|
|
7
10
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
circleci:
|
|
11
|
-
css:
|
|
12
|
-
json:
|
|
13
|
-
js:
|
|
14
|
-
yml:
|
|
15
|
-
yaml: './yml', // Alias --yaml for --yml
|
|
11
|
+
export default {
|
|
12
|
+
linters: {
|
|
13
|
+
circleci: linterCircleCI,
|
|
14
|
+
css: linterCss,
|
|
15
|
+
json: linterJson,
|
|
16
|
+
js: linterJs,
|
|
17
|
+
yml: linterYml,
|
|
16
18
|
},
|
|
17
19
|
/**
|
|
18
20
|
* Wrapper to lint all supported formats
|
|
@@ -20,7 +22,7 @@ module.exports = {
|
|
|
20
22
|
* @returns {boolean} True on success
|
|
21
23
|
**/
|
|
22
24
|
async run(cliArgs) {
|
|
23
|
-
const allTypesKeys = _.keys(this.
|
|
25
|
+
const allTypesKeys = _.keys(this.linters);
|
|
24
26
|
const userTypes = _.intersection(_.keys(cliArgs), allTypesKeys);
|
|
25
27
|
const typesToLint = _.isEmpty(userTypes) ? allTypesKeys : userTypes;
|
|
26
28
|
|
|
@@ -30,7 +32,7 @@ module.exports = {
|
|
|
30
32
|
try {
|
|
31
33
|
const configFile = _.get(cliArgs, `config.${type}`);
|
|
32
34
|
const userPatterns = _.get(cliArgs, '_');
|
|
33
|
-
const linter =
|
|
35
|
+
const linter = this.linters[type];
|
|
34
36
|
|
|
35
37
|
await linter[methodName](userPatterns, configFile);
|
|
36
38
|
} catch (error) {
|
|
@@ -45,37 +47,5 @@ module.exports = {
|
|
|
45
47
|
|
|
46
48
|
return true;
|
|
47
49
|
},
|
|
48
|
-
/**
|
|
49
|
-
* Find all relevant files of the specified extension in the host
|
|
50
|
-
* Note: Should be used by child classes
|
|
51
|
-
* @param {Array} safeListExtension List of allowed extensions to keep
|
|
52
|
-
* @param {Array} userPatterns Patterns to narrow the search down
|
|
53
|
-
* @returns {Array} Array of files
|
|
54
|
-
**/
|
|
55
|
-
async getInputFiles(safeListExtension, userPatterns = []) {
|
|
56
|
-
const inputPatterns = _.isEmpty(userPatterns) ? '.' : userPatterns;
|
|
57
|
-
return await helper.findHostFiles(inputPatterns, safeListExtension);
|
|
58
|
-
},
|
|
59
|
-
/**
|
|
60
|
-
* Fix all files using prettier
|
|
61
|
-
* Note: Will be called by child classes
|
|
62
|
-
* Note: Prettier does not output any information as to why it failed, so
|
|
63
|
-
* we'll manually run the command on each file individually so we can catch
|
|
64
|
-
* the file that errors and display it
|
|
65
|
-
* @param {Array} inputFiles Files to auto-fix
|
|
66
|
-
**/
|
|
67
|
-
async fixWithPrettier(inputFiles) {
|
|
68
|
-
const binary = await helper.which('prettier');
|
|
69
|
-
const options = ['--write', ...inputFiles];
|
|
70
|
-
try {
|
|
71
|
-
const command = `${binary} ${options.join(' ')}`;
|
|
72
|
-
await run(command, { stdout: false });
|
|
73
|
-
} catch (err) {
|
|
74
|
-
throw firostError(
|
|
75
|
-
'LINT_ERROR_FIX_PRETTIER',
|
|
76
|
-
'Some files could not be automatically fixed.\nPlease run `yarn run lint` to further debug'
|
|
77
|
-
);
|
|
78
|
-
}
|
|
79
|
-
},
|
|
80
50
|
__consoleError: consoleError,
|
|
81
51
|
};
|
package/commands/lint/js.js
CHANGED
|
@@ -1,76 +1,65 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
module.exports = {
|
|
1
|
+
import helper from '../../helper.js';
|
|
2
|
+
import _ from 'golgoth/lodash.js';
|
|
3
|
+
import firostError from 'firost/error.js';
|
|
4
|
+
import run from 'firost/run.js';
|
|
5
|
+
import { ESLint } from 'eslint';
|
|
6
|
+
|
|
7
|
+
export default {
|
|
9
8
|
/**
|
|
10
9
|
* Find all relevant files
|
|
11
10
|
* @param {Array} userPatterns Patterns to narrow the search down
|
|
12
11
|
* @returns {Array} Array of files
|
|
13
12
|
**/
|
|
14
13
|
async getInputFiles(userPatterns) {
|
|
15
|
-
|
|
16
|
-
const allJsFiles = await lint.getInputFiles(['.js'], userPatterns);
|
|
17
|
-
const allBinFiles = await this.getBinFiles();
|
|
18
|
-
|
|
19
|
-
return [...allJsFiles, ...allBinFiles];
|
|
20
|
-
},
|
|
21
|
-
/**
|
|
22
|
-
* Returns the list of all bin files defined in the package.json
|
|
23
|
-
* @returns {Array} List of bin files
|
|
24
|
-
**/
|
|
25
|
-
async getBinFiles() {
|
|
26
|
-
const packagePath = helper.hostPath('package.json');
|
|
27
|
-
const hasPackage = await exists(packagePath);
|
|
28
|
-
if (!hasPackage) {
|
|
29
|
-
return [];
|
|
30
|
-
}
|
|
31
|
-
const packageContent = await readJson(packagePath);
|
|
32
|
-
return _.chain(packageContent)
|
|
33
|
-
.get('bin', {})
|
|
34
|
-
.values()
|
|
35
|
-
.map((filepath) => {
|
|
36
|
-
return helper.hostPath(filepath);
|
|
37
|
-
})
|
|
38
|
-
.value();
|
|
14
|
+
return await helper.findHostFiles(userPatterns, ['.js']);
|
|
39
15
|
},
|
|
40
16
|
/**
|
|
41
17
|
* Lint all files and display results.
|
|
42
18
|
* @param {Array} userPatterns Patterns to narrow the search down
|
|
43
19
|
* @param {string} userConfigFile Custom config file to use
|
|
44
|
-
* @param {
|
|
20
|
+
* @param {object} userOptions Options to pass to ESLint, including fix
|
|
45
21
|
* @returns {boolean} True on success
|
|
46
22
|
**/
|
|
47
|
-
async run(userPatterns, userConfigFile,
|
|
23
|
+
async run(userPatterns, userConfigFile, userOptions = {}) {
|
|
24
|
+
// Options
|
|
25
|
+
const options = { fix: false, ...userOptions };
|
|
26
|
+
|
|
27
|
+
// Files to lint
|
|
48
28
|
const files = await this.getInputFiles(userPatterns);
|
|
49
29
|
if (_.isEmpty(files)) {
|
|
50
30
|
return true;
|
|
51
31
|
}
|
|
52
32
|
|
|
33
|
+
// Config file
|
|
53
34
|
const configFile = await helper.configFile(
|
|
54
35
|
userConfigFile,
|
|
55
|
-
'.eslintrc.
|
|
56
|
-
'lib/configs/eslint.
|
|
36
|
+
'.eslintrc.cjs',
|
|
37
|
+
'lib/configs/eslint.cjs',
|
|
57
38
|
);
|
|
58
|
-
const pluginResolveDir = helper.aberlaasRoot();
|
|
59
|
-
const options = [
|
|
60
|
-
...files,
|
|
61
|
-
...additionalOptions,
|
|
62
|
-
'--color',
|
|
63
|
-
`--config=${configFile}`,
|
|
64
|
-
`--resolve-plugins-relative-to=${pluginResolveDir}`,
|
|
65
|
-
];
|
|
66
|
-
const binary = await helper.which('eslint');
|
|
67
39
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
40
|
+
// Run the actual lint
|
|
41
|
+
const eslint = new ESLint({
|
|
42
|
+
overrideConfigFile: configFile,
|
|
43
|
+
resolvePluginsRelativeTo: helper.aberlaasRoot(),
|
|
44
|
+
...options,
|
|
45
|
+
});
|
|
46
|
+
const results = await eslint.lintFiles(files);
|
|
47
|
+
|
|
48
|
+
// Fix
|
|
49
|
+
if (options.fix) {
|
|
50
|
+
await ESLint.outputFixes(results);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// All good, we can stop
|
|
54
|
+
const errorCount = _.chain(results).map('errorCount').sum().value();
|
|
55
|
+
if (errorCount == 0) {
|
|
56
|
+
return true;
|
|
72
57
|
}
|
|
73
|
-
|
|
58
|
+
|
|
59
|
+
// Format errors
|
|
60
|
+
const formatter = await eslint.loadFormatter('stylish');
|
|
61
|
+
const errorText = formatter.format(results);
|
|
62
|
+
throw firostError('JavaScriptLintError', errorText);
|
|
74
63
|
},
|
|
75
64
|
/**
|
|
76
65
|
* Autofix files in place
|
|
@@ -79,7 +68,7 @@ module.exports = {
|
|
|
79
68
|
* @returns {boolean} True on success
|
|
80
69
|
**/
|
|
81
70
|
async fix(userPatterns, userConfigFile) {
|
|
82
|
-
return await this.run(userPatterns, userConfigFile,
|
|
71
|
+
return await this.run(userPatterns, userConfigFile, { fix: true });
|
|
83
72
|
},
|
|
84
73
|
__run: run,
|
|
85
74
|
};
|
package/commands/lint/json.js
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import helper from '../../helper.js';
|
|
2
|
+
import { fix as prettierFix } from './helpers/prettier.js';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
import _ from 'golgoth/lodash.js';
|
|
5
|
+
import pMap from 'golgoth/pMap.js';
|
|
6
|
+
import firostError from 'firost/error.js';
|
|
7
|
+
import read from 'firost/read.js';
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
export default {
|
|
10
10
|
/**
|
|
11
11
|
* Find all relevant files
|
|
12
12
|
* @param {Array} userPatterns Patterns to narrow the search down
|
|
13
13
|
* @returns {Array} Array of files
|
|
14
14
|
**/
|
|
15
15
|
async getInputFiles(userPatterns) {
|
|
16
|
-
return await
|
|
16
|
+
return await helper.findHostFiles(userPatterns, ['.json']);
|
|
17
17
|
},
|
|
18
18
|
/**
|
|
19
19
|
* Lint all files and display results.
|
|
@@ -54,7 +54,8 @@ module.exports = {
|
|
|
54
54
|
if (_.isEmpty(files)) {
|
|
55
55
|
return true;
|
|
56
56
|
}
|
|
57
|
-
await
|
|
57
|
+
await this.__prettierFix(files);
|
|
58
58
|
},
|
|
59
|
+
__prettierFix: prettierFix,
|
|
59
60
|
__parse: JSON.parse,
|
|
60
61
|
};
|