From 5e878d381f6a293b2352ed3500af3b3f21b674c4 Mon Sep 17 00:00:00 2001 From: Cherrie Chang Date: Mon, 9 Dec 2024 11:58:58 -0500 Subject: [PATCH] update getCitations() to always print jsPsych + no duplicates; update citation tool docs --- docs/about/about.md | 8 ++++---- packages/config/generateCitations.js | 2 ++ packages/jspsych/src/JsPsych.ts | 8 +++++++- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/docs/about/about.md b/docs/about/about.md index ba6382e962..dde30a3f9c 100644 --- a/docs/about/about.md +++ b/docs/about/about.md @@ -16,12 +16,12 @@ This paper is an updated description of jsPsych and includes all current core te Citations help us demonstrate that this library is used and valued, which allows us to continue working on it. -#### Cite using citation tool +#### Citation tool for third-party plugins/extensions -We also made a command-line citation tool that can be used to cite this library, as well as any plugins/extensions you use in your experiment that are developed by other developers. You can see this tool in action by following these steps: +jsPsych is an open-source, collaborative ecosystem, and many of the plugins/extensions you end up using may be contributed by third-party developers! We want to make sure they get recognition for their good work, so we made a command-line citation tool that you should use to cite this library and the plugins/extensions used in your experiment. You can see this tool in action by following these steps: 1. Launch a jsPsych experiment in your browser 2. Open up the browser console using Ctrl + ⇧ + J (Windows) or ⌘ + ⌥ + J (Mac) -3. Type `jsPsych.getCitations([jsPsychHtmlKeyboardResponse], "apa")` +3. Type `jsPsych.getCitations([], "apa")` -This should print the APA format citation for the `jsPsychHtmlKeyboardResponse` plugin, which you can then copy and paste into your working document. You can type any number of plugins/extensions by name in the array `[ ]` to generate a list of citations. We currently support APA formatting (`"apa"`) and BibTex formatting (`"bibtex"`). \ No newline at end of file +This should print the APA format citation for the jsPsych library, which you can then copy and paste into your working document. You can type any number of plugins/extensions by name in the array `[ ]` to generate a list of citations, e.g. `jsPsych.getCitations([jsPsychHtmlKeyboardResponse, jsPsychMouseTrackingExtension], "apa")`. We currently support APA formatting (`"apa"`) and BibTex formatting (`"bibtex"`). \ No newline at end of file diff --git a/packages/config/generateCitations.js b/packages/config/generateCitations.js index e24f42ef42..5c87248197 100644 --- a/packages/config/generateCitations.js +++ b/packages/config/generateCitations.js @@ -22,6 +22,7 @@ export default function generateCitations() { const citationCff = (() => { let rawCff; try { + // look for CITATION.cff in the current directory rawCff = fs.readFileSync("./CITATION.cff", "utf-8").toString(); const cffData = yaml.parse(rawCff); if (cffData["preferred-citation"]) { @@ -30,6 +31,7 @@ export default function generateCitations() { return yaml.stringify(rawCff); } catch (error) { try { + // look for CITATION.cff in the root of the repository rawCff = fs.readFileSync(path.join(appRootPath.path, "CITATION.cff"), "utf-8").toString(); return yaml.stringify(rawCff); } catch (error) { diff --git a/packages/jspsych/src/JsPsych.ts b/packages/jspsych/src/JsPsych.ts index cd1124147c..f89f7ef278 100644 --- a/packages/jspsych/src/JsPsych.ts +++ b/packages/jspsych/src/JsPsych.ts @@ -272,13 +272,19 @@ export class JsPsych { } // Check if array is empty else if (plugins.length == 0) { - console.warn("No plugins/extensions provided"); + console.log( + format == "apa" + ? "de Leeuw, J. R., Gilbert, R. A., & Luchterhandt, B. (2023). jsPsych: Enabling an Open-Source Collaborative Ecosystem of Behavioral Experiments. Journal of Open Source Software, 8(85), 5351. https://doi.org/10.21105/joss.05351 " + : '@article{Leeuw2023jsPsych, author = {de Leeuw, Joshua R. and Gilbert, Rebecca A. and Luchterhandt, Bj{\\" o}rn}, journal = {Journal of Open Source Software}, doi = {10.21105/joss.05351}, issn = {2475-9066}, number = {85}, year = {2023}, month = {may 11}, pages = {5351}, publisher = {Open Journals}, title = {jsPsych: Enabling an {Open}-{Source} {Collaborative} {Ecosystem} of {Behavioral} {Experiments}}, url = {https://joss.theoj.org/papers/10.21105/joss.05351}, volume = {8}, } ' + ); return; } // Check if format is supported else if (!Object.keys(plugins[0]["info"].citations).includes(format)) { throw new Error("Unsupported citation format"); } else { + const pluginsSet = new Set(plugins); + plugins = Array.from(pluginsSet); plugins.map((plugin) => { let pluginCitations = plugin["info"].citations; console.log(format == "apa" ? `${pluginCitations.apa}` : `${pluginCitations.bibtex}`);