-
-
Notifications
You must be signed in to change notification settings - Fork 668
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
add rollup plugin for building citation #3385
Open
cchang-vassar
wants to merge
17
commits into
update-config-dependencies
Choose a base branch
from
add-citation-module
base: update-config-dependencies
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+3,121
−3,236
Open
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
47d57f0
delete braces from root package.json
cchang-vassar 1c5f826
add rollup plugin for building citation
cchang-vassar bbd09e2
move citation rollup plugin to config folder
cchang-vassar 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
cchang-vassar d2ae26c
pulling bjorn fixes
cchang-vassar 715ed2a
pull bjorn fixes
cchang-vassar 7963fdc
move additionalPlugin out of outputOptions
cchang-vassar bab33ea
fix: error handling chain in building citations
cchang-vassar 909cb9a
fix build citation rollup plugin to actually generate citation
cchang-vassar bceacab
i really hate this library
cchang-vassar a2e7918
fix browser tool for citations
cchang-vassar 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
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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 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 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,98 @@ | ||
import "@citation-js/plugin-bibtex"; | ||
import "@citation-js/plugin-software-formats"; | ||
import "@citation-js/plugin-csl"; | ||
|
||
import fs from "node:fs"; | ||
import { extname } from "path"; | ||
|
||
import { Cite } from "@citation-js/core"; | ||
import { createFilter } from "@rollup/pluginutils"; | ||
import MagicString from "magic-string"; | ||
import yaml from "yaml"; | ||
|
||
export default function cffToJsonPlugin() { | ||
const options = { include: ["**/index*"], exclude: [], sourcemap: false }; | ||
let filter = createFilter(options.include, options.exclude); | ||
|
||
return { | ||
name: "rollup-plugin-cff-to-json", | ||
version: "1.0.0", | ||
transform: function (code, id) { | ||
if (!filter(id) || (extname(id) !== ".js" && extname(id) !== ".ts")) return; | ||
const magicString = new MagicString(code); | ||
let preferredCitation = false; | ||
|
||
// Try to find CITATION.cff file and look for preferred-citation | ||
const citationCff = (() => { | ||
try { | ||
const rawCff = fs.readFileSync("./CITATION.cff", "utf-8").toString(); | ||
const cffData = yaml.parse(rawCff); | ||
if (cffData["preferred-citation"]) { | ||
console.log("Found 'preferred-citation' in CITATION.cff"); | ||
preferredCitation = true; | ||
} else { | ||
console.log("No 'preferred-citation' found in CITATION.cff"); | ||
} | ||
return yaml.stringify(rawCff); | ||
} catch (error) { | ||
console.log(`Error finding CITATION.cff: ${error.message}`); | ||
return null; | ||
} | ||
})(); | ||
|
||
// Try to 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 null; | ||
} | ||
})(); | ||
|
||
// Try to 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; | ||
} | ||
})(); | ||
|
||
// Replace target string with citation APA and bibtex strings | ||
if (!citationApa && !citationBibtex) { | ||
return { code: code }; | ||
} | ||
//console.log(`citation: {\napa: "${citationApa.replace(/\n/g, ' ')}", \nbibtex: "${citationBibtex.replace(/\n/g, ' ')}"\n}`); | ||
const citationString = `citation:\n { apa: "${citationApa.replace( | ||
/\n/g, | ||
" " | ||
)}",\n bibtex: "${citationBibtex.replace(/\n/g, " ")}"\n }`; | ||
console.log(citationString); | ||
const targetString = "citation: []"; | ||
const startIndex = code.indexOf(targetString); | ||
if (startIndex !== -1) { | ||
magicString.overwrite(startIndex, startIndex + targetString.length, citationString); | ||
return { code: magicString.toString() }; | ||
} else { | ||
this.error(`Error replacing citation string in ${id}`); | ||
return { code: code }; | ||
} | ||
}, | ||
}; | ||
} |
This file contains 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 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 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,47 @@ | ||
cff-version: "1.2.0" | ||
authors: | ||
- family-names: Leeuw | ||
given-names: Joshua R. | ||
name-particle: de | ||
orcid: "https://orcid.org/0000-0003-4815-2364" | ||
- family-names: Gilbert | ||
given-names: Rebecca A. | ||
orcid: "https://orcid.org/0000-0003-4574-7792" | ||
- family-names: Luchterhandt | ||
given-names: Björn | ||
orcid: "https://orcid.org/0000-0002-9225-2787" | ||
contact: | ||
- family-names: Leeuw | ||
given-names: Joshua R. | ||
name-particle: de | ||
orcid: "https://orcid.org/0000-0003-4815-2364" | ||
doi: 10.5281/zenodo.7702307 | ||
message: If you use this software, please cite our article in the | ||
Journal of Open Source Software. | ||
preferred-citation: | ||
authors: | ||
- family-names: Leeuw | ||
given-names: Joshua R. | ||
name-particle: de | ||
orcid: "https://orcid.org/0000-0003-4815-2364" | ||
- family-names: Gilbert | ||
given-names: Rebecca A. | ||
orcid: "https://orcid.org/0000-0003-4574-7792" | ||
- family-names: Luchterhandt | ||
given-names: Björn | ||
orcid: "https://orcid.org/0000-0002-9225-2787" | ||
date-published: 2023-05-11 | ||
doi: 10.21105/joss.05351 | ||
issn: 2475-9066 | ||
issue: 85 | ||
journal: Journal of Open Source Software | ||
publisher: | ||
name: Open Journals | ||
start: 5351 | ||
title: "jsPsych: Enabling an Open-Source Collaborative Ecosystem of | ||
Behavioral Experiments" | ||
type: article | ||
url: "https://joss.theoj.org/papers/10.21105/joss.05351" | ||
volume: 8 | ||
title: "jsPsych: Enabling an Open-Source Collaborative Ecosystem of | ||
Behavioral Experiments" |
This file contains 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 |
---|---|---|
|
@@ -80,6 +80,7 @@ const info = <const>{ | |
type: ParameterType.STRING, | ||
}, | ||
}, | ||
citation: [], | ||
}; | ||
|
||
type Info = typeof info; | ||
|
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When I last checked a few months ago, NPM did only respect overrides defined in the root
package.json
. Did that change in a recent NPM version? If so, we still can't rely on it until we require the new version...