1 | const fs = require('fs-extra');
|
2 | const path = require('path');
|
3 | const getCwd = require('../utils/get-cwd');
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 | const updateKootInPackageJson = async (data = {}) => {
|
10 | const file = path.resolve(getCwd(), 'package.json');
|
11 |
|
12 | if (!fs.existsSync(file))
|
13 | throw new Error('"package.json" not found in project directory.');
|
14 |
|
15 | const p = await fs.readJson(file);
|
16 | if (typeof p.koot !== 'object') p.koot = {};
|
17 |
|
18 | Object.assign(p.koot, data);
|
19 |
|
20 | await fs.writeJson(file, p, {
|
21 | spaces: 4
|
22 | });
|
23 | };
|
24 |
|
25 | module.exports = updateKootInPackageJson;
|