@citolab/tspci-tao 2.7.1 → 2.8.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/CHANGELOG.md +24 -0
- package/package.json +9 -5
- package/src/createPackage.mjs +24 -12
- package/src/init.mjs +30 -15
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,30 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [2.8.2](https://github.com/Citolab/tspci/compare/v2.8.1...v2.8.2) (2026-02-24)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @citolab/tspci-tao
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
## [2.8.1](https://github.com/Citolab/tspci/compare/v2.8.0...v2.8.1) (2026-02-24)
|
|
15
|
+
|
|
16
|
+
**Note:** Version bump only for package @citolab/tspci-tao
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
# [2.8.0](https://github.com/Citolab/tspci/compare/v2.7.1...v2.8.0) (2026-02-24)
|
|
23
|
+
|
|
24
|
+
**Note:** Version bump only for package @citolab/tspci-tao
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
6
30
|
## [2.7.1](https://github.com/Citolab/tspci/compare/v2.7.0...v2.7.1) (2026-02-09)
|
|
7
31
|
|
|
8
32
|
**Note:** Version bump only for package @citolab/tspci-tao
|
package/package.json
CHANGED
|
@@ -1,16 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@citolab/tspci-tao",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.8.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": "",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"types": "types/index.d.ts",
|
|
9
|
-
"
|
|
10
|
-
"archiver": "^7.0.1",
|
|
9
|
+
"dependencies": {
|
|
11
10
|
"chalk": "5.6.2",
|
|
12
|
-
"inquirer": "13.2.2"
|
|
11
|
+
"inquirer": "13.2.2",
|
|
12
|
+
"yazl": "^3.3.1"
|
|
13
13
|
},
|
|
14
14
|
"scripts": {},
|
|
15
|
-
"
|
|
15
|
+
"publishConfig": {
|
|
16
|
+
"access": "public",
|
|
17
|
+
"registry": "https://registry.npmjs.org/"
|
|
18
|
+
},
|
|
19
|
+
"gitHead": "460f7339e0490caea95fc5e9bedfcd12ebfce41f"
|
|
16
20
|
}
|
package/src/createPackage.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import fs, { mkdirSync } from "fs";
|
|
2
2
|
import path from "path";
|
|
3
|
-
import
|
|
3
|
+
import yazl from "yazl";
|
|
4
4
|
|
|
5
5
|
export const bundle = () => {
|
|
6
6
|
const PACKAGE_ROOT_PATH = process.cwd();
|
|
@@ -16,7 +16,7 @@ export const bundle = () => {
|
|
|
16
16
|
typeIdentifier: "emptytypeIdentifier",
|
|
17
17
|
label: "label",
|
|
18
18
|
short: "short",
|
|
19
|
-
score: ["NONE"],
|
|
19
|
+
score: ["MATCH_CORRECT", "NONE"],
|
|
20
20
|
};
|
|
21
21
|
|
|
22
22
|
const config = path.join(PACKAGE_ROOT_PATH, "package.json");
|
|
@@ -160,7 +160,7 @@ export const bundle = () => {
|
|
|
160
160
|
"###_FIRST_SCORING_METHOD_###",
|
|
161
161
|
propertiesToReplace.score?.length > 0
|
|
162
162
|
? propertiesToReplace.score[0]
|
|
163
|
-
: "
|
|
163
|
+
: "MATCH_CORRECT"
|
|
164
164
|
);
|
|
165
165
|
replace_string_in_file(
|
|
166
166
|
creatorFile,
|
|
@@ -374,20 +374,32 @@ function copyDirectoryRecursiveSync(source, target) {
|
|
|
374
374
|
}
|
|
375
375
|
|
|
376
376
|
function zipDirectory(sourceDir, outPath) {
|
|
377
|
-
const
|
|
378
|
-
|
|
379
|
-
|
|
377
|
+
const zipFile = new yazl.ZipFile();
|
|
378
|
+
addDirectoryToZip(zipFile, sourceDir, sourceDir);
|
|
380
379
|
return new Promise((resolve, reject) => {
|
|
381
|
-
|
|
382
|
-
.directory(sourceDir, false)
|
|
383
|
-
.on("error", (err) => reject(err))
|
|
384
|
-
.pipe(stream);
|
|
385
|
-
|
|
380
|
+
const stream = fs.createWriteStream(outPath);
|
|
386
381
|
stream.on("close", () => resolve());
|
|
387
|
-
|
|
382
|
+
stream.on("error", (err) => reject(err));
|
|
383
|
+
zipFile.outputStream.on("error", (err) => reject(err)).pipe(stream);
|
|
384
|
+
zipFile.end();
|
|
388
385
|
});
|
|
389
386
|
}
|
|
390
387
|
|
|
388
|
+
function addDirectoryToZip(zipFile, rootDir, currentDir) {
|
|
389
|
+
for (const entry of fs.readdirSync(currentDir, { withFileTypes: true })) {
|
|
390
|
+
const fullPath = path.join(currentDir, entry.name);
|
|
391
|
+
if (entry.isDirectory()) {
|
|
392
|
+
addDirectoryToZip(zipFile, rootDir, fullPath);
|
|
393
|
+
continue;
|
|
394
|
+
}
|
|
395
|
+
if (!entry.isFile()) {
|
|
396
|
+
continue;
|
|
397
|
+
}
|
|
398
|
+
const relativePath = path.relative(rootDir, fullPath).split(path.sep).join("/");
|
|
399
|
+
zipFile.addFile(fullPath, relativePath, { compress: true });
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
|
|
391
403
|
function replaceAll(str, find, replace) {
|
|
392
404
|
return str.replace(new RegExp(find, "g"), replace);
|
|
393
405
|
}
|
package/src/init.mjs
CHANGED
|
@@ -31,6 +31,8 @@ function selectOptions(prompt, options) {
|
|
|
31
31
|
|
|
32
32
|
export const init = async () => {
|
|
33
33
|
console.log("adding TAO support to PCI");
|
|
34
|
+
const args = process.argv.slice(2);
|
|
35
|
+
const ciMode = args.includes("--ci");
|
|
34
36
|
const PACKAGE_ROOT_PATH = process.cwd();
|
|
35
37
|
const packageData = JSON.parse(fs.readFileSync(path.join(PACKAGE_ROOT_PATH, "package.json"), "utf8"));
|
|
36
38
|
const typeIdentifer = packageData.config?.tspci?.typeIdentifier;
|
|
@@ -42,15 +44,17 @@ export const init = async () => {
|
|
|
42
44
|
}
|
|
43
45
|
// get first 5 chars of identifier
|
|
44
46
|
const defaultShort = typeIdentifer.length > 5 ? typeIdentifer.substring(0, 5) : typeIdentifer;
|
|
45
|
-
const short =
|
|
47
|
+
const short = ciMode
|
|
48
|
+
? defaultShort
|
|
49
|
+
: (await askOption(`Enter a short name for the PCI: (default: ${defaultShort}) `)) || defaultShort;
|
|
46
50
|
|
|
47
51
|
const defaultLabel = typeIdentifer.length > 5 ? typeIdentifer.substring(0, 5) : typeIdentifer;
|
|
48
|
-
const label =
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
52
|
+
const label = ciMode
|
|
53
|
+
? defaultLabel
|
|
54
|
+
: (await askOption(`Enter the label of the PCI: (default: ${defaultLabel}) `)) || defaultLabel;
|
|
55
|
+
const scoreMethodArray = ciMode
|
|
56
|
+
? ["MATCH_CORRECT", "NONE"]
|
|
57
|
+
: (await selectOptions("Which scoring methods do you want to support?", ["MATCH_CORRECT", "NONE"])).values;
|
|
54
58
|
|
|
55
59
|
// adding short, label and typeIdentifer to packageData
|
|
56
60
|
packageData.config.tspci.short = short;
|
|
@@ -63,9 +67,13 @@ export const init = async () => {
|
|
|
63
67
|
// get package.json from PACKAGER_PATH
|
|
64
68
|
const PACKAGER_PATH = path.join(PACKAGE_ROOT_PATH + "/node_modules/@citolab/tspci-tao");
|
|
65
69
|
const packagerPackageData = JSON.parse(fs.readFileSync(path.join(PACKAGER_PATH, "package.json"), "utf8"));
|
|
66
|
-
// add
|
|
67
|
-
|
|
68
|
-
|
|
70
|
+
// add required runtime dependencies from the packager package to the generated project
|
|
71
|
+
const packagerDeps = {
|
|
72
|
+
...(packagerPackageData.dependencies || {}),
|
|
73
|
+
...(packagerPackageData.devDependencies || {}),
|
|
74
|
+
};
|
|
75
|
+
Object.keys(packagerDeps).forEach((key) => {
|
|
76
|
+
packageData.devDependencies[key] = packagerDeps[key];
|
|
69
77
|
});
|
|
70
78
|
|
|
71
79
|
packageData.scripts = packageData.scripts || {};
|
|
@@ -106,9 +114,12 @@ export const init = async () => {
|
|
|
106
114
|
// this.render();
|
|
107
115
|
};
|
|
108
116
|
`;
|
|
109
|
-
const
|
|
110
|
-
newSourceFile
|
|
111
|
-
|
|
117
|
+
const classEndMarker = "\n}\n\nconst factory";
|
|
118
|
+
if (newSourceFile.indexOf(classEndMarker) === -1) {
|
|
119
|
+
console.error("Cannot inject TAO methods automatically. Please implement TAOpci methods manually.");
|
|
120
|
+
} else {
|
|
121
|
+
newSourceFile = newSourceFile.replace(classEndMarker, `\n${defaultImplementation}\n}\n\nconst factory`);
|
|
122
|
+
}
|
|
112
123
|
|
|
113
124
|
fs.writeFileSync(path.join(PACKAGE_ROOT_PATH, packageData.source), newSourceFile, "utf8");
|
|
114
125
|
console.log(chalk.green("TAO interface implemented"));
|
|
@@ -165,8 +176,12 @@ export const init = async () => {
|
|
|
165
176
|
// 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.
|
|
166
177
|
};
|
|
167
178
|
`;
|
|
168
|
-
const
|
|
169
|
-
|
|
179
|
+
const classEndMarker = "\n}\n\nconst factory";
|
|
180
|
+
if (newSourceFile.indexOf(classEndMarker) === -1) {
|
|
181
|
+
console.error("Cannot inject TAO methods automatically for JavaScript. Please implement manually.");
|
|
182
|
+
} else {
|
|
183
|
+
newSourceFile = newSourceFile.replace(classEndMarker, `\n${jsImplementation}\n}\n\nconst factory`);
|
|
184
|
+
}
|
|
170
185
|
|
|
171
186
|
fs.writeFileSync(path.join(PACKAGE_ROOT_PATH, packageData.source), newSourceFile, "utf8");
|
|
172
187
|
|