You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-[`npm start` / `npm run list:region`](#npm-start--npm-run-listregion)
85
+
-[`npm run list:province`](#npm-run-listprovince)
86
+
-[NPM Scripts for Building Documentation](#npm-scripts-for-building-documentation)
87
+
-[`npm run generate-docs`](#npm-run-generate-docs)
88
+
-[`npm run docs:install`](#npm-run-docsinstall)
89
+
-[`npm run docs:build`](#npm-run-docsbuild)
90
+
-[NPM Scripts for Building Windows Executable Files of the Interactive CLI Scripts](#npm-scripts-for-building-windows-executable-files-of-the-interactive-cli-scripts)
91
+
-[`build:win:region`](#buildwinregion)
92
+
-[`build:win:province`](#buildwinprovince)
93
+
-[`build:win:all`](#buildwinall)
94
+
-[`npm run minify:region`](#npm-run-minifyregion)
95
+
-[NPM Scripts for Compiling the Interactive CLI Scripts into Stand-Alone Scripts](#npm-scripts-for-compiling-the-interactive-cli-scripts-into-stand-alone-scripts)
96
+
-[`npm run minify:province`](#npm-run-minifyprovince)
97
+
-[`npm run minify:all`](#npm-run-minifyall)
98
+
-[NPM Scripts for Linting Files and Unit Testing](#npm-scripts-for-linting-files-and-unit-testing)
99
+
-[`npm run lint`](#npm-run-lint)
100
+
-[`npm run lint:fix`](#npm-run-lintfix)
101
+
-[`npm test`](#npm-test)
102
+
-[`npm run example`](#npm-run-example)
92
103
-[Class Usage](#class-usage)
93
104
-[Load and Parse a Local Excel File](#load-and-parse-a-local-excel-file)
94
105
-[Download and Parse a Remote Excel File](#download-and-parse-a-remote-excel-file)
@@ -101,6 +112,8 @@ The following dependencies are used for this project. Feel free to use other dep
101
112
-[Using NodeJS](#using-nodejs)
102
113
-[Troubleshooting](#troubleshooting)
103
114
115
+
</details>
116
+
104
117
## Installation
105
118
106
119
1. Clone this repository.<br>
@@ -114,6 +127,9 @@ The following dependencies are used for this project. Feel free to use other dep
114
127
115
128
3. Create a `.env` file from the `.env.example` file inside the `/app` directory. Use the default values for the following environment variables.
116
129
130
+
<details>
131
+
<summary>List of .env variables and their description.</summary>
132
+
117
133
> **INFO:** If installed as an NPM package with `npm i ph-municipalities`, create the `.env` file inside the NPM project's root directory.
118
134
119
135
| Variable Name | Description |
@@ -124,13 +140,18 @@ The following dependencies are used for this project. Feel free to use other dep
124
140
| SPECIAL_CHARACTERS | Key-value pairs of special characters or garbled text and their normalized text conversions, delimited by the `":"` character.<br>Multiple key-value pairs are delimited by the `","` character.<br>If a special character key's value is a an empty string, write it as i.e.,: `"some-garbled-text:"`|
125
141
| IMAGE_URL | Raw URL of the README image file from this GitHub repository.<br> <blockquote>**NOTE:** Only add this variable in the GitHub Secrets for publishing to the NPM registry since NPM does not allow displaying images by relative path.</blockquote> |
126
142
143
+
</details>
144
+
127
145
## Installation Using Docker
128
146
129
147
We can use Docker to run dockerized Node app for local development mode. The following methods require Docker and Docker compose correctly installed and set up on your development machine.
130
148
131
149
### Docker Dependencies
132
150
151
+
<details>
152
+
<summary>
133
153
The following dependencies are used to build and run the image. Please feel feel free to use other OS and versions as needed.
154
+
</summary>
134
155
135
156
1. Ubuntu 22.04.1
136
157
- Docker version 23.0.1, build a5eeb1
@@ -141,8 +162,13 @@ The following dependencies are used to build and run the image. Please feel feel
141
162
- Docker Compose version v2.27.1-desktop.1
142
163
- Docker Engine version 26.1.4, build 5650f9b
143
164
165
+
</details>
166
+
144
167
### Docker for Localhost Development
145
168
169
+
<details>
170
+
<summary>Steps for using Docker with local development</summary>
171
+
146
172
1. Set up the environment variables for the `/app` directory. Visit the [Installation](#installation) section, **step #3** for more information.
147
173
148
174
2. Stop and delete all docker instances for a fresh start.
@@ -167,6 +193,8 @@ The following dependencies are used to build and run the image. Please feel feel
> _**Note:** These NPM scripts run relative within the `/app` directory, when working on a git-cloned repository of the app. To run using only NodeJS, navigate first to the `/app` directory and execute a target script, for example:_
<b>NPM Scripts for Compiling the Interactive CLI Scripts into Stand-Alone Scripts</b>
313
+
</summary>
314
+
266
315
### `npm run minify:region`
267
316
268
317
- Compiles the Node.js project's `npm list:region` script and dependencies into a single script using [**ncc**](https://www.npmjs.com/package/@vercel/ncc).
<b>NPM Scripts for Linting Files and Unit Testing</b>
339
+
</summary>
340
+
285
341
### `npm run lint`
286
342
287
343
Lint JavaScript source codes.
@@ -294,6 +350,13 @@ Fix JavaScript lint errors.
294
350
295
351
Run tests defined in the `/app/__tests__` directory.
296
352
353
+
### `npm run example`
354
+
355
+
- Downloads and parses a remote excel file.
356
+
- Demonstrates sample usage with `await`
357
+
358
+
</details>
359
+
297
360
## Class Usage
298
361
299
362
Below are example usages of the `ExcelFile` class, run from the **/app/src/examples** directory. Check out the `/app/src/examples/sample_usage.js` file for more examples.
@@ -302,7 +365,9 @@ Below are example usages of the `ExcelFile` class, run from the **/app/src/examp
302
365
303
366
This is a simple usage example of the `ExcelFile` class.
304
367
305
-
**Simple Usage**
368
+
<details>
369
+
<summary><b>Simple Usage</b></summary>
370
+
306
371
```javascript
307
372
constpath=require('path')
308
373
constExcelFile=require('../classes/excel')
@@ -346,7 +411,13 @@ file.datalist = [
346
411
{ municipality:'Bucay', province:'Abra' }]
347
412
```
348
413
349
-
**Reading regions, provinces and municipalities**
414
+
</details>
415
+
416
+
<details>
417
+
<summary>
418
+
<b>Reading regions, provinces and municipalities</b>
419
+
</summary>
420
+
350
421
```javascript
351
422
constpath=require('path')
352
423
constExcelFile=require('../classes/excel')
@@ -377,10 +448,17 @@ const municipalitiesFromProvince = file.listMunicipalities({ provinces })
Adding a `url` field in the constructor parameter prepares the class to download a remote Excel file for the data source.
383
456
457
+
<details>
458
+
<summary>
459
+
<b>Remote Excel file download example</b>
460
+
</summary>
461
+
384
462
> **INFO:** Run the `.init()` method after initializing a class with a `url` parameter to start the async file download.
385
463
386
464
```javascript
@@ -410,9 +488,14 @@ const main = async () => {
410
488
main()
411
489
```
412
490
491
+
</details>
492
+
413
493
### Alternate Usage - Events
414
494
415
-
Initialize an `ExcelFile` class instance.
495
+
<details>
496
+
<summary>
497
+
<b>Initialize an ExcelFile class instance.</b>
498
+
</summary>
416
499
417
500
```javascript
418
501
require('dotenv').config()
@@ -446,6 +529,8 @@ const main = () => {
446
529
main()
447
530
```
448
531
532
+
</details>
533
+
449
534
### Using a Custom Configuration File
450
535
451
536
The **ph-municipalities**`ExcelFile` and `ExcelFactory` classes use a default configuration file to define their regions and provinces in the `/app/config/regions.json` file. The regions and provinces data in this file syncs with the PAGASA Seasonal and 10-Day Weather Forecast Excel files provinces and municipalities naming convention, encoded by hand as of August 24, 2024.
@@ -454,7 +539,11 @@ Follow the codes to define a custom regions config file, following the format of
454
539
455
540
> _**Note:** The custom config file's province/municipality names should match those in the 10-day Excel file._
456
541
457
-
**config.json**
542
+
<details>
543
+
<summary>
544
+
<b>config.json</b>
545
+
</summary>
546
+
458
547
```
459
548
{
460
549
"metadata": {
@@ -485,7 +574,13 @@ Follow the codes to define a custom regions config file, following the format of
485
574
}
486
575
```
487
576
488
-
**Custom config usage**
577
+
</details>
578
+
579
+
<details>
580
+
<summary>
581
+
<b>Custom config usage</b>
582
+
</summary>
583
+
489
584
```javascript
490
585
require('dotenv').config()
491
586
constpath=require('path')
@@ -518,6 +613,8 @@ console.log('\nProvince/municipality names should match with those in the 10-day
518
613
console.log('---municipalities', municipalities)
519
614
```
520
615
616
+
</details>
617
+
521
618
## Building Standalone Windows Executables
522
619
523
620
The main npm scripts can be packaged into standalone windows executables. Pre-compiled windows binaries are available for download in the latest [Releases](https://github.com/ciatph/ph-municipalities/releases) download page.
@@ -550,7 +647,10 @@ The main npm scripts can be compiled into standalone JavaScript files together w
550
647
551
648
The class documentation uses [JSDoc](https://jsdoc.app/) annotations where applicable in the JavaScript source codes inside the **/src** directory. There are two (2) options for building the class documentation.
1. Run docker for localhost development. Refer to the [Docker for Localhost Development](#docker-for-localhost-development) section for more information.
556
656
@@ -564,7 +664,14 @@ The class documentation uses [JSDoc](https://jsdoc.app/) annotations where appli
564
664
docker exec -u root -it ph-municipalities npm run docs:build
0 commit comments