-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Expand file tree
/
Copy pathwizard.js
More file actions
95 lines (93 loc) · 2.68 KB
/
wizard.js
File metadata and controls
95 lines (93 loc) · 2.68 KB
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
94
95
const categories = require('./lib/app-categories');
const { isUrl } = require('./lib/is-url');
const inquirer = require('inquirer');
const path = require('path');
const fs = require('fs');
const slugify = require('slugify');
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 = Object.entries(answers).reduce((acc, [key, value]) => {
if (value === '' || (Array.isArray(value) && value.length === 1 && value[0] === '')) {
return acc;
}
acc[key] = value;
return acc;
}, {});
console.log({ app });
const slug = slugify(app.name);
const basepath = path.join(path.join(__dirname, 'apps'), slug);
const yamlPath = path.join(basepath, `${slug}.yml`);
const yamlContent = yaml.stringify(app, 2);
fs.mkdirSync(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);
});