Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
3750850
Dropdown with list of cities works.
tomwinskell Feb 7, 2025
dfe0584
Stop tracking node_modules
tomwinskell Feb 7, 2025
ed839e3
Validated input and fetching lat long.
tomwinskell Feb 7, 2025
17eeda9
Uses fetch to get data for current and forecasted weather. Displayed …
tomwinskell Feb 10, 2025
1631e00
Refactored to load html templates with placeholders.
tomwinskell Feb 11, 2025
5784963
Populate template function now looks for array in object. If array, i…
tomwinskell Feb 11, 2025
c54c571
Added toTitleCase function to change description of weather to title …
tomwinskell Feb 11, 2025
1e8761c
Used geolocation API to lookup location, fallback to ipapi API. TODO:…
tomwinskell Feb 12, 2025
575e8e7
Added toast, setDefault and geolocation loading location.
tomwinskell Feb 12, 2025
ae8da81
Refactored to render based on weatherData global variable
tomwinskell Feb 14, 2025
fd0e5f9
Reworked functions to filter dt stamps for forecast so that the close…
tomwinskell Feb 14, 2025
39f5851
Finally, the dates saga is resolved. I think :D
tomwinskell Feb 15, 2025
830252f
Remove console log
tomwinskell Feb 15, 2025
68defb2
Added webpack with Bootstrap, modified folder structure.
tomwinskell Feb 18, 2025
0bbac37
Webpack working. Adjusted some functions to include html as webpack s…
tomwinskell Feb 18, 2025
5ff6c05
Resolved Boostrap issues by using CDN instead of Boostrap as npm pack…
tomwinskell Feb 18, 2025
27c357d
Added title bar with name and icon.
tomwinskell Feb 18, 2025
22da205
Changed folder structure.
tomwinskell Feb 18, 2025
334da4d
Added readme file.
tomwinskell Feb 18, 2025
7d05d44
Small change to readme file.
tomwinskell Feb 18, 2025
6213215
Deploy with hashed main.js filename.
tomwinskell Feb 19, 2025
e71cde7
Amend homepage link.
tomwinskell Feb 19, 2025
2c9a283
Amend homepage link.
tomwinskell Feb 19, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Node modules
/node_modules/

# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# OS generated files
.DS_Store
.AppleDouble
.LSOverride

# Thumbnails
Thumbs.db

# Environment variables
.env
.env.local
.env.development.local
.env.test.local
.env.production.local

# Build output
/dist
/build

# IDE specific files
.idea/
.vscode/
*.sublime-project
*.sublime-workspace

# Other
coverage/
*.tgz

# environment variables
config.js
142 changes: 142 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,145 @@
This project has been created by a student at Parsity, an online software engineering course. The work in this repository is wholly of the student based on a sample starter project that can be accessed by looking at the repository that this project forks.

If you have any questions about this project or the program in general, visit [parsity.io](https://parsity.io/) or email hello@parsity.io.

## Live Demo

Live demo at [https://tomwinskell.github.io/weather-project/](https://tomwinskell.github.io/weather-project/)

## Tech Stack

- **Frontend**: HTML, CSS, JavaScript (ES6+)
- **Module Bundler**: Webpack
- **API**: OpenWeatherMap API (or specify the API you're using)
- **Version Control**: Git

## Project Structure

```
weather-project/
├── dist/ # Compiled and minified files
├── src/ # Source files
│ ├── index.html # Main HTML file
│ ├── scripts/ # JavaScript files
│ │ ├── main.js # Entry point for JS
│ │ └── modules/ # ES6 modules
│ │ ├── fetchData.js # Custom fetch API function
│ │ ├── handlers.js # handleSubmit and handleInput functions
│ │ └── templateM.js # Functions to inject data into html templates
├── .gitignore # Git ignore file
├── package.json # NPM package configuration
├── package-lock.json # NPM package lock file
└── webpack.config.js # Webpack configuration
```

## Setup Instructions

1. **Clone the Repository**:

```bash
git clone https://github.com/tomwinskell/weather-project.git
cd weather-project
```

2. **Install Dependencies**:
Ensure you have Node.js and npm installed. Then, run:

```bash
npm install
```

3. **API Key Configuration**:
Obtain an API key from [OpenWeatherMap](https://openweathermap.org/api) and configure it in your project:

- Create a `config.js` file in `/variables` directory:
```
WX_API_KEY=your_openweathermap_api_key
```
- Ensure your application code accesses this key appropriately.

4. **Build the Project**:
To bundle the JavaScript modules and prepare the project for deployment:

```bash
npm run build
```

This will generate the `dist/` directory with the compiled files.

5. **Start the Development Server**:
For development purposes, you can start a local server with hot reloading:
```bash
npm start
```
This utilizes `webpack-dev-server` for serving the project locally.

## Deployment

To deploy the application:

1. **Build for Production**:
Ensure the code is optimized for production:

```bash
npm run build
```

This updates the `dist/` directory with the latest production-ready code.

2. **Serve the `dist/` Directory**:
Deploy the contents of the `dist/` directory to your preferred hosting service (e.g., GitHub Pages, Netlify, Vercel).

## Webpack Configuration

The project uses Webpack to bundle JavaScript modules. Below is an overview of the `webpack.config.js`:

```javascript
'use strict';

const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');

module.exports = {
mode: 'development',
entry: './src/scripts/main.js',
output: {
filename: 'main.js',
path: path.resolve(__dirname, 'dist'),
},
devServer: {
static: path.resolve(__dirname, 'dist'),
port: 8080,
hot: true,
},
plugins: [new HtmlWebpackPlugin({ template: './src/index.html' })],
module: {
rules: [
{
test: /\.html$/i,
loader: 'html-loader',
},
],
},
};
```

### Key Points:

- **Entry Point**: `./src/scripts/main.js` is the main JavaScript file that imports other modules.
- **Output**: Bundled files are output to the `dist/` directory with the filename `main.js`.
- **DevServer**: Configured to serve content from the `dist/` directory, running on port 8080.

## JavaScript Module Structure

The project follows the ES6 module pattern:

- **`main.js`**: Serves as the entry point and orchestrates the application by importing necessary modules.

Each module is imported as needed:

```javascript
import { handleInput, handleSubmit, renderPage } from './modules/handlers.js';
import cities from '../assets/cities.json';
```

This modular approach promotes code reusability and maintainability.
Loading