Merge pull request #14 from LoredDev:improve-cli-api

Move configs array to it's own package
This commit is contained in:
Guz
2023-08-29 15:14:47 -03:00
committed by GitHub
20 changed files with 179 additions and 10 deletions

View File

@@ -0,0 +1,6 @@
---
"@eslit/cli": minor
---
Now the cli exports a API that runs the application and the configs object needs to be passed to the Cli class, this way any other package can run and have their configs array.
With this, the new command line interface that handles the actual configs of this repo is the "eslegant" package.

View File

@@ -0,0 +1,5 @@
---
"eslegant": patch
---
Created the ESLegant package, being now the actual command that runs the CLI with the ESLegant's configs

View File

@@ -0,0 +1,5 @@
---
"create-eslegant": patch
---
Created the "create-eslegant" package, as a _alias_ to the eslegant package, so it is compatible with `npm init` or `npm create` commands

View File

@@ -23,6 +23,6 @@
"yaml"
],
"cSpell.words": [
"ESLIT"
"eslegant"
]
}

17
packages/cli/index.d.ts vendored Normal file
View File

@@ -0,0 +1,17 @@
import type { CliArgs } from './src/types';
/**
* Class that handles the creation and running the ESLegant command line interface
*/
export default class Cli {
/**
* @param args Arguments to pass to the cli when its runs
*/
constructor(args: CliArgs);
/**
* Runs the cli with the given arguments
*/
async run(): Promise<void>;
}
export type { CliArgs, Config } from './src/types.d.ts';

1
packages/cli/index.js Normal file
View File

@@ -0,0 +1 @@
export { default as default } from './src/cli.js';

View File

@@ -1,5 +1,5 @@
{
"extends": "../../tsconfig.json",
"exclude": ["./node_modules/**", "./dist/**"],
"include": ["./index.d.ts", "./src/**/*.ts", "./src/**/*.js"],
"include": ["**/*.ts", "**/*.js"],
}

View File

