From a69d1ca301b2a7ffcbac689c95fb016b61050a7d Mon Sep 17 00:00:00 2001 From: cchang-vassar <79338042+cchang-vassar@users.noreply.github.com> Date: Sat, 24 Aug 2024 14:13:17 -0400 Subject: [PATCH] .cff to json for plugin-js --- templates/plugin-template-js/CITATION.cff | 41 ++++++++++++++++++ templates/plugin-template-js/package.json | 6 +++ .../plugin-template-js/src/build-citation.js | 43 +++++++++++++++++++ templates/plugin-template-js/src/index.js | 6 +++ 4 files changed, 96 insertions(+) create mode 100644 templates/plugin-template-js/CITATION.cff create mode 100644 templates/plugin-template-js/src/build-citation.js diff --git a/templates/plugin-template-js/CITATION.cff b/templates/plugin-template-js/CITATION.cff new file mode 100644 index 00000000..9ff27fdd --- /dev/null +++ b/templates/plugin-template-js/CITATION.cff @@ -0,0 +1,41 @@ +cff-version: 1.2.0 +message: "If you use this software, please cite it as below." +authors: +- family-names: "{author}" # Replace with last name + given-names: "{author}" # Replace with first name + name-particle: "{author}" # Replace with name particle(s) + orcid: "https://orcid.org/0000-0000-0000-0000" # Replace with ORCID +# More authors can be listed here in the same format as above +contact: # Contact person for this extension +- family-names: "{author}" + given-names: "{author}" + email: "{email}" # Replace with contact person's email + orcid: "https://orcid.org/0000-0000-0000-0000" # Replace with contact person's ORCID +title: "{globalName}" +version: 0.0.0 +doi: 10.5281/zenodo.1234 # Replace with DOI +date-released: 2000-01-01 +url: "{softwareUrl}" # Replace with URL to this extension + +# If you wish to cite a paper on this extension instead, you can use the following template: +preferred-citation: + authors: + - family-names: "{author}" + given-names: "{author}" + name-particle: "{author}" + orcid: "https://orcid.org/0000-0000-0000-0000" + # More authors can be listed here in the same format as above + date-published: 2023-05-11 + doi: 10.21105/joss.12345 + issn: 1234-5678 + issue: 01 + journal: Journal for Open Source Software + publisher: + name: Open Journals + start: 0001 + title: "{title}" + type: article # Other options include: book, pamphlet, conference-paper... + url: "{linkToPublicationInJournal}" + volume: 1 + +# More information on the preffered-citation CFF format can be found at https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/about-citation-files#citing-something-other-than-software \ No newline at end of file diff --git a/templates/plugin-template-js/package.json b/templates/plugin-template-js/package.json index 6220d952..3383b0b2 100644 --- a/templates/plugin-template-js/package.json +++ b/templates/plugin-template-js/package.json @@ -25,6 +25,12 @@ "url": "https://github.com/jspsych/jspsych-contrib/issues" }, "homepage": "https://github.com/jspsych/jspsych-contrib/tree/main/packages/plugin-{name}", + "dependencies": { + "@citation-js/core": "^0.7.14", + "@citation-js/plugin-software-formats": "^0.6.1", + "@citation-js/plugin-bibtex": "^0.7.14", + "@citation-js/plugin-cff": "^0.6.1" + }, "devDependencies": { "@jspsych/config": "^2.0.0", "jspsych": "^7.0.0" diff --git a/templates/plugin-template-js/src/build-citation.js b/templates/plugin-template-js/src/build-citation.js new file mode 100644 index 00000000..72fb8900 --- /dev/null +++ b/templates/plugin-template-js/src/build-citation.js @@ -0,0 +1,43 @@ +const fs = require("node:fs"); +const path = require("path"); +require("@citation-js/plugin-software-formats"); +const { Cite } = require("@citation-js/core"); + +const srcDir = __dirname; +const indexFilePath = path.join(srcDir, "index.js"); + +const updateCitations = (indexFilePath, apaCitation, bibtexCitation) => { + let fileContent = fs.readFileSync(indexFilePath, "utf-8"); + fileContent = fileContent.replace(/`{apaJson}`/g, apaCitation); + fileContent = fileContent.replace(/`{bibtexJson}`/g, bibtexCitation); + fs.writeFileSync(indexFilePath, fileContent, "utf-8"); +}; + +function cffToJson() { + const templateDir = path.dirname(srcDir); + const cffFilePath = path.join(templateDir, "CITATION.cff"); + let cffCitation = fs.readFileSync(cffFilePath, "utf-8").toString(); + Cite.async(cffCitation).then((data) => { + const apaJson = JSON.stringify( + data.format("data", { + format: "object", + template: "citation-apa", + lang: "en-US", + }), + null, + 2 + ); + const bibtexJson = JSON.stringify( + data.format("data", { + format: "object", + template: "citation-bibtex", + lang: "en-US", + }), + null, + 2 + ); + updateCitations(indexFilePath, apaJson, bibtexJson); + }); +} + +module.exports = { cffToJson, updateCitations }; diff --git a/templates/plugin-template-js/src/index.js b/templates/plugin-template-js/src/index.js index 7dde75fe..57651e69 100644 --- a/templates/plugin-template-js/src/index.js +++ b/templates/plugin-template-js/src/index.js @@ -25,6 +25,12 @@ var _globalName_ = (function (jspsych) { data2: { type: ParameterType.STRING, }, + citation: { + /** APA citation JSON */ + apa: `{apaJson}`, + /** BibTeX citation JSON */ + bibtex: `{bibtexJson}`, + }, }, };