-
Notifications
You must be signed in to change notification settings - Fork 62
/
utils.js
34 lines (33 loc) · 1002 Bytes
/
utils.js
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
28
29
30
31
32
33
34
const { writeJsonSync } = require('fs-extra');
const shell = require('shelljs');
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);
};
/**
* transform array data to object with truly value
* @param arr{Array}
* @return {Object}
*/
module.exports.transformArr2TrueObj = arr =>
arr.reduce((pre, cur) => ({ ...pre, ...{ [cur]: true } }), {});
/**
* format code
* @param src{string} absolute path
* @return {number}
*/
module.exports.formatCode = src => {
return shell.exec(`npx prettier --loglevel error --write ${src} `).code;
};