@tolgee/cli
Advanced tools
Comparing version 2.1.8 to 2.2.0
@@ -6,2 +6,3 @@ import tokenizer from './tokenizer.js'; | ||
import { ParserVue } from './parserVue/ParserVue.js'; | ||
import { ParserNgx } from './parserNgx/ParserNgx.js'; | ||
import { ParserSvelte } from './parserSvelte/ParserSvelte.js'; | ||
@@ -16,2 +17,4 @@ function pickParser(format) { | ||
return ParserSvelte(); | ||
case 'ngx': | ||
return ParserNgx(); | ||
} | ||
@@ -38,6 +41,10 @@ } | ||
if (debug) { | ||
console.log(JSON.stringify(result.tree, null, 2)); | ||
console.log(tokensList(tokensMerged)); | ||
console.log(visualizeRules(tokensMerged, code)); | ||
console.log(visualizeRules(tokensWithRules, code)); | ||
console.log(JSON.stringify(result.tree, null, 2) + | ||
'\n' + | ||
tokensList(tokensMerged) + | ||
'\n' + | ||
visualizeRules(tokensMerged, code) + | ||
'\n' + | ||
visualizeRules(tokensWithRules, code) + | ||
'\n'); | ||
} | ||
@@ -44,0 +51,0 @@ return result; |
@@ -17,7 +17,4 @@ import JSON5 from 'json5'; | ||
} | ||
function getEndLine(token) { | ||
return token.line + (token.token.match(/\n/gm)?.length ?? 0); | ||
} | ||
export function extractComment(token) { | ||
const comment = token.token.trim(); | ||
const comment = token.token.replaceAll(/[^\n]([\w]*\*+)/g, '').trim(); | ||
if (comment.startsWith('@tolgee-ignore')) { | ||
@@ -27,3 +24,3 @@ return { | ||
kind: 'ignore', | ||
line: getEndLine(token), | ||
line: token.line, | ||
}; | ||
@@ -39,3 +36,3 @@ } | ||
keyName: data.slice(1), | ||
line: getEndLine(token), | ||
line: token.line, | ||
}; | ||
@@ -52,3 +49,3 @@ } | ||
kind: 'W_INVALID_KEY_OVERRIDE', | ||
line: getEndLine(token), | ||
line: token.line, | ||
}; | ||
@@ -63,3 +60,3 @@ } | ||
defaultValue: key.defaultValue, | ||
line: getEndLine(token), | ||
line: token.line, | ||
}; | ||
@@ -72,3 +69,3 @@ } | ||
kind: 'W_MALFORMED_KEY_OVERRIDE', | ||
line: getEndLine(token), | ||
line: token.line, | ||
}; | ||
@@ -81,5 +78,5 @@ } | ||
keyName: data, | ||
line: getEndLine(token), | ||
line: token.line, | ||
}; | ||
} | ||
} |
@@ -16,5 +16,5 @@ export const generalMapper = (token) => { | ||
case 'punctuation.definition.string.begin.ts': | ||
return 'string.begin'; | ||
return 'string.quote'; | ||
case 'punctuation.definition.string.end.ts': | ||
return 'string.end'; | ||
return 'string.quote'; | ||
case 'string.quoted.single.ts': | ||
@@ -27,5 +27,5 @@ case 'string.quoted.double.ts': | ||
case 'punctuation.definition.string.template.begin.ts': | ||
return 'string.teplate.begin'; | ||
return 'string.teplate.quote'; | ||
case 'punctuation.definition.string.template.end.ts': | ||
return 'string.template.end'; | ||
return 'string.template.quote'; | ||
case 'string.template.ts': | ||
@@ -32,0 +32,0 @@ return 'string.template.body'; |
@@ -1,11 +0,13 @@ | ||
function defaultResultToken(matched) { | ||
return matched.map((t) => t.token).join(''); | ||
} | ||
const MERGE_ALL = Symbol('MERGE_ALL'); | ||
const MERGE_WITHOUT_LAST = Symbol('MERGE_WITHOUT_LAST'); | ||
const REPLACE_FIRST = Symbol('REPLACE_FIRST'); | ||
const MERGE_CUSTOM = Symbol('MERGE_CUSTOM'); | ||
export const endOptions = { | ||
MERGE_ALL, | ||
MERGE_WITHOUT_LAST, | ||
REPLACE_FIRST, | ||
MERGE_CUSTOM, | ||
}; | ||
function createNewToken(tokens, customType, merger) { | ||
const mergerData = merger?.(tokens); | ||
return { | ||
@@ -18,3 +20,4 @@ customType, | ||
line: tokens[0].line, | ||
token: merger(tokens), | ||
token: tokens.map((t) => t.token).join(''), | ||
...mergerData, | ||
}; | ||
@@ -38,11 +41,39 @@ } | ||
else if (newState === endOptions.MERGE_ALL || | ||
newState === endOptions.MERGE_WITHOUT_LAST) { | ||
const lastToken = newState === endOptions.MERGE_WITHOUT_LAST ? stack.pop() : undefined; | ||
const newToken = createNewToken(stack, machine.customType, machine.resultToken ?? defaultResultToken); | ||
state = machine.initial; | ||
stack = []; | ||
newState === endOptions.MERGE_WITHOUT_LAST || | ||
newState === endOptions.REPLACE_FIRST || | ||
newState === endOptions.MERGE_CUSTOM) { | ||
let before = []; | ||
let toMerge; | ||
let after; | ||
if (newState === endOptions.MERGE_ALL) { | ||
toMerge = stack; | ||
after = []; | ||
} | ||
else if (newState === endOptions.MERGE_WITHOUT_LAST) { | ||
after = [stack.pop()]; | ||
toMerge = stack; | ||
} | ||
else if (newState === endOptions.REPLACE_FIRST) { | ||
toMerge = [stack.shift()]; | ||
after = stack; | ||
} | ||
else { | ||
if (!machine.customMerge) { | ||
throw new Error('No custom merge cpecified'); | ||
} | ||
const result = machine.customMerge(stack); | ||
before = result.before; | ||
toMerge = result.toMerge; | ||
after = result.after; | ||
} | ||
const newToken = createNewToken(toMerge, machine.customType, machine.resultToken); | ||
for (const result of before) { | ||
yield result; | ||
} | ||
yield newToken; | ||
if (lastToken) { | ||
yield lastToken; | ||
for (const result of after) { | ||
yield result; | ||
} | ||
stack = []; | ||
state = machine.initial; | ||
continue; | ||
@@ -49,0 +80,0 @@ } |
@@ -25,4 +25,4 @@ export const closingTagMerger = { | ||
resultToken: (matched) => { | ||
return matched[1].token; | ||
return { token: matched[1].token }; | ||
}, | ||
}; |
@@ -15,3 +15,3 @@ export const commentsMerger = { | ||
} | ||
else if (type === 'comment.block') { | ||
else if (type === 'comment.block' || token.token === '\n') { | ||
return 2 /* S.CommentBlock */; | ||
@@ -31,8 +31,11 @@ } | ||
resultToken: (matched) => { | ||
return matched | ||
.filter((t) => t.customType && t.customType !== 'comment.definition') | ||
.map((t) => t.token) | ||
.join(''); | ||
return { | ||
token: matched | ||
.filter((t) => t.customType && t.customType !== 'comment.definition') | ||
.map((t) => t.token) | ||
.join(''), | ||
line: matched[matched.length - 1].line, | ||
}; | ||
}, | ||
customType: 'comment', | ||
}; |
@@ -8,6 +8,6 @@ import unescape from 'unescape-js'; | ||
case 0 /* S.Idle */: | ||
if (type === 'string.begin') { | ||
if (type === 'string.quote') { | ||
return 1 /* S.RegularString */; | ||
} | ||
else if (type === 'string.teplate.begin') { | ||
else if (type === 'string.teplate.quote') { | ||
return 2 /* S.TemplateString */; | ||
@@ -23,3 +23,3 @@ } | ||
} | ||
else if (type === 'string.end') { | ||
else if (type === 'string.quote') { | ||
return end.MERGE_ALL; | ||
@@ -35,3 +35,3 @@ } | ||
} | ||
else if (type === 'string.template.end') { | ||
else if (type === 'string.template.quote') { | ||
return end.MERGE_ALL; | ||
@@ -56,4 +56,4 @@ } | ||
.join(''); | ||
return unescape(escaped); | ||
return { token: unescape(escaped) }; | ||
}, | ||
}; |
@@ -53,4 +53,4 @@ export const templateStringMerger = { | ||
} | ||
return result.join('').trim(); | ||
return { token: result.join('').trim() }; | ||
}, | ||
}; |
@@ -1,2 +0,2 @@ | ||
function getCombinedOptions({ ns, noWrap, orEmpty, params, language, ...rest }, line) { | ||
export function getCombinedOptions({ ns, noWrap, orEmpty, params, language, ...rest }, line) { | ||
const options = { | ||
@@ -3,0 +3,0 @@ ns: ns, |
@@ -5,5 +5,5 @@ export const svelteMapper = (token) => { | ||
case 'punctuation.definition.string.begin.svelte': | ||
return 'string.begin'; | ||
return 'string.quote'; | ||
case 'punctuation.definition.string.end.svelte': | ||
return 'string.end'; | ||
return 'string.quote'; | ||
case 'string.quoted.svelte': | ||
@@ -10,0 +10,0 @@ return 'string.body'; |
@@ -27,5 +27,5 @@ export const vueMapper = (token) => { | ||
case 'punctuation.definition.string.begin.html': | ||
return 'string.begin'; | ||
return 'string.quote'; | ||
case 'punctuation.definition.string.end.html': | ||
return 'string.end'; | ||
return 'string.quote'; | ||
case 'string.quoted.single.html': | ||
@@ -32,0 +32,0 @@ case 'string.quoted.double.html': |
@@ -19,3 +19,10 @@ import glob from 'fast-glob'; | ||
const possibleFrameworks = []; | ||
const extensions = new Set(fileNames.map((name) => extname(name))); | ||
const extensions = new Set(fileNames.map((name) => { | ||
if (name.endsWith('.component.html')) { | ||
return '.component.html'; | ||
} | ||
else { | ||
return extname(name); | ||
} | ||
})); | ||
if (extensions.has('.jsx') || extensions.has('.tsx')) { | ||
@@ -30,2 +37,5 @@ possibleFrameworks.push('react'); | ||
} | ||
if (extensions.has('.component.html')) { | ||
possibleFrameworks.push('ngx'); | ||
} | ||
return possibleFrameworks; | ||
@@ -32,0 +42,0 @@ } |
@@ -12,2 +12,3 @@ import { extname } from 'path'; | ||
["source.vue" /* Grammar.VUE */]: new URL('Vue.tmLanguage', GRAMMAR_PATH), | ||
["html-template.ng" /* Grammar.ANGULAR_HTML */]: new URL('AngularHtml.tmLanguage', GRAMMAR_PATH), | ||
["text.html.basic" /* Grammar.HTML */]: new URL('HTML.tmLanguage', GRAMMAR_PATH), | ||
@@ -37,4 +38,5 @@ ["text.html.derivative" /* Grammar.HTML_D */]: new URL('HTML.tmLanguage', GRAMMAR_PATH), | ||
} | ||
function extnameToGrammar(extname) { | ||
switch (extname) { | ||
function fileNameToGrammar(fileName) { | ||
const ext = extname(fileName); | ||
switch (ext) { | ||
case '.js': | ||
@@ -55,3 +57,8 @@ case '.mjs': | ||
case '.html': | ||
return "text.html.basic" /* Grammar.HTML */; | ||
if (/.*\.component\.html/.test(fileName)) { | ||
return "html-template.ng" /* Grammar.ANGULAR_HTML */; | ||
} | ||
else { | ||
return "text.html.basic" /* Grammar.HTML */; | ||
} | ||
} | ||
@@ -104,6 +111,5 @@ } | ||
} | ||
const fileType = extname(fileName); | ||
const grammarName = extnameToGrammar(fileType); | ||
const grammarName = fileNameToGrammar(fileName); | ||
if (!grammarName) { | ||
throw new Error(`Cannot find grammar for file type ${fileType}`); | ||
throw new Error(`Cannot find grammar for file type ${fileName}`); | ||
} | ||
@@ -110,0 +116,0 @@ const grammar = await registry.loadGrammar(grammarName); |
@@ -62,3 +62,3 @@ import { existsSync } from 'fs'; | ||
export const DEFAULT_NAMESPACE = new Option('--default-namespace <namespace>', 'Default namespace used in extraction if not specified otherwise.'); | ||
export const PARSER = new Option('--parser <parser>', 'Override parser detection.').choices(['react', 'vue', 'svelte']); | ||
export const PARSER = new Option('--parser <parser>', 'Override parser detection.').choices(['react', 'vue', 'svelte', 'ngx']); | ||
export const VERBOSE = new Option('-v, --verbose [rules...]', 'Enable verbose logging. If you want more info to be logged pass an option.').choices(['extractor']); |
@@ -21,3 +21,3 @@ export type Key = { | ||
}; | ||
export type ParserType = 'react' | 'vue' | 'svelte'; | ||
export type ParserType = 'react' | 'vue' | 'svelte' | 'ngx'; | ||
export type Extractor = (fileContents: string, fileName: string, options: ExtractOptions) => ExtractionResult; | ||
@@ -24,0 +24,0 @@ export type ExtractionResult = { |
{ | ||
"name": "@tolgee/cli", | ||
"version": "2.1.8", | ||
"version": "2.2.0", | ||
"type": "module", | ||
@@ -5,0 +5,0 @@ "description": "A tool to interact with the Tolgee Platform through CLI", |
@@ -36,3 +36,3 @@ { | ||
"description": "Override parser detection.", | ||
"enum": ["react", "vue", "svelte"] | ||
"enum": ["react", "vue", "svelte", "ngx"] | ||
}, | ||
@@ -39,0 +39,0 @@ "push": { |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
905070
129
4968