Skip to content

Commit b3bf383

Browse files
authored
feat(*): finishing touches for V0 (#31)
1 parent 0583939 commit b3bf383

File tree

253 files changed

+3129
-15757
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

253 files changed

+3129
-15757
lines changed

.changeset/config.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@
77
"access": "restricted",
88
"baseBranch": "main",
99
"updateInternalDependencies": "patch",
10-
"ignore": []
10+
"ignore": ["@atmx-org/registry", "www"]
1111
}

.github/workflows/release.yml

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
concurrency: ${{ github.workflow }}-${{ github.ref }}
9+
10+
jobs:
11+
release:
12+
name: Release
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checkout Repo
16+
uses: actions/checkout@v3
17+
18+
- uses: oven-sh/setup-bun@v2
19+
with:
20+
bun-version: latest
21+
22+
- name: Install Dependencies
23+
run: bun install
24+
25+
- name: Create Release PR or Publish to NPM
26+
id: changesets
27+
uses: changesets/action@v1
28+
with:
29+
publish: bun run release
30+
env:
31+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
32+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

.github/workflows/tests.yml

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: Run tests
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
jobs:
10+
build:
11+
name: "Build & test packages"
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v4
15+
- name: Setup bun
16+
uses: oven-sh/setup-bun@v2
17+
with:
18+
bun-version: latest
19+
- name: Install dependencies
20+
run: bun install --frozen-lockfile
21+
- name: Build packages
22+
run: bun run build --filter='!www'
23+
- name: Running tests
24+
run: bun test

.gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ node_modules/
1313
npm-debug.log*
1414
yarn-debug.log*
1515
yarn-error.log*
16-
pnpm-debug.log*
16+
bun-debug.log*
1717

1818

1919
# environment variables
@@ -26,5 +26,7 @@ pnpm-debug.log*
2626
# jetbrains setting folder
2727
.idea/
2828

29+
__screenshots__
30+
2931
.vercel
3032
.turbo

bun.lockb

447 KB
Binary file not shown.

bunfig.toml

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[test]
2+
preload = "./happydom.ts"

examples/simple/package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
"description": "",
55
"private": true,
66
"main": "index.js",
7-
"scripts": {
8-
"test": "echo \"Error: no test specified\" && exit 1"
9-
},
107
"keywords": [],
118
"author": "",
129
"license": "ISC",
1310
"dependencies": {
14-
"atmx": "workspace:*"
11+
"atmx": "workspace:*",
12+
"chalk": "^5.3.0",
13+
"react": "^18.3.1",
14+
"svelte": "^4.2.19"
1515
}
1616
}

examples/simple/pnpm-lock.yaml

-12
This file was deleted.

examples/simple/src/lib/helpers/isPlainObject.ts

-22
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
import { useEffect, useState } from "react";
2+
3+
import type { Nullable } from "@/lib/types/nullable.js";
4+
5+
interface BatteryState {
6+
level: Nullable<number>;
7+
charging: Nullable<boolean>;
8+
chargingTime: Nullable<number>;
9+
dischargingTime: Nullable<number>;
10+
}
11+
12+
interface BatteryManager extends Readonly<BatteryState>, EventTarget {
13+
onchargingchange: () => void;
14+
onchargingtimechange: () => void;
15+
ondischargingtimechange: () => void;
16+
onlevelchange: () => void;
17+
}
18+
19+
interface NavigatorWithPossibleBattery extends Navigator {
20+
getBattery?: () => Promise<BatteryManager>;
21+
}
22+
23+
type UseBatteryState =
24+
| { isSupported: false } // Battery API is not supported
25+
| { isSupported: true; loading: true } // battery API supported but not fetched yet
26+
| (BatteryState & { isSupported: true; loading: false }); // battery API supported and fetched
27+
28+
const nav: NavigatorWithPossibleBattery | undefined =
29+
typeof navigator !== "undefined" ? navigator : undefined;
30+
31+
const isBatteryApiSupported = nav && typeof nav.getBattery === "function";
32+
33+
/**
34+
* Returns the device's current battery state if available via the Navigator API.
35+
*/
36+
function useBattery(): UseBatteryState {
37+
const [state, setState] = useState<UseBatteryState>({
38+
isSupported: true,
39+
loading: true,
40+
});
41+
42+
useEffect(() => {
43+
if (!nav?.getBattery) {
44+
setState((s) => ({ ...s, isSupported: false, loading: false }));
45+
return;
46+
}
47+
48+
let battery: BatteryManager | null = null;
49+
50+
const handleChange = () => {
51+
if (!battery) return;
52+
53+
const { level, charging, chargingTime, dischargingTime } = battery;
54+
55+
setState({
56+
isSupported: true,
57+
loading: false,
58+
level,
59+
charging,
60+
chargingTime,
61+
dischargingTime,
62+
});
63+
};
64+
65+
nav.getBattery().then((b) => {
66+
battery = b;
67+
handleChange();
68+
69+
b.addEventListener("levelchange", handleChange);
70+
b.addEventListener("chargingchange", handleChange);
71+
b.addEventListener("chargingtimechange", handleChange);
72+
b.addEventListener("dischargingtimechange", handleChange);
73+
});
74+
75+
return () => {
76+
if (battery) {
77+
battery.removeEventListener("levelchange", handleChange);
78+
battery.removeEventListener("chargingchange", handleChange);
79+
battery.removeEventListener("chargingtimechange", handleChange);
80+
battery.removeEventListener("dischargingtimechange", handleChange);
81+
}
82+
};
83+
}, []);
84+
85+
return state;
86+
}
87+
88+
const useBattery_ = isBatteryApiSupported
89+
? useBattery
90+
: (): UseBatteryState => ({ isSupported: false });
91+
92+
export { useBattery_ as useBattery };
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/**
2+
* Transforms a type into a nullable type.
3+
*
4+
* @example
5+
* type A = Nullable<string> // string | null
6+
*/
7+
export type Nullable<T> = T | null;

