Skip to content

Commit

Permalink
Merge pull request #128 from jspsych/gulp-api-to-private-task
Browse files Browse the repository at this point in the history
Gulp api to private task, update cli code
  • Loading branch information
cherriechang authored Aug 8, 2024
2 parents fec90eb + 4dacb61 commit 447e88e
Show file tree
Hide file tree
Showing 7 changed files with 119 additions and 7 deletions.
26 changes: 19 additions & 7 deletions templates/cli/src/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import fs from "node:fs";
import path, { format } from "node:path";
import path from "node:path";
import { fileURLToPath } from "node:url";

import { input, select } from "@inquirer/prompts";
Expand Down Expand Up @@ -56,29 +56,33 @@ async function runPrompts() {
});

const name = await input({
message: "What do you want to call this package?",
message: `What do you want to call this ${type == "plugin" ? "plugin" : "extension"} package?`,
required: true,
transformer: (input) => {
// convert to hyphen case
return formatName(input);
},
validate: (input) => {
const fullDestPath = `${repoRoot}/packages/${type}-${input}`;
const fullDestPath = `${repoRoot}/packages/${type}-${formatName(input)}`;
if (fs.existsSync(fullDestPath)) {
return "A package with this name already exists. Please choose a different name.";
return `A ${
type == "plugin" ? "plugin" : "extension"
} package with this name already exists. Please choose a different name.`;
} else {
return true;
}
},
});

const description = await input({
message: "Enter a brief description of the package",
message: `Enter a brief description of the ${
type == "plugin" ? "plugin" : "extension"
} package.`,
required: true,
});

const author = await input({
message: "Who is the author of this package?",
message: `Who is the author of this ${type == "plugin" ? "plugin" : "extension"} package?`,
required: true,
});

Expand Down Expand Up @@ -121,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 @@ -129,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/[email protected]"></script>
<!-- Example plugin an extension may work with -->
<script src="https://unpkg.com/@jspsych/[email protected]"></script>
<script src="../dist/index.browser.min.js"></script>
<link href="https://unpkg.com/[email protected]/css/jspsych.css" rel="stylesheet" />
</head>
<body>
<script>
const jsPsych = initJsPsych({
extensions: [{ type: {globalName} }],
});

const 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/[email protected]"></script>
<!-- Example plugin an extension may work with -->
<script src="https://unpkg.com/@jspsych/[email protected]"></script>
<script src="../dist/index.browser.min.js"></script>
<link href="https://unpkg.com/[email protected]/css/jspsych.css" rel="stylesheet" />
</head>
<body>
<script>
const jsPsych = initJsPsych({
extensions: [{ type: {globalName} }],
});

const 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 447e88e

Please sign in to comment.