Skip to content

Commit

Permalink
feat(package): 📝 updated README.md + added post-install script
Browse files Browse the repository at this point in the history
v1.0.0 should be ready to release now
  • Loading branch information
suptower committed Aug 8, 2023
1 parent e1b9ca4 commit 6b41f04
Show file tree
Hide file tree
Showing 7 changed files with 170 additions and 12 deletions.
85 changes: 81 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ Retrieve weather information directly from your terminal.

![terminal example usage](terminal.gif)

![3 day forecast preview](table_forecast.png)

# Install
via `npm`
```
Expand Down Expand Up @@ -77,23 +79,98 @@ You can show the current config with following command:
```
weather -c
```
The config allows you to change the temperature unit.
The config allows you to change the temperature unit, the forecast hour traversing style, the favorite location and the default action for blank command.
```
weather -c
# output
? Select config option » - Use arrow-keys. Return to submit.
Show API key
Delete API key
> Set temperature unit
Set forecast hour traversing style
Preset Times Configuration
Set favorite location
Set default action for blank command
Reset config
Cancel
---
√ Select config option » Set temperature unit
---
? Select temperature unit » - Use arrow-keys. Return to submit.
> Celsius
Fahrenheit
---
√ Select temperature unit » Celsius
---
Temperature unit is saved as metric.
```
```

## Temperature unit
The two options for temperature unit are Celsius (metric) and Fahrenheit (imperial). Every temperature will be converted to the selected unit when displayed.
You can change the temperature unit in the config (`weather -c`). The default unit is Celsius.

## Forecast hour traversing style
When checking forecast information, you can choose between two hour traversing styles. The default one (dial) lets you cycle the forecast for each hour individually (0-23) when accessing a forecast. The other style (preset) lets you configure a list of preset times which will be used to check the forecast. You can change the hour traversing style in the config (`weather -c`). The default style is dial. The default preset options are Morning (6 AM), Noon (12 PM), Evening (6 PM) and Night (12 AM). You are also able to configure these presets in the configuration.
For example:
```
weather -c
# output
? Select config option » - Use arrow-keys. Return to submit.
Show API key
Delete API key
Set temperature unit
Set forecast hour traversing style
> Preset Times Configuration
Set favorite location
Set default action for blank command
Reset config
Cancel
---
? Choose an option » - Use arrow-keys. Return to submit.
> Add preset time
Edit preset time
Remove preset times
Show preset times
Reset preset times
Cancel
---
? Enter a preset name » Afternoon
---
√ Enter a preset name ... Afternoon
? Enter a preset time » 16
Preset time added.
```
You can also show the preset times like this:
```
weather -c
# output
√ Select config option » Preset Times Configuration
? Choose an option » - Use arrow-keys. Return to submit.
Add preset time
Edit preset time
Remove preset times
> Show preset times
Reset preset times
Cancel
---
√ Choose an option » Show preset times
╔═══════════╤══════╗
║ Name │ Time ║
╟───────────┼──────╢
║ Night │ 0 ║
╟───────────┼──────╢
║ Morning │ 6 ║
╟───────────┼──────╢
║ Noon │ 12 ║
╟───────────┼──────╢
║ Afternoon │ 16 ║
╟───────────┼──────╢
║ Evening │ 18 ║
╚═══════════╧══════╝
```
You are also able to edit and remove existing preset times as well as resetting them to their default state.

## Favorite location
You can set a favorite location in the config (`weather -c`). This location will be used when you don't specify a location in the command. The default location is Munich.

## Default action for blank command
You can set a default action for the blank command (`weather`) in the config (`weather -c`). The default action is to show a three day forecast for the favorite location.
However, you can set the default action to show the full prompt menu for the favorite location instead.
6 changes: 3 additions & 3 deletions bin/configHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const configHandler = async noclear => {
{ title: "Preset Times Configuration", value: "preset" },
{ title: "Set favorite location", value: "location"},
{ title: "Set default action for blank command", value: "default"},
{ title: "Clear config", value: "clear" },
{ title: "Reset config", value: "reset" },
{ title: "Cancel", value: "cancel" },
],
});
Expand All @@ -48,7 +48,7 @@ export const configHandler = async noclear => {
await setUnit();
await recall(true);
}
if (response.config === "clear") {
if (response.config === "reset") {
await clearConfig();
await recall(true);
}
Expand Down Expand Up @@ -127,7 +127,7 @@ const setUnit = async () => {
};

const clearConfig = async () => {
await config.clear();
await config.reset();
console.log(chalk.green("Config cleared."));
};

Expand Down
11 changes: 11 additions & 0 deletions bin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ const options = getopts(argv, {
env: "e",
fast: "f",
three_day: "t",
prompt: "p",
info: "i",
},
});
Expand All @@ -108,6 +109,7 @@ if (options.help) {
-e, --env set api key from environment variable API_KEY
-f , --fast [loc] fast mode, no prompt, location as arg
-t, --three_day [loc] show three day forecast
-p, --prompt [loc] prompt mode (default when using blank command with location as arg)
-i, --info show project related info
Examples:
Expand Down Expand Up @@ -201,6 +203,15 @@ if (options.config) {
} else {
console.log(chalk.red("You need to specify a location."));
}
} else if (options.prompt) {
// prompt for location
console.clear();
if (argv.length > 1) {
argv.shift();
weatherprompt(argv.join(" "));
} else {
weatherprompt();
}
} else {
// prompt for location
console.clear();
Expand Down
14 changes: 14 additions & 0 deletions bin/post-install.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import chalk from "chalk";

import gradient from "gradient-string";

import terminalLink from "terminal-link";

console.log(gradient.pastel("Thank you for installing Weather CLI!\nTo start things off, you need to set your API key."));
const link = terminalLink("Weather API", "https://www.weatherapi.com/");
console.log(gradient.pastel("In order to retrieve your API key, you need to set up an account on " + link + " if not done already."));
console.log(gradient.pastel("Once you have your API key, run ") + chalk.green("weather --config") + gradient.mind(" and follow the instructions."));

console.log(chalk.cyan("You can always check the " + chalk.magenta.bgBlue("README.md") + " file for more information."));
const repository = terminalLink("GitHub repository", "https://www.github.com/suptower/weather-cli");
console.log(chalk.cyan("If you have any questions or suggestions, feel free to open an issue on the " + chalk.magenta(repository) + "."));
56 changes: 55 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
{
"name": "@suptower/weather-cli",
"version": "0.5.2",
"date": "Updated on 7th of August 2023.",
"date": "Updated on 8th of August 2023.",
"description": "A package to retrieve weather information directly from your terminal.",
"exports": "./bin/index.js",
"type": "module",
"scripts": {
"release": "node ./bin/autodate.js && commit-and-tag-version",
"lint": "prettier --check . && eslint .",
"lint:fix": "prettier --write . && eslint . --fix",
"autodate": "node ./bin/autodate.js"
"autodate": "node ./bin/autodate.js",
"postinstall": "node ./bin/post-install.js"
},
"bin": {
"weather": "./bin/index.js"
Expand Down Expand Up @@ -60,9 +61,10 @@
"ora": "^6.3.1",
"prompts": "^2.4.2",
"string-length": "^6.0.0",
"table": "^6.8.1"
"table": "^6.8.1",
"terminal-link": "^3.0.0"
},
"engines": {
"node": ">=16"
}
}
}
Binary file added table_forecast.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 6b41f04

Please sign in to comment.