Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/npm-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ jobs:
with:
name: build-artifact
path: build/
include-hidden-files: true
retention-days: 1

publish:
Expand All @@ -53,4 +54,5 @@ jobs:
with:
name: build-artifact
path: build/
include-hidden-files: true
- run: cd build && npm publish --access public --tag alpha --provenance
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
node_modules/
coverage/
build/
package-lock.json
.DS_Store
AGY.md
AYG.md
package-lock.json
13 changes: 9 additions & 4 deletions jest.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { execSync } from "child_process";
import path from "path";
import fs from "fs";
import { execSync } from "node:child_process";
import path from 'node:path';
import fs from 'node:fs';

let tsJestPath = "ts-jest";
try {
Expand All @@ -21,11 +21,16 @@ export default {
"**/test/**/*.test.ts",
"**/test/**/*.test.js"
],
"modulePathIgnorePatterns": [
"<rootDir>/build/"
],
"transform": {
"^.+\\.ts$": [
tsJestPath,
{
"tsconfig": "<rootDir>/tsconfig.json"
"tsconfig": "<rootDir>/tsconfig.json",
"isolatedModules": true,
"diagnostics": false
}
]
},
Expand Down
35 changes: 17 additions & 18 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,31 +1,29 @@
{
"name": "@ostro/console",
"version": "2.0.0-alpha.2",
"version": "2.0.0-alpha.3",
"description": "Command module for OstroJS",
"main": "build/application.js",
"types": "build/types/application.d.ts",
"files": [
"build"
],
"main": "application.js",
"types": ".typed/application.d.ts",
"exports": {
".": {
"types": "./build/types/application.d.ts",
"default": "./build/application.js"
"types": "./.typed/application.d.ts",
"default": "./application.js"
},
"./*": {
"types": "./build/types/*.d.ts",
"default": "./build/*.js"
"types": "./.typed/*.d.ts",
"default": "./*.js"
}
},
"scripts": {
"build": "npx tsc -p tsconfig.build.json && node scripts/build.js",
"build": "npm run lint:check && rm -rf build && ostro-build --prepare",
"prepublishOnly": "npm run build",
"test": "npx c8 npx jest",
"clean": "rm -rf build coverage"
"test": "jest",
"clean": "rm -rf build coverage",
"lint:check": "tsc --noEmit"
},
"dependencies": {
"@ostro/contracts": "^2.0.0-alpha.2",
"@ostro/support": "^2.0.0-alpha.2",
"@ostro/contracts": "^2.0.0-alpha.3",
"@ostro/support": "^2.0.0-alpha.3",
"commander": "^8.3.0",
"lodash": "^4.17.21",
"string-argv": "^0.3.2"
Expand All @@ -50,13 +48,14 @@
},
"homepage": "https://github.com/ostrojs/console#readme",
"devDependencies": {
"@types/node": "^22.0.0",
"typescript": "^5.8.0",
"@ostro/builder": "^2.0.0-alpha.1",
"@types/jest": "^30.0.0",
"@types/node": "^22.0.0",
"c8": "^10.1.3",
"jest": "^30.5.2",
"ts-jest": "^29.4.15",
"ts-node": "^10.9.2"
"ts-node": "^10.9.2",
"typescript": "^5.8.0"
},
"overrides": {
"sprintf-js": "^1.1.3",
Expand Down
94 changes: 0 additions & 94 deletions scripts/build.js

This file was deleted.

17 changes: 8 additions & 9 deletions src/application.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { parseArgsStringToArgv } from 'string-argv';
import commander from 'commander';
import { program } from 'commander';
import InputHandler from './inputHandler';
import OutputHandler from './outputHandler';
import Command from './command';
Expand All @@ -23,8 +23,8 @@ class Application {
constructor($app?: any) {
this.$app = $app;
this.setAutoExit(0);
(commander as any).exitOverride(()=>{});
(commander as any).showSuggestionAfterError(true);
program.exitOverride(() => { });
program.showSuggestionAfterError(true);

this.bootstrap();
}
Expand Down Expand Up @@ -52,7 +52,7 @@ class Application {
* @returns {any}
*/
public run($input: any[] = []) {
return (commander as any).parseAsync($input, {
return program.parseAsync($input, {
from: 'user'
})

Expand Down Expand Up @@ -111,7 +111,7 @@ class Application {
* @returns {any}
*/
public callCommand(...args: any[]) {
return (this.call as any)(...args)
return (this.call as (...a: unknown[]) => unknown)(...args)
}

/**
Expand Down Expand Up @@ -234,7 +234,7 @@ class Application {
this.$commands.push(command.$signature);
let options = command.$options || [];
let commandArguments = command.$arguments || [];
let cmd = (commander as any).command(command.$signature);
let cmd = program.command(command.$signature);

cmd.description(command.$description);

Expand Down Expand Up @@ -266,10 +266,9 @@ class Application {


let newCommand = Object.create(command);
command.input = new InputHandler(args, opts);
command.output = new OutputHandler();
newCommand.input = new InputHandler(args, opts);
newCommand.output = new OutputHandler();
return newCommand.handle()

})
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/argument.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class Argument {
* @returns The argument instance.
*/
public choices(values: readonly string[]): this {
this.$handler.choices(values as any);
this.$handler.choices(values as string[]);
return this;
}

Expand Down
41 changes: 37 additions & 4 deletions src/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,53 @@ class Command extends implement(CommandContracts, Interaction, CallCommands, Has
Object.defineProperty(this, '$arguments', { value: val, writable: true, configurable: true });
}

/**
* Determine if the application is using TypeScript.
*
* @returns {boolean}
*/
public isTypeScript(): boolean {
if (!this.$app) {
return false;
}
try {
if (this.$app['config']) {
const configVal = typeof this.$app['config'].get === 'function' ?
this.$app['config'].get('app.typescript') :
this.$app['config']['app.typescript'];
if (typeof configVal === 'boolean') {
return configVal;
}
}
} catch (_) {}

if (typeof this.$app.basePath !== 'function') {
return false;
}
try {
const fs = require('node:fs');
return fs.existsSync(this.$app.basePath('tsconfig.json')) ||
fs.existsSync(this.$app.basePath('tsconfig.build.json')) ||
fs.existsSync(this.$app.basePath('app.ts'));
} catch {
return false;
}
}

/**
* createArgument method.
* @returns {any}
*/
public createArgument(...args: any[]) {
return new (Argument as any)(...args)
public createArgument(name: string, description?: string) {
return new Argument(name, description);
}

/**
* createOption method.
* @returns {any}
*/
public createOption(...args: any[]) {
return new (Option as any)(...args)
public createOption(flags: string, description?: string) {
return new Option(flags, description);
}

/**
Expand Down
7 changes: 5 additions & 2 deletions src/concerns/callsCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
*/
class CallsCommands {
public declare output: any;
public declare getConsole: any;

public getConsole(): any {
return null;
}

/**
* callCommand method.
Expand All @@ -20,7 +23,7 @@ class CallsCommands {
* @returns {any}
*/
public call(...args: any[]) {
return (this.callCommand as any)(...args)
return (this.callCommand as (...a: unknown[]) => unknown)(...args)
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/concerns/hasParameters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ class HasParameters {
if (typeof InputArgument !== 'undefined' && $arguments instanceof InputArgument) {
this.getDefinition().addArgument($arguments);
} else {
this.addArgument(...Object.values($arguments as any));
this.addArgument(...Object.values($arguments as Record<string, unknown>));
}
}

for (let $options of this.getOptions()) {
if (typeof InputOption !== 'undefined' && $options instanceof InputOption) {
this.getDefinition().addOption($options);
} else {
this.addOption(...Object.values($options as any));
this.addOption(...Object.values($options as Record<string, unknown>));
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/concerns/intraction.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import OutputFormatterStyle from '../outputFormatterStyle';
import OutputInterface from '../outputInterface';
import CollectionInterface from '@ostro/contracts/collection/collect';
import type { ICollection } from '@ostro/contracts/collection/collect';
import Table from '../helpers/table';
import { isset } from '@ostro/support/function';

Expand Down Expand Up @@ -127,8 +128,8 @@ class Interaction {
public table($headers: Record<string, any>, $rows: any, $tableStyle: string = 'default', $columnStyles: any[] = []) {
let $table = new Table(this.output);

if ($rows instanceof CollectionInterface) {
$rows = ($rows as any).toArray();
if ($rows instanceof CollectionInterface || (typeof ($rows as ICollection)?.toArray === 'function')) {
$rows = ($rows as ICollection).toArray();
}

$table.setHeaders($headers).setRows($rows).setStyle($tableStyle);
Expand Down
Loading
Loading