forked from alteryx/alteryx-tool-generator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
user-input.js
170 lines (159 loc) · 6.14 KB
/
user-input.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
const prompt = require('prompt')
exports.getUserInput = () => new Promise((resolve, reject) => {
const schema = {
properties: {
ToolName: {
description: 'Tool Name',
pattern: /^[a-zA-Z\s\d.\-_]{1,100}$/,
message: 'Tool Name is required. May only contain letters, numbers, spaces, periods, underscores, or dashes and be 100 characters or less.',
required: true
},
RootToolName: {
description: 'Root Tool Name',
pattern: /^[a-zA-Z\s\d.\-_]{1,100}$/,
message: 'Root Tool Name is required. May only contain letters, numbers, spaces, periods, underscores, or dashes and be 100 characters or less.',
required: true
},
Version: {
description: 'Tool Version',
pattern: /^[\d]{0,25}$/,
message: 'Must be written as a whole number and be 25 characters or less.',
default: 1,
required: false
},
Author: {
description: 'Author',
pattern: /^[a-zA-Z\s\d.\-_,]{1,150}$/,
message: 'Author is required. May only contain letters, numbers, spaces, periods, commas, underscores, or dashes and be 150 characters or less.',
required: true
},
Company: {
description: 'Company',
pattern: /^[a-zA-Z\s\d.\-_,]{0,150}$/,
message: 'May only contain letters, numbers, spaces, periods, commas, underscores, or dashes and be 150 characters or less.',
required: false
},
Copyright: {
description: 'Copyright',
pattern: /^[\d]{4}$/,
message: 'May only contain numbers and be 4 characters long.',
required: false
},
Category: {
description: 'Category',
pattern: /^(?!.*Favorites|favorites)[a-zA-Z\s]{0,100}$/,
message: 'May only contain letters or spaces and be 100 characters or less. Cannot be categorized in Favorites.',
required: false
},
Description: {
description: 'Description',
pattern: /^[a-zA-Z\s\d.\-_,]{0,1000}$/,
message: 'May only contain letters, numbers, spaces, periods, commas, underscores, or dashes and be 1,000 characters or less.',
required: false
},
SearchTags: {
description: 'Search Tags (comma separated)',
pattern: /^[a-zA-Z\s,]{0,200}$/,
message: 'May only contain letters, spaces, or commas and be 200 characters or less.',
required: false
},
Backend: {
description: 'Will the engine for your tool be a macro (M) or JavaScript (J) file?',
pattern: /M{1}|J{1}|m{1}|j{1}/,
message: 'Please enter M (macro) or J (JavaScript).',
required: true
},
IconPath: {
description: 'Path to Icon image file',
pattern: /default_icon.png|[A-Z]:\\[a-zA-Z\s\d.\-_\\]{0,246}.png$|[A-Z]:\\[a-zA-Z\s\d.\-_\\]{0,246}.PNG$/,
message: 'Please select a png image file. Path must be 250 characters or less.',
default: 'default_icon.png',
required: false
},
InputConnections: {
description: 'Number of input connections',
pattern: /^[0-5]{1}$/,
message: 'Must be written as a whole number between 0 and 5.',
required: true
},
OutputConnections: {
description: 'Number of output connections',
pattern: /^[0-5]{1}$/,
message: 'Must be written as a whole number between 0 and 5.',
required: true
}
}
}
console.log('\nEnter the following to configure your project...\n')
prompt.message = '' // removes prompt: from the front of each question
prompt.start()
prompt.get(schema, (err, result) => {
if (err) {
reject(err)
return
}
const userInput = result
const inputSchema = {
'properties': {}
}
for (let i = 1; i <= userInput.InputConnections; i += 1) {
const name = `InputConnectionName_${i}`
const nameValue = {
description: `Input Connection Name ${i}`,
pattern: /^[a-zA-Z\s\d.\-_]{1,100}$/,
message: 'May only contain letters, numbers, spaces, periods, underscores, or dashes and be 100 characters or less.',
type: 'string',
required: true
}
inputSchema.properties[name] = nameValue
const label = `InputConnectionLabel_${i}`
const labelValue = {
description: `Input Connection Label ${i}`,
pattern: /^[a-zA-Z\d]{1}$/,
message: 'May only contain one letter or number.',
type: 'string',
required: true
}
inputSchema.properties[label] = labelValue
}
const outputSchema = {
'properties': {}
}
for (let i = 1; i <= userInput.OutputConnections; i += 1) {
const name = `OutputConnectionName_${i}`
const nameValue = {
description: `Output Connection Name ${i}`,
pattern: /^[a-zA-Z\s\d.\-_]{1,100}$/,
message: 'May only contain letters, numbers, spaces, periods, underscores, or dashes and be 100 characters or less.',
type: 'string',
required: true
}
outputSchema.properties[name] = nameValue
const label = `OutputConnectionLabel_${i}`
const labelValue = {
description: `Output Connection Label ${i}`,
pattern: /^[a-zA-Z\d]{1}$/,
message: 'May only contain one letter or number.',
type: 'string',
required: true
}
outputSchema.properties[label] = labelValue
}
if (userInput.InputConnections > 0) {
console.log(`\n${userInput.InputConnections} input connections specified. Please enter name and label for each (Required).\n`)
}
// prompt.get needs to be nested otherwise it acts weird and results in duplicate entries
prompt.get(inputSchema, (inputErr, inputResult) => {
userInput.InputDetails = inputResult
if (userInput.OutputConnections > 0) {
console.log(`\n${userInput.OutputConnections} output connections specified. Please enter name and label for each (Required).`)
}
prompt.get(outputSchema, (outputErr, outputResult) => {
userInput.OutputDetails = outputResult
console.log('\nProject Configuration:\n')
console.log(JSON.stringify(userInput, null, 4))
resolve(userInput)
})
})
})
})