@@ -16,6 +16,7 @@
"source": "./src/index.js",
"files": [
"src",
"index.js",
"index.d.ts"
],
"homepage": "https://github.com/LoredDev/ESLit",
@@ -25,7 +26,6 @@
"type": "git",
"url": "https://github.com/LoredDev/ESLit"
},
"bin": "./src/index.js",
"license": "MIT",
"dependencies": {
"cardinal": "^2.1.1",

View File

@@ -1,6 +1,5 @@
import { Command } from 'commander';
import ConfigsProcessor from './configsProcessor.js';
import configs from './configs.js';
import Workspace from './workspace.js';
import c from 'picocolors';
import path from 'node:path';
@@ -22,6 +21,7 @@ export default class Cli {
/** @type {import('./types').CliArgs} */
args = {
dir: process.cwd(),
configs: [],
};
/**
@@ -45,13 +45,13 @@ export default class Cli {
this.args.dir = !this.args.dir.startsWith('/')
? path.join(process.cwd(), this.args.dir)
: this.args.dir;
}
async run() {
process.chdir(this.args.dir);
const configs = this.args.configs;
const spinner = createSpinner('Detecting workspace configuration');
const processor = new ConfigsProcessor({ configs });

View File

@@ -1,4 +0,0 @@
import Cli from './cli.js';
const cli = new Cli();
await cli.run();

View File

@@ -7,6 +7,7 @@ type CliArgs = {
mergeToRoot?: boolean
installPkgs?: boolean | PackageManagerName
dir: string
configs: Config[]
} & OptionValues;
interface PackageManagerHandler {

View File

@@ -0,0 +1,4 @@
import Cli from '@eslit/cli';
const cli = new Cli({ configs: (await import('./configs.js')).default, dir: process.cwd() });
await cli.run();

View File

@@ -1,5 +1,5 @@
/** @type {import('./types').Config[]} */
/** @type {import('@eslit/cli').Config[]} */
const cliConfig = [
{
name: 'framework',

View File

@@ -0,0 +1,5 @@
{
"extends": "../../tsconfig.json",
"exclude": ["./node_modules/**", "./dist/**"],
"include": ["**/*.ts", "**/*.js"],
}

View File

@@ -0,0 +1,33 @@
{
"name": "create-eslegant",
"version": "0.1.0",
"description": "",
"keywords": [],
"author": {
"email": "contact.guz013@gmail.com",
"name": "Gustavo \"Guz\" L. de Mello",
"url": "https://guz.one"
},
"files": [
"./bin.js",
"./configs.js"
],
"dependencies": {
"@eslit/cli": "workspace:*"
},
"homepage": "https://github.com/LoredDev/ESLit",
"type": "module",
"repository": {
"directory": "packages/create-eslegant",
"type": "git",
"url": "https://github.com/LoredDev/ESLit"
},
"bin": "./bin.js",
"license": "MIT",
"publishConfig": {
"access": "public"
},
"devDependencies": {
"@types/node": "^20.5.3"
}
}

4
packages/eslegant/bin.js Normal file
View File

@@ -0,0 +1,4 @@
import Cli from '@eslit/cli';
const cli = new Cli({ configs: (await import('./configs.js')).default, dir: process.cwd() });
await cli.run();

View File

@@ -0,0 +1,34 @@
/** @type {import('@eslit/cli').Config[]} */
const cliConfig = [
{
name: 'framework',
type: 'multiple',
description: 'The UI frameworks being used in the project',
options: [
{
name: 'svelte',
packages: { 'svelte': 'svelte' },
configs: ['svelte.recommended'],
detect: ['**/*.svelte', 'svelte.config.{js,ts,cjs,cts}'],
},
{
name: 'vue',
packages: { 'vue': ['vue', ['hello', 'world']], 'svelte': ['hello'] },
configs: ['vue.recommended'],
detect: ['nuxt.config.{js,ts,cjs,cts}', '**/*.vue'],
},
],
},
{
name: 'strict',
type: 'confirm',
manual: true,
options: [{
name: 'yes',
packages: { 'eslint': 'config', 'svelte': ['test1'] },
configs: ['config.strict'],
}],
},
];
export default cliConfig;

View File

@@ -0,0 +1,5 @@
{
"extends": "../../tsconfig.json",
"exclude": ["./node_modules/**", "./dist/**"],
"include": ["**/*.ts", "**/*.js"],
}

View File

@@ -0,0 +1,33 @@
{
"name": "eslegant",
"version": "0.1.0",
"description": "",
"keywords": [],
"author": {
"email": "contact.guz013@gmail.com",
"name": "Gustavo \"Guz\" L. de Mello",
"url": "https://guz.one"
},
"files": [
"./bin.js",
"./configs.js"
],
"dependencies": {
"@eslit/cli": "workspace:*"
},
"homepage": "https://github.com/LoredDev/ESLit",
"type": "module",
"repository": {
"directory": "packages/eslegant",
"type": "git",
"url": "https://github.com/LoredDev/ESLit"
},
"bin": "./bin.js",
"license": "MIT",
"publishConfig": {
"access": "public"
},
"devDependencies": {
"@types/node": "^20.5.3"
}
}

20
pnpm-lock.yaml generated
View File

@@ -177,6 +177,26 @@ importers:
specifier: ^5.1.6
version: 5.1.6
packages/create-eslegant:
dependencies:
'@eslit/cli':
specifier: workspace:*
version: link:../cli
devDependencies:
'@types/node':
specifier: ^20.5.3
version: 20.5.3
packages/eslegant:
dependencies:
'@eslit/cli':
specifier: workspace:*
version: link:../cli
devDependencies:
'@types/node':
specifier: ^20.5.3
version: 20.5.3
packages:
/@aashutoshrathi/word-wrap@1.2.6: