-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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 more features to "deno init" subcommand #12781
Comments
I have created an installable package. Please try it. Thanks. |
I don't think we want to enoucrage many projects to be created with all the possible compiler options because generally people should not be changing any of the compiler options. If we do have this command, perhaps just have all the settings mostly empty, which should be a sufficient starting point. The LSP provides autocomplete to explore other options. |
I am also not in favour. The CLI is designed to have sensible defaults and to allow incremental changes when those defaults don't make sense for a particular context. That would reduce an init command to writing out an empty |
Rather than empty, this could be solved by generating the file as Example
|
@jsejcksn Thank you for the suggestion! How about this script? function generate(schema: any): any {
if ("default" in schema) {
return schema.default;
}
if ("type" in schema) {
switch (schema.type) {
case "object":
return Object.fromEntries(
Object.entries(schema.properties).map(([key, value]) => {
return [key, generate(value)];
}),
);
case "array":
return [];
}
}
}
const schemaUrl =
"https://deno.land/x/[email protected]/cli/schemas/config-file.v1.json";
const response = await fetch(schemaUrl);
const schema = await response.json();
const config = JSON.stringify(generate(schema), null, 2);
for(const line of config.split('\n')) {
if (!line.includes('{}') && !line.includes('[]') && (line.match(/[{}\[\]]/))) {
console.log(line)
} else {
console.log('//'+line)
}
} This script produces the JSONC as follows. deno.jsonc{
"compilerOptions": {
// "allowJs": true,
// "allowUnreachableCode": false,
// "allowUnusedLabels": false,
// "checkJs": false,
// "experimentalDecorators": true,
// "jsx": "react",
// "jsxFactory": "React.createElement",
// "jsxFragmentFactory": "React.Fragment",
// "jsxImportSource": "react",
// "keyofStringsOnly": false,
"lib": [
// "deno.window"
],
// "noFallthroughCasesInSwitch": false,
// "noImplicitAny": true,
// "noImplicitReturns": false,
// "noImplicitThis": true,
// "noImplicitUseStrict": true,
// "noStrictGenericChecks": false,
// "noUnusedLocals": false,
// "noUnusedParameters": false,
// "noUncheckedIndexedAccess": false,
// "strict": true,
// "strictBindCallApply": true,
// "strictFunctionTypes": true,
// "strictPropertyInitialization": true,
// "strictNullChecks": true,
// "suppressExcessPropertyErrors": false,
// "suppressImplicitAnyIndexErrors": false
},
"lint": {
"files": {
// "include": [],
// "exclude": []
},
"rules": {
// "tags": [],
// "exclude": [],
// "include": []
}
},
"fmt": {
"files": {
// "include": [],
// "exclude": []
},
"options": {
// "useTabs": false,
// "lineWidth": 80,
// "indentWidth": 2,
// "singleQuote": false,
// "proseWrap": "always"
}
}
} |
@tani It's probably better to think about the actual implementation after there is consensus about the content and format. Here are some thoughts in regard to that:
|
"deno init" subcommand was added in #15469 |
@bartlomieju The possibility of generating a config file (as described in this issue) is mentioned in the PR, but it doesn't look like the PR actually included this feature. Since you closed this issue, is that a signal of "no interest to implement"? |
I've reopened the issue. For now we're shipping a first iteration of |
@bartlomieju Thanks! Maybe we can change the title to reflect the more specific nature of this suggestion in comparison to what was merged. |
I'm not sure the A more useful |
to expand upon @dragonwocky, I think that npm does something pretty useful, with the |
I don't think this has anything actionable for us to do regarding |
Related to #5040, we propose the
deno.json
config generator liketsc --init
fortsconfig.json
.Background
Because of the increasing configuration parameters, deno developers employed the configuration file
deno.json
to keep the configuration parameter for each project.Problem
As there exist many parameters, it is hard to know what parameter we can use.
In the close future, deno may have more options to tweak their behaviour.
We need to write a new configuration file from a scratch for each project.
Solution
We already have a JSON Schema to validate a configuration file.
The schema file contains the default value information.
Thus, we can mechanically generate the default configuration file from this schema.
Related work
We can see similar functions in the related project.
npm init
yarn init
cargo init
tsc --init
eslint --init
We also have the counterexample.
babel
does not provide ainit
command.Proof of Concept
The text was updated successfully, but these errors were encountered: