Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
zeitounmax committed Jul 18, 2023
0 parents commit 0b8ba87
Show file tree
Hide file tree
Showing 56 changed files with 11,966 additions and 0 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/_lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: lint

on:
workflow_call:

jobs:
lint:
name: Run linters
runs-on: ubuntu-latest

permissions:
checks: write
contents: write

steps:
- name: Check out Git repository
uses: actions/checkout@v3

- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: 16

- name: Install pnpm
run: npm -g install pnpm

- name: Install Node.js dependencies
run: cd ./frontend && pnpm install && cd ../backend && pnpm install

- name: Run linters
run: cd ./frontend && pnpm run lint && cd ../backend && pnpm run lint
18 changes: 18 additions & 0 deletions .github/workflows/dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: dev

on:
push:
branches:
- develop
- dev
pull_request:
branches:
- develop
- dev

jobs:
lint:
uses: ./.github/workflows/_lint.yml
permissions:
checks: write
contents: write
65 changes: 65 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: main

on:
push:
branches:
- main
- master
pull_request:
branches:
- main
- master
types: [closed]

jobs:
lint:
uses: ./.github/workflows/_lint.yml
permissions:
checks: write
contents: write

check-secrets: # thx https://stackoverflow.com/a/70249520/6612932
runs-on: ubuntu-latest

needs: lint

outputs:
caprover-server: ${{ steps.caprover-server.outputs.defined }}

steps:
- name: Check for secrets.CAPROVER_SERVER availability
id: caprover-server
# perform secret check & put boolean result as an output
shell: bash
run: |
if [ "${{ secrets.CAPROVER_SERVER }}" != '' ]; then
echo "defined=true" >> $GITHUB_OUTPUT;
else
echo "defined=false" >> $GITHUB_OUTPUT;
fi
deploy:
# secret checked and action merged or pushed only
if: needs.check-secrets.outputs.caprover-server == 'true' && (github.event.pull_request.merged || github.event_name == 'push')

runs-on: ubuntu-latest

needs: check-secrets

steps:
- name: Check out Git repository
uses: actions/checkout@v3

- name: Set up npm
uses: actions/setup-node@v3
with:
node-version: 16

- name: Install caprover
run: npm install -g caprover

- name: Deploy back
run: caprover deploy -h "${{ secrets.CAPROVER_SERVER }}" -p '${{ secrets.CAPROVER_PASSWORD }}' -b 'main' -a "${{ secrets.CAPROVER_BACK_APPNAME }}"

- name: Deploy front
run: caprover deploy -h "${{ secrets.CAPROVER_SERVER }}" -p '${{ secrets.CAPROVER_PASSWORD }}' -b 'main' -a "${{ secrets.CAPROVER_FRONT_APPNAME }}"
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
22 changes: 22 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

fileList=$(git diff --cached --name-only :^README.md :^LISEZ-MOI.md :^frontend :^backend)

echo '----- Checking Root...'

if [ ! -z "$fileList" ]
then
echo "error: Unauthorized modifications\n"

echo "$fileList\n"

echo "use 'git restore ...' to fix the problem"
echo "(and ask your instructor why you should not change these files)\n"

exit 1
fi

echo '----- Done!'

