mirror of
https://github.com/microsoft/vscode.git
synced 2025-12-24 20:26:08 +00:00
Refactor darwinBundleDocumentType
Allow the caller to provide a specific file type description. The new function will not require source changes to existing calls, but will change how the file type description is generated. An unmodified call to darwinBundleDocumentType will use the given icon name as the file type description. All extensions passed to this function continue to use the same icon as before, and all extensions will have the same file type description as before.
This commit is contained in:
@@ -12,15 +12,54 @@ import * as filter from 'gulp-filter';
|
||||
import * as _ from 'underscore';
|
||||
import * as util from './util';
|
||||
|
||||
type DarwinDocumentSuffix = 'document' | 'script' | 'file' | 'source code';
|
||||
type DarwinDocumentType = {
|
||||
name: string,
|
||||
role: string,
|
||||
ostypes: string[],
|
||||
extensions: string[],
|
||||
iconFile: string,
|
||||
};
|
||||
|
||||
function isDocumentSuffix(str?: string): str is DarwinDocumentSuffix {
|
||||
return str != undefined && (
|
||||
str === 'document' || str === 'script' || str === 'file' || str === 'source code'
|
||||
);
|
||||
}
|
||||
|
||||
const root = path.dirname(path.dirname(__dirname));
|
||||
const product = JSON.parse(fs.readFileSync(path.join(root, 'product.json'), 'utf8'));
|
||||
const commit = util.getVersion(root);
|
||||
|
||||
const darwinCreditsTemplate = product.darwinCredits && _.template(fs.readFileSync(path.join(root, product.darwinCredits), 'utf8'));
|
||||
|
||||
function darwinBundleDocumentType(extensions: string[], icon: string) {
|
||||
/**
|
||||
* Generate a `DarwinDocumentType` given a list of file extensions, an icon name, and an optional suffix or file type name.
|
||||
* @param extensions A list of file extensions, such as `['bat', 'cmd']`
|
||||
* @param icon A sentence-cased file type name that matches the lowercase name of a darwin icon resource.
|
||||
* For example, `'HTML'` instead of `'html'`, or `'Java'` instead of `'java'`.
|
||||
* This parameter is lowercased before it is used to reference an icon file.
|
||||
* @param nameOrSuffix An optional suffix or a string to use as the file type. If a suffix is provided,
|
||||
* it is used with the icon parameter to generate a file type string. If nothing is provided,
|
||||
* `'document'` is used with the icon parameter to generate file type string.
|
||||
*
|
||||
* For example, if you call `darwinBundleDocumentType(..., 'HTML')`, the resulting file type is `"HTML document"`,
|
||||
* and the `'html'` darwin icon is used.
|
||||
*
|
||||
* If you call `darwinBundleDocumentType(..., 'Javascript', 'file')`, the resulting file type is `"Javascript file"`.
|
||||
* and the `'javascript'` darwin icon is used.
|
||||
*
|
||||
* If you call `darwinBundleDocumentType(..., 'bat', 'Windows command script')`, the file type is `"Windows command script"`,
|
||||
* and the `'bat'` darwin icon is used.
|
||||
*/
|
||||
function darwinBundleDocumentType(extensions: string[], icon: string, nameOrSuffix?: string | DarwinDocumentSuffix): DarwinDocumentType {
|
||||
// If given a suffix, generate a name from it. If not given anything, default to 'document'
|
||||
if (isDocumentSuffix(nameOrSuffix) || !nameOrSuffix) {
|
||||
nameOrSuffix = icon.charAt(0).toUpperCase() + icon.slice(1) + ' ' + (nameOrSuffix ?? 'document');
|
||||
}
|
||||
|
||||
return {
|
||||
name: product.nameLong + ' document',
|
||||
name: nameOrSuffix,
|
||||
role: 'Editor',
|
||||
ostypes: ['TEXT', 'utxt', 'TUTX', '****'],
|
||||
extensions: extensions,
|
||||
|
||||
Reference in New Issue
Block a user