Skip to content

Commit

Permalink
feat(cmd): add install command
Browse files Browse the repository at this point in the history
  • Loading branch information
jlenon7 committed Mar 4, 2024
1 parent dfb9551 commit 09c2e37
Show file tree
Hide file tree
Showing 40 changed files with 185 additions and 57 deletions.
72 changes: 36 additions & 36 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 12 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@athenna/core",
"version": "4.30.0",
"version": "4.31.0",
"description": "One foundation for multiple applications.",
"license": "MIT",
"author": "João Lenon <[email protected]>",
Expand Down Expand Up @@ -57,6 +57,7 @@
"./commands/ServeCommand": "./src/commands/ServeCommand.js",
"./commands/TestCommand": "./src/commands/TestCommand.js",
"./commands/BuildCommand": "./src/commands/BuildCommand.js",
"./commands/InstallCommand": "./src/commands/InstallCommand.js",
"./testing/BaseHttpTest": "./src/testing/BaseHttpTest.js",
"./testing/BaseConsoleTest": "./src/testing/BaseConsoleTest.js"
},
Expand All @@ -76,15 +77,15 @@
"semver": "^7.5.4"
},
"devDependencies": {
"@athenna/artisan": "^4.37.0",
"@athenna/common": "^4.34.0",
"@athenna/config": "^4.16.0",
"@athenna/http": "^4.23.0",
"@athenna/ioc": "^4.16.0",
"@athenna/logger": "^4.17.0",
"@athenna/artisan": "^4.38.0",
"@athenna/common": "^4.35.0",
"@athenna/config": "^4.18.0",
"@athenna/http": "^4.24.0",
"@athenna/ioc": "^4.18.0",
"@athenna/logger": "^4.18.0",
"@athenna/test": "^4.22.0",
"@athenna/tsconfig": "^4.12.0",
"@athenna/view": "^4.18.0",
"@athenna/view": "^4.20.0",
"@typescript-eslint/eslint-plugin": "^6.7.4",
"@typescript-eslint/parser": "^6.7.4",
"commitizen": "^4.2.6",
Expand Down Expand Up @@ -249,6 +250,9 @@
"path": "#src/commands/BuildCommand",
"tsconfig": "./tests/fixtures/tsconfig.json",
"outDir": "build"
},
"install": {
"path": "#src/commands/InstallCommand"
}
},
"providers": [
Expand Down
2 changes: 1 addition & 1 deletion src/applications/Console.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

import { debug } from '#src/debug'
import { Log } from '@athenna/logger'
import { Module, Options } from '@athenna/common'
import type { ArtisanImpl } from '@athenna/artisan'
import { Path, Module, Options } from '@athenna/common'
import type { ConsoleOptions } from '#src/types/ConsoleOptions'

export class Console {
Expand Down
2 changes: 1 addition & 1 deletion src/applications/Http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
import { debug } from '#src/debug'
import { Log } from '@athenna/logger'
import type { ServerImpl } from '@athenna/http'
import { Is, Module, Options } from '@athenna/common'
import type { HttpOptions } from '#src/types/HttpOptions'
import { Is, Path, Module, Options } from '@athenna/common'

export class Http {
/**
Expand Down
75 changes: 75 additions & 0 deletions src/commands/InstallCommand.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/**
* @athenna/core
*
* (c) João Lenon <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

import { File, Module, Path } from '@athenna/common'
import { Argument, BaseCommand, Option } from '@athenna/artisan'

export class InstallCommand extends BaseCommand {
@Argument({
signature: '<...libraries>',
description: 'The libraries to install in your project.'
})
public libraries: string[]

@Option({
signature: '--registry',
description:
'Change the package manager that will be used to install the libraries',
default: 'npm'
})
public registry: string

@Option({
signature: '-D, --save-dev',
description: 'Install libraries as devDependencies.',
default: false
})
public isDev: boolean

public static signature(): string {
return 'install'
}

public static description(): string {
return 'Install libraries and automatically run the configurer if it exist.'
}

public async handle(): Promise<void> {
this.logger.simple('({bold,green} [ INSTALLING LIBRARIES ])\n')

const task = this.logger.task()

task.addPromise(`Installing ${this.libraries.join(', ')} libraries`, () => {
return this.npm.install(this.libraries, {
registry: Config.get('rc.commands.install.registry', this.registry),
dev: this.isDev
})
})

for (const library of this.libraries) {
const path = Path.nodeModules(`${library}/configurer/index.js`)

if (!(await File.exists(path))) {
continue
}

task.addPromise(`Configuring ${library}`, async () => {
const Configurer = await Module.getFrom(path)

return new Configurer().setPath(path).configure()
})
}

await task.run()

this.logger.success(
`Successfully installed ${this.libraries.join(', ')} libraries`
)
}
}
2 changes: 1 addition & 1 deletion src/commands/ReplCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* file that was distributed with this source code.
*/

import { Module } from '@athenna/common'
import { Path, Module } from '@athenna/common'
import { BaseCommand } from '@athenna/artisan'

export class ReplCommand extends BaseCommand {
Expand Down
2 changes: 1 addition & 1 deletion src/commands/ServeCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import { Log } from '@athenna/logger'
import { Config } from '@athenna/config'
import { Module } from '@athenna/common'
import { Path, Module } from '@athenna/common'
import { BaseCommand, Option } from '@athenna/artisan'

export class ServeCommand extends BaseCommand {
Expand Down
2 changes: 1 addition & 1 deletion src/commands/TestCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* file that was distributed with this source code.
*/

import { Module } from '@athenna/common'
import { Path, Module } from '@athenna/common'
import { BaseCommand, Commander } from '@athenna/artisan'

export class TestCommand extends BaseCommand {
Expand Down
2 changes: 0 additions & 2 deletions src/constants/InternalReplProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
/**
* All node:repl internal properties to remove
* from list when using ".ls" command.
*
* @type {string[]}
*/
export const INTERNAL_REPL_PROPS = [
'global',
Expand Down
2 changes: 1 addition & 1 deletion src/ignite/Ignite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { CommanderHandler } from '@athenna/artisan'
import { LoadHelper } from '#src/helpers/LoadHelper'
import { Log, LoggerProvider } from '@athenna/logger'
import { Repl as ReplApp } from '#src/applications/Repl'
import { File, Is, Module, Options } from '@athenna/common'
import { Is, Path, File, Module, Options } from '@athenna/common'
import { parse as semverParse, satisfies as semverSatisfies } from 'semver'
import { NotSatisfiedNodeVersion } from '#src/exceptions/NotSatisfiedNodeVersion'

Expand Down
2 changes: 1 addition & 1 deletion src/testing/BaseConsoleTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
* file that was distributed with this source code.
*/

import { Json, Options } from '@athenna/common'
import { AfterAll, BeforeAll } from '@athenna/test'
import { Path, Json, Options } from '@athenna/common'
import { Ignite, type IgniteOptions } from '@athenna/core'
import { TestCommand } from '@athenna/artisan/testing/plugins'

Expand Down
2 changes: 1 addition & 1 deletion src/testing/BaseHttpTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
*/

import { ServerImpl } from '@athenna/http'
import { Json, Options } from '@athenna/common'
import { AfterAll, BeforeAll } from '@athenna/test'
import { Path, Json, Options } from '@athenna/common'
import { Ignite, type HttpOptions, type IgniteOptions } from '@athenna/core'

export class BaseHttpTest {
Expand Down
1 change: 1 addition & 0 deletions tests/fixtures/consoles/absolute-path-entry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* file that was distributed with this source code.
*/

import { Path } from '@athenna/common'
import { ViewProvider } from '@athenna/view'
import { Rc, Config } from '@athenna/config'
import { LoggerProvider } from '@athenna/logger'
Expand Down
1 change: 1 addition & 0 deletions tests/fixtures/consoles/base-console.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* file that was distributed with this source code.
*/

import { Path } from '@athenna/common'
import { ViewProvider } from '@athenna/view'
import { Rc, Config } from '@athenna/config'
import { LoggerProvider } from '@athenna/logger'
Expand Down
1 change: 1 addition & 0 deletions tests/fixtures/consoles/console-mock-dest-import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* file that was distributed with this source code.
*/

import { Path } from '@athenna/common'
import { ViewProvider } from '@athenna/view'
import { Rc, Config } from '@athenna/config'
import { LoggerProvider } from '@athenna/logger'
Expand Down
Loading

0 comments on commit 09c2e37

Please sign in to comment.