|
1 | 1 | #!/usr/bin/env node |
2 | 2 | const sortObjectKeys = require('sort-object-keys'); |
3 | 3 | const detectIndent = require('detect-indent'); |
| 4 | +const glob = require('glob'); |
4 | 5 |
|
5 | 6 | const sortOrder = [ |
6 | 7 | 'name', |
@@ -204,16 +205,19 @@ module.exports.sortOrder = sortOrder; |
204 | 205 | if (require.main === module) { |
205 | 206 | const fs = require('fs'); |
206 | 207 |
|
207 | | - const filesToProcess = process.argv[2] |
| 208 | + const paths = process.argv[2] |
208 | 209 | ? process.argv.slice(2) |
209 | 210 | : [`${process.cwd()}/package.json`]; |
210 | 211 |
|
211 | | - filesToProcess.forEach(filePath => { |
212 | | - const packageJson = fs.readFileSync(filePath, 'utf8'); |
213 | | - const sorted = sortPackageJson(packageJson); |
214 | | - if (sorted !== packageJson) { |
215 | | - fs.writeFileSync(filePath, sorted, 'utf8'); |
216 | | - console.log(`${filePath} is sorted!`); |
217 | | - } |
| 212 | + paths.forEach(path => { |
| 213 | + const filesToProcess = glob.sync(path); |
| 214 | + filesToProcess.forEach(filePath => { |
| 215 | + const packageJson = fs.readFileSync(filePath, 'utf8'); |
| 216 | + const sorted = sortPackageJson(packageJson); |
| 217 | + if (sorted !== packageJson) { |
| 218 | + fs.writeFileSync(filePath, sorted, 'utf8'); |
| 219 | + console.log(`${filePath} is sorted!`); |
| 220 | + } |
| 221 | + }); |
218 | 222 | }); |
219 | 223 | } |
0 commit comments