Skip to content

Commit

Permalink
added package manager detection
Browse files Browse the repository at this point in the history
  • Loading branch information
K1NXZ committed Oct 7, 2023
1 parent 1eaa4a7 commit 47495a9
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 11 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"base-x": "^4.0.0",
"commander": "^11.0.0",
"copy-paste": "^1.5.3",
"detect-package-manager": "^3.0.1",
"inquirer": "^9.2.11",
"untildify": "^5.0.0"
},
Expand Down
62 changes: 56 additions & 6 deletions pnpm-lock.yaml

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

10 changes: 5 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { decrypt, encrypt } from './lib/encryption.js'
import { fromBase58, toBase58 } from './lib/base58.js'
import ncp from 'copy-paste'
import untildify from 'untildify'
import { fetchCommand } from 'lib/command.js'

const program = new Command().name('envshare-cli').version('1.0.0')

Expand Down Expand Up @@ -93,13 +94,13 @@ program

const envFilePath = path.join(process.cwd(), envFile!)
const compositeKey = await uploadFile(envFilePath, ttl, reads)

const fc = await fetchCommand(compositeKey)
console.log(
`
Env file uploaded successfully.
name: ${path.basename(envFilePath)}
ID: ${compositeKey}
Command: npx envshare-cli@latest fetch ${compositeKey}
Command: ${fc}
`
)

Expand All @@ -126,9 +127,8 @@ Command: npx envshare-cli@latest fetch ${compositeKey}
console.log(`ID "${compositeKey}" copied to clipboard`)
break
case 'Command':
const c = `npx envshare-cli@latest fetch ${compositeKey}`
ncp.copy(c)
console.log(`Command "${c}" copied to clipboard`)
ncp.copy(fc)
console.log(`Command "${fc}" copied to clipboard`)
break
}
}
Expand Down
13 changes: 13 additions & 0 deletions src/lib/command.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { detect } from 'detect-package-manager'

export async function fetchCommand(id: string) {
const pm = await detect()
switch (pm) {
case 'pnpm':
return `pnpx envshare-cli@latest fetch ${id}`
case 'bun':
return `bunx envshare-cli@latest fetch ${id}`
default:
return `npx envshare-cli@latest fetch ${id}`
}
}

0 comments on commit 47495a9

Please sign in to comment.