@finan-sbh/shared-common

v0.0.6

Published

Common shared utilities và providers cho ứng dụng **Sổ Bán Hàng** - hệ thống quản lý bán hàng của Finan.

Downloads

12

Readme

@finan-sbh/shared-common

Common shared utilities và providers cho ứng dụng Sổ Bán Hàng - hệ thống quản lý bán hàng của Finan.

📦 Cài đặt

npm install @finan-sbh/shared-common
# hoặc
yarn add @finan-sbh/shared-common

🚀 Cách dùng

import React from 'react'
import {CommonProvider, ShareValues, MAIN_APP_LIST} from '@finan-sbh/shared-common'

// 1. Wrap toàn bộ app với CommonProvider
const App = () => {
  return (
    <CommonProvider
      reduxProps={{store, persistor}}
      navigationProps={{onReady: () => console.log('Ready')}}
    >
      <YourAppContent />
    </CommonProvider>
  )
}

// 2. Sử dụng ShareValues để quản lý global state
ShareValues.setUserId('user123')
ShareValues.setBusinessId('business456')
const userId = ShareValues.getUserId()

// 3. Sử dụng constants
const currentApp = MAIN_APP_LIST.finanSobanhang

🏗️ React Native Builder Bob

Package này sử dụng react-native-builder-bob để build multiple formats:

Cấu hình trong package.json:

{
  "react-native-builder-bob": {
    "source": "src",
    "output": "lib",
    "targets": [["module", {"esm": true}], "typescript"]
  }
}

Cấu trúc thư mục sau khi build:

lib/
├── module/                    # ES Modules (cho bundlers hiện đại)
│   ├── index.js
│   ├── constants/
│   ├── contexts/
│   ├── globals/
│   └── types/
└── typescript/                # TypeScript definitions
    ├── index.d.ts
    ├── index.d.ts.map
    ├── constants/
    ├── contexts/
    ├── globals/
    └── types/

🧪 Test Local

Cách 1: npm link (Development)

# Trong thư mục shared-common
npm link

# Trong project muốn test
npm link @finan-sbh/shared-common

Cách 2: Test với file pack

# Build và tạo file package
yarn build
npm pack

# Install trong project khác
yarn add file:libs/shared-common/finan-sbh-shared-common-0.0.3.tgz

Cách 3: Monorepo (NX workspace)

{
  "dependencies": {
    "@finan-sbh/shared-common": "file:../shared-common"
  }
}

🚀 Deploy lên NPM

# Build trước khi publish
yarn build

# Tăng version
npm version patch    # 0.0.3 → 0.0.4
npm version minor    # 0.0.3 → 0.1.0
npm version major    # 0.0.3 → 1.0.0

# Publish (tự động build với prepare script)
npm publish --access public

# Kiểm tra đã publish
npm view @finan-sbh/shared-common

Phát triển cho hệ sinh thái Sổ Bán Hàng