UNPKG

668 BJavaScriptView Raw
1const fs = require('fs-extra');
2const path = require('path');
3const getCwd = require('../utils/get-cwd');
4
5/**
6 * 更新项目的 `package.json` 中的 `koot` 对象属性
7 * @param {*} data
8 */
9const 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
25module.exports = updateKootInPackageJson;