Skip to content

Commit

Permalink
.cff to json for plugin-ts
Browse files Browse the repository at this point in the history
  • Loading branch information
cherriechang committed Aug 24, 2024
1 parent a69d1ca commit b990290
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 0 deletions.
41 changes: 41 additions & 0 deletions templates/plugin-template-ts/CITATION.cff
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions templates/plugin-template-ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
46 changes: 46 additions & 0 deletions templates/plugin-template-ts/src/build-citation.js
Original file line number Diff line number Diff line change
@@ -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 };
6 changes: 6 additions & 0 deletions templates/plugin-template-ts/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ const info = <const>{
data2: {
type: ParameterType.STRING,
},
citation: {
/** APA citation JSON */
apa: `{apaJson}`,
/** BibTeX citation JSON */
bibtex: `{bibtexJson}`,
},
},
};

Expand Down

0 comments on commit b990290

Please sign in to comment.