1 | # [@cat-org/configs][website] · <!-- badges.start -->[![npm][npm-image]][npm-link] ![npm-size][npm-size-image]
|
2 |
|
3 | [npm-image]: https://img.shields.io/npm/v/@cat-org/configs.svg
|
4 | [npm-link]: https://www.npmjs.com/package/@cat-org/configs
|
5 | [npm-size-image]: https://img.shields.io/bundlephobia/minzip/@cat-org/configs.svg
|
6 |
|
7 |
|
8 |
|
9 | [website]: https://cat-org.github.io/core/configs
|
10 |
|
11 | Use to manage the multiple configs.
|
12 |
|
13 | ## Install
|
14 |
|
15 | ```sh
|
16 | yarn add @cat-org/configs --dev
|
17 | ```
|
18 |
|
19 | ## Run command
|
20 |
|
21 | Depend on the first argument, `@cat-org/configs` will run the command, generate the config file and use the default option.
|
22 |
|
23 | ```sh
|
24 | yarn configs babel
|
25 | ```
|
26 |
|
27 | In this case, this will generate `babel.config.js` and run `babel src -d lib --verbose`.
|
28 | You can also add other option to this command.
|
29 |
|
30 | ```sh
|
31 | yarn configs babel -w
|
32 | ```
|
33 |
|
34 | This command is equal to `babel src -d lib --verbose -w`.
|
35 |
|
36 | #### Get the configs lint
|
37 |
|
38 | ```sh
|
39 | yarn configs --info
|
40 | ```
|
41 |
|
42 | #### Get the information about the config
|
43 |
|
44 | By this option, you can get the detail of this config.
|
45 |
|
46 | ```sh
|
47 | yarn configs babel --info
|
48 | ```
|
49 |
|
50 | #### Download the packages from the config
|
51 |
|
52 | ```sh
|
53 | yarn configs babel --install
|
54 | ```
|
55 |
|
56 | In this case, this will run `yarn install @babel/cli @babel/core @cat-org/babel-plugin-base --dev`.
|
57 |
|
58 | ## Write config
|
59 |
|
60 | This module use [cosmiconfig](https://github.com/davidtheclark/cosmiconfig) to find the config file. The filename which is supported by `cosmiconfig` can be used.
|
61 |
|
62 | ```js
|
63 | module.exports = {
|
64 | // configsEnv is special key, this will give to the argument of the each config function
|
65 | configsEnv: ['react'],
|
66 |
|
67 | // overwrite the existing config by function
|
68 | babel: config => { ... },
|
69 |
|
70 | // overwrite the existing config by object
|
71 | jest: {
|
72 | config: config => { ... },
|
73 | },
|
74 |
|
75 | // add custom config, each field is optional
|
76 | custom: {
|
77 | aliase: 'babel', // run config with babel cli
|
78 | install: install => [ // install packages
|
79 | ...install,
|
80 | '@cat-org/configs',
|
81 | ],
|
82 | config: config => { // write the config
|
83 | ...config,
|
84 | key: 'value',
|
85 | },
|
86 | ignore: ignore => [ // generate ignore file
|
87 | ...ignore,
|
88 | 'node_modules'
|
89 | ],
|
90 | ignoreName: '.gitignore' // ignore filename
|
91 | run: argv => [ // command to run
|
92 | ...argv,
|
93 | 'src',
|
94 | '-d',
|
95 | 'lib',
|
96 | ],
|
97 | env: { // run command with environment
|
98 | NODE_ENV: 'development',
|
99 | },
|
100 | configFiles: { // link the config files. For example, `jest` need to run with `babel`, you need to add `babel: true`
|
101 | eslint: true,
|
102 | },
|
103 | },
|
104 | };
|
105 | ```
|