tj
2025-06-05 bba272999cc546f65781bf3d20245a3f819af67f
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
52
// eslint-disable-next-line import/no-extraneous-dependencies
const path = require('path')
const fs = require('fs-extra')
const chalk = require('chalk')
const { came } = require('./util')
 
// 验证是否是插件
function isPlugin(source) {
  let result = true
  if (!fs.lstatSync(source).isDirectory()) {
    return false
  }
  const configPath = path.resolve(source, './stage-config.js')
  const packagePath = path.resolve(source, './package.json')
  if (result && !fs.existsSync(configPath)) {
    result = false
  }
  if (result && !fs.existsSync(packagePath)) {
    result = false
  }
  if (!result) {
    console.log(chalk.yellow(`${source} 不符合 Lin-CMS 插件规范`))
  }
 
  return result
}
 
function getPlugins(source) {
  if (!fs.existsSync(source)) {
    console.log(chalk.yellow(`目录不存在: ${source}`))
    return []
  }
  const folders = fs.readdirSync(source)
  const pluginsList = []
 
  folders.forEach(item => {
    const itemPath = path.join(source, item)
    if (!isPlugin(itemPath)) {
      return
    }
    const config = {}
    config.name = item
    config.camelCaseName = came(item)
    config.path = path.resolve(__dirname, `../src/plugins/${item}/`)
    config.packageCtx = JSON.parse(fs.readFileSync(path.resolve(itemPath, './package.json'), 'utf8'))
    pluginsList.push(config)
  })
 
  return pluginsList
}
 
module.exports = getPlugins