구성

Sumor Cloud 도구.
추가 문서 Config Loader는 yaml 및 json 파일을 지원합니다. 디렉토리의 모든 파일을 로드할 수 있습니다.
그리고 파일을 지정된 형식으로 자동으로 변환합니다.

CI Test Coverage Audit

설치

npm i @sumor/config --save

Prerequisites

Node.JS 버전

Node.JS 버전 16.x 이상이 필요합니다.

Node.JS ES 모듈 요구 사항

이 패키지는 ES 모듈로 작성되었기 때문에, package.json 파일에서 다음 코드를 변경해주셔야 합니다:

{
  "type": "module"
}

사용법

진입 메서드

load

import { load } from '@sumor/config'

search

디렉토리의 모든 파일을 로드합니다.

import { meta } from '@sumor/config'

const config = await meta(process.cwd(), ['sql'], ['js', 'sql'])

/*
데모 디렉토리 구조
- root
  - car.json
  - car.sql
  - ship.js
  - plane.yml
*/

// 아래와 같이 모든 config 파일을 로드합니다.
/*
{
  car: {
    name: 'car',
    sql: "..."
  },
  ship: {
    name: 'ship'
    // js 파일은 로드되지 않음
  },
  plane: {
    name: 'plane'
  }
}
*/

이전 방식 메서드

find

import { find } from '@sumor/config'

findReference

import { findReference } from '@sumor/config'

Config 파일 로드

import { load } from '@sumor/config'

const config1 = await load(process.cwd(), 'demo')
// 루트 디렉토리에 있는 demo.yml 또는 demo.json을 로드합니다.

const config2 = await load(process.cwd(), 'demo', 'yaml')
// 루트 디렉토리에 있는 demo.yml 또는 demo.json을 로드하고, yaml 형식 파일로 변환합니다.

Config 파일 찾기

import { find } from '@sumor/config'

const config = await find(process.cwd(), 'entity')
// 루트 디렉토리에서 모든 *.entity.yml 또는 *.entity.json을 로드합니다.
/*
 * 예시:
 *   car.entity.yml, bike.entity.json
 *   {
 *       "car": {...}
 *       "bike": {...}
 *   }
 * */

다른 파일에서 Config 파일 찾기

.vue, .js 파일과 같이, 같은 이름의 config 파일이 있는 경우

import { findReference } from '@sumor/config'

const config = await findReference(process.cwd(), ['vue', 'js'])
// 루트 디렉토리에서 *.vue 또는 *.js와 같은 이름의 *.entity.yml 또는 *.entity.json을 로드합니다.
/*
 * 예시:
 *   car.entity.yml, bike.entity.json
 *   car.vue, bike.js
 *   {
 *       "car": {...}
 *       "bike": {...}
 *   }
 * */