Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cli): watch mode #7

Merged
merged 13 commits into from
Feb 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
17 changes: 17 additions & 0 deletions .changeset/soft-impalas-wash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
"@labdigital/intl-extractor": major
---

## Watch mode

This release adds watch mode using `@parcel/watcher` (optional dependency). Use `--watch` or `-w` cli flag to run.
Note: This is a simple implementation that just reprocesses all files once there's an update.

Breaking change: Only one input directory is allowed instead of multiple, this is so we do not have to run multiple watchers for each input directory.


## Other

- Update to pnpm 10
- Use corepack
- Use unified release workflow for Lab Digital packages
55 changes: 9 additions & 46 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,9 @@ jobs:
uses: actions/checkout@v4

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 18

- uses: pnpm/action-setup@v3
name: Install pnpm
id: pnpm-install
with:
version: 8
run_install: true
uses: labd/gh-actions-typescript/pnpm-install@main

- name: Check formatting and typing
- name: Lint
run: pnpm check

build:
Expand All @@ -33,25 +24,18 @@ jobs:
needs: lint
strategy:
matrix:
node: ["18.x", "20.x"]
os: [ubuntu-latest, windows-latest, macOS-latest]
node: ["20.x", "22.x"]
os: [ubuntu-latest]

steps:
- name: Checkout repo
uses: actions/checkout@v4

- name: Use Node ${{ matrix.node }}
uses: actions/setup-node@v4
- name: Set up Node.js
uses: labd/gh-actions-typescript/pnpm-install@main
with:
node-version: ${{ matrix.node }}

- uses: pnpm/action-setup@v3
name: Install pnpm
id: pnpm-install
with:
version: 8
run_install: true

- name: Test
run: pnpm run test:ci

Expand All @@ -69,37 +53,16 @@ jobs:
with:
fetch-depth: 0

- name: Install node.js
uses: actions/setup-node@v4
with:
node-version: 18

- uses: pnpm/action-setup@v3
name: Install pnpm
id: pnpm-install
with:
version: 8
run_install: true

- name: Get pnpm store directory
id: pnpm-cache
shell: bash
run: echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT

- uses: actions/cache@v4
name: Setup pnpm cache
with:
path: ${{ steps.pnpm-cache.outputs.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- name: Set up Node.js
uses: labd/gh-actions-typescript/pnpm-install@main

- name: Create and publish versions
uses: changesets/action@v1
with:
title: "Release new version"
commit: "update version"
publish: pnpm publish:ci
version: pnpm publish:version
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,7 @@ npx @labdigital/intl-extractor -i ./path/to/files -o ./path/to/output.json
## How it works

Scans input files for `useTranslations` or `getTranslations` usage using the TypeScript SDK. It will then merge them all together and check the source JSON file for label values.

## Watch mode

You can use watch mode by installing `@parcel/watcher` and using the `--watch` or `-w` flag. It's a really simple implementation that reprocesses all files whenever there's an update.
2 changes: 1 addition & 1 deletion examples/client.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export function MyOtherComponent = () => {
const t = useTranslations("MyComponent");

const content () => {
const foobar = t("foodiebar");
const foobar = t("foodiebar3");
return (
<div>
<h1>{t("title")}</h1>
Expand Down
8 changes: 4 additions & 4 deletions examples/output.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"ProductListing": {
"foobar": "foobar",
"title": "title cool",
"foobar": "ProductListing.foobar",
"title": "ProductListing.title",
"Second": {
"results": "results cool"
"results": "ProductListing.Second.results"
}
},
"MyComponent": {
"foobar": "foobar mooi geupdate",
"title": "title",
"foodiebar": "foodiebar hallo"
"foodiebar3": "MyComponent.foodiebar3"
}
}
10 changes: 10 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@
"bin": {
"intl-extractor": "./dist/bin/cli.js"
},
"packageManager": "[email protected]",
"scripts": {
"build": "tsup",
"check": "pnpm lint && tsc",
"format": "eslint src --fix ; prettier --write .",
"lint": "eslint src && prettier --check .",
"publish:ci": "pnpm build && pnpm changeset publish",
"publish:version": "pnpm changeset version && pnpm format",
"test": "vitest run",
"test:ci": "vitest run --coverage"
},
Expand All @@ -21,17 +23,25 @@
"yargs": "^17.7.2"
},
"peerDependencies": {
"@parcel/watcher": "2.5.1",
"typescript": ">=5.5"
},
"peerDependenciesMeta": {
"@parcel/watcher": {
"optional": true
}
},
"devDependencies": {
"@changesets/cli": "^2.27.6",
"@parcel/watcher": "2.5.1",
"@types/node": "^20.14.9",
"@types/yargs": "^17.0.32",
"@typescript-eslint/eslint-plugin": "^7.14.1",
"@vitest/coverage-v8": "^1.6.0",
"eslint": "^8.57.0",
"eslint-plugin-sort-class-members": "^1.20.0",
"eslint-plugin-unused-imports": "^4.0.0",
"prettier": "^3.5.2",
"tsup": "^8.1.0",
"typescript": "^5.5.2",
"vitest": "^1.6.0"
Expand Down
Loading