examples/simple/utils.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
"ts": true,
33
"aliases": {
44
"helpers": "@/lib/helpers",
5-
"hooks": "@/lib/hooks"
5+
"hooks": "@/lib/hooks",
6+
"types": "@/lib/types",
7+
"actions": "@/lib/actions"
68
}
79
}

happydom.ts

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { GlobalRegistrator } from "@happy-dom/global-registrator";
2+
3+
GlobalRegistrator.register();

package.json

+7-4
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,15 @@
55
"type": "module",
66
"private": true,
77
"scripts": {
8+
"release": "turbo run build && changesets publish",
89
"build": "turbo run build",
910
"dev": "turbo run dev",
11+
"clean": "rimraf -g packages/**/dist www/**/.vercel packages/**/.turbo www/**/.turbo www/**/.astro",
1012
"preview": "turbo run preview",
11-
"www": "pnpm --filter www run",
12-
"cli": "pnpm --filter cli run",
13-
"common": "pnpm --filter common run"
13+
"check": "turbo run check",
14+
"www": "bun --filter www run",
15+
"cli": "bun --filter cli run",
16+
"common": "bun --filter common run"
1417
},
1518
"workspaces": [
1619
"packages/*",
@@ -26,7 +29,7 @@
2629
"turbo": "^2.1.1",
2730
"typescript": "^5.5.4"
2831
},
29-
"packageManager": "[email protected]+sha512.60c18acd138bff695d339be6ad13f7e936eea6745660d4cc4a776d5247c540d0edee1a563695c183a66eb917ef88f2b4feb1fc25f32a7adcadc7aaf3438e99c1",
32+
"packageManager": "[email protected]",
3033
"license": "MIT",
3134
"dependencies": {
3235
"eta": "^3.5.0"

packages/cli/package.json

+14-9
Original file line numberDiff line numberDiff line change
@@ -8,29 +8,34 @@
88
},
99
"scripts": {
1010
"build": "tsup --env.NODE_ENV production",
11-
"dev": "tsup --watch",
12-
"prepare": "pnpm run build",
13-
"generate-schema": "tsx scripts/generate-schema.ts",
14-
"test": "vitest"
11+
"dev": "cross-env NODE_ENV=development tsup --watch",
12+
"generate-schema": "tsx scripts/generate-schema.ts"
1513
},
16-
"keywords": ["atmx", "atomics", "lodash", "utilities", "hooks", "cli"],
14+
"keywords": [
15+
"atmx",
16+
"atomics",
17+
"lodash",
18+
"utilities",
19+
"hooks",
20+
"cli"
21+
],
1722
"author": "Tyler Nickerson",
1823
"license": "MIT",
1924
"devDependencies": {
20-
"@types/fs-extra": "^11.0.4",
25+
"@atmx-org/registry": "workspace:*",
26+
"@types/bun": "^1.1.8",
27+
"cross-env": "^7.0.3",
2128
"tsup": "^8.2.4",
2229
"tsx": "^4.17.0",
2330
"typescript": "^5.5.4",
24-
"vitest": "^2.0.5",
25-
"zod-to-json-schema": "^3.23.2"
31+
"vite-tsconfig-paths": "^5.0.1"
2632
},
2733
"dependencies": {
2834
"@atmx-org/common": "workspace:*",
2935
"@inquirer/prompts": "^5.3.8",
3036
"commander": "^12.1.0",
3137
"detect-package-manager": "^3.0.2",
3238
"execa": "^9.3.1",
33-
"fs-extra": "^11.2.0",
3439
"lilconfig": "^3.1.2",
3540
"ora": "^8.0.1",
3641
"tsconfig-paths": "^4.2.0",

0 commit comments

Comments
 (0)