npm package: @smartlot-co/models
Description: Smartlot schemas and dto's
Latest version: 1.0.12


# 🔗 Testing Local with npm link

This guide explains how to test type packages locally using npm link before publishing them to npm.

## 📋 Prerequisites

- Node.js and npm installed
- Your type package with a valid package.json
- A consumer project to test the package

## 🎯 What is npm link?

`npm link` creates a symbolic link between your local package and the global npm registry. This allows other local projects to use it as if it were installed directly from npm.

## 🚀 Initial Setup

### Step 1: Prepare the Type Package

```bash
# Navigate to the package directory
cd /path/to/models

# Create the global link
npm link 
```

### Step 2: Connect in the Consumer Project

```bash
# Navigate to the project that uses the package
cd /path/to/consumer-project

# Link the local package
npm link @smartlot-co/models
```

## 🔄 Development Workflow

### During Development

1. **Make changes to your type package::**
   ```typescript
   export type CreateParkingLotDTO = Required<
     Pick<ParkingLot, "name" | "address" | /*...rest*/>
   > & Partial<Pick<ParkingLot, /*...optional fields*/>>;
   ```

2. **Rebuild the package::**
   ```bash
   cd /path/to/models
   npm run build
   ```

3. **The changes are reflected automatically::**
   ```typescript
   import { CreateParkingLotDTO } from 'smartlot-types';
   ```


## 🔍 Verify It's Working

### Verify the Link
```bash
# In the consumer project
ls -la node_modules/@smartlot-co/models

# See all active links
npm ls --link=true
```
## 🧹 Cleanup (Important!)

### When You Finish Developing

```bash
# 1. In the consumer project
cd /path/to/proyecto-consumidor
npm unlink @smartlot-co/models
npm install  # Reinstall the npm version

# 2. In the type package
cd /path/to/models
npm run dev:unlink # or manually:
npm unlink
```

### Verify Cleanup
```bash
# In the consumer project
npm ls @smartlot-co/models
#It should now show the npm version, not a local link.
```

## 📦 Before Publishing

### Pre-Publication Checklist

- [ ] Clean up links: `npm unlink` in both projects
- [ ] Install npm version (consumer project): `npm install --save @smartlot-co/models`
- [ ] Test that it works with the npm version (consumer project)
- [ ] Commit changes
- [ ] Push to GitHub
- [ ] Verify GitHub Actions

<br>
<br>
<br>

# 🔗 Testing local with Workflows

This guide explains how to work locally with the `@smartlot-co/models` package using npm link.
It also includes a pre-check script that ensures all required system dependencies are installed before running the workflow.

## ⚙️ Requirements
Make sure you have the following tools installed:

- Node.js >= 18
- npm >= 9
- jq (command-line JSON processor)

### Install jq
  ```bash
    sudo apt install jq -y
  ```

## Usage
  ```bash
  #1. Verify that you have the necessary dependencies
    chmod +x dev-workflow-pre-check.sh #make it executable
    ./dev-workflow-pre-check.sh start #{start|update|end}

  #2. Run exe
      chmod +x dev-workflow.sh #make it executable
    ./dev-workflow.sh start #{start|update|status|end}
  ```

## Commands
### Start: Prepares the package for local development
- Renames the package to `@smartlot-co/models-dev`
- Builds and links it globally
- Links it into the `TARGET_PROYECT_PATH`
- Shows how to update your imports temporarily
### Update: Rebuilds the package after changes
- Keeps your backend project linked to the dev version.
- Run this whenever you change code inside the package.
### End: Cleans up and restores everything.
- Unlinks the dev package from the `TARGET_PROYECT_PATH`.
- Restores the original package.json name.
- Reinstalls the published version of @smartlot-co/models.

## Recommended Workflow
  ```bash
  #1. Run dependency check:
    ./dev-workflow-pre-check.sh

  #2. Start local development:
    ./dev-workflow.sh start
  
  #3. Make changes in your package and update:
    ./dev-workflow.sh update
  
  #4. When finished, restore everything:
    ./dev-workflow.sh end
  ```

## Important Considerations
### 🔗 The Magic of npm link
When you use npm link, the `@smartlot-co/models-dev` package is symbolically linked globally on your system, and then a symbolic link is created locally in the `node_modules` folder of your target project.

Not a package.json dependency: This symbolic link bypasses the need to have the package listed in your server's package.json. You won't see `@smartlot-co/models-dev` listed there, as it's not an actual installed dependency.

TypeScript compatibility: If your target project is a TypeScript project, the compiler might not recognize symbolic links by default, resulting in a Cannot find module error. To fix this, you must add `"preserveSymlinks": true` to the compilerOptions in your `tsconfig.json` file.