Skip to content

Commit

Permalink
fix auto generation for js new-timeline template; add changeset
Browse files Browse the repository at this point in the history
  • Loading branch information
cherriechang committed Jan 20, 2025
1 parent 8317d5b commit f4ef2d5
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 27 deletions.
5 changes: 5 additions & 0 deletions .changeset/great-kids-sell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@jspsych/new-timeline": patch
---

This patch adds an executable to the new-timeline package so that it can be run via npx; fixes new-timeline js template to accomodate for non-jspsych-timelines uses.
3 changes: 2 additions & 1 deletion packages/new-timeline/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "0.0.1",
"description": "CLI tool for creating new jsPsych timelines",
"type": "module",
"bin": "./src/cli.js",
"files": [
"src",
"templates"
Expand All @@ -21,7 +22,7 @@
"license": "MIT",
"dependencies": {
"@inquirer/prompts": "^5.3.8",
"del": "^7.1.0",
"del": "^8.0.0",
"gulp": "^5.0.0",
"gulp-rename": "^2.0.0",
"gulp-replace": "^1.1.4",
Expand Down
16 changes: 13 additions & 3 deletions packages/new-timeline/src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,14 +201,23 @@ async function processAnswers(answers) {

function renameExampleTemplate() {
return src(`${destPath}/examples/index.html`)
.pipe(replace("{name}", answers.name))
.pipe(replace("{globalName}", globalName))
.pipe(
replace(
"{publishingComment}\n",
answers.isTimelinesRepo
? // prettier-ignore
'<!-- Once this timeline package is published, it can be loaded via\n<script src="https://unpkg.com/@jspsych-timelines/{name}"></script> -->\n'
: ""
)
)
.pipe(replace("{name}", answers.name))
.pipe(dest(`${destPath}/examples`));
}

function renameDocsTemplate() {
return src(`${destPath}/docs/docs-template.md`)
.pipe(rename(`${answers.name}.md`))
.pipe(rename(`timeline-${answers.name}.md`))
.pipe(dest(`${destPath}/docs`))
.on("end", function () {
deleteSync(`${destPath}/docs/docs-template.md`, { force: true });
Expand All @@ -228,7 +237,8 @@ async function processAnswers(answers) {
replace(
`## Loading`,
answers.isTimelinesRepo
? '## Loading\n\n### In browser\n\n```html\n<script src="https://unpkg.com/@jspsych-timelines/{name}">\n```\n\n### Via NPM\n\n```\nnpm install @jspsych-timelines/{name}\n```'
? // prettier-ignore
'## Loading\n\n### In browser\n\n```html\n<script src="https://unpkg.com/@jspsych-timelines/{name}">\n```\n\n### Via NPM\n\n```\nnpm install @jspsych-timelines/{name}\n```\n\n```js\nimport { createTimeline, timelineUnits, utils } from "@jspsych-timelines/{name}\n"```'
: `## Loading`
)
)
Expand Down
18 changes: 1 addition & 17 deletions packages/new-timeline/templates/timeline-template-js/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,9 @@

## Loading

### In browser

```html
<script src="https://unpkg.com/@jspsych-timelines/{name}">
```
### Via NPM
```
npm install @jspsych-timelines/{name}
```
```js
import { createTimeline, timelineUnits, utils } from "@jspsych-timelines/{name}"
```
## Compatibility

`@jspsych-timelines/{name}` requires jsPsych v7.0.0 or later.
`{npmPackageName}` requires jsPsych v7.0.0 or later.

## Documentation

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@

<head>
<script src="https://unpkg.com/jspsych"></script>
<!-- Once this timeline package is published, it can be loaded via
<script src="https://unpkg.com/@jspsych-timelines/{name}"></script> -->
{publishingComment}
<script src="../dist/index.global.js"></script>
<link rel="stylesheet" href="https://unpkg.com/jspsych/css/jspsych.css">
</head>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "@jspsych-timelines/{name}",
"name": "{npmPackageName}",
"version": "0.0.1",
"description": "{description}",
"unpkg": "dist/index.browser.min.js",
Expand All @@ -13,7 +13,7 @@
},
"repository": {
"type": "git",
"url": "git+https://github.com/jspsych/jspsych-timelines.git",
"url": "{gitRootUrl}",
"directory": "packages/{name}"
},
"author": {
Expand All @@ -22,9 +22,9 @@
},
"license": "MIT",
"bugs": {
"url": "https://github.com/jspsych/jspsych-timelines/issues"
"url": "{gitRootHttpsUrl}/issues"
},
"homepage": "https://github.com/jspsych/jspsych-timelines/tree/main/packages/{name}",
"homepage": "{documentationUrl}",
"devDependencies": {
"@jspsych/config": "^2.0.0",
"jspsych": "^7.0.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

<head>
<script src="https://unpkg.com/jspsych"></script>
{publishingComment}
<script src="../dist/index.global.js"></script>
<link rel="stylesheet" href="https://unpkg.com/jspsych/css/jspsych.css">
</head>
Expand Down

0 comments on commit f4ef2d5

Please sign in to comment.