i18-fe-automator-beta 1.0.13 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -19,6 +19,7 @@ var uuid = require('uuid');
19
19
  var eslint = require('eslint');
20
20
  var espree = require('espree');
21
21
  var node_module = require('node:module');
22
+ var tsParser = require('@typescript-eslint/parser');
22
23
  var stripAnsi = require('strip-ansi');
23
24
  require('shelljs');
24
25
  var process$1 = require('child_process');
@@ -195,7 +196,7 @@ function uploadExcel({ data, token, env }) {
195
196
 
196
197
  // 获取命令行所在的目录
197
198
  function getRunCliPath({ directory = false, root = false } = {}) {
198
- const __filename = url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.src || new URL('index.js', document.baseURI).href)));
199
+ const __filename = url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.js', document.baseURI).href)));
199
200
  const __dirname = path.dirname(__filename);
200
201
  if (root) {
201
202
  return path.resolve(__dirname, "../");
@@ -1821,12 +1822,10 @@ function getConditionValue(node, moduleArr,getPath) {
1821
1822
  * @fileoverview 国际化
1822
1823
  * @author ypf
1823
1824
  */
1824
- const require$1 = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.src || new URL('index.js', document.baseURI).href)));
1825
+ const require$1 = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.js', document.baseURI).href)));
1825
1826
  const VueESlintParserPath = require$1.resolve('vue-eslint-parser');
