@citolab/tspci-qbci 2.5.4 → 2.5.15

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 ADDED
@@ -0,0 +1,88 @@
1
+ # Change Log
2
+
3
+ All notable changes to this project will be documented in this file.
4
+ See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
+
6
+ ## 2.5.15 (2024-10-11)
7
+
8
+ **Note:** Version bump only for package @citolab/tspci-qbci
9
+
10
+
11
+
12
+
13
+
14
+ ## 2.5.14 (2024-10-11)
15
+
16
+ **Note:** Version bump only for package @citolab/tspci-qbci
17
+
18
+
19
+
20
+
21
+
22
+ ## 2.5.13 (2024-10-11)
23
+
24
+ **Note:** Version bump only for package @citolab/tspci-qbci
25
+
26
+
27
+
28
+
29
+
30
+ ## 2.5.12 (2024-10-11)
31
+
32
+ **Note:** Version bump only for package @citolab/tspci-qbci
33
+
34
+
35
+
36
+
37
+
38
+ ## 2.5.11 (2024-10-11)
39
+
40
+ **Note:** Version bump only for package @citolab/tspci-qbci
41
+
42
+
43
+
44
+
45
+
46
+ ## 2.5.10 (2024-10-11)
47
+
48
+ **Note:** Version bump only for package @citolab/tspci-qbci
49
+
50
+
51
+
52
+
53
+
54
+ ## 2.5.9 (2024-10-11)
55
+
56
+ **Note:** Version bump only for package @citolab/tspci-qbci
57
+
58
+
59
+
60
+
61
+
62
+ ## 2.5.8 (2024-10-10)
63
+
64
+ **Note:** Version bump only for package @citolab/tspci-qbci
65
+
66
+
67
+
68
+
69
+
70
+ ## 2.5.7 (2024-10-10)
71
+
72
+ **Note:** Version bump only for package @citolab/tspci-qbci
73
+
74
+
75
+
76
+
77
+
78
+ ## [2.5.6](https://github.com/Citolab/tspci/compare/v2.5.5...v2.5.6) (2024-10-10)
79
+
80
+ **Note:** Version bump only for package @citolab/tspci-qbci
81
+
82
+
83
+
84
+
85
+
86
+ ## [2.5.5](https://github.com/Citolab/tspci/compare/v2.5.4...v2.5.5) (2024-10-10)
87
+
88
+ **Note:** Version bump only for package @citolab/tspci-qbci
package/package.json CHANGED
@@ -1,16 +1,17 @@
1
1
  {
2
2
  "name": "@citolab/tspci-qbci",
3
- "version": "2.5.4",
3
+ "version": "2.5.15",
4
4
  "description": "create a .ci file that can be imported into Questify",
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
9
  "dependencies": {
10
- "archiver": "^7.0.1"
10
+ "archiver": "^7.0.1",
11
+ "chalk": "5.3.0"
11
12
  },
12
13
  "scripts": {},
13
- "gitHead": "3f69ce948e8d2e02131235a9488645aaa95e0413",
14
+ "gitHead": "1970a9a73da54053545f3b9a470dcad44c8abd21",
14
15
  "publishConfig": {
15
16
  "access": "public"
16
17
  }
package/release-notes.md CHANGED
@@ -1,3 +1,13 @@
1
+
2
+ # 2.1.1
3
+ tspci
4
+ - support for your own export plugin not in the npm package by using full name of npm path
5
+
6
+ tspci-qbci
7
+ - all media files from the assets folder in your root will be copied to .ref/media
8
+ - all found media files will be added in an array .ref/json/manifes.json as media property
9
+ - added chalk for some nice warning colors in cli mesages
10
+
1
11
  # 2.0.0
2
12
 
3
13
  - first release questify builder ci plugin
@@ -1,6 +1,8 @@
1
+ "use strict";
1
2
  import fs, { mkdirSync } from "fs";
2
3
  import path from "path";
3
4
  import archiver from "archiver";
5
+ import chalk from "chalk";
4
6
 
5
7
  export const bundle = () => {
6
8
  const PACKAGE_ROOT_PATH = process.cwd();
@@ -40,7 +42,7 @@ export const bundle = () => {
40
42
  const questifyMetadataData = JSON.parse(rawMetadata);
41
43
 
42
44
  const propertiesToReplace = {
43
- typeIdentifier: "emptytypeIdentifier"
45
+ typeIdentifier: "emptytypeIdentifier",
44
46
  };
45
47
  copyDirectoryRecursiveSync(path.join(PACKAGER_PATH, "questify-default"), outputDirectoryTemp, false);
46
48
 
@@ -54,13 +56,13 @@ export const bundle = () => {
54
56
  if (propertyName === "typeIdentifier") {
55
57
  if (!packageData.config?.tspci[propertyName]) {
56
58
  console.error(
57
- "'typeIdentifier' should be added as an option in package.json and should match the typeIdentifier of the PCI code file."
59
+ "'typeIdentifier' should be added as an option in package.json and should match the typeIdentifier of the PCI code file.",
58
60
  );
59
61
  return;
60
62
  } else {
61
63
  if (!packageData.config?.tspci[propertyName])
62
64
  console.info(
63
- `${propertyName} not specified in ${packageData.name} in package.json using { config: tspci: {${propertiesToReplace[propertyName]}}`
65
+ `${propertyName} not specified in ${packageData.name} in package.json using { config: tspci: {${propertiesToReplace[propertyName]}}`,
64
66
  );
65
67
  }
66
68
  }
@@ -84,23 +86,82 @@ export const bundle = () => {
84
86
  if (!fs.existsSync(scriptPath)) {
85
87
  fs.mkdirSync(scriptPath);
86
88
  }
87
- fs.copyFileSync(path.join(PACKAGE_ROOT_PATH, pciFile), path.join(scriptPath, "/index.min.js"));
89
+ const minifiedFilePath = path.join(scriptPath, "/index.min.js");
90
+ const maxJsFileSize = 499; // the facet player has a limit of 500kb for js files
91
+ fs.copyFileSync(path.join(PACKAGE_ROOT_PATH, pciFile), minifiedFilePath);
92
+
93
+ // make changes to the if files found in ./assets in the root of the project
94
+ // add media files to manifest.json and copy them to the output directory
95
+ // replace 'assets/' with 'ref/media/' in the minified js file
96
+ const assetsFolderPath = path.join(PACKAGE_ROOT_PATH, "assets");
97
+ const media = getMediaPathFilesArray(assetsFolderPath);
98
+ if (media.length > 0) {
99
+ const manifestRaw = fs.readFileSync(path.join(outputDirectoryTemp, "ref/json/manifest.json"), "utf8");
100
+ let manifestData = JSON.parse(manifestRaw);
101
+ manifestData = { ...manifestData, media };
102
+
103
+ // check if ref/media folder exists, if not create it
104
+ const mediaPath = path.join(outputDirectoryTemp, "ref/media");
105
+ if (!fs.existsSync(mediaPath)) {
106
+ fs.mkdirSync(mediaPath);
107
+ }
108
+
109
+ fs.writeFileSync(path.join(outputDirectoryTemp, "ref/json/manifest.json"), JSON.stringify(manifestData), "utf8");
110
+ copyDirectoryRecursiveSync(assetsFolderPath, path.join(outputDirectoryTemp, "ref/media"));
111
+ }
112
+
113
+ isMaxFileSize(maxJsFileSize, minifiedFilePath);
88
114
 
89
115
  // zip the folder
90
116
  const zipName = `${name}_${packageData.version}.ci`;
91
117
  zipDirectory(outputDirectoryTemp, path.join(outputDirectory, zipName)).then(() =>
92
118
  // fs.rmdirSync(outputDirectoryTemp, { recursive: true });
93
- console.log(`created questify ci zip: ${zipName}`)
119
+ console.log(`created questify ci zip: ${zipName}`),
94
120
  );
95
121
  };
96
122
 
123
+ function getMediaPathFilesArray(assetsFolderPath) {
124
+ if (!fs.existsSync(assetsFolderPath)) {
125
+ console.log(chalk.orange(`Assets folder not found: ${assetsFolderPath}`));
126
+ return [];
127
+ }
128
+
129
+ const mediaFiles = [];
130
+ const files = fs.readdirSync(assetsFolderPath);
131
+
132
+ files.forEach((file) => {
133
+ // check if file is an image, if not skip
134
+ if (!file.match(/\.(png|jpe?g|gif|svg)$/)) {
135
+ return;
136
+ }
137
+
138
+ const filePath = `ref/media/${file}`;
139
+ mediaFiles.push(filePath);
140
+ });
141
+
142
+ return mediaFiles;
143
+ }
144
+
145
+ function isMaxFileSize(maxFileSize, filePath) {
146
+ const fileSizeInBytes = fs.statSync(filePath).size;
147
+ const fileSizeInKilobytes = (fileSizeInBytes / 1024).toFixed(2);
148
+ if (parseFloat(fileSizeInKilobytes) > maxFileSize) {
149
+ // js file to big
150
+ console.log(chalk.red(`❗️Warning, minified file size of ${maxFileSize}kb exceeded: ${fileSizeInKilobytes} KB.❗️`));
151
+ console.log(chalk.red(`This will result in a packagestream error in the player.`));
152
+ } else {
153
+ // js file is ok
154
+ console.log(`✅ minified js file size: ${fileSizeInKilobytes} KB (max: ${maxFileSize} KB)`);
155
+ }
156
+ }
157
+
97
158
  function copyDirectoryRecursiveSync(source, target) {
98
159
  if (!fs.lstatSync(source).isDirectory() || source.endsWith("tmp")) return;
99
160
  // var operation = move ? fs.renameSync : fs.copyFileSync;
100
161
  fs.readdirSync(source).forEach(function (itemName) {
101
162
  if (!(itemName.indexOf("questify-pci-") !== -1 && itemName.indexOf(".zip") !== -1)) {
102
- var sourcePath = path.join(source, itemName);
103
- var targetPath = path.join(target, itemName);
163
+ const sourcePath = path.join(source, itemName);
164
+ const targetPath = path.join(target, itemName);
104
165
  if (fs.lstatSync(sourcePath).isDirectory()) {
105
166
  if (!fs.existsSync(targetPath) && !targetPath.toLocaleLowerCase().endsWith("tmp")) {
106
167
  fs.mkdirSync(targetPath);