@citolab/tspci 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
9
+
10
+
11
+
12
+
13
+
14
+ ## 2.5.14 (2024-10-11)
15
+
16
+ **Note:** Version bump only for package @citolab/tspci
17
+
18
+
19
+
20
+
21
+
22
+ ## 2.5.13 (2024-10-11)
23
+
24
+ **Note:** Version bump only for package @citolab/tspci
25
+
26
+
27
+
28
+
29
+
30
+ ## 2.5.12 (2024-10-11)
31
+
32
+ **Note:** Version bump only for package @citolab/tspci
33
+
34
+
35
+
36
+
37
+
38
+ ## 2.5.11 (2024-10-11)
39
+
40
+ **Note:** Version bump only for package @citolab/tspci
41
+
42
+
43
+
44
+
45
+
46
+ ## 2.5.10 (2024-10-11)
47
+
48
+ **Note:** Version bump only for package @citolab/tspci
49
+
50
+
51
+
52
+
53
+
54
+ ## 2.5.9 (2024-10-11)
55
+
56
+ **Note:** Version bump only for package @citolab/tspci
57
+
58
+
59
+
60
+
61
+
62
+ ## 2.5.8 (2024-10-10)
63
+
64
+ **Note:** Version bump only for package @citolab/tspci
65
+
66
+
67
+
68
+
69
+
70
+ ## 2.5.7 (2024-10-10)
71
+
72
+ **Note:** Version bump only for package @citolab/tspci
73
+
74
+
75
+
76
+
77
+
78
+ ## [2.5.6](/compare/v2.5.5...v2.5.6) (2024-10-10)
79
+
80
+ **Note:** Version bump only for package @citolab/tspci
81
+
82
+
83
+
84
+
85
+
86
+ ## [2.5.5](/compare/v2.5.4...v2.5.5) (2024-10-10)
87
+
88
+ **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.4",
3
+ "version": "2.5.15",
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": "3f69ce948e8d2e02131235a9488645aaa95e0413"
49
+ "gitHead": "1970a9a73da54053545f3b9a470dcad44c8abd21"
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: ```npx @citolab/tspci@latest init```
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
- ``` sh
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,10 @@ 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}
177
+ --targetExt -tx Same as -target but reffering to a fully qualified package (not in @citolab)
173
178
  init Init PCI development environment.
174
- add --target Add specific implementation to the PCI.
179
+ add --target Add specific implementation to the PCI.
175
180
 
176
181
  Examples package.json scripts
177
182
  $ "dev": "tspci --dev",
@@ -182,11 +187,12 @@ Examples package.json scripts
182
187
 
183
188
  ## 🛣 What's next
184
189
 
185
- Use one of the [examples](https://github.com/Citolab/tspci-examples) to get a headstart
190
+ Use one of the [examples](https://github.com/Citolab/tspci-examples) to get a headstart
186
191
 
187
- Or read further how we build our PCIs
192
+ Or read further how we build our PCIs
188
193
 
189
194
  Our prefered layout of our PCIs
195
+
190
196
  ```
191
197
  your-pci-project
192
198
  │ package.json // Definition of your PCI in a standard package.json, TAO adds some props
@@ -195,7 +201,7 @@ your-pci-project
195
201
  │
196
202
  └───src
197
203
  │ │ config.json // Used to configure PCI, and in TAO for authors
198
- │ │ index.ts // The api for the player and bootstraps your interaction
204
+ │ │ index.ts // The api for the player and bootstraps your interaction
199
205
  │ │ interaction.ts // the actual interaction, preferably a main preact component
200
206
  │ │ store.ts // definition of the state and all possible state mutations of your pci
201
207
  │ └───style.css // css styles, imported by your pci and possible to use tailwind classes
@@ -204,8 +210,8 @@ your-pci-project
204
210
  │ tailwind.config.js // include tailwind classes
205
211
  ```
206
212
 
207
-
208
213
  ### Use JSX
214
+
209
215
  Use (p)react in your PCI's to create interactions and bind your data to HTML
210
216
 
211
217
  ```ts
@@ -220,6 +226,7 @@ Use (p)react in your PCI's to create interactions and bind your data to HTML
220
226
  ```
221
227
 
222
228
  ### Bundle your css
229
+
223
230
  Import and bundle css
224
231
  Appending css to shadowdom will prevent styles leaking into your player
225
232
 
@@ -239,20 +246,18 @@ Appending css to shadowdom will prevent styles leaking into your player
239
246
 
240
247
  install autoprefixer
241
248
 
242
- ``` sh
249
+ ```sh
243
250
  npm i -D autoprefixer
244
251
  ```
245
252
 
246
253
  add `postcss.config.js` with autoprefixer
247
254
 
248
255
  // postcss.config.js
256
+
249
257
  ```js
250
258
  module.exports = {
251
- plugins: [
252
- require('postcss-import'),
253
- require('autoprefixer'),
254
- ]
255
- }
259
+ plugins: [require("postcss-import"), require("autoprefixer")],
260
+ };
256
261
  ```
257
262
 
