From b302f11fc580e801155ebeef106ff0ab70f0daa9 Mon Sep 17 00:00:00 2001 From: Artrix <39530102+Artrix9095@users.noreply.github.com> Date: Sat, 12 Nov 2022 17:52:44 -0800 Subject: [PATCH 1/4] =?UTF-8?q?=F0=9F=94=A5=20Add=20Docusaurus=20Icon?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- icons/docusaurus.svg | 1 + src/icons/fileIcons.ts | 4 ++++ 2 files changed, 5 insertions(+) create mode 100644 icons/docusaurus.svg diff --git a/icons/docusaurus.svg b/icons/docusaurus.svg new file mode 100644 index 0000000000..250f2fce73 --- /dev/null +++ b/icons/docusaurus.svg @@ -0,0 +1 @@ + diff --git a/src/icons/fileIcons.ts b/src/icons/fileIcons.ts index 56fed89428..5051b0a6ea 100644 --- a/src/icons/fileIcons.ts +++ b/src/icons/fileIcons.ts @@ -2159,5 +2159,9 @@ export const fileIcons: FileIcons = { `.nanostagedrc`, ], }, + { + name: 'docusaurus', + fileNames: ['docusaurus.config.js'] + } ], }; From b3094449e74a256b3f21feb36e3fa0451ebb5f95 Mon Sep 17 00:00:00 2001 From: Artrix <39530102+Artrix9095@users.noreply.github.com> Date: Thu, 16 Feb 2023 09:29:28 -0800 Subject: [PATCH 2/4] Update icons/docusaurus.svg Co-authored-by: Z Mohamed (CTFL - CTTAE) <114668551+zm-cttae@users.noreply.github.com> --- icons/docusaurus.svg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/icons/docusaurus.svg b/icons/docusaurus.svg index 250f2fce73..05894a95ce 100644 --- a/icons/docusaurus.svg +++ b/icons/docusaurus.svg @@ -1 +1 @@ - + From 94e9ce8064716dcae11787102e6f35e10aa77246 Mon Sep 17 00:00:00 2001 From: Philipp Kief Date: Mon, 20 May 2024 12:29:50 +0200 Subject: [PATCH 3/4] =?UTF-8?q?feat:=20=E2=9A=99=EF=B8=8F=20Refactor=20pat?= =?UTF-8?q?tern=20code=20structure=20(#2326)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: ⚙️ Refactor pattern code structure * Rename type * feat: update barrels * feat: update recommended extensions for development * Add comment --- CONTRIBUTING.md | 13 ++- src/icons/fileIcons.ts | 105 ++++++++++++------------ src/{models => icons}/patterns/index.ts | 0 src/icons/patterns/libs.ts | 28 ------- src/icons/patterns/patterns.ts | 95 +++++++++++++++++++++ src/icons/patterns/utils.ts | 45 ---------- src/models/icons/files/fileIcon.ts | 6 ++ src/models/icons/index.ts | 7 +- src/models/icons/patterns/index.ts | 1 + src/models/icons/patterns/patterns.ts | 18 ++++ src/models/index.ts | 1 - src/models/patterns/patterns.ts | 8 -- 12 files changed, 182 insertions(+), 145 deletions(-) rename src/{models => icons}/patterns/index.ts (100%) delete mode 100644 src/icons/patterns/libs.ts create mode 100644 src/icons/patterns/patterns.ts delete mode 100644 src/icons/patterns/utils.ts create mode 100644 src/models/icons/patterns/index.ts create mode 100644 src/models/icons/patterns/patterns.ts delete mode 100644 src/models/patterns/patterns.ts diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 97494485fd..2a33d43d07 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -160,24 +160,23 @@ It is also possible to use patterns for file names and extensions. This is usefu ```ts { - name: 'sample', + name: 'graphql', patterns: { - sample: ['ecmascript'], - } + graphql: FileNamePattern.Ecmascript, + }, } ``` -In case of this example the generated file names are "sample.js", "sample.mjs", "sample.cjs", -sample.ts", "sample.mts" and "sample.cts". The pattern is defined in the [patterns.ts](src/icons/patterns/utils.ts) file. +In case of this example the generated file names are "graphql.js", "graphql.mjs", "graphql.cjs", "graphql.ts", "graphql.mts" and "graphql.cts". The pattern is defined in the [patterns.ts](src/icons/patterns/patterns.ts) file. -Allowed patterns are right now: +Available patterns are right now: | Pattern | File extensions | | ------------- | ---------------------------------------------------------------------------------------------------------- | | ecmascript | `js`, `mjs`, `cjs`, `ts`, `mts`, `cts` | | configuration | `json`, `jsonc`, `json5`, `yaml`, `yml`, `toml` | | nodeEcosystem | Combination of ecmascript and configuration patterns | -| cosmiconfig | Similar to nodeEcosystem but in form of `.${fileName}rc`, `.config/${fileName}rc` and `${fileName}.config` | +| cosmiconfig | `.${fileName}rc`, `.config/${fileName}rc` and `${fileName}.config` with file extensions of `nodeEcosystem` | #### Folder icons diff --git a/src/icons/fileIcons.ts b/src/icons/fileIcons.ts index b3817c4267..6fc47e7bba 100644 --- a/src/icons/fileIcons.ts +++ b/src/icons/fileIcons.ts @@ -1,6 +1,5 @@ -import { FileIcons, IconPack } from '../models/index'; -import { parseByPattern } from './patterns/libs'; -import { cosmiconfig, ecmascript } from './patterns/utils'; +import { FileIcons, FileNamePattern, IconPack } from '../models'; +import { parseByPattern } from './patterns'; /** * Defines file icons @@ -673,7 +672,7 @@ export const fileIcons: FileIcons = { fileExtensions: ['graphql', 'gql'], fileNames: ['.graphqlconfig'], patterns: { - graphql: cosmiconfig, + graphql: FileNamePattern.Ecmascript, }, }, { name: 'rust', fileExtensions: ['rs', 'ron'] }, @@ -973,14 +972,14 @@ export const fileIcons: FileIcons = { fileExtensions: ['pcss', 'sss'], fileNames: [], patterns: { - postcss: cosmiconfig, + postcss: FileNamePattern.Cosmiconfig, }, }, { name: 'posthtml', fileNames: [], patterns: { - posthtml: cosmiconfig, + posthtml: FileNamePattern.Cosmiconfig, }, }, { @@ -1013,41 +1012,41 @@ export const fileIcons: FileIcons = { name: 'webpack', fileNames: ['webpack.config.coffee'], patterns: { - 'webpack.base': ecmascript, - 'webpack.client': ecmascript, - 'webpack.common': ecmascript, - 'webpack.config.babel': ecmascript, - 'webpack.config.base.babel': ecmascript, - 'webpack.config.base': ecmascript, - 'webpack.config.client': ecmascript, - 'webpack.config.common.babel': ecmascript, - 'webpack.config.common': ecmascript, - 'webpack.config.dev.babel': ecmascript, - 'webpack.config.dev': ecmascript, - 'webpack.config.main': ecmascript, - 'webpack.config.prod.babel': ecmascript, - 'webpack.config.prod': ecmascript, - 'webpack.config.production.babel': ecmascript, - 'webpack.config.production': ecmascript, - 'webpack.config.renderer': ecmascript, - 'webpack.config.server': ecmascript, - 'webpack.config.staging.babel': ecmascript, - 'webpack.config.staging': ecmascript, - 'webpack.config.test': ecmascript, - 'webpack.config.vendor.production': ecmascript, - 'webpack.config.vendor': ecmascript, - 'webpack.config': ecmascript, - 'webpack.dev': ecmascript, - 'webpack.development': ecmascript, - 'webpack.dist': ecmascript, - 'webpack.mix': ecmascript, - 'webpack.prod.config': ecmascript, - 'webpack.prod': ecmascript, - 'webpack.production': ecmascript, - 'webpack.server': ecmascript, - 'webpack.test': ecmascript, - webpack: ecmascript, - webpackfile: ecmascript, + 'webpack.base': FileNamePattern.Ecmascript, + 'webpack.client': FileNamePattern.Ecmascript, + 'webpack.common': FileNamePattern.Ecmascript, + 'webpack.config.babel': FileNamePattern.Ecmascript, + 'webpack.config.base.babel': FileNamePattern.Ecmascript, + 'webpack.config.base': FileNamePattern.Ecmascript, + 'webpack.config.client': FileNamePattern.Ecmascript, + 'webpack.config.common.babel': FileNamePattern.Ecmascript, + 'webpack.config.common': FileNamePattern.Ecmascript, + 'webpack.config.dev.babel': FileNamePattern.Ecmascript, + 'webpack.config.dev': FileNamePattern.Ecmascript, + 'webpack.config.main': FileNamePattern.Ecmascript, + 'webpack.config.prod.babel': FileNamePattern.Ecmascript, + 'webpack.config.prod': FileNamePattern.Ecmascript, + 'webpack.config.production.babel': FileNamePattern.Ecmascript, + 'webpack.config.production': FileNamePattern.Ecmascript, + 'webpack.config.renderer': FileNamePattern.Ecmascript, + 'webpack.config.server': FileNamePattern.Ecmascript, + 'webpack.config.staging.babel': FileNamePattern.Ecmascript, + 'webpack.config.staging': FileNamePattern.Ecmascript, + 'webpack.config.test': FileNamePattern.Ecmascript, + 'webpack.config.vendor.production': FileNamePattern.Ecmascript, + 'webpack.config.vendor': FileNamePattern.Ecmascript, + 'webpack.config': FileNamePattern.Ecmascript, + 'webpack.dev': FileNamePattern.Ecmascript, + 'webpack.development': FileNamePattern.Ecmascript, + 'webpack.dist': FileNamePattern.Ecmascript, + 'webpack.mix': FileNamePattern.Ecmascript, + 'webpack.prod.config': FileNamePattern.Ecmascript, + 'webpack.prod': FileNamePattern.Ecmascript, + 'webpack.production': FileNamePattern.Ecmascript, + 'webpack.server': FileNamePattern.Ecmascript, + 'webpack.test': FileNamePattern.Ecmascript, + webpack: FileNamePattern.Ecmascript, + webpackfile: FileNamePattern.Ecmascript, }, }, { name: 'ionic', fileNames: ['ionic.config.json', '.io-config.json'] }, @@ -1130,8 +1129,8 @@ export const fileIcons: FileIcons = { name: 'babel', fileNames: ['babel-transform.js'], patterns: { - babel: cosmiconfig, - 'babel-plugin-macros': cosmiconfig, + babel: FileNamePattern.Cosmiconfig, + 'babel-plugin-macros': FileNamePattern.Cosmiconfig, }, }, { @@ -1249,7 +1248,7 @@ export const fileIcons: FileIcons = { '.eslintrc.base.json', ], patterns: { - eslint: cosmiconfig, + eslint: FileNamePattern.Cosmiconfig, }, }, { @@ -1339,7 +1338,7 @@ export const fileIcons: FileIcons = { light: true, fileNames: ['.stylelintignore', '.stylelintcache'], patterns: { - stylelint: cosmiconfig, + stylelint: FileNamePattern.Cosmiconfig, }, }, { name: 'code-climate', fileNames: ['.codeclimate.yml'], light: true }, @@ -1347,7 +1346,7 @@ export const fileIcons: FileIcons = { name: 'prettier', fileNames: ['.prettierignore'], patterns: { - prettier: cosmiconfig, + prettier: FileNamePattern.Cosmiconfig, }, }, { @@ -1535,7 +1534,7 @@ export const fileIcons: FileIcons = { light: true, fileNames: [], patterns: { - release: cosmiconfig, + release: FileNamePattern.Cosmiconfig, }, }, { @@ -1788,7 +1787,7 @@ export const fileIcons: FileIcons = { name: 'husky', fileNames: [], patterns: { - husky: cosmiconfig, + husky: FileNamePattern.Cosmiconfig, }, }, { name: 'coconut', fileExtensions: ['coco'] }, @@ -1815,7 +1814,7 @@ export const fileIcons: FileIcons = { name: 'commitlint', fileNames: ['.commitlint.yaml', '.commitlint.yml'], patterns: { - commitlint: cosmiconfig, + commitlint: FileNamePattern.Cosmiconfig, }, }, { name: 'buck', fileNames: ['.buckconfig'] }, @@ -2177,7 +2176,7 @@ export const fileIcons: FileIcons = { name: 'svgr', fileNames: [], patterns: { - svgr: cosmiconfig, + svgr: FileNamePattern.Cosmiconfig, }, }, { name: 'rome', fileNames: ['rome.json'] }, @@ -2284,7 +2283,7 @@ export const fileIcons: FileIcons = { name: 'craco', fileNames: [], patterns: { - craco: cosmiconfig, + craco: FileNamePattern.Cosmiconfig, }, }, { @@ -2340,7 +2339,7 @@ export const fileIcons: FileIcons = { name: 'syncpack', fileNames: [], patterns: { - syncpack: cosmiconfig, + syncpack: FileNamePattern.Cosmiconfig, }, }, { @@ -2394,7 +2393,7 @@ export const fileIcons: FileIcons = { name: 'puppeteer', fileNames: [], patterns: { - puppeteer: cosmiconfig, + puppeteer: FileNamePattern.Cosmiconfig, }, }, { name: 'apps-script', fileExtensions: ['gs'] }, diff --git a/src/models/patterns/index.ts b/src/icons/patterns/index.ts similarity index 100% rename from src/models/patterns/index.ts rename to src/icons/patterns/index.ts diff --git a/src/icons/patterns/libs.ts b/src/icons/patterns/libs.ts deleted file mode 100644 index e040189cf1..0000000000 --- a/src/icons/patterns/libs.ts +++ /dev/null @@ -1,28 +0,0 @@ -import { RawFileIcons, FileIcon, Patterns } from '../../models'; - -/** - * Maps the patterns to an array of strings. - * Each pattern is a function that generates file names based on a key. - * - * @param patterns The patterns to map. - * @returns An array of strings generated by applying the patterns. - */ -const mapPatterns = (patterns: Patterns): string[] => { - return Object.entries(patterns).flatMap(([fileName, pattern]) => - pattern(fileName) - ); -}; - -/** - * Parses the raw file icons by applying the patterns. - * A pattern helps to generate file names based on a key. - * - * @param rawFileIcons - The list of file icons without applied patterns. - * @returns The list of file icons with applied patterns. - */ -export const parseByPattern = (rawFileIcons: RawFileIcons): FileIcon[] => { - return rawFileIcons.map(({ patterns, fileNames = [], ...rest }) => ({ - ...rest, - fileNames: patterns ? [...mapPatterns(patterns), ...fileNames] : fileNames, - })); -}; diff --git a/src/icons/patterns/patterns.ts b/src/icons/patterns/patterns.ts new file mode 100644 index 0000000000..2bdf0c13b3 --- /dev/null +++ b/src/icons/patterns/patterns.ts @@ -0,0 +1,95 @@ +import { + FileIconWithPatterns, + FileIcon, + Patterns, + FileNamePattern, +} from '../../models'; + +/** + * Maps the patterns to an array of strings. + * Each pattern is a function that generates file names based on a key. + * + * @param patterns The patterns to map. + * @returns An array of strings generated by applying the patterns. + */ +const mapPatterns = (patterns: Patterns): string[] => { + return Object.entries(patterns).flatMap(([fileName, pattern]) => { + switch (pattern) { + case FileNamePattern.Ecmascript: + return [ + `${fileName}.js`, + `${fileName}.mjs`, + `${fileName}.cjs`, + `${fileName}.ts`, + `${fileName}.mts`, + `${fileName}.cts`, + ]; + + case FileNamePattern.Configuration: + return [ + `${fileName}.json`, + `${fileName}.jsonc`, + `${fileName}.json5`, + `${fileName}.yaml`, + `${fileName}.yml`, + `${fileName}.toml`, + ]; + + case FileNamePattern.NodeEcosystem: + return [ + `${fileName}.js`, + `${fileName}.mjs`, + `${fileName}.cjs`, + `${fileName}.ts`, + `${fileName}.mts`, + `${fileName}.cts`, + `${fileName}.json`, + `${fileName}.jsonc`, + `${fileName}.json5`, + `${fileName}.yaml`, + `${fileName}.yml`, + `${fileName}.toml`, + ]; + + case FileNamePattern.Cosmiconfig: + return [ + `.${fileName}rc`, + `.config/${fileName}rc`, + `${fileName}.config`, + `${fileName}.js`, + `${fileName}.mjs`, + `${fileName}.cjs`, + `${fileName}.ts`, + `${fileName}.mts`, + `${fileName}.cts`, + `${fileName}.json`, + `${fileName}.jsonc`, + `${fileName}.json5`, + `${fileName}.yaml`, + `${fileName}.yml`, + `${fileName}.toml`, + ]; + + default: + // Check if all potential pattern cases are handled + const exhaustiveCheck: never = pattern; + throw new Error(`Unhandled pattern: ${exhaustiveCheck}`); + } + }); +}; + +/** + * Parses the raw file icons by applying the patterns. + * A pattern helps to generate file names based on a key. + * + * @param rawFileIcons - The list of file icons without applied patterns. + * @returns The list of file icons with applied patterns. + */ +export const parseByPattern = ( + rawFileIcons: FileIconWithPatterns +): FileIcon[] => { + return rawFileIcons.map(({ patterns, fileNames = [], ...rest }) => ({ + ...rest, + fileNames: patterns ? [...mapPatterns(patterns), ...fileNames] : fileNames, + })); +}; diff --git a/src/icons/patterns/utils.ts b/src/icons/patterns/utils.ts deleted file mode 100644 index 902b8ee8f6..0000000000 --- a/src/icons/patterns/utils.ts +++ /dev/null @@ -1,45 +0,0 @@ -import { Method, PatternFunction } from '../../models'; - -const addNameExtensions = ( - fileName: string, - fileExtensions: string[] -): string[] => { - return fileExtensions.map((ext) => fileName + '.' + ext); -}; - -const ext: Record = { - CONF: ['json', 'jsonc', 'json5', 'yaml', 'yml', 'toml'], - ECMA: ['js', 'mjs', 'cjs', 'ts', 'mts', 'cts'], - get BOTH() { - return [...this.CONF, ...this.ECMA]; - }, -}; - -const to: Record = { - ECMA: (name) => addNameExtensions(name, ext.ECMA), - CONF: (name) => addNameExtensions(name, ext.CONF), - BOTH: (name) => addNameExtensions(name, ext.BOTH), - AsRC: (name) => [name, ...addNameExtensions(name, ext.BOTH)], -}; - -/** Adds the following extensions to the file name: `js`, `mjs`, `cjs`, `ts`, `mts`, `cts`. */ -export const ecmascript: PatternFunction = (fileName) => to.ECMA(fileName); - -/** Adds the following extensions to the file name: `json`, `jsonc`, `json5`, `yaml`, `yml`, `toml`. */ -export const configuration: PatternFunction = (fileName) => to.CONF(fileName); - -/** Adds the following extensions to the file name: `js`, `mjs`, `cjs`, `ts`, `mts`, `cts`, `json`, `jsonc`, `json5`, `yaml`, `yml`, `toml`. */ -export const nodeEcosystem: PatternFunction = (fileName) => to.BOTH(fileName); - -/** It adjusts the name with the following patterns: '.fileNamerc', '.config/fileNamerc', 'fileName.config' */ -export const cosmiconfig: PatternFunction = (fileName) => [ - ...to.AsRC(`.${fileName}rc`), - ...to.AsRC(`.config/${fileName}rc`), - ...to.BOTH(`${fileName}.config`), -]; - -export type PatternType = - | typeof ecmascript - | typeof configuration - | typeof nodeEcosystem - | typeof cosmiconfig; diff --git a/src/models/icons/files/fileIcon.ts b/src/models/icons/files/fileIcon.ts index 55b6278157..194e9d32f2 100644 --- a/src/models/icons/files/fileIcon.ts +++ b/src/models/icons/files/fileIcon.ts @@ -1,4 +1,5 @@ import { RequireAtLeastOne } from '../../../helpers/types'; +import { Patterns } from '../patterns'; import { CloneOptions } from '../cloneOptions'; import { IconPack } from '../index'; @@ -20,6 +21,11 @@ interface BasicFileIcon { */ fileNames?: string[]; + /** + * Define patterns for file names. Patterns are used to generate common file names and file extensions based on a key. + */ + patterns?: Patterns; + /** * Define if there is a light icon available. */ diff --git a/src/models/icons/index.ts b/src/models/icons/index.ts index fa6d579700..3e2c306151 100644 --- a/src/models/icons/index.ts +++ b/src/models/icons/index.ts @@ -1,6 +1,7 @@ +export * from './defaultIcon'; export * from './files'; export * from './folders'; -export * from './languages'; -export * from './iconPack'; export * from './iconJsonOptions'; -export * from './defaultIcon'; +export * from './iconPack'; +export * from './languages'; +export * from './patterns'; diff --git a/src/models/icons/patterns/index.ts b/src/models/icons/patterns/index.ts new file mode 100644 index 0000000000..99a3bc58b5 --- /dev/null +++ b/src/models/icons/patterns/index.ts @@ -0,0 +1 @@ +export * from './patterns'; diff --git a/src/models/icons/patterns/patterns.ts b/src/models/icons/patterns/patterns.ts new file mode 100644 index 0000000000..e2eaf3f285 --- /dev/null +++ b/src/models/icons/patterns/patterns.ts @@ -0,0 +1,18 @@ +import { FileIcon } from '..'; + +export enum FileNamePattern { + /** Adds the following extensions to the file name: `js`, `mjs`, `cjs`, `ts`, `mts`, `cts`. */ + Ecmascript = 'ecmascript', + + /** Adds the following extensions to the file name: `json`, `jsonc`, `json5`, `yaml`, `yml`, `toml`. */ + Configuration = 'configuration', + + /** Adds the following extensions to the file name: `js`, `mjs`, `cjs`, `ts`, `mts`, `cts`, `json`, `jsonc`, `json5`, `yaml`, `yml`, `toml`. */ + NodeEcosystem = 'nodeEcosystem', + + /** It adjusts the name with the following patterns: '.fileNamerc', '.config/fileNamerc', 'fileName.config' and combines that with the pattern NodeEcosystem */ + Cosmiconfig = 'cosmiconfig', +} + +export type Patterns = Record; +export type FileIconWithPatterns = (FileIcon & { patterns?: Patterns })[]; diff --git a/src/models/index.ts b/src/models/index.ts index 525e602570..0ac4462f6e 100644 --- a/src/models/index.ts +++ b/src/models/index.ts @@ -1,4 +1,3 @@ export * from './i18n'; export * from './iconConfiguration'; export * from './icons'; -export * from './patterns'; diff --git a/src/models/patterns/patterns.ts b/src/models/patterns/patterns.ts deleted file mode 100644 index 81fba19632..0000000000 --- a/src/models/patterns/patterns.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { PatternType } from '../../icons/patterns/utils'; -import { FileIcon } from '../icons'; - -export type Patterns = Record; -export type RawFileIcons = (FileIcon & { patterns?: Patterns })[]; - -export type Method = 'CONF' | 'ECMA' | 'BOTH'; -export type PatternFunction = (key: string) => string[]; From d4fab28a1d3892e2828edfd68a11903ef6b632b9 Mon Sep 17 00:00:00 2001 From: Artrix Date: Tue, 21 May 2024 09:05:56 -0700 Subject: [PATCH 4/4] Remove trailing comma Co-authored-by: Okinea Dev <81070564+okineadev@users.noreply.github.com> --- src/icons/fileIcons.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/icons/fileIcons.ts b/src/icons/fileIcons.ts index 711fad862a..2a2e0c1a98 100644 --- a/src/icons/fileIcons.ts +++ b/src/icons/fileIcons.ts @@ -2355,7 +2355,7 @@ export const fileIcons: FileIcons = { }, { name: 'docusaurus', - fileNames: ['docusaurus.config.js'] + fileNames: ['docusaurus.config.js'], }, { name: 'taskfile',