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
+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 };