@citolab/tspci 2.5.4 β 2.5.5
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 +8 -0
- package/package.json +2 -2
- package/readme.md +40 -31
- package/src/cli.js +16 -29
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
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.5](/compare/v2.5.4...v2.5.5) (2024-10-10)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @citolab/tspci
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@citolab/tspci",
|
|
3
|
-
"version": "2.5.
|
|
3
|
+
"version": "2.5.5",
|
|
4
4
|
"description": "an opiniated typescript ims-pci builder with tao integration",
|
|
5
5
|
"author": "patrick <patrick.deklein@cito.nl>",
|
|
6
6
|
"repository": "@citolab/tspci",
|
|
@@ -46,5 +46,5 @@
|
|
|
46
46
|
"rollup-plugin-watch-assets": "^1.0.1",
|
|
47
47
|
"tailwindcss": "^3.4.11"
|
|
48
48
|
},
|
|
49
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "107b2fde32e7e09f6ac2cac98a6018bce51539c0"
|
|
50
50
|
}
|
package/readme.md
CHANGED
|
@@ -32,26 +32,29 @@ This will ask a few options, and creates a PCI development environment with an e
|
|
|
32
32
|
<img src="https://github.com/Citolab/tspci/blob/main/lib/tspci/tspci-console.png" alt="Setup using console">
|
|
33
33
|
</p>
|
|
34
34
|
|
|
35
|
-
Run:
|
|
35
|
+
Run: `npx @citolab/tspci@latest init`
|
|
36
36
|
|
|
37
37
|
1. It will ask to download the latest version of tspci.
|
|
38
|
-
2. If agreed; tspci will be downloaded and started.
|
|
38
|
+
2. If agreed; tspci will be downloaded and started.
|
|
39
39
|
3. You should provide a name/identifier for your PCI.
|
|
40
40
|
4. You should provide a description.
|
|
41
41
|
5. Last option is to choose how you want to build your pci, using tailwind and preact, typescript or javascript
|
|
42
42
|
|
|
43
43
|
#### Tailwind
|
|
44
|
+
|
|
44
45
|
Tailwind is a popular css framework and can be used to give a nice look and feel of the PCI. The cli will make sure the css is added; and all build stuff that comes with tailwind is setup.
|
|
45
46
|
|
|
46
47
|
#### preact
|
|
48
|
+
|
|
47
49
|
preact is a small version of react. You can develop your PCI using hooks and the render function as you are familiar with in react. When preact is selected the cli will also add a store to manage state. This can easily be used to store all user actions in the PCI, and even replay them.
|
|
48
50
|
|
|
49
51
|
### specific implementations like TAO.
|
|
52
|
+
|
|
50
53
|
We also support to create a PCI that can be imported in TAO. Therefor you should use @citolab/tspci-tao.
|
|
51
54
|
|
|
52
55
|
To add tao using the cli you should run the following command inside your PCI folder:
|
|
53
56
|
|
|
54
|
-
```
|
|
57
|
+
```sh
|
|
55
58
|
npm run tspci -- add --target tao
|
|
56
59
|
```
|
|
57
60
|
|
|
@@ -64,6 +67,7 @@ For more info: [@citolab/tspci-tao](https://github.com/Citolab/tspci/tree/main/l
|
|
|
64
67
|
2οΈ. **Set up** your `package.json`:
|
|
65
68
|
|
|
66
69
|
`// package.json`
|
|
70
|
+
|
|
67
71
|
```json
|
|
68
72
|
{
|
|
69
73
|
"name": "@citolab/hello-world",
|
|
@@ -151,9 +155,9 @@ Add a `tsconfig.json` to your project for type checking
|
|
|
151
155
|
"jsxImportSource": "preact",
|
|
152
156
|
"allowSyntheticDefaultImports": true,
|
|
153
157
|
"resolveJsonModule": true,
|
|
154
|
-
"esModuleInterop": true
|
|
158
|
+
"esModuleInterop": true
|
|
155
159
|
},
|
|
156
|
-
"include": ["**/*"]
|
|
160
|
+
"include": ["**/*"]
|
|
157
161
|
}
|
|
158
162
|
```
|
|
159
163
|
|
|
@@ -169,9 +173,9 @@ Available Commands
|
|
|
169
173
|
--dev -d Start development server
|
|
170
174
|
--watch -w Only watch changes
|
|
171
175
|
--help -h Help about commandos
|
|
172
|
-
--target -t Build production for platform
|
|
176
|
+
--target -t Build production for platform, could be @citolab/tscpi-${target} or a fully qualified specified npm package name.
|
|
173
177
|
init Init PCI development environment.
|
|
174
|
-
add --target Add specific implementation to the PCI.
|
|
178
|
+
add --target Add specific implementation to the PCI.
|
|
175
179
|
|
|
176
180
|
Examples package.json scripts
|
|
177
181
|
$ "dev": "tspci --dev",
|
|
@@ -182,11 +186,12 @@ Examples package.json scripts
|
|
|
182
186
|
|
|
183
187
|
## π£ What's next
|
|
184
188
|
|
|
185
|
-
Use one of the [examples](https://github.com/Citolab/tspci-examples) to get a headstart
|
|
189
|
+
Use one of the [examples](https://github.com/Citolab/tspci-examples) to get a headstart
|
|
186
190
|
|
|
187
|
-
Or read further how we build our PCIs
|
|
191
|
+
Or read further how we build our PCIs
|
|
188
192
|
|
|
189
193
|
Our prefered layout of our PCIs
|
|
194
|
+
|
|
190
195
|
```
|
|
191
196
|
your-pci-project
|
|
192
197
|
β package.json // Definition of your PCI in a standard package.json, TAO adds some props
|
|
@@ -195,7 +200,7 @@ your-pci-project
|
|
|
195
200
|
β
|
|
196
201
|
ββββsrc
|
|
197
202
|
β β config.json // Used to configure PCI, and in TAO for authors
|
|
198
|
-
β β index.ts // The api for the player and bootstraps your interaction
|
|
203
|
+
β β index.ts // The api for the player and bootstraps your interaction
|
|
199
204
|
β β interaction.ts // the actual interaction, preferably a main preact component
|
|
200
205
|
β β store.ts // definition of the state and all possible state mutations of your pci
|
|
201
206
|
β ββββstyle.css // css styles, imported by your pci and possible to use tailwind classes
|
|
@@ -204,8 +209,8 @@ your-pci-project
|
|
|
204
209
|
β tailwind.config.js // include tailwind classes
|
|
205
210
|
```
|
|
206
211
|
|
|
207
|
-
|
|
208
212
|
### Use JSX
|
|
213
|
+
|
|
209
214
|
Use (p)react in your PCI's to create interactions and bind your data to HTML
|
|
210
215
|
|
|
211
216
|
```ts
|
|
@@ -220,6 +225,7 @@ Use (p)react in your PCI's to create interactions and bind your data to HTML
|
|
|
220
225
|
```
|
|
221
226
|
|
|
222
227
|
### Bundle your css
|
|
228
|
+
|
|
223
229
|
Import and bundle css
|
|
224
230
|
Appending css to shadowdom will prevent styles leaking into your player
|
|
225
231
|
|
|
@@ -239,20 +245,18 @@ Appending css to shadowdom will prevent styles leaking into your player
|
|
|
239
245
|
|
|
240
246
|
install autoprefixer
|
|
241
247
|
|
|
242
|
-
```
|
|
248
|
+
```sh
|
|
243
249
|
npm i -D autoprefixer
|
|
244
250
|
```
|
|
245
251
|
|
|
246
252
|
add `postcss.config.js` with autoprefixer
|
|
247
253
|
|
|
248
254
|
// postcss.config.js
|
|
255
|
+
|
|
249
256
|
```js
|
|
250
257
|
module.exports = {
|
|
251
|
-
plugins: [
|
|
252
|
-
|
|
253
|
-
require('autoprefixer'),
|
|
254
|
-
]
|
|
255
|
-
}
|
|
258
|
+
plugins: [require("postcss-import"), require("autoprefixer")],
|
|
259
|
+
};
|
|
256
260
|
```
|
|
257
261
|
|
|
258
262
|
### Modern UI with existing classes
|
|
@@ -262,10 +266,7 @@ and add a `tailwind.config.js`
|
|
|
262
266
|
|
|
263
267
|
```js
|
|
264
268
|
// postcss.config.js
|
|
265
|
-
|
|
266
|
-
+ require('tailwindcss/nesting'),
|
|
267
|
-
+ require('tailwindcss'),
|
|
268
|
-
];
|
|
269
|
+
plugins: [+require("tailwindcss/nesting"), +require("tailwindcss")];
|
|
269
270
|
```
|
|
270
271
|
|
|
271
272
|
```js
|
|
@@ -280,7 +281,8 @@ module.exports = {
|
|
|
280
281
|
```
|
|
281
282
|
|
|
282
283
|
### Bundle all your images
|
|
283
|
-
|
|
284
|
+
|
|
285
|
+
Images are bundled in the js by importing them in code:
|
|
284
286
|
imports JPG, PNG, GIF, SVG, and WebP files
|
|
285
287
|
|
|
286
288
|
```ts
|
|
@@ -289,6 +291,7 @@ import procenten from "./assets/procenten.png";
|
|
|
289
291
|
```
|
|
290
292
|
|
|
291
293
|
### Create advanced PCIs with 3D libraries
|
|
294
|
+
|
|
292
295
|
For example, import threejs to create 3D pci's
|
|
293
296
|
|
|
294
297
|
```ts
|
|
@@ -300,6 +303,7 @@ class VoxelPainterClass {
|
|
|
300
303
|
```
|
|
301
304
|
|
|
302
305
|
### Record user interaction
|
|
306
|
+
|
|
303
307
|
A store will centralize your PCI state but also all mutations.
|
|
304
308
|
This means, this way you could replay everything a user did
|
|
305
309
|
And you can use Redux devtools to debug
|
|
@@ -312,17 +316,20 @@ dispatch<{ x: number }>("ADD_ACTION", { x: +inputValue });
|
|
|
312
316
|
```
|
|
313
317
|
|
|
314
318
|
### Let authors configure your PCI in QTI
|
|
319
|
+
|
|
315
320
|
Use properties in config.json to let authors configure your PCI
|
|
316
321
|
Also used in the TAO export for configuring PCIs in TAO
|
|
317
322
|
`// src/config.json`
|
|
323
|
+
|
|
318
324
|
```json
|
|
319
325
|
{
|
|
320
326
|
"buttonText": "Calculate",
|
|
321
|
-
"sum1"
|
|
322
|
-
"sum2"
|
|
323
|
-
"tableSize"
|
|
327
|
+
"sum1": "$1 * 14 + 1",
|
|
328
|
+
"sum2": "$1 * 2 + 21",
|
|
329
|
+
"tableSize": "4"
|
|
324
330
|
}
|
|
325
331
|
```
|
|
332
|
+
|
|
326
333
|
```ts
|
|
327
334
|
// src/index.ts
|
|
328
335
|
+ import configProps from "./config.json";
|
|
@@ -341,6 +348,7 @@ Also used in the TAO export for configuring PCIs in TAO
|
|
|
341
348
|
```
|
|
342
349
|
|
|
343
350
|
### Make use of existing react hooks
|
|
351
|
+
|
|
344
352
|
```ts
|
|
345
353
|
// src/useMousePosition
|
|
346
354
|
import { useEffect, useState } from "react";
|
|
@@ -354,20 +362,21 @@ export const useMousePosition = () => {
|
|
|
354
362
|
return () => window.removeEventListener("mousemove", setPosFromEvent);
|
|
355
363
|
}, []);
|
|
356
364
|
|
|
357
|
-
return { clientX: position.x, clientY: position.y }
|
|
365
|
+
return { clientX: position.x, clientY: position.y };
|
|
358
366
|
};
|
|
359
367
|
```
|
|
360
368
|
|
|
361
369
|
### Use in TAO
|
|
362
|
-
Tao adds some lifecycle methods which you can implement and we supply an extended interfaee on top of the IMS one.
|
|
363
370
|
|
|
364
|
-
|
|
371
|
+
Tao adds some lifecycle methods which you can implement and we supply an extended interfaee on top of the IMS one.
|
|
372
|
+
|
|
373
|
+
More info, see our extension
|
|
374
|
+
|
|
365
375
|
- [github](https://github.com/Citolab/tspci/blob/main/lib/tspci-tao)
|
|
366
376
|
- [@citolab/tspci-tao](https://www.npmjs.com/package/@citolab/tspci-tao)
|
|
367
377
|
|
|
368
|
-
If you want your platform to be support,
|
|
369
|
-
|
|
378
|
+
If you want your platform to be support, [contact us](mailto://getinspiredbycitolab@gmail.com)
|
|
370
379
|
|
|
371
380
|
## License
|
|
372
381
|
|
|
373
|
-
|
|
382
|
+
[GPLv3](https://github.com/Citolab/tspci/blob/main/LICENSE)
|
package/src/cli.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { loadConfigFile } from "rollup/dist/loadConfigFile.js";
|
|
3
|
-
import { execSync
|
|
3
|
+
import { execSync } from "child_process";
|
|
4
4
|
import { rollup, watch } from "rollup";
|
|
5
5
|
import readline from "readline";
|
|
6
6
|
import chalk from "chalk";
|
|
@@ -31,7 +31,9 @@ const watchBuild = (devServer = false, target = "IMS") => {
|
|
|
31
31
|
process.env.ROLLUP_WATCH = "true";
|
|
32
32
|
|
|
33
33
|
fs.rmSync(PACKAGE_DIST_PATH, { recursive: true, force: true });
|
|
34
|
-
!fs.existsSync(PACKAGE_DIST_PATH)
|
|
34
|
+
if (!fs.existsSync(PACKAGE_DIST_PATH)) {
|
|
35
|
+
fs.mkdirSync(PACKAGE_DIST_PATH);
|
|
36
|
+
}
|
|
35
37
|
|
|
36
38
|
if (devServer) {
|
|
37
39
|
try {
|
|
@@ -65,8 +67,12 @@ const watchBuild = (devServer = false, target = "IMS") => {
|
|
|
65
67
|
warnings.flush();
|
|
66
68
|
const watcher = watch(options);
|
|
67
69
|
watcher.on("event", (event) => {
|
|
68
|
-
event.code == "START"
|
|
69
|
-
|
|
70
|
+
if (event.code == "START") {
|
|
71
|
+
console.log("starting build");
|
|
72
|
+
}
|
|
73
|
+
if (event.code == "ERROR") {
|
|
74
|
+
console.log("ERROR", event);
|
|
75
|
+
}
|
|
70
76
|
});
|
|
71
77
|
watcher.on("event", ({ result }) => {
|
|
72
78
|
if (result) {
|
|
@@ -105,30 +111,6 @@ const prodBuild = async () => {
|
|
|
105
111
|
});
|
|
106
112
|
};
|
|
107
113
|
|
|
108
|
-
function promptYesNo(prompt) {
|
|
109
|
-
const rl = readline.createInterface({
|
|
110
|
-
input: process.stdin,
|
|
111
|
-
output: process.stdout,
|
|
112
|
-
});
|
|
113
|
-
return new Promise((resolve) => {
|
|
114
|
-
rl.question(`${prompt} (y/n): `, (answer) => {
|
|
115
|
-
const normalizedAnswer = answer.trim().toLowerCase();
|
|
116
|
-
if (normalizedAnswer === "y" || normalizedAnswer === "yes") {
|
|
117
|
-
console.log(chalk.green("Yes"));
|
|
118
|
-
resolve(true);
|
|
119
|
-
} else if (normalizedAnswer === "n" || normalizedAnswer === "no") {
|
|
120
|
-
console.log(chalk.red("No"));
|
|
121
|
-
resolve(false);
|
|
122
|
-
} else {
|
|
123
|
-
console.log("Invalid input. Please enter 'y' or 'n'.");
|
|
124
|
-
resolve(promptYesNo(prompt));
|
|
125
|
-
}
|
|
126
|
-
});
|
|
127
|
-
}).finally(() => {
|
|
128
|
-
rl.close();
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
|
-
|
|
132
114
|
function selectOptions(prompt, options) {
|
|
133
115
|
return inquirer.prompt([
|
|
134
116
|
{
|
|
@@ -396,10 +378,13 @@ const run = async () => {
|
|
|
396
378
|
const packageJson = JSON.parse(packageFileContent);
|
|
397
379
|
|
|
398
380
|
const modifyPci = () => {
|
|
399
|
-
|
|
381
|
+
let scriptFile = path.join(
|
|
400
382
|
path.join(path.join(path.join(NODE_MODULES, `@citolab`), `tspci-${targetname}`), "src"),
|
|
401
383
|
`init.mjs`
|
|
402
384
|
);
|
|
385
|
+
if (!fs.existsSync(scriptFile)) {
|
|
386
|
+
scriptFile = path.join(path.join(path.join(NODE_MODULES, targetname), "src"), `init.mjs`);
|
|
387
|
+
}
|
|
403
388
|
let init = false;
|
|
404
389
|
if (fs.existsSync(scriptFile)) {
|
|
405
390
|
// run init() script
|
|
@@ -414,6 +399,8 @@ const run = async () => {
|
|
|
414
399
|
}
|
|
415
400
|
}
|
|
416
401
|
});
|
|
402
|
+
} else {
|
|
403
|
+
console.log(chalk.red(`No init script found. Searched for ${scriptFile}`));
|
|
417
404
|
}
|
|
418
405
|
};
|
|
419
406
|
|