-
Notifications
You must be signed in to change notification settings - Fork 31
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
feat: support ts from env and pkg #71
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
'use strict'; | ||
|
||
const fs = require('fs'); | ||
const path = require('path'); | ||
const mm = require('mm'); | ||
const debug = require('debug')('mm'); | ||
|
@@ -39,6 +40,21 @@ module.exports = function formatOptions(options) { | |
} | ||
options.customEgg = options.framework = framework; | ||
|
||
// typescript | ||
if (!options.hasOwnProperty('typescript')) { | ||
if (process.env.EGG_TYPESCRIPT) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. 感觉 env 优先更合理一些 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. 所以命令行 > 环境 > pkg There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这里应该不存在命令行的情况, |
||
options.typescript = Boolean(process.env.EGG_TYPESCRIPT); | ||
} else { | ||
const pkgFile = path.join(options.baseDir, 'package.json'); | ||
if (fs.existsSync(pkgFile)) { | ||
const pkgInfo = require(pkgFile); | ||
if (pkgInfo && pkgInfo.egg && pkgInfo.egg.typescript) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. pkgInfo.egg.typescript === true |
||
options.typescript = true; | ||
} | ||
} | ||
} | ||
} | ||
|
||
const plugins = options.plugins = options.plugins || {}; | ||
|
||
// add self as a plugin | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"name": "ts", | ||
"egg": { | ||
"typescript": true | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -153,4 +153,19 @@ describe('test/format_options.test.js', () => { | |
formatOptions(); | ||
assert.notEqual(process.env.HOME, baseDir); | ||
}); | ||
|
||
it('should read egg.typescript', () => { | ||
const baseDir = path.join(__dirname, 'fixtures/ts'); | ||
mm(process, 'cwd', () => baseDir); | ||
const opts = formatOptions(); | ||
assert(opts.typescript === true); | ||
}); | ||
|
||
it('should read process.env.EGG_TYPESCRIPT', () => { | ||
const baseDir = path.join(__dirname, 'fixtures/demo'); | ||
mm(process, 'cwd', () => baseDir); | ||
mm(process.env, 'EGG_TYPESCRIPT', true); | ||
const opts = formatOptions(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这个不是应该传 typescript 测一下优先级? |
||
assert(opts.typescript === true); | ||
}); | ||
}); |
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.
不要 hasOwnProperty 吧
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.
options. typescript === undefined ?
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.
'typescript; in options
?测试是不是就提供环境变量就好了