258
263
  ### Modern UI with existing classes
@@ -262,10 +267,7 @@ and add a `tailwind.config.js`
262
267
 
263
268
  ```js
264
269
  // postcss.config.js
265
- plugins: [
266
- + require('tailwindcss/nesting'),
267
- + require('tailwindcss'),
268
- ];
270
+ plugins: [+require("tailwindcss/nesting"), +require("tailwindcss")];
269
271
  ```
270
272
 
271
273
  ```js
@@ -280,7 +282,8 @@ module.exports = {
280
282
  ```
281
283
 
282
284
  ### Bundle all your images
283
- Images are bundled in the js by importing them in code:
285
+
286
+ Images are bundled in the js by importing them in code:
284
287
  imports JPG, PNG, GIF, SVG, and WebP files
285
288
 
286
289
  ```ts
@@ -289,6 +292,7 @@ import procenten from "./assets/procenten.png";
289
292
  ```
290
293
 
291
294
  ### Create advanced PCIs with 3D libraries
295
+
292
296
  For example, import threejs to create 3D pci's
293
297
 
294
298
  ```ts
@@ -300,6 +304,7 @@ class VoxelPainterClass {
300
304
  ```
301
305
 
302
306
  ### Record user interaction
307
+
303
308
  A store will centralize your PCI state but also all mutations.
304
309
  This means, this way you could replay everything a user did
305
310
  And you can use Redux devtools to debug
@@ -312,17 +317,20 @@ dispatch<{ x: number }>("ADD_ACTION", { x: +inputValue });
312
317
  ```
313
318
 
314
319
  ### Let authors configure your PCI in QTI
320
+
315
321
  Use properties in config.json to let authors configure your PCI
316
322
  Also used in the TAO export for configuring PCIs in TAO
317
323
  `// src/config.json`
324
+
318
325
  ```json
319
326
  {
320
327
  "buttonText": "Calculate",
321
- "sum1" : "$1 * 14 + 1",
322
- "sum2" : "$1 * 2 + 21",
323
- "tableSize" : "4"
328
+ "sum1": "$1 * 14 + 1",
329
+ "sum2": "$1 * 2 + 21",
330
+ "tableSize": "4"
324
331
  }
325
332
  ```
333
+
326
334
  ```ts
327
335
  // src/index.ts
328
336
  + import configProps from "./config.json";
@@ -341,6 +349,7 @@ Also used in the TAO export for configuring PCIs in TAO
341
349
  ```
342
350
 
343
351
  ### Make use of existing react hooks
352
+
344
353
  ```ts
345
354
  // src/useMousePosition
346
355
  import { useEffect, useState } from "react";
@@ -354,20 +363,21 @@ export const useMousePosition = () => {
354
363
  return () => window.removeEventListener("mousemove", setPosFromEvent);
355
364
  }, []);
356
365
 
357
- return { clientX: position.x, clientY: position.y }
366
+ return { clientX: position.x, clientY: position.y };
358
367
  };
359
368
  ```
360
369
 
361
370
  ### 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
371
 
