Skip to content

Commit ab87b60

Browse files
committed
Refactor and fix errors
1 parent 639fb7c commit ab87b60

File tree

9 files changed

+58
-60
lines changed

9 files changed

+58
-60
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,3 @@ build/Release
2525
# Dependency directory
2626
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
2727
node_modules
28-
lib

.node-version

Lines changed: 0 additions & 1 deletion
This file was deleted.

.npmignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
node_modules
2-
src
2+
LICENSE
3+
.*

.nvmrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v5
1+
v6

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2015 Leonardo Gatica
3+
Copyright (c) 2016 Leonardo Gatica
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

package.json

Lines changed: 19 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,15 @@
22
"name": "totp-cli",
33
"version": "1.0.0",
44
"description": "Insert/Generate a TOTP for a service from pass",
5-
"main": "lib",
5+
"main": "src",
66
"scripts": {
7-
"prepublish": "npm run build -s",
8-
"prebuild": "npm run lint -s && npm run clean -s",
9-
"build": "babel src --out-dir lib --source-maps",
10-
"lint": "eslint src",
11-
"clean": "rimraf lib"
7+
"prepublish": "eslint src"
128
},
139
"engines": {
14-
"node": ">=0.12"
10+
"node": ">=4"
1511
},
1612
"bin": {
17-
"totp": "lib/totp.js"
13+
"totp": "src/totp.js"
1814
},
1915
"preferGlobal": true,
2016
"repository": {
@@ -33,54 +29,43 @@
3329
},
3430
"homepage": "https://github.com/lgaticaq/node-totp-cli#readme",
3531
"dependencies": {
32+
"chalk": "^1.1.3",
3633
"commander": "^2.9.0",
3734
"copy-paste": "^1.2.0",
38-
"inquirer": "^0.11.1",
35+
"inquirer": "^1.0.2",
3936
"notp": "^2.0.3",
40-
"thirty-two": "^1.0.1"
37+
"thirty-two": "^1.0.1",
38+
"update-notifier": "^0.7.0"
4139
},
4240
"devDependencies": {
43-
"babel-cli": "^6.8.0",
44-
"babel-core": "^6.8.0",
45-
"babel-preset-es2015": "^6.3.13",
46-
"eslint": "^2.10.0",
47-
"rimraf": "^2.5.0"
41+
"eslint": "^2.10.1"
4842
},
4943
"eslintConfig": {
44+
"env": {
45+
"es6": true,
46+
"node": true
47+
},
48+
"extends": "eslint:recommended",
5049
"rules": {
5150
"indent": [
5251
2,
5352
2
5453
],
55-
"quotes": [
56-
2,
57-
"single"
58-
],
5954
"linebreak-style": [
6055
2,
6156
"unix"
6257
],
58+
"quotes": [
59+
2,
60+
"single"
61+
],
6362
"semi": [
6463
2,
6564
"always"
6665
],
6766
"no-console": [
6867
0
6968
]
70-
},
71-
"ecmaFeatures": {
72-
"modules": true
73-
},
74-
"env": {
75-
"es6": true,
76-
"node": true,
77-
"mocha": true
78-
},
79-
"extends": "eslint:recommended"
80-
},
81-
"babel": {
82-
"presets": [
83-
"es2015"
84-
]
69+
}
8570
}
8671
}

src/totp-generate.js

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,31 @@
22

33
'use strict';
44

5-
import {exec} from 'child_process';
6-
import program from 'commander';
7-
import notp from 'notp';
8-
import ncp from 'copy-paste';
9-
import base32 from 'thirty-two';
5+
const exec = require('child_process').exec;
6+
const program = require('commander');
7+
const chalk = require('chalk');
8+
const notp = require('notp');
9+
const ncp = require('copy-paste');
10+
const base32 = require('thirty-two');
11+
const updateNotifier = require('update-notifier');
12+
const pkg = require('../package.json');
1013

14+
updateNotifier({pkg}).notify();
1115

12-
const getCode = (service) => {
16+
const getCode = service => {
1317
let key;
1418
const pass = exec(`pass 2fa/${service}/code`);
1519

16-
pass.stdout.on('data', (data) => {
20+
pass.stdout.on('data', data => {
1721
key = data;
1822
});
19-
pass.stderr.on('data', (data) => {
20-
console.log(`Error: ${data}`);
23+
pass.stderr.on('data', () => {
24+
console.log(chalk.red(`Error: ${service} not stored`));
25+
process.exit(1);
2126
});
2227
pass.on('close', () => {
2328
const totp = notp.totp.gen(base32.decode(key));
24-
console.log(totp);
29+
console.log(chalk.green(totp));
2530
ncp.copy(totp.toString());
2631
process.exit(0);
2732
});
@@ -32,7 +37,7 @@ program
3237
.parse(process.argv);
3338

3439
if (program.args.length === 0) {
35-
console.error('service required');
40+
console.log(chalk.red('Service required'));
3641
process.exit(1);
3742
} else {
3843
getCode(program.args[0]);

src/totp-insert.js

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,16 @@
22

33
'use strict';
44

5-
import {exec} from 'child_process';
6-
import program from 'commander';
7-
import inquirer from 'inquirer';
5+
const exec = require('child_process').exec;
6+
const program = require('commander');
7+
const chalk = require('chalk');
8+
const inquirer = require('inquirer');
9+
const updateNotifier = require('update-notifier');
10+
const pkg = require('../package.json');
811

9-
const setCode = (service) => {
12+
updateNotifier({pkg}).notify();
13+
14+
const setCode = service => {
1015
inquirer.prompt([
1116
{
1217
type: 'password',
@@ -24,14 +29,15 @@ const setCode = (service) => {
2429
pass.stdin.write(`${answers.code1}\n`);
2530
pass.stdin.write(`${answers.code1}\n`);
2631

27-
pass.stderr.on('data', (data) => {
28-
console.log(`Error: ${data}`);
32+
pass.stderr.on('data', data => {
33+
console.log(chalk.red(`Error: ${data}`));
2934
});
3035
pass.on('close', () => {
36+
console.log(chalk.green('Stored code'));
3137
process.exit(0);
3238
});
3339
} else {
34-
console.log('Wrong code');
40+
console.log(chalk.red('Wrong code'));
3541
}
3642
});
3743
};
@@ -41,7 +47,7 @@ program
4147
.parse(process.argv);
4248

4349
if (program.args.length === 0) {
44-
console.error('service required');
50+
console.log(chalk.red('Service required'));
4551
process.exit(1);
4652
} else {
4753
setCode(program.args[0]);

src/totp.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@
22

33
'use strict';
44

5-
import program from 'commander';
6-
import pkg from '../package.json';
5+
const program = require('commander');
6+
const updateNotifier = require('update-notifier');
7+
const pkg = require('../package.json');
8+
9+
updateNotifier({pkg}).notify();
710

811
program
912
.version(pkg.version)

0 commit comments

Comments
 (0)