Compare commits

..

9 Commits

Author SHA1 Message Date
Kim Biesbjerg
41bd679fcd (fix) bundle flat dependency. Closes #138 2019-08-29 11:22:40 +02:00
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 95 additions and 58 deletions

71
package-lock.json generated
View File

@@ -1,21 +1,21 @@
{ {
"name": "@biesbjerg/ngx-translate-extract", "name": "@biesbjerg/ngx-translate-extract",
"version": "2.3.4", "version": "3.0.4",
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "dependencies": {
"@angular/compiler": { "@angular/compiler": {
"version": "8.1.3", "version": "8.2.2",
"resolved": "https://registry.npmjs.org/@angular/compiler/-/compiler-8.1.3.tgz", "resolved": "https://registry.npmjs.org/@angular/compiler/-/compiler-8.2.2.tgz",
"integrity": "sha512-mKeRkpPy/iBPGBCVQIPF9x4f1S68ilEYaQTTfHoLR0OfivEQsyGuf2GEegwbTosEBX3JF+0JHfCNvsAE1zI5Og==", "integrity": "sha512-UMhOQehvi9u1r4u48Ymwm5JkdOKoH057ImCo26WqRqJBUgA44xwmUsKLFAmSg1JqzWCO5pBDyA3RaNBscD8ZzQ==",
"requires": { "requires": {
"tslib": "^1.9.0" "tslib": "^1.9.0"
} }
}, },
"@babel/code-frame": { "@babel/code-frame": {
"version": "7.0.0", "version": "7.5.5",
"resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.0.0.tgz", "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.5.5.tgz",
"integrity": "sha512-OfC2uemaknXr87bdLUkWog7nYuliM9Ij5HUcajsVcMCpQrcLmtxRbVFTIqmcSkSeYRBFBRxs2FiUqFJDLdiebA==", "integrity": "sha512-27d4lZoomVyo51VegxI20xZPuSHusqbQag/ztrBC7wegWoQ1nLREPVSKSW8byhTlzTKyNE4ifaTA6lCp7JjpFw==",
"dev": true, "dev": true,
"requires": { "requires": {
"@babel/highlight": "^7.0.0" "@babel/highlight": "^7.0.0"
@@ -33,9 +33,9 @@
} }
}, },
"@types/chai": { "@types/chai": {
"version": "4.1.7", "version": "4.2.0",
"resolved": "https://registry.npmjs.org/@types/chai/-/chai-4.1.7.tgz", "resolved": "https://registry.npmjs.org/@types/chai/-/chai-4.2.0.tgz",
"integrity": "sha512-2Y8uPt0/jwjhQ6EiluT0XCri1Dbplr0ZxfFXUz+ye13gaqE8u5gL5ppao1JrUYr9cIip5S6MvQzBS7Kke7U9VA==", "integrity": "sha512-zw8UvoBEImn392tLjxoavuonblX/4Yb9ha4KBU10FirCfwgzhKO0dvyJSF9ByxV1xK1r2AgnAi/tvQaLgxQqxA==",
"dev": true "dev": true
}, },
"@types/events": { "@types/events": {
@@ -89,9 +89,9 @@
"dev": true "dev": true
}, },
"@types/yargs": { "@types/yargs": {
"version": "13.0.1", "version": "13.0.2",
"resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-13.0.1.tgz", "resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-13.0.2.tgz",
"integrity": "sha512-7X+FaCpRQ1scFQnWUY0TnVuuNaP5ajN45IGmwHVkAbsH1g4txz4hNb6sjJeR/wLaqUdNoInOwLk7oRL5M4zVFA==", "integrity": "sha512-lwwgizwk/bIIU+3ELORkyuOgDjCh7zuWDFqRtPPhhVgq9N1F7CvLNKg1TX4f2duwtKQ0p044Au9r1PLIXHrIzQ==",
"dev": true, "dev": true,
"requires": { "requires": {
"@types/yargs-parser": "*" "@types/yargs-parser": "*"
@@ -483,9 +483,9 @@
"dev": true "dev": true
}, },
"esutils": { "esutils": {
"version": "2.0.2", "version": "2.0.3",
"resolved": "https://registry.npmjs.org/esutils/-/esutils-2.0.2.tgz", "resolved": "https://registry.npmjs.org/esutils/-/esutils-2.0.3.tgz",
"integrity": "sha1-Cr9PHKpbyx96nYrMbepPqqBLrJs=", "integrity": "sha512-kVscqXk4OCp68SZ0dkgEKVi6/8ij300KBWTJq32P/dYeWTSwK41WyTxalN1eRmA5Z9UU/LX9D7FWSmV9SAYx6g==",
"dev": true "dev": true
}, },
"execa": { "execa": {
@@ -512,9 +512,8 @@
} }
}, },
"flat": { "flat": {
"version": "4.1.0", "version": "github:lenchvolodymyr/flat#ffe77efe8c33bc80ffb2f7a465537610dea4f611",
"resolved": "https://registry.npmjs.org/flat/-/flat-4.1.0.tgz", "from": "github:lenchvolodymyr/flat#ffe77ef",
"integrity": "sha512-Px/TiLIznH7gEDlPXcUD4KnBusa6kR6ayRUVcnEAbreRIuhkqow/mun59BuRXwoYk7ZQOLW1ZM05ilIvK38hFw==",
"requires": { "requires": {
"is-buffer": "~2.0.3" "is-buffer": "~2.0.3"
} }
@@ -1091,9 +1090,9 @@
"integrity": "sha512-NKN5kMDylKuldxYLSUfrbo5Tuzh4hd+2E8NPPX02mZtn1VuREQToYe/ZdlJy+J3uCpfaiGF05e7B8W0iXbQHmg==" "integrity": "sha512-NKN5kMDylKuldxYLSUfrbo5Tuzh4hd+2E8NPPX02mZtn1VuREQToYe/ZdlJy+J3uCpfaiGF05e7B8W0iXbQHmg=="
}, },
"resolve": { "resolve": {
"version": "1.11.1", "version": "1.12.0",
"resolved": "https://registry.npmjs.org/resolve/-/resolve-1.11.1.tgz", "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.12.0.tgz",
"integrity": "sha512-vIpgF6wfuJOZI7KKKSP+HmiKggadPQAdsp5HiC1mvqnfp0gF1vdwgBWZIdrVft9pgqoMFQN+R7BSWZiBxx+BBw==", "integrity": "sha512-B/dOmuoAik5bKcD6s6nXDCjzUKnaDvdkRyAk6rsmsKLipWj4797iothd7jmmUhWTfinVMU+wc56rYKsit2Qy4w==",
"dev": true, "dev": true,
"requires": { "requires": {
"path-parse": "^1.0.6" "path-parse": "^1.0.6"
@@ -1269,14 +1268,14 @@
} }
}, },
"tslib": { "tslib": {
"version": "1.9.3", "version": "1.10.0",
"resolved": "https://registry.npmjs.org/tslib/-/tslib-1.9.3.tgz", "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.10.0.tgz",
"integrity": "sha512-4krF8scpejhaOgqzBEcGM7yDIEfi0/8+8zDRZhNZZ2kjmHJ4hv3zCbQWxoJGz1iw5U0Jl0nma13xzHXcncMavQ==" "integrity": "sha512-qOebF53frne81cf0S9B41ByenJ3/IuH8yJKngAX35CmiZySA0khhkovshKK+jGCaMnVomla7gVlIcc3EvKPbTQ=="
}, },
"tslint": { "tslint": {
"version": "5.18.0", "version": "5.19.0",
"resolved": "https://registry.npmjs.org/tslint/-/tslint-5.18.0.tgz", "resolved": "https://registry.npmjs.org/tslint/-/tslint-5.19.0.tgz",
"integrity": "sha512-Q3kXkuDEijQ37nXZZLKErssQVnwCV/+23gFEMROi8IlbaBG6tXqLPQJ5Wjcyt/yHPKBC+hD5SzuGaMora+ZS6w==", "integrity": "sha512-1LwwtBxfRJZnUvoS9c0uj8XQtAnyhWr9KlNvDIdB+oXyT+VpsOAaEhEgKi1HrZ8rq0ki/AAnbGSv4KM6/AfVZw==",
"dev": true, "dev": true,
"requires": { "requires": {
"@babel/code-frame": "^7.0.0", "@babel/code-frame": "^7.0.0",
@@ -1491,11 +1490,12 @@
"integrity": "sha512-r9S/ZyXu/Xu9q1tYlpsLIsa3EeLXXk0VwlxqTcFRfg9EhMW+17kbt9G0NrgCmhGb5vT2hyhJZLfDGx+7+5Uj/w==" "integrity": "sha512-r9S/ZyXu/Xu9q1tYlpsLIsa3EeLXXk0VwlxqTcFRfg9EhMW+17kbt9G0NrgCmhGb5vT2hyhJZLfDGx+7+5Uj/w=="
}, },
"yargs": { "yargs": {
"version": "13.3.0", "version": "14.0.0",
"resolved": "https://registry.npmjs.org/yargs/-/yargs-13.3.0.tgz", "resolved": "https://registry.npmjs.org/yargs/-/yargs-14.0.0.tgz",
"integrity": "sha512-2eehun/8ALW8TLoIl7MVaRUrg+yCnenu8B4kBlRxj3GJGDKU1Og7sMXPNm1BYyM1DOJmTZ4YeN/Nwxv+8XJsUA==", "integrity": "sha512-ssa5JuRjMeZEUjg7bEL99AwpitxU/zWGAGpdj0di41pOEmJti8NR6kyUIJBkR78DTYNPZOU08luUo0GTHuB+ow==",
"requires": { "requires": {
"cliui": "^5.0.0", "cliui": "^5.0.0",
"decamelize": "^1.2.0",
"find-up": "^3.0.0", "find-up": "^3.0.0",
"get-caller-file": "^2.0.1", "get-caller-file": "^2.0.1",
"require-directory": "^2.1.1", "require-directory": "^2.1.1",
@@ -1582,6 +1582,15 @@
"yargs": "^12.0.5" "yargs": "^12.0.5"
}, },
"dependencies": { "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": { "get-caller-file": {
"version": "1.0.3", "version": "1.0.3",
"resolved": "https://registry.npmjs.org/get-caller-file/-/get-caller-file-1.0.3.tgz", "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", "name": "@biesbjerg/ngx-translate-extract",
"version": "3.0.0", "version": "3.0.5",
"description": "Extract strings from projects using ngx-translate", "description": "Extract strings from projects using ngx-translate",
"main": "dist/index.js", "main": "dist/index.js",
"typings": "dist/index.d.ts", "typings": "dist/index.d.ts",
@@ -44,29 +44,32 @@
}, },
"config": {}, "config": {},
"devDependencies": { "devDependencies": {
"@types/chai": "^4.1.7", "@types/chai": "^4.2.0",
"@types/flat": "^0.0.28", "@types/flat": "^0.0.28",
"@types/glob": "^7.1.1", "@types/glob": "^7.1.1",
"@types/mkdirp": "^0.5.2", "@types/mkdirp": "^0.5.2",
"@types/mocha": "^5.2.7", "@types/mocha": "^5.2.7",
"@types/yargs": "^13.0.1", "@types/yargs": "^13.0.2",
"chai": "^4.2.0", "chai": "^4.2.0",
"mocha": "^6.2.0", "mocha": "^6.2.0",
"ts-node": "^8.3.0", "ts-node": "^8.3.0",
"tslint": "^5.18.0", "tslint": "^5.19.0",
"tslint-eslint-rules": "^5.4.0" "tslint-eslint-rules": "^5.4.0"
}, },
"bundledDependencies": [
"flat"
],
"dependencies": { "dependencies": {
"@angular/compiler": "^8.1.3", "@angular/compiler": "^8.2.2",
"boxen": "^4.1.0", "boxen": "^4.1.0",
"colorette": "^1.1.0", "colorette": "^1.1.0",
"flat": "^4.1.0", "flat": "github:lenchvolodymyr/flat#ffe77ef",
"gettext-parser": "^4.0.1", "gettext-parser": "^4.0.1",
"glob": "^7.1.4", "glob": "^7.1.4",
"mkdirp": "^0.5.1", "mkdirp": "^0.5.1",
"path": "^0.12.7", "path": "^0.12.7",
"terminal-link": "^1.3.0", "terminal-link": "^1.3.0",
"typescript": "^3.5.3", "typescript": "^3.5.3",
"yargs": "^13.3.0" "yargs": "^14.0.0"
} }
} }

View File

@@ -4,7 +4,8 @@ import {
CallExpression, CallExpression,
Node, Node,
SyntaxKind, SyntaxKind,
StringLiteral StringLiteral,
NoSubstitutionTemplateLiteral
} from 'typescript'; } from 'typescript';
export abstract class AbstractAstParser { export abstract class AbstractAstParser {
@@ -24,19 +25,23 @@ export abstract class AbstractAstParser {
} }
const firstArg = callNode.arguments[0]; 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 * 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 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 childrenNodes.reduce((result: Node[], childNode: Node) => {
return result.concat(this.findNodes(childNode, kind)); return result.concat(this.findNodes(childNode, kinds));
}, initialValue); }, initialValue);
} }

View File

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

View File

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

View File

@@ -3,17 +3,15 @@ import * as boxen from 'boxen';
import * as terminalLink from 'terminal-link'; import * as terminalLink from 'terminal-link';
const url = 'https://donate.biesbjerg.com'; const url = 'https://donate.biesbjerg.com';
const text = ` const link = terminalLink(url, url);
If this tool saves you time, please consider making a const message = `
donation towards the continued maintainence and development: 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, padding: 1,
margin: 0, margin: 0,
borderColor: 'yellow',
backgroundColor: 'black',
dimBorder: true 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}'); 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']); 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', () => { it('should not extract strings in get()/instant()/stream() methods of other services', () => {
const contents = ` const contents = `
@Component({ }) @Component({ })

View File

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