Skip to content

Commit fd3bcfe

Browse files
committed
merge main into teach
2 parents 424b380 + ded715d commit fd3bcfe

File tree

116 files changed

+36978
-17622
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

116 files changed

+36978
-17622
lines changed

.github/workflows/test.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
2+
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
3+
4+
name: Node.js CI
5+
6+
on:
7+
push:
8+
branches: [ main ]
9+
pull_request:
10+
branches: [ main ]
11+
12+
jobs:
13+
test:
14+
15+
runs-on: ubuntu-latest
16+
17+
strategy:
18+
matrix:
19+
node-version: [14.x]
20+
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
21+
22+
steps:
23+
- uses: actions/checkout@v2
24+
- name: Use Node.js ${{ matrix.node-version }}
25+
uses: actions/setup-node@v1
26+
with:
27+
node-version: ${{ matrix.node-version }}
28+
- run: npm ci
29+
- run: npm test
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Update p5.js documentation
2+
3+
on:
4+
# This workflow is triggered by the p5.js repo on every new release.
5+
repository_dispatch
6+
env:
7+
# These are the tag name and the commit sha of the p5.js release.
8+
P5JS_REF: ${{github.event.client_payload.ref}}
9+
P5JS_SHA: ${{github.event.client_payload.sha}}
10+
11+
jobs:
12+
build:
13+
name: Update p5.js documentation
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- name: Clone repository
18+
uses: actions/checkout@v1
19+
- name: Install Node.JS 12.x
20+
uses: actions/setup-node@v1
21+
with:
22+
node-version: 12.x
23+
- name: Extract documentation from the p5.js repo
24+
run: |
25+
npm install
26+
npm run grunt update-enJSON
27+
- name: Get p5.js release info
28+
id: p5js
29+
run: |
30+
echo ::set-output name=VERSION::${P5JS_REF/refs\/tags\//}
31+
echo ::set-output name=SHA::${P5JS_SHA}
32+
- name: Commit changes
33+
uses: EndBug/add-and-commit@v4
34+
with:
35+
message: 'Update Reference files for p5.js ${{ steps.p5js.outputs.VERSION }} release (${{ steps.p5js.outputs.SHA }})'
36+
env:
37+
GITHUB_TOKEN: ${{ secrets.DOCS_COMMIT_TOKEN }}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: Update i18n files
2+
3+
on:
4+
push:
5+
paths:
6+
- 'src/data/reference/*.json'
7+
- 'src/data/*.yml'
8+
9+
jobs:
10+
build:
11+
name: Update i18n files
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- name: Clone repository
16+
uses: actions/checkout@v1
17+
- name: Install Node.JS 12.x
18+
uses: actions/setup-node@v1
19+
with:
20+
node-version: 12.x
21+
- name: npm install
22+
run: npm install
23+
- name: Update json files
24+
run: |
25+
npm run grunt update-json-i18n-files
26+
- name: Update yaml files
27+
run: |
28+
npm run grunt update-yaml-i18n-files
29+
- name: Commit changes
30+
uses: EndBug/add-and-commit@v4
31+
with:
32+
message: 'Automatic update of translation files (${{ github.sha }})'
33+
env:
34+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Gruntfile.js

Lines changed: 89 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,12 @@
88

99
const yaml = require('js-yaml');
1010
const fs = require('fs').promises;
11+
const fse = require('fs-extra');
12+
const git = require('simple-git');
1113
const pkg = require('./package.json');
14+
const update_i18n = require('./updatei18nFiles.js');
15+
const mozjpeg = require('imagemin-mozjpeg');
16+
const pngquant = require('imagemin-pngquant');
1217

1318
module.exports = function(grunt) {
1419
require('time-grunt')(grunt);
@@ -148,7 +153,8 @@ module.exports = function(grunt) {
148153
imagemin: {
149154
images: {
150155
options: {
151-
optimizationLevel: 2
156+
optimizationLevel: 2,
157+
use: [mozjpeg({quality: 70}), pngquant()] //plugins for jpeg & png image compression
152158
},
153159
files: [{
154160
expand: true,
@@ -167,8 +173,8 @@ module.exports = function(grunt) {
167173
dist: {
168174
src: [
169175
'<%= config.src %>/assets/css/normalize.css',
170-
'<%= config.src %>/assets/css/main.css',
171-
'<%= config.src %>/assets/css/prism.css'
176+
'<%= config.src %>/assets/css/prism.css',
177+
'<%= config.src %>/assets/css/main.css'
172178
],
173179
dest: '<%= config.dist %>/assets/css/all.css'
174180
}
@@ -347,10 +353,21 @@ module.exports = function(grunt) {
347353
ignore: [
348354
/^This document appears to be written in English/,
349355
/^Bad value https:/,
350-
/^Consider adding a lang attribute to the html/
356+
/^Consider adding a lang attribute to the html/,
357+
/^Attribute paypalexpress not allowed on element script at this point./
351358
]
352359
}
353360
}
361+
},
362+
shell: {
363+
generate_dataJSON: {
364+
command: 'npm ci && npm run grunt yui',
365+
options: {
366+
execOptions: {
367+
cwd: 'tmp/p5.js'
368+
}
369+
}
370+
}
354371
}
355372
});
356373

@@ -371,13 +388,80 @@ module.exports = function(grunt) {
371388
});
372389
});
373390

391+
// runs the updateJSON() function from update18nFiles.js
392+
// is run by the update-translation-files workflow every time one of them is modified
393+
grunt.registerTask('update-json-i18n-files', function() {
394+
const JSONfiles_URL = 'src/data/reference/';
395+
const lang = pkg.languages.filter(v => v !== 'en');
396+
lang.forEach(langCode => {
397+
update_i18n.updateJSON(
398+
JSONfiles_URL + 'en.json',
399+
JSONfiles_URL + langCode + '.json'
400+
);
401+
});
402+
});
403+
404+
// runs the updateYAML() function from update18nFiles.js
405+
// is run by the update-translation-files workflow every time one of them is modified
406+
grunt.registerTask('update-yaml-i18n-files', function() {
407+
const YAMLfiles_URL = 'src/data/';
408+
const lang = pkg.languages.filter(v => v !== 'en');
409+
lang.forEach(langCode => {
410+
update_i18n.updateYAML(
411+
YAMLfiles_URL + 'en.yml',
412+
YAMLfiles_URL + langCode + '.yml'
413+
);
414+
});
415+
});
416+
374417
grunt.loadNpmTasks('grunt-exec');
375418
grunt.loadNpmTasks('grunt-assemble');
376419
grunt.loadNpmTasks('grunt-file-append');
377420
grunt.loadNpmTasks('grunt-contrib-compress');
378421
grunt.loadNpmTasks('grunt-contrib-requirejs');
379422
grunt.loadNpmTasks('grunt-html');
380423

424+
grunt.registerTask('make_tmp_dir', function() {
425+
const tmp_path = 'tmp/p5.js';
426+
fse.mkdirpSync(tmp_path);
427+
});
428+
429+
grunt.registerTask('clone_p5js_repo', async function() {
430+
const done = this.async();
431+
try {
432+
await git().clone('https://github.com/processing/p5.js', 'tmp/p5.js');
433+
done();
434+
} catch (err) {
435+
console.log('Failed to clone p5.js repository.');
436+
throw new Error(err);
437+
}
438+
});
439+
440+
grunt.registerTask('generate_dataJSON', ['shell:generate_dataJSON']);
441+
442+
grunt.registerTask('move_dataJSON', function() {
443+
const dataJSON_p5js = 'tmp/p5.js/docs/reference/data.json';
444+
const dataJSON_p5jswebsite = 'src/templates/pages/reference/data.json';
445+
// move the data.json from the cloned p5.js repository to the p5.js-website repository
446+
fse.moveSync(dataJSON_p5js, dataJSON_p5jswebsite, { overwrite: true });
447+
// delete the tmp folder that contained the p5.js repository
448+
fse.removeSync('tmp/');
449+
});
450+
451+
grunt.registerTask('generate_enJSON', function() {
452+
const getenJSON = require('./getenJSON.js');
453+
// generate and save the en.json
454+
getenJSON();
455+
});
456+
457+
grunt.registerTask('update-enJSON', [
458+
'make_tmp_dir',
459+
'clone_p5js_repo',
460+
'generate_dataJSON',
461+
'move_dataJSON',
462+
'generate_enJSON'
463+
]);
464+
381465
// multi-tasks: collections of other tasks
382466
grunt.registerTask('server', [
383467
'build',
@@ -421,4 +505,4 @@ module.exports = function(grunt) {
421505

422506
// runs with just grunt command
423507
grunt.registerTask('default', ['build']);
424-
};
508+
};

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
## How To Contribute
66

7-
Known bugs and intended new features are tracked using [GitHub issues](https://github.com/processing/p5.js-website/issues). If you'd like to start working on an existing issue, comment on the issue that you plan to work on it so other contributors know it's being handled and can offer help. Once you have completed your work on this issue, [submit a pull request (PR)](https://github.com/processing/p5.js/blob/main/contributor_docs/preparing_a_pull_request.md) against the p5.js master branch. In the description field of the PR, include "resolves #XXXX" tagging the issue you are fixing. If the PR addresses the issue but doesn't completely resolve it (ie the issue should remain open after your PR is merged), write "addresses #XXXX".
7+
Known bugs and intended new features are tracked using [GitHub issues](https://github.com/processing/p5.js-website/issues). If you'd like to start working on an existing issue, comment on the issue that you plan to work on it so other contributors know it's being handled and can offer help. Once you have completed your work on this issue, [submit a pull request (PR)](https://github.com/processing/p5.js/blob/main/contributor_docs/preparing_a_pull_request.md) against the p5.js main branch. In the description field of the PR, include "resolves #XXXX" tagging the issue you are fixing. If the PR addresses the issue but doesn't completely resolve it (ie the issue should remain open after your PR is merged), write "addresses #XXXX".
88

99
If you discover a bug or have an idea for a new feature you'd like to add, begin by submitting an issue. Please do not simply submit a pull request containing the fix or new feature without making an issue first, we will probably not be able to accept it. Once you have gotten some feedback on the issue and a go ahead to address it, you can follow the process above to add the fix or feature.
1010

@@ -24,14 +24,14 @@ Once you've setup the site, type `npm run watch` to run the website. This should
2424

2525
## File structure
2626

27-
* __See note about what to include in pull requests [here](https://github.com/processing/p5.js-website/wiki/Pull-requests).__
27+
* __See note about what to include in pull requests [here](https://github.com/processing/p5.js/blob/main/contributor_docs/preparing_a_pull_request.md).__
2828
* `src/` – All the pieces for generating the built site. __Edits should be made here.__
2929
* `assets/` – All static files (imgs, css, fonts, js, p5_featured homepage sketches)
3030
* Note: if you make edits here you must restart the server to see your changes. To see changes immediately, you can edit the assets files in the dist directory, but need to copy and paste your updated work here for it to be saved.
3131
* `data/` – translation files
3232
* `templates/`
3333
* `layouts/` – default.hbs is main page template
34-
* `pages/` – Contains each of the pages of the p5 site, these get inserted in `{{> body }}` tag of default layout.
34+
* `pages/` – Contains each of the pages of the p5 site, these get inserted in `{{> body }}` tag of default layout. Note that for some pages (ex: learn, teach, and libraries) the hbs files are built from ejs files in the `data/` folder. When this is the case, you will find a README file inside that page's folder with notes about how this works.
3535
* `partials/` – These are reusable pieces that can get added to any page or layout, they correspond to other `{{> filename }}` tags in the pages or default layout.
3636
* `dist/` – Where the rendered files are stored, this gets generated via `grunt server` but does not get added to pull requests as it is auto-built online.
3737
* `Gruntfile.js` – This file contains all the tasks for using assemble and YAML to generate the final, static site. It uses the taskrunner [grunt](http://gruntjs.com/).
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
## Automated Reference update
2+
3+
The p5.js documentation needs to be updated every time a new p5.js release gets published.
4+
This process is done by the `update-enJSON` [grunt task](https://github.com/processing/p5.js-website/blob/main/Gruntfile.js).
5+
The task:
6+
- clones the p5.js repository in a tmp folder
7+
- generates the updated data.json file with the command `npm run grunt yui`
8+
- commits the data.json in the p5.js-website repository
9+
- generates the updated en.json with the getenJSON() function
10+
- commits the en.json in the p5.js-website repository
11+
- deletes the tmp folder
12+
13+
This task is run by a GitHub workflow in the p5.js-website repository that [gets triggered by another workflow](https://docs.github.com/en/actions/reference/events-that-trigger-workflows#repository_dispatch) in the p5.js repository.
14+
15+
Every time a new p5.js release gets published, the update-p5jswebsite workflow (in the p5.js repository) gets triggered and in turn triggers the update-documentation workflow (in the p5.js-website repository) that runs the `update-enJSON` task.
16+
17+
When the update-documentation workflow commits the updated Reference files, the commit message will show both the p5.js release tag and the commit's sha.
18+
19+
### Notes:
20+
- For the repository_dispatch event of the update-p5jswebsite workflow, [this GitHub action](https://github.com/peter-evans/repository-dispatch) was used.
21+
- In order for the update-p5jswebsite workflow to trigger the update-documentation workflow, **it requires a repo scoped Personal Access Token created on a user with write access to the p5.js-website repository**. The Personal Access Token needs to be stored as secret in the p5.js repository.

0 commit comments

Comments
 (0)