Skip to content

Commit 6e942e5

Browse files
authored
Merge pull request #324 from aminya/prompt-less-installation
feat: add support for prompt-less installation
2 parents b436ead + b61d06b commit 6e942e5

File tree

3 files changed

+22
-9
lines changed

3 files changed

+22
-9
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,13 @@ module.exports = {
5353
You can use this package programatically via this exported interface:
5454

5555
```js
56-
export function install(packageName: string)
56+
export function install(packageName: string, hideUserPrompt: boolean = false)
5757
```
5858

5959
Alternatively, if you want to install dependencies via CLI, this package exposes a bin for that
6060

6161
```
62-
Usage: atom-package-deps <directory>
62+
Usage: atom-package-deps <directory> <hideUserPrompt = true>
6363
```
6464

6565
#### Screenshots

src/bin.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@ if (process.argv.length !== 3) {
66
console.error('Usage: atom-package-deps <directory>')
77
process.exit(1)
88
}
9-
const [, , directory] = process.argv
9+
const [, , directory, hideUserPromptStr] = process.argv
10+
11+
const hideUserPrompt = hideUserPromptStr === 'true'
1012

1113
async function main() {
1214
const resolved = path.resolve(process.cwd(), directory)
13-
await install(resolved)
15+
await install(resolved, hideUserPrompt)
1416
console.log('All Done!')
1517
}
1618

src/index.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { DependencyResolved } from './types'
1414

1515
type DependenciesResolved = (DependencyResolved | DependencyResolved[])[]
1616

17-
export async function install(packageName: string): Promise<void> {
17+
export async function install(packageName: string, hideUserPrompt = false): Promise<void> {
1818
invariant(typeof packageName === 'string' && packageName.length > 0, '[Package-Deps] Package name is required')
1919

2020
if (isPackageIgnored(packageName)) {
@@ -60,10 +60,21 @@ export async function install(packageName: string): Promise<void> {
6060
return
6161
}
6262

63-
const chosenDependencies = await confirmPackagesToInstall({
64-
packageName,
65-
dependencies: dependenciesToInstall,
66-
})
63+
let chosenDependencies: DependencyResolved[]
64+
if (!hideUserPrompt) {
65+
chosenDependencies = await confirmPackagesToInstall({
66+
packageName,
67+
dependencies: dependenciesToInstall,
68+
})
69+
} else {
70+
// prompt-less installation
71+
chosenDependencies = dependenciesToInstall.map((dep) => {
72+
if (Array.isArray(dep)) {
73+
return dep[0]
74+
}
75+
return dep
76+
})
77+
}
6778

6879
if (chosenDependencies.length === 0) {
6980
// Short-circuit if user interaction cancelled all

0 commit comments

Comments
 (0)