-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathprompt.ts
More file actions
109 lines (105 loc) · 3.43 KB
/
prompt.ts
File metadata and controls
109 lines (105 loc) · 3.43 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import Debug from 'debug';
import kleur from 'kleur';
import prompts from 'prompts';
import type { OptionValues, Options } from './options';
import { VALIDATORS } from './options';
const debug = Debug('@capacitor/create-plugin:prompt');
export const gatherDetails = (initialOptions: Options): Promise<OptionValues> => {
prompts.override(initialOptions);
return prompts(
[
{
type: 'text',
name: 'name',
message: `What should be the npm package of your plugin?\n`,
validate: VALIDATORS.name,
format: (value) => value.trim(),
},
{
type: 'text',
name: 'dir',
message: `What directory should be used for your plugin?\n`,
// no TS support for initial as a function
initial: ((prev: string) => prev.replace(/^@[^/]+\//, '')) as any,
validate: VALIDATORS.dir,
format: (value) => value.trim(),
},
{
type: 'text',
name: 'package-id',
message:
`What should be the Package ID for your plugin?\n\n` +
`${kleur.reset(
` Package IDs are unique identifiers used in apps and plugins. For plugins,\n` +
` they're used as a Java namespace. They must be in reverse domain name\n` +
` notation, generally representing a domain name that you or your company owns.\n`,
)}\n`,
initial: 'com.mycompany.plugins.example',
validate: VALIDATORS['package-id'],
format: (value) => value.trim(),
},
{
type: 'text',
name: 'class-name',
message: `What should be the class name for your plugin?\n`,
initial: 'Example',
validate: VALIDATORS['class-name'],
format: (value) => value.trim(),
},
{
type: 'text',
name: 'author',
message: `${kleur.reset('(optional)')} ${kleur.bold('Who is the author of this plugin?')}\n`,
validate: VALIDATORS.author,
format: (value) => value.trim(),
},
{
type: 'text',
name: 'repo',
message: `What is the repository URL for your plugin?\n`,
initial: (_prev, values) => `https://github.com/${values.author}/${values.dir}`,
validate: VALIDATORS.repo,
format: (value) => value.trim(),
},
{
type: 'select',
name: 'license',
message: `What license should be used for your plugin?\n`,
choices: [
{ title: 'MIT', value: 'MIT' },
{ title: 'ISC', value: 'ISC' },
{ title: 'Apache-2.0', value: 'Apache-2.0' },
{ title: 'other...', value: 'other' },
],
},
{
type: (prev) => (prev === 'other' ? 'text' : null),
name: 'license',
message: `Enter a SPDX license identifier for your plugin.\n`,
validate: VALIDATORS.license,
},
{
type: 'select',
name: 'android-lang',
message: `What language would you like to use for your Android plugin?\n`,
choices: [
{ title: 'Kotlin', value: 'kotlin' },
{ title: 'Java', value: 'java' },
],
},
{
type: 'text',
name: 'description',
message: `Enter a short description of plugin features.\n`,
validate: VALIDATORS.description,
format: (value) => value.trim(),
},
],
{
onCancel: async () => {
debug('Prompt cancelled by user.');
process.exit(1);
},
},
);
};