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>
This commit is contained in:
Chi Zhang
2022-12-29 10:20:57 +08:00
committed by GitHub
parent 0b418e05b2
commit 4dfccf5c95
6 changed files with 92 additions and 5 deletions
+3 -1
View File
@@ -1,4 +1,6 @@
**/webpack.config.js
**/jest.config.js
**/scripts/*.js
**/node_modules/**
.github/**
.github/**
**/__tests__/**
+10 -3
View File
@@ -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,
},
];
}
+2 -1
View File
@@ -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",
@@ -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')
);
});
});
+20
View File
@@ -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 };
+36
View File
@@ -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}