@citolab/tspci-tao 2.5.1-alpha.0 → 2.5.2
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/package.json +2 -2
- package/src/init.mjs +87 -27
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@citolab/tspci-tao",
|
|
3
|
-
"version": "2.5.
|
|
3
|
+
"version": "2.5.2",
|
|
4
4
|
"description": "create a zip file that can be imported into TAO",
|
|
5
5
|
"author": "patrick <patrick.deklein@cito.nl>, Marcel Hoekstra <marcel.hoekstra@cito.nl>",
|
|
6
6
|
"repository": "",
|
|
@@ -12,5 +12,5 @@
|
|
|
12
12
|
"inquirer": "11.0.1"
|
|
13
13
|
},
|
|
14
14
|
"scripts": {},
|
|
15
|
-
"gitHead": "
|
|
15
|
+
"gitHead": "675cb6d40b418bac93a3e970d4d6dc4dc7c17bb5"
|
|
16
16
|
}
|
package/src/init.mjs
CHANGED
|
@@ -42,18 +42,15 @@ export const init = async () => {
|
|
|
42
42
|
}
|
|
43
43
|
// get first 5 chars of identifier
|
|
44
44
|
const defaultShort = typeIdentifer.length > 5 ? typeIdentifer.substring(0, 5) : typeIdentifer;
|
|
45
|
-
const short = (await askOption(
|
|
46
|
-
`Enter a short name for the PCI: (default: ${defaultShort}) `
|
|
47
|
-
)) || defaultShort;
|
|
45
|
+
const short = (await askOption(`Enter a short name for the PCI: (default: ${defaultShort}) `)) || defaultShort;
|
|
48
46
|
|
|
49
47
|
const defaultLabel = typeIdentifer.length > 5 ? typeIdentifer.substring(0, 5) : typeIdentifer;
|
|
50
|
-
const label = (await askOption(
|
|
51
|
-
`Enter the label of the PCI: (default: ${defaultLabel}) `
|
|
52
|
-
)) || defaultLabel;
|
|
48
|
+
const label = (await askOption(`Enter the label of the PCI: (default: ${defaultLabel}) `)) || defaultLabel;
|
|
53
49
|
const scoringsMethods = await selectOptions("Which scoring methods do you want to support?", [
|
|
54
|
-
"MATCH_CORRECT",
|
|
50
|
+
"MATCH_CORRECT",
|
|
51
|
+
"NONE",
|
|
55
52
|
]);
|
|
56
|
-
const scoreMethodArray = scoringsMethods.values
|
|
53
|
+
const scoreMethodArray = scoringsMethods.values;
|
|
57
54
|
|
|
58
55
|
// adding short, label and typeIdentifer to packageData
|
|
59
56
|
packageData.config.tspci.short = short;
|
|
@@ -62,7 +59,7 @@ export const init = async () => {
|
|
|
62
59
|
packageData.config.tspci.score = scoreMethodArray;
|
|
63
60
|
|
|
64
61
|
packageData.devDependencies = packageData.devDependencies || {};
|
|
65
|
-
|
|
62
|
+
|
|
66
63
|
// get package.json from PACKAGER_PATH
|
|
67
64
|
const PACKAGER_PATH = path.join(PACKAGE_ROOT_PATH + "/node_modules/@citolab/tspci-tao");
|
|
68
65
|
const packagerPackageData = JSON.parse(fs.readFileSync(path.join(PACKAGER_PATH, "package.json"), "utf8"));
|
|
@@ -81,9 +78,12 @@ export const init = async () => {
|
|
|
81
78
|
if (!packageData.source) {
|
|
82
79
|
console.error("Failed implementing TAO interface; No source property found in package.json.");
|
|
83
80
|
}
|
|
84
|
-
|
|
81
|
+
|
|
82
|
+
// Determine if the file is TypeScript or JavaScript
|
|
83
|
+
const isTypeScript = packageData.source.endsWith(".ts");
|
|
84
|
+
|
|
85
85
|
const sourceFile = fs.readFileSync(path.join(PACKAGE_ROOT_PATH, packageData.source), "utf8");
|
|
86
|
-
if (sourceFile.indexOf("implements IMSpci<PropTypes>, TAOpci") === -1) {
|
|
86
|
+
if (isTypeScript && sourceFile.indexOf("implements IMSpci<PropTypes>, TAOpci") === -1) {
|
|
87
87
|
console.log("TAO interface not implemented yet; Implementing...");
|
|
88
88
|
if (sourceFile.indexOf("implements IMSpci<PropTypes> {") === -1) {
|
|
89
89
|
console.error("Cannot implement TAOpci interface automatically. Please implement it manually.");
|
|
@@ -98,29 +98,89 @@ export const init = async () => {
|
|
|
98
98
|
newSourceFile = `import { QtiVariableJSON } from "@citolab/tspci";\r\n${newSourceFile}`;
|
|
99
99
|
}
|
|
100
100
|
const defaultImplementation = `
|
|
101
|
-
off = () => {}; // called when setting correct response in tao
|
|
102
|
-
on = (val) => {};
|
|
103
|
-
trigger = (event: string, value: any) => {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
};
|
|
107
|
-
resetResponse = () => {
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
};
|
|
111
|
-
setResponse = (response: QtiVariableJSON) => {
|
|
112
|
-
|
|
113
|
-
};
|
|
114
|
-
|
|
101
|
+
off = () => {}; // called when setting correct response in tao
|
|
102
|
+
on = (val) => {};
|
|
103
|
+
trigger = (event: string, value: any) => {
|
|
104
|
+
this.config.properties[event] = value;
|
|
105
|
+
this.render();
|
|
106
|
+
};
|
|
107
|
+
resetResponse = () => {
|
|
108
|
+
// used in tao to reset the response. clean-up and re-render the PCI would be best.
|
|
109
|
+
// this.render();
|
|
110
|
+
};
|
|
111
|
+
setResponse = (response: QtiVariableJSON) => {
|
|
112
|
+
// used to set the response in tao. E.g. when the item author has set a correct response. And you refresh TAO it will call this method to set the response in the PCI in the score-editor.
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
`;
|
|
115
116
|
const lastBracket = newSourceFile.lastIndexOf("}");
|
|
116
|
-
newSourceFile =
|
|
117
|
+
newSourceFile =
|
|
118
|
+
newSourceFile.substring(0, lastBracket) + defaultImplementation + newSourceFile.substring(lastBracket);
|
|
117
119
|
|
|
118
120
|
fs.writeFileSync(path.join(PACKAGE_ROOT_PATH, packageData.source), newSourceFile, "utf8");
|
|
119
121
|
console.log(chalk.green("TAO interface implemented"));
|
|
120
122
|
}
|
|
123
|
+
} else if (!isTypeScript) {
|
|
124
|
+
// For JavaScript implementation
|
|
125
|
+
let newSourceFile = sourceFile;
|
|
126
|
+
|
|
127
|
+
if (sourceFile.indexOf("@implements {TAOpci}") === -1) {
|
|
128
|
+
// Add @implements {TAOpci} to JSDoc of an existing method, e.g., getInstance
|
|
129
|
+
newSourceFile = newSourceFile.replace("/**", `/**\n * @implements {TAOpci}`);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
const jsImplementation = `
|
|
133
|
+
/**
|
|
134
|
+
* Called when setting correct response in tao
|
|
135
|
+
* @method off
|
|
136
|
+
*/
|
|
137
|
+
off = function() {};
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Called when setting a value in TAO
|
|
141
|
+
* @method on
|
|
142
|
+
* @param {any} val
|
|
143
|
+
*/
|
|
144
|
+
on = function(val) {};
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Triggers an event and updates the configuration
|
|
148
|
+
* @method trigger
|
|
149
|
+
* @param {string} event
|
|
150
|
+
* @param {any} value
|
|
151
|
+
*/
|
|
152
|
+
trigger = function(event, value) {
|
|
153
|
+
this.config.properties[event] = value;
|
|
154
|
+
this.render();
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Resets the response in TAO
|
|
159
|
+
* @method resetResponse
|
|
160
|
+
*/
|
|
161
|
+
resetResponse = function() {
|
|
162
|
+
// used in tao to reset the response. clean-up and re-render the PCI would be best.
|
|
163
|
+
// this.render();
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Sets the response in TAO
|
|
168
|
+
* @method setResponse
|
|
169
|
+
* @param {QtiVariableJSON} response
|
|
170
|
+
*/
|
|
171
|
+
setResponse = function(response) {
|
|
172
|
+
// used to set the response in tao. E.g. when the item author has set a correct response. And you refresh TAO it will call this method to set the response in the PCI in the score-editor.
|
|
173
|
+
};
|
|
174
|
+
`;
|
|
175
|
+
const lastBracket = newSourceFile.lastIndexOf("}");
|
|
176
|
+
newSourceFile = newSourceFile.substring(0, lastBracket) + jsImplementation + newSourceFile.substring(lastBracket);
|
|
177
|
+
|
|
178
|
+
fs.writeFileSync(path.join(PACKAGE_ROOT_PATH, packageData.source), newSourceFile, "utf8");
|
|
179
|
+
|
|
180
|
+
fs.writeFileSync(path.join(PACKAGE_ROOT_PATH, packageData.source), newSourceFile, "utf8");
|
|
181
|
+
console.log(chalk.green("TAO interface implemented for JavaScript"));
|
|
121
182
|
} else {
|
|
122
183
|
console.log("TAO interface already implemented");
|
|
123
184
|
}
|
|
124
185
|
console.log(chalk.green("Done!"));
|
|
125
186
|
};
|
|
126
|
-
|