Skip to content

Conversation

popomore
Copy link
Member

@popomore popomore commented Oct 11, 2017

Checklist
  • npm test passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines
Affected core subsystem(s)
Description of change
  • export this.child
  • support customize stdout and stderr

- 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;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个原来这样设置有啥用

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不是把 node_modules 里面的 node 加入到环境变量么?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

但是没加到 PATH

Copy link
Member

@atian25 atian25 Oct 11, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

哈... 写漏了。这块当时还在想怎么写测试

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个测不了,nyc 有 hack

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

之前想过一种,调用 nodeinstall 下载一个 node 版本,然后 app 里面 print 下,但麻烦就放弃了。

@popomore popomore changed the title refactor: modify the directory of logDir WIP: refactor: modify the directory of logDir Oct 11, 2017
@codecov-io
Copy link

codecov-io commented Oct 11, 2017

Codecov Report

Merging #8 into master will decrease coverage by 0.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            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
Impacted Files Coverage Δ
lib/cmd/start.js 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 49d8033...1a7805b. Read the comment docs.

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:`)));
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

只能这样假装测试一下

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

哈哈哈哈哈

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

: 这个改为 path.delimiter 吧,万一后面支持 win

@popomore popomore changed the title WIP: refactor: modify the directory of logDir refactor: modify the directory of logDir Oct 11, 2017
@popomore
Copy link
Member Author

这个用例 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) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

暴露了这个方法

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

要不要改为 generator 的?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

哪里是 generator 的?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

* getFrameworkPath,这种一般都要去检查文件啥的吧, utils 里面是用 sync 么?

@popomore
Copy link
Member Author

@atian25 过了

Copy link
Member

@atian25 atian25 left a 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';
Copy link
Member

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) {
Copy link
Member

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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里其实如果能重命名为上次启动的时间,而不是本次的时间会更好一点,避免误导。
但好像 fs 拿文件的 create time 不准?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

标记为重启时间也还行

Copy link
Member

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",
Copy link
Member

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');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这样会误删其他 logs 吧?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

本来这个目录都要删除吧

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这是 home 目录下的吧,如果同时开多个项目,那边还在跑的时候,这个单测就把人家的日志删了。

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

换成 mock 的目录

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

嗯,这个目录要不要加到 gitignore 去?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

用例会删除的

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:`)));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

: 这个改为 path.delimiter 吧,万一后面支持 win

@popomore
Copy link
Member Author

@atian25
Copy link
Member

atian25 commented Oct 12, 2017

+1

@popomore
Copy link
Member Author

过了

@atian25
Copy link
Member

atian25 commented Oct 12, 2017

不用 homedir 的新功能?

那你合了发版本吧

@popomore
Copy link
Member Author

homedir 已经发布了

@popomore popomore merged commit cfd0d2f into master Oct 12, 2017
@popomore popomore deleted the log branch October 12, 2017 03:35
@atian25
Copy link
Member

atian25 commented Oct 12, 2017

顺便 link 下自定义日志的那个 Issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants