forked from electron/apps
-
Notifications
You must be signed in to change notification settings - Fork 1
/
wizard.js
93 lines (91 loc) · 2.48 KB
/
wizard.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
const categories = require('./lib/app-categories')
const inquirer = require('inquirer')
const isUrl = require('is-url')
const path = require('path')
const fs = require('fs')
const slugify = require('slugg')
const mkdirp = require('mkdirp')
const cleanDeep = require('clean-deep')
const yaml = require('yaml')
const existingSlugs = fs.readdirSync(path.join(__dirname, 'apps'))
const questions = [
{
type: 'input',
name: 'name',
message: 'What is the name of the app?',
validate: function (value) {
if (!value) return 'Please enter a name'
const slug = slugify(value)
if (existingSlugs.includes(slug))
return `There is already an app directory named '${slug}'.`
return true
},
},
{
type: 'input',
name: 'description',
message: 'Short description',
validate: function (value) {
if (!value) return 'Please enter a description'
if (value.length > 100) return `Too long! Try shortening: ${value}`
return true
},
},
{
type: 'input',
name: 'website',
message: 'Website (can be repository URL if app has no website)',
validate: function (value) {
if (!isUrl(value)) return 'Please enter a fully-qualified URL'
return true
},
},
{
type: 'list',
name: 'category',
message: 'App category',
choices: categories,
validate: function (value) {
if (!value) return 'Please select a category'
},
},
{
type: 'input',
name: 'repository',
message: 'Repository (optional)',
},
{
type: 'input',
name: 'keywords',
message: 'Keywords (optional, comma-delimited)',
filter: function (value) {
return value.split(',').map((keyword) => keyword.trim())
},
},
{
type: 'input',
name: 'license',
message: 'License (optional)',
},
]
inquirer
.prompt(questions)
.then(function (answers) {
const app = cleanDeep(answers)
const slug = slugify(app.name)
const basepath = path.join(__dirname, `apps/${slug}`)
const yamlPath = path.join(basepath, `${slug}.yml`)
const yamlContent = yaml.stringify(app, 2)
mkdirp(basepath)
fs.writeFileSync(yamlPath, yamlContent)
console.log()
console.log(`Yay! Created ${path.relative(process.cwd(), yamlPath)}`)
console.log(`Now you just need to add an icon named ${slug}-icon.png\n`)
console.log(
`Once you're done, run \`npm test\` to verify. Then open your pull request!`
)
console.log()
})
.catch((error) => {
console.error(error)
})