-
-
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.
- Loading branch information
1 parent
1d97867
commit b4973ff
Showing
6 changed files
with
408 additions
and
8 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 |
---|---|---|
@@ -0,0 +1,89 @@ | ||
#!/usr/bin/env node | ||
const fs = require('node:fs') | ||
const path = require('node:path') | ||
const process = require('node:process') | ||
|
||
const { Command } = require('commander') | ||
const inquirer = require('inquirer') | ||
const program = new Command() | ||
|
||
const rootDir = path.join(__dirname, '..') | ||
const configDir = path.join(rootDir, 'template', 'config') | ||
const currentDir = process.cwd() | ||
|
||
const file = { | ||
eslintignore: '.eslintignore', | ||
eslintrc: '.eslintrc.js', | ||
prettierrc: '.prettierrc', | ||
} | ||
|
||
const templateConfig = { | ||
eslintignore: path.join(configDir, file.eslintignore), | ||
eslintrc: path.join(configDir, file.eslintrc), | ||
prettierrc: path.join(configDir, file.prettierrc), | ||
} | ||
|
||
const destination = { | ||
eslintignore: path.join(currentDir, file.eslintignore), | ||
eslintrc: path.join(currentDir, file.eslintrc), | ||
prettierrc: path.join(currentDir, file.prettierrc), | ||
} | ||
|
||
program.name('eslint-config-ts-prefixer') | ||
program | ||
.command('config') | ||
.description( | ||
`create ${file.prettierrc}/${file.eslintrc}/${file.eslintignore} files your current directory.` | ||
) | ||
.option('--prettier', `create ${file.prettierrc} only`) | ||
.option('--eslint', `create ${file.eslintrc}/${file.eslintignore} only`) | ||
.action(async (options) => { | ||
if (Object.keys(options).length === 0) { | ||
await createESLintConfig() | ||
await createPrettierConfig() | ||
return | ||
} | ||
if (options.eslint === true) await createESLintConfig() | ||
if (options.prettier === true) await createPrettierConfig() | ||
}) | ||
|
||
// run | ||
program.parse() | ||
|
||
// functions | ||
async function createESLintConfig() { | ||
await copyConfig('eslintrc') | ||
await copyConfig('eslintignore') | ||
} | ||
|
||
async function createPrettierConfig() { | ||
await copyConfig('prettierrc') | ||
} | ||
|
||
async function copyConfig(filename) { | ||
if (fs.existsSync(destination[filename])) { | ||
const answer = await inquirer.prompt({ | ||
choices: [ | ||
{ | ||
key: 'y', | ||
name: 'Overwrite', | ||
value: 'overwrite', | ||
}, | ||
{ | ||
key: 'n', | ||
name: 'Abort', | ||
value: 'abort', | ||
}, | ||
], | ||
message: `Your ${filename} already exists.`, | ||
name: 'overwrite', | ||
type: 'expand', | ||
}) | ||
|
||
if (answer.overwrite === 'overwrite') { | ||
fs.copyFileSync(templateConfig[filename], destination[filename]) | ||
} | ||
} else { | ||
fs.copyFileSync(templateConfig[filename], destination[filename]) | ||
} | ||
} |
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 @@ | ||
node_modules |
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,7 @@ | ||
module.export = { | ||
extends: 'ts-prefixer', | ||
globals: {}, | ||
plugins: [], | ||
rules: {}, | ||
settings: {}, | ||
} |
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,4 @@ | ||
{ | ||
"singleQuote": true, | ||
"semi": false | ||
} |
Oops, something went wrong.