Skip to content

Commit

Permalink
Merge pull request #3 from Rafaelfferreira/pages-structure
Browse files Browse the repository at this point in the history
Main update with CI/CD
  • Loading branch information
Rafaelfferreira authored Jul 14, 2024
2 parents 3523813 + f2a7d95 commit afc7bbd
Show file tree
Hide file tree
Showing 55 changed files with 9,499 additions and 478 deletions.
12 changes: 12 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# EditorConfig is awesome: https://EditorConfig.org

# top-most EditorConfig file
root = true

[*]
indent_style = space
indent_size = 4
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = false
insert_final_newline = true
34 changes: 34 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
module.exports = {
parser: "@typescript-eslint/parser",
env: {
browser: true,
es2021: true,
node: true,
},
// plugins: ["react", "prettier", "@typescript-eslint"],
plugins: ["react", "@typescript-eslint"],
extends: [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:react/recommended",
"plugin:prettier/recommended",
],
overrides: [],
parserOptions: {
ecmaVersion: "latest",
sourceType: "module",
},
settings: {
react: {
version: "detect",
},
},
ignorePatterns: ["node_modules/", "cypress/"],
// Cherry of the Cake
rules: {
"prettier/prettier": 0,
"nonblock-statement-body-position": "off",
// "no-console": "error",
"react/no-unknown-property": ["error", { ignore: ["jsx", "global"] }],
},
};
28 changes: 28 additions & 0 deletions .github/workflows/continuous-delivery.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: "CD- Continuous Delivery"

# on:
# push:
# branches: [ main ]

on:
pull_request:
types: [opened, synchronize]

env:
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}

jobs:
deploy:
runs-on: ubuntu-latest
steps:
## [Common_CI_Steps]
- uses: actions/checkout@v3
## ===========================
- name: "Debug"
run: |
ls -la
- name: "Install Dependencies"
run: "npm install"
- name: "Deploy"
run: "npx vercel --prod --token=${{ secrets.VERCEL_TOKEN }} "
35 changes: 35 additions & 0 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: "CI - Continuous Integration"

on:
pull_request:
types: [opened, synchronize]

jobs:
lint:
runs-on: ubuntu-latest
steps:
## [Common_CI_Steps]
- uses: actions/checkout@v3
## ===========================
- name: "Debug"
run: |
ls -la
echo "Second command line!"
- name: "Install Dependencies"
run: "npm install"
- name: "Lint"
run: "npm run lint"
test:
runs-on: ubuntu-22.04
container:
image: "cypress/browsers:node-20.9.0-chrome-118.0.5993.88-1-ff-118.0.2-edge-118.0.2088.46-1"
options: --user 1001
steps:
## [Common_CI_Steps]
- uses: actions/checkout@v3

- name: "Install Dependencies"
run: "npm install "
## ===========================
- name: "Test"
run: "npm run test"
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,4 @@ dist
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*
.vercel
5 changes: 5 additions & 0 deletions .vercelignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.github
.vscode
core
cypress
.env
7 changes: 7 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"recommendations": [
"EditorConfig.EditorConfig",
"dbaeumer.vscode-eslint",
"github.vscode-github-actions"
]
}
3 changes: 0 additions & 3 deletions app/api/route.ts

This file was deleted.

11 changes: 0 additions & 11 deletions app/layout.tsx

This file was deleted.

3 changes: 0 additions & 3 deletions app/page.tsx

This file was deleted.

79 changes: 79 additions & 0 deletions core/crud.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import fs from "fs";
import { v4 as uuid } from "uuid";

// MARK: - CONSTANTS
const DB_FILE_PATH = "./core/db";

// MARK: - TYPES
type UUID = string;

type Todo = {
id: UUID;
date: string;
content: string;
done: boolean;
};

// MARK: - CRUD FUNCTIONS
export function create(content: string): Todo {
const todo: Todo = {
id: uuid(),
date: new Date().toISOString(),
content: content,
done: false,
};

const todos: Array<Todo> = [
...read(),
todo,
];

// salvar o content no sistema
fs.writeFileSync(DB_FILE_PATH, JSON.stringify({
todos,
"dogs": []
}, null, 2)); // Sync -> synchronous
return todo;
}

export function read(): Array<Todo> {
const dbString = fs.readFileSync(DB_FILE_PATH, "utf-8");
const db = JSON.parse(dbString || "{}");
if (!db.todos) {
return [];
}
return db.todos;
}

export function update(id: UUID, partialTodo: Partial<Todo>): Todo { // Partial<Todo> -> Partial is a built-in type that makes all properties of Todo optional
let updatedTodo;

const todos = read();
todos.forEach((currentItem) => {
const isToUpdate = currentItem.id === id;
if(isToUpdate) {
updatedTodo = Object.assign(currentItem, partialTodo); // Object.assign -> built-in function that copies all properties from the second object to the first object
}
});

fs.writeFileSync(DB_FILE_PATH, JSON.stringify({
todos,
}, null, 2));

if(!updatedTodo) {
throw new Error("Please provide another ID!")
}

return updatedTodo;
}

export function deleteById(id: UUID) {
const todos = read();

const todosWithoutDeleted = todos.filter((todo) => {
if(todo.id === id) { return false; }
return true;
});

fs.writeFileSync(DB_FILE_PATH, JSON.stringify({ todos: todosWithoutDeleted }, null, 2));
}
29 changes: 29 additions & 0 deletions core/db
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"todos": [
{
"id": "30c08ad9-cd30-4e5f-8fb9-b84cb358b9a5",
"date": "2024-04-27T22:31:07.560Z",
"content": "Primeira TODO",
"done": true
},
{
"id": "a49eb7da-9586-4646-b2d9-c365e84b261d",
"date": "2024-04-27T22:31:07.561Z",
"content": "Terceira TODO com novo content!",
"done": false
},
{
"id": "4613fcbf-2561-47c8-9021-30cb0a4e226f",
"date": "2024-05-16T01:36:18.008Z",
"content": "Next day task",
"done": true
},
{
"id": "c733e23e-37f7-4cc0-b765-a3de7a157345",
"date": "2024-05-19T20:32:49.395Z",
"content": "alo alo w brazil",
"done": false
}
],
"dogs": []
}
9 changes: 9 additions & 0 deletions cypress.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { defineConfig } from "cypress";

export default defineConfig({
e2e: {
setupNodeEvents() {
// implement node event listeners here
},
},
});
Loading

0 comments on commit afc7bbd

Please sign in to comment.