Skip to content

Commit c09d77f

Browse files
committed
initial structure
1 parent 191d781 commit c09d77f

10 files changed

Lines changed: 5240 additions & 2 deletions

File tree

.eslintrc.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
root: true
2+
extends: 'semistandard'
3+
ignorePatterns: ['dist/*']

dist/bundle.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package-lock.json

Lines changed: 5131 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@
44
"description": "Health Data Safe - Library",
55
"main": "src/index.js",
66
"scripts": {
7-
"test": "echo \"Error: no test specified\" && exit 1"
7+
"test": "mocha tests --test-reporter=spec",
8+
"build": "webpack",
9+
"lint": "eslint .",
10+
"lint:fix": "eslint . --fix",
11+
"lint:change": "eslint $(git diff --name-only HEAD | grep -E '\\.(js|jsx)$' | xargs)"
812
},
913
"repository": {
1014
"type": "git",
@@ -21,5 +25,16 @@
2125
"bugs": {
2226
"url": "https://github.com/healthdatasafe/hds-lib-js/issues"
2327
},
24-
"homepage": "https://github.com/healthdatasafe/hds-lib-js#readme"
28+
"homepage": "https://github.com/healthdatasafe/hds-lib-js#readme",
29+
"devDependencies": {
30+
"eslint": "^8.57.0",
31+
"eslint-config-semistandard": "^17.0.0",
32+
"eslint-config-standard": "^17.1.0",
33+
"eslint-plugin-import": "^2.29.1",
34+
"eslint-plugin-n": "^15.7.0",
35+
"eslint-plugin-promise": "^6.1.1",
36+
"mocha": "^11.5.0",
37+
"webpack": "^5.99.9",
38+
"webpack-cli": "^6.0.1"
39+
}
2540
}

scripts/pre-commit

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash
2+
set -e
3+
4+
## Will be added to git hooks to make sure
5+
## we don't commit not linted code
6+
npm run lint:change

scripts/setup-dev-env.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/bin/bash
2+
set -e
3+
4+
# Sets up the dev environment on a MacOS or GNU/Linux system
5+
6+
# working dir fix
7+
SCRIPT_FOLDER=$(cd $(dirname "$0"); pwd)
8+
cd $SCRIPT_FOLDER/.. # root
9+
10+
# setup git pre-commit hook if appropriate ($CI is "true" in GitHub workflows)
11+
PRE_COMMIT="scripts/pre-commit"
12+
if [[ -d .git && "$CI" != "true" ]]; then
13+
cp $PRE_COMMIT .git/hooks/
14+
echo ""
15+
echo "Git pre-commit hook setup from '$PRE_COMMIT'"
16+
echo ""
17+
fi
18+
19+
20+
echo ""
21+
echo "Setup Dev env complete!"
22+
echo ""

src/HDSModel.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
class HDSModel {
2+
/**
3+
* JSON definition file
4+
* Should come from service/info assets.hds-model
5+
* @type {string}
6+
*/
7+
#modelUrl;
8+
9+
/**
10+
* Content on model definitions
11+
* @type {object}
12+
*/
13+
#modelData;
14+
15+
/**
16+
* JSON definition file
17+
* Should come from service/info assets.hds-model
18+
* @type {string}
19+
*/
20+
constructor (modelUrl) {
21+
this.#modelUrl = modelUrl;
22+
}
23+
24+
/**
25+
* Load model definitions
26+
*/
27+
async load () {
28+
const response = await fetch(this.#modelUrl);
29+
const resultText = await response.text();
30+
const result = JSON.parse(resultText);
31+
this.#modelData = result;
32+
}
33+
}
34+
35+
module.exports = HDSModel;

src/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
HDSModel: require('./HDSModel')
3+
};

tests/hdsModel.test.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/* eslint-env mocha */
2+
3+
const modelURL = 'https://model.datasafe.dev/pack.json';
4+
5+
const { HDSModel } = require('../');
6+
7+
describe('[MODX] Model', () => {
8+
it('[MODL] Load model', async () => {
9+
const model = new HDSModel(modelURL);
10+
await model.load();
11+
});
12+
});

webpack.config.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
const path = require('path');
2+
3+
module.exports = {
4+
entry: './src/index.js',
5+
mode: 'production',
6+
output: {
7+
path: path.resolve(__dirname, 'dist'),
8+
filename: 'hds-lib.js'
9+
}
10+
};

0 commit comments

Comments
 (0)