initial
This commit is contained in:
26
.gitignore
vendored
Normal file
26
.gitignore
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
# Dependencies
|
||||
node_modules/
|
||||
|
||||
# Build output
|
||||
dist/
|
||||
|
||||
# IDE
|
||||
.vscode/
|
||||
.idea/
|
||||
.zed/
|
||||
*.swp
|
||||
*.swo
|
||||
|
||||
# OS
|
||||
.DS_Store
|
||||
Thumbs.db
|
||||
|
||||
# Logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
|
||||
# Environment
|
||||
.env
|
||||
.env.local
|
||||
141
README.md
Normal file
141
README.md
Normal file
@@ -0,0 +1,141 @@
|
||||
# Shared TypeScript Types
|
||||
|
||||
This package contains shared TypeScript type definitions used across multiple applications.
|
||||
|
||||
## Setup
|
||||
|
||||
### 1. Initialize the package
|
||||
|
||||
```bash
|
||||
npm install
|
||||
npm run build
|
||||
```
|
||||
|
||||
### 2. Push to Git
|
||||
|
||||
```bash
|
||||
git init
|
||||
git add .
|
||||
git commit -m "Initial commit: shared types package"
|
||||
git remote add origin <your-git-repo-url>
|
||||
git push -u origin main
|
||||
```
|
||||
|
||||
## Usage in Other Projects
|
||||
|
||||
### Option 1: Install from Git (HTTPS)
|
||||
|
||||
Add to your project's `package.json`:
|
||||
|
||||
```json
|
||||
{
|
||||
"dependencies": {
|
||||
"@your-org/shared-types": "git+https://github.com/your-org/shared-types.git"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Or install via command:
|
||||
|
||||
```bash
|
||||
npm install git+https://github.com/your-org/shared-types.git
|
||||
```
|
||||
|
||||
### Option 2: Install from Git (SSH)
|
||||
|
||||
```json
|
||||
{
|
||||
"dependencies": {
|
||||
"@your-org/shared-types": "git+ssh://git@github.com:your-org/shared-types.git"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Option 3: Install specific branch or tag
|
||||
|
||||
```json
|
||||
{
|
||||
"dependencies": {
|
||||
"@your-org/shared-types": "git+https://github.com/your-org/shared-types.git#v1.0.0"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Or for a branch:
|
||||
|
||||
```json
|
||||
{
|
||||
"dependencies": {
|
||||
"@your-org/shared-types": "git+https://github.com/your-org/shared-types.git#develop"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Using the Types
|
||||
|
||||
```typescript
|
||||
import { User, ApiResponse, Status } from '@your-org/shared-types';
|
||||
|
||||
const user: User = {
|
||||
id: '123',
|
||||
email: 'user@example.com',
|
||||
name: 'John Doe',
|
||||
createdAt: new Date(),
|
||||
updatedAt: new Date()
|
||||
};
|
||||
|
||||
const response: ApiResponse<User> = {
|
||||
success: true,
|
||||
data: user,
|
||||
message: 'User retrieved successfully'
|
||||
};
|
||||
|
||||
const status = Status.Active;
|
||||
```
|
||||
|
||||
## Updating the Package
|
||||
|
||||
When you make changes to the types:
|
||||
|
||||
1. Update the version in `package.json`
|
||||
2. Build the package: `npm run build`
|
||||
3. Commit and push changes
|
||||
4. Update consuming applications: `npm update @your-org/shared-types`
|
||||
|
||||
## Development Workflow
|
||||
|
||||
### Adding New Types
|
||||
|
||||
1. Create new `.ts` files in the `src/` directory
|
||||
2. Export types from `src/index.ts`
|
||||
3. Build and test: `npm run build`
|
||||
4. Commit changes and push
|
||||
|
||||
### Versioning
|
||||
|
||||
Follow semantic versioning:
|
||||
- **MAJOR**: Breaking changes
|
||||
- **MINOR**: New features, backward compatible
|
||||
- **PATCH**: Bug fixes, backward compatible
|
||||
|
||||
### Best Practices
|
||||
|
||||
- Keep types focused and modular
|
||||
- Use clear, descriptive names
|
||||
- Document complex types with JSDoc comments
|
||||
- Avoid coupling to specific implementations
|
||||
- Export everything through `index.ts`
|
||||
|
||||
## Structure
|
||||
|
||||
```
|
||||
shared-types/
|
||||
├── src/
|
||||
│ ├── index.ts # Main export file
|
||||
│ └── types.ts # Type definitions
|
||||
├── dist/ # Compiled output (generated)
|
||||
├── package.json
|
||||
├── tsconfig.json
|
||||
├── .gitignore
|
||||
└── README.md
|
||||
```
|
||||
32
package-lock.json
generated
Normal file
32
package-lock.json
generated
Normal file
@@ -0,0 +1,32 @@
|
||||
{
|
||||
"name": "@dpu/types",
|
||||
"version": "1.0.0",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "@dpu/types",
|
||||
"version": "1.0.0",
|
||||
"devDependencies": {
|
||||
"typescript": "^5.3.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"typescript": ">=4.5.0"
|
||||
}
|
||||
},
|
||||
"node_modules/typescript": {
|
||||
"version": "5.9.3",
|
||||
"resolved": "https://registry.npmjs.org/typescript/-/typescript-5.9.3.tgz",
|
||||
"integrity": "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw==",
|
||||
"dev": true,
|
||||
"license": "Apache-2.0",
|
||||
"bin": {
|
||||
"tsc": "bin/tsc",
|
||||
"tsserver": "bin/tsserver"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=14.17"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
27
package.json
Normal file
27
package.json
Normal file
@@ -0,0 +1,27 @@
|
||||
{
|
||||
"name": "@dpu/types",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "dist/index.js",
|
||||
"types": "dist/index.d.ts",
|
||||
"files": [
|
||||
"dist"
|
||||
],
|
||||
"scripts": {
|
||||
"build": "tsc",
|
||||
"prepublishOnly": "npm run build",
|
||||
"clean": "rm -rf dist"
|
||||
},
|
||||
"keywords": [
|
||||
"typescript",
|
||||
"types",
|
||||
"shared"
|
||||
],
|
||||
"author": "Darius",
|
||||
"devDependencies": {
|
||||
"typescript": "^5.3.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"typescript": ">=4.5.0"
|
||||
}
|
||||
}
|
||||
25
src/homeassistant.ts
Normal file
25
src/homeassistant.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
export type HomeAssistantEntity = {
|
||||
entity_id: string;
|
||||
state: string;
|
||||
attributes: {
|
||||
state_class?: string;
|
||||
unit_of_measurement?: string;
|
||||
icon?: string;
|
||||
friendly_name?: string;
|
||||
[key: string]: unknown;
|
||||
};
|
||||
last_changed: string; // datetime string
|
||||
last_reported: string; // datetime string
|
||||
last_updated: string; // datetime string
|
||||
context: {
|
||||
id: string;
|
||||
parent_id: string | null;
|
||||
user_id: string | null;
|
||||
};
|
||||
};
|
||||
|
||||
export interface HomeAssistantDeskPositionResult {
|
||||
raw: HomeAssistantEntity;
|
||||
asBoolean: boolean;
|
||||
asText: () => string;
|
||||
}
|
||||
2
src/index.ts
Normal file
2
src/index.ts
Normal file
@@ -0,0 +1,2 @@
|
||||
export * from "./homeassistant";
|
||||
export * from "./tidal";
|
||||
14
src/tidal.ts
Normal file
14
src/tidal.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
export type TidalSong = {
|
||||
title: string;
|
||||
artists: string;
|
||||
album: string;
|
||||
playingFrom: string;
|
||||
status: "playing" | "paused";
|
||||
url: string;
|
||||
current: string;
|
||||
duration: string;
|
||||
};
|
||||
|
||||
export type TidalVolume = {
|
||||
volume: number;
|
||||
};
|
||||
19
tsconfig.json
Normal file
19
tsconfig.json
Normal file
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "ES2020",
|
||||
"module": "commonjs",
|
||||
"lib": ["ES2020"],
|
||||
"declaration": true,
|
||||
"declarationMap": true,
|
||||
"outDir": "./dist",
|
||||
"rootDir": "./src",
|
||||
"strict": true,
|
||||
"esModuleInterop": true,
|
||||
"skipLibCheck": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"moduleResolution": "node",
|
||||
"resolveJsonModule": true
|
||||
},
|
||||
"include": ["src/**/*"],
|
||||
"exclude": ["node_modules", "dist"]
|
||||
}
|
||||
Reference in New Issue
Block a user