easygettext
Advanced tools
Comparing version 2.9.0 to 2.10.0
{ | ||
"name": "easygettext", | ||
"version": "2.9.0", | ||
"version": "2.10.0", | ||
"description": "Simple tools to extract gettext strings", | ||
@@ -38,2 +38,3 @@ "main": "src/extract-cli.js", | ||
"cheerio": "^1.0.0-rc.3", | ||
"codecov": "^3.6.5", | ||
"flow-remove-types": "^1.2.3", | ||
@@ -40,0 +41,0 @@ "minimist": "^1.2.0", |
@@ -70,17 +70,3 @@ #!/usr/bin/env node | ||
extractor.parse(file, extract.preprocessTemplate(data, ext)); | ||
let lang = 'js'; | ||
if (ext === 'vue') { | ||
const script = extract.preprocessVueFile(data); | ||
if (script) { | ||
data = script.content; | ||
lang = script.lang; | ||
} else { | ||
lang = null; | ||
} | ||
} | ||
if (lang === 'js') { | ||
extractor.parseJavascript(file, data); | ||
} | ||
extractor.parseJavascript(file, extract.preprocessJavascript(data, ext)); | ||
} catch (e) { | ||
@@ -87,0 +73,0 @@ console.error(`[${PROGRAM_NAME}] could not read: '${filename}`); |
@@ -54,11 +54,14 @@ const cheerio = require('cheerio'); | ||
function preprocessVueFile(data) { | ||
const vueFile = vueCompiler.parse({ compiler, source: data, needMap: false }); | ||
if (!vueFile.script) { | ||
return null; | ||
function preprocessJavascript(data, type) { | ||
let scriptData = ''; | ||
switch (type) { | ||
case 'vue': | ||
const vueFile = vueCompiler.parse({ compiler, source: data, needMap: false }); | ||
if (!vueFile.script) return ''; | ||
scriptData = vueFile.script.content.trim(); | ||
break; | ||
default: | ||
break; | ||
} | ||
return { | ||
content: vueFile.script.content.trim(), | ||
lang: vueFile.script.lang || 'js', | ||
}; | ||
return scriptData; | ||
} | ||
@@ -89,3 +92,3 @@ | ||
exports.preprocessTemplate = preprocessTemplate; | ||
exports.preprocessVueFile = preprocessVueFile; | ||
exports.preprocessJavascript = preprocessJavascript; | ||
@@ -92,0 +95,0 @@ exports.NodeTranslationInfo = class NodeTranslationInfo { |
@@ -124,25 +124,22 @@ const extract = require('./extract.js'); | ||
it('should preprocess VueJS script tag correctly', () => { | ||
const script = extract.preprocessVueFile(fixtures.VUE_COMPONENT_WITH_SCRIPT_TAG); | ||
const script = extract.preprocessJavascript(fixtures.VUE_COMPONENT_WITH_SCRIPT_TAG, 'vue'); | ||
expect(script.content).toEqual(fixtures.VUE_COMPONENT_EXPECTED_PROCESSED_SCRIPT_TAG); | ||
expect(script.lang).toEqual('js'); | ||
expect(script).toEqual(fixtures.VUE_COMPONENT_EXPECTED_PROCESSED_SCRIPT_TAG); | ||
}); | ||
it('should preprocess VueJS no script tag correctly', () => { | ||
const script = extract.preprocessVueFile(fixtures.VUE_COMPONENT_WITHOUT_SCRIPT_TAG); | ||
const script = extract.preprocessJavascript(fixtures.VUE_COMPONENT_WITHOUT_SCRIPT_TAG, 'vue'); | ||
expect(script).toBe(null); | ||
expect(script).toBe(''); | ||
}); | ||
it('should preprocess VueJS script tag in TypeScript correctly', () => { | ||
const script = extract.preprocessVueFile(fixtures.VUE_COMPONENT_WITH_TS_SCRIPT_TAG); | ||
const script = extract.preprocessJavascript(fixtures.VUE_COMPONENT_WITH_TS_SCRIPT_TAG, 'vue'); | ||
expect(script.content).toEqual(fixtures.VUE_COMPONENT_EXPECTED_PROCESSED_TS_SCRIPT_TAG); | ||
expect(script.lang).toEqual('ts'); | ||
expect(script).toEqual(fixtures.VUE_COMPONENT_EXPECTED_PROCESSED_TS_SCRIPT_TAG); | ||
}); | ||
it('should preprocess VueJS script tag with Flow', () => { | ||
const script = extract.preprocessVueFile(fixtures.VUE_COMPONENT_WITH_FLOW_SCRIPT_TAG); | ||
expect(script.content).toEqual(fixtures.VUE_COMPONENT_EXPECTED_PROCESSED_FLOW_SCRIPT_TAG); | ||
expect(script.lang).toEqual('js'); | ||
const script = extract.preprocessJavascript(fixtures.VUE_COMPONENT_WITH_FLOW_SCRIPT_TAG, 'vue'); | ||
expect(script).toEqual(fixtures.VUE_COMPONENT_EXPECTED_PROCESSED_FLOW_SCRIPT_TAG); | ||
}); | ||
@@ -149,0 +146,0 @@ }); |
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
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
92140
11
2196
1
+ Addedcodecov@^3.6.5
+ Added@tootallnate/once@1.1.2(transitive)
+ Addedagent-base@6.0.2(transitive)
+ Addedargparse@1.0.10(transitive)
+ Addedargv@0.0.2(transitive)
+ Addedbalanced-match@1.0.2(transitive)
+ Addedbrace-expansion@1.1.11(transitive)
+ Addedcodecov@3.8.3(transitive)
+ Addedconcat-map@0.0.1(transitive)
+ Addeddebug@4.3.7(transitive)
+ Addedesprima@4.0.1(transitive)
+ Addedfast-url-parser@1.1.3(transitive)
+ Addedhttp-proxy-agent@4.0.1(transitive)
+ Addedhttps-proxy-agent@5.0.1(transitive)
+ Addedignore-walk@3.0.4(transitive)
+ Addedjs-yaml@3.14.1(transitive)
+ Addedminimatch@3.1.2(transitive)
+ Addedms@2.1.3(transitive)
+ Addednode-fetch@2.7.0(transitive)
+ Addedpunycode@1.4.1(transitive)
+ Addedsprintf-js@1.0.3(transitive)
+ Addedstream-events@1.0.5(transitive)
+ Addedstubs@3.0.0(transitive)
+ Addedteeny-request@7.1.1(transitive)
+ Addedtr46@0.0.3(transitive)
+ Addedurlgrey@1.0.0(transitive)
+ Addeduuid@8.3.2(transitive)
+ Addedwebidl-conversions@3.0.1(transitive)
+ Addedwhatwg-url@5.0.0(transitive)