@biesbjerg/ng2-translate-extract
Advanced tools
Comparing version 0.3.3 to 0.3.4
@@ -12,4 +12,4 @@ "use strict"; | ||
var options = cli.parse({ | ||
dir: ['d', 'Directory path you would like to extract strings from', 'dir', process.env.PWD], | ||
output: ['o', 'Directory path you would like to save extracted strings to', 'dir', process.env.PWD], | ||
dir: ['d', 'Path you would like to extract strings from', 'dir', process.env.PWD], | ||
output: ['o', 'Path you would like to save extracted strings to', 'dir', process.env.PWD], | ||
format: ['f', 'Output format', ['json', 'pot'], 'json'], | ||
@@ -19,9 +19,16 @@ replace: ['r', 'Replace the contents of output file if it exists (Merges by default)', 'boolean', false], | ||
}); | ||
[options.dir, options.output].forEach(function (dir) { | ||
if (!fs.existsSync(dir)) { | ||
cli.fatal("The directory path you supplied was not found: '" + dir + "'"); | ||
var normalizedDir = path.resolve(options.dir); | ||
var normalizedOutput = path.resolve(options.output); | ||
var outputDir = normalizedOutput; | ||
var outputFilename = "template." + options.format; | ||
if (!fs.existsSync(normalizedOutput) || !fs.statSync(normalizedOutput).isDirectory()) { | ||
outputDir = path.dirname(normalizedOutput); | ||
outputFilename = path.basename(normalizedOutput); | ||
} | ||
var outputPath = path.join(outputDir, outputFilename); | ||
[normalizedDir, outputDir].forEach(function (dir) { | ||
if (!fs.existsSync(dir) || !fs.statSync(dir).isDirectory()) { | ||
cli.fatal("The path you supplied was not found: '" + dir + "'"); | ||
} | ||
}); | ||
var filename = 'template.' + options.format; | ||
var dest = path.join(options.output, filename); | ||
var parsers = [ | ||
@@ -39,4 +46,4 @@ new pipe_parser_1.PipeParser(), | ||
var extractor = new extractor_1.Extractor(parsers, patterns); | ||
cli.info("Extracting strings from '" + options.dir + "'"); | ||
var extracted = extractor.process(options.dir); | ||
cli.info("Extracting strings from '" + normalizedDir + "'"); | ||
var extracted = extractor.process(normalizedDir); | ||
cli.ok("* Extracted " + extracted.count() + " strings"); | ||
@@ -48,4 +55,4 @@ var collection = extracted; | ||
} | ||
if (!options.replace && fs.existsSync(dest)) { | ||
var existing = compiler.parse(fs.readFileSync(dest, 'utf-8')); | ||
if (!options.replace && fs.existsSync(outputPath)) { | ||
var existing = compiler.parse(fs.readFileSync(outputPath, 'utf-8')); | ||
if (existing.count() > 0) { | ||
@@ -64,4 +71,4 @@ collection = extracted.union(existing); | ||
} | ||
fs.writeFileSync(dest, compiler.compile(collection)); | ||
cli.ok("* Saved to '" + dest + "'"); | ||
fs.writeFileSync(outputPath, compiler.compile(collection)); | ||
cli.ok("* Saved to '" + outputPath + "'"); | ||
} | ||
@@ -68,0 +75,0 @@ catch (e) { |
@@ -1,2 +0,2 @@ | ||
export * from './extractor'; | ||
export * from './utils/extractor'; | ||
export * from './utils/translation.collection'; | ||
@@ -3,0 +3,0 @@ export * from './parsers/parser.interface'; |
@@ -5,3 +5,3 @@ "use strict"; | ||
} | ||
__export(require('./extractor')); | ||
__export(require('./utils/extractor')); | ||
__export(require('./utils/translation.collection')); | ||
@@ -8,0 +8,0 @@ __export(require('./parsers/abstract-template.parser')); |
export declare abstract class AbstractTemplateParser { | ||
protected _isAngularComponent(path: string): boolean; | ||
protected _extractInlineTemplate(contents: string): string; | ||
protected _normalizeTemplateAttributes(template: string): string; | ||
} |
@@ -15,5 +15,2 @@ "use strict"; | ||
}; | ||
AbstractTemplateParser.prototype._normalizeTemplateAttributes = function (template) { | ||
return template.replace(/\[([^\]]+)\]="'([^']*)'"/g, '$1="$2"'); | ||
}; | ||
return AbstractTemplateParser; | ||
@@ -20,0 +17,0 @@ }()); |
@@ -7,2 +7,3 @@ import { ParserInterface } from './parser.interface'; | ||
protected _parseTemplate(template: string): TranslationCollection; | ||
protected _normalizeTemplateAttributes(template: string): string; | ||
} |
@@ -46,2 +46,5 @@ "use strict"; | ||
}; | ||
DirectiveParser.prototype._normalizeTemplateAttributes = function (template) { | ||
return template.replace(/\[([^\]]+)\]="'([^']*)'"/g, '$1="$2"'); | ||
}; | ||
return DirectiveParser; | ||
@@ -48,0 +51,0 @@ }(abstract_template_parser_1.AbstractTemplateParser)); |
{ | ||
"name": "@biesbjerg/ng2-translate-extract", | ||
"version": "0.3.3", | ||
"version": "0.3.4", | ||
"description": "Extract strings from projects using ng2-translate", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
37032
475