npm run lint
57 changes: 57 additions & 0 deletions .tours/03-backend.tour
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{
"$schema": "https://aka.ms/codetour-schema",
"title": "03: Backend",
"steps": [
{
"file": "backend/index.js",
"description": "Aaah, the `backend` folder ! \n\n_Before we begin, a fair warning: it's a bit more advanced than what you've seen previously, so don't dive in there too soon or you may get overwhelmed!_\n\nStill there ? Okay, here we go !",
"line": 15
},
{
"file": "backend/index.js",
"description": "The irst file you'll run through is the global `index.js`\nIt's just there to set things in motion, and we'll write very few lines of code here:\n- We set environment variables (Hello `.dotenv` !)\n- We call the `src/app.js` file (that's our real app, more on that in a few seconds)\n- We make our app start listening on a specific port (otherwise, even with the best code in the world it would d absolutely nothing)",
"line": 1
},
{
"file": "backend/src/app.js",
"description": "In the `src/app.js` file, we set up Express and app-wise middlewares (bits of code which are independent from our routes). For example, in this case we:\n- use the `cors` package to specify who has the right to call our backend\n- use the `express.json()` middleware to be able to read our client's request's **body**\n- use the `express.static()` middleware to allow files situated in the `public` folder to be accessed directly, without using routes\n\nWe also call for `src/router.js`, our next stop...",
"line": 1
},
{
"file": "backend/src/router.js",
"description": "Here, we'll specify which routes are available, and what does every one of them do.\n\nFor lisibility's sake, we don't write route-specifid code, but instead link to methods situated in *Controllers*\n\nFor example, if your client calls a \"GET /items/17\", the request will be redirected to the \"read\" method of the ItemController class.",
"line": 1
},
{
"file": "backend/src/controllers/ItemController.js",
"description": "Ah, here we are!\n\nThis \"read\" method in ItemController is a classic Express route middleware: given a request (`req`) and a response (`res`) variables, it'll execute code and try to satisfy your clients demands",
"line": 16
},
{
"file": "backend/src/controllers/ItemController.js",
"description": "Every route middleware's goal is to `res.send` something, be it useful data or an error code. Here you may see we have several possibilities:\n- If we found the item our client requested (remember the \"GET /items/17\" call ?), we send it\n- If we did not find it, we send a 404 (\"Content not found\") status\n- If something goes wrong (MySQL global error, syntax typo ,...) we send a 500 (\"Internal server error\") code (we don't want potential attackers to know what broke !)",
"line": 23
},
{
"file": "backend/src/controllers/ItemController.js",
"description": "Now, I'm speaking about MySQL errors but there are no \"SELECT * FROM item\" queries here, there's just this `models.item.find()` call...\n\nThat's normal, because your requests manipulate an _Entity_, a _Model_ of your target (here, an item). So we'll have to go to the `src/models/ItemManager.js` file!",
"line": 17
},
{
"file": "backend/src/models/ItemManager.js",
"description": "Ah, here we are, we found our SQL queries!\n\nAs you can see, every method here is dead simple: \"do something with the DB, and return the result\".\nThat allows us to regroup **all** our queries in the same files, t make it easier to maintain.\n\nHmm, but although we're in the Item model, I can't see the `find` method...\nOur ItemManager is a specialized AbstractManager (that's OOP for you!), we may as well go and see what this one does ?",
"line": 3
},
{
"file": "backend/src/models/AbstractManager.js",
"description": "Hah! Nailed it! (At last)\n\nWe have a `find` method, which does our `SELECT * FROM` query.\nAnd looking more in detail, we can imagine why: except for the table name, the query is strictly identical to find a specific item, or book, or car, or unicorn... So, it makes sense to write it onl once and make sure *every* somethingManager has access to it by default, doesn't it ?\n\nNote that the same goes for `findAll` ans `delete`: you'll never have to write these queries in your own managers !",
"line": 7
},
{
"file": "backend/index.js",
"description": "Congrats on following me through this complex architecture! I hope that's a bit clearer now that it was a while ago!",
"line": 3
}
],
"ref": "master"
}
37 changes: 37 additions & 0 deletions .tours/frontend.tour
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"$schema": "https://aka.ms/codetour-schema",
"title": "02: Frontend",
"steps": [
{
"file": "frontend/src/App.jsx",
"description": "From your App.jsx file you'll be able to build your application. Consider you're already in the `<body>` tag of your HTML page and code on !",
"line": 5
},
{
"file": "frontend/src/App.jsx",
"description": "On this very first line, you see the import of another component: Home (you may delete it if you don't need it, it's just a sample!)\n\nTwo things to note here:\n- this import gets the `Home.jsx` file situated in the `pages` folder (no need to add the \".jsx\" extension in your imports)\n- the `@pages` notation is a shortcut pre-configured by your trainers: wherever you are in your frontend file architecture, it will lead to the `frontend/src/pages` folder. You don't need to know how it was done for now, but there are other shortcuts as this one:\n - `@assets`\n - `@components`\n - `@pages`\n - `@services`\n",
"line": 1
},
{
"file": "frontend/src/assets/.gitignore",
"description": "The `src/assets` folder is meant to hold all your non-code files : fonts, images, audio & video files, ...\n\nFeel free to make subfolders to keep it as clean as possible!",
"line": 1
},
{
"file": "frontend/src/components/.gitignore",
"description": "You may store any component you create in the `src/components` folder (thanks Captain Obvious!)\n\nIt'll allow you to keep the `src` folder clean. As seen in the previous step, please create folders here as you see fit",
"line": 1
},
{
"file": "frontend/src/pages/.gitignore",
"description": "The `src/pages` folder is meant to hold components directy caled by react-router (or whatever router you're using) (and if you don't understand what I'm saying riht now, don't worry it'll become clearer soon!)\n\nYou want to store here your \"pages\" (even though React apps don't typically work like vanilla HTML websites and don't know of the \"page\" concept)",
"line": 1
},
{
"file": "frontend/src/services/.gitignore",
"description": "This one is a bit trickier to explain: sometimes, in your React app, you'll need some files which are not components at all : a custom hook, redux files, an API abstraction layer, etc... The `src/services` folder is here for that purpose exactly.\n\nDon't worry if you don't have anything to put in there for now: you'll know when you need it ;-)",
"line": 1
}
],
"ref": "master"
}
37 changes: 37 additions & 0 deletions .tours/global-behaviour.tour
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"$schema": "https://aka.ms/codetour-schema",
"title": "01: Global behaviour",
"steps": [
{
"file": "README.md",
"description": "First thing first: read this file! A few explanations can go a long way towards comprehension...",
"line": 1
},
{
"file": "package.json",
"description": "Here are the scripts we spoke about in the README.\nEven if you don't understand the exact syntax (and seriously, you don't need to!), know these commands because you'll be using them a lot during your project.\n\nNB: most of these are \"meta-commands\" : they just execute the matching command in the frontend and the backend folders.",
"line": 6
},
{
"file": "frontend/package.json",
"description": "Here we are, in the *frontend* package.json. I insist on this, but **It is not the same as the other one!**\nCommands listed here will have absolutely zero impact on the rest of the project: that's why you should **always** be in your project's root directory in your Terminal before you run any commands.",
"line": 1
},
{
"file": "frontend/package.json",
"description": "Side note: You may notice there are a lot of (front-specific!) developer dependancies here. They are the packages used to enforce React-only rules (JSX, Accessibility, ...), and would have no interest nor use in the backend folder.",
"line": 16
},
{
"file": "frontend/.env.sample",
"description": "Here we have a `.env` safe copy. Ask your trainer for more details on it as you see fit, but please note that:\n- every information you don't want everyone to get their hands on should end here. API keys, your bank account number, passwords, ...\n- all the variables you'll list here (in the \".sample\" version) should have **FAKE** values: the `.env.sample` file will go on GHub, whereas the `.env` one won't",
"line": 1
},
{
"file": "frontend/src/App.jsx",
"description": "Here, you may see (at last!) your App itself!\n\nCongrats on finishing this first global CodeTour, for further ado on the frontend architecture you may want to check the next one ;-) ",
"line": 1
}
],
"ref": "master"
}
91 changes: 91 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

