Skip to content

Commit

Permalink
feat: v3 pre-publish updates
Browse files Browse the repository at this point in the history
  • Loading branch information
dmythro committed Sep 12, 2023
1 parent f42f74c commit 993bbee
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 16 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,7 @@ composer.phar

# Dependency directory
node_modules

# Copied during build
dist/README*
dist/LICENSE*
17 changes: 8 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ Also, contains separate JSON files with additional country **Emoji** flags data.

## Version 3.0: Breaking changes

Version 3 comes with some data structure changes. Also, it was completely reworked with TypeScript, ESM exports and Turborepo file structure.
Version 3 comes with some data structure changes.
It was completely reworked under the hood with **TypeScript**, **ESM** exports and **Turborepo** file structure.

## Version 2.0: Breaking changes
Everything is strongly typed so you can easily use data with auto-complete in your IDE.

This version changes a lot in the data structures, and placement of the files.
So, if your projects depend on the old structure — specify previous versions, `<2.0.0`.
**Note**: If your projects depend on the old structure, carefully specify required versions in your dependencies.

## Installation

Expand Down Expand Up @@ -57,10 +57,9 @@ getCountryCode('Україна') // 'UA'
getCountryData('UA') // ICountryData
```

Built files are in the `dist` directory of this repository.
The `packages/countries` directory contains source data.
Built files are in the `dist` directory of this repository, and `packages/countries` directory contains source data.

**Note**: JS builds:
**Note**: JS build contains ES modules, CommonJS and IIFE (for now)

- CJS `index.min.js`.
- ESM `index.min.mjs`.
Expand Down Expand Up @@ -108,13 +107,13 @@ const languages = {
}
```

## Contributing
## Contributing to this repository

Everything is generated from strongly typed files in `packages/countries/src`, including SQL file.

Everything in `dist` is generated,
so please make data related changes **ONLY** to files from `packages/countries`, commit them.
Use `npm run build` command to build/test generated files.
Use `npm run build` (or `turbo build`, `turbo test`) command to build/test generated files.

## Credits

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
],
"authors": [
{
"name": "Dmytro",
"name": "Dmytro Klymenko",
"email": "[email protected]",
"homepage": "https://github.com/dmythro"
}
Expand Down
7 changes: 2 additions & 5 deletions dist/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@
"description": "Continents & countries: ISO 3166-1 alpha-2 code, name, ISO 639-1 languages, capital, currency, native name, phone. JSON, CSV and SQL.",
"type": "module",
"exports": {
"./*": {
"require": "./*.min.js",
"import": "./*.min.mjs"
},
"./minimal/*": "./minimal/*",
".": {
"require": "./index.min.js",
"import": "./index.min.mjs"
Expand Down Expand Up @@ -40,7 +37,7 @@
"typescript"
],
"author": {
"name": "Dmytro",
"name": "Dmytro Klymenko",
"email": "[email protected]",
"url": "https://github.com/dmythro"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/countries/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"*": "./src/*"
},
"author": {
"name": "Dmytro",
"name": "Dmytro Klymenko",
"email": "[email protected]",
"url": "https://github.com/dmythro"
},
Expand Down
4 changes: 4 additions & 0 deletions packages/scripts/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { copyFiles } from 'scripts/tasks/copyFiles.ts'
import { generateCsv } from 'scripts/tasks/generateCsv.ts'
import { generateSql } from 'scripts/tasks/generateSql.ts'
import { generateTypings } from 'scripts/tasks/generateTypings.ts'
Expand All @@ -12,3 +13,6 @@ generateSql()

// Meta
generateTypings()

// Necessary files for publishing
copyFiles()
10 changes: 10 additions & 0 deletions packages/scripts/tasks/copyFiles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import chalk from 'chalk'

import { copyFileToDist } from 'scripts/utils.ts'

export const copyFiles = (): void => {
console.log(chalk.bold('\nCopying files to DIST:\n'))

copyFileToDist('../../LICENSE')
copyFileToDist('../../README.md')
}
8 changes: 8 additions & 0 deletions packages/scripts/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ const MIN_EXT = '.min'
const JSON_EXT = '.json'
const JSON_MIN_EXT = `${MIN_EXT}${JSON_EXT}`

export const copyFileToDist = (src: string) => {
const filename = path.basename(src)
const dest = path.resolve(DIST, filename)
fs.copyFileSync(src, dest)

console.log('Copied', chalk.blue(path.relative('../../', dest)))
}

export const getCountryDataToCsv = (
{ name, native, phone, continent, capital, currency, languages }: ICountryCsv,
joinWith: string
Expand Down

0 comments on commit 993bbee

Please sign in to comment.