Skip to content

Commit

Permalink
feat: Cross-platform support for glob paths (#74)
Browse files Browse the repository at this point in the history
  • Loading branch information
tylerbutler authored and keithamus committed Nov 7, 2019
1 parent 14a9ee1 commit a940e93
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 28 deletions.
20 changes: 12 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env node
const sortObjectKeys = require('sort-object-keys');
const detectIndent = require('detect-indent');
const glob = require('glob');

const sortOrder = [
'name',
Expand Down Expand Up @@ -204,16 +205,19 @@ module.exports.sortOrder = sortOrder;
if (require.main === module) {
const fs = require('fs');

const filesToProcess = process.argv[2]
const paths = process.argv[2]
? process.argv.slice(2)
: [`${process.cwd()}/package.json`];

filesToProcess.forEach(filePath => {
const packageJson = fs.readFileSync(filePath, 'utf8');
const sorted = sortPackageJson(packageJson);
if (sorted !== packageJson) {
fs.writeFileSync(filePath, sorted, 'utf8');
console.log(`${filePath} is sorted!`);
}
paths.forEach(path => {
const filesToProcess = glob.sync(path);
filesToProcess.forEach(filePath => {
const packageJson = fs.readFileSync(filePath, 'utf8');
const sorted = sortPackageJson(packageJson);
if (sorted !== packageJson) {
fs.writeFileSync(filePath, sorted, 'utf8');
console.log(`${filePath} is sorted!`);
}
});
});
}
29 changes: 9 additions & 20 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
},
"dependencies": {
"detect-indent": "^5.0.0",
"glob": "^7.1.6",
"sort-object-keys": "^1.1.2"
},
"devDependencies": {
Expand Down

0 comments on commit a940e93

Please sign in to comment.