Skip to content

Commit 52d271b

Browse files
authored
Merge pull request #78 from wally-yawn/migrate_to_vite
Migrate to vite
2 parents 3587bcb + 0bcb969 commit 52d271b

28 files changed

Lines changed: 2994 additions & 17639 deletions

.env

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# .env
2+
VITE_BASE_URL=http://localhost:3000/api/v1
3+
VITE_GARDEN_ID=1

.github/workflows/ci.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ jobs:
1313
- name: Use Node.js
1414
uses: actions/setup-node@v3
1515
with:
16-
node-version: 18
16+
node-version: 20
1717

1818
- name: Install dependencies
1919
run: npm ci
2020

2121
- name: Run Cypress tests
2222
uses: cypress-io/github-action@v6
2323
with:
24-
start: npm start
25-
wait-on: 'http://localhost:3001'
24+
start: npm run dev
25+
wait-on: 'http://localhost:5173'
2626
wait-on-timeout: 90

README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,27 @@ The planning, preparation, and development of this project were completed over t
4040
![App Demo starting](./readme_assets/Demo_start.gif)
4141
![App Demo ending](./readme_assets/Demo_end.gif)
4242

43+
## Project Setup (Cloning from GitHub)
44+
This project is built using Vite and React. To get started:
45+
46+
1. Clone the repository: `git clone git@github.com:wally-yawn/smart_gardening_fe.git`
47+
2. cd your-repo-name
48+
3. Install dependencies: `npm install`
49+
4. Start the development server: `npm run dev`
50+
51+
## Migrating from Create React App (CRA) to Vite
52+
If you previously have set this project up as a CRA project you will need to follow these steps to migrate it to Vite:
53+
54+
1. Remove CRA-specific packages
55+
`npm uninstall react-scripts`
56+
2. Install Vite
57+
`npm install --save-dev vite`
58+
3. Install React plugin
59+
`npm install @vitejs/plugin-react`
60+
4. Install any other libraries
61+
`npm install`
62+
5. Note that to start the development server the command is now `npm run dev`
63+
4364
## Team Members
4465
#### Wally Wallace
4566
- [LinkedIn Profile](https://www.linkedin.com/in/wally--wallace)

cypress/e2e/errors.cy.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ describe("gardenPlantErrors", () => {
3232
fixture: "404_error",
3333
});
3434

35-
cy.visit("http://localhost:3001");
35+
cy.visit("http://localhost:5173");
3636
})
3737

