Compare commits

...

5 Commits

Author SHA1 Message Date
Kim Biesbjerg
40051f4144 Bump version 2017-11-07 15:17:38 +01:00
Sean G. Wright
14eb09f947 feat(cli): add verbose (vb) flag that can control output of all file … (#74)
* feat(cli): add verbose (vb) flag that can control output of all file paths to console

* docs(README): add -vb description
2017-11-07 15:14:31 +01:00
Tiago Dionesto Willrich da Silva
8d1e2c5a2f Change typescript to be a dependency (#75)
Typescript is being imported by the parser files, so it should be a direct dependency instead of just a development one.

Without that change, it's impossible to use the extractor programatically or with npx.
2017-11-07 15:13:35 +01:00
Dominik Herbst
4892ea5146 Configured cheerio to work with non-HTML standard elements to fix issues with custom component tags. (#79) 2017-11-07 15:13:01 +01:00
Kim Biesbjerg
ee28fe2a64 Create LICENSE 2017-07-08 14:10:54 +02:00
7 changed files with 46 additions and 7 deletions

21
LICENSE Normal file
View File

@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2017 Kim Biesbjerg
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@@ -93,3 +93,5 @@ Options:
[boolean] [default: false]
--clean, -c Remove obsolete strings when merging
[boolean] [default: false]
--verbose, -vb If true, prints all processed file paths to console
[boolean] [default: true]

View File

@@ -1,6 +1,6 @@
{
"name": "@biesbjerg/ngx-translate-extract",
"version": "2.3.2",
"version": "2.3.3",
"description": "Extract strings from projects using ngx-translate",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
@@ -59,8 +59,7 @@
"mocha": "3.4.2",
"ts-node": "3.1.0",
"tslint": "5.4.3",
"tslint-eslint-rules": "4.1.1",
"typescript": "2.4.1"
"tslint-eslint-rules": "4.1.1"
},
"dependencies": {
"chalk": "2.0.1",
@@ -71,6 +70,7 @@
"glob": "7.1.2",
"path": "0.12.7",
"mkdirp": "0.5.1",
"flat": "2.0.1"
"flat": "2.0.1",
"typescript": "2.4.1"
}
}

View File

@@ -82,6 +82,12 @@ export const cli = yargs
default: false,
type: 'boolean'
})
.option('verbose', {
alias: 'vb',
describe: 'Log all output to console',
default: true,
type: 'boolean'
})
.exitProcess(true)
.parse(process.argv);

View File

@@ -14,6 +14,7 @@ export interface ExtractTaskOptionsInterface {
sort?: boolean;
clean?: boolean;
patterns?: string[];
verbose?: boolean;
}
export class ExtractTask implements TaskInterface {
@@ -22,7 +23,8 @@ export class ExtractTask implements TaskInterface {
replace: false,
sort: false,
clean: false,
patterns: []
patterns: [],
verbose: true
};
protected _parsers: ParserInterface[] = [];
@@ -64,7 +66,7 @@ export class ExtractTask implements TaskInterface {
let collection: TranslationCollection = new TranslationCollection();
this._input.forEach(dir => {
this._readDir(dir, this._options.patterns).forEach(path => {
this._out(chalk.gray('- %s'), path);
this._options.verbose && this._out(chalk.gray('- %s'), path);
const contents: string = fs.readFileSync(path, 'utf-8');
this._parsers.forEach((parser: ParserInterface) => {
collection = collection.union(parser.extract(contents, path));

View File

@@ -2,7 +2,9 @@ import { ParserInterface } from './parser.interface';
import { AbstractTemplateParser } from './abstract-template.parser';
import { TranslationCollection } from '../utils/translation.collection';
import * as $ from 'cheerio';
import * as cheerio from 'cheerio';
const $ = cheerio.load('', {xmlMode: true});
export class DirectiveParser extends AbstractTemplateParser implements ParserInterface {

View File

@@ -118,4 +118,10 @@ describe('DirectiveParser', () => {
expect(template).to.equal('<p translate="KEY">Hello World</p>');
});
it('should extract contents from within custom tags', () => {
const contents = `<custom-table><tbody><tr><td translate>Hello World</td></tr></tbody></custom-table>`;
const keys = parser.extract(contents, templateFilename).keys();
expect(keys).to.deep.equal(['Hello World']);
});
});