-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.js
51 lines (42 loc) · 1.1 KB
/
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
const { minimatch } = require('minimatch')
const fs = require('fs')
const p = require('path')
function recursiveReaddirSync(path) {
let list = []
const files = fs
.readdirSync(path)
.filter((file) => file !== 'node_modules' && file.charAt(0) !== '.')
let stats
files.forEach((file) => {
stats = fs.lstatSync(p.join(path, file))
if (stats.isDirectory()) {
list = list.concat(recursiveReaddirSync(p.join(path, file)))
} else {
list.push(p.join(path, file))
}
})
return list.filter((f) => minimatch(f, '**/*.json') || minimatch(f, '*.json'))
}
const files = recursiveReaddirSync(process.cwd())
let isTs = false
let reactVersion = 'detect'
while (files.length) {
const file = files.shift()
if (/tsconfig.json/.test(file)) {
isTs = true
continue
}
const pkg = require(file)
const { react } = pkg.dependencies || {}
if (react && typeof react === 'string') {
if (isNaN(Number(react.charAt(0)))) {
reactVersion = react.replace(react.charAt(0), '')
} else {
reactVersion = react
}
}
}
module.exports = {
isTs,
reactVersion
}