3838
it("display an error if fetching garden plants fails", () => {

cypress/e2e/gardeninput.cy.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ describe("tool tip test", () => {
2222
})
2323

2424
it("should display the tool tip on hover", () => {
25-
cy.visit("http://localhost:3001/");
25+
cy.visit("http://localhost:5173/");
2626
cy.get(".info-icon").trigger("mouseover");
2727
cy.get("#my-tooltip")
2828
.should("be.visible")

cypress/e2e/gardens.cy.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ describe("Gardens Page", () => {
1414
fixture: 'lottie'
1515
})
1616

17-
cy.visit("http://localhost:3001/mygarden");
17+
cy.visit("http://localhost:5173/mygarden");
1818
cy.wait("@getPlants");
1919
});
2020

@@ -27,7 +27,7 @@ describe("Gardens Page", () => {
2727

2828
it("should show empty state when no plants exist", () => {
2929
cy.intercept("GET", "http://localhost:3000/api/v1/1/plants", { body: { plants: [] } }).as("emptyGarden");
30-
cy.visit("http://localhost:3001/mygarden");
30+
cy.visit("http://localhost:5173/mygarden");
3131
cy.wait("@emptyGarden");
3232
cy.get('[data-testid="empty-garden"]').should("be.visible").and("contain", "No Plants Saved Yet");
3333
});

cypress/e2e/header.cy.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ describe("Header Component", () => {
2929
{
3030
fixture: "gardens",
3131
};
32-
cy.visit("http://localhost:3001");
32+
cy.visit("http://localhost:5173");
3333
});
3434

3535
it("displays the welcome message on the main page", () => {
@@ -43,14 +43,14 @@ describe("Header Component", () => {
4343
});
4444

4545
it("displays the page does not exist message", () => {
46-
cy.visit("http://localhost:3001/test", { failOnStatusCode: false });
46+
cy.visit("http://localhost:5173/test", { failOnStatusCode: false });
4747

4848
cy.get("h1").contains("Oops! This page doesn’t exist. 🌱");
4949
});
5050

5151
it("displays the home button on non-main pages and navigates back home", () => {
52-
cy.visit("http://localhost:3001/mygarden");
52+
cy.visit("http://localhost:5173/mygarden");
5353
cy.get(".home-btn").should("exist").click();
54-
cy.url().should("eq", "http://localhost:3001/");
54+
cy.url().should("eq", "http://localhost:5173/");
5555
});
5656
});

cypress/e2e/recommendations.cy.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ describe("recommendations", () => {
5151
cy.intercept("PATCH", "http://localhost:3000/api/v1/1", {
5252
fixture: "gardens",
5353
});
54-
cy.visit("http://localhost:3001/");
54+
cy.visit("http://localhost:5173/");
5555
});
5656

5757
it("shows the main page before a search has not been completed with a default garden", () => {

cypress/e2e/saveplant.cy.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ describe("Garden Plant Saving Functionality with Recommendation", () => {
4545
}
4646
);
4747

48-
cy.visit("http://localhost:3001/");
48+
cy.visit("http://localhost:5173/");
4949
});
5050

5151
it("runs a recommendation, saves a plant, and verifies it appears in the garden", () => {
@@ -61,7 +61,7 @@ describe("Garden Plant Saving Functionality with Recommendation", () => {
6161
cy.get(".plant-cards > :nth-child(1) .button-disabled")
6262
.contains("Plant Saved")
6363
.should("be.disabled");
64-
cy.visit("http://localhost:3001/mygarden");
64+
cy.visit("http://localhost:5173/mygarden");
6565
cy.get(".all-plant-cards").contains("Strawberry");
6666
});
6767

fix-imports.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// fix-imports.js
2+
const fs = require('fs');
3+
const path = require('path');
4+
5+
const SRC_DIR = path.join(__dirname, 'src');
6+
7+
// Recursively scan a folder
8+
function scanFolder(folder) {
9+
const files = fs.readdirSync(folder);
10+
11+
files.forEach((file) => {
12+
const fullPath = path.join(folder, file);
13+
const stat = fs.statSync(fullPath);
14+
15+
if (stat.isDirectory()) {
16+
scanFolder(fullPath);
17+
} else if (stat.isFile() && (file.endsWith('.js') || file.endsWith('.jsx'))) {
18+
let content = fs.readFileSync(fullPath, 'utf-8');
19+
let updated = content;
20+
21+
// Match import statements
22+
updated = updated.replace(
23+
/import\s+([^\n]+?)\s+from\s+['"](.+?)['"]/g,
24+
(match, imports, importPath) => {
25+
// Only update relative imports
26+
if (importPath.startsWith('.') && !importPath.endsWith('.css') && !importPath.endsWith('.json')) {
27+
const resolvedPathJs = path.resolve(path.dirname(fullPath), importPath + '.js');
28+
if (fs.existsSync(resolvedPathJs)) {
29+
return `import ${imports} from '${importPath}.jsx'`;
30+
}
31+
}
32+
return match;
33+
}
34+
);
35+
36+
if (updated !== content) {
37+
fs.writeFileSync(fullPath, updated, 'utf-8');
38+
console.log(`Updated imports in: ${fullPath}`);
39+
}
40+
}
41+
});
42+
}
43+
44+
scanFolder(SRC_DIR);
45+
console.log('Done fixing imports to include .jsx.');

0 commit comments

Comments
 (0)