Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
97 commits
Select commit Hold shift + click to select a range
1e47dd2
format: prettify
raymondwjang Apr 23, 2024
0b289bc
eslint: ignore build js
raymondwjang Apr 23, 2024
3dbb422
feat: queries for schema
raymondwjang Apr 26, 2024
3bb1b62
env: add sqlite
raymondwjang Apr 26, 2024
f701259
feat: polish db schema
raymondwjang Apr 26, 2024
3e1006d
chore: gitignore
raymondwjang Apr 26, 2024
9a0b6ca
TODO: not working suddenly...
raymondwjang May 1, 2024
183398a
update dev doc
raymondwjang May 1, 2024
8aea44f
docs: add api docs on dev.md
raymondwjang May 14, 2024
ca65429
chore: add homepage url to manifest
raymondwjang May 14, 2024
d06d532
feat: init create database
raymondwjang May 15, 2024
1781374
chore: cleanup tsconfig
raymondwjang May 15, 2024
c861f43
chore: esbuild prettify
raymondwjang May 15, 2024
0ba09c0
chore: migrate to source folder
raymondwjang May 15, 2024
3de87fb
feat: global declare Zotero
raymondwjang May 15, 2024
d749f1d
feat: export functions in bootstrap (readable on Zotero!)
raymondwjang May 15, 2024
7181e82
chore: add node to gitignore
raymondwjang May 16, 2024
4745078
feat: can read global referencenetwork
raymondwjang May 16, 2024
f8c1833
chore: declutter
raymondwjang May 17, 2024
4186455
feat: learned what d.ts is for (extending types from external librari…
raymondwjang May 17, 2024
490ea22
feat: move RN declar/def to module & remove togglegreen
raymondwjang May 17, 2024
5852142
feat: deprecate unused functions from Make-It-Red
raymondwjang May 17, 2024
391f55f
temp: relax linting rules
raymondwjang May 21, 2024
45f36df
feat: add airbnb linter
raymondwjang May 21, 2024
97b847e
chore: linting
raymondwjang May 21, 2024
ee62c39
chore: ignore linting esbuild.js
raymondwjang May 21, 2024
efd2496
chore: declutter style.css and install.rdf
raymondwjang May 21, 2024
b2a1acb
chore: reorganization
raymondwjang May 21, 2024
0040d71
feat: manually add error tracing :'(
raymondwjang May 21, 2024
1ce3e70
linting: divide rules between ts and js
raymondwjang May 21, 2024
a7dce72
feat: translate sql to typeorm
raymondwjang May 23, 2024
6f560d5
env: add tslib
raymondwjang May 23, 2024
998dd8a
chore: modify tsconfig for typeorm
raymondwjang May 23, 2024
afada11
???: temporary turn of linting warnings
raymondwjang May 23, 2024
cc6f92d
feat: turn init to async
raymondwjang May 23, 2024
21aab17
feat: typeorm db gen
raymondwjang May 23, 2024
0258965
feat: ok, runs again. some of the comments in the bootstrap doesn't w…
raymondwjang May 30, 2024
83e41a1
chore: remove sql files
raymondwjang May 30, 2024
b57bb7d
TODO: How to initialize a db without bombing the bootstrap????
raymondwjang May 31, 2024
0ba8347
feat: add zotero-toolkit
raymondwjang Jun 4, 2024
930c888
TODO: Cannot figure out why using typeorm breaks bootstrap... :(
raymondwjang Jun 4, 2024
745f277
feat: can run query to make db/table/add rows with inline queries
raymondwjang Jun 4, 2024
e85bcc3
refactor: let's do UI later
raymondwjang Jun 4, 2024
0af0ede
TODO: can't import anything from typeORM. Find an alternative
raymondwjang Jun 6, 2024
be6f874
feat: remove node-fetch
raymondwjang Jun 7, 2024
75aa378
feat: move sql to .ts
raymondwjang Jun 10, 2024
ea37d90
feat: clarify entity/queries names
raymondwjang Jun 10, 2024
aac40af
feat: remove deprecate comments
raymondwjang Jun 10, 2024
d55d653
feat: port from typeorm to .ts dicts
raymondwjang Jun 10, 2024
fd8f1c9
feat: flesh out databasemanager
raymondwjang Jun 10, 2024
9da0104
feat: align entity names with tables
raymondwjang Jun 10, 2024
2e63f2b
feat: align entity names with tables
raymondwjang Jun 10, 2024
5451dc6
feat: add batch doi fetch
raymondwjang Jun 10, 2024
b7e7380
refactor: condense apimanager
raymondwjang Jun 11, 2024
1402349
refactor: condense ref-network
raymondwjang Jun 11, 2024
05fd1ff
TODO: figure out loadSubScript
raymondwjang Jun 11, 2024
75201ff
feat: revert to normal import
raymondwjang Jun 11, 2024
2f1e872
TODO: no clue what this main function does...
raymondwjang Jun 11, 2024
940887d
Merge branch 'main' into database
raymondwjang Jun 11, 2024
7918321
feat: revert to vanilla import
raymondwjang Jun 11, 2024
3e4044c
chore: declutter
raymondwjang Jun 11, 2024
969f6d3
feat: improve logging
raymondwjang Jun 12, 2024
e811c1a
feat: grab cite/citedby lists from OpenAlex
raymondwjang Jun 12, 2024
7ac97ce
feat: declutter entities
raymondwjang Jun 12, 2024
bd71ed5
feat: give structure to table creation
raymondwjang Jun 12, 2024
d9c3dd5
env: add dexie.js
raymondwjang Jun 12, 2024
06f403f
test: dexie seems to work, but it does not connect to zotero db.
raymondwjang Jun 12, 2024
7cbe4d5
chore: cleanup bundling
raymondwjang Jun 12, 2024
04f7c70
feat: cleanup ref-net.ts, begin event-driven
raymondwjang Jun 12, 2024
00cf7df
same as previous
raymondwjang Jun 12, 2024
90bc41a
feat: remove dexie and other clutteres from dbmanager
raymondwjang Jun 12, 2024
12bddd2
style: refactor esbuild.js
raymondwjang Jun 12, 2024
a2a4b8c
feat: add prefs.ts
raymondwjang Jun 12, 2024
7928a56
feat: copy pref.xhtml during build
raymondwjang Jun 12, 2024
4ce18db
feat: change name to weaver
raymondwjang Jun 13, 2024
81d24f1
feat: start building UI interactions
raymondwjang Jun 13, 2024
182d486
TODO: figure out how the preferences pane works...:/
raymondwjang Jun 13, 2024
8d3a555
chore: cleanup UI.ts
raymondwjang Jun 13, 2024
38b1b9b
feat: weaver loading with scriptloader than import
raymondwjang Jun 14, 2024
eeef301
feat: add copy directory in esbuild
raymondwjang Jun 15, 2024
a24c659
feat: switch to raw import in bootstrap
raymondwjang Jun 15, 2024
89b747a
TODO: figure out preference pane...
raymondwjang Jun 15, 2024
bc4d2eb
debug: fix typo
raymondwjang Jun 15, 2024
e64cb74
feat: condense data model
raymondwjang Jun 15, 2024
3180b59
feat: parametrize library id in query
raymondwjang Jun 15, 2024
3edc186
chore: rename apimanager methods for clarity
raymondwjang Jun 15, 2024
b269aef
feat: begin modulizing weaver functionalities
raymondwjang Jun 15, 2024
906f8e5
feat: separate install step in bootstrap
raymondwjang Jun 15, 2024
59ffe57
feat: modulize installation
raymondwjang Jun 16, 2024
7f3ec38
feat: isud for dbmanager
raymondwjang Jun 16, 2024
485485d
feat: isud for entities
raymondwjang Jun 16, 2024
7f426f6
feat: fix query
raymondwjang Jun 17, 2024
28d9a34
style: ISOD to CRUD
raymondwjang Jun 17, 2024
4ee3f21
chore: readability
raymondwjang Jun 17, 2024
282848b
feat: modulize db populate
raymondwjang Jun 17, 2024
5b96563
ARE YOU FUCKING KIDDING ME
raymondwjang Jun 17, 2024
61ce455
debug: cannot start queries with linebreak...
raymondwjang Jun 17, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
560 changes: 287 additions & 273 deletions .eslintrc.json

Large diffs are not rendered by default.

133 changes: 131 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,136 @@ cython_debug/
/data

# javascript
node_modules
.cache*
gen
xpi

# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
.pnpm-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# Snowpack dependency directory (https://snowpack.dev/)
web_modules/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional stylelint cache
.stylelintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variable files
.env
.env.development.local
.env.test.local
.env.production.local
.env.local

# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache

# Next.js build output
.next
out

# Nuxt.js build / generate output
.nuxt
dist

# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public

# vuepress build output
.vuepress/dist

# vuepress v2.x temp and cache directory
.temp
.cache

# Docusaurus cache and generated files
.docusaurus

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# TernJS port file
.tern-port

# Stores VSCode versions used for testing VSCode extensions
.vscode-test

# yarn v2
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*
30 changes: 19 additions & 11 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,27 @@
# DB Schema

- graph
- source
- type
- target
- data_source
- id
- id INTEGER PRIMARY KEY AUTOINCREMENT
- source TEXT
- type TEXT
- target TEXT
- data_source TEXT

- items
- itemID
- updated_datetime
- itemID INTEGER PRIMARY KEY
- updated_datetime DATETIME

- authors
- creatorID
- ORCID
- name
- author-item link table
- creatorID INTEGER PRIMARY KEY
- ORCID TEXT
- name TEXT

- author_item_link
- creatorID INTEGER
- itemID INTEGER
- FOREIGN KEY(creatorID) REFERENCES authors(creatorID)
- FOREIGN KEY(itemID) REFERENCES items(itemID)
- PRIMARY KEY (creatorID, itemID)

# TODOs

Expand Down
13 changes: 11 additions & 2 deletions docs/plugin/dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,21 @@

Following: https://www.zotero.org/support/dev/client_coding/plugin_development

- set the location of the plugin in the `reference-network@example.com` file to `{repo}/build/`
- set the location of the plugin in the `weaver@example.com` file to `{repo}/build/`
- (do the rest of the stuff in the above guide)
- watch and rebuild the plugin with `npm run start`
- you have to restart zotero between each change i think

To run zotero with the plugin in debug mode, run the following command:

```sh
./zotero -purgecaches -zoteroDebugText
```

Weird things:
- the build step was generating the extension id as `reference-network@gmail.com` because [`zotero-plugin/rdf` just does that for some reason](https://github.com/retorquere/zotero-plugin/blob/ab40ae4ba59d2b6a3fcce3222d415d9b5d72b14b/rdf.ts#L16)
- the build step was generating the extension id as `weaver@gmail.com` because [`zotero-plugin/rdf` just does that for some reason](https://github.com/retorquere/zotero-plugin/blob/ab40ae4ba59d2b6a3fcce3222d415d9b5d72b14b/rdf.ts#L16)
so the extension ID has to be updated in both the `package.json` file as well as the actual `manifest.json` file


Official API Documentation:
https://www.zotero.org/support/dev/client_coding/javascript_api
169 changes: 118 additions & 51 deletions esbuild.js
Original file line number Diff line number Diff line change
@@ -1,77 +1,144 @@
const path = require('path')
const fs = require('fs')
const esbuild = require('esbuild')
const rmrf = require('rimraf')
rmrf.sync('gen')

require('zotero-plugin/copy-assets')
require('zotero-plugin/rdf')
require('zotero-plugin/version')

function js(src) {
return src.replace(/[.]ts$/, '.js')
const path = require("path");
const fs = require("fs");
const esbuild = require("esbuild");
const rmrf = require("rimraf");

// Clear the 'gen' directory synchronously
rmrf.sync("gen");

// Load Zotero plugin tasks
require("zotero-plugin/copy-assets");
require("zotero-plugin/rdf");
require("zotero-plugin/version");

// Helper function to replace TypeScript file extension with JavaScript
function replaceExtToJs(src) {
return src.replace(/[.]ts$/, ".js");
}

async function copyFile(source, destination) {
await fs.promises.mkdir(path.dirname(destination), { recursive: true });
await fs.promises.copyFile(source, destination);
}

async function copyDirectory(source, destination) {
// Ensure the destination directory exists
await fs.promises.mkdir(destination, { recursive: true });

// Read all items in the source directory
const items = await fs.promises.readdir(source, { withFileTypes: true });

// Iterate through each item in the source directory
for (const item of items) {
const sourcePath = path.join(source, item.name);
const destinationPath = path.join(destination, item.name);

if (item.isDirectory()) {
// If it's a directory, recursively copy it
await copyDirectory(sourcePath, destinationPath);
} else {
// If it's a file, copy the file
await copyFile(sourcePath, destinationPath);
}
}
}

// Bundles the files with the provided configuration
async function bundle(config) {
// Default configuration enhanced with custom settings
config = {
bundle: true,
format: 'iife',
target: ['firefox60'],
format: "iife",
target: ["firefox60"],
inject: [],
treeShaking: true,
keepNames: true,
...config,
}
};

let target
if (config.outfile) {
target = config.outfile
let target = determineTarget(config);

const exportGlobals = config.exportGlobals;
delete config.exportGlobals;

if (exportGlobals) {
await handleExportGlobals(config);
}
else if (config.entryPoints.length === 1 && config.outdir) {
target = path.join(config.outdir, js(path.basename(config.entryPoints[0])))

console.log("* bundling", target);
await esbuild.build(config);

if (exportGlobals) {
await rewriteGlobals(target, config);
}
else {
target = `${config.outdir} [${config.entryPoints.map(js).join(', ')}]`
}

// Determine the target file or directory for output
function determineTarget(config) {
if (config.outfile) {
return config.outfile;
} else if (config.entryPoints.length === 1 && config.outdir) {
return path.join(
config.outdir,
replaceExtToJs(path.basename(config.entryPoints[0]))
);
} else {
return `${config.outdir} [${config.entryPoints
.map(replaceExtToJs)
.join(", ")}]`;
}
}

const exportGlobals = config.exportGlobals
delete config.exportGlobals
if (exportGlobals) {
const esm = await esbuild.build({ ...config, logLevel: 'silent', format: 'esm', metafile: true, write: false })
if (Object.values(esm.metafile.outputs).length !== 1) throw new Error('exportGlobals not supported for multiple outputs')
for (const output of Object.values(esm.metafile.outputs)) {
if (output.entryPoint) {
config.globalName = escape(`{ ${output.exports.sort().join(', ')} }`).replace(/%/g, '$')
// make these var, not const, so they get hoisted and are available in the global scope.
}
// Handle export of globals when required
async function handleExportGlobals(config) {
const esm = await esbuild.build({
...config,
logLevel: "silent",
format: "esm",
metafile: true,
write: false,
});
if (Object.values(esm.metafile.outputs).length !== 1) {
throw new Error("exportGlobals not supported for multiple outputs");
}
for (const output of Object.values(esm.metafile.outputs)) {
if (output.entryPoint) {
config.globalName = escape(
`{ ${output.exports.sort().join(", ")} }`
).replace(/%/g, "$");
}
}
}

console.log('* bundling', target)
await esbuild.build(config)
if (exportGlobals) {
await fs.promises.writeFile(
target,
(await fs.promises.readFile(target, 'utf-8')).replace(config.globalName, unescape(config.globalName.replace(/[$]/g, '%')))
)
}
// Rewrite global variable names in the output files
async function rewriteGlobals(target, config) {
const originalContent = await fs.promises.readFile(target, "utf-8");
const modifiedContent = originalContent.replace(
config.globalName,
unescape(config.globalName.replace(/[$]/g, "%"))
);
await fs.promises.writeFile(target, modifiedContent);
}

// Main build function
async function build() {
await bundle({
exportGlobals: true,
entryPoints: [ 'src/reference_network/bootstrap.ts' ],
outdir: 'build',
banner: { js: 'var Zotero;\n' },
})
entryPoints: ["src/bootstrap.ts"],
outdir: "build",
});

await bundle({
entryPoints: [ 'src/reference_network/lib.ts' ],
outdir: 'build',
})
entryPoints: ["src/weaver.ts", "src/prefs/prefs.ts"],
outdir: "build",
});

await copyFile("src/prefs/prefs.xhtml", "build/prefs/prefs.xhtml");
await copyDirectory("src/locale/", "build/locale/");
}

build().catch(err => {
console.log(err)
process.exit(1)
})
// Run build and handle any errors
build().catch((err) => {
console.log(err);
process.exit(1);
});
Loading