Home

tailwind-ctp-intellisense @1b730cb6568d8e19b160fe25bdb0b6f8157d174c - refs - log -
-
https://git.jolheiser.com/tailwind-ctp-intellisense.git
Tailwind intellisense + Catppuccin
tailwind-ctp-intellisense / packages / tailwindcss-language-server / scripts / createNoticesFile.mjs
- raw
 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import { writeFileSync } from 'fs'
import checker from 'license-checker'
import { readFileSync } from 'fs'
import { dirname, resolve } from 'path'
import { fileURLToPath } from 'url'

const exclude = [
  /^@types\//,
  'esbuild',
  'rimraf',
  'jest',
  'prettier',
  'typescript',
  'license-checker',
]

function isExcluded(name) {
  for (let pattern of exclude) {
    if (typeof pattern === 'string') {
      if (name === pattern) {
        return true
      }
    } else if (pattern.test(name)) {
      return true
    }
  }
  return false
}

function getDeps(dir, dev = false) {
  return Object.entries(
    JSON.parse(readFileSync(resolve(dir, 'package.json'), 'utf-8'))[
      dev ? 'devDependencies' : 'dependencies'
    ]
  ).map(([name, version]) => `${name}@${version}`)
}

function getLicenses(dir) {
  return new Promise((resolve, reject) => {
    checker.init({ start: dir }, (err, packages) => {
      if (err) {
        reject(err)
      } else {
        resolve(packages)
      }
    })
  })
}

;(async function () {
  const __dirname = dirname(fileURLToPath(import.meta.url))
  let contents = []

  let serverDeps = getDeps(resolve(__dirname, '..'), true)
  let serviceDeps = getDeps(resolve(__dirname, '../../tailwindcss-language-service'))
  let allDeps = [...serverDeps, ...serviceDeps]

  let serverLicenses = await getLicenses(resolve(__dirname, '../'))
  let serviceLicenses = await getLicenses(resolve(__dirname, '../../tailwindcss-language-service'))
  let allLicenses = { ...serverLicenses, ...serviceLicenses }

  for (let pkg in allLicenses) {
    let parts = pkg.split('@')
    let name = parts.slice(0, parts.length - 1).join('@')
    if (allDeps.includes(pkg) && !isExcluded(name)) {
      let license = allLicenses[pkg].licenseFile
        ? readFileSync(allLicenses[pkg].licenseFile, 'utf-8').trim()
        : undefined
      if (license) {
        contents.push(`${pkg}\n\n${license}`)
      }
    }
  }

  writeFileSync(
    resolve(__dirname, '../ThirdPartyNotices.txt'),
    contents.join(`\n\n${'='.repeat(80)}\n\n`),
    'utf-8'
  )
})()