From 5356fef0bd36d39599181baf9142ce40057b555a Mon Sep 17 00:00:00 2001 From: DaoYuan Date: Thu, 14 Jul 2022 18:47:47 +0800 Subject: [PATCH] feat: log (#16) * feat: log * chore: npm&pnpm --- .npmrc | 2 +- packages/auto-command/src/translate/index.ts | 8 +- .../src/translate/translate-i18n/index.ts | 8 +- packages/txp-utils/package.json | 4 +- packages/txp-utils/src/node/logger.ts | 9 +- pnpm-lock.yaml | 105 ++++++++++++++++-- 6 files changed, 118 insertions(+), 18 deletions(-) diff --git a/.npmrc b/.npmrc index 69aae37..3880f92 100644 --- a/.npmrc +++ b/.npmrc @@ -1,2 +1,2 @@ -registry=https://registry.npmjs.org/ +registry=https://registry.npmmirror.com strict-peer-dependencies=false diff --git a/packages/auto-command/src/translate/index.ts b/packages/auto-command/src/translate/index.ts index 71b543f..3f3a790 100644 --- a/packages/auto-command/src/translate/index.ts +++ b/packages/auto-command/src/translate/index.ts @@ -335,4 +335,10 @@ async function core({ } signale.timeEnd('translate'); } -export default core; +export default async (options: TranslateConfig) => { + try { + await core(options); + } catch (error) { + utils.node.logger.error(error); + } +}; diff --git a/packages/auto-command/src/translate/translate-i18n/index.ts b/packages/auto-command/src/translate/translate-i18n/index.ts index c92e3e0..bb34a3c 100644 --- a/packages/auto-command/src/translate/translate-i18n/index.ts +++ b/packages/auto-command/src/translate/translate-i18n/index.ts @@ -33,12 +33,16 @@ export default async function i18n(content: string, options: I18nOptions) { if (options.language.from) { obj.language.from = handelCode( options.language.from, - options.translatorType, + options.translatorType || 'youdao', options.separator, ); } if (options.language.to) { - obj.language.to = handelCode(options.language.to, options.translatorType, options.separator); + obj.language.to = handelCode( + options.language.to, + options.translatorType || 'youdao', + options.separator, + ); } const res = await translate(content, obj); return res; diff --git a/packages/txp-utils/package.json b/packages/txp-utils/package.json index 5096849..ce30ad8 100644 --- a/packages/txp-utils/package.json +++ b/packages/txp-utils/package.json @@ -21,8 +21,10 @@ }, "dependencies": { "chalk": "^5.0.1", + "dayjs": "^1.11.3", "fs-extra": "^10.1.0", - "pino": "^8.1.0" + "pino": "^8.1.0", + "pino-pretty": "^8.1.0" }, "authors": [ "tangxiaoping (https://github.com/txp1035)" diff --git a/packages/txp-utils/src/node/logger.ts b/packages/txp-utils/src/node/logger.ts index b0f4f15..c36c16b 100644 --- a/packages/txp-utils/src/node/logger.ts +++ b/packages/txp-utils/src/node/logger.ts @@ -10,9 +10,6 @@ const customLevels = { ready: 31, event: 32, wait: 55, - // 虽然这里设置了 debug 为 30,但日志中还是 20,符合预期 - // 这里不加会不生成到 txp.log,transport 的 level 配置没有生效,原因不明 - debug: 30, }; let logger: Logger<{ customLevels: typeof customLevels }>; @@ -23,13 +20,17 @@ function init() { logger = pino( { customLevels, + level: 'debug', }, pino.transport({ targets: [ { - target: require.resolve('pino/file'), + target: 'pino-pretty', options: { destination: loggerPath, + colorize: false, + translateTime: 'SYS:yyyy-mm-dd HH:MM:ss.l', + messageFormat: 'level: {level}、msg: {msg}', }, level: 'trace', }, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 4cff0c3..6b4bb7c 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -7,10 +7,12 @@ importers: '@types/babel__core': ^7.1.19 '@types/babel__generator': ^7.6.4 '@types/fs-extra': ^9.0.13 + '@types/got': ^9.6.12 '@types/jest': ^24.0.15 '@types/lodash': ^4.14.182 '@types/md5': ^2.3.2 '@types/signale': ^1.4.4 + '@types/tunnel': ^0.0.3 '@types/yargs-parser': ^21.0.0 '@umijs/fabric': ^1.1.9 esno: ^0.16.3 @@ -25,10 +27,12 @@ importers: '@types/babel__core': 7.1.19 '@types/babel__generator': 7.6.4 '@types/fs-extra': 9.0.13 + '@types/got': 9.6.12 '@types/jest': 24.9.1 '@types/lodash': 4.14.182 '@types/md5': 2.3.2 '@types/signale': 1.4.4 + '@types/tunnel': 0.0.3 '@types/yargs-parser': 21.0.0 '@umijs/fabric': 1.2.14_typescript@4.7.4 esno: 0.16.3 @@ -48,11 +52,14 @@ importers: axios: ^0.27.2 esbuild: ^0.14.49 fs-extra: ^9.0.1 + got: 9.6.0 inquirer: ^7.3.0 md5: ^2.3.0 pirates: ^4.0.5 prettier: ^2.7.1 + querystring: ^0.2.1 signale: ^1.4.0 + tunnel: ^0.0.6 txp-utils: ^1.2.0 yargs-parser: ^21.0.1 dependencies: @@ -62,11 +69,14 @@ importers: axios: 0.27.2 esbuild: 0.14.49 fs-extra: 9.1.0 + got: 9.6.0 inquirer: 7.3.3 md5: 2.3.0 pirates: 4.0.5 prettier: 2.7.1 + querystring: 0.2.1 signale: 1.4.0 + tunnel: 0.0.6 txp-utils: link:../txp-utils yargs-parser: 21.0.1 @@ -114,12 +124,16 @@ importers: packages/txp-utils: specifiers: chalk: ^5.0.1 + dayjs: ^1.11.3 fs-extra: ^10.1.0 pino: ^8.1.0 + pino-pretty: ^8.1.0 dependencies: chalk: 5.0.1 + dayjs: 1.11.3 fs-extra: 10.1.0 pino: 8.1.0 + pino-pretty: 8.1.0 packages/umi-plugin-codegen: specifiers: @@ -3976,6 +3990,14 @@ packages: form-data: 2.5.1 dev: false + /@types/got/9.6.12: + resolution: {integrity: sha512-X4pj/HGHbXVLqTpKjA2ahI4rV/nNBc9mGO2I/0CgAra+F2dKgMXnENv2SRpemScBzBAI4vMelIVYViQxlSE6xA==} + dependencies: + '@types/node': 18.0.0 + '@types/tough-cookie': 4.0.2 + form-data: 2.5.1 + dev: true + /@types/hapi__joi/16.0.12: resolution: {integrity: sha512-xJYifuz59jXdWY5JMS15uvA3ycS3nQYOGqoIIE0+fwQ0qI3/4CxBc6RHsOTp6wk9M0NWEdpcTl02lOQOKMifbQ==} dev: false @@ -4299,7 +4321,12 @@ packages: /@types/tough-cookie/4.0.2: resolution: {integrity: sha512-Q5vtl1W5ue16D+nIaW8JWebSSraJVlK+EthKn7e7UcD4KWsaSJ8BqGPXNaPghgtcn/fhvrN17Tv8ksUsQpiplw==} - dev: false + + /@types/tunnel/0.0.3: + resolution: {integrity: sha512-sOUTGn6h1SfQ+gbgqC364jLFBw2lnFqkgF3q0WovEHRLMrVD1sd5aufqi/aJObLekJO+Aq5z646U4Oxy6shXMA==} + dependencies: + '@types/node': 18.0.0 + dev: true /@types/uglify-js/3.16.0: resolution: {integrity: sha512-0yeUr92L3r0GLRnBOvtYK1v2SjqMIqQDHMl7GLb+l2L8+6LSFWEEWEIgVsPdMn5ImLM8qzWT8xFPtQYpp8co0g==} @@ -5530,7 +5557,6 @@ packages: /asynckit/0.4.0: resolution: {integrity: sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==} - dev: false /at-least-node/1.0.0: resolution: {integrity: sha512-+q/t7Ekv1EDY2l6Gda6LLiX14rU9TV20Wa3ofeQmwPFZbOMo9DXrLbOjFaaclkXKWidIaopwAObQDqwWtGUjqg==} @@ -6542,7 +6568,6 @@ packages: /colorette/2.0.19: resolution: {integrity: sha512-3tlv/dIP7FWvj3BsbHrGLJ6l/oKh1O3TcgBqMn+yyCagOxc23fyzDS6HypQbgxWbkpDnf52p1LuR4eWDQ/K9WQ==} - dev: true /colors/1.0.3: resolution: {integrity: sha512-pFGrxThWcWQ2MsAz6RtgeWe4NK2kUE1WfsrvvlctdII745EW9I0yflqhe7++M5LEc7bV2c/9/5zc8sFcpL0Drw==} @@ -6562,7 +6587,6 @@ packages: engines: {node: '>= 0.8'} dependencies: delayed-stream: 1.0.0 - dev: false /commander/2.20.3: resolution: {integrity: sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==} @@ -7261,6 +7285,10 @@ packages: resolution: {integrity: sha512-jyCETtSl3VMZMWeRo7iY1FL19ges1t55hMo5yaam4Jrsm5EPL89UQkoQRyiI+Yf4k8r2ZpdngkV8hr1lIdjb3Q==} dev: true + /dateformat/4.6.3: + resolution: {integrity: sha512-2P0p0pFGzHS5EMnhdxQi7aJN+iMheud0UhG4dlE1DLAlvL8JHjJJTX/CSm4JXwV0Ka5nGk3zC5mcb5bUQUxxMA==} + dev: false + /dayjs/1.11.3: resolution: {integrity: sha512-xxwlswWOlGhzgQ4TKzASQkUhqERI3egRNqgV4ScR8wlANA/A9tZ7miXa44vTTKEq5l7vWoL5G57bG3zA+Kow0A==} dev: false @@ -7392,7 +7420,6 @@ packages: /delayed-stream/1.0.0: resolution: {integrity: sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==} engines: {node: '>=0.4.0'} - dev: false /delegates/1.0.0: resolution: {integrity: sha512-bd2L678uiWATM6m5Z1VzNCErI3jiGzt6HGY8OVICs40JQq/HALfbyNJmp0UDakEY4pMMaN0Ly5om/B1VI/+xfQ==} @@ -8911,6 +8938,10 @@ packages: transitivePeerDependencies: - supports-color + /fast-copy/2.1.3: + resolution: {integrity: sha512-LDzYKNTHhD+XOp8wGMuCkY4eTxFZOOycmpwLBiuF3r3OjOmZnURRD8t2dUAbmKuXGbo/MGggwbSjcBdp8QT0+g==} + dev: false + /fast-deep-equal/3.1.3: resolution: {integrity: sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==} @@ -8950,6 +8981,10 @@ packages: engines: {node: '>=6'} dev: false + /fast-safe-stringify/2.1.1: + resolution: {integrity: sha512-W+KJc2dmILlPplD/H4K9l9LcAHAfPtP6BY84uVLXQ6Evcz9Lcg33Y2z1IVblT6xdY54PXYVHEv+0Wpq8Io6zkA==} + dev: false + /fastq/1.13.0: resolution: {integrity: sha512-YpkpUnK8od0o1hmeSc7UUs/eB/vIPWJYjKck2QKIzAf71Vm1AAQ3EbuZB3g2JIy+pg+ERD0vqI79KyZiB2e2Nw==} dependencies: @@ -9233,7 +9268,6 @@ packages: asynckit: 0.4.0 combined-stream: 1.0.8 mime-types: 2.1.35 - dev: false /form-data/3.0.1: resolution: {integrity: sha512-RHkBKtLWUVwd7SqRIvCZMEvAMoGUp0XU+seQiZejj0COz3RI3hWP4sCv3gZWWLjJTd7rGwcsF5eKZGii0r/hbg==} @@ -9596,7 +9630,6 @@ packages: inherits: 2.0.4 minimatch: 5.1.0 once: 1.4.0 - dev: true /global-modules/2.0.0: resolution: {integrity: sha512-NGbfmJBp9x8IxyJSd1P+otYK8vonoJactOogrVfFRIAEY1ukil8RSKDz2Yo7wh1oihl51l/r6W4epkeKJHqL8A==} @@ -9811,6 +9844,13 @@ packages: minimalistic-assert: 1.0.1 dev: false + /help-me/4.0.1: + resolution: {integrity: sha512-PLv01Z+OhEPKj2QPYB4kjoCUkopYNPUK3EROlaPIf5bib752fZ+VCvGDAoA+FXo/OwCyLEA4D2e0mX8+Zhcplw==} + dependencies: + glob: 8.0.3 + readable-stream: 3.6.0 + dev: false + /hex-color-regex/1.1.0: resolution: {integrity: sha512-l9sfDFsuqtOqKDsQdqrMRk0U85RZc0RtOR9yPI7mRVOa4FsR/BVnZ0shmQRM96Ji99kYZP/7hn1cedc1+ApsTQ==} dev: false @@ -10712,6 +10752,11 @@ packages: json-schema-to-typescript: 8.2.0 dev: false + /joycon/3.1.1: + resolution: {integrity: sha512-34wB/Y7MW7bzjKRjUKTa46I2Z7eV62Rkhva+KkopW7Qvv/OSWBqvkSY7vusOPrNuZcUG3tApvdVgNB8POj3SPw==} + engines: {node: '>=10'} + dev: false + /js-tokens/4.0.0: resolution: {integrity: sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==} @@ -11650,14 +11695,12 @@ packages: /mime-db/1.52.0: resolution: {integrity: sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==} engines: {node: '>= 0.6'} - dev: false /mime-types/2.1.35: resolution: {integrity: sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==} engines: {node: '>= 0.6'} dependencies: mime-db: 1.52.0 - dev: false /mime/1.6.0: resolution: {integrity: sha512-x0Vn8spI+wuJ1O6S7gnbaQg8Pxh4NNHb7KSINmEWKiPE4RKOplvijn+NkmYmmRgP68mc70j2EbeTFRsrswaQeg==} @@ -12426,6 +12469,10 @@ packages: resolution: {integrity: sha512-PX1wu0AmAdPqOL1mWhqmlOd8kOIZQwGZw6rh7uby9fTc5lhaOWFLX3I6R1hrF9k3zUY40e6igsLGkDXK92LJNg==} dev: false + /on-exit-leak-free/1.0.0: + resolution: {integrity: sha512-Ve8ubhrXRdnuCJ5bQSQpP3uaV43K1PMcOfSRC1pqHgRZommXCgsXwh08jVC5NpjwScE23BPDwDvVg4cov3mwjw==} + dev: false + /on-exit-leak-free/2.1.0: resolution: {integrity: sha512-VuCaZZAjReZ3vUwgOB8LxAosIurDiAW0s13rI1YwmaP++jvcxP77AWoQvenZebpCA2m8WC1/EosPYPMjnRAp/w==} dev: false @@ -12895,6 +12942,26 @@ packages: split2: 4.1.0 dev: false + /pino-pretty/8.1.0: + resolution: {integrity: sha512-oKfI8qKXR2a3haHs/X8iB6QSnWLqoOGAjwxIAXem4+XOGIGNw7IKpozId1uE7j89Rj46HIfWnGbAgmQmr8+yRw==} + hasBin: true + dependencies: + colorette: 2.0.19 + dateformat: 4.6.3 + fast-copy: 2.1.3 + fast-safe-stringify: 2.1.1 + help-me: 4.0.1 + joycon: 3.1.1 + minimist: 1.2.6 + on-exit-leak-free: 1.0.0 + pino-abstract-transport: 1.0.0 + pump: 3.0.0 + readable-stream: 4.0.0 + secure-json-parse: 2.4.0 + sonic-boom: 3.0.0 + strip-json-comments: 3.1.1 + dev: false + /pino-std-serializers/5.6.0: resolution: {integrity: sha512-VdUXCw8gO+xhir7sFuoYSjTnzB+TMDGxhAC/ph3YS3sdHnXNdsK0wMtADNUltfeGkn2KDxEM21fnjF3RwXyC8A==} dev: false @@ -13985,6 +14052,12 @@ packages: deprecated: The querystring API is considered Legacy. new code should use the URLSearchParams API instead. dev: false + /querystring/0.2.1: + resolution: {integrity: sha512-wkvS7mL/JMugcup3/rMitHmd9ecIGd2lhFhK9N3UUQ450h66d1r3Y9nvXzQAW1Lq+wyx61k/1pfKS5KuKiyEbg==} + engines: {node: '>=0.4.x'} + deprecated: The querystring API is considered Legacy. new code should use the URLSearchParams API instead. + dev: false + /querystringify/2.2.0: resolution: {integrity: sha512-FIqgj2EUvTa7R50u0rGsyTftzjYmv/a3hO345bZNrqabNqjtgiDMgmo4mkUjd+nzU5oF3dClKqFIPUKybUyqoQ==} dev: false @@ -15464,6 +15537,10 @@ packages: compute-scroll-into-view: 1.0.17 dev: false + /secure-json-parse/2.4.0: + resolution: {integrity: sha512-Q5Z/97nbON5t/L/sH6mY2EacfjVGwrCcSi5D3btRO2GZ8pf1K1UN7Z9H5J57hjVU2Qzxr1xO+FmBhOvEkzCMmg==} + dev: false + /select-hose/2.0.0: resolution: {integrity: sha512-mEugaLK+YfkijB4fx0e6kImuJdCIt2LxCRcbEYPqRGCs4F2ogyfZU5IAZRdjCP8JPq2AtdNoC/Dux63d9Kiryg==} dev: false @@ -16289,6 +16366,11 @@ packages: engines: {node: '>=0.10.0'} dev: true + /strip-json-comments/3.1.1: + resolution: {integrity: sha512-6fPc+R4ihwqP6N/aIv2f1gMH8lOVtWQHoqC4yK6oSDVVocumAsfCqjkXnqiYMhmMwS/mEHLp7Vehlt3ql6lEig==} + engines: {node: '>=8'} + dev: false + /strong-log-transformer/2.1.0: resolution: {integrity: sha512-B3Hgul+z0L9a236FAUC9iZsL+nVHgoCJnqCbN588DjYxvGXaXaaFbfmQ/JhvKjZwsOukuR72XbHv71Qkug0HxA==} engines: {node: '>=4'} @@ -16929,6 +17011,11 @@ packages: resolution: {integrity: sha512-JVa5ijo+j/sOoHGjw0sxw734b1LhBkQ3bvUGNdxnVXDCX81Yx7TFgnZygxrIIWn23hbfTaMYLwRmAxFyDuFmIw==} dev: false + /tunnel/0.0.6: + resolution: {integrity: sha512-1h/Lnq9yajKY2PEbBadPXj3VxsDDu844OnaAo52UVmIzIvwwtBPIuNvkjuzBlTWpfJyUbG3ez0KSBibQkj4ojg==} + engines: {node: '>=0.6.11 <=0.7.0 || >=0.7.3'} + dev: false + /turbo-android-arm64/1.3.1: resolution: {integrity: sha512-JcnZh9tLbZDpKaXaao/s/k4qXt3TbNEc1xEYYXurVWnqiMueGeS7QAtThVB85ZSqzj7djk+ngSrZabPy5RG25Q==} cpu: [arm64]