Add more types to grammar and theme reading
This commit is contained in:
Родитель
9426f0c12e
Коммит
50104a72e8
|
@ -19,7 +19,7 @@ function file(language: Language, extension: Extension) {
|
|||
return path.join(__dirname, '..', `${language}.${extension}`);
|
||||
}
|
||||
|
||||
function writePlistFile(grammar: any, fileName: string) {
|
||||
function writePlistFile(grammar: TmGrammar | TmTheme, fileName: string) {
|
||||
const text = plist.build(grammar);
|
||||
fs.writeFileSync(fileName, text);
|
||||
}
|
||||
|
@ -35,20 +35,21 @@ function changeTsToTsx(str: string) {
|
|||
|
||||
function transformGrammarRule(rule: any, propertyNames: string[], transformProperty: (ruleProperty: string) => string) {
|
||||
for (const propertyName of propertyNames) {
|
||||
if (typeof rule[propertyName] === 'string') {
|
||||
rule[propertyName] = transformProperty(rule[propertyName]);
|
||||
const value = rule[propertyName];
|
||||
if (typeof value === 'string') {
|
||||
rule[propertyName] = transformProperty(value);
|
||||
}
|
||||
}
|
||||
|
||||
for (var propertyName in rule) {
|
||||
var value = rule[propertyName];
|
||||
const value = rule[propertyName];
|
||||
if (typeof value === 'object') {
|
||||
transformGrammarRule(value, propertyNames, transformProperty);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function transformGrammarRepository(grammar: any, propertyNames: string[], transformProperty: (ruleProperty: string) => string) {
|
||||
function transformGrammarRepository(grammar: TmGrammar, propertyNames: string[], transformProperty: (ruleProperty: string) => string) {
|
||||
const repository = grammar.repository;
|
||||
for (let key in repository) {
|
||||
transformGrammarRule(repository[key], propertyNames, transformProperty);
|
||||
|
@ -56,8 +57,8 @@ function transformGrammarRepository(grammar: any, propertyNames: string[], trans
|
|||
}
|
||||
|
||||
function getTsxGrammar() {
|
||||
let variables: any;
|
||||
const tsxUpdatesBeforeTransformation = readYaml(file(Language.TypeScriptReact, Extension.YamlTmLangauge));
|
||||
let variables: MapLike<string>;
|
||||
const tsxUpdatesBeforeTransformation = readYaml(file(Language.TypeScriptReact, Extension.YamlTmLangauge)) as TmGrammar;
|
||||
const grammar = getTsGrammar(tsGrammarVariables => {
|
||||
variables = tsGrammarVariables;
|
||||
for (const variableName in tsxUpdatesBeforeTransformation.variables) {
|
||||
|
@ -68,11 +69,10 @@ function getTsxGrammar() {
|
|||
const tsxUpdates = updateGrammarVariables(tsxUpdatesBeforeTransformation, variables);
|
||||
|
||||
// Update name, file types, scope name and uuid
|
||||
for (let key in tsxUpdates) {
|
||||
if (key !== "repository") {
|
||||
grammar[key] = tsxUpdates[key];
|
||||
}
|
||||
}
|
||||
grammar.name = tsxUpdates.name;
|
||||
grammar.scopeName = tsxUpdates.scopeName;
|
||||
grammar.fileTypes = tsxUpdates.fileTypes;
|
||||
grammar.uuid = tsxUpdates.uuid;
|
||||
|
||||
// Update scope names to .tsx
|
||||
transformGrammarRepository(grammar, ["name", "contentName"], changeTsToTsx);
|
||||
|
@ -84,7 +84,7 @@ function getTsxGrammar() {
|
|||
switch(key) {
|
||||
case "expressionWithoutIdentifiers":
|
||||
// Update expression
|
||||
repository[key].patterns.unshift(updatesRepository[key].patterns[0]);
|
||||
(repository[key] as TmGrammarRepositoryPatterns).patterns.unshift((updatesRepository[key] as TmGrammarRepositoryPatterns).patterns[0]);
|
||||
break;
|
||||
default:
|
||||
// Add jsx
|
||||
|
@ -95,8 +95,8 @@ function getTsxGrammar() {
|
|||
return grammar;
|
||||
}
|
||||
|
||||
function getTsGrammar(getVariables: (tsGrammarVariables: any) => any) {
|
||||
const tsGrammarBeforeTransformation = readYaml(file(Language.TypeScript, Extension.YamlTmLangauge));
|
||||
function getTsGrammar(getVariables: (tsGrammarVariables: MapLike<string>) => MapLike<string>) {
|
||||
const tsGrammarBeforeTransformation = readYaml(file(Language.TypeScript, Extension.YamlTmLangauge)) as TmGrammar;
|
||||
return updateGrammarVariables(tsGrammarBeforeTransformation, getVariables(tsGrammarBeforeTransformation.variables));
|
||||
}
|
||||
|
||||
|
@ -109,7 +109,7 @@ function replacePatternVariables(pattern: string, variableReplacers: VariableRep
|
|||
}
|
||||
|
||||
type VariableReplacer = [RegExp, string];
|
||||
function updateGrammarVariables(grammar: any, variables: any) {
|
||||
function updateGrammarVariables(grammar: TmGrammar, variables: MapLike<string>) {
|
||||
delete grammar.variables;
|
||||
const variableReplacers: VariableReplacer[] = [];
|
||||
for (const variableName in variables) {
|
||||
|
@ -136,15 +136,12 @@ function buildGrammar() {
|
|||
writePlistFile(tsxGrammar, file(Language.TypeScriptReact, Extension.TmLanguage));
|
||||
}
|
||||
|
||||
function changeTsToTsxTheme(theme: any) {
|
||||
const tsxUpdates = readYaml(file(Language.TypeScriptReact, Extension.YamlTmTheme));
|
||||
function changeTsToTsxTheme(theme: TmTheme) {
|
||||
const tsxUpdates = readYaml(file(Language.TypeScriptReact, Extension.YamlTmTheme)) as TmTheme;
|
||||
|
||||
// Update name, uuid
|
||||
for (let key in tsxUpdates) {
|
||||
if (key !== "settings") {
|
||||
theme[key] = tsxUpdates[key];
|
||||
}
|
||||
}
|
||||
theme.name = tsxUpdates.name;
|
||||
theme.uuid = tsxUpdates.uuid;
|
||||
|
||||
// Update scope names to .tsx
|
||||
const settings = theme.settings;
|
||||
|
@ -159,7 +156,7 @@ function changeTsToTsxTheme(theme: any) {
|
|||
}
|
||||
|
||||
function buildTheme() {
|
||||
const tsTheme = readYaml(file(Language.TypeScript, Extension.YamlTmTheme));
|
||||
const tsTheme = readYaml(file(Language.TypeScript, Extension.YamlTmTheme)) as TmTheme;
|
||||
|
||||
// Write TypeScript.tmTheme
|
||||
writePlistFile(tsTheme, file(Language.TypeScript, Extension.TmTheme));
|
||||
|
|
|
@ -1,3 +1,54 @@
|
|||
declare module "plist" {
|
||||
export function build(json: any): string;
|
||||
declare module "plist" {
|
||||
export function build(json: any): string;
|
||||
}
|
||||
|
||||
declare interface MapLike<T> {
|
||||
[s: string]: T;
|
||||
}
|
||||
|
||||
declare interface TmGrammarRuleName {
|
||||
name: string;
|
||||
}
|
||||
|
||||
declare interface TmGrammarRule {
|
||||
name?: string;
|
||||
}
|
||||
declare interface TmGrammarMatchRule extends TmGrammarRule {
|
||||
match: string;
|
||||
captures: MapLike<TmGrammarRuleName>;
|
||||
}
|
||||
declare interface TmGrammarBeginEndRule extends TmGrammarRule {
|
||||
contentName?: string;
|
||||
begin: string;
|
||||
end: string;
|
||||
beginCaptures?: MapLike<TmGrammarRuleName>;
|
||||
endCaptures?: MapLike<TmGrammarRuleName>;
|
||||
patterns: AnyTmGrammarRule[];
|
||||
}
|
||||
declare interface TmGrammarIncludeRule extends TmGrammarRule {
|
||||
include: string;
|
||||
}
|
||||
declare type AnyTmGrammarRule = TmGrammarMatchRule | TmGrammarBeginEndRule | TmGrammarIncludeRule;
|
||||
declare interface TmGrammarRepositoryPatterns {
|
||||
patterns: AnyTmGrammarRule[];
|
||||
}
|
||||
declare type TmGrammarRepositaryRule = AnyTmGrammarRule | TmGrammarRepositoryPatterns;
|
||||
declare interface TmGrammar {
|
||||
name: string;
|
||||
scopeName: string;
|
||||
fileTypes: string[];
|
||||
uuid: string;
|
||||
variables: MapLike<string>;
|
||||
patterns?: AnyTmGrammarRule[];
|
||||
repository: MapLike<TmGrammarRepositaryRule>;
|
||||
}
|
||||
|
||||
declare interface TmThemeSetting {
|
||||
scope: string;
|
||||
settings: { vsclassificationtype: string; };
|
||||
}
|
||||
declare interface TmTheme {
|
||||
name: string;
|
||||
uuid: string;
|
||||
settings: TmThemeSetting[];
|
||||
}
|
|
@ -2,7 +2,8 @@
|
|||
"compilerOptions": {
|
||||
"target": "ES5",
|
||||
"module": "commonjs",
|
||||
"noImplicitAny": true
|
||||
"noImplicitAny": true,
|
||||
"skipLibCheck": true
|
||||
},
|
||||
"exclude": [
|
||||
"node_modules"
|
||||
|
|
|
@ -5,24 +5,24 @@
|
|||
"requires": true,
|
||||
"dependencies": {
|
||||
"@types/chai": {
|
||||
"version": "4.1.2",
|
||||
"resolved": "https://registry.npmjs.org/@types/chai/-/chai-4.1.2.tgz",
|
||||
"integrity": "sha512-D8uQwKYUw2KESkorZ27ykzXgvkDJYXVEihGklgfp5I4HUP8D6IxtcdLTMB1emjQiWzV7WZ5ihm1cxIzVwjoleQ=="
|
||||
"version": "4.1.3",
|
||||
"resolved": "https://registry.npmjs.org/@types/chai/-/chai-4.1.3.tgz",
|
||||
"integrity": "sha512-f5dXGzOJycyzSMdaXVhiBhauL4dYydXwVpavfQ1mVCaGjR56a9QfklXObUxlIY9bGTmCPHEEZ04I16BZ/8w5ww=="
|
||||
},
|
||||
"@types/js-yaml": {
|
||||
"version": "3.10.1",
|
||||
"resolved": "https://registry.npmjs.org/@types/js-yaml/-/js-yaml-3.10.1.tgz",
|
||||
"integrity": "sha512-IpKg0KGIUNcydttaGURhSLrq1eSNoSjN7T1MokAuasIPBKzsHxcz3MAdFGzasmYQVWf6XxG+jQTJ9UFOL29Ubg=="
|
||||
"version": "3.11.1",
|
||||
"resolved": "https://registry.npmjs.org/@types/js-yaml/-/js-yaml-3.11.1.tgz",
|
||||
"integrity": "sha512-M5qhhfuTt4fwHGqqANNQilp3Htb5cHwBxlMHDUw/TYRVkEp3s3IIFSH3Fe9HIAeEtnO4p3SSowLmCVavdRYfpw=="
|
||||
},
|
||||
"@types/mocha": {
|
||||
"version": "2.2.48",
|
||||
"resolved": "https://registry.npmjs.org/@types/mocha/-/mocha-2.2.48.tgz",
|
||||
"integrity": "sha512-nlK/iyETgafGli8Zh9zJVCTicvU3iajSkRwOh3Hhiva598CMqNJ4NcVCGMTGKpGpTYj/9R8RLzS9NAykSSCqGw=="
|
||||
"version": "5.2.0",
|
||||
"resolved": "https://registry.npmjs.org/@types/mocha/-/mocha-5.2.0.tgz",
|
||||
"integrity": "sha512-YeDiSEzznwZwwp766SJ6QlrTyBYUGPSIwmREHVTmktUYiT/WADdWtpt9iH0KuUSf8lZLdI4lP0X6PBzPo5//JQ=="
|
||||
},
|
||||
"@types/node": {
|
||||
"version": "9.4.6",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-9.4.6.tgz",
|
||||
"integrity": "sha512-CTUtLb6WqCCgp6P59QintjHWqzf4VL1uPA27bipLAPxFqrtK1gEYllePzTICGqQ8rYsCbpnsNypXjjDzGAAjEQ=="
|
||||
"version": "10.0.0",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-10.0.0.tgz",
|
||||
"integrity": "sha512-kctoM36XiNZT86a7tPsUje+Q/yl+dqELjtYApi0T5eOQ90Elhu0MI10rmYk44yEP4v1jdDvtjQ9DFtpRtHf2Bw=="
|
||||
},
|
||||
"anymatch": {
|
||||
"version": "1.3.2",
|
||||
|
@ -107,11 +107,6 @@
|
|||
"resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz",
|
||||
"integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c="
|
||||
},
|
||||
"base64-js": {
|
||||
"version": "1.2.0",
|
||||
"resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.2.0.tgz",
|
||||
"integrity": "sha1-o5mS1yNYSBGYK+XikLtqU9hnAPE="
|
||||
},
|
||||
"binary-extensions": {
|
||||
"version": "1.11.0",
|
||||
"resolved": "https://registry.npmjs.org/binary-extensions/-/binary-extensions-1.11.0.tgz",
|
||||
|
@ -138,11 +133,6 @@
|
|||
"repeat-element": "1.1.2"
|
||||
}
|
||||
},
|
||||
"browser-stdout": {
|
||||
"version": "1.3.0",
|
||||
"resolved": "https://registry.npmjs.org/browser-stdout/-/browser-stdout-1.3.0.tgz",
|
||||
"integrity": "sha1-81HTKWnTL6XXpVZxVCY9korjvR8="
|
||||
},
|
||||
"chai": {
|
||||
"version": "4.1.2",
|
||||
"resolved": "https://registry.npmjs.org/chai/-/chai-4.1.2.tgz",
|
||||
|
@ -255,11 +245,6 @@
|
|||
"type-detect": "4.0.8"
|
||||
}
|
||||
},
|
||||
"diff": {
|
||||
"version": "3.3.1",
|
||||
"resolved": "https://registry.npmjs.org/diff/-/diff-3.3.1.tgz",
|
||||
"integrity": "sha512-MKPHZDMB0o6yHyDryUOScqZibp914ksXwAMYMTHj6KO8UeKsRYNJD3oNCKjTqZon+V488P7N/HzXF8t7ZR95ww=="
|
||||
},
|
||||
"duplexer": {
|
||||
"version": "0.1.1",
|
||||
"resolved": "https://registry.npmjs.org/duplexer/-/duplexer-0.1.1.tgz",
|
||||
|
@ -534,9 +519,9 @@
|
|||
}
|
||||
},
|
||||
"js-yaml": {
|
||||
"version": "3.10.0",
|
||||
"resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.10.0.tgz",
|
||||
"integrity": "sha512-O2v52ffjLa9VeM43J4XocZE//WT9N0IiwDa3KSHH7Tu8CtH+1qM8SIZvnsTh6v+4yFy5KUY3BHUVwjpfAWsjIA==",
|
||||
"version": "3.11.0",
|
||||
"resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.11.0.tgz",
|
||||
"integrity": "sha512-saJstZWv7oNeOyBh3+Dx1qWzhW0+e6/8eDzo7p5rDFqxntSztloLtuKu+Ejhtq82jsilwOIZYsCz+lIjthg1Hw==",
|
||||
"requires": {
|
||||
"argparse": "1.0.10",
|
||||
"esprima": "4.0.0"
|
||||
|
@ -610,20 +595,33 @@
|
|||
}
|
||||
},
|
||||
"mocha": {
|
||||
"version": "5.0.1",
|
||||
"resolved": "https://registry.npmjs.org/mocha/-/mocha-5.0.1.tgz",
|
||||
"integrity": "sha512-SpwyojlnE/WRBNGtvJSNfllfm5PqEDFxcWluSIgLeSBJtXG4DmoX2NNAeEA7rP5kK+79VgtVq8nG6HskaL1ykg==",
|
||||
"version": "5.1.1",
|
||||
"resolved": "https://registry.npmjs.org/mocha/-/mocha-5.1.1.tgz",
|
||||
"integrity": "sha512-kKKs/H1KrMMQIEsWNxGmb4/BGsmj0dkeyotEvbrAuQ01FcWRLssUNXCEUZk6SZtyJBi6EE7SL0zDDtItw1rGhw==",
|
||||
"requires": {
|
||||
"browser-stdout": "1.3.0",
|
||||
"browser-stdout": "1.3.1",
|
||||
"commander": "2.11.0",
|
||||
"debug": "3.1.0",
|
||||
"diff": "3.3.1",
|
||||
"diff": "3.5.0",
|
||||
"escape-string-regexp": "1.0.5",
|
||||
"glob": "7.1.2",
|
||||
"growl": "1.10.3",
|
||||
"he": "1.1.1",
|
||||
"minimatch": "3.0.4",
|
||||
"mkdirp": "0.5.1",
|
||||
"supports-color": "4.4.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"browser-stdout": {
|
||||
"version": "1.3.1",
|
||||
"resolved": "https://registry.npmjs.org/browser-stdout/-/browser-stdout-1.3.1.tgz",
|
||||
"integrity": "sha512-qhAVI1+Av2X7qelOfAIYwXONood6XlZE/fXaBSmW/T5SzLAmCgzi+eiWE7fUvbHaeNBQH13UftjpXxsfLkMpgw=="
|
||||
},
|
||||
"diff": {
|
||||
"version": "3.5.0",
|
||||
"resolved": "https://registry.npmjs.org/diff/-/diff-3.5.0.tgz",
|
||||
"integrity": "sha512-A46qtFgd+g7pDZinpnwiRJtxbC1hpgf0uzP3iG89scHk0AUC7A1TGxf5OiiOUv/JMZR8GOt8hL900hV0bOy5xA=="
|
||||
}
|
||||
}
|
||||
},
|
||||
"ms": {
|
||||
|
@ -700,13 +698,25 @@
|
|||
"integrity": "sha1-uULm1L3mUwBe9rcTYd74cn0GReA="
|
||||
},
|
||||
"plist": {
|
||||
"version": "2.1.0",
|
||||
"resolved": "https://registry.npmjs.org/plist/-/plist-2.1.0.tgz",
|
||||
"integrity": "sha1-V8zbeggh3yGDEhejytVOPhRqECU=",
|
||||
"version": "3.0.1",
|
||||
"resolved": "https://registry.npmjs.org/plist/-/plist-3.0.1.tgz",
|
||||
"integrity": "sha512-GpgvHHocGRyQm74b6FWEZZVRroHKE1I0/BTjAmySaohK+cUn+hZpbqXkc3KWgW3gQYkqcQej35FohcT0FRlkRQ==",
|
||||
"requires": {
|
||||
"base64-js": "1.2.0",
|
||||
"xmlbuilder": "8.2.2",
|
||||
"base64-js": "1.3.0",
|
||||
"xmlbuilder": "9.0.7",
|
||||
"xmldom": "0.1.27"
|
||||
},
|
||||
"dependencies": {
|
||||
"base64-js": {
|
||||
"version": "1.3.0",
|
||||
"resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.3.0.tgz",
|
||||
"integrity": "sha512-ccav/yGvoa80BQDljCxsmmQ3Xvx60/UpBIij5QN21W3wBi/hhIC9OoO+KLpu9IJTS9j4DRVJ3aDDF9cMSoa2lw=="
|
||||
},
|
||||
"xmlbuilder": {
|
||||
"version": "9.0.7",
|
||||
"resolved": "https://registry.npmjs.org/xmlbuilder/-/xmlbuilder-9.0.7.tgz",
|
||||
"integrity": "sha1-Ey7mPS7FVlxVfiD0wi35rKaGsQ0="
|
||||
}
|
||||
}
|
||||
},
|
||||
"preserve": {
|
||||
|
@ -921,9 +931,9 @@
|
|||
"integrity": "sha512-0fr/mIH1dlO+x7TlcMy+bIDqKPsw/70tVyeHW787goQjhmqaZe10uwLujubK9q9Lg6Fiho1KUKDYz0Z7k7g5/g=="
|
||||
},
|
||||
"typescript": {
|
||||
"version": "2.7.2",
|
||||
"resolved": "https://registry.npmjs.org/typescript/-/typescript-2.7.2.tgz",
|
||||
"integrity": "sha512-p5TCYZDAO0m4G344hD+wx/LATebLWZNkkh2asWUFqSsD2OrDNhbAHuSjobrmsUmdzjJjEeZVU9g1h3O6vpstnw=="
|
||||
"version": "2.8.3",
|
||||
"resolved": "https://registry.npmjs.org/typescript/-/typescript-2.8.3.tgz",
|
||||
"integrity": "sha512-K7g15Bb6Ra4lKf7Iq2l/I5/En+hLIHmxWZGq3D4DIRNFxMNV6j2SHSvDOqs2tGd4UvD/fJvrwopzQXjLrT7Itw=="
|
||||
},
|
||||
"util-deprecate": {
|
||||
"version": "1.0.2",
|
||||
|
@ -932,9 +942,9 @@
|
|||
"dev": true
|
||||
},
|
||||
"vscode-textmate": {
|
||||
"version": "3.2.0",
|
||||
"resolved": "https://registry.npmjs.org/vscode-textmate/-/vscode-textmate-3.2.0.tgz",
|
||||
"integrity": "sha1-h+WrHtMEYykac/4os3pYWQp3d9w=",
|
||||
"version": "3.3.3",
|
||||
"resolved": "https://registry.npmjs.org/vscode-textmate/-/vscode-textmate-3.3.3.tgz",
|
||||
"integrity": "sha512-nOYGc99fRUW+SsLumP6H5tq9CZ/sceId2TQakvBXcTcYeUdpPq2tCF8p8IzSewdaK1WpdrAEyx6oiEMHLySuwQ==",
|
||||
"requires": {
|
||||
"fast-plist": "0.1.2",
|
||||
"oniguruma": "6.2.1"
|
||||
|
@ -954,11 +964,6 @@
|
|||
"resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz",
|
||||
"integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8="
|
||||
},
|
||||
"xmlbuilder": {
|
||||
"version": "8.2.2",
|
||||
"resolved": "https://registry.npmjs.org/xmlbuilder/-/xmlbuilder-8.2.2.tgz",
|
||||
"integrity": "sha1-aSSGc0ELS6QuGmE2VR0pIjNap3M="
|
||||
},
|
||||
"xmldom": {
|
||||
"version": "0.1.27",
|
||||
"resolved": "https://registry.npmjs.org/xmldom/-/xmldom-0.1.27.tgz",
|
||||
|
|
|
@ -2,7 +2,8 @@
|
|||
"compilerOptions": {
|
||||
"target": "ES5",
|
||||
"module": "commonjs",
|
||||
"noImplicitAny": true
|
||||
"noImplicitAny": true,
|
||||
"skipLibCheck": true
|
||||
},
|
||||
"exclude": [
|
||||
"cases",
|
||||
|
|
Загрузка…
Ссылка в новой задаче