UNPKG

pinecone-cli

Version:
51 lines (50 loc) 2.02 kB
import fs from 'node:fs'; import path from 'node:path'; import slugify from '@sindresorhus/slugify'; import { readPackage } from 'read-pkg'; import { writePackage } from 'write-pkg'; import { log, toRelativePath } from '../utilities.js'; export const tidy = async ({ options, variants }) => { const safeFiles = [path.basename(options.source)]; const themes = []; const themesDir = './' + path.normalize(options.output); for (const variant of Object.keys(variants)) { const currentVariant = variants[variant]; if (typeof currentVariant !== 'undefined') { const { name, type } = currentVariant; const slug = slugify(name, { lowercase: true }); safeFiles.push(`${slug}-color-theme.json`); themes.push({ label: name, uiTheme: type === 'light' ? 'vs' : 'vs-dark', path: `${themesDir}/${slug}-color-theme.json`, }); if (options.includeNonItalicVariants) { safeFiles.push(`${slug}-no-italics-color-theme.json`); themes.push({ label: `${name} (no italics)`, uiTheme: type === 'light' ? 'vs' : 'vs-dark', path: `${themesDir}/${slug}-color-theme.json`, }); } } } // Remove non-pinecone themes from output directory const outputPath = toRelativePath(options.output); fs.readdir(outputPath, (error, files) => { if (error) { log.error(error.message); } for (const file of files) { const filePath = path.join(outputPath, file); if (!safeFiles.includes(file) && file.includes('-color-theme.json')) { try { fs.unlinkSync(filePath); } catch { } } } }); const pkg = await readPackage({ normalize: false }); await writePackage({ ...pkg, contributes: { themes: themes ?? [] } }); };