cht-conf 3.15.2 → 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 +14 -0
- package/package.json +1 -1
- package/src/fn/convert-training-forms.js +17 -0
- package/src/fn/upload-training-forms.js +17 -0
- package/src/fn/validate-training-forms.js +12 -0
- package/src/fn/watch-project.js +73 -66
- package/src/lib/main.js +9 -1
- package/src/lib/package-lib.js +1 -0
- package/src/lib/project-paths.js +1 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
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
|
+
|
|
8
|
+
## [3.15.3](https://github.com/medic/cht-conf/compare/v3.15.2...v3.15.3) (2023-02-28)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* **#538:** support node 18 ([f7fb90c](https://github.com/medic/cht-conf/commit/f7fb90c0feb87e23311b97aa44fc3f5b60e17d10)), closes [#538](https://github.com/medic/cht-conf/issues/538)
|
|
14
|
+
|
|
1
15
|
## [3.15.2](https://github.com/medic/cht-conf/compare/v3.15.1...v3.15.2) (2022-12-15)
|
|
2
16
|
|
|
3
17
|
|
package/package.json
CHANGED
|
@@ -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
|
+
};
|
package/src/fn/watch-project.js
CHANGED
|
@@ -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
|
|
91
|
-
if (
|
|
92
|
-
return
|
|
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
|
-
|
|
95
|
-
if (
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
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
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
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
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
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
|
-
|
|
131
|
+
|
|
132
|
+
return;
|
|
126
133
|
};
|
|
127
134
|
|
|
128
|
-
const
|
|
129
|
-
if (eventType === watcherEvents.DeleteEvent && deleteForm(fileName,
|
|
135
|
+
const processForm = (eventType, fileName, commandContext) => {
|
|
136
|
+
if (eventType === watcherEvents.DeleteEvent && deleteForm(fileName, commandContext.path)) {
|
|
130
137
|
return true;
|
|
131
138
|
}
|
|
132
|
-
let form =
|
|
139
|
+
let form = uploadForms.formFileMatcher(fileName);
|
|
133
140
|
if (form) {
|
|
134
141
|
eventQueue.enqueue(async () => {
|
|
135
|
-
await
|
|
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 =
|
|
149
|
+
form = convertForms.formFileMatcher(fileName);
|
|
142
150
|
if (form) {
|
|
143
151
|
eventQueue.enqueue(async () => {
|
|
144
|
-
await
|
|
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
|
|
154
|
-
if (
|
|
155
|
-
|
|
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
|
-
|
|
158
|
-
if (
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
216
|
-
|
|
232
|
+
const formContext = getFormCommandContext(parsedPath);
|
|
233
|
+
if (formContext) {
|
|
234
|
+
processForm(event.type, fileName, formContext);
|
|
217
235
|
continue;
|
|
218
236
|
}
|
|
219
237
|
|
|
220
|
-
|
|
221
|
-
|
|
238
|
+
const formMediaContext = getFormMediaCommandContext(parsedPath);
|
|
239
|
+
if (formMediaContext) {
|
|
222
240
|
const dirName = path.parse(parsedPath.dir).base;
|
|
223
|
-
|
|
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 => {
|
package/src/lib/package-lib.js
CHANGED
|
@@ -25,6 +25,7 @@ module.exports = (pathToProject, entry, baseEslintPath, options = {}) => {
|
|
|
25
25
|
filename: outputFilename,
|
|
26
26
|
libraryTarget: options.libraryTarget ? 'umd' : undefined,
|
|
27
27
|
globalObject: options.libraryTarget,
|
|
28
|
+
hashFunction: 'sha512' // remove when we upgrade to webpack 5
|
|
28
29
|
},
|
|
29
30
|
optimization: {
|
|
30
31
|
minimize: !!options.minifyScripts,
|
package/src/lib/project-paths.js
CHANGED
|
@@ -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'
|