Skip to content

Commit

Permalink
add contrib examples template
Browse files Browse the repository at this point in the history
  • Loading branch information
cchang-vassar committed Aug 8, 2024
1 parent de10801 commit 6e10d74
Show file tree
Hide file tree
Showing 7 changed files with 113 additions and 5 deletions.
18 changes: 13 additions & 5 deletions templates/cli/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ async function runPrompts() {
const language = await select({
message: "What language do you want to use?",
choices: [
{
name: "TypeScript",
value: "ts",
},
{
name: "JavaScript",
value: "js",
},
{
name: "TypeScript",
value: "ts",
},
],
loop: false,
});
Expand Down Expand Up @@ -125,6 +125,13 @@ async function processAnswers(answers) {
.pipe(dest(`${repoRoot}/packages/${destPath}`));
}

function renameExampleTemplate() {
return src(`${repoRoot}/packages/${destPath}/examples/index.html`)
.pipe(replace("{name}", answers.name))
.pipe(replace("{globalName}", globalName))
.pipe(dest(`${repoRoot}/packages/${destPath}/examples`));
}

function renameDocsTemplate() {
return src(`${repoRoot}/packages/${destPath}/docs/docs-template.md`)
.pipe(rename(`${answers.name}.md`))
Expand All @@ -133,7 +140,8 @@ async function processAnswers(answers) {
deleteSync(`${repoRoot}/packages/${destPath}/docs/docs-template.md`);
});
}
series(processTemplate, renameDocsTemplate)();

series(processTemplate, renameExampleTemplate, renameDocsTemplate)();
}

const answers = await runPrompts();
Expand Down
27 changes: 27 additions & 0 deletions templates/extension-template-js/examples/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>{name} Extension Example</title>
<script src="https://unpkg.com/jspsych@7.3.4"></script>
<!-- Example plugin an extension may work with -->
<script src="https://unpkg.com/@jspsych/plugin-html-keyboard-response@1.1.3"></script>
<script src="../dist/index.browser.min.js"></script>
<link href="https://unpkg.com/jspsych@7.3.4/css/jspsych.css" rel="stylesheet" />
</head>
<body>
<script>
let jsPsych = initJsPsych({
extensions: [{ type: {globalName} }],
});

let trial = {
type: jsPsychHtmlKeyboardResponse,
stimulus: "Hello world",
extensions: [{ type: {globalName} },
],
};

jsPsych.run([trial]);
</script>
</body>
</html>
File renamed without changes.
27 changes: 27 additions & 0 deletions templates/extension-template-ts/examples/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>{name} Extension Example</title>
<script src="https://unpkg.com/jspsych@7.3.4"></script>
<!-- Example plugin an extension may work with -->
<script src="https://unpkg.com/@jspsych/plugin-html-keyboard-response@1.1.3"></script>
<script src="../dist/index.browser.min.js"></script>
<link href="https://unpkg.com/jspsych@7.3.4/css/jspsych.css" rel="stylesheet" />
</head>
<body>
<script>
let jsPsych = initJsPsych({
extensions: [{ type: {globalName} }],
});

let trial = {
type: jsPsychHtmlKeyboardResponse,
stimulus: "Hello world",
extensions: [{ type: {globalName} },
],
};

jsPsych.run([trial]);
</script>
</body>
</html>
23 changes: 23 additions & 0 deletions templates/plugin-template-js/examples/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!DOCTYPE html>
<html>

<head>
<script src="https://unpkg.com/jspsych"></script>
<!-- The plugin is loaded here -->
<script src="https://unpkg.com/@jspsych/plugin-{name}"></script>
<script src="../dist/index.global.js"></script>
<link rel="stylesheet" href="https://unpkg.com/jspsych/css/jspsych.css">
</head>

<body></body>
<script>
const jsPsych = initJsPsych();

const trial = {
type: {globalName}
};

jsPsych.run([trial])
</script>

</html>
File renamed without changes.
23 changes: 23 additions & 0 deletions templates/plugin-template-ts/examples/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!DOCTYPE html>
<html>

<head>
<script src="https://unpkg.com/jspsych"></script>
<!-- The plugin is loaded here -->
<script src="https://unpkg.com/@jspsych/plugin-{name}"></script>
<script src="../dist/index.global.js"></script>
<link rel="stylesheet" href="https://unpkg.com/jspsych/css/jspsych.css">
</head>

<body></body>
<script>
const jsPsych = initJsPsych();

const trial = {
type: {globalName}
};

jsPsych.run([trial])
</script>

</html>

0 comments on commit 6e10d74

Please sign in to comment.