diff --git a/fixtures/monorepo/.gitignore b/fixtures/monorepo/.gitignore new file mode 100644 index 0000000..d1595af --- /dev/null +++ b/fixtures/monorepo/.gitignore @@ -0,0 +1,36 @@ +# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. + +# dependencies +node_modules +.pnp +.pnp.js + +# testing +coverage + +# next.js +.next/ +out/ +build + +# misc +.DS_Store +*.pem + +# debug +npm-debug.log* +yarn-debug.log* +yarn-error.log* + +# local env files +.env +.env.local +.env.development.local +.env.test.local +.env.production.local + +# turbo +.turbo + +# vercel +.vercel diff --git a/fixtures/monorepo/package.json b/fixtures/monorepo/package.json new file mode 100644 index 0000000..aa0b92a --- /dev/null +++ b/fixtures/monorepo/package.json @@ -0,0 +1,15 @@ +{ + "private": true, + "scripts": { + "test:cli": "pnpm cli" + }, + "devDependencies": { + "@eslit/cli": "workspace:*" + }, + "packageManager": "pnpm@8.6.10", + "name": "monorepo", + "workspaces": [ + "apps/*", + "packages/*" + ] +} diff --git a/packages/cli/package.json b/packages/cli/package.json index 6f053b4..39e2683 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -28,6 +28,7 @@ "bin": "./src/index.js", "license": "MIT", "dependencies": { + "commander": "^11.0.0", "magic-string": "^0.30.2", "nanospinner": "^1.1.0", "picocolors": "^1.0.0", diff --git a/packages/cli/src/cli.js b/packages/cli/src/cli.js index 24e22c1..2da197d 100755 --- a/packages/cli/src/cli.js +++ b/packages/cli/src/cli.js @@ -12,19 +12,20 @@ export default class Cli { /** @type {import('./types').Config[]} */ configs; + /** @type {string[] | undefined} */ + #packagesPatterns; + /** * @param {{ - * configs: import('./types').Config[] + * configs: import('./types').Config[], * packages?: string[], - * workspace?: import('./types').Package[], * directory?: string, - * debug?: boolean, * }} options - Cli options */ constructor(options) { + this.#packagesPatterns = options.packages; this.configs = options?.configs; this.dir = path.normalize(options.directory ?? this.dir); - this.debug = options.debug ?? this.debug; } /** @@ -136,7 +137,7 @@ export default class Cli { } async run() { - let packages = await new Workspace(this.dir).getPackages(); + let packages = await new Workspace(this.dir, this.#packagesPatterns).getPackages(); packages = packages.map( pkg => { @@ -144,8 +145,7 @@ export default class Cli { }, ); - console.log(packages.length); - console.log(this.generateConfigMap(packages)); + console.log(packages); } } diff --git a/packages/cli/src/index.js b/packages/cli/src/index.js index 71d2979..454f4a8 100755 --- a/packages/cli/src/index.js +++ b/packages/cli/src/index.js @@ -1,5 +1,12 @@ import Cli from './cli.js'; import configs from './configs.js'; +import { program } from 'commander'; -const cli = new Cli({ configs }); +program.option('--packages '); + +program.parse(process.argv); +/** @type {{ packages?: string[] } & import('commander').OptionValues} */ +const options = program.opts(); + +const cli = new Cli({ configs, packages: options.packages }); await cli.run(); diff --git a/packages/cli/src/workspace.js b/packages/cli/src/workspace.js index a3b1f08..1bbaad1 100644 --- a/packages/cli/src/workspace.js +++ b/packages/cli/src/workspace.js @@ -56,14 +56,14 @@ async function getPackageName(directory) { } export default class Workspace { - /** @type {{files: string[], directories: string[]} | undefined} */ - paths; /** * @param {string} directory - The directory to get the workspace from + * @param {string[]} [packagePatterns] - List of package patterns */ - constructor(directory) { + constructor(directory, packagePatterns) { this.dir = directory; + this.packagePatterns = packagePatterns; } /** @@ -109,9 +109,6 @@ export default class Workspace { }; } - /** @type {string[] | undefined} */ - packages; - /** * @returns {Promise} - List of packages on a directory; */ @@ -160,11 +157,9 @@ export default class Workspace { async getPackages() { const paths = await this.getPaths(); - const packagePatterns = await this.getPackagePatterns(); + const packagePatterns = this.packagePatterns ?? await this.getPackagePatterns(); const packagePaths = paths.directories.filter(d => picomatch.isMatch(d, packagePatterns)); - console.log(packagePatterns); - /** @type {import('./types').Package} */ const rootPackage = { root: true, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 727fcda..5edc700 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -43,6 +43,12 @@ importers: specifier: workspace:* version: link:../../packages/cli + fixtures/monorepo: + devDependencies: + '@eslit/cli': + specifier: workspace:* + version: link:../../packages/cli + fixtures/svelte: devDependencies: '@eslit/cli': @@ -93,6 +99,9 @@ importers: packages/cli: dependencies: + commander: + specifier: ^11.0.0 + version: 11.0.0 magic-string: specifier: ^0.30.2 version: 0.30.2 @@ -1426,6 +1435,11 @@ packages: /color-name@1.1.4: resolution: {integrity: sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==} + /commander@11.0.0: + resolution: {integrity: sha512-9HMlXtt/BNoYr8ooyjjNRdIilOTkVJXB+GhxMTtOKwk0R4j4lS4NpjuqmRxroBfnfTSHQIHQB7wryHhXarNjmQ==} + engines: {node: '>=16'} + dev: false + /comment-parser@1.3.1: resolution: {integrity: sha512-B52sN2VNghyq5ofvUsqZjmk6YkihBX5vMSChmSK9v4ShjKf3Vk5Xcmgpw4o+iIgtrnM/u5FiMpz9VKb8lpBveA==} engines: {node: '>= 12.0.0'}