Skip to content

Commit

Permalink
feat(*): finishing touches for V0 (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nickersoft authored Sep 8, 2024
1 parent 0583939 commit b3bf383
Show file tree
Hide file tree
Showing 253 changed files with 3,129 additions and 15,757 deletions.
2 changes: 1 addition & 1 deletion .changeset/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
"access": "restricted",
"baseBranch": "main",
"updateInternalDependencies": "patch",
"ignore": []
"ignore": ["@atmx-org/registry", "www"]
}
32 changes: 32 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Release

on:
push:
branches:
- main

concurrency: ${{ github.workflow }}-${{ github.ref }}

jobs:
release:
name: Release
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@v3

- uses: oven-sh/setup-bun@v2
with:
bun-version: latest

- name: Install Dependencies
run: bun install

- name: Create Release PR or Publish to NPM
id: changesets
uses: changesets/action@v1
with:
publish: bun run release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
24 changes: 24 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Run tests

on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
build:
name: "Build & test packages"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup bun
uses: oven-sh/setup-bun@v2
with:
bun-version: latest
- name: Install dependencies
run: bun install --frozen-lockfile
- name: Build packages
run: bun run build --filter='!www'
- name: Running tests
run: bun test
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ node_modules/
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
bun-debug.log*


# environment variables
Expand All @@ -26,5 +26,7 @@ pnpm-debug.log*
# jetbrains setting folder
.idea/

__screenshots__

.vercel
.turbo
Binary file added bun.lockb
Binary file not shown.
2 changes: 2 additions & 0 deletions bunfig.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[test]
preload = "./happydom.ts"
8 changes: 4 additions & 4 deletions examples/simple/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
"description": "",
"private": true,
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"atmx": "workspace:*"
"atmx": "workspace:*",
"chalk": "^5.3.0",
"react": "^18.3.1",
"svelte": "^4.2.19"
}
}
12 changes: 0 additions & 12 deletions examples/simple/pnpm-lock.yaml

This file was deleted.

22 changes: 0 additions & 22 deletions examples/simple/src/lib/helpers/isPlainObject.ts

This file was deleted.

92 changes: 92 additions & 0 deletions examples/simple/src/lib/hooks/use-battery.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import { useEffect, useState } from "react";

import type { Nullable } from "@/lib/types/nullable.js";

interface BatteryState {
level: Nullable<number>;
charging: Nullable<boolean>;
chargingTime: Nullable<number>;
dischargingTime: Nullable<number>;
}

interface BatteryManager extends Readonly<BatteryState>, EventTarget {
onchargingchange: () => void;
onchargingtimechange: () => void;
ondischargingtimechange: () => void;
onlevelchange: () => void;
}

interface NavigatorWithPossibleBattery extends Navigator {
getBattery?: () => Promise<BatteryManager>;
}

type UseBatteryState =
| { isSupported: false } // Battery API is not supported
| { isSupported: true; loading: true } // battery API supported but not fetched yet
| (BatteryState & { isSupported: true; loading: false }); // battery API supported and fetched

const nav: NavigatorWithPossibleBattery | undefined =
typeof navigator !== "undefined" ? navigator : undefined;

const isBatteryApiSupported = nav && typeof nav.getBattery === "function";

/**
* Returns the device's current battery state if available via the Navigator API.
*/
function useBattery(): UseBatteryState {
const [state, setState] = useState<UseBatteryState>({
isSupported: true,
loading: true,
});

useEffect(() => {
if (!nav?.getBattery) {
setState((s) => ({ ...s, isSupported: false, loading: false }));
return;
}

let battery: BatteryManager | null = null;

const handleChange = () => {
if (!battery) return;

const { level, charging, chargingTime, dischargingTime } = battery;

setState({
isSupported: true,
loading: false,
level,
charging,
chargingTime,
dischargingTime,
});
};

nav.getBattery().then((b) => {
battery = b;
handleChange();

b.addEventListener("levelchange", handleChange);
b.addEventListener("chargingchange", handleChange);
b.addEventListener("chargingtimechange", handleChange);
b.addEventListener("dischargingtimechange", handleChange);
});

return () => {
if (battery) {
battery.removeEventListener("levelchange", handleChange);
battery.removeEventListener("chargingchange", handleChange);
battery.removeEventListener("chargingtimechange", handleChange);
battery.removeEventListener("dischargingtimechange", handleChange);
}
};
}, []);

return state;
}

