From f1dd6de4e865355ea111cd367bf98d0325e5fd84 Mon Sep 17 00:00:00 2001 From: Tanner Bennett Date: Fri, 26 Feb 2021 13:55:41 -0600 Subject: [PATCH] Add darwinBundleDocumentTypes Split darwinBundleDocumentType into two separate functions. The first function is unchanged. The second function allows you to specify specific names for different groups of extensions while all sharing the same icon. For example, this would allow you to differentiate between a C header and a C source file while using the same icon for both. Inherently, the second function will generate multiple file type declarations, so it returns an array instead of a single object. As a result we must use the splat operator on it when passing the result to an array literal. --- build/lib/electron.ts | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/build/lib/electron.ts b/build/lib/electron.ts index d6ae906207c..f96173f8364 100644 --- a/build/lib/electron.ts +++ b/build/lib/electron.ts @@ -67,6 +67,30 @@ function darwinBundleDocumentType(extensions: string[], icon: string, nameOrSuff }; } +/** + * Generate several `DarwinDocumentType`s with unique names and a shared icon. + * @param types A map of file type names to their associated file extensions. + * @param icon A darwin icon resource to use. For example, `'HTML'` would refer to `resources/darwin/html.icns` + * + * Examples: + * ``` + * darwinBundleDocumentTypes({ 'C header file': 'h', 'C source code': 'c' },'c') + * darwinBundleDocumentTypes({ 'React source code': ['jsx', 'tsx'] }, 'react') + * ``` + */ +function darwinBundleDocumentTypes(types: { [name: string]: string | string[] }, icon: string): DarwinDocumentType[] { + return Object.keys(types).map((name: string): DarwinDocumentType => { + const extensions = types[name]; + return { + name: name, + role: 'Editor', + ostypes: ['TEXT', 'utxt', 'TUTX', '****'], + extensions: Array.isArray(extensions) ? extensions : [extensions], + iconFile: 'resources/darwin/' + icon + '.icns', + } as DarwinDocumentType; + }); +} + export const config = { version: util.getElectronVersion(), productAppName: product.nameLong,