-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: 🔥 added init wizard in configuration
added init wizard in configuration
- Loading branch information
Tal Rofe
committed
Apr 16, 2022
1 parent
75a35ee
commit f393958
Showing
19 changed files
with
309 additions
and
128 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
🚧 This package is in progres.. :) 🚧 | ||
🚧 This package is in progres... Use it once released with version 1.x.x :) 🚧 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,13 @@ | ||
import { getCLIArgv } from '@/utils/cli-argv'; | ||
import { startCLIPhase } from '@/utils/cli-phase'; | ||
import { getCLIArgv } from '@/utils/argv'; | ||
import StartCLI from '@/modules/cli'; | ||
import StartConfiguration from '@/modules/configuration'; | ||
|
||
(() => { | ||
const argv = getCLIArgv(); | ||
|
||
startCLIPhase(argv); | ||
const configFromCLI = StartCLI(argv); | ||
|
||
if (configFromCLI) { | ||
StartConfiguration(); | ||
} | ||
})(); |
This file was deleted.
Oops, something went wrong.
64 changes: 10 additions & 54 deletions
64
src/utils/cli-help.ts → src/modules/cli/functions/help.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import inquirer from 'inquirer'; | ||
|
||
import { convertAliasesAnswers, exportFilesFromInit } from '../utils/init'; | ||
import type { IAliasAnswer, IInitialAnswers, IAliasAnswers } from '../models/init'; | ||
|
||
/** | ||
* The function initialize the project with basic Inflint configuration | ||
* @returns void | ||
*/ | ||
export const initConfiguration = async () => { | ||
const initialQuestions: inquirer.QuestionCollection = [ | ||
{ | ||
type: 'list', | ||
name: 'file_format', | ||
message: 'Please choose the configuration file format:', | ||
default: 'Javascript', | ||
choices: ['Javascript', 'JSON', 'YAML'], | ||
}, | ||
{ | ||
type: 'list', | ||
name: 'with_ignore_file', | ||
message: 'Do you want to create an ignore file?', | ||
default: 'Yes', | ||
choices: ['Yes', 'No'], | ||
}, | ||
{ | ||
type: 'list', | ||
name: 'with_aliases', | ||
message: 'Do you want to set some aliases to your configuration?', | ||
default: 'No', | ||
choices: ['Yes', 'No'], | ||
}, | ||
]; | ||
|
||
const initialAnswers = await inquirer.prompt<IInitialAnswers>(initialQuestions); | ||
const aliasesAnswers: IAliasAnswers = []; | ||
|
||
if (initialAnswers.with_aliases === 'Yes') { | ||
let stopAliases = false; | ||
|
||
do { | ||
const aliasQuestions: inquirer.QuestionCollection = [ | ||
{ | ||
type: 'input', | ||
name: 'name', | ||
message: 'Enter name of the alias:', | ||
validate: (input: string) => (input ? true : 'Please enter an alias name'), | ||
}, | ||
{ | ||
type: 'input', | ||
name: 'regex', | ||
message: 'Enter regex the alias will match:', | ||
validate: (input: string) => (input ? true : 'Please enter a regex for the alias'), | ||
}, | ||
{ | ||
type: 'list', | ||
name: 'with_resume', | ||
message: 'Do you want to set an another alias?', | ||
default: 'Yes', | ||
choices: ['Yes', 'No'], | ||
}, | ||
]; | ||
|
||
const aliasAnswers = await inquirer.prompt<IAliasAnswer>(aliasQuestions); | ||
|
||
aliasesAnswers.push({ | ||
name: aliasAnswers.name, | ||
regex: aliasAnswers.regex, | ||
}); | ||
|
||
if (aliasAnswers.with_resume === 'No') { | ||
stopAliases = true; | ||
} | ||
} while (!stopAliases); | ||
} | ||
|
||
const convertedAliases = convertAliasesAnswers(aliasesAnswers); | ||
|
||
await exportFilesFromInit(initialAnswers.file_format, initialAnswers.with_ignore_file, convertedAliases); | ||
}; |
2 changes: 1 addition & 1 deletion
2
src/utils/cli-version.ts → src/modules/cli/functions/version.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { ParsedArgs } from 'minimist'; | ||
|
||
import { printHelp } from './functions/help'; | ||
import { printVersion } from './functions/version'; | ||
import { initConfiguration } from './functions/init'; | ||
|
||
const StartCLI = (argv: ParsedArgs) => { | ||
if (argv['h'] === true || argv['help'] === true) { | ||
printHelp(); | ||
|
||
return null; | ||
} | ||
|
||
if (argv['v'] === true || argv['version'] === true) { | ||
printVersion(); | ||
|
||
return null; | ||
} | ||
|
||
if (argv['init'] === true) { | ||
initConfiguration(); | ||
|
||
return null; | ||
} | ||
|
||
return null; | ||
}; | ||
|
||
export default StartCLI; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
type IOptionsKeys = | ||
| 'noInflintrc' | ||
| 'config' | ||
| 'rule' | ||
| 'alias' | ||
| 'ignorePath' | ||
| 'noIgnore' | ||
| 'ignorePattern' | ||
| 'quiet' | ||
| 'maxWarnings' | ||
| 'outputFile' | ||
| 'format' | ||
| 'color' | ||
| 'init' | ||
| 'debug' | ||
| 'help' | ||
| 'version' | ||
| 'printRule'; | ||
|
||
export const options: Record<IOptionsKeys, [string, string]> = { | ||
noInflintrc: [ | ||
'--no-inflintrc', | ||
'Disable use of configuration from configuration file or package.json. Default: false', | ||
], | ||
config: ['-c, --config (path::String)', 'Inflint will use the provided configuration file'], | ||
rule: ['--rule (String)', 'Specify rules'], | ||
alias: ['--alias (String)', 'Specify custom aliases'], | ||
ignorePath: ['--ignore-path (path::String)', 'Specify path of ignore file'], | ||
noIgnore: ['--no-ignore', 'Disable use of ignore files and patterns. Default: false'], | ||
ignorePattern: [ | ||
'--ignore-pattern (String)', | ||
'Pattern of files to ignore (in addition to those in .inflintignore)', | ||
], | ||
quiet: ['--quiet', 'Report errors only. Default: false'], | ||
maxWarnings: ['--max-warnings (Int)', 'Number of warnings to trigger non-zero exit code. Default: -1'], | ||
outputFile: ['-o, --output-file (path::String)', 'Specify file to write report to'], | ||
format: ['-f, --format (String)', 'Use a specific output format. Default: "stylish"'], | ||
color: ['--color, --no-color', 'Force enabling/disabling of color'], | ||
init: ['--init', 'Run configuration initialization wizard. Default: false'], | ||
debug: ['--debug', 'Output debugging information'], | ||
help: ['-h, --help', 'Show help'], | ||
version: ['-v, --version', 'Output the version number'], | ||
printRule: ['--print-rule (path::String)', 'Print the expected rule to be enforced on a given file'], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
export type IBooleanQuestion = 'Yes' | 'No'; | ||
|
||
export type IFileFormat = 'Javascript' | 'JSON' | 'YAML'; | ||
|
||
export interface IAliasAnswer { | ||
readonly name: string; | ||
readonly regex: string; | ||
readonly with_resume: IBooleanQuestion; | ||
} | ||
|
||
export interface IInitialAnswers { | ||
readonly file_format: IFileFormat; | ||
readonly with_ignore_file: IBooleanQuestion; | ||
readonly with_aliases: IBooleanQuestion; | ||
} | ||
|
||
export type IAliasAnswers = Omit<IAliasAnswer, 'with_resume'>[]; |
Oops, something went wrong.