From 26f29009d66e0bcbd1fe2b38f5198999a3ca11c8 Mon Sep 17 00:00:00 2001 From: Guz013 <43732358+Guz013@users.noreply.github.com> Date: Tue, 29 Aug 2023 15:06:24 -0300 Subject: [PATCH 1/2] =?UTF-8?q?feat:=20=E2=9C=A8=20create=20the=20eslegant?= =?UTF-8?q?=20package?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .changeset/pretty-buckets-cover.md | 5 ++++ .changeset/swift-dragons-tell.md | 5 ++++ .vscode/settings.json | 2 +- packages/create-eslegant/bin.js | 4 +++ packages/create-eslegant/configs.js | 34 ++++++++++++++++++++++++++ packages/create-eslegant/jsconfig.json | 5 ++++ packages/create-eslegant/package.json | 33 +++++++++++++++++++++++++ packages/eslegant/bin.js | 4 +++ packages/eslegant/configs.js | 34 ++++++++++++++++++++++++++ packages/eslegant/jsconfig.json | 5 ++++ pnpm-lock.yaml | 20 +++++++++++++++ 11 files changed, 150 insertions(+), 1 deletion(-) create mode 100644 .changeset/pretty-buckets-cover.md create mode 100644 .changeset/swift-dragons-tell.md create mode 100644 packages/create-eslegant/bin.js create mode 100644 packages/create-eslegant/configs.js create mode 100644 packages/create-eslegant/jsconfig.json create mode 100644 packages/create-eslegant/package.json create mode 100644 packages/eslegant/bin.js create mode 100644 packages/eslegant/configs.js create mode 100644 packages/eslegant/jsconfig.json diff --git a/.changeset/pretty-buckets-cover.md b/.changeset/pretty-buckets-cover.md new file mode 100644 index 0000000..08e2691 --- /dev/null +++ b/.changeset/pretty-buckets-cover.md @@ -0,0 +1,5 @@ +--- +"eslegant": patch +--- + +Created the ESLegant package, being now the actual command that runs the CLI with the ESLegant's configs diff --git a/.changeset/swift-dragons-tell.md b/.changeset/swift-dragons-tell.md new file mode 100644 index 0000000..dedac95 --- /dev/null +++ b/.changeset/swift-dragons-tell.md @@ -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 diff --git a/.vscode/settings.json b/.vscode/settings.json index 2deff29..14b4db7 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -23,6 +23,6 @@ "yaml" ], "cSpell.words": [ - "ESLIT" + "eslegant" ] } diff --git a/packages/create-eslegant/bin.js b/packages/create-eslegant/bin.js new file mode 100644 index 0000000..774934f --- /dev/null +++ b/packages/create-eslegant/bin.js @@ -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(); diff --git a/packages/create-eslegant/configs.js b/packages/create-eslegant/configs.js new file mode 100644 index 0000000..2a6b5a4 --- /dev/null +++ b/packages/create-eslegant/configs.js @@ -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; diff --git a/packages/create-eslegant/jsconfig.json b/packages/create-eslegant/jsconfig.json new file mode 100644 index 0000000..ac91127 --- /dev/null +++ b/packages/create-eslegant/jsconfig.json @@ -0,0 +1,5 @@ +{ + "extends": "../../tsconfig.json", + "exclude": ["./node_modules/**", "./dist/**"], + "include": ["**/*.ts", "**/*.js"], +} diff --git a/packages/create-eslegant/package.json b/packages/create-eslegant/package.json new file mode 100644 index 0000000..8abad83 --- /dev/null +++ b/packages/create-eslegant/package.json @@ -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" + } +} diff --git a/packages/eslegant/bin.js b/packages/eslegant/bin.js new file mode 100644 index 0000000..774934f --- /dev/null +++ b/packages/eslegant/bin.js @@ -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(); diff --git a/packages/eslegant/configs.js b/packages/eslegant/configs.js new file mode 100644 index 0000000..2a6b5a4 --- /dev/null +++ b/packages/eslegant/configs.js @@ -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; diff --git a/packages/eslegant/jsconfig.json b/packages/eslegant/jsconfig.json new file mode 100644 index 0000000..ac91127 --- /dev/null +++ b/packages/eslegant/jsconfig.json @@ -0,0 +1,5 @@ +{ + "extends": "../../tsconfig.json", + "exclude": ["./node_modules/**", "./dist/**"], + "include": ["**/*.ts", "**/*.js"], +} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 74a4572..de40da3 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -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: From c061fdc8cd78e130e3e8f56b5633d0601fcb9b5e Mon Sep 17 00:00:00 2001 From: Guz013 <43732358+Guz013@users.noreply.github.com> Date: Tue, 29 Aug 2023 15:08:29 -0300 Subject: [PATCH 2/2] =?UTF-8?q?feat!:=20=F0=9F=92=A5=20=E2=9C=A8=20export?= =?UTF-8?q?=20cli=20api=20and=20remove=20configs=20array?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Removed the configs array from the cli package, as it now is handled by the eslegant package. Exported the Cli class so it can be run by other packages BREAKING CHANGE --- .changeset/light-mails-hang.md | 6 ++++++ packages/cli/index.d.ts | 17 +++++++++++++++++ packages/cli/index.js | 1 + packages/cli/jsconfig.json | 2 +- packages/cli/package.json | 2 +- packages/cli/src/cli.js | 4 ++-- packages/cli/src/configs.js | 34 ---------------------------------- packages/cli/src/index.js | 4 ---- packages/cli/src/types.d.ts | 1 + packages/eslegant/package.json | 33 +++++++++++++++++++++++++++++++++ 10 files changed, 62 insertions(+), 42 deletions(-) create mode 100644 .changeset/light-mails-hang.md create mode 100644 packages/cli/index.d.ts create mode 100644 packages/cli/index.js delete mode 100644 packages/cli/src/configs.js delete mode 100755 packages/cli/src/index.js create mode 100644 packages/eslegant/package.json diff --git a/.changeset/light-mails-hang.md b/.changeset/light-mails-hang.md new file mode 100644 index 0000000..dd29740 --- /dev/null +++ b/.changeset/light-mails-hang.md @@ -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. diff --git a/packages/cli/index.d.ts b/packages/cli/index.d.ts new file mode 100644 index 0000000..be33e9f --- /dev/null +++ b/packages/cli/index.d.ts @@ -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; +} + +export type { CliArgs, Config } from './src/types.d.ts'; diff --git a/packages/cli/index.js b/packages/cli/index.js new file mode 100644 index 0000000..16c6c35 --- /dev/null +++ b/packages/cli/index.js @@ -0,0 +1 @@ +export { default as default } from './src/cli.js'; diff --git a/packages/cli/jsconfig.json b/packages/cli/jsconfig.json index d4e37f4..ac91127 100644 --- a/packages/cli/jsconfig.json +++ b/packages/cli/jsconfig.json @@ -1,5 +1,5 @@ { "extends": "../../tsconfig.json", "exclude": ["./node_modules/**", "./dist/**"], - "include": ["./index.d.ts", "./src/**/*.ts", "./src/**/*.js"], + "include": ["**/*.ts", "**/*.js"], } diff --git a/packages/cli/package.json b/packages/cli/package.json index 23d01ad..f4f6c49 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -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", diff --git a/packages/cli/src/cli.js b/packages/cli/src/cli.js index d9b16ce..57cd6fe 100644 --- a/packages/cli/src/cli.js +++ b/packages/cli/src/cli.js @@ -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 }); diff --git a/packages/cli/src/configs.js b/packages/cli/src/configs.js deleted file mode 100644 index 2607961..0000000 --- a/packages/cli/src/configs.js +++ /dev/null @@ -1,34 +0,0 @@ - -/** @type {import('./types').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; diff --git a/packages/cli/src/index.js b/packages/cli/src/index.js deleted file mode 100755 index 20e2906..0000000 --- a/packages/cli/src/index.js +++ /dev/null @@ -1,4 +0,0 @@ -import Cli from './cli.js'; - -const cli = new Cli(); -await cli.run(); diff --git a/packages/cli/src/types.d.ts b/packages/cli/src/types.d.ts index f0b536a..36a369c 100644 --- a/packages/cli/src/types.d.ts +++ b/packages/cli/src/types.d.ts @@ -7,6 +7,7 @@ type CliArgs = { mergeToRoot?: boolean installPkgs?: boolean | PackageManagerName dir: string + configs: Config[] } & OptionValues; interface PackageManagerHandler { diff --git a/packages/eslegant/package.json b/packages/eslegant/package.json new file mode 100644 index 0000000..4312a1c --- /dev/null +++ b/packages/eslegant/package.json @@ -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" + } +}