-
Notifications
You must be signed in to change notification settings - Fork 37
refactor: modify the directory of logDir #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
- export this.child - support customize stdout and stderr
const envPath = env.PATH || env.Path; | ||
if (envPath) { | ||
// for nodeinstall | ||
envPath = path.join(baseDir, 'node_modules/.bin') + path.delimiter + envPath; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个原来这样设置有啥用
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不是把 node_modules
里面的 node 加入到环境变量么?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
但是没加到 PATH
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
哈... 写漏了。这块当时还在想怎么写测试
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个测不了,nyc 有 hack
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
之前想过一种,调用 nodeinstall 下载一个 node 版本,然后 app 里面 print 下,但麻烦就放弃了。
Codecov Report
@@ Coverage Diff @@
## master #8 +/- ##
=========================================
- Coverage 97.72% 97.7% -0.02%
=========================================
Files 6 6
Lines 132 131 -1
=========================================
- Hits 129 128 -1
Misses 3 3
Continue to review full report at Codecov.
|
test/start.test.js
Outdated
let result = yield httpclient.request('http://127.0.0.1:7001/env'); | ||
assert(result.data.toString() === 'pre, true'); | ||
result = yield httpclient.request('http://127.0.0.1:7001/path'); | ||
assert(result.data.toString().match(new RegExp(`^${fixturePath}/node_modules/.bin:`))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
只能这样假装测试一下
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
哈哈哈哈哈
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:
这个改为 path.delimiter
吧,万一后面支持 win
这个用例 windows 是不是跑不起来 |
lib/cmd/start.js
Outdated
function* getRotatelog(logDir) { | ||
const stdoutPath = path.join(logDir, 'master-stdout.log'); | ||
const stderrPath = path.join(logDir, 'master-stderr.log'); | ||
getFrameworkPath(params) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
暴露了这个方法
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
要不要改为 generator 的?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
哪里是 generator 的?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* getFrameworkPath
,这种一般都要去检查文件啥的吧, utils 里面是用 sync 么?
@atian25 过了 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
|
||
const env = context.env; | ||
env.HOME = HOME; | ||
env.NODE_ENV = 'production'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PWD
不传了?
看到下面 options 传了
lib/cmd/start.js
Outdated
function* getRotatelog(logDir) { | ||
const stdoutPath = path.join(logDir, 'master-stdout.log'); | ||
const stderrPath = path.join(logDir, 'master-stderr.log'); | ||
getFrameworkPath(params) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
要不要改为 generator 的?
/* istanbul ignore else */ | ||
if (yield fs.exists(stderrPath)) { | ||
yield fs.rename(stderrPath, stderrPath + timestamp); | ||
yield fs.rename(logfile, logfile + timestamp); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里其实如果能重命名为上次启动的时间,而不是本次的时间会更好一点,避免误导。
但好像 fs 拿文件的 create time 不准?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
标记为重启时间也还行
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
只是感觉会误导的,一般不都是文件名 + 启动时间
么? 当时想改的,但没找到获取时间的地方。
不过这里面应该也没什么太多有价值的 log。
package.json
Outdated
"cov": "egg-bin cov", | ||
"lint": "eslint .", | ||
"ci": "egg-bin pkgfiles --check && npm run lint && npm run cov", | ||
"ci": "egg-bin pkgfiles -- --check && npm run lint && npm run cov", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里不用 --
不是 npm scripts。
const fixturePath = path.join(__dirname, 'fixtures/example'); | ||
const homePath = homedir(); | ||
const logDir = path.join(homePath, 'logs/example'); | ||
const logDir = path.join(homePath, 'logs'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这样会误删其他 logs 吧?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
本来这个目录都要删除吧
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这是 home 目录下的吧,如果同时开多个项目,那边还在跑的时候,这个单测就把人家的日志删了。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
换成 mock 的目录
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
嗯,这个目录要不要加到 gitignore 去?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
用例会删除的
test/start.test.js
Outdated
let result = yield httpclient.request('http://127.0.0.1:7001/env'); | ||
assert(result.data.toString() === 'pre, true'); | ||
result = yield httpclient.request('http://127.0.0.1:7001/path'); | ||
assert(result.data.toString().match(new RegExp(`^${fixturePath}/node_modules/.bin:`))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:
这个改为 path.delimiter
吧,万一后面支持 win
+1 |
过了 |
不用 homedir 的新功能? 那你合了发版本吧 |
homedir 已经发布了 |
顺便 link 下自定义日志的那个 Issue |
Checklist
npm test
passesAffected core subsystem(s)
Description of change