Compare commits

...

8 Commits

Author SHA1 Message Date
Kim Biesbjerg
24ebd8f428 (bugfix) extract strings encapsulated with backticks. Closes #139 2019-08-26 12:29:52 +02:00
Kim Biesbjerg
e1bb5bfd02 bump version 2019-08-21 10:02:31 +02:00
Kim Biesbjerg
1323c2e6a1 update dependencies 2019-08-21 10:02:07 +02:00
Steven Liekens
0f465014df Use github URL syntax (#135) 2019-08-21 09:58:02 +02:00
Kim Biesbjerg
5d5b07ba2c bump version 2019-08-03 11:30:50 +02:00
Kim Biesbjerg
7eefd6c8d3 fix donation message colors 2019-08-03 11:30:30 +02:00
Kim Biesbjerg
50fd3ae9e2 (chore) bump version 2019-08-02 13:34:45 +02:00
Kim Biesbjerg
a5b8f6e6c6 (bugfix) order of keys was not preserved when using namespaced-json format. Closes #131 2019-08-02 13:34:18 +02:00
9 changed files with 92 additions and 58 deletions

71
package-lock.json generated
View File

@@ -1,21 +1,21 @@
{
"name": "@biesbjerg/ngx-translate-extract",
"version": "2.3.4",
"version": "3.0.2",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
"@angular/compiler": {
"version": "8.1.3",
"resolved": "https://registry.npmjs.org/@angular/compiler/-/compiler-8.1.3.tgz",
"integrity": "sha512-mKeRkpPy/iBPGBCVQIPF9x4f1S68ilEYaQTTfHoLR0OfivEQsyGuf2GEegwbTosEBX3JF+0JHfCNvsAE1zI5Og==",
"version": "8.2.2",
"resolved": "https://registry.npmjs.org/@angular/compiler/-/compiler-8.2.2.tgz",
"integrity": "sha512-UMhOQehvi9u1r4u48Ymwm5JkdOKoH057ImCo26WqRqJBUgA44xwmUsKLFAmSg1JqzWCO5pBDyA3RaNBscD8ZzQ==",
"requires": {
"tslib": "^1.9.0"
}
},
"@babel/code-frame": {
"version": "7.0.0",
"resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.0.0.tgz",
"integrity": "sha512-OfC2uemaknXr87bdLUkWog7nYuliM9Ij5HUcajsVcMCpQrcLmtxRbVFTIqmcSkSeYRBFBRxs2FiUqFJDLdiebA==",
"version": "7.5.5",
"resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.5.5.tgz",
"integrity": "sha512-27d4lZoomVyo51VegxI20xZPuSHusqbQag/ztrBC7wegWoQ1nLREPVSKSW8byhTlzTKyNE4ifaTA6lCp7JjpFw==",
"dev": true,
"requires": {
"@babel/highlight": "^7.0.0"
@@ -33,9 +33,9 @@
}
},
"@types/chai": {
"version": "4.1.7",
"resolved": "https://registry.npmjs.org/@types/chai/-/chai-4.1.7.tgz",
"integrity": "sha512-2Y8uPt0/jwjhQ6EiluT0XCri1Dbplr0ZxfFXUz+ye13gaqE8u5gL5ppao1JrUYr9cIip5S6MvQzBS7Kke7U9VA==",
"version": "4.2.0",
"resolved": "https://registry.npmjs.org/@types/chai/-/chai-4.2.0.tgz",
"integrity": "sha512-zw8UvoBEImn392tLjxoavuonblX/4Yb9ha4KBU10FirCfwgzhKO0dvyJSF9ByxV1xK1r2AgnAi/tvQaLgxQqxA==",
"dev": true
},
"@types/events": {
@@ -89,9 +89,9 @@
"dev": true
},
"@types/yargs": {
"version": "13.0.1",
"resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-13.0.1.tgz",
"integrity": "sha512-7X+FaCpRQ1scFQnWUY0TnVuuNaP5ajN45IGmwHVkAbsH1g4txz4hNb6sjJeR/wLaqUdNoInOwLk7oRL5M4zVFA==",
"version": "13.0.2",
"resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-13.0.2.tgz",
"integrity": "sha512-lwwgizwk/bIIU+3ELORkyuOgDjCh7zuWDFqRtPPhhVgq9N1F7CvLNKg1TX4f2duwtKQ0p044Au9r1PLIXHrIzQ==",
"dev": true,
"requires": {
"@types/yargs-parser": "*"
@@ -483,9 +483,9 @@
"dev": true
},
"esutils": {
"version": "2.0.2",
"resolved": "https://registry.npmjs.org/esutils/-/esutils-2.0.2.tgz",
"integrity": "sha1-Cr9PHKpbyx96nYrMbepPqqBLrJs=",
"version": "2.0.3",
"resolved": "https://registry.npmjs.org/esutils/-/esutils-2.0.3.tgz",
"integrity": "sha512-kVscqXk4OCp68SZ0dkgEKVi6/8ij300KBWTJq32P/dYeWTSwK41WyTxalN1eRmA5Z9UU/LX9D7FWSmV9SAYx6g==",
"dev": true
},
"execa": {
@@ -512,9 +512,8 @@
}
},
"flat": {
"version": "4.1.0",
"resolved": "https://registry.npmjs.org/flat/-/flat-4.1.0.tgz",
"integrity": "sha512-Px/TiLIznH7gEDlPXcUD4KnBusa6kR6ayRUVcnEAbreRIuhkqow/mun59BuRXwoYk7ZQOLW1ZM05ilIvK38hFw==",
"version": "github:lenchvolodymyr/flat#ffe77efe8c33bc80ffb2f7a465537610dea4f611",
"from": "github:lenchvolodymyr/flat#ffe77ef",
"requires": {
"is-buffer": "~2.0.3"
}
@@ -1091,9 +1090,9 @@
"integrity": "sha512-NKN5kMDylKuldxYLSUfrbo5Tuzh4hd+2E8NPPX02mZtn1VuREQToYe/ZdlJy+J3uCpfaiGF05e7B8W0iXbQHmg=="
},
"resolve": {
"version": "1.11.1",
"resolved": "https://registry.npmjs.org/resolve/-/resolve-1.11.1.tgz",
"integrity": "sha512-vIpgF6wfuJOZI7KKKSP+HmiKggadPQAdsp5HiC1mvqnfp0gF1vdwgBWZIdrVft9pgqoMFQN+R7BSWZiBxx+BBw==",
"version": "1.12.0",
"resolved": "https://registry.npmjs.org/resolve/-/resolve-1.12.0.tgz",
"integrity": "sha512-B/dOmuoAik5bKcD6s6nXDCjzUKnaDvdkRyAk6rsmsKLipWj4797iothd7jmmUhWTfinVMU+wc56rYKsit2Qy4w==",
"dev": true,
"requires": {
"path-parse": "^1.0.6"
@@ -1269,14 +1268,14 @@
}
},
"tslib": {
"version": "1.9.3",
"resolved": "https://registry.npmjs.org/tslib/-/tslib-1.9.3.tgz",
"integrity": "sha512-4krF8scpejhaOgqzBEcGM7yDIEfi0/8+8zDRZhNZZ2kjmHJ4hv3zCbQWxoJGz1iw5U0Jl0nma13xzHXcncMavQ=="
"version": "1.10.0",
"resolved": "https://registry.npmjs.org/tslib/-/tslib-1.10.0.tgz",
"integrity": "sha512-qOebF53frne81cf0S9B41ByenJ3/IuH8yJKngAX35CmiZySA0khhkovshKK+jGCaMnVomla7gVlIcc3EvKPbTQ=="
},
"tslint": {
"version": "5.18.0",
"resolved": "https://registry.npmjs.org/tslint/-/tslint-5.18.0.tgz",
"integrity": "sha512-Q3kXkuDEijQ37nXZZLKErssQVnwCV/+23gFEMROi8IlbaBG6tXqLPQJ5Wjcyt/yHPKBC+hD5SzuGaMora+ZS6w==",
"version": "5.19.0",
"resolved": "https://registry.npmjs.org/tslint/-/tslint-5.19.0.tgz",
"integrity": "sha512-1LwwtBxfRJZnUvoS9c0uj8XQtAnyhWr9KlNvDIdB+oXyT+VpsOAaEhEgKi1HrZ8rq0ki/AAnbGSv4KM6/AfVZw==",
"dev": true,
"requires": {
"@babel/code-frame": "^7.0.0",
@@ -1491,11 +1490,12 @@
"integrity": "sha512-r9S/ZyXu/Xu9q1tYlpsLIsa3EeLXXk0VwlxqTcFRfg9EhMW+17kbt9G0NrgCmhGb5vT2hyhJZLfDGx+7+5Uj/w=="
},
"yargs": {
"version": "13.3.0",
"resolved": "https://registry.npmjs.org/yargs/-/yargs-13.3.0.tgz",
"integrity": "sha512-2eehun/8ALW8TLoIl7MVaRUrg+yCnenu8B4kBlRxj3GJGDKU1Og7sMXPNm1BYyM1DOJmTZ4YeN/Nwxv+8XJsUA==",
"version": "14.0.0",
"resolved": "https://registry.npmjs.org/yargs/-/yargs-14.0.0.tgz",
"integrity": "sha512-ssa5JuRjMeZEUjg7bEL99AwpitxU/zWGAGpdj0di41pOEmJti8NR6kyUIJBkR78DTYNPZOU08luUo0GTHuB+ow==",
"requires": {
"cliui": "^5.0.0",
"decamelize": "^1.2.0",
"find-up": "^3.0.0",
"get-caller-file": "^2.0.1",
"require-directory": "^2.1.1",
@@ -1582,6 +1582,15 @@
"yargs": "^12.0.5"
},
"dependencies": {
"flat": {
"version": "4.1.0",
"resolved": "https://registry.npmjs.org/flat/-/flat-4.1.0.tgz",
"integrity": "sha512-Px/TiLIznH7gEDlPXcUD4KnBusa6kR6ayRUVcnEAbreRIuhkqow/mun59BuRXwoYk7ZQOLW1ZM05ilIvK38hFw==",
"dev": true,
"requires": {
"is-buffer": "~2.0.3"
}
},
"get-caller-file": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/get-caller-file/-/get-caller-file-1.0.3.tgz",

View File

@@ -1,6 +1,6 @@
{
"name": "@biesbjerg/ngx-translate-extract",
"version": "3.0.0",
"version": "3.0.4",
"description": "Extract strings from projects using ngx-translate",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
@@ -44,29 +44,29 @@
},
"config": {},
"devDependencies": {
"@types/chai": "^4.1.7",
"@types/chai": "^4.2.0",
"@types/flat": "^0.0.28",
"@types/glob": "^7.1.1",
"@types/mkdirp": "^0.5.2",
"@types/mocha": "^5.2.7",
"@types/yargs": "^13.0.1",
"@types/yargs": "^13.0.2",
"chai": "^4.2.0",
"mocha": "^6.2.0",
"ts-node": "^8.3.0",
"tslint": "^5.18.0",
"tslint": "^5.19.0",
"tslint-eslint-rules": "^5.4.0"
},
"dependencies": {
"@angular/compiler": "^8.1.3",
"@angular/compiler": "^8.2.2",
"boxen": "^4.1.0",
"colorette": "^1.1.0",
"flat": "^4.1.0",
"flat": "github:lenchvolodymyr/flat#ffe77ef",
"gettext-parser": "^4.0.1",
"glob": "^7.1.4",
"mkdirp": "^0.5.1",
"path": "^0.12.7",
"terminal-link": "^1.3.0",
"typescript": "^3.5.3",
"yargs": "^13.3.0"
"yargs": "^14.0.0"
}
}

View File

@@ -4,7 +4,8 @@ import {
CallExpression,
Node,
SyntaxKind,
StringLiteral
StringLiteral,
NoSubstitutionTemplateLiteral
} from 'typescript';
export abstract class AbstractAstParser {
@@ -24,19 +25,23 @@ export abstract class AbstractAstParser {
}
const firstArg = callNode.arguments[0];
return this.findNodes(firstArg, SyntaxKind.StringLiteral)
.map((node: StringLiteral) => node.text);
return this.findNodes(firstArg, [
SyntaxKind.StringLiteral,
SyntaxKind.NoSubstitutionTemplateLiteral
])
.map((node: StringLiteral | NoSubstitutionTemplateLiteral) => node.text);
}
/**
* Find all child nodes of a kind
*/
protected findNodes(node: Node, kind: SyntaxKind): Node[] {
protected findNodes(node: Node, kinds: SyntaxKind[]): Node[] {
const childrenNodes: Node[] = node.getChildren(this.sourceFile);
const initialValue: Node[] = node.kind === kind ? [node] : [];
const initialValue: Node[] = kinds.includes(node.kind) ? [node] : [];
return childrenNodes.reduce((result: Node[], childNode: Node) => {
return result.concat(this.findNodes(childNode, kind));
return result.concat(this.findNodes(childNode, kinds));
}, initialValue);
}

View File

@@ -38,7 +38,7 @@ export class FunctionParser extends AbstractAstParser implements ParserInterface
node = this.sourceFile;
}
let callNodes = this.findNodes(node, SyntaxKind.CallExpression) as CallExpression[];
let callNodes = this.findNodes(node, [SyntaxKind.CallExpression]) as CallExpression[];
callNodes = callNodes
.filter(callNode => {
// Only call expressions with arguments

View File

@@ -89,14 +89,14 @@ export class ServiceParser extends AbstractAstParser implements ParserInterface
* Find class nodes
*/
protected findClassNodes(node: Node): ClassDeclaration[] {
return this.findNodes(node, SyntaxKind.ClassDeclaration) as ClassDeclaration[];
return this.findNodes(node, [SyntaxKind.ClassDeclaration]) as ClassDeclaration[];
}
/**
* Find constructor
*/
protected findConstructorNode(node: ClassDeclaration): ConstructorDeclaration {
const constructorNodes = this.findNodes(node, SyntaxKind.Constructor) as ConstructorDeclaration[];
const constructorNodes = this.findNodes(node, [SyntaxKind.Constructor]) as ConstructorDeclaration[];
if (constructorNodes) {
return constructorNodes[0];
}
@@ -106,7 +106,7 @@ export class ServiceParser extends AbstractAstParser implements ParserInterface
* Find all calls to TranslateService methods
*/
protected findCallNodes(node: Node, propertyIdentifier: string): CallExpression[] {
let callNodes = this.findNodes(node, SyntaxKind.CallExpression) as CallExpression[];
let callNodes = this.findNodes(node, [SyntaxKind.CallExpression]) as CallExpression[];
callNodes = callNodes
.filter(callNode => {
// Only call expressions with arguments

View File

@@ -3,17 +3,15 @@ import * as boxen from 'boxen';
import * as terminalLink from 'terminal-link';
const url = 'https://donate.biesbjerg.com';
const text = `
If this tool saves you time, please consider making a
donation towards the continued maintainence and development:
const link = terminalLink(url, url);
const message = `
If this tool saves you or your company time, please consider making a
donation to support my work and the continued maintainence and development:
${yellow(terminalLink(url, url))}
`;
${yellow(link)}`;
export const donateMessage = boxen(text.trim(), {
export const donateMessage = boxen(message.trim(), {
padding: 1,
margin: 0,
borderColor: 'yellow',
backgroundColor: 'black',
dimBorder: true
});

View File

@@ -57,4 +57,13 @@ describe('NamespacedJsonCompiler', () => {
expect(result).to.equal('{\n "NAMESPACE": {\n "KEY": {\n "FIRST_KEY": "",\n "SECOND_KEY": "VALUE"\n }\n }\n}');
});
it('should not reorder keys when compiled', () => {
const collection = new TranslationCollection({
'BROWSE': '',
'LOGIN': ''
});
const result: string = compiler.compile(collection);
expect(result).to.equal('{\n\t"BROWSE": "",\n\t"LOGIN": ""\n}');
});
});

View File

@@ -122,6 +122,19 @@ describe('ServiceParser', () => {
expect(key).to.deep.equal(['Hello', 'World']);
});
it('should extract string arrays encapsulated in backticks', () => {
const contents = `
@Component({ })
export class AppComponent {
public constructor(protected _translateService: TranslateService) { }
public test() {
this._translateService.get([\`Hello\`, \`World\`]);
}
`;
const keys = parser.extract(contents, componentFilename).keys();
expect(keys).to.deep.equal(['Hello', 'World']);
});
it('should not extract strings in get()/instant()/stream() methods of other services', () => {
const contents = `
@Component({ })

View File

@@ -5,10 +5,10 @@
"noImplicitAny": true,
"removeComments": true,
"declaration": true,
"target": "es6",
"target": "es2015",
"lib": [
"dom",
"es2015"
"es2018"
],
"module": "commonjs",
"outDir": "./dist/",