Skip to content

Commit

Permalink
updating commander dependency and solving braking changes
Browse files Browse the repository at this point in the history
  • Loading branch information
carvilsi committed Aug 26, 2023
1 parent bf3d563 commit 2cc14bd
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 25 deletions.
11 changes: 6 additions & 5 deletions bin/snoopm.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@

'use strict';

const options = require('commander');
const { program } = require('commander');
const snoopm = require('./../index.js');
const version = require('./../package.json').version;

options
program
.version(version)
.usage('[options] [package dir or url repository] \n\n ProTip: On OS X Terminal Command Key + double_click must open the link on default browser')
.option('-v, --verbose','prints name, url and version (shows if there is newer version)')
.option('-c, --color','suprime colors output')
.option('-d, --dev','snooping devDependencies')
.option('-l, --lines','outputs lines instead table')
.parse(process.argv);
.option('-l, --lines','outputs lines instead table');

snoopm(options);
program.parse();
const options = program.opts();
snoopm(program.args, options);
31 changes: 18 additions & 13 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ var urls = [],
table = new Table(),
urlsPromises = [],
spinner,
dep = {};
dep = {},
args;
const debug = false;

var readPackage = (packageData) => {
Expand Down Expand Up @@ -223,34 +224,38 @@ var writeDown = (depData) => {
}
}

var snoopm = (options) => {
var snoopm = (args, options) => {
try {
spinner = new Spinner('SnOOping.. %s');
spinner.setSpinnerString('==^^^^==||__');
this.options = options;
if (typeof args === 'undefined') {
this.args = [];
} else {
this.args = args;
}

// we want a clean output for lines option without the spinner
if (typeof this.options.lines === 'undefined') {
spinner.start();
}

if (debug) console.log(`🐞 args[0] ${this.options.args[0]}`);
// we want to read the local package json file
if (!this.options.args.length || this.options.args[0] === '.') {
if (!this.args.length || this.args[0] === '.') {
readPackage(require(process.cwd().concat('/package.json')));
} else {
if (path.basename(this.options.args[0]).trim() === 'package.json'
|| this.options.args[0].indexOf('node_modules') !== -1) {
if (this.options.args[0].indexOf('.') === 0 || this.options.args[0].indexOf('/') === 0) {
var pathPackage = this.options.args[0];
if (this.options.args[0].indexOf('package.json') === -1) {
if (path.basename(this.args[0]).trim() === 'package.json'
|| this.args[0].indexOf('node_modules') !== -1) {
if (this.args[0].indexOf('.') === 0 || this.args[0].indexOf('/') === 0) {
var pathPackage = this.args[0];
if (this.args[0].indexOf('package.json') === -1) {
pathPackage = `${pathPackage}/package.json`;
}
readPackage(require(pathPackage));
}
// url to json raw provided
if (this.options.args[0].indexOf('http') === 0) {
var url = this.options.args[0];
if (this.args[0].indexOf('http') === 0) {
var url = this.args[0];
if (url.indexOf('github.com') > 0) {
url = url.replace('github.com','raw.githubusercontent.com');
url = url.replace('blob/','');
Expand All @@ -259,8 +264,8 @@ var snoopm = (options) => {
}
}
// trying yo read package.json from git hub repository and master branch
else if (this.options.args[0].indexOf('http') === 0) {
var url = this.options.args[0];
else if (this.args[0].indexOf('http') === 0) {
var url = this.args[0];
var urlArr = url.split('\/');
if (url.indexOf('github.com') > 0 && urlArr.length === 5) {
url = url.replace('github.com','raw.githubusercontent.com');
Expand Down
11 changes: 7 additions & 4 deletions package-lock.json

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

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "snoopm",
"version": "1.1.12",
"version": "1.1.13",
"description": "A cli to get at a glance what are the fundations of other Node.js code.",
"main": "index.js",
"scripts": {
Expand All @@ -21,7 +21,7 @@
"cli-spinner": "^0.2.10",
"cli-table": "^0.3.11",
"colors": "^1.4.0",
"commander": "^2.20.3",
"commander": "^11.0.0",
"logplease": "^1.2.15",
"semver": "^7.5.4"
},
Expand Down
1 change: 0 additions & 1 deletion tests/snoopm.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,6 @@ describe('SnOOpm at node_modules', async ()=> {

it('should retieve default table output for snooping at node_modules package.json "[node_modules_path]" with absolute path', async () => {
const absolutePathPackageNodeModule = `${process.cwd()}${pathPackageNodeModule.substring(1)}`;
console.log(absolutePathPackageNodeModule);
const {stdout} = await execa('./bin/snoopm.js', [absolutePathPackageNodeModule]);
console.log(stdout);
assertDependencies(stdout, snoopmDependencies);
Expand Down

0 comments on commit 2cc14bd

Please sign in to comment.