-
Notifications
You must be signed in to change notification settings - Fork 15
/
index.js
executable file
·45 lines (38 loc) · 1.06 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#! /usr/bin/env node
const prompts = require('prompts');
const {
getGitignoreNames, getFileType, writeFile, readFile,
} = require('./file_utils');
(async () => {
// Get .gitignore file names
const gitignores = await getGitignoreNames()
// Extract each .gitignore's type
const gitignoreTypes = getFileType(gitignores)
// Query the user
const { file } = await prompts(
[
{
type: 'confirm',
name: 'confirmation',
message: 'Would you like multiple .gitignore files?',
initial: false,
},
{
type: prev => (prev === false ? 'autocomplete' : 'autocompleteMultiselect'),
name: 'file',
message: 'What type of .gitignore file do you need?',
choices: gitignoreTypes,
min: 1,
limit: 15,
},
],
)
if (!file) {
console.info('👋 No type selected, exiting.')
return
}
// Get gitignore content based on the answer
const gitignoreContent = await readFile(`${file}`)
// Create the .gitignore file
await writeFile('.gitignore', gitignoreContent)
})();