config

A Sumor Cloud Tool.
More Documentation Config Loader support yaml and json files. It can load all files in a directory. And automatically convert the file to the specified format.

CI Test Coverage Audit

Installation

npm i @sumor/config --save

Prerequisites

Node.JS version

Require Node.JS version 16.x or above

require Node.JS ES module

As this package is written in ES module, please change the following code in your package.json file:

{
  "type": "module"
}

Usage

entry methods

load

import { load } from '@sumor/config'

search

load all files in the directory

import { meta } from '@sumor/config'

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

/*
Demo directory structure
- root
  - car.json
  - car.sql
  - ship.js
  - plane.yml
*/

// it will load all config files as below
/*
{
  car: {
    name: 'car',
    sql: "..."
  },
  ship: {
    name: 'ship'
    // js file will not load
  },
  plane: {
    name: 'plane'
  }
}
*/

Legacy methods

find

import { find } from '@sumor/config'

findReference

import { findReference } from '@sumor/config'

Load config file

import { load } from '@sumor/config'

const config1 = await load(process.cwd(), 'demo')
// it will load demo.yml or demo.json in root directory

const config2 = await load(process.cwd(), 'demo', 'yaml')
// it will load demo.yml or demo.json in root directory, and convert it to yaml format file

Find config files

import { find } from '@sumor/config'

const config = await find(process.cwd(), 'entity')
// it will load all *.entity.yml or *.entity.json in root directory
/*
 * example:
 *   car.entity.yml, bike.entity.json
 *   {
 *       "car": {...}
 *       "bike": {...}
 *   }
 * */

Find config files from other files

such as .vue, .js files, it has same name config file

import { findReference } from '@sumor/config'

const config = await findReference(process.cwd(), ['vue', 'js'])
// it will load all *.entity.yml or *.entity.json which has same name with *.vue or *.js in root directory
/*
 * example:
 *   car.entity.yml, bike.entity.json
 *   car.vue, bike.js
 *   {
 *       "car": {...}
 *       "bike": {...}
 *   }
 * */