Skip to content

Commit dfe71db

Browse files
committed
chore: fix eslint related dev dependencies
1 parent c99a65f commit dfe71db

File tree

25 files changed

+391
-6
lines changed

25 files changed

+391
-6
lines changed

bin/sync-dev-deps.js

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,13 @@ async function syncDevDeps() {
2626
.dependencies;
2727

2828
const deps = [
29-
'typescript',
30-
'eslint',
3129
'@typescript-eslint/eslint-plugin',
3230
'@typescript-eslint/parser',
31+
'eslint',
32+
'eslint-config-prettier',
3333
'eslint-plugin-eslint-plugin',
34+
'eslint-plugin-mocha',
35+
'typescript',
3436
];
3537
const masterDeps = {};
3638
for (const d of deps) {
@@ -61,7 +63,7 @@ async function syncDevDeps() {
6163
* @param masterDeps - Master dependencies
6264
*/
6365
function updatePackageJson(pkgFile, masterDeps) {
64-
const data = readJsonFile(pkgFile);
66+
const data = readPackageJson(pkgFile);
6567
const isExample = data.name.startsWith('@loopback/example-');
6668
const isRoot = data.name === 'loopback-next';
6769

@@ -85,17 +87,34 @@ function updatePackageJson(pkgFile, masterDeps) {
8587
}
8688
}
8789
if (!modified) return false;
88-
writeJsonFile(pkgFile, data);
90+
writePackageJson(pkgFile, data);
8991
return true;
9092
}
9193

9294
if (require.main === module) syncDevDeps();
9395

94-
function readJsonFile(filePath) {
96+
function readPackageJson(filePath) {
9597
return JSON.parse(fs.readFileSync(filePath, 'utf-8'));
9698
}
9799

98-
function writeJsonFile(filePath, data) {
100+
function writePackageJson(filePath, data) {
101+
data.dependencies = sortObjectByKeys(data.dependencies);
102+
data.devDependencies = sortObjectByKeys(data.devDependencies);
99103
fs.writeFileSync(filePath, JSON.stringify(data, null, 2) + '\n', 'utf-8');
100104
console.log('%s has been updated.', filePath);
101105
}
106+
107+
/**
108+
* Sort an object by keys
109+
* @param data - An object to be sorted
110+
*/
111+
function sortObjectByKeys(data) {
112+
if (data == null) return undefined;
113+
if (typeof data !== 'object') return data;
114+
const keys = Object.keys(data).sort();
115+
const result = {};
116+
for (const k of keys) {
117+
result[k] = data[k];
118+
}
119+
return result;
120+
}

examples/context/package-lock.json

Lines changed: 30 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/context/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@
4747
"@typescript-eslint/eslint-plugin": "^1.9.0",
4848
"@typescript-eslint/parser": "^1.9.0",
4949
"eslint": "^5.16.0",
50+
"eslint-config-prettier": "^4.3.0",
5051
"eslint-plugin-eslint-plugin": "^2.1.0",
52+
"eslint-plugin-mocha": "^5.3.0",
5153
"typescript": "~3.5.1"
5254
},
5355
"keywords": [

examples/express-composition/package-lock.json

Lines changed: 30 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/express-composition/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,9 @@
6363
"@typescript-eslint/eslint-plugin": "^1.9.0",
6464
"@typescript-eslint/parser": "^1.9.0",
6565
"eslint": "^5.16.0",
66+
"eslint-config-prettier": "^4.3.0",
6667
"eslint-plugin-eslint-plugin": "^2.1.0",
68+
"eslint-plugin-mocha": "^5.3.0",
6769
"typescript": "~3.5.1"
6870
}
6971
}

examples/greeter-extension/package-lock.json

Lines changed: 30 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/greeter-extension/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@
5151
"@typescript-eslint/eslint-plugin": "^1.9.0",
5252
"@typescript-eslint/parser": "^1.9.0",
5353
"eslint": "^5.16.0",
54+
"eslint-config-prettier": "^4.3.0",
5455
"eslint-plugin-eslint-plugin": "^2.1.0",
56+
"eslint-plugin-mocha": "^5.3.0",
5557
"typescript": "~3.5.1"
5658
},
5759
"dependencies": {

examples/greeting-app/package-lock.json

Lines changed: 30 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/greeting-app/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@
5151
"@typescript-eslint/eslint-plugin": "^1.9.0",
5252
"@typescript-eslint/parser": "^1.9.0",
5353
"eslint": "^5.16.0",
54+
"eslint-config-prettier": "^4.3.0",
5455
"eslint-plugin-eslint-plugin": "^2.1.0",
56+
"eslint-plugin-mocha": "^5.3.0",
5557
"typescript": "~3.5.1"
5658
},
5759
"dependencies": {

examples/hello-world/package-lock.json

Lines changed: 30 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/hello-world/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@
4848
"@typescript-eslint/eslint-plugin": "^1.9.0",
4949
"@typescript-eslint/parser": "^1.9.0",
5050
"eslint": "^5.16.0",
51+
"eslint-config-prettier": "^4.3.0",
5152
"eslint-plugin-eslint-plugin": "^2.1.0",
53+
"eslint-plugin-mocha": "^5.3.0",
5254
"typescript": "~3.5.1"
5355
},
5456
"keywords": [

0 commit comments

Comments
 (0)