Skip to content

Commit 33d8d35

Browse files
authored
Merge pull request #1198 from joshunrau/interactive-features
updates to handle tmb tasks without touching their code
2 parents 532760f + 1d5aa5c commit 33d8d35

File tree

35 files changed

+514
-672
lines changed

35 files changed

+514
-672
lines changed

.husky/commit-msg

Lines changed: 0 additions & 3 deletions
This file was deleted.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<div style="display: flex; justify-content: center; align-items: center; flex-direction: column">
2+
<h1>Instrument</h1>
3+
<img src="/smiley.png" />
4+
<button type="button" id="submit-btn">Submit</button>
5+
</div>
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/* eslint-disable perfectionist/sort-objects */
2+
3+
import { defineInstrument } from '/runtime/v1/@opendatacapture/runtime-core';
4+
import { z } from '/runtime/v1/[email protected]';
5+
6+
import html from './fragment.html';
7+
import smiley from './smiley.png';
8+
9+
export default defineInstrument({
10+
kind: 'INTERACTIVE',
11+
language: 'en',
12+
internal: {
13+
edition: 1,
14+
name: 'INTERACTIVE_WITH_STATIC_ASSETS'
15+
},
16+
tags: [],
17+
content: {
18+
render(done) {
19+
const button = document.getElementById('submit-btn')!;
20+
button.addEventListener('click', () => {
21+
done({ message });
22+
});
23+
},
24+
html,
25+
staticAssets: {
26+
'/smiley.png': smiley
27+
}
28+
},
29+
clientDetails: {
30+
estimatedDuration: 1,
31+
instructions: ['Please complete the task.']
32+
},
33+
details: {
34+
description: 'This is an example of an instrument with static assets intercepted using a service worker.',
35+
license: 'Apache-2.0',
36+
title: 'Interactive Instrument with Static Assets'
37+
},
38+
measures: {},
39+
validationSchema: z.object({
40+
message: z.string()
41+
})
42+
});
258 KB
Loading

package.json

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,6 @@
3434
"ws": "./scripts/workspace.sh $@"
3535
},
3636
"devDependencies": {
37-
"@commitlint/cli": "^19.6.1",
38-
"@commitlint/config-conventional": "^19.6.0",
39-
"@commitlint/types": "^19.5.0",
4037
"@douglasneuroinformatics/eslint-config": "^5.3.1",
4138
"@douglasneuroinformatics/prettier-config": "^0.0.2",
4239
"@douglasneuroinformatics/tsconfig": "^1.0.3",
@@ -75,11 +72,6 @@
7572
"x64",
7673
"arm64"
7774
],
78-
"commitlint": {
79-
"extends": [
80-
"@commitlint/config-conventional"
81-
]
82-
},
8375
"pnpm": {
8476
"overrides": {
8577
"@types/react": "-",

packages/instrument-bundler/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@opendatacapture/instrument-bundler",
33
"type": "module",
4-
"version": "0.0.1",
4+
"version": "0.0.0",
55
"license": "Apache-2.0",
66
"exports": {
77
".": "./src/index.ts"

packages/instrument-bundler/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ export { InstrumentBundlerError } from './error.js';
33
export { resolveIndexInput, resolveInput } from './resolve.js';
44
export type { BundleOptions, BundlerInput } from './schemas.js';
55
export type * from './types.js';
6-
export { extractInputFileExtension } from './utils.js';
6+
export { BUNDLER_FILE_EXT_REGEX, extractInputFileExtension, inferLoader } from './utils.js';

packages/instrument-bundler/src/plugin.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export const plugin = (options: { inputs: BundlerInput[] }): Plugin => {
99
name: 'instrument-bundler-plugin',
1010
setup(build) {
1111
const namespaces = { bundle: 'bundle' };
12-
const legacyScripts: string[] = [];
12+
const legacyScripts = new Map<string, string>();
1313
build.onResolve({ filter: /.*/ }, (args) => {
1414
// css @import statement
1515
if (args.kind === 'import-rule') {
@@ -56,7 +56,7 @@ export const plugin = (options: { inputs: BundlerInput[] }): Plugin => {
5656
]
5757
};
5858
}
59-
legacyScripts.push(input.content as string);
59+
legacyScripts.set(args.path, input.content as string);
6060
return { contents: input.content, loader: 'empty' };
6161
});
6262
build.onLoad({ filter: /^\/runtime\/v1\/.*.css$/, namespace: namespaces.bundle }, (args) => {
@@ -84,7 +84,14 @@ export const plugin = (options: { inputs: BundlerInput[] }): Plugin => {
8484
return { contents, loader };
8585
});
8686
build.onEnd((result) => {
87-
result.legacyScripts = legacyScripts;
87+
result.legacyScripts = [];
88+
Object.keys(result.metafile!.inputs).forEach((path) => {
89+
const script = legacyScripts.get(path.replace('bundle:', ''));
90+
if (!script) {
91+
return;
92+
}
93+
result.legacyScripts!.push(script);
94+
});
8895
});
8996
}
9097
};

packages/instrument-bundler/src/utils.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ import { InstrumentBundlerError } from './error.js';
55
import type { BundlerInputFileExtension } from './types.js';
66
import type { Loader } from './vendor/esbuild.js';
77

8+
export const BUNDLER_FILE_EXT_REGEX = /\.(css|html|jpeg|jpg|js|jsx|json|mp3|mp4|png|svg|ts|tsx|webp)$/i;
9+
810
export function extractInputFileExtension(filename: string) {
9-
const ext = /\.(css|html|jpeg|jpg|js|jsx|json|mp3|mp4|png|svg|ts|tsx|webp)$/i.exec(filename)?.[0];
11+
const ext = BUNDLER_FILE_EXT_REGEX.exec(filename)?.[0];
1012
return (ext ?? null) as BundlerInputFileExtension | null;
1113
}
1214

packages/instrument-interpreter/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
"lint": "tsc && eslint --fix src"
1212
},
1313
"dependencies": {
14-
"@opendatacapture/evaluate-instrument": "workspace:*",
1514
"@opendatacapture/runtime-core": "workspace:*",
15+
"@opendatacapture/runtime-internal": "workspace:*",
1616
"@opendatacapture/schemas": "workspace:*"
1717
},
1818
"devDependencies": {

0 commit comments

Comments
 (0)