@allohamora/cli
Advanced tools
Comparing version 1.20.0 to 1.21.0
133
bin/cli.js
@@ -8,2 +8,3 @@ #!/usr/bin/env node | ||
var node_events = require('node:events'); | ||
var prettier$1 = require('prettier'); | ||
var ora = require('ora'); | ||
@@ -370,42 +371,53 @@ var inquirer = require('inquirer'); | ||
const defaultConfig$a = { | ||
config: { | ||
semi: true, | ||
trailingComma: 'all', | ||
singleQuote: true, | ||
printWidth: 120, | ||
tabWidth: 2, | ||
overrides: [ | ||
{ | ||
files: '*.yml', | ||
options: { | ||
singleQuote: false, | ||
}, | ||
}, | ||
], | ||
}, | ||
ignore: ['dist', 'node_modules', 'public', '.husky', 'package-lock.json', 'coverage'], | ||
scripts: [ | ||
{ name: 'format', script: 'prettier . --check' }, | ||
{ name: 'format:fix', script: 'prettier --write .' }, | ||
], | ||
}; | ||
const [getConfig$a] = jsCategoryState.useConfigState({ | ||
default: defaultConfig$a, | ||
}); | ||
const format = async (input) => { | ||
const { config } = getConfig$a(); | ||
return await prettier$1.format(input, { parser: 'typescript', ...config }); | ||
}; | ||
const optional = (value, map) => (value ? map(value) : ''); | ||
const buildConfig = (config) => { | ||
const start = config.typescript ? `// @ts-check\n` : ''; | ||
const start = optional(config.typescript, () => '// @ts-check'); | ||
const imports = `${config.imports.map((item) => `${item};`).join('\n')}\n`.trim(); | ||
const exportStart = config.typescript ? `export default tseslint.config(` : `export default [`; | ||
const exportEnd = config.typescript ? `);` : `];`; | ||
const imports = `${start}${config.imports.join(';\n')}${config.imports.length ? ';\n' : ''}`; | ||
const configs = config.configs.map((item) => ` ${item},`).join('\n'); | ||
const files = config.eslintConfig.files | ||
? ` files: ${JSON.stringify(config.eslintConfig.files).replace(/"/gim, `'`)},` | ||
: ''; | ||
const ignores = config.eslintConfig.ignores | ||
? ` ignores: [\n${config.eslintConfig.ignores.map((item) => ` '${item}'`).join(',\n')}\n ],` | ||
: ''; | ||
const globals = config.eslintConfig.languageOptions?.globals | ||
? config.eslintConfig.languageOptions.globals.map((item) => ` ...globals.${item}`).join(',\n') | ||
: ''; | ||
const parserOptions = config.eslintConfig.languageOptions?.parserOptions | ||
? ` parserOptions: {\n${Object.entries(config.eslintConfig.languageOptions.parserOptions) | ||
.map(([key, value]) => ` ${key}: ${value}`) | ||
.join(',\n')}\n }` | ||
: ''; | ||
const plugins = config.eslintConfig.plugins | ||
? ` plugins: { ${Object.entries(config.eslintConfig.plugins) | ||
.map(([key, value]) => `\n '${key}': ${value}`) | ||
.join(',')}\n },` | ||
: ''; | ||
const rules = config.eslintConfig.rules | ||
? ` rules: ${JSON.stringify(config.eslintConfig.rules, null, 2) | ||
.replace(/"/gim, "'") | ||
.replace(/\n {2}/gim, '\n' + ' '.repeat(6)) | ||
.replace('\n}', '\n }')},` | ||
: ''; | ||
const languageOptions = config.eslintConfig.languageOptions | ||
? ` languageOptions: { | ||
globals: { | ||
${globals} | ||
}${parserOptions ? `,\n${parserOptions}` : ''} | ||
},` | ||
: ''; | ||
const mainConfig = ` {\n${[files, ignores, languageOptions, plugins, rules].filter(Boolean).join('\n')}\n }`; | ||
return [imports, exportStart, configs, mainConfig, exportEnd].filter(Boolean).join('\n'); | ||
const configs = config.configs.map((item) => `${item},`).join('\n'); | ||
const files = optional(config.eslintConfig.files, (value) => `files: ${JSON.stringify(value)}`); | ||
const plugins = optional(config.eslintConfig.plugins, (values) => `plugins: {${Object.entries(values) | ||
.map(([key, value]) => `'${key}': ${value}`) | ||
.join(',')}}`); | ||
const rules = optional(config.eslintConfig.rules, (value) => `rules: ${JSON.stringify(value)}`); | ||
const globals = optional(config.eslintConfig.languageOptions?.globals, (value) => `globals: {${value.map((item) => `...globals.${item}`).join(',')}}`); | ||
const parserOptions = optional(config.eslintConfig.languageOptions?.parserOptions, (value) => `parserOptions: ${JSON.stringify(value)}`); | ||
const languageOptions = optional(config.eslintConfig.languageOptions, () => `languageOptions: {${[globals, parserOptions].filter(Boolean).join(',')}}`); | ||
const ignoresConfig = optional(config.eslintConfig.ignores, (value) => `{ignores: ${JSON.stringify(value)}},`); | ||
const mainContent = [files, languageOptions, plugins, rules].filter(Boolean).join(','); | ||
const mainConfig = optional(mainContent, (content) => `{${content}}`); | ||
return [start, imports, exportStart, configs, ignoresConfig, mainConfig, exportEnd].filter(Boolean).join('\n'); | ||
}; | ||
@@ -417,3 +429,3 @@ const eslint = async () => { | ||
await installDevelopmentDependencies(PACKAGE_NAME$3, ...dependencies); | ||
const eslintConfig = buildConfig(config); | ||
const eslintConfig = await format(buildConfig(config)); | ||
await addFileToRoot(CONFIG_FILE_NAME$1, eslintConfig); | ||
@@ -500,3 +512,3 @@ await addScripts(...scripts); | ||
const defaultConfig$a = { | ||
const defaultConfig$9 = { | ||
config: {}, | ||
@@ -521,4 +533,4 @@ mutations: [prettierMutation, stylelintMutation('*.css'), eslintMutation('*.js'), jestMutation('*.js')], | ||
const [getConfig$a] = jsCategoryState.useConfigState({ | ||
default: defaultConfig$a, | ||
const [getConfig$9] = jsCategoryState.useConfigState({ | ||
default: defaultConfig$9, | ||
'node:ts': nodeTsConfig$1, | ||
@@ -529,3 +541,3 @@ 'react:ts': reactTsConfig$2, | ||
const lintStaged = async () => { | ||
const { config, mutations } = getConfig$a(); | ||
const { config, mutations } = getConfig$9(); | ||
await applyMutations(config, mutations); | ||
@@ -583,3 +595,3 @@ await installDevelopmentDependencies(PACKAGE_NAME$2); | ||
`; | ||
const defaultConfig$9 = { | ||
const defaultConfig$8 = { | ||
stylelintConfig: stylelintConfig$1, | ||
@@ -621,4 +633,4 @@ stylelintIgnore: stylelintIgnore$1, | ||
const [getConfig$9] = jsCategoryState.useConfigState({ | ||
default: defaultConfig$9, | ||
const [getConfig$8] = jsCategoryState.useConfigState({ | ||
default: defaultConfig$8, | ||
'react:ts': reactTsConfig$1, | ||
@@ -628,3 +640,3 @@ }); | ||
const stylelint = async () => { | ||
const config = getConfig$9(); | ||
const config = getConfig$8(); | ||
for (const mutation of config.mutations) { | ||
@@ -640,31 +652,4 @@ await mutation(config); | ||
const defaultConfig$8 = { | ||
config: { | ||
semi: true, | ||
trailingComma: 'all', | ||
singleQuote: true, | ||
printWidth: 120, | ||
tabWidth: 2, | ||
overrides: [ | ||
{ | ||
files: '*.yml', | ||
options: { | ||
singleQuote: false, | ||
}, | ||
}, | ||
], | ||
}, | ||
ignore: ['dist', 'node_modules', 'public', '.husky', 'package-lock.json', 'coverage'], | ||
scripts: [ | ||
{ name: 'format', script: 'prettier . --check' }, | ||
{ name: 'format:fix', script: 'prettier --write .' }, | ||
], | ||
}; | ||
const [getConfig$8] = jsCategoryState.useConfigState({ | ||
default: defaultConfig$8, | ||
}); | ||
const prettier = async () => { | ||
const { config, ignore, scripts } = getConfig$8(); | ||
const { config, ignore, scripts } = getConfig$a(); | ||
await installDevelopmentDependencies(PACKAGE_NAME$4); | ||
@@ -671,0 +656,0 @@ await addJsonFileToRoot(CONFIG_FILE_NAME$2, config); |
{ | ||
"name": "@allohamora/cli", | ||
"version": "1.20.0", | ||
"version": "1.21.0", | ||
"description": "cli to initialize projects and more", | ||
@@ -71,3 +71,2 @@ "input": "./src/index.ts", | ||
"lint-staged": "^15.2.10", | ||
"prettier": "^3.3.3", | ||
"rimraf": "^6.0.1", | ||
@@ -87,3 +86,4 @@ "rollup": "^3.29.5", | ||
"inquirer": "8.2.4", | ||
"ora": "5.4.1" | ||
"ora": "5.4.1", | ||
"prettier": "^3.3.3" | ||
}, | ||
@@ -90,0 +90,0 @@ "lint-staged": { |
Sorry, the diff of this file is not supported yet
25
129479
3
1023
+ Addedprettier@^3.3.3
+ Addedprettier@3.5.3(transitive)