@m2c2kit/cli 0.1.7 → 0.1.8

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/dist/.env CHANGED
@@ -1 +1 @@
1
- CLI_VERSION=0.1.7
1
+ CLI_VERSION=0.1.8
package/dist/cli.js CHANGED
@@ -266,25 +266,10 @@ await yarg
266
266
  if (abort) {
267
267
  yarg.exit(1, new Error("user aborted"));
268
268
  }
269
- // get study code first from command line, then from config file, then assign blank
270
- let studyCode = argv["studyCode"] ??
269
+ // get study code first from command line, then from config file, then generate new one
270
+ const studyCode = argv["studyCode"] ??
271
271
  serverConfig?.studyCode ??
272
- "";
273
- if (studyCode === "") {
274
- const response = await prompts({
275
- type: "text",
276
- name: "studyCode",
277
- message: "study code?",
278
- validate: (text) => text.length > 0
279
- ? true
280
- : "provide a study code (5 random alphanumeric digits, e.g., R5T7A)",
281
- onState: (state) => (abort = state.aborted === true),
282
- });
283
- studyCode = response.studyCode;
284
- }
285
- if (abort) {
286
- yarg.exit(1, new Error("user aborted"));
287
- }
272
+ generateStudyCode();
288
273
  // if new url or study code was provided, save these
289
274
  if (url !== serverConfig?.url || studyCode !== serverConfig?.studyCode) {
290
275
  m2c2kitProjectConfig.set("server", { url, studyCode });
@@ -7,8 +7,8 @@
7
7
  },
8
8
  "private": true,
9
9
  "dependencies": {
10
- "@m2c2kit/core": "0.1.5",
11
- "@m2c2kit/addons": "0.1.5"
10
+ "@m2c2kit/core": "0.1.6",
11
+ "@m2c2kit/addons": "0.1.6"
12
12
  },
13
13
  "devDependencies": {
14
14
  "rollup": "2.63.0",
@@ -339,6 +339,18 @@ class {{className}} extends Game {
339
339
  }
340
340
  }
341
341
 
342
+ // ============================================================================
343
+
344
+ // When running within an Android webview, the below defines how the session
345
+ // can communicate events to the Android app. Note: the names of this Android
346
+ // namespace and its functions must match the corresponding Android code
347
+ // in addJavascriptInterface() and @JavascriptInterface
348
+ // eslint-disable-next-line @typescript-eslint/no-namespace
349
+ declare namespace Android {
350
+ function onGameTrialComplete(gameTrialEventAsString: string): void;
351
+ function onGameLifecycleChange(gameLifecycleEventAsString: string): void;
352
+ }
353
+
342
354
  // default was 3 trials; this is how we can specify a different value
343
355
  const game1 = new {{className}}({ TrialNum: 2 });
344
356
 
@@ -352,9 +364,14 @@ const session = new Session({
352
364
  console.log("data: " + JSON.stringify(e.gameData));
353
365
  console.log("trial schema: " + JSON.stringify(e.trialSchema));
354
366
  console.log("game parameters: " + JSON.stringify(e.gameParameters));
367
+
368
+ // callback to native Android app, if running in that context
369
+ if (typeof Android !== "undefined") {
370
+ Android.onGameTrialComplete(JSON.stringify(e));
371
+ }
355
372
  },
356
- // onGameEnd() is called when the user is done
357
- onGameEnd: (e: GameLifecycleEvent) => {
373
+ // onGameLifecycleChange() is called when the game lifecycles changes
374
+ onGameLifecycleChange: (e: GameLifecycleEvent) => {
358
375
  if (e.ended) {
359
376
  console.log(`user requested exit in game ${e.gameName}`);
360
377
  // this session has only one activity, but this is how it would go to
@@ -362,6 +379,11 @@ const session = new Session({
362
379
  if (session.nextActivity) {
363
380
  session.advanceToNextActivity();
364
381
  }
382
+
383
+ // callback to native Android app, if running in that context
384
+ if (typeof Android !== "undefined") {
385
+ Android.onGameLifecycleChange(JSON.stringify(e));
386
+ }
365
387
  }
366
388
  },
367
389
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@m2c2kit/cli",
3
- "version": "0.1.7",
3
+ "version": "0.1.8",
4
4
  "description": "m2c2kit command line interface",
5
5
  "module": "dist/cli.js",
6
6
  "files": [