Skip to content

Commit

Permalink
Make static-assets into a real module (#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
siefkenj authored Oct 2, 2023
1 parent 4c62320 commit af4e6cb
Show file tree
Hide file tree
Showing 12 changed files with 46,793 additions and 28 deletions.
1 change: 1 addition & 0 deletions package-lock.json

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

3 changes: 3 additions & 0 deletions packages/codemirror/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
"exports": {
".": {
"import": "./dist/index.js"
},
"./*json": {
"import": "./dist/generated/*.json"
}
},
"scripts": {
Expand Down
3 changes: 1 addition & 2 deletions packages/codemirror/src/CodeMirror.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ import {
} from "@codemirror/language";
import { completeFromSchema } from "@codemirror/lang-xml";
import { parser } from "@doenet/parser";
// @ts-ignore
import doenetSchema from "@doenet/static-assets/doenet-schema.json";
import { doenetSchema } from "@doenet/static-assets";

export function CodeMirror({
setInternalValueTo,
Expand Down
5 changes: 5 additions & 0 deletions packages/static-assets/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Static Assets for DoenetML

Some static assets are dynamically generated from source (e.g., the schema). This package
hosts those static assets and allows them to be rebuilt. JSON files are re-exported as JavaScript
files to allow for tree shaking.
7 changes: 3 additions & 4 deletions packages/static-assets/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,13 @@
"/dist"
],
"exports": {
"./*json": {
"import": "./dist/*json"
".": {
"import": "./dist/index.js"
}
},
"scripts": {
"test": "echo \"No tests \"",
"build": "npm run build:pre && npm run build:schema",
"build:pre": "rm -rf dist; mkdir dist",
"build": "vite build",
"build:schema": "vite-node ./scripts/generate-schema.ts"
}
}
2 changes: 1 addition & 1 deletion packages/static-assets/scripts/generate-schema.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as fs from "node:fs/promises";
import { getSchema } from "./get-schema";

const destUrl = new URL("../dist/doenet-schema.json", import.meta.url);
const destUrl = new URL("../src/generated/doenet-schema.json", import.meta.url);

const schema = getSchema();
console.log(
Expand Down
8 changes: 4 additions & 4 deletions packages/static-assets/scripts/get-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ export function getSchema() {
}
}

let inheritedOrAdaptedTypes: Record<string, string[]> = {};
let inheritedOrAdaptedTypes: Record<string, string | string[]> = {};

for (let type1 in componentClasses) {
let inherited = [];
let inherited: string[] = [];
for (let type2 in componentClasses) {
if (type2[0] == "_") {
continue;
Expand Down Expand Up @@ -113,10 +113,10 @@ export function getSchema() {
}
}

let elements = [];
let elements: Record<string, any>[] = [];

for (let type in componentClasses) {
let children = [];
let children: string[] = [];
let acceptsStringChildren = false;

// All components have the name and copySource attributes,
Expand Down
Loading

0 comments on commit af4e6cb

Please sign in to comment.