-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
68 lines (56 loc) · 1.64 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
const ts = {
root: true,
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint'],
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/eslint-recommended',
'plugin:@typescript-eslint/recommended',
'minecraft-scripting'
],
rules: {
'@typescript-eslint/no-namespace': 'off',
'@typescript-eslint/ban-ts-comment': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'no-non-null-assertion': 'off'
},
parserOptions: {
tsconfigRootDir: './'
}
};
const js = {
root: true,
extends: ['minecraft-scripting']
};
async function setup({ InfoHandler, NpmHandler, IO }) {
const { language } = await InfoHandler.getInfo();
console.log('[start] setup eslint...');
if (language === 'ts') {
NpmHandler.add(
'eslint @typescript-eslint/eslint-plugin @typescript-eslint/parser eslint-plugin-minecraft-linting'
);
IO.writeJSON('.eslintrc', ts);
} else {
NpmHandler.add('eslint eslint-plugin-minecraft-linting');
IO.writeJSON('.eslintrc', js);
}
IO.writeText('.eslintignore', 'node_modules\nout');
const package_ = IO.readJSON('package.json');
if (!package_['scripts']) package_['scripts'] = {};
package_['scripts']['lint'] = 'eslint . --ext .ts';
IO.writeJSON('package.json', package_);
console.log('[done] setup eslint.');
}
export default async function (program, handlers) {
handlers.InfoHandler.bind('ext');
program
.command('eslint-setup')
.alias('ess')
.description('install eslint for the project')
.action(() => setup(handlers));
program
.command('eslint-lint')
.alias('esl')
.description('check code for compliance with current eslint standards')
.action(() => IO.exec('npm run lint'));
}