mirror of
https://github.com/zed-industries/zed.git
synced 2025-02-10 20:29:05 +00:00
refactor: add license file and check it exists
This commit is contained in:
parent
05d1dd6b11
commit
14efc18eca
2 changed files with 29 additions and 9 deletions
|
@ -1,11 +1,12 @@
|
||||||
import fs from "fs"
|
import fs from "fs"
|
||||||
import path from "path"
|
import path from "path"
|
||||||
import { ColorScheme, Meta } from "./themes/common/colorScheme"
|
import { ColorScheme, MetaAndLicense } from "./themes/common/colorScheme"
|
||||||
|
|
||||||
const THEMES_DIRECTORY = path.resolve(`${__dirname}/themes`)
|
const THEMES_DIRECTORY = path.resolve(`${__dirname}/themes`)
|
||||||
const STAFF_DIRECTORY = path.resolve(`${__dirname}/themes/staff`)
|
const STAFF_DIRECTORY = path.resolve(`${__dirname}/themes/staff`)
|
||||||
const IGNORE_ITEMS = ["staff", "common", "common.ts"]
|
const IGNORE_ITEMS = ["staff", "common", "common.ts"]
|
||||||
const ACCEPT_EXTENSION = ".ts"
|
const ACCEPT_EXTENSION = ".ts"
|
||||||
|
const LICENSE_FILE_NAME = "LICENSE"
|
||||||
|
|
||||||
function getAllTsFiles(directoryPath: string) {
|
function getAllTsFiles(directoryPath: string) {
|
||||||
const files = fs.readdirSync(directoryPath)
|
const files = fs.readdirSync(directoryPath)
|
||||||
|
@ -30,7 +31,9 @@ function getAllColorSchemes(directoryPath: string) {
|
||||||
const files = getAllTsFiles(directoryPath)
|
const files = getAllTsFiles(directoryPath)
|
||||||
return files.map((filePath) => ({
|
return files.map((filePath) => ({
|
||||||
colorScheme: require(filePath),
|
colorScheme: require(filePath),
|
||||||
filePath: path.basename(filePath),
|
filePath,
|
||||||
|
fileName: path.basename(filePath),
|
||||||
|
licenseFile: `${path.dirname(filePath)}/${LICENSE_FILE_NAME}`,
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,15 +48,27 @@ function getColorSchemes(directoryPath: string) {
|
||||||
return colorSchemes
|
return colorSchemes
|
||||||
}
|
}
|
||||||
|
|
||||||
function getMeta(directoryPath: string) {
|
function getMetaAndLicense(directoryPath: string) {
|
||||||
const meta: Meta[] = []
|
const meta: MetaAndLicense[] = []
|
||||||
|
|
||||||
for (const { colorScheme, filePath } of getAllColorSchemes(directoryPath)) {
|
for (const { colorScheme, filePath, licenseFile } of getAllColorSchemes(
|
||||||
if (colorScheme.meta) {
|
directoryPath
|
||||||
meta.push(colorScheme.meta)
|
)) {
|
||||||
} else {
|
const licenseExists = fs.existsSync(licenseFile)
|
||||||
|
if (!licenseExists) {
|
||||||
|
throw Error(
|
||||||
|
`Public theme should have a LICENSE file ${licenseFile}`
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!colorScheme.meta) {
|
||||||
throw Error(`Public theme ${filePath} must have a meta field`)
|
throw Error(`Public theme ${filePath} must have a meta field`)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
meta.push({
|
||||||
|
meta: colorScheme.meta,
|
||||||
|
licenseFile,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
return meta
|
return meta
|
||||||
|
@ -61,4 +76,4 @@ function getMeta(directoryPath: string) {
|
||||||
|
|
||||||
export const colorSchemes = getColorSchemes(THEMES_DIRECTORY)
|
export const colorSchemes = getColorSchemes(THEMES_DIRECTORY)
|
||||||
export const staffColorSchemes = getColorSchemes(STAFF_DIRECTORY)
|
export const staffColorSchemes = getColorSchemes(STAFF_DIRECTORY)
|
||||||
export const schemeMeta = getMeta(THEMES_DIRECTORY)
|
export const schemeMeta = getMetaAndLicense(THEMES_DIRECTORY)
|
||||||
|
|
|
@ -19,6 +19,11 @@ export interface ColorScheme {
|
||||||
syntax?: Partial<ThemeSyntax>
|
syntax?: Partial<ThemeSyntax>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface MetaAndLicense {
|
||||||
|
meta: Meta
|
||||||
|
licenseFile: string
|
||||||
|
}
|
||||||
|
|
||||||
export interface Meta {
|
export interface Meta {
|
||||||
name: string
|
name: string
|
||||||
author: string
|
author: string
|
||||||
|
|
Loading…
Reference in a new issue