From 4dfccf5c955dd9a8115cfc848cf0ca31e38b5334 Mon Sep 17 00:00:00 2001 From: Chi Zhang Date: Thu, 29 Dec 2022 10:20:57 +0800 Subject: [PATCH] feat: printer next (#601) * feat: add printer and next.js logger style * chore: add info for API Proxy * tests: unit test cases is added to printer * fix: deps Co-authored-by: DarkSky <25152247+darkskygit@users.noreply.github.com> --- .eslintignore | 4 ++- packages/app/next.config.js | 13 +++++-- packages/app/package.json | 3 +- .../app/scripts/__tests__/printer.spec.ts | 21 +++++++++++ packages/app/scripts/printer.js | 20 +++++++++++ pnpm-lock.yaml | 36 +++++++++++++++++++ 6 files changed, 92 insertions(+), 5 deletions(-) create mode 100644 packages/app/scripts/__tests__/printer.spec.ts create mode 100644 packages/app/scripts/printer.js diff --git a/.eslintignore b/.eslintignore index 9809316cc9..63e7a67a1e 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1,4 +1,6 @@ **/webpack.config.js **/jest.config.js +**/scripts/*.js **/node_modules/** -.github/** \ No newline at end of file +.github/** +**/__tests__/** diff --git a/packages/app/next.config.js b/packages/app/next.config.js index eacd634a8d..e20b495874 100644 --- a/packages/app/next.config.js +++ b/packages/app/next.config.js @@ -2,6 +2,7 @@ const { getGitVersion, getCommitHash } = require('./scripts/gitInfo'); const { dependencies } = require('./package.json'); const path = require('node:path'); +const printer = require('./scripts/printer').printer; /** @type {import('next').NextConfig} */ const nextConfig = { @@ -32,18 +33,24 @@ const nextConfig = { // XXX not test yet rewrites: async () => { if (process.env.NODE_API_SERVER === 'ac') { - console.log('use ac server'); + let destinationAC = 'http://100.85.73.88:12001/api/:path*'; + printer.info('API request proxy to [AC Server] ' + destinationAC); return [ { source: '/api/:path*', - destination: 'http://100.85.73.88:12001/api/:path*', + destination: destinationAC, }, ]; } else { + let destinationStandard = 'http://100.77.180.48:11001/api/:path*'; + printer.info( + 'API request proxy to [Standard Server] ' + destinationStandard + ); + return [ { source: '/api/:path*', - destination: 'http://100.77.180.48:11001/api/:path*', + destination: destinationStandard, }, ]; } diff --git a/packages/app/package.json b/packages/app/package.json index a050a1d081..e33b403f95 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -10,6 +10,7 @@ "lint": "next lint" }, "dependencies": { + "@affine/data-services": "workspace:@affine/data-services@*", "@blocksuite/blocks": "0.3.0-20221225075400-9710eea", "@blocksuite/editor": "0.3.0-20221225075400-9710eea", "@blocksuite/icons": "^2.0.2", @@ -23,7 +24,6 @@ "@mui/base": "^5.0.0-alpha.87", "@mui/icons-material": "^5.10.9", "@mui/material": "^5.8.6", - "@affine/data-services": "workspace:@affine/data-services@*", "@toeverything/pathfinder-logger": "workspace:@affine/logger@*", "cmdk": "^0.1.20", "css-spring": "^4.1.0", @@ -44,6 +44,7 @@ "@types/node": "18.7.18", "@types/react": "18.0.20", "@types/react-dom": "18.0.6", + "chalk-next": "^6.1.5", "eslint": "8.22.0", "eslint-config-next": "12.3.1", "eslint-config-prettier": "^8.5.0", diff --git a/packages/app/scripts/__tests__/printer.spec.ts b/packages/app/scripts/__tests__/printer.spec.ts new file mode 100644 index 0000000000..beb14114e6 --- /dev/null +++ b/packages/app/scripts/__tests__/printer.spec.ts @@ -0,0 +1,21 @@ +import { describe, test, expect } from '@jest/globals'; +import { printer } from './../printer'; +const chalk = require('chalk'); +describe('printer', () => { + test('test debug', () => { + expect(printer.debug('test debug')).toBe( + chalk.green`debug` + chalk.white(' - test debug') + ); + }); + + test('test info', () => { + expect(printer.info('test info')).toBe( + chalk.rgb(19, 167, 205)`info` + chalk.white(' - test info') + ); + }); + test('test warn', () => { + expect(printer.warn('test warn')).toBe( + chalk.yellow`warn` + chalk.white(' - test warn') + ); + }); +}); diff --git a/packages/app/scripts/printer.js b/packages/app/scripts/printer.js new file mode 100644 index 0000000000..8853819ed5 --- /dev/null +++ b/packages/app/scripts/printer.js @@ -0,0 +1,20 @@ +const chalk = require('chalk'); +const printer = { + debug: msg => { + const result = chalk.green`debug` + chalk.white(' - ' + msg); + console.log(result); + return result; + }, + info: msg => { + const result = chalk.rgb(19, 167, 205)`info` + chalk.white(' - ' + msg); + console.log(result); + return result; + }, + warn: msg => { + const result = chalk.yellow`warn` + chalk.white(' - ' + msg); + console.log(result); + return result; + }, +}; + +module.exports = { printer }; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 0b01c0454b..f5b079ef53 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -60,6 +60,7 @@ importers: '@types/node': 18.7.18 '@types/react': 18.0.20 '@types/react-dom': 18.0.6 + chalk-next: ^6.1.5 cmdk: ^0.1.20 css-spring: ^4.1.0 dayjs: ^1.11.7 @@ -114,6 +115,7 @@ importers: '@types/node': 18.7.18 '@types/react': 18.0.20 '@types/react-dom': 18.0.6 + chalk-next: 6.1.5 eslint: 8.22.0 eslint-config-next: 12.3.1_76twfck5d7crjqrmw4yltga7zm eslint-config-prettier: 8.5.0_eslint@8.22.0 @@ -2829,6 +2831,14 @@ packages: engines: {node: '>=4'} dev: true + /axios/0.21.4: + resolution: {integrity: sha512-ut5vewkiu8jjGBdqpM44XxjuCjq9LAKeHVmoVfHVzy8eHgxxq8SbAVQNovDA8mVi05kP0Ea/n/UzcSHcTJQfNg==} + dependencies: + follow-redirects: 1.15.2 + transitivePeerDependencies: + - debug + dev: true + /axobject-query/2.2.0: resolution: {integrity: sha512-Td525n+iPOOyUQIeBfcASuG6uJsDOITl7Mds5gFyerkWiX7qhUTdYUBlSgNMyVqtSJqwpt1kXGLdUt6SykLMRA==} dev: true @@ -3017,6 +3027,18 @@ packages: /caniuse-lite/1.0.30001419: resolution: {integrity: sha512-aFO1r+g6R7TW+PNQxKzjITwLOyDhVRLjW0LcwS/HCZGUUKTGNp9+IwLC4xyDSZBygVL/mxaFR3HIV6wEKQuSzw==} + /chalk-next/6.1.5: + resolution: {integrity: sha512-OAx9F3vSk18qpfCohk0849/j3GyaoIpv8eXjmpdbmLZt+5+sWYq8xwt3B5ue25irLcxFcLL2hAbxxHSsBxupbw==} + engines: {node: '>=10'} + dependencies: + ansi-styles: 4.3.0 + axios: 0.21.4 + fs: 0.0.1-security + supports-color: 7.2.0 + transitivePeerDependencies: + - debug + dev: true + /chalk/2.4.2: resolution: {integrity: sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==} engines: {node: '>=4'} @@ -4195,6 +4217,16 @@ packages: resolution: {integrity: sha512-W7cHV7Hrwjid6lWmy0IhsWDFQboWSng25U3VVywpHOTJnnAZNPScog67G+cVpeX9f7yDD21ih0WDrMMT+JoaYg==} dev: false + /follow-redirects/1.15.2: + resolution: {integrity: sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA==} + engines: {node: '>=4.0'} + peerDependencies: + debug: '*' + peerDependenciesMeta: + debug: + optional: true + dev: true + /form-data-encoder/2.1.4: resolution: {integrity: sha512-yDYSgNMraqvnxiEXO4hi88+YZxaHC6QKzb5N84iRCTDeRO7ZALpir/lVmf/uXUhnwUr2O4HU8s/n6x+yNjQkHw==} engines: {node: '>= 14.17'} @@ -4203,6 +4235,10 @@ packages: /fs.realpath/1.0.0: resolution: {integrity: sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==} + /fs/0.0.1-security: + resolution: {integrity: sha512-3XY9e1pP0CVEUCdj5BmfIZxRBTSDycnbqhIOGec9QYtmVH2fbLpj86CFWkrNOkt/Fvty4KZG5lTglL9j/gJ87w==} + dev: true + /fsevents/2.3.2: resolution: {integrity: sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==} engines: {node: ^8.16.0 || ^10.6.0 || >=11.0.0}