-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Add private flag for yarn init command #4165
Changes from 4 commits
be1eda4
666c8b7
5e4b024
70c82b8
1d385cb
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
yarn-offline-mirror=./mirror-for-offline |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,9 +11,11 @@ import * as validate from '../../util/normalize-manifest/validate.js'; | |
|
||
const objectPath = require('object-path'); | ||
const path = require('path'); | ||
const yn = require('yn'); | ||
|
||
export function setFlags(commander: Object) { | ||
commander.option('-y, --yes', 'use default options'); | ||
commander.option('-p, --private', 'use default options and private true'); | ||
} | ||
|
||
export function hasWrapper(commander: Object, args: Array<string>): boolean { | ||
|
@@ -89,12 +91,18 @@ export async function run(config: Config, reporter: Reporter, flags: Object, arg | |
question: 'license', | ||
default: String(config.getOption('init-license')), | ||
}, | ||
{ | ||
key: 'private', | ||
question: 'private', | ||
default: '', | ||
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. If the default was If the above change is not done, the default should probably be "false" instead of empty string so that when the question is printed to the user they can see that it is explicitly false by default. Empty string might make someone question if the default is actually going to end up true or false (in reality it depends how "yn" interprets empty string) 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. I keep |
||
inputFormatter: yn, | ||
}, | ||
]; | ||
|
||
// get answers | ||
const pkg = {}; | ||
for (const entry of keys) { | ||
const {yes} = flags; | ||
const {yes, private: privateFlag} = flags; | ||
const {key: manifestKey} = entry; | ||
let {question, default: def} = entry; | ||
|
||
|
@@ -114,8 +122,12 @@ export async function run(config: Config, reporter: Reporter, flags: Object, arg | |
def = val; | ||
} | ||
|
||
if (manifestKey === 'private' && privateFlag) { | ||
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. This conditional could be eliminated if the default is set above in the array of questions 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. no need, just add |
||
def = true; | ||
} | ||
|
||
if (def) { | ||
question += ` (${def})`; | ||
question += ` (${def.toString()})`; | ||
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. Why the additional 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. because after i add this flag, 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. But it's already inside a string interpolation, so would get converted to a string already. 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. If removed it will generate 2 errors:
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. That's interesting. That is Flow complaining about the type. I didn't think it would complain inside an interpolated string. Oh well, in that case the |
||
} | ||
|
||
let answer; | ||
|
@@ -141,6 +153,9 @@ export async function run(config: Config, reporter: Reporter, flags: Object, arg | |
} | ||
|
||
if (answer) { | ||
if (entry.inputFormatter) { | ||
answer = entry.inputFormatter(answer); | ||
} | ||
objectPath.set(pkg, manifestKey, answer); | ||
} | ||
} | ||
|
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.
Could also add
validation
andvalidationError
fields to ensure the user enters something that "yn" can convert to boolean (or only accept "true" and "false" and eliminate the dependency on "yn").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.
I think
1
i shorter way user want to fill this key, so i useyn
. And everything can be become a boolean when we useyn
. So, if users want to change it, they can change it later by editpackage.json
file. Justboolean
value is approved.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.
This is a valid point. I was thinking yn might error if the user types in something like "i guess so" as the answer, but I suspect it will just try to convert it anyway. As long as yn doesn't throw an exception, then I would be OK with no validation.