@citolab/tspci-tao 2.0.9 → 2.3.0-alpha.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/LICENSE +674 -674
- package/package.json +6 -4
- package/readme.md +85 -85
- package/release-notes.md +9 -9
- package/src/createPackage.mjs +331 -307
- package/src/init.mjs +112 -0
- package/toa_pci_default/imsPciCreator.js +66 -66
- package/toa_pci_default/imsPciCreator.json +41 -41
- package/toa_pci_default/interaction/creator/img/icon.svg +8 -8
- package/toa_pci_default/interaction/creator/tpl/markup.tpl +18 -18
- package/toa_pci_default/interaction/creator/tpl/propertiesForm.tpl +7 -7
- package/toa_pci_default/interaction/creator/widget/Widget.js +14 -14
- package/toa_pci_default/interaction/creator/widget/states/Answer.js +26 -26
- package/toa_pci_default/interaction/creator/widget/states/Correct.js +44 -44
- package/toa_pci_default/interaction/creator/widget/states/Question.js +51 -51
- package/toa_pci_default/interaction/creator/widget/states/states.js +8 -8
- package/types/index.d.ts +17 -17
package/src/createPackage.mjs
CHANGED
|
@@ -1,307 +1,331 @@
|
|
|
1
|
-
import fs, { mkdirSync } from "fs";
|
|
2
|
-
import path from "path";
|
|
3
|
-
import archiver from "archiver";
|
|
4
|
-
|
|
5
|
-
export const bundle = () => {
|
|
6
|
-
const PACKAGE_ROOT_PATH = process.cwd();
|
|
7
|
-
|
|
8
|
-
const PACKAGER_PATH = path.join(PACKAGE_ROOT_PATH + "/node_modules/@citolab/tspci-tao");
|
|
9
|
-
|
|
10
|
-
// PROPERTIES CAN BE OVERRIDEN BY VALUES IN YOUR Package.json INSIDE YOUR PCI FOLDER
|
|
11
|
-
// OTHER CONFIG VALUES ARE: "pciJsFile" THE BUNDLED PCI FILE DEFAULTS TO: "/dist/index.js"
|
|
12
|
-
// AND icon WHICH CAN BE REFERENCED TO A SVG TO OVERRIDE THE 'LIKE' ICON.
|
|
13
|
-
const propertiesToReplace = {
|
|
14
|
-
typeIdentifier: "emptytypeIdentifier",
|
|
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
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
.
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
// copy
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
//
|
|
242
|
-
const
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
.
|
|
285
|
-
.
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
1
|
+
import fs, { mkdirSync } from "fs";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import archiver from "archiver";
|
|
4
|
+
|
|
5
|
+
export const bundle = () => {
|
|
6
|
+
const PACKAGE_ROOT_PATH = process.cwd();
|
|
7
|
+
|
|
8
|
+
const PACKAGER_PATH = path.join(PACKAGE_ROOT_PATH + "/node_modules/@citolab/tspci-tao");
|
|
9
|
+
|
|
10
|
+
// PROPERTIES CAN BE OVERRIDEN BY VALUES IN YOUR Package.json INSIDE YOUR PCI FOLDER
|
|
11
|
+
// OTHER CONFIG VALUES ARE: "pciJsFile" THE BUNDLED PCI FILE DEFAULTS TO: "/dist/index.js"
|
|
12
|
+
// AND icon WHICH CAN BE REFERENCED TO A SVG TO OVERRIDE THE 'LIKE' ICON.
|
|
13
|
+
const propertiesToReplace = {
|
|
14
|
+
typeIdentifier: "emptytypeIdentifier",
|
|
15
|
+
label: "label",
|
|
16
|
+
short: "short",
|
|
17
|
+
score: ["NONE"],
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const config = path.join(PACKAGE_ROOT_PATH, "package.json");
|
|
21
|
+
if (!fs.existsSync(config)) {
|
|
22
|
+
console.error(`cannot find package.json: ${config}`);
|
|
23
|
+
process.exit();
|
|
24
|
+
}
|
|
25
|
+
const rawConfigData = fs.readFileSync(config);
|
|
26
|
+
const packageData = JSON.parse(rawConfigData);
|
|
27
|
+
let migrated = false;
|
|
28
|
+
// show warning if not specified
|
|
29
|
+
for (const propertyName in propertiesToReplace) {
|
|
30
|
+
if (!packageData.config) {
|
|
31
|
+
migrated = true;
|
|
32
|
+
packageData.config = {};
|
|
33
|
+
}
|
|
34
|
+
if (!packageData.config.tspci) {
|
|
35
|
+
migrated = true;
|
|
36
|
+
packageData.config.tspci = {};
|
|
37
|
+
}
|
|
38
|
+
if (!packageData.config.tspci[propertyName] && packageData[propertyName]) {
|
|
39
|
+
packageData.config.tspci[propertyName] = packageData[propertyName];
|
|
40
|
+
delete packageData[propertyName];
|
|
41
|
+
migrated = true;
|
|
42
|
+
}
|
|
43
|
+
if (propertyName === "typeIdentifier") {
|
|
44
|
+
if (!packageData.config.tspci[propertyName]) {
|
|
45
|
+
console.error(
|
|
46
|
+
"'typeIdentifier' should be added as an option in package.json and should match the typeIdentifier of the PCI code file."
|
|
47
|
+
);
|
|
48
|
+
return;
|
|
49
|
+
} else if (!/^[A-Za-z0-9]*$/.test(packageData.config.tspci[propertyName])) {
|
|
50
|
+
console.error(
|
|
51
|
+
"'typeIdentifier' can only contain (alpha)numeric characters. The pci does not work in TAO if typeindentifier contains a hyphen therefor we restrict all non (alpha)numeric characters. Make sure typeIdentifier of the PCI code file matches the typeidentier in package.json."
|
|
52
|
+
);
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
} else {
|
|
56
|
+
if (!packageData.config.tspci[propertyName])
|
|
57
|
+
console.warn(
|
|
58
|
+
`${propertyName} not specified in ${packageData.name} in package.json using { config: tspci: {${propertiesToReplace[propertyName]}}`
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
propertiesToReplace.description = packageData.description;
|
|
64
|
+
propertiesToReplace.version = packageData.version;
|
|
65
|
+
|
|
66
|
+
if (migrated) {
|
|
67
|
+
console.warn('package.json has been migrated to use "{ config: { tspci: { typeIdentifier: ..., xx" properties.');
|
|
68
|
+
fs.writeFileSync(config, JSON.stringify(packageData, null, 2));
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const outputDirectory = path.join(PACKAGE_ROOT_PATH, "dist");
|
|
72
|
+
const outputDirectoryTemp = path.join(outputDirectory, "tmp");
|
|
73
|
+
|
|
74
|
+
// remove directory to be sure it's empty
|
|
75
|
+
if (fs.existsSync(outputDirectoryTemp)) {
|
|
76
|
+
fs.rmdirSync(outputDirectoryTemp, { recursive: true });
|
|
77
|
+
}
|
|
78
|
+
// re-create the directory
|
|
79
|
+
if (!fs.existsSync(outputDirectory)) {
|
|
80
|
+
mkdirSync(outputDirectory);
|
|
81
|
+
}
|
|
82
|
+
if (!fs.existsSync(outputDirectoryTemp)) {
|
|
83
|
+
mkdirSync(outputDirectoryTemp);
|
|
84
|
+
} else {
|
|
85
|
+
fs.rmdirSync(outputDirectoryTemp, { recursive: true });
|
|
86
|
+
mkdirSync(outputDirectoryTemp);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// copy all toa files that will be used as base,
|
|
90
|
+
// to override these files for a specific PCI: add them in the same structure in the tao_pci folder
|
|
91
|
+
// of the pci.
|
|
92
|
+
|
|
93
|
+
copyDirectoryRecursiveSync(path.join(PACKAGER_PATH, "toa_pci_default"), outputDirectoryTemp, false);
|
|
94
|
+
|
|
95
|
+
// ---------------------------------------------------------------------
|
|
96
|
+
// ADD THE VALUES THAT ARE SHOULD BE CONFIGURABLE WITHIN TAO
|
|
97
|
+
// ---------------------------------------------------------------------
|
|
98
|
+
|
|
99
|
+
// add variables from taoConfigValues, to be able to configurate PCI's
|
|
100
|
+
const configPath = path.join(PACKAGE_ROOT_PATH, "src/config.json");
|
|
101
|
+
|
|
102
|
+
if (fs.existsSync(configPath)) {
|
|
103
|
+
let configValues;
|
|
104
|
+
let configJson = JSON.parse(fs.readFileSync(configPath, "utf-8"));
|
|
105
|
+
configValues = Object.keys(configJson).reduce((acc, elem) => {
|
|
106
|
+
const defaultValue = configJson[elem];
|
|
107
|
+
|
|
108
|
+
let type = "string";
|
|
109
|
+
if (Number.isInteger(parseInt(defaultValue))) {
|
|
110
|
+
type = "number";
|
|
111
|
+
}
|
|
112
|
+
if (isBoolean(defaultValue)) {
|
|
113
|
+
type = "boolean";
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
acc.push({
|
|
117
|
+
name: `${elem}`,
|
|
118
|
+
type,
|
|
119
|
+
defaultValue: `"${defaultValue}"`, // type === "number" ? `${defaultValue}` : `"${defaultValue}"`,
|
|
120
|
+
optional: true,
|
|
121
|
+
});
|
|
122
|
+
return acc;
|
|
123
|
+
}, []);
|
|
124
|
+
|
|
125
|
+
// add default values in imsPciCreator.js
|
|
126
|
+
const defaultValues = `{
|
|
127
|
+
${configValues
|
|
128
|
+
.map((cv) => {
|
|
129
|
+
return `${cv.name}: ${cv.defaultValue}`;
|
|
130
|
+
})
|
|
131
|
+
.join(",")}
|
|
132
|
+
};`;
|
|
133
|
+
|
|
134
|
+
// loop through properties with values that should be replaced
|
|
135
|
+
// if the value is not in the config, the default value will be used
|
|
136
|
+
const defaultPackageJsonProperties = ["version", "description"];
|
|
137
|
+
for (const propertyName in propertiesToReplace) {
|
|
138
|
+
if (defaultPackageJsonProperties.includes(propertyName)) {
|
|
139
|
+
propertiesToReplace[propertyName] = packageData[propertyName];
|
|
140
|
+
} else {
|
|
141
|
+
propertiesToReplace[propertyName] = packageData.config.tspci[propertyName];
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
const creatorFile = path.join(outputDirectoryTemp, "imsPciCreator.js");
|
|
146
|
+
|
|
147
|
+
replace_string_in_file(
|
|
148
|
+
creatorFile,
|
|
149
|
+
"###_FIRST_SCORING_METHOD_###",
|
|
150
|
+
propertiesToReplace.score?.length > 0 ? propertiesToReplace.score[0] : "NONE"
|
|
151
|
+
);
|
|
152
|
+
replace_string_in_file(creatorFile, `'##__DEFAULT_VALUES__##'`, defaultValues);
|
|
153
|
+
|
|
154
|
+
// add stuff in interaction/creator/widget/states/Question.js
|
|
155
|
+
const variableDeclaration = `
|
|
156
|
+
${configValues
|
|
157
|
+
.map((cv) => {
|
|
158
|
+
return `var ${cv.name} = interaction.prop('${cv.name}') || ${cv.defaultValue};`;
|
|
159
|
+
})
|
|
160
|
+
.join("\r\n")}
|
|
161
|
+
`;
|
|
162
|
+
|
|
163
|
+
const setVariables = `
|
|
164
|
+
${configValues
|
|
165
|
+
.map((cv) => {
|
|
166
|
+
return `${cv.name} : ${cv.name},`;
|
|
167
|
+
})
|
|
168
|
+
.join("\r\n")}
|
|
169
|
+
`;
|
|
170
|
+
|
|
171
|
+
const callbacks = `${configValues
|
|
172
|
+
.map((cv) => {
|
|
173
|
+
return `${cv.name} : function(interaction, value){
|
|
174
|
+
//update the pci property value:
|
|
175
|
+
interaction.prop('${cv.name}', value);
|
|
176
|
+
|
|
177
|
+
//trigger change event:
|
|
178
|
+
interaction.triggerPci('${cv.name}', value);
|
|
179
|
+
}`;
|
|
180
|
+
})
|
|
181
|
+
.join(",\r\n")}
|
|
182
|
+
`;
|
|
183
|
+
|
|
184
|
+
const widgetAnswerFile = path.join(outputDirectoryTemp, "interaction/creator/widget/states/Answer.js");
|
|
185
|
+
replace_string_in_file(
|
|
186
|
+
widgetAnswerFile,
|
|
187
|
+
`'###_RD_TEMPLATES_###'`,
|
|
188
|
+
JSON.stringify(propertiesToReplace.score).replace("[", "").replace("]", "")
|
|
189
|
+
);
|
|
190
|
+
|
|
191
|
+
const widgetQuestionFile = path.join(outputDirectoryTemp, "interaction/creator/widget/states/Question.js");
|
|
192
|
+
|
|
193
|
+
replace_string_in_file(widgetQuestionFile, `// ##__SET_VARIABLES__##`, setVariables);
|
|
194
|
+
replace_string_in_file(widgetQuestionFile, `// ##__DECLARE_VARIABLES__##`, variableDeclaration);
|
|
195
|
+
replace_string_in_file(widgetQuestionFile, `// ##__CALLBACK__##`, callbacks);
|
|
196
|
+
// add controls in
|
|
197
|
+
const propertiesFormFile = path.join(outputDirectoryTemp, "interaction/creator/tpl/propertiesForm.tpl");
|
|
198
|
+
const template = `${configValues
|
|
199
|
+
.map((cv) => {
|
|
200
|
+
const capitalizedName = cv.name.charAt(0).toUpperCase() + cv.name.slice(1);
|
|
201
|
+
return `<label for="${cv.name}">{{__ "${capitalizedName}"}}</label>
|
|
202
|
+
<span class="icon-help tooltipstered" data-tooltip="~ .tooltip-content:first" data-tooltip-theme="info"></span>
|
|
203
|
+
<span class="tooltip-content">{{__ "${capitalizedName}"}}</span>
|
|
204
|
+
<input type="text"
|
|
205
|
+
name="${cv.name}"
|
|
206
|
+
type="${cv.type === "string" ? "text" : cv.type === "number" ? "number" : "text"}"
|
|
207
|
+
value="{{${cv.name}}}"
|
|
208
|
+
placeholder="e.g. ${replaceAll(cv.defaultValue, '"', "")}"
|
|
209
|
+
data-validate="${cv.optional ? "" : "$notEmpty"};">`;
|
|
210
|
+
})
|
|
211
|
+
.join("\r\n")}
|
|
212
|
+
`;
|
|
213
|
+
replace_string_in_file(propertiesFormFile, `<!-- ##_HTML_CONTROLS_## -->`, template);
|
|
214
|
+
} else {
|
|
215
|
+
console.warn("Create a config.json with properties to generate a TAO config");
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
// copy specific files
|
|
219
|
+
if (fs.existsSync(path.join(PACKAGE_ROOT_PATH, "tao_pci"))) {
|
|
220
|
+
copyDirectoryRecursiveSync(path.join(PACKAGE_ROOT_PATH, "tao_pci"), outputDirectoryTemp, false);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
// files that contain values that should be replaced
|
|
224
|
+
const filesToEdit = [
|
|
225
|
+
"imsPciCreator.js",
|
|
226
|
+
"imsPciCreator.json",
|
|
227
|
+
"interaction/creator/widget/Widget.js",
|
|
228
|
+
"interaction/creator/widget/states/states.js",
|
|
229
|
+
"interaction/creator/widget/states/Question.js",
|
|
230
|
+
"interaction/creator/widget/states/Correct.js",
|
|
231
|
+
];
|
|
232
|
+
|
|
233
|
+
// loop through the files and replace values.
|
|
234
|
+
for (const fileToEdit of filesToEdit) {
|
|
235
|
+
for (const propertyName in propertiesToReplace) {
|
|
236
|
+
const pathToFile = path.join(outputDirectoryTemp, fileToEdit);
|
|
237
|
+
replace_string_in_file(pathToFile, `##${propertyName}##`, propertiesToReplace[propertyName]);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
// copy the actual PCI file
|
|
242
|
+
const pciFile = config.main || "/dist/index.js";
|
|
243
|
+
|
|
244
|
+
if (!fs.existsSync(path.join(outputDirectoryTemp, "/interaction/runtime/js"))) {
|
|
245
|
+
mkdirSync(path.join(outputDirectoryTemp, "/interaction/runtime/js"));
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
fs.copyFileSync(
|
|
249
|
+
path.join(PACKAGE_ROOT_PATH, pciFile),
|
|
250
|
+
path.join(outputDirectoryTemp, "/interaction/runtime/js/index.js")
|
|
251
|
+
);
|
|
252
|
+
|
|
253
|
+
// the icon can be replaced by a custom icon
|
|
254
|
+
const iconLocation = path.join(PACKAGE_ROOT_PATH, `${propertiesToReplace.typeIdentifier}.svg`);
|
|
255
|
+
if (fs.existsSync(iconLocation)) {
|
|
256
|
+
fs.copyFileSync(iconLocation, path.join(outputDirectoryTemp, "/interaction/creator/img/icon.svg"));
|
|
257
|
+
} else {
|
|
258
|
+
console.warn(
|
|
259
|
+
`Cannot find svg file at: ${iconLocation} default icon will be used. To have a custom icon for the PCI in TAO add a svg file here: ${iconLocation}`
|
|
260
|
+
);
|
|
261
|
+
}
|
|
262
|
+
// console.log(propertiesToReplace.short)
|
|
263
|
+
|
|
264
|
+
// zip the folder
|
|
265
|
+
const zipName = `tao-pci-${propertiesToReplace.typeIdentifier}_${packageData.version}.zip`;
|
|
266
|
+
zipDirectory(outputDirectoryTemp, path.join(outputDirectory, zipName)).then(() =>
|
|
267
|
+
// fs.rmdirSync(outputDirectoryTemp, { recursive: true });
|
|
268
|
+
console.log(`created tao pci zip: ${zipName}`)
|
|
269
|
+
);
|
|
270
|
+
};
|
|
271
|
+
|
|
272
|
+
function replace_string_in_file(filename, to_replace, replace_with) {
|
|
273
|
+
var data = fs.readFileSync(filename, "utf8");
|
|
274
|
+
|
|
275
|
+
var result = data.replace(new RegExp(to_replace, "g"), replace_with);
|
|
276
|
+
fs.writeFileSync(filename, result, "utf8");
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
function copyDirectoryRecursiveSync(source, target) {
|
|
280
|
+
if (!fs.lstatSync(source).isDirectory() || source.endsWith("tmp")) return;
|
|
281
|
+
// var operation = move ? fs.renameSync : fs.copyFileSync;
|
|
282
|
+
fs.readdirSync(source).forEach(function (itemName) {
|
|
283
|
+
if (!(itemName.indexOf("tao-pci-") !== -1 && itemName.indexOf(".zip") !== -1)) {
|
|
284
|
+
var sourcePath = path.join(source, itemName);
|
|
285
|
+
var targetPath = path.join(target, itemName);
|
|
286
|
+
if (fs.lstatSync(sourcePath).isDirectory()) {
|
|
287
|
+
if (!fs.existsSync(targetPath) && !targetPath.toLocaleLowerCase().endsWith("tmp")) {
|
|
288
|
+
fs.mkdirSync(targetPath);
|
|
289
|
+
}
|
|
290
|
+
copyDirectoryRecursiveSync(sourcePath, targetPath);
|
|
291
|
+
} else {
|
|
292
|
+
if (fs.existsSync(targetPath)) {
|
|
293
|
+
fs.unlinkSync(targetPath);
|
|
294
|
+
}
|
|
295
|
+
fs.copyFileSync(sourcePath, targetPath, 0);
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
function zipDirectory(sourceDir, outPath) {
|
|
302
|
+
const archive = archiver("zip", { zlib: { level: 9 } });
|
|
303
|
+
const stream = fs.createWriteStream(outPath);
|
|
304
|
+
|
|
305
|
+
return new Promise((resolve, reject) => {
|
|
306
|
+
archive
|
|
307
|
+
.directory(sourceDir, false)
|
|
308
|
+
.on("error", (err) => reject(err))
|
|
309
|
+
.pipe(stream);
|
|
310
|
+
|
|
311
|
+
stream.on("close", () => resolve());
|
|
312
|
+
archive.finalize();
|
|
313
|
+
});
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
function replaceAll(str, find, replace) {
|
|
317
|
+
return str.replace(new RegExp(find, "g"), replace);
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
function isBoolean(string) {
|
|
321
|
+
switch (string.toLowerCase().trim()) {
|
|
322
|
+
case "true":
|
|
323
|
+
case "yes":
|
|
324
|
+
case "false":
|
|
325
|
+
case "no":
|
|
326
|
+
return true;
|
|
327
|
+
|
|
328
|
+
default:
|
|
329
|
+
return false;
|
|
330
|
+
}
|
|
331
|
+
}
|