Skip to content

Commit e78c371

Browse files
authored
Merge pull request #4 from ml5js/add-prettier
Add prettier code formatter
2 parents 381e612 + 1745575 commit e78c371

File tree

6 files changed

+92
-21
lines changed

6 files changed

+92
-21
lines changed

.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/dist

.prettierrc.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

CONTRIBUTING.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
## Setup
2+
3+
This build uses node version 18.15.0 and npm version.
4+
Install nvm and run the following commands:
5+
6+
```
7+
nvm install 18.15
8+
nvm use 18
9+
```
10+
11+
To build the library, run the following commands:
12+
13+
```
14+
npm install
15+
npm run build
16+
```
17+
18+
This will create the build in the dist folder.
19+
20+
Open `examples/NeuralNetwork/index.html` in the browser to see the build running an example from the ml5 website.
21+
22+
## Code Formatting
23+
24+
To keep the coding style consistent, we will be using the Prettier formatter.
25+
26+
### Visual Studio Code
27+
28+
If you are using Visual Studio Code, you can install the Prettier extension by going to the **Extensions** tab and search for "Prettier". Click on **Prettier - Code formatter** and click **Install**.
29+
30+
Go to **File > Preferences > Settings**, search for "default formatter" and make sure **Prettier - Code formatter** is selected for **Editor: Default Formatter**.
31+
32+
To automatically format a document when saving it, search for "format on save" in the settings and make sure **Editor: Format On Save** is checked. Otherwise, you can use the VS Code keyboard shortcut to format an opened document, which is <kbd>shift</kbd> + <kbd>alt</kbd> + <kbd>f</kbd> for Windows or <kbd>shift</kbd> + <kbd>option</kbd> + <kbd>f</kbd> for Mac by default.
33+
34+
### Command Line
35+
36+
You can also format a document via the command line. To format all JavaScript documents in the repo, use:
37+
38+
```
39+
npm run format
40+
```
41+
42+
To format a specific document, use
43+
44+
```
45+
npx prettier --write path/to/file
46+
```
47+
48+
For more options with the command line, refer to the [Prettier Documentation](https://prettier.io/docs/en/cli.html)
49+
50+
## Process
51+
52+
_This section explains how this repository was creates and is for reference purposes only. The steps outlines in this section do not need to be followed by contributors._
53+
54+
I am building the library using Webpack, which was installed with:
55+
56+
```
57+
npm install --save-dev webpack webpack cli
58+
```
59+
60+
I also created package.json using `npm init` and set up a basic config file for a library build named `webpack.config.js`. I configured package.json so I could run webpack with `npm run build`.
61+
62+
From the original ml5 library's `src` folder, I copied over all source files from the `NeuralNetwork` directory and necessary dependency files from `utils` directory. I also copied over `index.js` from the `src` folder and deleted everything unrelated to NeuralNetwork. I then installed `@tensorflow/[email protected]`, `@tensorflow/[email protected]`, and `[email protected]` with npm.
63+
64+
At this point, the library can be built without error. I was only getting an error about exceeding recommended size limit. For the build, I am using the latest version of node, npm, and tfjs. I have not tested all the features of NeuralNetwork, but it appears to be working just fine.

README.md

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,24 @@
11
# ml5-neuralnetwork-test-build
2-
This is a test repo to see what it would take to build only the NeuralNetwork feature of the ml5 library.
2+
3+
Welcome to the next-generation repo for the ml5.js project! Due to the complexities inherent in updating all the dependencies in [the original repo](https://github.com/ml5js/ml5-library), we're exploring rebuilding from the ground up. This fresh repository allows us to migrate over classes and functions one at a time. This is very much a work in progress and is currently in its early, experimental stage. We appreciate your patience as we work towards refining this next evolution of the ml5.js project. Stay tuned!
34

45
## Setup
6+
57
This build uses node version 18.15.0 and npm version.
68
Install nvm and run the following commands:
9+
710
```
811
nvm install 18.15
912
nvm use 18
1013
```
1114

12-
1315
To build the library, run the following commands:
16+
1417
```
15-
cd package
1618
npm install
1719
npm run build
1820
```
19-
This will create the build in the dist folder.
2021

22+
This will create the build in the dist folder.
2123

2224
Open `examples/NeuralNetwork/index.html` in the browser to see the build running an example from the ml5 website.
23-
24-
25-
## Process
26-
I am building the library using Webpack, which was installed with:
27-
```
28-
npm install --save-dev webpack webpack cli
29-
```
30-
31-
I also created package.json using `npm init` and set up a basic config file for a library build named `webpack.config.js`. I configured package.json so I could run webpack with `npm run build`.
32-
33-
34-
From the original ml5 library's `src` folder, I copied over all source files from the `NeuralNetwork` directory and necessary dependency files from `utils` directory. I also copied over `index.js` from the `src` folder and deleted everything unrelated to NeuralNetwork. I then installed `@tensorflow/[email protected]`, `@tensorflow/[email protected]`, and `[email protected]` with npm.
35-
36-
37-
At this point, the library can be built without error. I was only getting an error about exceeding recommended size limit. For the build, I am using the latest version of node, npm, and tfjs. I have not tested all the features of NeuralNetwork, but it appears to be working just fine.

package-lock.json

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
"description": "",
55
"main": "index.js",
66
"scripts": {
7-
"build": "webpack --config webpack.config.js"
7+
"build": "webpack --config webpack.config.js",
8+
"format": "prettier --write \"**/*.js\""
89
},
910
"keywords": [
1011
"ML5"
@@ -13,9 +14,10 @@
1314
"license": "ISC",
1415
"repository": {
1516
"type": "git",
16-
"url": ""
17+
"url": "https://github.com/ml5js/ml5-next-gen"
1718
},
1819
"devDependencies": {
20+
"prettier": "2.8.8",
1921
"webpack": "^5.76.1",
2022
"webpack-cli": "^5.0.1"
2123
},

0 commit comments

Comments
 (0)