364
- More info, see our extension
372
+ Tao adds some lifecycle methods which you can implement and we supply an extended interfaee on top of the IMS one.
373
+
374
+ More info, see our extension
375
+
365
376
  - [github](https://github.com/Citolab/tspci/blob/main/lib/tspci-tao)
366
377
  - [@citolab/tspci-tao](https://www.npmjs.com/package/@citolab/tspci-tao)
367
378
 
368
- If you want your platform to be support, [contact us](mailto://getinspiredbycitolab@gmail.com)
369
-
379
+ If you want your platform to be support, [contact us](mailto://getinspiredbycitolab@gmail.com)
370
380
 
371
381
  ## License
372
382
 
373
- [GPLv3](https://github.com/Citolab/tspci/blob/main/LICENSE)
383
+ [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, spawn } from "child_process";
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,8 +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) && fs.mkdirSync(PACKAGE_DIST_PATH);
35
-
34
+ if (!fs.existsSync(PACKAGE_DIST_PATH)) {
35
+ fs.mkdirSync(PACKAGE_DIST_PATH);
36
+ }
36
37
  if (devServer) {
37
38
  try {
38
39
  if (fs.existsSync(path.join(PACKAGE_ROOT_PATH, "src/index.html"))) {
@@ -65,8 +66,12 @@ const watchBuild = (devServer = false, target = "IMS") => {
65
66
  warnings.flush();
66
67
  const watcher = watch(options);
67
68
  watcher.on("event", (event) => {
68
- event.code == "START" && console.log("starting build");
69
- event.code == "ERROR" && console.log("ERROR", event);
69
+ if (event.code == "START") {
70
+ console.log("starting build");
71
+ }
72
+ if (event.code == "ERROR") {
73
+ console.log("ERROR", event);
74
+ }
70
75
  });
71
76
  watcher.on("event", ({ result }) => {
72
77
  if (result) {
@@ -105,30 +110,6 @@ const prodBuild = async () => {
105
110
  });
106
111
  };
107
112
 
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
113
  function selectOptions(prompt, options) {
133
114
  return inquirer.prompt([
134
115
  {
@@ -204,8 +185,10 @@ const run = async () => {
204
185
  const help = args.indexOf("--help") >= 0 || args.indexOf("-h") >= 0;
205
186
  const watch = args.indexOf("--watch") >= 0 || args.indexOf("-w") >= 0;
206
187
  const dev = args.indexOf("--dev") >= 0 || args.indexOf("-d") >= 0;
207
- const target = args.indexOf("--target") >= 0 || args.indexOf("-t") >= 0;
188
+ const t = args.indexOf("--target") >= 0 || args.indexOf("-t") >= 0;
189
+ const tExt = args.indexOf("--targetExt") >= 0 || args.indexOf("-tx") >= 0;
208
190
  const init = args.indexOf("init") >= 0;
191
+ const targetName = t !== -1 ? `@citolab/tspci-${t}` : tExt !== -1 ? tExt : null;
209
192
 
210
193
  if (help) {
211
194
  console.log(`•\t${chalk.blueBright("--help -h")} list these commands`);
@@ -364,6 +347,9 @@ const run = async () => {
364
347
  pciName
365
348
  );
366
349
  // point to the javascript file
350
+ const packageJson = path.join(destinationFolder, "package.json");
351
+ const packageJsonContent = fs.readFileSync(packageJson, "utf8");
352
+ let packageJsonContentJson = JSON.parse(packageJsonContent);
367
353
  packageJsonContentJson.source = "src/index.js";
368
354
  const newPackageJsonContent = JSON.stringify(packageJsonContentJson, null, 2);
369
355
  fs.writeFileSync(packageJson, newPackageJsonContent);
@@ -391,37 +377,31 @@ const run = async () => {
391
377
  return;
392
378
  }
393
379
  const version = args.indexOf("--next") !== -1 ? "next" : "latest";
394
- const targetname = args[targetIndex + 1];
395
380
  const packageFileContent = fs.readFileSync(path.join(PACKAGE_ROOT_PATH, "package.json"), "utf8");
396
381
  const packageJson = JSON.parse(packageFileContent);
397
382
 
398
383
  const modifyPci = () => {
399
- const scriptFile = path.join(
400
- path.join(path.join(path.join(NODE_MODULES, `@citolab`), `tspci-${targetname}`), "src"),
401
- `init.mjs`
402
- );
384
+ const scriptFile = path.join(path.join(path.join(NODE_MODULES, `${targetName}`), "src"), `init.mjs`);
403
385
  let init = false;
404
386
  if (fs.existsSync(scriptFile)) {
405
387
  // run init() script
406
388
  import(`file:///${scriptFile}`).then((script) => {
407
389
  if (script.init) {
408
390
  init = true;
409
- console.log(chalk.green(`Running init script for @citolab/tspci-${targetname}`));
391
+ console.log(chalk.green(`Running init script for ${targetName}`));
410
392
  script.init();
411
393
  } else {
412
394
  if (!init) {
413
- console.log(chalk.red(`No init script found for @citolab/tspci-${targetname}`));
395
+ console.log(chalk.red(`No init script found for ${targetName}`));
414
396
  }
415
397
  }
416
398
  });
417
399
  }
418
400
  };
419
-
420
- // check if `@citolab/tspci-${targetname}]}` is already in devDependencies
421
- if (!packageJson.devDependencies || !packageJson.devDependencies[`@citolab/tspci-${targetname}`]) {
422
- console.log(chalk.white(`Adding @citolab/tspci-${targetname}`));
401
+ if (!packageJson.devDependencies || !packageJson.devDependencies[targetName]) {
402
+ console.log(chalk.white(`Adding ${targetName}`));
423
403
  // install @citolab/tspci-${targetname} to devDepencies
424
- execSync(`npm install @citolab/tspci-${targetname}@${version} --save-dev`, {
404
+ execSync(`npm install ${targetName}@${version} --save-dev`, {
425
405
  cwd: PACKAGE_ROOT_PATH,
426
406
  stdio: [0, 1, 2],
427
407
  });
@@ -449,16 +429,11 @@ const run = async () => {
449
429
  }
450
430
 
451
431
  prodBuild().then(() => {
452
- if (target) {
453
- const targetIndex = args.indexOf("--target");
454
- if (args.length <= targetIndex + 1) {
455
- console.error("Missing target name. Use tspci --target target");
432
+ if (t) {
433
+ if (!targetName) {
434
+ console.error("Missing target name. Use tspci --target target or tspci --targetExt target");
456
435
  }
457
- const targetname = args[targetIndex + 1];
458
- const scriptFile = path.join(
459
- path.join(path.join(path.join(NODE_MODULES, `@citolab`), `tspci-${targetname}`), "src"),
460
- `createPackage.mjs`
461
- );
436
+ const scriptFile = path.join(path.join(path.join(NODE_MODULES, `${targetName}`), "src"), `createPackage.mjs`);
462
437
  import(`file:///${scriptFile}`).then((script) => {
463
438
  script.bundle();
464
439
  });