Skip to content

Commit

Permalink
chore: fix eslint related dev dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
raymondfeng committed Jun 4, 2019
1 parent c99a65f commit dfe71db
Show file tree
Hide file tree
Showing 25 changed files with 391 additions and 6 deletions.
31 changes: 25 additions & 6 deletions bin/sync-dev-deps.js
Expand Up @@ -26,11 +26,13 @@ async function syncDevDeps() {
.dependencies;

const deps = [
'typescript',
'eslint',
'@typescript-eslint/eslint-plugin',
'@typescript-eslint/parser',
'eslint',
'eslint-config-prettier',
'eslint-plugin-eslint-plugin',
'eslint-plugin-mocha',
'typescript',
];
const masterDeps = {};
for (const d of deps) {
Expand Down Expand Up @@ -61,7 +63,7 @@ async function syncDevDeps() {
* @param masterDeps - Master dependencies
*/
function updatePackageJson(pkgFile, masterDeps) {
const data = readJsonFile(pkgFile);
const data = readPackageJson(pkgFile);
const isExample = data.name.startsWith('@loopback/example-');
const isRoot = data.name === 'loopback-next';

Expand All @@ -85,17 +87,34 @@ function updatePackageJson(pkgFile, masterDeps) {
}
}
if (!modified) return false;
writeJsonFile(pkgFile, data);
writePackageJson(pkgFile, data);
return true;
}

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

function readJsonFile(filePath) {
function readPackageJson(filePath) {
return JSON.parse(fs.readFileSync(filePath, 'utf-8'));
}

function writeJsonFile(filePath, data) {
function writePackageJson(filePath, data) {
data.dependencies = sortObjectByKeys(data.dependencies);
data.devDependencies = sortObjectByKeys(data.devDependencies);
fs.writeFileSync(filePath, JSON.stringify(data, null, 2) + '\n', 'utf-8');
console.log('%s has been updated.', filePath);
}

/**
* Sort an object by keys
* @param data - An object to be sorted
*/
function sortObjectByKeys(data) {
if (data == null) return undefined;
if (typeof data !== 'object') return data;
const keys = Object.keys(data).sort();
const result = {};
for (const k of keys) {
result[k] = data[k];
}
return result;
}
30 changes: 30 additions & 0 deletions examples/context/package-lock.json

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

2 changes: 2 additions & 0 deletions examples/context/package.json
Expand Up @@ -47,7 +47,9 @@
"@typescript-eslint/eslint-plugin": "^1.9.0",
"@typescript-eslint/parser": "^1.9.0",
"eslint": "^5.16.0",
"eslint-config-prettier": "^4.3.0",
"eslint-plugin-eslint-plugin": "^2.1.0",
"eslint-plugin-mocha": "^5.3.0",
"typescript": "~3.5.1"
},
"keywords": [
Expand Down
30 changes: 30 additions & 0 deletions examples/express-composition/package-lock.json

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

2 changes: 2 additions & 0 deletions examples/express-composition/package.json
Expand Up @@ -63,7 +63,9 @@
"@typescript-eslint/eslint-plugin": "^1.9.0",
"@typescript-eslint/parser": "^1.9.0",
"eslint": "^5.16.0",
"eslint-config-prettier": "^4.3.0",
"eslint-plugin-eslint-plugin": "^2.1.0",
"eslint-plugin-mocha": "^5.3.0",
"typescript": "~3.5.1"
}
}
30 changes: 30 additions & 0 deletions examples/greeter-extension/package-lock.json

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

2 changes: 2 additions & 0 deletions examples/greeter-extension/package.json
Expand Up @@ -51,7 +51,9 @@
"@typescript-eslint/eslint-plugin": "^1.9.0",
"@typescript-eslint/parser": "^1.9.0",
"eslint": "^5.16.0",
"eslint-config-prettier": "^4.3.0",
"eslint-plugin-eslint-plugin": "^2.1.0",
"eslint-plugin-mocha": "^5.3.0",
"typescript": "~3.5.1"
},
"dependencies": {
Expand Down
30 changes: 30 additions & 0 deletions examples/greeting-app/package-lock.json

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

2 changes: 2 additions & 0 deletions examples/greeting-app/package.json
Expand Up @@ -51,7 +51,9 @@
"@typescript-eslint/eslint-plugin": "^1.9.0",
"@typescript-eslint/parser": "^1.9.0",
"eslint": "^5.16.0",
"eslint-config-prettier": "^4.3.0",
"eslint-plugin-eslint-plugin": "^2.1.0",
"eslint-plugin-mocha": "^5.3.0",
"typescript": "~3.5.1"
},
"dependencies": {
Expand Down
30 changes: 30 additions & 0 deletions examples/hello-world/package-lock.json

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

2 changes: 2 additions & 0 deletions examples/hello-world/package.json
Expand Up @@ -48,7 +48,9 @@
"@typescript-eslint/eslint-plugin": "^1.9.0",
"@typescript-eslint/parser": "^1.9.0",
"eslint": "^5.16.0",
"eslint-config-prettier": "^4.3.0",
"eslint-plugin-eslint-plugin": "^2.1.0",
"eslint-plugin-mocha": "^5.3.0",
"typescript": "~3.5.1"
},
"keywords": [
Expand Down

0 comments on commit dfe71db

Please sign in to comment.