const useBattery_ = isBatteryApiSupported
? useBattery
: (): UseBatteryState => ({ isSupported: false });

export { useBattery_ as useBattery };
7 changes: 7 additions & 0 deletions examples/simple/src/lib/types/nullable.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/**
* Transforms a type into a nullable type.
*
* @example
* type A = Nullable<string> // string | null
*/
export type Nullable<T> = T | null;
4 changes: 3 additions & 1 deletion examples/simple/utils.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
"ts": true,
"aliases": {
"helpers": "@/lib/helpers",
"hooks": "@/lib/hooks"
"hooks": "@/lib/hooks",
"types": "@/lib/types",
"actions": "@/lib/actions"
}
}
3 changes: 3 additions & 0 deletions happydom.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { GlobalRegistrator } from "@happy-dom/global-registrator";

GlobalRegistrator.register();
11 changes: 7 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@
"type": "module",
"private": true,
"scripts": {
"release": "turbo run build && changesets publish",
"build": "turbo run build",
"dev": "turbo run dev",
"clean": "rimraf -g packages/**/dist www/**/.vercel packages/**/.turbo www/**/.turbo www/**/.astro",
"preview": "turbo run preview",
"www": "pnpm --filter www run",
"cli": "pnpm --filter cli run",
"common": "pnpm --filter common run"
"check": "turbo run check",
"www": "bun --filter www run",
"cli": "bun --filter cli run",
"common": "bun --filter common run"
},
"workspaces": [
"packages/*",
Expand All @@ -26,7 +29,7 @@
"turbo": "^2.1.1",
"typescript": "^5.5.4"
},
"packageManager": "[email protected]+sha512.60c18acd138bff695d339be6ad13f7e936eea6745660d4cc4a776d5247c540d0edee1a563695c183a66eb917ef88f2b4feb1fc25f32a7adcadc7aaf3438e99c1",
"packageManager": "[email protected]",
"license": "MIT",
"dependencies": {
"eta": "^3.5.0"
Expand Down
23 changes: 14 additions & 9 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,34 @@
},
"scripts": {
"build": "tsup --env.NODE_ENV production",
"dev": "tsup --watch",
"prepare": "pnpm run build",
"generate-schema": "tsx scripts/generate-schema.ts",
"test": "vitest"
"dev": "cross-env NODE_ENV=development tsup --watch",
"generate-schema": "tsx scripts/generate-schema.ts"
},
"keywords": ["atmx", "atomics", "lodash", "utilities", "hooks", "cli"],
"keywords": [
"atmx",
"atomics",
"lodash",
"utilities",
"hooks",
"cli"
],
"author": "Tyler Nickerson",
"license": "MIT",
"devDependencies": {
"@types/fs-extra": "^11.0.4",
"@atmx-org/registry": "workspace:*",
"@types/bun": "^1.1.8",
"cross-env": "^7.0.3",
"tsup": "^8.2.4",
"tsx": "^4.17.0",
"typescript": "^5.5.4",
"vitest": "^2.0.5",
"zod-to-json-schema": "^3.23.2"
"vite-tsconfig-paths": "^5.0.1"
},
"dependencies": {
"@atmx-org/common": "workspace:*",
"@inquirer/prompts": "^5.3.8",
"commander": "^12.1.0",
"detect-package-manager": "^3.0.2",
"execa": "^9.3.1",
"fs-extra": "^11.2.0",
"lilconfig": "^3.1.2",
"ora": "^8.0.1",
"tsconfig-paths": "^4.2.0",
Expand Down
Loading

0 comments on commit b3bf383

Please sign in to comment.