-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
💥 Use ES modules instead of CommonJS
- Loading branch information
Showing
16 changed files
with
150 additions
and
160 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,4 @@ node_modules/ | |
package-lock.json | ||
|
||
.coveralls.yml | ||
.nyc_output/ | ||
coverage/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
language: node_js | ||
|
||
node_js: | ||
- "10" | ||
- "12" | ||
- "14" | ||
- "node" | ||
|
||
cache: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
#!/usr/bin/env node | ||
import chalk from 'chalk'; | ||
import Table from 'cli-table3'; | ||
import { program } from 'commander'; | ||
|
||
import config from './lib/config.js'; | ||
import * as dates from './lib/dates.js'; | ||
import * as dependencies from './lib/dependencies.js'; | ||
import * as versions from './lib/versions.js'; | ||
|
||
const SHORT = { | ||
devDependencies: chalk.blue.bold('dev'), | ||
peerDependencies: chalk.magenta.bold('peer'), | ||
bundledDependencies: chalk.cyan.bold('bundled'), | ||
}; | ||
|
||
const table = new Table({ | ||
head: [ | ||
chalk.keyword('orange').underline('Name'), | ||
chalk.keyword('orange').underline('Type'), | ||
chalk.keyword('orange').underline('Version'), | ||
chalk.keyword('orange').underline('Last Publish') | ||
] | ||
}); | ||
|
||
program | ||
.name('package-age') | ||
.version(config.version, '-v, --version') | ||
.description('A CLI for detecting old dependencies used in your project') | ||
.option('-f, --file [optional]', 'path to the package.json', 'package.json') | ||
|
||
.option('-y, --year [optional]', 'after how much years a package should be considered old', 2) | ||
.option('-m, --month [optional]', 'after how much months a package should be considered old', 0) | ||
|
||
.option('-a, --all', 'parameter to get all kinds of dependencies', false) | ||
.option('-d, --dev', 'parameter to get the devDependencies', false) | ||
.option('-p, --peer', 'parameter to get the peerDependencies', false) | ||
.option('-b, --bundled', 'parameter to get the bundledDependencies', false) | ||
.parse(process.argv); | ||
|
||
async function cli() { | ||
const options = program.opts(); | ||
const results = await dependencies.get(Object.assign(config, { | ||
file: options.file, | ||
year: options.year, | ||
month: options.month, | ||
dependencies: { | ||
all: options.all, | ||
dev: options.dev, | ||
peer: options.peer, | ||
bundled: options.bundled | ||
} | ||
})); | ||
|
||
// Print the results to the console | ||
Object.entries(results).forEach(([key, dependencies]) => { | ||
dependencies.forEach(dependency => { | ||
let version; | ||
let date; | ||
|
||
if (dependency.valid) { | ||
version = versions.compare(dependency.version, dependency.latest); | ||
date = dates.compare(dependency.date, config.year, config.month); | ||
} else { | ||
version = chalk.bgRed.bold(`supplied invalid version: '${version}'`); | ||
date = null; | ||
} | ||
|
||
table.push([ | ||
dependency.name, | ||
SHORT[key] || null, | ||
version, | ||
date | ||
]); | ||
}); | ||
}); | ||
|
||
process.stdout.write(table.toString()); | ||
} | ||
|
||
cli(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,94 +1,4 @@ | ||
#!/usr/bin/env node | ||
import config from './lib/config.js'; | ||
import * as dependencies from './lib/dependencies.js'; | ||
|
||
const chalk = require('chalk'); | ||
const Table = require('cli-table3'); | ||
const commander = require('commander'); | ||
|
||
const dates = require('./lib/dates'); | ||
const dependencies = require('./lib/dependencies'); | ||
const versions = require('./lib/versions'); | ||
|
||
const config = { | ||
version: require('./package.json').version, | ||
registry: 'https://registry.npmjs.org', | ||
file: 'package.json', | ||
year: 2, | ||
month: 0, | ||
dependencies: {} | ||
}; | ||
|
||
const SHORT = { | ||
devDependencies: chalk.blue.bold('dev'), | ||
peerDependencies: chalk.magenta.bold('peer'), | ||
bundledDependencies: chalk.cyan.bold('bundled'), | ||
}; | ||
|
||
const table = new Table({ | ||
head: [ | ||
chalk.keyword('orange').underline('Name'), | ||
chalk.keyword('orange').underline('Type'), | ||
chalk.keyword('orange').underline('Version'), | ||
chalk.keyword('orange').underline('Last Publish') | ||
] | ||
}); | ||
|
||
commander | ||
.version(config.version, '-v, --version') | ||
.description('A CLI for detecting old dependencies used in your project') | ||
.option('-f, --file [optional]', 'path to the package.json', 'package.json') | ||
|
||
.option('-y, --year [optional]', 'after how much years a package should be considered old', 2) | ||
.option('-m, --month [optional]', 'after how much months a package should be considered old', 0) | ||
|
||
.option('-a, --all', 'parameter to get all kinds of dependencies', false) | ||
.option('-d, --dev', 'parameter to get the devDependencies', false) | ||
.option('-p, --peer', 'parameter to get the peerDependencies', false) | ||
.option('-b, --bundled', 'parameter to get the bundledDependencies', false) | ||
.parse(process.argv); | ||
|
||
|
||
async function cli() { | ||
const results = await dependencies.get(Object.assign(config, { | ||
file: commander.file, | ||
year: commander.year, | ||
month: commander.month, | ||
dependencies: { | ||
all: commander.all, | ||
dev: commander.dev, | ||
peer: commander.peer, | ||
bundled: commander.bundled | ||
} | ||
})); | ||
|
||
// Print the results to the console | ||
Object.entries(results).forEach(([key, dependencies]) => { | ||
dependencies.forEach(dependency => { | ||
let version; | ||
let date; | ||
|
||
if (dependency.valid) { | ||
version = versions.compare(dependency.version, dependency.latest); | ||
date = dates.compare(dependency.date, config.year, config.month); | ||
} else { | ||
version = chalk.bgRed.bold(`supplied invalid version: '${version}'`); | ||
date = null; | ||
} | ||
|
||
table.push([ | ||
dependency.name, | ||
SHORT[key] || null, | ||
version, | ||
date | ||
]); | ||
}); | ||
}); | ||
|
||
console.log(table.toString()); // eslint-disable-line no-console | ||
} | ||
|
||
|
||
if (require.main === module) { | ||
cli(); | ||
} else { | ||
module.exports = options => dependencies.get(Object.assign(config, options)); | ||
} | ||
export default options => dependencies.get(Object.assign({}, config, options)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { readPackageSync } from 'read-pkg'; | ||
|
||
const version = readPackageSync().version; | ||
const registry = 'https://registry.npmjs.org'; | ||
const file = 'package.json'; | ||
const year = 2; | ||
const month = 0; | ||
const dependencies = {}; | ||
|
||
export default { version, registry, file, year, month, dependencies }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.