cht-conf 3.15.3 → 3.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ # [3.16.0](https://github.com/medic/cht-conf/compare/v3.15.3...v3.16.0) (2023-03-09)
2
+
3
+
4
+ ### Features
5
+
6
+ * **medic/cht-core#6598:** Command line to convert and upload training forms ([#529](https://github.com/medic/cht-conf/issues/529)) ([fb700ef](https://github.com/medic/cht-conf/commit/fb700ef94fc8a0b86bb9bdeab36f42bc93970d20)), closes [medic/cht-core#6598](https://github.com/medic/cht-core/issues/6598)
7
+
1
8
  ## [3.15.3](https://github.com/medic/cht-conf/compare/v3.15.2...v3.15.3) (2023-02-28)
2
9
 
3
10
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cht-conf",
3
- "version": "3.15.3",
3
+ "version": "3.16.0",
4
4
  "description": "Configure CHT deployments",
5
5
  "main": "./src/lib/main.js",
6
6
  "engines": {
@@ -0,0 +1,17 @@
1
+ const convertForms = require('../lib/convert-forms').execute;
2
+ const environment = require('../lib/environment');
3
+ const { TRAINING_FORMS_PATH } = require('../lib/project-paths');
4
+
5
+ const convertTrainingForms = (forms) => {
6
+ return convertForms(environment.pathToProject, 'training', {
7
+ enketo: true,
8
+ forms: forms,
9
+ });
10
+ };
11
+
12
+ module.exports = {
13
+ requiresInstance: false,
14
+ convertTrainingForms,
15
+ TRAINING_FORMS_PATH,
16
+ execute: () => convertTrainingForms(environment.extraArgs)
17
+ };
@@ -0,0 +1,17 @@
1
+ const environment = require('../lib/environment');
2
+ const uploadForms = require('../lib/upload-forms').execute;
3
+ const { TRAINING_FORMS_PATH } = require('../lib/project-paths');
4
+
5
+ const uploadTrainingForms = (forms) => {
6
+ return uploadForms(environment.pathToProject, 'training', {
7
+ id_prefix: 'training:',
8
+ forms: forms,
9
+ });
10
+ };
11
+
12
+ module.exports = {
13
+ requiresInstance: true,
14
+ uploadTrainingForms,
15
+ TRAINING_FORMS_PATH,
16
+ execute: () => uploadTrainingForms(environment.extraArgs)
17
+ };
@@ -0,0 +1,12 @@
1
+ const validateForms = require('../lib/validate-forms');
2
+ const environment = require('../lib/environment');
3
+
4
+ const validateTrainingForms = (forms) => {
5
+ return validateForms(environment.pathToProject, 'training', { forms });
6
+ };
7
+
8
+ module.exports = {
9
+ requiresInstance: false,
10
+ validateTrainingForms,
11
+ execute: () => validateTrainingForms(environment.extraArgs)
12
+ };
@@ -8,14 +8,17 @@ const watcher = require('@parcel/watcher');
8
8
  const { validateAppForms } = require('./validate-app-forms');
9
9
  const { validateContactForms } = require('./validate-contact-forms');
10
10
  const { validateCollectForms } = require('./validate-collect-forms');
11
+ const { validateTrainingForms } = require('./validate-training-forms');
11
12
  const { uploadAppForms } = require('./upload-app-forms');
12
13
  const { uploadContactForms } = require('./upload-contact-forms');
13
14
  const { uploadCollectForms } = require('./upload-collect-forms');
15
+ const { uploadTrainingForms } = require('./upload-training-forms');
14
16
  const convertForms = require('../lib/convert-forms');
15
17
  const uploadForms = require('../lib/upload-forms');
16
18
  const { deleteForms } = require('../fn/delete-forms');
17
19
  const { convertAppForms, APP_FORMS_PATH } = require('./convert-app-forms');
18
20
  const { convertContactForm, CONTACT_FORMS_PATH } = require('./convert-contact-forms');
21
+ const { convertTrainingForms, TRAINING_FORMS_PATH } = require('./convert-training-forms');
19
22
  const { convertCollectForms, COLLECT_FORMS_PATH } = require('./convert-collect-forms');
20
23
  const { uploadAppSettings, APP_SETTINGS_DIR_PATH, APP_SETTINGS_JSON_PATH } = require('./upload-app-settings');
21
24
  const { execute: compileAppSettings, configFileMatcher } = require('./compile-app-settings');
@@ -39,8 +42,10 @@ const uploadInitialState = async (api) => {
39
42
  await uploadResources();
40
43
  await runValidation(validateAppForms, environment.extraArgs);
41
44
  await runValidation(validateContactForms, environment.extraArgs);
45
+ await runValidation(validateTrainingForms, environment.extraArgs);
42
46
  await uploadAppForms(environment.extraArgs);
43
47
  await uploadContactForms(environment.extraArgs);
48
+ await uploadTrainingForms(environment.extraArgs);
44
49
  await uploadCustomTranslations();
45
50
  await uploadAppSettings(api);
46
51
  };
@@ -87,62 +92,64 @@ const deleteForm = (fileName, formDir) => {
87
92
  return false;
88
93
  };
89
94
 
90
- const processAppForm = (eventType, fileName) => {
91
- if (eventType === watcherEvents.DeleteEvent && deleteForm(fileName, APP_FORMS_PATH)) {
92
- return true;
95
+ const getFormCommandContext = (parsedPath) => {
96
+ if (parsedPath.dir === path.join(environment.pathToProject, APP_FORMS_PATH)) {
97
+ return {
98
+ path: APP_FORMS_PATH,
99
+ validateForms: validateAppForms,
100
+ uploadForms: uploadAppForms,
101
+ convertForms: convertAppForms,
102
+ };
93
103
  }
94
- let form = uploadForms.formFileMatcher(fileName);
95
- if (form) {
96
- eventQueue.enqueue(async () => {
97
- await runValidation(validateAppForms, [form]);
98
- await uploadAppForms([form]);
99
- return fileName;
100
- });
101
- return true;
104
+
105
+ if (parsedPath.dir === path.join(environment.pathToProject, TRAINING_FORMS_PATH)) {
106
+ return {
107
+ path: TRAINING_FORMS_PATH,
108
+ validateForms: validateTrainingForms,
109
+ uploadForms: uploadTrainingForms,
110
+ convertForms: convertTrainingForms,
111
+ };
102
112
  }
103
113
 
104
- form = convertForms.formFileMatcher(fileName);
105
- if (form) {
106
- eventQueue.enqueue(async () => {
107
- await convertAppForms([form]);
108
- return fileName;
109
- });
110
- return true;
114
+ if (parsedPath.dir === path.join(environment.pathToProject, CONTACT_FORMS_PATH)) {
115
+ return {
116
+ path: CONTACT_FORMS_PATH,
117
+ validateForms: validateContactForms,
118
+ uploadForms: uploadContactForms,
119
+ convertForms: convertContactForm,
120
+ };
111
121
  }
112
- return false;
113
- };
114
122
 
115
- const processAppFormMedia = (formMediaDir, fileName) => {
116
- const form = uploadForms.formMediaMatcher(formMediaDir);
117
- if (form) {
118
- eventQueue.enqueue(async () => {
119
- await runValidation(validateAppForms,[form]);
120
- await uploadAppForms([form]);
121
- return fileName;
122
- });
123
- return true;
123
+ if (parsedPath.dir === path.join(environment.pathToProject, COLLECT_FORMS_PATH)) {
124
+ return {
125
+ path: COLLECT_FORMS_PATH,
126
+ validateForms: validateCollectForms,
127
+ uploadForms: uploadCollectForms,
128
+ convertForms: convertCollectForms,
129
+ };
124
130
  }
125
- return false;
131
+
132
+ return;
126
133
  };
127
134
 
128
- const processContactForm = (eventType, fileName) => {
129
- if (eventType === watcherEvents.DeleteEvent && deleteForm(fileName, CONTACT_FORMS_PATH)) {
135
+ const processForm = (eventType, fileName, commandContext) => {
136
+ if (eventType === watcherEvents.DeleteEvent && deleteForm(fileName, commandContext.path)) {
130
137
  return true;
131
138
  }
132
- let form = convertForms.formFileMatcher(fileName);
139
+ let form = uploadForms.formFileMatcher(fileName);
133
140
  if (form) {
134
141
  eventQueue.enqueue(async () => {
135
- await convertContactForm([form]);
142
+ await runValidation(commandContext.validateForms, [form]);
143
+ await commandContext.uploadForms([form]);
136
144
  return fileName;
137
145
  });
138
146
  return true;
139
147
  }
140
148
 
141
- form = uploadForms.formFileMatcher(fileName);
149
+ form = convertForms.formFileMatcher(fileName);
142
150
  if (form) {
143
151
  eventQueue.enqueue(async () => {
144
- await runValidation(validateContactForms,[form]);
145
- await uploadContactForms([form]);
152
+ await commandContext.convertForms([form]);
146
153
  return fileName;
147
154
  });
148
155
  return true;
@@ -150,24 +157,34 @@ const processContactForm = (eventType, fileName) => {
150
157
  return false;
151
158
  };
152
159
 
153
- const processCollectForm = (eventType, fileName) => {
154
- if (eventType === watcherEvents.DeleteEvent && deleteForm(fileName, COLLECT_FORMS_PATH)) {
155
- return true;
160
+ const getFormMediaCommandContext = (parsedPath) => {
161
+ if (parsedPath.dir.startsWith(path.join(environment.pathToProject, APP_FORMS_PATH))
162
+ && path.parse(parsedPath.dir).dir.endsWith(APP_FORMS_PATH)) {
163
+ // Check if the directory's immediate parent is forms/app
164
+ return {
165
+ validateForms: validateAppForms,
166
+ uploadForms: uploadAppForms,
167
+ };
156
168
  }
157
- let form = uploadForms.formFileMatcher(fileName);
158
- if (form) {
159
- eventQueue.enqueue(async () => {
160
- await runValidation(validateCollectForms,[form]);
161
- await uploadCollectForms([form]);
162
- return fileName;
163
- });
164
- return true;
169
+
170
+ if (parsedPath.dir.startsWith(path.join(environment.pathToProject, TRAINING_FORMS_PATH))
171
+ && path.parse(parsedPath.dir).dir.endsWith(TRAINING_FORMS_PATH)) {
172
+ // Check if the directory's immediate parent is forms/training
173
+ return {
174
+ validateForms: validateTrainingForms,
175
+ uploadForms: uploadTrainingForms,
176
+ };
165
177
  }
166
178
 
167
- form = convertForms.formFileMatcher(fileName);
179
+ return;
180
+ };
181
+
182
+ const processFormMedia = (formMediaDir, fileName, commandContext) => {
183
+ const form = uploadForms.formMediaMatcher(formMediaDir);
168
184
  if (form) {
169
185
  eventQueue.enqueue(async () => {
170
- await convertCollectForms([form]);
186
+ await runValidation(commandContext.validateForms,[form]);
187
+ await commandContext.uploadForms([form]);
171
188
  return fileName;
172
189
  });
173
190
  return true;
@@ -212,29 +229,19 @@ const watchProject = {
212
229
  const parsedPath = path.parse(changePath);
213
230
  const fileName = parsedPath.base;
214
231
 
215
- if (parsedPath.dir === path.join(environment.pathToProject, APP_FORMS_PATH)) {
216
- processAppForm(event.type, fileName);
232
+ const formContext = getFormCommandContext(parsedPath);
233
+ if (formContext) {
234
+ processForm(event.type, fileName, formContext);
217
235
  continue;
218
236
  }
219
237
 
220
- if (parsedPath.dir.startsWith(path.join(environment.pathToProject, APP_FORMS_PATH))
221
- && path.parse(parsedPath.dir).dir.endsWith(APP_FORMS_PATH)) { // check if the directory's immediate parent is forms/app
238
+ const formMediaContext = getFormMediaCommandContext(parsedPath);
239
+ if (formMediaContext) {
222
240
  const dirName = path.parse(parsedPath.dir).base;
223
- processAppFormMedia(dirName, fileName);
241
+ processFormMedia(dirName, fileName, formMediaContext);
224
242
  continue;
225
243
  }
226
244
 
227
- if (parsedPath.dir === path.join(environment.pathToProject, CONTACT_FORMS_PATH)) {
228
- processContactForm(event.type, fileName);
229
- continue;
230
- }
231
-
232
- if (parsedPath.dir === path.join(environment.pathToProject, COLLECT_FORMS_PATH)) {
233
- processCollectForm(event.type, fileName);
234
- continue;
235
- }
236
-
237
-
238
245
  if (parsedPath.dir === path.join(environment.pathToProject, TRANSLATIONS_DIR_PATH)) {
239
246
  eventQueue.enqueue(async () => {
240
247
  await uploadCustomTranslations();
package/src/lib/main.js CHANGED
@@ -21,14 +21,17 @@ const defaultActions = [
21
21
  'convert-app-forms',
22
22
  'convert-collect-forms',
23
23
  'convert-contact-forms',
24
+ 'convert-training-forms',
24
25
  'validate-app-forms',
25
26
  'validate-collect-forms',
26
27
  'validate-contact-forms',
28
+ 'validate-training-forms',
27
29
  'backup-all-forms',
28
30
  'delete-all-forms',
29
31
  'upload-app-forms',
30
32
  'upload-collect-forms',
31
33
  'upload-contact-forms',
34
+ 'upload-training-forms',
32
35
  'upload-resources',
33
36
  'upload-branding',
34
37
  'upload-partners',
@@ -41,12 +44,15 @@ const defaultArchiveActions = [
41
44
  'convert-app-forms',
42
45
  'convert-collect-forms',
43
46
  'convert-contact-forms',
47
+ 'convert-training-forms',
44
48
  'validate-app-forms',
45
49
  'validate-collect-forms',
46
50
  'validate-contact-forms',
51
+ 'validate-training-forms',
47
52
  'upload-app-forms',
48
53
  'upload-collect-forms',
49
54
  'upload-contact-forms',
55
+ 'upload-training-forms',
50
56
  'upload-resources',
51
57
  'upload-branding',
52
58
  'upload-partners',
@@ -148,7 +154,8 @@ module.exports = async (argv, env) => {
148
154
  const validateActions = [
149
155
  'validate-app-forms',
150
156
  'validate-collect-forms',
151
- 'validate-contact-forms'
157
+ 'validate-contact-forms',
158
+ 'validate-training-forms',
152
159
  ];
153
160
  actions = actions.filter(action => !validateActions.includes(action));
154
161
  } else {
@@ -161,6 +168,7 @@ module.exports = async (argv, env) => {
161
168
  addFormValidationIfNecessary('app');
162
169
  addFormValidationIfNecessary('collect');
163
170
  addFormValidationIfNecessary('contact');
171
+ addFormValidationIfNecessary('training');
164
172
  }
165
173
 
166
174
  actions = actions.map(actionName => {
@@ -6,6 +6,7 @@ module.exports = {
6
6
  APP_FORMS_PATH: path.join('forms', 'app'),
7
7
  CONTACT_FORMS_PATH: path.join('forms', 'contact'),
8
8
  COLLECT_FORMS_PATH: path.join('forms', 'collect'),
9
+ TRAINING_FORMS_PATH: path.join('forms', 'training'),
9
10
  TRANSLATIONS_DIR_PATH: 'translations',
10
11
  RESOURCE_CONFIG_PATH: 'resources.json',
11
12
  RESOURCES_DIR_PATH: 'resources'