Skip to content

Commit

Permalink
chore(version): Bump version to v1.0.0.2 & Optimize package structure…
Browse files Browse the repository at this point in the history
… and minify data files
  • Loading branch information
Alice39s committed Feb 9, 2025
1 parent 1231682 commit d009554
Show file tree
Hide file tree
Showing 31 changed files with 777 additions and 493 deletions.
11 changes: 3 additions & 8 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,17 @@
"es2021": true,
"node": true
},
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended"
],
"extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended"],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module"
},
"plugins": [
"@typescript-eslint"
],
"plugins": ["@typescript-eslint"],
"rules": {
"@typescript-eslint/explicit-function-return-type": "warn",
"@typescript-eslint/no-explicit-any": "error",
"@typescript-eslint/no-unused-vars": "error",
"no-console": ["warn", { "allow": ["warn", "error"] }]
}
}
}
24 changes: 12 additions & 12 deletions .github/workflows/data-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,48 +8,48 @@ on:
- package.json
- .github/workflows/**
schedule:
- cron: '0 0 1 * *' # Every month on the 1st day at 00:00 UTC
workflow_dispatch: # Accept manual trigger
- cron: '0 0 1 * *' # Every month on the 1st day at 00:00 UTC
workflow_dispatch: # Accept manual trigger

jobs:
build-and-release:
runs-on: ubuntu-latest
permissions:
contents: write

steps:
- uses: actions/checkout@v4

- name: Setup Bun
uses: oven-sh/setup-bun@v1
with:
bun-version: latest

- name: Install dependencies
run: bun install

- name: Fetch latest airports data
run: bun run fetch-data

- name: Get package version
id: package_version
run: echo "version=$(node -p "require('./package.json').version")" >> $GITHUB_OUTPUT

- name: Get current date
id: date
run: echo "date=$(date +'%Y-%m-%d')" >> $GITHUB_OUTPUT

- name: Create backup archive
run: tar -czf backup.gz data/*.json

- name: Create Release
uses: softprops/action-gh-release@v1
with:
tag_name: v${{ steps.package_version.outputs.version }}-${{ steps.date.outputs.date }}
name: Release v${{ steps.package_version.outputs.version }} (${{ steps.date.outputs.date }})
body: |
Monthly airports data update for version ${{ steps.package_version.outputs.version }}
This release contains the latest airports data from OurAirports, split into the following files:
- basic_info.json: Basic airport information (name, type)
- codes.json: Airport codes (IATA, ICAO, local)
Expand All @@ -65,4 +65,4 @@ jobs:
data/references.json
backup.gz
draft: false
prerelease: false
prerelease: false
20 changes: 10 additions & 10 deletions .github/workflows/npm-publish.yml
Original file line number Diff line number Diff line change
@@ -1,38 +1,38 @@
name: Publish Package to NPM

on:
# release:
# types: [created]
workflow_dispatch: # Accept manual trigger
# release:
# types: [created]
workflow_dispatch: # Accept manual trigger

jobs:
build-and-publish:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write

steps:
- uses: actions/checkout@v4

- name: Setup Bun
uses: oven-sh/setup-bun@v1
with:
bun-version: latest

- name: Install dependencies
run: bun install

- name: Build package
run: bun run build

- name: Setup Node.js for NPM
uses: actions/setup-node@v4
with:
node-version: '20.x'
registry-url: 'https://registry.npmjs.org'

- name: Publish to NPM
run: npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
2 changes: 1 addition & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
"printWidth": 100,
"bracketSpacing": true,
"arrowParens": "avoid"
}
}
29 changes: 29 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.0.2] - 2024-02-09

### Changed
- Optimized build output structure for better module consumption
- Separated Node.js and browser builds into distinct directories
- Added proper CommonJS support for Node.js environment
- Improved ESM module format for browser environment
- Enhanced type declarations generation
- Added separate type declarations for Node.js and browser builds
- Improved type definitions organization

### Optimized
- Significantly reduced JSON data file sizes through minification
- Improved module tree-shaking support
- Better source maps generation for both Node.js and browser builds

### Fixed
- Fixed incorrect file extensions in package exports
- Resolved module format compatibility issues
- Fixed type declarations path in package.json

[1.0.2]: https://github.com/alice39s/ourairports-data-js/compare/v1.0.1...v1.0.2
51 changes: 28 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ A TypeScript library for working with [OurAirports Data](https://github.com/davi

> [!WARNING]
> 🔧 This library is not yet ready for production use. It is still under development.
>
>
> This project uses only clean data containing IATA Code airports in order to reduce the size of the package.
> [!IMPORTANT]
Expand Down Expand Up @@ -41,15 +41,15 @@ bun add ourairports-data-js
<!-- Using unpkg -->
<script type="module">
import OurAirports from 'https://unpkg.com/ourairports-data-js/dist/browser/index.js';
const airports = new OurAirports();
await airports.initialize();
</script>

<!-- Using jsDelivr -->
<script type="module">
import OurAirports from 'https://cdn.jsdelivr.net/npm/ourairports-data-js/dist/browser/index.js';
const airports = new OurAirports();
await airports.initialize();
</script>
Expand Down Expand Up @@ -95,19 +95,22 @@ console.log(`Found ${chineseAirports.length} airports in China`);

// Find airports within 100km radius of Beijing Capital Airport
const nearbyAirports = airports.findAirportsInRadius(40.0799, 116.6031, 100);
console.log('Nearby airports:', nearbyAirports.map(a => ({
name: a.name,
type: a.type,
distance: 'calculated by the library'
})));
console.log(
'Nearby airports:',
nearbyAirports.map(a => ({
name: a.name,
type: a.type,
distance: 'calculated by the library',
}))
);

// Search airports with filters
const largeAirports = airports.searchAirports({
type: 'large_airport',
hasIataCode: true,
hasScheduledService: true,
country: 'CN',
continent: 'AS'
continent: 'AS',
});
```

Expand All @@ -119,19 +122,19 @@ import { AirportFilter } from 'ourairports-data-js';

async function initAirports() {
const airports = new OurAirports();

try {
// Asynchronous initialization in browser (automatically uses CDN)
await airports.initializeAsync();

// Search for major Chinese airports
const filter: AirportFilter = {
country: 'CN',
type: 'large_airport',
hasIataCode: true,
hasScheduledService: true
hasScheduledService: true,
};

const majorAirports = airports.searchAirports(filter);
console.log('Major Chinese airports:', majorAirports);
} catch (error) {
Expand All @@ -151,15 +154,15 @@ import OurAirports, { BasicInfo } from 'ourairports-data-js';

async function searchAirport(iataCode: string): Promise<BasicInfo | undefined> {
const airports = new OurAirports();

try {
// Library automatically uses the appropriate initialization method
if (typeof window !== 'undefined') {
await airports.initializeAsync(); // Browser environment
} else {
airports.initialize(); // Node.js environment
}

return airports.findByIataCode(iataCode);
} catch (error) {
console.error('Error searching airport:', error);
Expand Down Expand Up @@ -191,18 +194,18 @@ async function searchAirport(iataCode: string): Promise<BasicInfo | undefined> {

```typescript
interface AirportFilter {
type?: string; // e.g., 'large_airport', 'medium_airport', 'small_airport'
country?: string; // ISO country code, e.g., 'US', 'CN'
continent?: string; // Continent code, e.g., 'NA', 'AS'
type?: string; // e.g., 'large_airport', 'medium_airport', 'small_airport'
country?: string; // ISO country code, e.g., 'US', 'CN'
continent?: string; // Continent code, e.g., 'NA', 'AS'
hasIataCode?: boolean; // Whether the airport has an IATA code
hasScheduledService?: boolean; // Whether the airport has scheduled service
}

interface BasicInfo {
id: number; // Unique identifier
ident: string; // Airport identifier (usually ICAO code)
type: string; // Airport type
name: string; // Airport name
id: number; // Unique identifier
ident: string; // Airport identifier (usually ICAO code)
type: string; // Airport type
name: string; // Airport name
// ... more fields available in ./src/types.ts
}
```
Expand All @@ -218,12 +221,14 @@ The library uses data from OurAirports, which is updated periodically:
## Environment-Specific Features

### Node.js

- Synchronous data loading
- File system access for data files
- Better performance with local data
- Full tree-shaking support in ESM mode

### Browser

- Asynchronous data loading
- Automatic CDN fallback
- No file system dependencies
Expand All @@ -241,4 +246,4 @@ MIT License - see the [LICENSE](LICENSE) file for details.

- Data provided by [OurAirports](https://ourairports.com/)
- Built with TypeScript and Zod
- Powered by jsDelivr CDN for browser environments
- Powered by jsDelivr CDN for browser environments
Binary file modified bun.lockb
Binary file not shown.
Loading

0 comments on commit d009554

Please sign in to comment.