Skip to content

Commit

Permalink
Merge pull request #6 from GuiLeme/h5p-dynamically-set
Browse files Browse the repository at this point in the history
feat: Add possibility to set h5p.json dynamically as a string
  • Loading branch information
TiagoJacobs authored Jul 24, 2024
2 parents 6adacea + 6779592 commit 5d9e883
Show file tree
Hide file tree
Showing 11 changed files with 1,773 additions and 1,551 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:

strategy:
matrix:
node: [ 14, 16, 18 ]
node: [ 18, 20, 22 ]

steps:
- name: Checkout
Expand Down
11 changes: 11 additions & 0 deletions cypress.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { defineConfig } from 'cypress'

export default defineConfig({
e2e: {
// We've imported your old cypress plugins here.
// You may want to clean this up later by importing these.
setupNodeEvents(on, config) {
return require('./cypress/plugins/index.js')(on, config)
},
},
})
1 change: 0 additions & 1 deletion cypress.json

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
18 changes: 14 additions & 4 deletions src/h5p-standalone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ interface Options {
librariesPath?: string;
contentJsonPath?: string;
contentAsJson?: string;
h5pAsJson?: string;

frame?: boolean;
copyright?: boolean;
Expand Down Expand Up @@ -201,12 +202,21 @@ export class H5PStandalone {
/**
* Load H5P content and libraries
*/
const { contentAsJson } = options
const { contentAsJson, h5pAsJson } = options;
const {h5pJsonPath, contentJsonPath, librariesPath} = this.getH5PPaths(options);

const H5PJsonContent = <H5PPackageDefinition>(await getJSON(`${h5pJsonPath}/h5p.json`, options?.assetsRequestFetchOptions).catch((e) => {
console.log('Error while trying to fetch h5p json content: ', e, `${h5pJsonPath}/h5p.json`, options?.assetsRequestFetchOptions)
}));
let H5PJsonContent;
if (h5pAsJson) {
try {
H5PJsonContent = JSON.parse(h5pAsJson);
} catch (e) {
throw new Error(`Structure of h5pAsJson is not a valid json. ${e}`);
}
} else {
H5PJsonContent = <H5PPackageDefinition>(await getJSON(`${h5pJsonPath}/h5p.json`, options?.assetsRequestFetchOptions).catch((e) => {
console.log('Error while trying to fetch h5p json content: ', e, `${h5pJsonPath}/h5p.json`, options?.assetsRequestFetchOptions)
}));
}

//populate the variable before executing other functions.We assume other dependent
// libraries follow the same format rather than performing the check for each library
Expand Down
3,292 changes: 1,747 additions & 1,545 deletions yarn.lock

Large diffs are not rendered by default.

0 comments on commit 5d9e883

Please sign in to comment.