-
-
Notifications
You must be signed in to change notification settings - Fork 718
Generate citation strings from citation.cff file as part of build process #3385
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 39 commits
Commits
Show all changes
49 commits
Select commit
Hold shift + click to select a range
47d57f0
delete braces from root package.json
cherriechang 1c5f826
add rollup plugin for building citation
cherriechang bbd09e2
move citation rollup plugin to config folder
cherriechang 59ce0b3
very broken :(
jodeleeuw 7ca68ea
Merge branch 'main' into add-citation-module
jodeleeuw 62d3427
This fixes build errors, but warnings are still present. Adds rollup/…
jodeleeuw c8ad1db
Merge branch 'update-config-dependencies' into add-citation-module
bjoluc e7abded
Update package.json
bjoluc fd07de6
Merge branch 'update-config-dependencies' into add-citation-module
bjoluc e2039c4
pulling bjorn fixes
cherriechang d2ae26c
pulling bjorn fixes
cherriechang 715ed2a
pull bjorn fixes
cherriechang 7963fdc
move additionalPlugin out of outputOptions
cherriechang bab33ea
fix: error handling chain in building citations
cherriechang 909cb9a
fix build citation rollup plugin to actually generate citation
cherriechang bceacab
i really hate this library
cherriechang a2e7918
fix browser tool for citations
cherriechang 8bbf9b7
move citation build logic from rollup to esbuild
cherriechang 00d60fb
remove generateCitation from node scripts and directly call
cherriechang 1365dcc
just not replacing the var
cherriechang 81fd767
fix some config options
jodeleeuw eace9bf
merge with josh
cherriechang ef89a80
define works now
cherriechang 99392b4
citation stuff done
cherriechang 2cdf231
clean up dependencies
cherriechang d02f625
delete console logs
cherriechang 9d5215e
clean up errors
cherriechang f0bc8ae
add jest tests for citation tool
cherriechang 5753468
update plugins index.ts
cherriechang b63d8b6
fix double quotes in plugin src to single quotes
cherriechang df588e9
change prettier to allow single quotes
cherriechang a28ca04
localize prettier to apply only to lines
cherriechang 1b08438
citation documentation + delete CITATION.cff files
cherriechang 5e878d3
update getCitations() to always print jsPsych + no duplicates; update…
cherriechang e42ba99
modifiy citation test to check for built version
jodeleeuw f2d1a03
fix citation logic
cherriechang 466b44c
Merge branch 'add-citation-module' of github.com:jspsych/jsPsych into…
cherriechang 5b64a47
change citations test to include default jspsych citation
cherriechang 81e7473
add prettier-ignore to jspsych.ts
cherriechang 909ac91
update docs
cherriechang ca6c4eb
add docstring in JsPsych.ts for getCitations()
cherriechang 90ee2c5
add prettier-ignore for IIFE builds
cherriechang f364931
change contributing.md
cherriechang f8e454e
delete console spies and mocks
cherriechang 8ffe64a
add changeset
cherriechang 3948fdc
add changeset
cherriechang 5611b3c
remove the overrides
jodeleeuw 4834c96
add getCitations() doc in jspsych.md under reference; delete extra ch…
cherriechang faf6cce
Merge branch 'add-citation-module' of github.com:jspsych/jsPsych into…
cherriechang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,3 +11,4 @@ coverage/ | |
dist.zip | ||
packages/jspsych/README.md | ||
.turbo | ||
.env |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import "@citation-js/plugin-bibtex"; | ||
import "@citation-js/plugin-software-formats"; | ||
import "@citation-js/plugin-csl"; | ||
|
||
import fs from "node:fs"; | ||
import path from "node:path"; | ||
|
||
import { Cite } from "@citation-js/core"; | ||
import appRootPath from "app-root-path"; | ||
import yaml from "yaml"; | ||
|
||
/** | ||
* Generate citation data from CITATION.cff file | ||
* Currently supported formats: APA, BibTeX | ||
* | ||
* @returns {Object} - Object containing APA and BibTeX formatted citation data | ||
*/ | ||
export default function generateCitations() { | ||
let preferredCitation = false; | ||
|
||
// Try to find CITATION.cff file and look for preferred-citation | ||
const citationCff = (() => { | ||
let rawCff; | ||
const getCff = (path) => { | ||
rawCff = fs.readFileSync(path, "utf-8").toString(); | ||
const cffData = yaml.parse(rawCff); | ||
if (cffData["preferred-citation"]) { | ||
preferredCitation = true; | ||
} | ||
return yaml.stringify(rawCff); | ||
}; | ||
|
||
try { | ||
// look for CITATION.cff in the current directory | ||
return getCff("./CITATION.cff"); | ||
} catch (error) { | ||
try { | ||
// look for CITATION.cff in the root of the repository | ||
return getCff(path.join(appRootPath.path, "CITATION.cff")); | ||
} catch (error) { | ||
console.warn( | ||
`No CITATION.cff file found: ${error.message}. If you would like to include a citation, please create a CITATION.cff file in the root of your repository.` | ||
); | ||
return null; | ||
} | ||
} | ||
})(); | ||
|
||
if (!citationCff) { | ||
return { apa: "", bibtex: "" }; | ||
} | ||
|
||
// Convert CITATION.cff to APA string | ||
const citationApa = (() => { | ||
try { | ||
const apaCite = new Cite(citationCff); | ||
apaCite["data"] = preferredCitation ? apaCite["data"].slice(1) : apaCite["data"]; | ||
const citationApa = apaCite.format("bibliography", { | ||
format: "text", | ||
template: "apa", | ||
lang: "en-us", | ||
}); | ||
return citationApa; | ||
} catch (error) { | ||
console.log(`Error converting CITATION.cff to APA string: ${error.message}`); | ||
return ""; | ||
} | ||
})(); | ||
|
||
// Convert CITATION.cff to BibTeX string | ||
const citationBibtex = (() => { | ||
try { | ||
const bibtexCite = new Cite(citationCff); | ||
bibtexCite["data"] = preferredCitation ? bibtexCite["data"].slice(1) : bibtexCite["data"]; | ||
const citationBibtex = bibtexCite.format("bibtex", { | ||
format: "text", | ||
template: "bibtex", | ||
lang: "en-us", | ||
}); | ||
return citationBibtex; | ||
} catch (error) { | ||
console.log(`Error converting CITATION.cff to BibTeX string: ${error.message}`); | ||
return null; | ||
} | ||
})(); | ||
|
||
// Return formatted citation data | ||
const citationData = { | ||
apa: citationApa.replace(/\n/g, " "), | ||
bibtex: citationBibtex.replace(/\n/g, " "), | ||
}; | ||
|
||
return citationData; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.