forked from lgwebdream/fe-code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.js
More file actions
27 lines (26 loc) · 800 Bytes
/
utils.js
File metadata and controls
27 lines (26 loc) · 800 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
const { writeJsonSync } = require('fs-extra');
const { componentDependencies } = require('./dependencies.config');
/**
* patch dependencies to package.json
* @param packagesPath{string} package path
* @param main{string} react/vue
* @return {void}
*/
module.exports.patchPackageJson = ({ packagesPath, main }) => {
const packages = require(packagesPath);
const ds = componentDependencies[main];
ds &&
Reflect.ownKeys(ds).forEach(item => {
packages[item] = componentDependencies[item];
}) &&
writeJsonSync(packagesPath, packages, {
spaces: 2,
});
};
/**
* transform array data to object with truly value
* @param arr{Array}
* @return {Object}
*/
module.exports.transformArr2TrueObj = arr =>
arr.reduce((pre, cur) => ({ ...pre, ...{ [cur]: true } }), {});