├── .jshintrc ├── README.md ├── index.js └── package.json /.jshintrc: -------------------------------------------------------------------------------- 1 | { 2 | "predef": [ 3 | ], 4 | 5 | "maxerr": 100000, 6 | 7 | // Enforcing Options 8 | "bitwise": true, 9 | "curly": false, 10 | "eqeqeq": true, 11 | "forin": true, 12 | "immed": false, 13 | "latedef": false, 14 | "newcap": true, 15 | "noarg": true, 16 | "noempty": true, 17 | "nonew": true, 18 | "plusplus": false, 19 | "regexp": false, 20 | "undef": true, 21 | "strict": true, 22 | "trailing": true, 23 | 24 | // Relaxing Options 25 | "asi": true, 26 | "boss": true, 27 | "debug": false, 28 | "eqnull": true, 29 | "es5": false, 30 | "esnext": false, 31 | "evil": false, 32 | "expr": true, 33 | "funcscope": false, 34 | "globalstrict": false, 35 | "iterator": false, 36 | "lastsemic": true, 37 | "laxbreak": false, 38 | "laxcomma": false, 39 | "loopfunc": false, 40 | "multistr": false, 41 | "onecase": false, 42 | "proto": false, 43 | "regexdash": false, 44 | "scripturl": false, 45 | "smarttabs": false, 46 | "shadow": false, 47 | "sub": false, 48 | "supernew": false, 49 | "validthis": false, 50 | 51 | // Environments 52 | "browser": true, 53 | "couch": false, 54 | "devel": true, 55 | "dojo": false, 56 | "jquery": false, 57 | "mootools": true, 58 | "node": false, 59 | "nonstandard": true, 60 | "prototypejs": false, 61 | "rhino": false, 62 | "wsh": false, 63 | 64 | // Legacy 65 | "nomen": true, 66 | "onevar": false, 67 | "passfail": false, 68 | "white": false 69 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # npm-sort 2 | Sort *~alphabetically* your dependecies 3 | 4 | ## Install 5 | $ npm install npm-sort -g 6 | 7 | ## Usage 8 | $ cd my_node_project 9 | $ npm-sort 10 | 11 | ## Example result 12 | 13 | From 14 | 15 | ```js 16 | "dependencies": { 17 | "koa": "~0.1.2", 18 | "koa-router": "~1.6.1", 19 | "co": "~3.0.1", 20 | "request": "~2.30.0", 21 | "colors": "~0.6.2", 22 | "async": "~0.2.9", 23 | "JSONStream": "~0.7.1", 24 | "qs": "~0.6.6", 25 | "event-stream": "~3.0.20", 26 | "json-array-stream": "~0.1.2", 27 | "koa-jsonp": "~0.0.3", 28 | "koa-mount": "~1.2.2", 29 | "koa-compress": "~1.0.0", 30 | "koa-favicon": "~1.0.1", 31 | "koa-response-time": "~1.0.1", 32 | "debug": "~0.7.4", 33 | "co-body": "0.0.1", 34 | "nano": "~4.2.1" 35 | }, 36 | ``` 37 | 38 | to 39 | 40 | ```js 41 | "dependencies": { 42 | "async": "~0.2.9", 43 | "co": "~3.0.1", 44 | "colors": "~0.6.2", 45 | "co-body": "0.0.1", 46 | "debug": "~0.7.4", 47 | "json-array-stream": "~0.1.2", 48 | "JSONStream": "~0.7.1", 49 | "koa": "~0.1.2", 50 | "koa-jsonp": "~0.0.3", 51 | "koa-mount": "~1.2.2", 52 | "koa-router": "~1.6.1", 53 | "koa-favicon": "~1.0.1", 54 | "koa-compress": "~1.0.0", 55 | "koa-response-time": "~1.0.1", 56 | "nano": "~4.2.1", 57 | "request": "~2.30.0" 58 | } 59 | ``` -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | 'use strict'; 4 | 5 | /** 6 | * Sorts object keys ~alphabetically 7 | * 8 | * @param {Object} obj The object to be sorted 9 | * @return {Object} An sorted copy of `obj` 10 | */ 11 | 12 | function sortObject(obj) { 13 | var out = Object.create(null) 14 | 15 | Object.keys(obj).sort(function (a, b) { 16 | return a.toLowerCase().localeCompare(b.toLowerCase()) 17 | }).forEach(function (key) { 18 | out[key] = obj[key] 19 | }) 20 | 21 | return out 22 | } 23 | 24 | (function () { 25 | var save = require('fs').writeFileSync 26 | var pkgPath = process.cwd() + '/package.json' 27 | var pkg = require(pkgPath) 28 | 29 | if (pkg.dependencies) { 30 | console.log(' > Sorting dependencies...') 31 | pkg.dependencies = sortObject(pkg.dependencies) 32 | console.log(JSON.stringify(pkg.dependencies, null, ' ')) 33 | } 34 | 35 | if (pkg.devDependencies) { 36 | console.log(' > Sorting devDependencies...') 37 | pkg.devDependencies = sortObject(pkg.devDependencies) 38 | console.log(JSON.stringify(pkg.devDependencies, null, ' ')) 39 | } 40 | 41 | if (pkg.optionalDependencies) { 42 | console.log(' > Sorting optionalDependencies...') 43 | pkg.optionalDependencies = sortObject(pkg.optionalDependencies) 44 | console.log(JSON.stringify(pkg.optionalDependencies, null, ' ')) 45 | } 46 | 47 | console.log(' > Writing package.json...') 48 | save(pkgPath, JSON.stringify(pkg, null, ' ')) 49 | 50 | console.log(' > Done') 51 | })() -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "npm-sort", 3 | "version": "0.0.4", 4 | "description": "npm install and sort deps", 5 | "main": "index.js", 6 | "bin": { 7 | "npm-sort": "./index.js" 8 | }, 9 | "scripts": { 10 | "test": "make test" 11 | }, 12 | "repository": { 13 | "type": "git", 14 | "url": "git@github.com:kilianc/npm-sort.git" 15 | }, 16 | "keywords": [ 17 | "npm", 18 | "install", 19 | "sort", 20 | "deps" 21 | ], 22 | "author": "Kilian Ciuffolo ", 23 | "license": "MIT", 24 | "bugs": { 25 | "url": "https://github.com/kilianc/npm-sort/issues" 26 | }, 27 | "homepage": "https://github.com/kilianc/npm-sort" 28 | } 29 | --------------------------------------------------------------------------------