From 2a3ce6de0190349c396dbf7692a26cfe97007da6 Mon Sep 17 00:00:00 2001 From: Becky Gilbert Date: Fri, 25 Oct 2024 13:45:55 -0700 Subject: [PATCH 1/5] Video file names in standard format (#70) * add recorder method for constructing video file name and add/modify params for recorder.start (consent boolean, trial type string) * update recorder.start params in consentVideo test * add mock for jsPsych.getCurrentTrial (passes current trial type from trial recording extension to recorder.start) * update recorder.start params in existing tests, mock getLastTrialData, test new createFileName method * add changeset * add private getCurrentPluginName method to trial extension, get plugin name from info, fix types, fix/add tests --- .changeset/rotten-cars-swim.md | 6 +++ packages/record/src/consentVideo.spec.ts | 2 +- packages/record/src/consentVideo.ts | 2 +- packages/record/src/index.spec.ts | 12 +++-- packages/record/src/recorder.spec.ts | 66 +++++++++++++++++++++++- packages/record/src/recorder.ts | 38 ++++++++++++-- packages/record/src/start.ts | 8 +-- packages/record/src/trial.ts | 16 +++++- packages/record/src/types.ts | 8 +++ 9 files changed, 142 insertions(+), 16 deletions(-) create mode 100644 .changeset/rotten-cars-swim.md diff --git a/.changeset/rotten-cars-swim.md b/.changeset/rotten-cars-swim.md new file mode 100644 index 00000000..da1a0d91 --- /dev/null +++ b/.changeset/rotten-cars-swim.md @@ -0,0 +1,6 @@ +--- +"@lookit/record": patch +--- + +Change video file names to match existing format, and to pass necessary info to +AWS Lambda for saving video files to database. diff --git a/packages/record/src/consentVideo.spec.ts b/packages/record/src/consentVideo.spec.ts index fa048dd2..26d03ccc 100644 --- a/packages/record/src/consentVideo.spec.ts +++ b/packages/record/src/consentVideo.spec.ts @@ -233,7 +233,7 @@ test("recordButton", async () => { // Start recorder expect(Recorder.prototype.start).toHaveBeenCalledTimes(1); - expect(Recorder.prototype.start).toHaveBeenCalledWith("consent"); + expect(Recorder.prototype.start).toHaveBeenCalledWith(true, "consent-video"); }); test("playButton", () => { diff --git a/packages/record/src/consentVideo.ts b/packages/record/src/consentVideo.ts index 8d79349c..4c5e52d5 100644 --- a/packages/record/src/consentVideo.ts +++ b/packages/record/src/consentVideo.ts @@ -212,7 +212,7 @@ export class VideoConsentPlugin implements JsPsychPlugin { play.disabled = true; next.disabled = true; this.getImg(display, "record-icon").style.visibility = "visible"; - await this.recorder.start("consent"); + await this.recorder.start(true, VideoConsentPlugin.info.name); }); } diff --git a/packages/record/src/index.spec.ts b/packages/record/src/index.spec.ts index aa97f299..cf17c3db 100644 --- a/packages/record/src/index.spec.ts +++ b/packages/record/src/index.spec.ts @@ -10,9 +10,12 @@ jest.mock("./recorder"); jest.mock("@lookit/data"); jest.mock("jspsych", () => ({ ...jest.requireActual("jspsych"), - initJsPsych: jest - .fn() - .mockReturnValue({ finishTrial: jest.fn().mockImplementation() }), + initJsPsych: jest.fn().mockReturnValue({ + finishTrial: jest.fn().mockImplementation(), + getCurrentTrial: jest + .fn() + .mockReturnValue({ type: { info: { name: "test-type" } } }), + }), })); /** @@ -41,6 +44,7 @@ test("Trial recording", () => { const mockRecStop = jest.spyOn(Recorder.prototype, "stop"); const jsPsych = initJsPsych(); const trialRec = new Rec.TrialRecordExtension(jsPsych); + const getCurrentPluginNameSpy = jest.spyOn(trialRec, "getCurrentPluginName"); trialRec.on_start(); trialRec.on_load(); @@ -48,7 +52,9 @@ test("Trial recording", () => { expect(Recorder).toHaveBeenCalledTimes(1); expect(mockRecStart).toHaveBeenCalledTimes(1); + expect(mockRecStart).toHaveBeenCalledWith(false, "test-type"); expect(mockRecStop).toHaveBeenCalledTimes(1); + expect(getCurrentPluginNameSpy).toHaveBeenCalledTimes(1); }); test("Trial recording's initialize does nothing", async () => { diff --git a/packages/record/src/recorder.spec.ts b/packages/record/src/recorder.spec.ts index de9ead4e..2fb77c85 100644 --- a/packages/record/src/recorder.spec.ts +++ b/packages/record/src/recorder.spec.ts @@ -1,4 +1,5 @@ import Data from "@lookit/data"; +import { LookitWindow } from "@lookit/data/dist/types"; import Handlebars from "handlebars"; import { initJsPsych } from "jspsych"; import playbackFeed from "../hbs/playback-feed.hbs"; @@ -19,6 +20,19 @@ import { import Recorder from "./recorder"; import { CSSWidthHeight } from "./types"; +declare const window: LookitWindow; + +window.chs = { + study: { + id: "123", + }, + response: { + id: "456", + }, +} as typeof window.chs; + +let originalDate: DateConstructor; + jest.mock("@lookit/data"); jest.mock("jspsych", () => ({ ...jest.requireActual("jspsych"), @@ -35,6 +49,13 @@ jest.mock("jspsych", () => ({ }, }), }, + data: { + getLastTrialData: jest.fn().mockReturnValue({ + values: jest + .fn() + .mockReturnValue([{ trial_type: "test-type", trial_index: 0 }]), + }), + }, }), })); @@ -68,7 +89,7 @@ test("Recorder start", async () => { const jsPsych = initJsPsych(); const rec = new Recorder(jsPsych); const media = jsPsych.pluginAPI.getCameraRecorder(); - await rec.start("consent"); + await rec.start(true, "video-consent"); expect(media.addEventListener).toHaveBeenCalledTimes(2); expect(media.start).toHaveBeenCalledTimes(1); @@ -112,7 +133,7 @@ test("Recorder initialize error", () => { .fn() .mockReturnValue(undefined); - expect(async () => await rec.start("consent")).rejects.toThrow( + expect(async () => await rec.start(true, "video-consent")).rejects.toThrow( RecorderInitializeError, ); @@ -444,3 +465,44 @@ test("Recorder insert record Feed with height/width", () => { Handlebars.compile(recordFeed)(view), ); }); + +test("Recorder createFileName constructs video file names correctly", () => { + const jsPsych = initJsPsych(); + const rec = new Recorder(jsPsych); + + // Mock Date().getTime() timestamp + originalDate = Date; + const mockTimestamp = 1634774400000; + jest.spyOn(global, "Date").mockImplementation(() => { + return new originalDate(mockTimestamp); + }); + // Mock random 3-digit number + jest.spyOn(global.Math, "random").mockReturnValue(0.123456789); + const rand_digits = Math.floor(Math.random() * 1000); + + const index = jsPsych.data.getLastTrialData().values()[0].trial_index + 1; + const trial_type = "test-type"; + + // Consent prefix is "consent-videoStream" + expect(rec["createFileName"](true, trial_type)).toBe( + `consent-videoStream_${window.chs.study.id}_${index.toString()}-${trial_type}_${window.chs.response.id}_${mockTimestamp.toString()}_${rand_digits.toString()}.webm`, + ); + + // Non-consent prefix is "videoStream" + expect(rec["createFileName"](false, trial_type)).toBe( + `videoStream_${window.chs.study.id}_${index.toString()}-${trial_type}_${window.chs.response.id}_${mockTimestamp.toString()}_${rand_digits.toString()}.webm`, + ); + + // Trial index is 0 if there's no value for 'last trial index' (jsPsych data is empty) + jsPsych.data.getLastTrialData = jest.fn().mockReturnValueOnce({ + values: jest.fn().mockReturnValue([]), + }); + expect(rec["createFileName"](false, trial_type)).toBe( + `videoStream_${window.chs.study.id}_${0}-${trial_type}_${window.chs.response.id}_${mockTimestamp.toString()}_${rand_digits.toString()}.webm`, + ); + + // Restore the original Date constructor + global.Date = originalDate; + // Restore Math.random + jest.spyOn(global.Math, "random").mockRestore(); +}); diff --git a/packages/record/src/recorder.ts b/packages/record/src/recorder.ts index e0b3462c..c802bb50 100644 --- a/packages/record/src/recorder.ts +++ b/packages/record/src/recorder.ts @@ -1,5 +1,6 @@ import Data from "@lookit/data"; import LookitS3 from "@lookit/data/dist/lookitS3"; +import { LookitWindow } from "@lookit/data/dist/types"; import autoBind from "auto-bind"; import Handlebars from "handlebars"; import { JsPsych } from "jspsych"; @@ -20,6 +21,8 @@ import { } from "./errors"; import { CSSWidthHeight } from "./types"; +declare const window: LookitWindow; + /** Recorder handles the state of recording and data storage. */ export default class Recorder { private url?: string; @@ -219,14 +222,16 @@ export default class Recorder { * Start recording. Also, adds event listeners for handling data and checks * for recorder initialization. * - * @param prefix - Prefix for the video recording file name (string). This is - * the string that comes before "_.webm". + * @param consent - Boolean indicating whether or not the recording is consent + * footage. + * @param trial_type - Trial type, as saved in the jsPsych data. This comes + * from the plugin info "name" value (not the class name). */ - public async start(prefix: "consent" | "session_video" | "trial_video") { + public async start(consent: boolean, trial_type: string) { this.initializeCheck(); - // Set filename - this.filename = `${prefix}_${new Date().getTime()}.webm`; + // Set video filename + this.filename = this.createFileName(consent, trial_type); // Instantiate s3 object if (!this.localDownload) { @@ -350,4 +355,27 @@ export default class Recorder { webcam_feed_element.remove(); } } + + /** + * Creates a valid video file name based on parameters + * + * @param consent - Boolean indicating whether or not the recording is consent + * footage. + * @param trial_type - Trial type, as saved in the jsPsych data. This comes + * from the plugin info "name" value (not the class name). + * @returns File name string with .webm extension. + */ + private createFileName(consent: boolean, trial_type: string) { + // File name formats: + // consent: consent-videoStream_{study}_{frame_id}_{response}_{timestamp}_{random_digits}.webm + // non-consent: videoStream_{study}_{frame_id}_{response}_{timestamp}_{random_digits}.webm + const prefix = consent ? "consent-videoStream" : "videoStream"; + const last_data = this.jsPsych.data.getLastTrialData().values(); + const curr_trial_index = ( + last_data.length > 0 ? last_data[last_data.length - 1].trial_index + 1 : 0 + ).toString(); + const trial_id = `${curr_trial_index}-${trial_type}`; + const rand_digits = Math.floor(Math.random() * 1000); + return `${prefix}_${window.chs.study.id}_${trial_id}_${window.chs.response.id}_${new Date().getTime()}_${rand_digits}.webm`; + } } diff --git a/packages/record/src/start.ts b/packages/record/src/start.ts index 6e569589..5220922e 100644 --- a/packages/record/src/start.ts +++ b/packages/record/src/start.ts @@ -29,8 +29,10 @@ export default class StartRecordPlugin implements JsPsychPlugin { /** Trial function called by jsPsych. */ public trial() { - this.recorder.start("session_video").then(() => { - this.jsPsych.finishTrial(); - }); + this.recorder + .start(false, `${StartRecordPlugin.info.name}-multiframe`) + .then(() => { + this.jsPsych.finishTrial(); + }); } } diff --git a/packages/record/src/trial.ts b/packages/record/src/trial.ts index f31576e6..d5d6091d 100644 --- a/packages/record/src/trial.ts +++ b/packages/record/src/trial.ts @@ -1,6 +1,7 @@ import autoBind from "auto-bind"; import { JsPsych, JsPsychExtension, JsPsychExtensionInfo } from "jspsych"; import Recorder from "./recorder"; +import { jsPsychPluginWithInfo } from "./types"; /** This extension will allow reasearchers to record trials. */ export default class TrialRecordExtension implements JsPsychExtension { @@ -9,6 +10,7 @@ export default class TrialRecordExtension implements JsPsychExtension { }; private recorder?: Recorder; + private pluginName: string | undefined; /** * Video recording extension. @@ -32,7 +34,8 @@ export default class TrialRecordExtension implements JsPsychExtension { /** Ran when the trial has loaded. */ public on_load() { - this.recorder?.start("trial_video"); + this.pluginName = this.getCurrentPluginName(); + this.recorder?.start(false, `${this.pluginName}`); } /** @@ -44,4 +47,15 @@ export default class TrialRecordExtension implements JsPsychExtension { this.recorder?.stop(); return {}; } + + /** + * Gets the plugin name for the trial that is being extended. This is same as + * the "trial_type" value that is stored in the data for this trial. + * + * @returns Plugin name string from the plugin class's info. + */ + private getCurrentPluginName() { + const current_plugin_class = this.jsPsych.getCurrentTrial().type; + return (current_plugin_class as jsPsychPluginWithInfo).info.name; + } } diff --git a/packages/record/src/types.ts b/packages/record/src/types.ts index 69b5043a..24f04ab2 100644 --- a/packages/record/src/types.ts +++ b/packages/record/src/types.ts @@ -1,3 +1,11 @@ +import { JsPsychPlugin, PluginInfo } from "jspsych"; +import { Class } from "type-fest"; + +export interface jsPsychPluginWithInfo + extends Class> { + info: PluginInfo; +} + /** * A valid CSS height/width value, which can be a number, a string containing a * number with units, or 'auto'. From 19ace5bd2dadaac0650b31c2851465369521a783 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Mon, 28 Oct 2024 12:10:13 -0400 Subject: [PATCH 2/5] chore(release): version packages (#67) Co-authored-by: github-actions[bot] --- .changeset/cold-chairs-confess.md | 5 ----- .changeset/early-seahorses-brush.md | 6 ------ .changeset/large-rabbits-matter.md | 6 ------ .changeset/moody-points-cheat.md | 7 ------- .changeset/nice-hats-sing.md | 9 --------- .changeset/rotten-cars-swim.md | 6 ------ .changeset/shaggy-toes-swim.md | 6 ------ .changeset/silver-pigs-develop.md | 5 ----- .changeset/strange-bottles-invent.md | 6 ------ packages/data/CHANGELOG.md | 7 +++++++ packages/data/package.json | 2 +- packages/lookit-initjspsych/CHANGELOG.md | 9 +++++++++ packages/lookit-initjspsych/package.json | 4 ++-- packages/record/CHANGELOG.md | 23 +++++++++++++++++++++++ packages/record/package.json | 6 +++--- packages/style/CHANGELOG.md | 8 ++++++++ packages/style/package.json | 6 +++--- packages/surveys/CHANGELOG.md | 9 +++++++++ packages/surveys/package.json | 4 ++-- packages/templates/CHANGELOG.md | 13 +++++++++++++ packages/templates/package.json | 4 ++-- 21 files changed, 82 insertions(+), 69 deletions(-) delete mode 100644 .changeset/cold-chairs-confess.md delete mode 100644 .changeset/early-seahorses-brush.md delete mode 100644 .changeset/large-rabbits-matter.md delete mode 100644 .changeset/moody-points-cheat.md delete mode 100644 .changeset/nice-hats-sing.md delete mode 100644 .changeset/rotten-cars-swim.md delete mode 100644 .changeset/shaggy-toes-swim.md delete mode 100644 .changeset/silver-pigs-develop.md delete mode 100644 .changeset/strange-bottles-invent.md create mode 100644 packages/templates/CHANGELOG.md diff --git a/.changeset/cold-chairs-confess.md b/.changeset/cold-chairs-confess.md deleted file mode 100644 index 001ffbdc..00000000 --- a/.changeset/cold-chairs-confess.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -"@lookit/style": patch ---- - -Update consent trial style diff --git a/.changeset/early-seahorses-brush.md b/.changeset/early-seahorses-brush.md deleted file mode 100644 index 7eefaca5..00000000 --- a/.changeset/early-seahorses-brush.md +++ /dev/null @@ -1,6 +0,0 @@ ---- -"@lookit/templates": patch -"@lookit/record": patch ---- - -Move translations and video consent templates to new templates package. diff --git a/.changeset/large-rabbits-matter.md b/.changeset/large-rabbits-matter.md deleted file mode 100644 index 804b881e..00000000 --- a/.changeset/large-rabbits-matter.md +++ /dev/null @@ -1,6 +0,0 @@ ---- -"@lookit/templates": patch -"@lookit/record": patch ---- - -Add ability to select specific video consent template. diff --git a/.changeset/moody-points-cheat.md b/.changeset/moody-points-cheat.md deleted file mode 100644 index a88c15ce..00000000 --- a/.changeset/moody-points-cheat.md +++ /dev/null @@ -1,7 +0,0 @@ ---- -"@lookit/record": patch ---- - -Adds `chs_type: "consent"` to consentVideo trial data and updates the lookit-api -response object with `completed_consent_frame: true` at the end of the -consentVideo trial. diff --git a/.changeset/nice-hats-sing.md b/.changeset/nice-hats-sing.md deleted file mode 100644 index 99cea7dd..00000000 --- a/.changeset/nice-hats-sing.md +++ /dev/null @@ -1,9 +0,0 @@ ---- -"@lookit/lookit-initjspsych": patch -"@lookit/surveys": patch -"@lookit/record": patch -"@lookit/style": patch -"@lookit/data": patch ---- - -Update rollup config to hide known circular warnings diff --git a/.changeset/rotten-cars-swim.md b/.changeset/rotten-cars-swim.md deleted file mode 100644 index da1a0d91..00000000 --- a/.changeset/rotten-cars-swim.md +++ /dev/null @@ -1,6 +0,0 @@ ---- -"@lookit/record": patch ---- - -Change video file names to match existing format, and to pass necessary info to -AWS Lambda for saving video files to database. diff --git a/.changeset/shaggy-toes-swim.md b/.changeset/shaggy-toes-swim.md deleted file mode 100644 index f8968923..00000000 --- a/.changeset/shaggy-toes-swim.md +++ /dev/null @@ -1,6 +0,0 @@ ---- -"@lookit/style": patch -"@lookit/data": patch ---- - -Update to unpkg config diff --git a/.changeset/silver-pigs-develop.md b/.changeset/silver-pigs-develop.md deleted file mode 100644 index ff75539f..00000000 --- a/.changeset/silver-pigs-develop.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -"@lookit/record": patch ---- - -Unmute playback of recorded consent video. diff --git a/.changeset/strange-bottles-invent.md b/.changeset/strange-bottles-invent.md deleted file mode 100644 index 9774fea1..00000000 --- a/.changeset/strange-bottles-invent.md +++ /dev/null @@ -1,6 +0,0 @@ ---- -"@lookit/templates": patch -"@lookit/record": patch ---- - -Add Garden's consent template diff --git a/packages/data/CHANGELOG.md b/packages/data/CHANGELOG.md index 1cec618a..c40eb7a2 100644 --- a/packages/data/CHANGELOG.md +++ b/packages/data/CHANGELOG.md @@ -1,5 +1,12 @@ # @lookit/data +## 0.0.4 + +### Patch Changes + +- b111054: Update rollup config to hide known circular warnings +- 888be3d: Update to unpkg config + ## 0.0.3 ### Patch Changes diff --git a/packages/data/package.json b/packages/data/package.json index f0bc3fc1..731b5473 100644 --- a/packages/data/package.json +++ b/packages/data/package.json @@ -1,6 +1,6 @@ { "name": "@lookit/data", - "version": "0.0.3", + "version": "0.0.4", "description": "This is a JS implementation of lookit's RESTful API.", "homepage": "https://github.com/lookit/lookit-jspsych#readme", "bugs": { diff --git a/packages/lookit-initjspsych/CHANGELOG.md b/packages/lookit-initjspsych/CHANGELOG.md index d0f698e0..6f298286 100644 --- a/packages/lookit-initjspsych/CHANGELOG.md +++ b/packages/lookit-initjspsych/CHANGELOG.md @@ -1,5 +1,14 @@ # @lookit/lookit-initjspsych +## 0.0.4 + +### Patch Changes + +- b111054: Update rollup config to hide known circular warnings +- Updated dependencies [b111054] +- Updated dependencies [888be3d] + - @lookit/data@0.0.4 + ## 0.0.3 ### Patch Changes diff --git a/packages/lookit-initjspsych/package.json b/packages/lookit-initjspsych/package.json index 76294860..dda16425 100644 --- a/packages/lookit-initjspsych/package.json +++ b/packages/lookit-initjspsych/package.json @@ -1,6 +1,6 @@ { "name": "@lookit/lookit-initjspsych", - "version": "0.0.3", + "version": "0.0.4", "description": "This package overloads jsPsych's init function.", "homepage": "https://github.com/lookit/lookit-jspsych#readme", "bugs": { @@ -26,7 +26,7 @@ "test": "jest --coverage" }, "dependencies": { - "@lookit/data": "0.0.3" + "@lookit/data": "0.0.4" }, "devDependencies": { "@jspsych/config": "^2.0.0" diff --git a/packages/record/CHANGELOG.md b/packages/record/CHANGELOG.md index 36ba349e..563b61ff 100644 --- a/packages/record/CHANGELOG.md +++ b/packages/record/CHANGELOG.md @@ -1,5 +1,28 @@ # @lookit/record +## 0.0.4 + +### Patch Changes + +- bb6754c: Move translations and video consent templates to new templates + package. +- c879e6a: Add ability to select specific video consent template. +- 4e72f2b: Adds `chs_type: "consent"` to consentVideo trial data and updates the + lookit-api response object with `completed_consent_frame: true` at the end of + the consentVideo trial. +- b111054: Update rollup config to hide known circular warnings +- 2a3ce6d: Change video file names to match existing format, and to pass + necessary info to AWS Lambda for saving video files to database. +- 496b62d: Unmute playback of recorded consent video. +- 9385555: Add Garden's consent template +- Updated dependencies [bb6754c] +- Updated dependencies [c879e6a] +- Updated dependencies [b111054] +- Updated dependencies [888be3d] +- Updated dependencies [9385555] + - @lookit/templates@0.0.1 + - @lookit/data@0.0.4 + ## 0.0.3 ### Patch Changes diff --git a/packages/record/package.json b/packages/record/package.json index df3deee3..f7801347 100644 --- a/packages/record/package.json +++ b/packages/record/package.json @@ -1,6 +1,6 @@ { "name": "@lookit/record", - "version": "0.0.3", + "version": "0.0.4", "description": "Recording extensions and plugins for CHS studies.", "homepage": "https://github.com/lookit/lookit-jspsych#readme", "bugs": { @@ -46,8 +46,8 @@ "typescript": "^5.6.2" }, "peerDependencies": { - "@lookit/data": "^0.0.3", - "@lookit/templates": "^0.0.0", + "@lookit/data": "^0.0.4", + "@lookit/templates": "^0.0.1", "jspsych": "^8.0.2" } } diff --git a/packages/style/CHANGELOG.md b/packages/style/CHANGELOG.md index a82abcd2..4a765d3e 100644 --- a/packages/style/CHANGELOG.md +++ b/packages/style/CHANGELOG.md @@ -1,5 +1,13 @@ # @lookit/style +## 0.0.4 + +### Patch Changes + +- 9385555: Update consent trial style +- b111054: Update rollup config to hide known circular warnings +- 888be3d: Update to unpkg config + ## 0.0.3 ### Patch Changes diff --git a/packages/style/package.json b/packages/style/package.json index 422ca5da..6cca9ae8 100644 --- a/packages/style/package.json +++ b/packages/style/package.json @@ -1,6 +1,6 @@ { "name": "@lookit/style", - "version": "0.0.3", + "version": "0.0.4", "description": "", "license": "ISC", "author": "", @@ -18,8 +18,8 @@ }, "devDependencies": { "@jspsych/config": "^2.0.0", - "@lookit/record": "^0.0.3", - "@lookit/surveys": "^0.0.3", + "@lookit/record": "^0.0.4", + "@lookit/surveys": "^0.0.4", "rollup-plugin-scss": "^4.0.0", "sass": "^1.78.0", "trash-cli": "^5.0.0" diff --git a/packages/surveys/CHANGELOG.md b/packages/surveys/CHANGELOG.md index 57ad5070..45289a04 100644 --- a/packages/surveys/CHANGELOG.md +++ b/packages/surveys/CHANGELOG.md @@ -1,5 +1,14 @@ # @lookit/surveys +## 0.0.4 + +### Patch Changes + +- b111054: Update rollup config to hide known circular warnings +- Updated dependencies [b111054] +- Updated dependencies [888be3d] + - @lookit/data@0.0.4 + ## 0.0.3 ### Patch Changes diff --git a/packages/surveys/package.json b/packages/surveys/package.json index 191f53cb..95b5f9ab 100644 --- a/packages/surveys/package.json +++ b/packages/surveys/package.json @@ -1,6 +1,6 @@ { "name": "@lookit/surveys", - "version": "0.0.3", + "version": "0.0.4", "description": "A survey plugin for lookit studies.", "homepage": "https://github.com/lookit/lookit-jspsych#readme", "bugs": { @@ -26,7 +26,7 @@ }, "dependencies": { "@jspsych/plugin-survey": "^2.0.0", - "@lookit/data": "^0.0.3", + "@lookit/data": "^0.0.4", "dompurify": "^3.0.11", "marked": "^12.0.1", "survey-jquery": "^1.9.136" diff --git a/packages/templates/CHANGELOG.md b/packages/templates/CHANGELOG.md new file mode 100644 index 00000000..7a7a3b49 --- /dev/null +++ b/packages/templates/CHANGELOG.md @@ -0,0 +1,13 @@ +# @lookit/templates + +## 0.0.1 + +### Patch Changes + +- bb6754c: Move translations and video consent templates to new templates + package. +- c879e6a: Add ability to select specific video consent template. +- 9385555: Add Garden's consent template +- Updated dependencies [b111054] +- Updated dependencies [888be3d] + - @lookit/data@0.0.4 diff --git a/packages/templates/package.json b/packages/templates/package.json index eb3c558d..c8ff72c6 100644 --- a/packages/templates/package.json +++ b/packages/templates/package.json @@ -1,6 +1,6 @@ { "name": "@lookit/templates", - "version": "0.0.0", + "version": "0.0.1", "description": "CHS jsPsych trial templates and their translations", "homepage": "https://github.com/lookit/lookit-jspsych#readme", "bugs": { @@ -31,7 +31,7 @@ "rollup-plugin-polyfill-node": "^0.13.0" }, "peerDependencies": { - "@lookit/data": "^0.0.3", + "@lookit/data": "^0.0.4", "jspsych": "^8.0.2" } } From 6c42a48ec81769ddde06f54758bb06692a130977 Mon Sep 17 00:00:00 2001 From: CJ Green <44074998+okaycj@users.noreply.github.com> Date: Tue, 29 Oct 2024 09:02:09 -0400 Subject: [PATCH 3/5] Production dotenv (#88) * Add env file creation to build script * Move env file to central location * Update dev docs * Changeset --- .changeset/mean-llamas-cheat.md | 7 +++++++ .github/workflows/build.yml | 8 +++++++- README.md | 12 +++++++++--- packages/data/rollup.config.mjs | 2 +- packages/record/rollup.config.mjs | 2 +- packages/templates/rollup.config.mjs | 2 +- 6 files changed, 26 insertions(+), 7 deletions(-) create mode 100644 .changeset/mean-llamas-cheat.md diff --git a/.changeset/mean-llamas-cheat.md b/.changeset/mean-llamas-cheat.md new file mode 100644 index 00000000..e6dede65 --- /dev/null +++ b/.changeset/mean-llamas-cheat.md @@ -0,0 +1,7 @@ +--- +"@lookit/templates": patch +"@lookit/record": patch +"@lookit/data": patch +--- + +Generate environment file before production build diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index f6a219a6..30b07edb 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -8,7 +8,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - node: [18, 20] + node: ["18.x", "20.x"] steps: - uses: actions/checkout@v4 @@ -25,6 +25,12 @@ jobs: - name: Install NPM dependencies run: npm ci + - name: Create environment file + run: printenv > .env + env: + DEBUG: "false" + LOCAL_DOWNLOAD: "false" + - name: Build packages run: npm run build diff --git a/README.md b/README.md index 4711e2bf..4953a162 100644 --- a/README.md +++ b/README.md @@ -95,15 +95,21 @@ npm i @jspsych/config -w @lookit/ ## Build all packages -We can use npm workspaces to build all packages. +First, create a `.env` file at the root of the monorepo. It can contain the +following for a successful local development build. -First, install dependencies: +``` +DEBUG=true +LOCAL_DOWNLOAD=true +``` + +Next, we can use npm to install dependencies. ``` npm ci ``` -Build all packages: +Then, build all packages. ``` npm run build diff --git a/packages/data/rollup.config.mjs b/packages/data/rollup.config.mjs index 010f204b..43981b10 100644 --- a/packages/data/rollup.config.mjs +++ b/packages/data/rollup.config.mjs @@ -9,7 +9,7 @@ export default makeRollupConfig("chsData").map((config) => { // Resolve node dependencies to be used in a browser. nodeResolve({ browser: true, preferBuiltins: false }), // Add support for .env files - dotenv(), + dotenv({ cwd: "../../" }), ...config.plugins, ], }; diff --git a/packages/record/rollup.config.mjs b/packages/record/rollup.config.mjs index d45968af..9bc94497 100644 --- a/packages/record/rollup.config.mjs +++ b/packages/record/rollup.config.mjs @@ -11,7 +11,7 @@ export default makeRollupConfig("chsRecord").map((config) => { plugins: [ ...config.plugins, // Add support for .env files - dotenv(), + dotenv({ cwd: "../../" }), // Add support to import yaml and handlebars files as strings importAsString({ include: ["**/*.yaml", "**/*.hbs"], diff --git a/packages/templates/rollup.config.mjs b/packages/templates/rollup.config.mjs index 63119b11..a63d624a 100644 --- a/packages/templates/rollup.config.mjs +++ b/packages/templates/rollup.config.mjs @@ -9,7 +9,7 @@ export default makeRollupConfig("chsTemplates").map((config) => { plugins: [ ...config.plugins, // Add support for .env files - dotenv(), + dotenv({ cwd: "../../" }), // Add support to import yaml and handlebars files as strings importAsString({ include: ["**/*.yaml", "**/*.hbs"], From de388767d368c8ddebea631e22ee563e7adb6934 Mon Sep 17 00:00:00 2001 From: CJ Green <44074998+okaycj@users.noreply.github.com> Date: Tue, 29 Oct 2024 09:08:10 -0400 Subject: [PATCH 4/5] NPM token documentation update (#86) * Update documentation to include how to generate npm token * Update node version in release script --- .github/workflows/release.yml | 2 +- README.md | 39 +++++++++++++++++++++++++++++++---- 2 files changed, 36 insertions(+), 5 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 3a3673e7..5e0ef6ba 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -21,7 +21,7 @@ jobs: - name: Setup Node.js uses: actions/setup-node@v4 with: - node-version: 20 + node-version: "20.x" cache: npm - name: Install pango for NPM package "canvas" diff --git a/README.md b/README.md index 4953a162..c68f5e21 100644 --- a/README.md +++ b/README.md @@ -117,15 +117,15 @@ npm run build ## Linting/formating -Lint and formating is done at the monorepo level. +Lint and formatting is done at the monorepo level. -To auto fix linting/formating issues: +To auto fix linting/formatting issues: ``` npm run fix ``` -Unfixable issues will be diplayed as errors. +Unfixable issues will be displayed as errors. ## Change log @@ -135,7 +135,38 @@ Adding a change log through `changeset` is done with the following command: npm run changeset ``` -Make sure to add the change log found in the `.changeset` directory to the PR. +Try to only bump packages that have actual changes and be sure to add the change +log found in the `.changeset` directory to the PR. + +## Package Release + +Package release is automated using github actions. You can find the release +script in this repo in the `.github/workflows/` directory. + +The NPM token required to release packages should never expire. If, for some +reason, a new token is required. You will have to first generate one through +NPM. + +1. Login to https://www.npmjs.com. +2. Select "Access Tokens" from your user dropdown. +3. In the "Generate New Token" dropdown, select "Classic Token". +4. Give the token a meaningful name, select "Automation" radio button, and + click "Generate Token". +5. Copy token or leave the website open. If you close this page without + copying, you will have to generate a new token. There will be no way to get + it back. + +Next we have to move the NPM token to github actions. + +1. Login to Github and goto + https://github.com/lookit/lookit-jspsych/settings/secrets/actions. +2. Click the "Pencil" icon next to `NPM_TOKEN`. +3. Paste NPM token from above. There won't be a token in the value box. This is + to keep the current token secret. +4. Click "Update secret". + +This should allow the release script to be able to publish our packages without +authentication. ## Run dev server From 7230f51586d116d194cea3a89fc185fb8e73a596 Mon Sep 17 00:00:00 2001 From: Becky Gilbert Date: Tue, 29 Oct 2024 06:52:43 -0700 Subject: [PATCH 5/5] Add default for optional `additional_segments` parameter in video consent (#89) * fix undefined default for optional additional_segments param, and move text property into nested param object * fix formatting * add changeset --- .changeset/smart-books-scream.md | 6 ++++++ packages/record/src/consentVideo.ts | 9 +++++---- 2 files changed, 11 insertions(+), 4 deletions(-) create mode 100644 .changeset/smart-books-scream.md diff --git a/.changeset/smart-books-scream.md b/.changeset/smart-books-scream.md new file mode 100644 index 00000000..507435b2 --- /dev/null +++ b/.changeset/smart-books-scream.md @@ -0,0 +1,6 @@ +--- +"@lookit/record": patch +--- + +Add missing default value for video consent "additional_segments" parameter, +which was causing an error when this optional parameter was omitted (#84). diff --git a/packages/record/src/consentVideo.ts b/packages/record/src/consentVideo.ts index 4c5e52d5..97a4046d 100644 --- a/packages/record/src/consentVideo.ts +++ b/packages/record/src/consentVideo.ts @@ -46,15 +46,16 @@ const info = { additional_segments: { type: ParameterType.COMPLEX, array: true, + default: [], nested: { title: { type: ParameterType.STRING, default: "", }, - }, - text: { - type: ParameterType.STRING, - default: "", + text: { + type: ParameterType.STRING, + default: "", + }, }, }, prompt_all_adults: { type: ParameterType.BOOL, default: false },