## [3.0.2] - 2023-07-12

### Fixed

- Fixed deploy workflow. Thanks to [Pierre Paillard]([https://github.com/vandanjon](https://github.com/PPaillard)).

## [3.0.1] - 2023-07-10

### Fixed

- Removed useless eslint disable comment in `backend/index.js`. Thanks to [Benoît Vandanjon](https://github.com/vandanjon).

- Fixed pre-commit hook to reject modifications in the root directory.

## [3.0.0] - 2023-05-29

### Added

- Git commands for Windows users, to fix issues with different newline formats (see [README.md](README.md#windows-users)).

### Changed

- Changed default ports configuration to 3000 for frontend and 6000 for backend. Thanks to [Loris Chastanet](https://github.com/lchastanet).

- **Breaking change:** removed cutomized alias for imports in frontend.

### Fixed

- Moved `vite` `and `@`vitejs/plugin-react` as regular dependencies in frontend, and fixed imports in config. Thanks to [Pierre Paillard](https://github.com/PPaillard/).

[Open an issue](https://github.com/WildCodeSchool/js-template-fullstack/issues/new) if you have any request/feedback :)

## [2.0.1] - 2023-03-24

### Changed

- Removed useless code in `package.json` files.

## [2.0.0] - 2023-02-10

### Added

- Deployment workflows using CapRover. Thanks to [Anthony Gorski](https://github.com/GorskiAnthony).
- Compatibility with `npm` alternatives (`yarn`, `pnpm`...). Set `config.cli` in root `package.json` with the wanted value.

### Changed

- Allowed usage `console.info` in ESLint configuration (front and back).
- Bumped dependencies versions. Thanks to [Valentin Dupin](https://github.com/ydainna).
- Cleaned backend/src/app.js and removed public index.html file to avoid conflicts when serving react build.

- **Breaking change:** removed setup script: `npm install` (or any other alternative) triggers a `postinstall` script.

- **Breaking change:** removed models "autoloading": now managers should be instantiated manually in `backend/src/models/index.js`.

For example, given you created a `FooManager.js` file to be associated with a `foo` table,
you should add to index, after `const models = {}` statement:

```js
const FooManager = require("./FooManager");

models.foo = new FooManager();
models.foo.setDatabase(pool);
```

- **Breaking change:** renamed `connection` property of managers as `database` to be consistent with quests.

Managers methods should be fixed from:

```js
findAll() {
return this.connection.query(`select * from ${this.table}`);
}
```

To:

```js
findAll() {
return this.database.query(`select * from ${this.table}`);
}
```
Loading

0 comments on commit 0b8ba87

Please sign in to comment.