fis3-parser-react-i18n
Advanced tools
Comparing version 0.0.0-beta.2 to 0.0.1
53
index.js
@@ -7,2 +7,5 @@ var parse = require('@babel/parser').parse; | ||
var crypto = require('crypto'); | ||
var fs = require('fs'); | ||
var p = require('path'); | ||
var ignore = require('ignore'); | ||
function hash(str) { | ||
@@ -14,5 +17,21 @@ var md5 = crypto.createHash('md5'); | ||
module.exports = function (content, file, options) { | ||
var _a = options.importInfo, importSource = _a.source, importImported = _a.imported, importLocal = _a.local; | ||
var filePath = file.realpath; | ||
var _a = options.ignore || {}, sameGit = _a.sameGit, list = _a.list; | ||
var ignoreList = list || []; | ||
if (sameGit) { | ||
var gitIgnore = fs | ||
.readFileSync(p.resolve(process.cwd(), '.gitignore')) | ||
.toString(); | ||
ignoreList.push.apply(ignoreList, gitIgnore.split('\n')); | ||
} | ||
var relativePath = p.relative(process.cwd(), filePath); | ||
var includes = ignore().add(options.includes); | ||
var included = includes.ignores(relativePath); | ||
var ig = ignore().add(ignoreList); | ||
if (ig.ignores(relativePath) && !included) { | ||
return content; | ||
} | ||
var _b = options.importInfo, importSource = _b.source, importImported = _b.imported, importLocal = _b.local; | ||
var plugins = ['typescript', 'decorators-legacy']; | ||
if (/.*(tsx|jsx)$/.test(file)) { | ||
if (/.*(tsx|jsx)$/.test(filePath)) { | ||
plugins.push('jsx'); | ||
@@ -26,3 +45,4 @@ } | ||
if (ast.errors.length > 0) { | ||
throw new Error(JSON.stringify(ast.errors)); | ||
console.warn(ast.errors); | ||
return content; | ||
} | ||
@@ -74,2 +94,3 @@ var needI18n = false; | ||
]); | ||
needI18n = true; | ||
} | ||
@@ -98,8 +119,17 @@ }, | ||
var variables_1 = []; | ||
var i_1 = 0; | ||
var value = path | ||
.toString() | ||
.replace(/`/g, '') | ||
.replace(/\$\{([\s\S]+?)\}/g, function ($1, $2) { | ||
variables_1.push($2); | ||
return "{{".concat($2, "}}"); | ||
.replace(/\$\{([\s\S]+?)\}/g, function () { | ||
var agr = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
agr[_i] = arguments[_i]; | ||
} | ||
i_1++; | ||
variables_1.push({ | ||
id: i_1, | ||
name: agr[1] | ||
}); | ||
return "{{@".concat(i_1, "}}"); | ||
}); | ||
@@ -109,10 +139,7 @@ var id = hash(value); | ||
t.stringLiteral(id), | ||
t.objectExpression(node.expressions.map(function (item) { | ||
return t.objectProperty(t.stringLiteral(generate(item, { | ||
jsescOption: { | ||
minimal: true | ||
} | ||
}).code), item); | ||
t.objectExpression(node.expressions.map(function (item, index) { | ||
return t.objectProperty(t.stringLiteral("@".concat(index + 1)), item); | ||
})) | ||
])); | ||
needI18n = true; | ||
} | ||
@@ -138,2 +165,3 @@ } | ||
} | ||
needI18n = true; | ||
} | ||
@@ -149,3 +177,4 @@ } | ||
}, content); | ||
console.log("i18n: ".concat(relativePath)); | ||
return codeRes.code; | ||
}; |
{ | ||
"name": "fis3-parser-react-i18n", | ||
"version": "0.0.0-beta.2", | ||
"version": "0.0.1", | ||
"description": "fis3处理react国际化插件", | ||
@@ -19,3 +19,4 @@ "main": "index.js", | ||
"@babel/traverse": "^7.18.10", | ||
"@babel/types": "^7.18.10" | ||
"@babel/types": "^7.18.10", | ||
"ignore": "^5.2.0" | ||
}, | ||
@@ -27,2 +28,2 @@ "devDependencies": { | ||
} | ||
} | ||
} |
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
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
7574
172
0
6
2
+ Addedignore@^5.2.0
+ Addedignore@5.3.2(transitive)