Compare commits

...

9 Commits

4 changed files with 84 additions and 64 deletions
+9
View File
@@ -136,6 +136,15 @@ There are also eslint extensions / plugins for most editors.
When opening a PR, the CI runner will (once approved by a human) check the code style and eslint, as well as run all tests. You can run the same check with `pnpm check`.
## Publishing a change live on *.strudel.cc
There are a few steps to a contribution to strudel making it to https://strudel.cc/
1. If a maintainer adds a 'serve-hot' label to a pull request on codeberg, it is built and exposed as http://pr-1000.hot.strudel.cc (where 1000 is the pr number). This allows changes to be tried out live, without building locally. However, because it's plain http, some webaudio things etc won't work. A maintainer with server access can assign a certificate for https via a manual process if needed.
2. When a pull request is merged into the main branch by a maintainer, it is automatically built and served under https://hot.strudel.cc/
3. Then a maintainer can trigger an action on codeberg to rebuild https://strudel.cc/ (also known as https://warm.strudel.cc/) from the main branch. This [currently makes strudel refresh for all users](https://codeberg.org/uzu/strudel/pulls/2130), and is intended to happen around once a week, early in the week (when fewer people will be performing with it!), or more often for urgent fixes.
4. There is also https://cold.strudel.cc/, which is intended to reflect the last package release to npm.
## Package Workflow
The project is split into multiple [packages](https://codeberg.org/uzu/strudel/src/branch/main/packages) with independent versioning.
+63 -17
View File
@@ -2,20 +2,23 @@ import jsdoc from '../../../doc.json'; // doc.json is built with `npm run jsdoc-
const docs = jsdoc.docs.reduce((acc, obj) => Object.assign(acc, { [obj.longname]: obj }), {});
import { MiniRepl } from './MiniRepl';
export function JsDoc({ name, h = 3, hideDescription, punchcard, canvasHeight }) {
/**
*
* @param {Object} arguments
* @param {number} [arguments.h] Adds a heading (like 3 for h3). Deprecated, add the heading in MDX instead.
* @returns
*/
export function JsDoc({ name, h = undefined, hideDescription, punchcard, canvasHeight, hideMiniRepl }) {
const item = docs[name];
if (!item) {
console.warn('Not found: ' + name);
return <div />;
console.warn(`JsDoc for ${name} not found`);
return <div>Could not load docs for ${name}</div>;
}
const CustomHeading = `h${h}`;
const description =
item.description?.replaceAll(/\{@link ([a-zA-Z\.]+)?#?([a-zA-Z]*)\}/g, (_, a, b) => {
return `<a href="#${a.replaceAll('.', '').toLowerCase()}${b ? `-${b}` : ''}">${a}${b ? `#${b}` : ''}</a>`;
}) || '';
const CustomHeading = h ? `h${h}` : undefined;
const description = parseAndReplaceLink(item.description ?? '');
return (
<>
{!!h && <CustomHeading>{item.longname}</CustomHeading>}
{!!h && <CustomHeading id={name}>{item.longname}</CustomHeading>}
{!hideDescription && (
<>
{!!item.synonyms_text && (
@@ -26,19 +29,43 @@ export function JsDoc({ name, h = 3, hideDescription, punchcard, canvasHeight })
<div dangerouslySetInnerHTML={{ __html: description }} />
</>
)}
{item.params && item.params.length > 0 && <p className="font-bold">Arguments</p>}
<ul>
{item.params?.map((param, i) => (
<li key={i}>
{param.name} ({param.type?.names?.join('|')}): {param.description?.replace(/(<([^>]+)>)/gi, '')}
</li>
))}
{item.params?.map(({ name, type, description }, i) => {
// Check if the param is actually the parameter of an object
const objParamSeperator = name.indexOf('.');
const isObjectParam = objParamSeperator !== -1;
return (
<li key={i} className={isObjectParam ? 'list-none' : ''}>
{isObjectParam ? name.substring(objParamSeperator + 1) : name} : {type?.names?.join(' | ')}{' '}
{description ? <> - {removeHtmlTags(description)}</> : ''}
</li>
);
})}
</ul>
{item.returns && (
<p>
<span className="font-bold">Returns</span>{' '}
{item.returns
.map((returnValue) => {
const description = returnValue.description ? `- ${removeHtmlTags(returnValue.description)}` : '';
return `${returnValue.type?.names?.join(' | ')} ${description}`;
})
.join(' or ')}
</p>
)}
{item.examples?.length ? (
<div className="space-y-2">
{item.examples?.map((example, k) => (
<MiniRepl tune={example} key={k} {...{ punchcard, canvasHeight }} />
))}
{item.examples?.map((example, k) => {
const key = `${item.longname}_example_${k}`;
return hideMiniRepl ? (
<pre key={key}>{example}</pre>
) : (
<MiniRepl tune={example} key={key} {...{ punchcard, canvasHeight }} />
);
})}
</div>
) : (
<div />
@@ -46,3 +73,22 @@ export function JsDoc({ name, h = 3, hideDescription, punchcard, canvasHeight })
</>
);
}
/**
* Replaces the jsDocs link with something else.
* @param {string} string
* @param {(name:string,longname: string) => string} [replaceWith]
*/
export const parseAndReplaceLink = (string, replaceWith) => {
const jsDocsLinkRegex = /\{@link ([a-zA-Z\.#]+)\}/g;
const fun = replaceWith ?? ((name, longname) => `<a target="_blank" href="/reference#${longname}">${name}</a>`);
return string
.replaceAll(/<a href="https:\/\//g, `<a target="_blank" href="https://`)
.replaceAll(jsDocsLinkRegex, (_, longname) => {
const name = [...longname.matchAll(/[a-zA-Z]+[\.#]([a-zA-Z]+)/g)].at(0)?.at(1); //take the string after . or #
return fun(name ?? longname, longname);
});
};
const removeHtmlTags = (string) => string.replace(/(<([^>]+)>)/gi, '');
+10 -5
View File
@@ -10,11 +10,15 @@ import { loadModules, setVersionDefaultsFrom } from '../repl/util.mjs';
import Claviature from '@components/Claviature';
import useClient from '@src/useClient.mjs';
let prebaked, modulesLoading, audioReady;
if (typeof window !== 'undefined') {
prebaked = prebake();
modulesLoading = loadModules();
audioReady = initAudioOnFirstClick();
let prebaked, modulesLoading, audioReady, initicated;
export function initMiniRepl() {
if (typeof window !== 'undefined' && !initicated) {
prebaked = prebake();
modulesLoading = loadModules();
audioReady = initAudioOnFirstClick();
initicated = true;
}
}
export function MiniRepl({
@@ -44,6 +48,7 @@ export function MiniRepl({
const [activeNotes, setActiveNotes] = useState([]);
const init = useCallback(({ code, autodraw }) => {
initMiniRepl();
const drawContext = canvasId ? document.querySelector('#' + canvasId)?.getContext('2d') : getDrawContext();
const editor = new StrudelMirror({
@@ -3,6 +3,7 @@ import { memo, useEffect, useMemo, useState, Fragment } from 'react';
import jsdocJson from '../../../../../doc.json';
import { Textbox } from '@src/repl/components/panel/SettingsTab';
import { settingsMap, useSettings } from '@src/settings.mjs';
import { JsDoc } from '@src/docs/JsDoc';
import { computeAvailableFunctions } from '@src/jsDocsUtils.mjs';
const availableFunctions = computeAvailableFunctions(jsdocJson);
@@ -178,48 +179,7 @@ export const Reference = memo(function Reference() {
</span>
)}
</div>
{!!entry.synonyms_text && (
<p>
Synonyms: <code>{entry.synonyms_text}</code>
</p>
)}
<p
dangerouslySetInnerHTML={{
// If we have an external url make sure it opens in another tab to not interrupt the player
__html: entry.description.replaceAll(/<a href="https:\/\//g, `<a target="_blank" href="https://`),
}}
></p>
{entry.params && entry.params.length > 0 && <p className="font-bold">Arguments</p>}
<ul>
{entry.params?.map(({ name, type, description }, i) => {
// Check if the param is actually the parameter of an object
const objParamSeperator = name.indexOf('.');
const isObjectParam = objParamSeperator !== -1;
return (
<li key={i} className={isObjectParam ? 'list-none' : ''}>
{isObjectParam ? name.substring(objParamSeperator + 1) : name} : {type?.names?.join(' | ')}{' '}
{description ? <> - {getInnerText(description)}</> : ''}
</li>
);
})}
</ul>
{entry.returns && (
<p>
<span className="font-bold">Returns</span>{' '}
{entry.returns.map(({ type, description }) => (
<>
{type?.names?.join(' | ')} {description ? <> - {getInnerText(description)}</> : ''}
</>
))}
</p>
)}
{entry.examples?.map((example, j) => (
<pre className="bg-background border border-muted" key={j}>
{example}
</pre>
))}
<JsDoc name={entry.longname} hideMiniRepl></JsDoc>
</section>
)) || <p className="font-sans">Search or select a tag to get started.</p>}
{detailVisibleFunctions.length > 0 && <div className="h-screen" />}