Skip to content

Commit

Permalink
Merge pull request #65 from eyereasoner/feat/dynamic-imports
Browse files Browse the repository at this point in the history
feat: produce dynamic imports
  • Loading branch information
jeswr authored Jan 25, 2023
2 parents 582ee88 + 5877d80 commit 34140d9
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 2 deletions.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,22 @@ Github also serves these files with a `gzip` content encoding which compresses t

![](./github-transfer.png)

### Dynamic imports

We also distribute bundles that can be dynamically imported on github pages; for example
```ts
const { eyereasoner } = await import('https://eyereasoner.github.io/eye-js/2/latest/index.js');

// Instantiate a new SWIPL module and log any results it produces to the console
const Module = await eyereasoner.SwiplEye({ print: (str: string) => { console.log(str) }, arguments: ['-q'] });

// Load the the strings data and query as files data.n3 and query.n3 into the module
Module.FS.writeFile('data.n3', data);
Module.FS.writeFile('query.n3', query);

// Execute main(['--nope', '--quiet', './data.n3', '--query', './query.n3']).
eyereasoner.queryOnce(Module, 'main', ['--nope', '--quiet', './data.n3', '--query', './query.n3']);
```
## Examples

We provide some examples of using `eyereasoner`:
Expand Down
21 changes: 21 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
"devDependencies": {
"@qiwi/semantic-release-gh-pages-plugin": "^5.2.4",
"@rollup/plugin-commonjs": "^24.0.1",
"@types/fs-extra": "^11.0.1",
"@types/jest": "^29.2.6",
"@types/n3": "^1.10.4",
"@typescript-eslint/eslint-plugin": "^5.48.2",
Expand All @@ -63,6 +64,7 @@
"eslint": "^8.32.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-plugin-import": "^2.27.5",
"fs-extra": "^11.1.0",
"jest": "^29.3.1",
"jest-environment-jsdom": "^29.3.1",
"jest-rdf": "^1.8.0",
Expand Down
13 changes: 11 additions & 2 deletions scripts/post-webpack.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
import fs from 'fs';
/* eslint-disable import/no-extraneous-dependencies */
import fs from 'fs-extra';
import path from 'path';

let version = process.argv.find((name) => name.startsWith('--name='))?.slice(8).split('.');

if (version) {
version = ['bundle', ...version];

fs.writeFileSync(
path.join(__dirname, '..', ...version, 'dynamic-import.js'),
fs.readFileSync(
path.join(__dirname, '..', ...version, 'index.js'),
).toString().replace('var eyereasoner;', 'export var eyereasoner;'),
);

for (let i = 1; i < version.length; i += 1) {
const destDir = path.join(__dirname, '..', ...version.slice(0, i), 'latest');

if (!fs.existsSync(destDir)) {
fs.mkdirSync(destDir, { recursive: true });
}
fs.copyFileSync(path.join(__dirname, '..', ...version, 'index.js'), path.join(destDir, 'index.js'));
fs.copySync(path.join(__dirname, '..', ...version), destDir);
}
}

0 comments on commit 34140d9

Please sign in to comment.