Skip to content

Commit

Permalink
Removed clipboardy due to problems with pkg
Browse files Browse the repository at this point in the history
  • Loading branch information
ThisNils authored and ThisNils committed Feb 9, 2021
1 parent 4858088 commit 795638e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,8 @@ dist

# TernJS port file
.tern-port

# Binaries
get-exchange-code-win.exe
get-exchange-code-linux
get-exchange-code-macos
15 changes: 12 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ const {
readdir, mkdir, writeFile, readFile,
} = require('fs').promises;
const { join } = require('path');
const { write } = require('clipboardy');
const open = require('open');
const { exec } = require('child_process');

const makeBool = (text) => text.toLowerCase() === 'y' || text.toLowerCase() === 'yes' || !text;

Expand All @@ -23,6 +23,15 @@ const makeForm = (keyValuePairs) => {
return data.toString();
};

const copyToClipboard = (text) => {
switch (process.platform) {
case 'darwin': exec(`echo '${text}' | pbcopy`); break;
case 'linux': exec(`echo ${text} | xclip -sel c`); break;
case 'win32': exec(`echo | set /p ecgvar="${text}" | clip`); break;
default: console.log('your OS is not supported');
}
};

const useDeviceAuth = async (deviceAuth) => {
const { data: { access_token: accessToken } } = await axios({
method: 'POST',
Expand Down Expand Up @@ -161,10 +170,10 @@ const useDeviceCode = (deviceCode) => new Promise((res) => {
process.stdout.cursorTo(0);
process.stdout.write('\r\x1b[K');
if (key.name.toLowerCase() === 'e') {
write(exchangeCode);
copyToClipboard(exchangeCode);
console.log('exchange code copied to clipboard');
} else if (key.name.toLowerCase() === 'a') {
write(JSON.stringify(deviceAuth, null, 2));
copyToClipboard(JSON.stringify(deviceAuth));
console.log('device auth copied to clipboard');
}
});
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
"license": "MIT",
"dependencies": {
"axios": "^4.2.5",
"clipboardy": "^2.3.0",
"open": "^7.4.0"
},
"pkg": {
Expand Down

0 comments on commit 795638e

Please sign in to comment.