This repository has been archived by the owner on Feb 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsetdefaults.js
135 lines (128 loc) · 5.45 KB
/
setdefaults.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
const fs = require('fs-extra');
const prompt = require('prompt');
prompt.colors = false;
if (!process.env.CONFIG_FILE_PATH) throw 'Missing CONFIG_FILE_PATH. Please provide complete path to config file that will used to store trello and googlesheet configurations';
var schema = {
properties: {
'sprint.trello.board.id': {
pattern: /^[a-zA-Z0-9]+$/,
description: 'Enter trello board id used for sprint',
message: 'Must be alphanumeric',
required: true
},
'sprint.trello.board.listToExclude': {
pattern: /^[A-Za-z0-9\s\()\.-]+(?:, ?[A-Za-z0-9\s\()\.-]+)*$/,
description: 'List to exclude contains comma separated values for list to be excluded from fetching cards in corresponding list',
message: 'Comma separated list of alphanumeric characters plus allower characters: (, ), space and -',
default: 'Backlog'
},
'sprint.trello.label.name': {
pattern: /^[a-zA-Z0-9\s]+$/,
message: 'Must be alphanumeric characters separated by space.',
description: 'Name for label used for cards in current sprint',
default: 'Planned',
required: true
},
'sprint.trello.label.id': {
pattern: /^[a-zA-Z0-9]+$/,
description: 'Id for label used for cards in current sprint',
message: 'Must be alphanumeric.',
required: true
},
'unplanned.trello.label.name': {
pattern: /^[a-zA-Z0-9\s]+$/,
message: 'Must be alphanumeric characters separated by space.',
description: 'Name for label used for unplanned cards in current sprint',
default: 'Unplanned',
required: true
},
'unplanned.trello.label.id': {
pattern: /^[a-zA-Z0-9]+$/,
description: 'Id for label used for unplanned cards in current sprint',
message: 'Must be alphanumeric.',
required: true
},
'release.trello.board.id': {
pattern: /^[a-zA-Z0-9]+$/,
description: 'Enter trello board id used for release, that is, a separate board to handle completed sprint cards',
message: 'Must be alphanumeric.',
},
'release.trello.board.listToExclude': {
pattern: /^[A-Za-z0-9]+(?:, ?[A-Za-z0-9]+)*$/,
description: 'List to exclude contains comma separated values for board list to be excluded from fetching cards in corresponding list',
message: 'Comma separated list of alphanumeric characters'
},
'sheets.backlog.name': {
pattern: /^[a-zA-Z0-9]+$/,
description: 'Googlesheet sheet name used to maintain cards, and status, of current sprint.',
message: 'Must be alphanumeric.',
default: 'Sprint'
},
'sheets.backlog.range': {
pattern: /^![A-Z]\d+(?:\:[A-Z]\d*){1}$/,
message: 'Must be of GridRange format, for example, !A2:Z. Refer https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/other#gridrange',
default: '!A2:H'
},
'sheets.unplanned.name': {
pattern: /^[a-zA-Z0-9]+$/,
description: 'Googlesheet sheet name used to maintain unplanned cards added in current sprint',
message: 'Must be alphanumeric.',
default: 'Unplanned'
},
'sheets.unplanned.range': {
pattern: /^![A-Z]\d+(?:\:[A-Z]\d*){1}$/,
message: 'Must be of GridRange format, for example, !A2:Z. Refer https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/other#gridrange',
default: '!A3:H'
},
}
};
prompt.start();
prompt.get(schema, function(err, result) {
const FILENAME = process.env.CONFIG_FILE_PATH;
fs.outputFile(FILENAME, JSON.stringify(requestParamsToJSON(result), null, 2), 'utf8').then(() => {
console.log('The config file was saved successfully.');
}).catch(err => {
console.log(err);
});
});
/**
* Populate and return JSON format from input enter on prompt line
* @param {params} object that contains values provided
*/
function requestParamsToJSON(params) {
let config = {
"trello": {
"board": {
"sprint": {
"id": params['sprint.trello.board.id'],
"listToExclude": params['sprint.trello.board.listToExclude'],
"sprintLabel": {
"id": params['sprint.trello.label.id'],
"name": params['sprint.trello.label.name']
},
"unplannedLabel": {
"id": params['unplanned.trello.label.id'],
"name": params['unplanned.trello.label.name']
}
},
"release": {
"id": params['release.trello.board.id'],
"listToExclude": params['release.trello.board.listToExclude']
}
}
},
"googlesheet": {
"sheets": {
"backlog": {
"name": params['sheets.backlog.name'],
"range": params['sheets.backlog.range']
},
"unplanned": {
"name": params['sheets.unplanned.name'],
"range": params['sheets.unplanned.range']
},
}
}
};
return config;
}