From b99029036ac0426ac483a2e52dcc8a34fd5a63b2 Mon Sep 17 00:00:00 2001 From: cchang-vassar <79338042+cchang-vassar@users.noreply.github.com> Date: Sat, 24 Aug 2024 14:17:31 -0400 Subject: [PATCH] .cff to json for plugin-ts --- templates/plugin-template-ts/CITATION.cff | 41 +++++++++++++++++ templates/plugin-template-ts/package.json | 6 +++ .../plugin-template-ts/src/build-citation.js | 46 +++++++++++++++++++ templates/plugin-template-ts/src/index.ts | 6 +++ 4 files changed, 99 insertions(+) create mode 100644 templates/plugin-template-ts/CITATION.cff create mode 100644 templates/plugin-template-ts/src/build-citation.js diff --git a/templates/plugin-template-ts/CITATION.cff b/templates/plugin-template-ts/CITATION.cff new file mode 100644 index 00000000..9ff27fdd --- /dev/null +++ b/templates/plugin-template-ts/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-ts/package.json b/templates/plugin-template-ts/package.json index a23a450b..afb7d7a6 100644 --- a/templates/plugin-template-ts/package.json +++ b/templates/plugin-template-ts/package.json @@ -36,6 +36,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" + }, "peerDependencies": { "jspsych": ">=7.0.0" }, diff --git a/templates/plugin-template-ts/src/build-citation.js b/templates/plugin-template-ts/src/build-citation.js new file mode 100644 index 00000000..1bb853c3 --- /dev/null +++ b/templates/plugin-template-ts/src/build-citation.js @@ -0,0 +1,46 @@ +import "@citation-js/plugin-software-formats"; + +import fs from "node:fs"; +import { fileURLToPath } from "node:url"; +import path from "path"; + +import { Cite } from "@citation-js/core"; + +const srcDir = path.dirname(fileURLToPath(import.meta.url)); +const indexFilePath = path.join(srcDir, "index.ts"); + +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); + }); +} + +export { cffToJson, updateCitations }; diff --git a/templates/plugin-template-ts/src/index.ts b/templates/plugin-template-ts/src/index.ts index b2396d68..82676176 100644 --- a/templates/plugin-template-ts/src/index.ts +++ b/templates/plugin-template-ts/src/index.ts @@ -26,6 +26,12 @@ const info = { data2: { type: ParameterType.STRING, }, + citation: { + /** APA citation JSON */ + apa: `{apaJson}`, + /** BibTeX citation JSON */ + bibtex: `{bibtexJson}`, + }, }, };