1826
1827
  const meta = {
1827
- name: "eslint-plugin-i18n",
1828
- version: "1.0.0",
1829
- };
1828
+ name: "eslint-plugin-i18n"};
1830
1829
  var i18n = {
1831
1830
  rules: {
1832
1831
  "no-single-chinese": noSingleChineseRule,
@@ -1856,8 +1855,8 @@ var i18n = {
1856
1855
  parser: {
1857
1856
  js: espree__namespace,
1858
1857
  jsx: espree__namespace, // 支持jsx语法
1859
- // ts: tsParser,
1860
- // tsx: tsParser,
1858
+ ts: tsParser,
1859
+ tsx: tsParser,
1861
1860
  },
1862
1861
  },
1863
1862
  },
@@ -2071,11 +2070,12 @@ async function lint$1(patterns, fix, rule, hook = {}) {
2071
2070
  rules$1[`i18n/no-single-${rule}`] = "warn";
2072
2071
  }
2073
2072
  const eslint$1 = new eslint.ESLint({
2074
- useEslintrc: false, // 不检测其他规则,只检测i18n规则, 不设置为false,则会检测项目中的.eslintrc.js文件规则
2075
- // 只检测js,jsx,vue文件
2076
- extensions: [".js", ".jsx", ".vue"],
2073
+ useEslintrc: false, // 不加载项目中的 .eslintrc 文件, 即不检测执行项目里规则,只检测i18n规则, 不设置为false,则会检测项目中的.eslintrc.js文件规则
2074
+ // allowInlineConfig: false, // 禁止解析文件内的 /* eslint-disable */ 等注释,否则虽然设置了useEslintrc:false, 它也会检测/* eslint-disable */等注释,然后找不到该规则的定义,从而检测出错误.但⚠️该规则会导致eslint-disable 失效
2075
+ // 只检测js,jsx,vue,ts,tsx文件
2076
+ extensions: [".js", ".jsx", ".vue",'ts', 'tsx'],
2077
2077
  fix: fix || false, // 是否自动修复
2078
- overrideConfigFile: null,
2078
+ overrideConfigFile: null, // 所有规则通过下面overrideConfig配置,不使用基于文件的配置方式,如传配指定配置文件路径
2079
2079
  plugins: { [meta.name]: i18n }, // 必须写,下面的extends才能识别, 和配置文件那种不一样,配置文件那种只写extends就行,不用写plugins
2080
2080
  overrideConfig: {
2081
2081
  extends: [
@@ -2089,6 +2089,16 @@ async function lint$1(patterns, fix, rule, hook = {}) {
2089
2089
  try {
2090
2090
  // 检查文件
2091
2091
  const results = await eslint$1.lintFiles(patterns);
2092
+ results.forEach(item=>{
2093
+ if(item?.messages?.length){
2094
+ // 脚本只会检测脚本自定义的规则,但是在项目中运行发现eslint-disable-line xx规则会报找不到规则的错误,如
2095
+ // error Definition for rule '@typescript-eslint/no-unused-vars' was not found @typescript-eslint/no-unused-vars
2096
+ // 这种报错没有messageId,忽略掉
2097
+ item.messages=item.messages.filter(message=>{
2098
+ return message.messageId
2099
+ });
2100
+ }
2101
+ });
2092
2102
  hook.lintFilesAfter && (await hook.lintFilesAfter(results, Loading$1));
2093
2103
  if (!fix) {
2094
2104
  // 判断是否有匹配到错误
@@ -2549,7 +2559,6 @@ function translateUtil(appid, key, projectName, isLintFix) {
2549
2559
  let str = "";
2550
2560
  let cutArr = [];
2551
2561
  console.log(chalk.green(`共有${allArr.length}条数据需要翻译`));
2552
- console.log(allArr,'allArr');
2553
2562
 
2554
2563
  allArr.forEach((item, index) => {
2555
2564
  if (str.length > 2000) {
@@ -17,6 +17,7 @@ import { v5 } from 'uuid';
17
17
  import { ESLint } from 'eslint';
18
18
  import * as espree from 'espree';
19
19
  import { createRequire } from 'node:module';
20
+ import tsParser from '@typescript-eslint/parser';
20
21
  import stripAnsi from 'strip-ansi';
21
22
  import 'shelljs';
22
23
  import process$1 from 'child_process';
@@ -26,10 +27,10 @@ import request$1 from 'request-promise';
26
27
  import 'os';
27
28
  import 'console';
28
29
 
29
- function Loading() {
30
+ function Loading$1() {
30
31
  this.spinner = ora();
31
32
  }
32
- var Loading$1 = new Loading().spinner;
33
+ var Loading = new Loading$1().spinner;
33
34
 
34
35
  //加密
35
36
  function encrypt(word, keyStr) {
@@ -46,7 +47,7 @@ function encrypt(word, keyStr) {
46
47
  function login(data) {
47
48
  data.password = encrypt(md5$1(data.password));
48
49
  const env=data.env;
49
- Loading$1.start(`${env}: 登录中...`);
50
+ Loading.start(`${env}: 登录中...`);
50
51
  return new Promise((resolve, reject) => {
51
52
  request(
52
53
  {
@@ -60,11 +61,11 @@ function login(data) {
60
61
  function (error, response, body) {
61
62
  const res = body;
62
63
  if (!error && res.code == 200) {
63
- Loading$1.succeed(`${env}: 登录成功`);
64
+ Loading.succeed(`${env}: 登录成功`);
64
65
  const access_token = res.data.access_token;
65
66
  resolve(access_token);
66
67
  } else {
67
- Loading$1.fail(`${env}: 登录失败`);
68
+ Loading.fail(`${env}: 登录失败`);
68
69
  console.log(chalk.red(error || res.msg));
69
70
  }
70
71
  }
@@ -73,7 +74,7 @@ function login(data) {
73
74
  }
74
75
 
75
76
  function importExcel({ uploadFilePath, token, env }) {
76
- Loading$1.start(`${env}: 导入文件中...`);
77
+ Loading.start(`${env}: 导入文件中...`);
77
78
  const stream = fs.createReadStream(uploadFilePath);
78
79
  return new Promise((resolve, reject) => {
79
80
  request(
@@ -94,10 +95,10 @@ function importExcel({ uploadFilePath, token, env }) {
94
95
  function (error, response, body) {
95
96
  const res = JSON.parse(body);
96
97
  if (!error && res.code == 200) {
97
- Loading$1.succeed(`${env}: 导入文件成功`);
98
+ Loading.succeed(`${env}: 导入文件成功`);
98
99
  resolve(true);
99
100
  } else {
100
- Loading$1.fail(`${env}: 导入文件失败`);
101
+ Loading.fail(`${env}: 导入文件失败`);
101
102
  console.log(
102
103
  chalk.red(error || (res.data ? JSON.stringify(res.data) : res.msg))
103
104
  );
@@ -142,7 +143,7 @@ function readExcel({ uploadFilePath }) {
142
143
  }
143
144
 
144
145
  function uploadExcel({ data, token, env }) {
145
- Loading$1.start(`${env}: 导入项目 ${data.projectList.join()}`);
146
+ Loading.start(`${env}: 导入项目 ${data.projectList.join()}`);
146
147
  return new Promise((resolve, reject) => {
147
148
  request(
148
149
  {
@@ -160,10 +161,10 @@ function uploadExcel({ data, token, env }) {
160
161
  function (error, response, body) {
161
162
  const res = body;
162
163
  if (!error && res.code == 200) {
163
- Loading$1.succeed(`${env}: 导入项目成功`);
164
+ Loading.succeed(`${env}: 导入项目成功`);
164
165
  resolve(true);
165
166
  } else {
166
- Loading$1.fail(`${env}: 导入项目失败`);
167
+ Loading.fail(`${env}: 导入项目失败`);
167
168
  console.log(chalk.red(error || res.msg || res.message));
168
169
  }
169
170
  }
@@ -810,7 +811,7 @@ function getApplicationList({ appName, env, token }) {
810
811
  }
811
812
  // 获取应用按钮权限配置
812
813
  function getApplicationButtonConfig({ appId, env, token }) {
813
- Loading$1.start(`获取按钮权限配置中...`);
814
+ Loading.start(`获取按钮权限配置中...`);
814
815
  return new Promise((resolve, reject) => {
815
816
  request(
816
817
  {
@@ -828,10 +829,10 @@ function getApplicationButtonConfig({ appId, env, token }) {
828
829
  function (error, response, body) {
829
830
  const res = body;
830
831
  if (!error && res.code == 200) {
831
- Loading$1.succeed(`获取${env}环境按钮权限配置成功`);
832
+ Loading.succeed(`获取${env}环境按钮权限配置成功`);
832
833
  resolve(res.data);
833
834
  } else {
834
- Loading$1.fail(`获取${env}环境按钮权限配置失败`);
835
+ Loading.fail(`获取${env}环境按钮权限配置失败`);
835
836
  console.log(chalk.red(error || JSON.stringify(res.data)));
836
837
  }
837
838
  }
@@ -869,7 +870,7 @@ function deleteApplicationButtonConfig({ data, env, token }) {
869
870
  }
870
871
  // 新增应用按钮权限
871
872
  function addApplicationButtonConfig({ data, env, token }) {
872
- Loading$1.start(`新增按钮权限 ${data.code} 中...`);
873
+ Loading.start(`新增按钮权限 ${data.code} 中...`);
873
874
  return new Promise((resolve, reject) => {
874
875
  request(
875
876
  {
@@ -887,10 +888,10 @@ function addApplicationButtonConfig({ data, env, token }) {
887
888
  function (error, response, body) {
888
889
  const res = body;
889
890
  if (!error && res.code == 200) {
890
- Loading$1.succeed(`${data.code}`);
891
+ Loading.succeed(`${data.code}`);
891
892
  resolve(true);
892
893
  } else {
893
- Loading$1.fail(`${data.code}`);
894
+ Loading.fail(`${data.code}`);
894
895
  console.log(chalk.red(error || JSON.stringify(res.data)));
895
896
  }
896
897
  }
@@ -1008,9 +1009,9 @@ async function syncSassConfig() {
1008
1009
  token: toToken,
1009
1010
  });
1010
1011
  });
1011
- Loading$1.start(`删除${to}环境按钮权限配置中...`);
1012
+ Loading.start(`删除${to}环境按钮权限配置中...`);
1012
1013
  await Promise.all(deleteButtonPromiseList);
1013
- Loading$1.succeed(`删除${to}环境按钮权限配置成功`);
1014
+ Loading.succeed(`删除${to}环境按钮权限配置成功`);
1014
1015
  }
1015
1016
  } catch (error) {
1016
1017
  console.log(chalk.red(`删除${to}环境按钮权限配置失败`));
@@ -1799,12 +1800,10 @@ function getConditionValue(node, moduleArr,getPath) {
1799
1800
  * @fileoverview 国际化
1800
1801
  * @author ypf
1801
1802
  */
1802
- const require = createRequire(import.meta.url);
1803
- const VueESlintParserPath = require.resolve('vue-eslint-parser');
1803
+ const require$1 = createRequire(import.meta.url);
1804
+ const VueESlintParserPath = require$1.resolve('vue-eslint-parser');
1804
1805
  const meta = {
1805
- name: "eslint-plugin-i18n",
1806
- version: "1.0.0",
1807
- };
1806
+ name: "eslint-plugin-i18n"};
1808
1807
  var i18n = {
1809
1808
  rules: {
1810
1809
  "no-single-chinese": noSingleChineseRule,
@@ -1834,8 +1833,8 @@ var i18n = {
1834
1833
  parser: {
1835
1834
  js: espree,
1836
1835
  jsx: espree, // 支持jsx语法
1837
- // ts: tsParser,
1838
- // tsx: tsParser,
1836
+ ts: tsParser,
1837
+ tsx: tsParser,
1839
1838
  },
1840
1839
  },
1841
1840
  },
@@ -2049,11 +2048,12 @@ async function lint$1(patterns, fix, rule, hook = {}) {
2049
2048
  rules$1[`i18n/no-single-${rule}`] = "warn";
2050
2049
  }
2051
2050
  const eslint = new ESLint({
2052
- useEslintrc: false, // 不检测其他规则,只检测i18n规则, 不设置为false,则会检测项目中的.eslintrc.js文件规则
2053
- // 只检测js,jsx,vue文件
2054
- extensions: [".js", ".jsx", ".vue"],
2051
+ useEslintrc: false, // 不加载项目中的 .eslintrc 文件, 即不检测执行项目里规则,只检测i18n规则, 不设置为false,则会检测项目中的.eslintrc.js文件规则
2052
+ // allowInlineConfig: false, // 禁止解析文件内的 /* eslint-disable */ 等注释,否则虽然设置了useEslintrc:false, 它也会检测/* eslint-disable */等注释,然后找不到该规则的定义,从而检测出错误.但⚠️该规则会导致eslint-disable 失效
2053
+ // 只检测js,jsx,vue,ts,tsx文件
2054
+ extensions: [".js", ".jsx", ".vue",'ts', 'tsx'],
2055
2055
  fix: fix || false, // 是否自动修复
2056
- overrideConfigFile: null,
2056
+ overrideConfigFile: null, // 所有规则通过下面overrideConfig配置,不使用基于文件的配置方式,如传配指定配置文件路径
2057
2057
  plugins: { [meta.name]: i18n }, // 必须写,下面的extends才能识别, 和配置文件那种不一样,配置文件那种只写extends就行,不用写plugins
2058
2058
  overrideConfig: {
2059
2059
  extends: [
@@ -2063,20 +2063,30 @@ async function lint$1(patterns, fix, rule, hook = {}) {
2063
2063
  rules: rules$1,
2064
2064
  },
2065
2065
  });
2066
- Loading$1.start(`检测中...`);
2066
+ Loading.start(`检测中...`);
2067
2067
  try {
2068
2068
  // 检查文件
2069
2069
  const results = await eslint.lintFiles(patterns);
2070
- hook.lintFilesAfter && (await hook.lintFilesAfter(results, Loading$1));
2070
+ results.forEach(item=>{
2071
+ if(item?.messages?.length){
2072
+ // 脚本只会检测脚本自定义的规则,但是在项目中运行发现eslint-disable-line xx规则会报找不到规则的错误,如
2073
+ // error Definition for rule '@typescript-eslint/no-unused-vars' was not found @typescript-eslint/no-unused-vars
2074
+ // 这种报错没有messageId,忽略掉
2075
+ item.messages=item.messages.filter(message=>{
2076
+ return message.messageId
2077
+ });
2078
+ }
2079
+ });
2080
+ hook.lintFilesAfter && (await hook.lintFilesAfter(results, Loading));
2071
2081
  if (!fix) {
2072
2082
  // 判断是否有匹配到错误
2073
2083
  const hasErrors = results.some(
2074
2084
  (result) => result.messages && result.messages.length
2075
2085
  );
2076
2086
  if (!hasErrors) {
2077
- return Loading$1.succeed(`没有要修复的错误`);
2087
+ return Loading.succeed(`没有要修复的错误`);
2078
2088
  }
2079
- Loading$1.succeed(`检测完成`);
2089
+ Loading.succeed(`检测完成`);
2080
2090
  // 如果没有fix,则直接输出错误
2081
2091
  return console.log(stylish(results));
2082
2092
  }
@@ -2085,11 +2095,11 @@ async function lint$1(patterns, fix, rule, hook = {}) {
2085
2095
  (result) => result.output || result.warningCount
2086
2096
  );
2087
2097
  if (!hasErrors1) {
2088
- return Loading$1.succeed(`没有要修复的错误`);
2098
+ return Loading.succeed(`没有要修复的错误`);
2089
2099
  }
2090
2100
  // 输出回原文件
2091
2101
  await ESLint.outputFixes(results);
2092
- Loading$1.succeed(`替换空key完成`);
2102
+ Loading.succeed(`替换空key完成`);
2093
2103
  inquirer
2094
2104
  .prompt([
2095
2105
  {
@@ -2108,7 +2118,7 @@ async function lint$1(patterns, fix, rule, hook = {}) {
2108
2118
  }
2109
2119
  });
2110
2120
  } catch (error) {
2111
- Loading$1.fail(`检测失败`);
2121
+ Loading.fail(`检测失败`);
2112
2122
  console.error(chalk.red(error));
2113
2123
  }
2114
2124
  }
@@ -2527,7 +2537,6 @@ function translateUtil(appid, key, projectName, isLintFix) {
2527
2537
  let str = "";
2528
2538
  let cutArr = [];
2529
2539
  console.log(chalk.green(`共有${allArr.length}条数据需要翻译`));
2530
- console.log(allArr,'allArr');
2531
2540
 
2532
2541
  allArr.forEach((item, index) => {
2533
2542
  if (str.length > 2000) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "i18-fe-automator-beta",
3
- "version": "1.0.13",
3
+ "version": "2.0.0",
4
4
  "description": "i18-fe-automator-beta内测版本,只用于key: ''替换、检测中文规则等",
5
5
  "type": "module",
6
6
  "bin": {
@@ -15,6 +15,9 @@
15
15
  "dist/commonjs",
16
16
  "dist/esm"
17
17
  ],
18
+ "engines": {
19
+ "node": "^18.18.0 || ^20.9.0 || >=21.1.0"
20
+ },
18
21
  "keywords": [],
19
22
  "author": "pengfei.yin",
20
23
  "license": "MIT",
@@ -23,6 +26,7 @@
23
26
  "rollup": "^4.9.1"
24
27
  },
25
28
  "dependencies": {
29
+ "@typescript-eslint/parser": "^8.53.1",
26
30
  "chalk": "^5.3.0",
27
31
  "commander": "^11.1.0",
28
32
  "crypto-js": "^4.2.0",