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
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ jobs:
runs-on: ${{ matrix.operating-system }}
strategy:
matrix:
operating-system: [ubuntu-latest, windows-latest]
node-version: [18, 20, 22, 24, 25]
operating-system: [ubuntu-latest, macos-latest, windows-latest]
node-version: [20, 22, 24, 26]
name: Node.js ${{ matrix.node-version }} Test on ${{ matrix.operating-system }}

steps:
Expand Down
8 changes: 5 additions & 3 deletions README-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

[![NPM version](https://img.shields.io/npm/v/@axiosleo/cli-tool.svg?style=flat-square)](https://npmjs.org/package/@axiosleo/cli-tool)
[![npm download](https://img.shields.io/npm/dm/@axiosleo/cli-tool.svg?style=flat-square)](https://npmjs.org/package/@axiosleo/cli-tool)
[![node version](https://img.shields.io/badge/node.js-%3E=_14.0-green.svg?style=flat-square)](http://nodejs.org/download/)
[![node version](https://img.shields.io/badge/node.js-%3E=_16.0-green.svg?style=flat-square)](http://nodejs.org/download/)
[![CI Build Status](https://github.com/AxiosLeo/node-cli/actions/workflows/ci.yml/badge.svg)](https://github.com/AxiosLeo/node-cli/actions/workflows/ci.yml)
[![Codecov](https://codecov.io/gh/AxiosLeo/node-cli/branch/master/graph/badge.svg)](https://codecov.io/gh/AxiosLeo/node-cli)
[![License](https://img.shields.io/github/license/AxiosLeo/node-cli?color=%234bc524)](LICENSE)
Expand Down Expand Up @@ -33,7 +33,7 @@ cli-tool make <command-name> <commands-dir-path>
cli-tool make test ./commands/ # 将会生成 ./commands/test.js 文件

# 直接执行生成的命令行脚本文件
cli-tool exec ./command/test.js
cli-tool exec ./commands/test.js
```

## 使用
Expand Down Expand Up @@ -88,6 +88,8 @@ app.exec("<command-name>");

> 开启多语言模式后,应用和命令的“描述”将会根据配置的 locales json 文件,自动翻译成对应语言
>
> 检测到的系统语言在 `sets` 中时使用它,否则使用第一项。Windows 上只读取 `LC_ALL`、`LC_MESSAGES`、`LANG`、`LANGUAGE` 这几个环境变量,都没有时按 `en-US` 处理。
>
> locales 示例 json 文件 : [locales](./locales)
>
> 详见 [locales wiki](https://github.com/AxiosLeo/node-cli/wiki/locales)
Expand All @@ -96,7 +98,7 @@ app.exec("<command-name>");
const path = require("path");
app.locale({
dir: path.join(__dirname, "../locales"), // /path/to/app/locales/dir
sets: ["en-US", "zh-CN"], // 不能为空, 且第一个元素为默认值
sets: ["en-US", "zh-CN"], // 不能为空。检测到的系统语言在列表中时使用它,否则使用第一项。
});
app.start(); // 需要在调用 app.start() 方法前配置 locale
```
Expand Down
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ English | [简体中文](/README-CN.md)

[![NPM version](https://img.shields.io/npm/v/@axiosleo/cli-tool.svg?style=flat-square)](https://npmjs.org/package/@axiosleo/cli-tool)
[![npm download](https://img.shields.io/npm/dm/@axiosleo/cli-tool.svg?style=flat-square)](https://npmjs.org/package/@axiosleo/cli-tool)
[![node version](https://img.shields.io/badge/node.js-%3E=_14.0-green.svg?style=flat-square)](http://nodejs.org/download/)
[![node version](https://img.shields.io/badge/node.js-%3E=_16.0-green.svg?style=flat-square)](http://nodejs.org/download/)
[![CI Build Status](https://github.com/AxiosLeo/node-cli/actions/workflows/ci.yml/badge.svg)](https://github.com/AxiosLeo/node-cli/actions/workflows/ci.yml)
[![Codecov](https://codecov.io/gh/AxiosLeo/node-cli/branch/master/graph/badge.svg)](https://codecov.io/gh/AxiosLeo/node-cli)
[![License](https://img.shields.io/github/license/AxiosLeo/node-cli?color=%234bc524)](LICENSE)
Expand Down Expand Up @@ -33,7 +33,7 @@ cli-tool make <command-name> <commands-dir-path>
cli-tool make test ./commands/ # will generate command file on ./commands/test.js

# run command js script
cli-tool exec ./command/test.js
cli-tool exec ./commands/test.js
```

## Usage
Expand Down Expand Up @@ -88,6 +88,8 @@ app.exec("<command-name>");

> The "desc" of CLI Application and Command will be automatically translated by using the locales json file.
>
> The detected system locale is used when it is listed in `sets`; otherwise the first item is used. On Windows only the `LC_ALL`, `LC_MESSAGES`, `LANG` and `LANGUAGE` environment variables are read, and `en-US` is used when none of them is set.
>
> locales example json file : [locales](./locales)
>
> see detail from [locales wiki](https://github.com/AxiosLeo/node-cli/wiki/locales)
Expand All @@ -96,7 +98,7 @@ app.exec("<command-name>");
const path = require("path");
app.locale({
dir: path.join(__dirname, "../locales"), // /path/to/app/locales/dir
sets: ["en-US", "zh-CN"], // cannot be empty, the first set as default.
sets: ["en-US", "zh-CN"], // cannot be empty. The detected system locale is used when it is in this list, otherwise the first item.
});
app.start(); // set locale before start app
```
Expand Down
2 changes: 1 addition & 1 deletion bin/cli-tool.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const { App } = require('..');
const app = new App({
name: 'Cli Tool',
bin: 'cli-tool',
version: '1.6.12',
version: '2.0.0',
desc: 'application_desc',
commands_dir: path.join(__dirname, '../commands'),
commands_sort: ['help', 'init', 'make', 'exec'],
Expand Down
2 changes: 1 addition & 1 deletion commands/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class InitCommand extends Command {
},
'license': 'MIT',
'dependencies': {
'@axiosleo/cli-tool': '^1.6.12'
'@axiosleo/cli-tool': '^2.0.0'

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Init scaffold misses ESLint 10 packages

Medium Severity

cli-tool init still writes eslint as the only lint devDependency, while the copied eslint.config.mjs imports @eslint/js and globals. ESLint 10 no longer depends on @eslint/js, so npm run lint in a newly generated project fails to resolve those modules.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 3f43a49. Configure here.

},
'devDependencies': {
'eslint': '*'
Expand Down
15 changes: 2 additions & 13 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -1,22 +1,11 @@
import globals from "globals";
import path from "node:path";
import { fileURLToPath } from "node:url";
import js from "@eslint/js";
import { FlatCompat } from "@eslint/eslintrc";

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const compat = new FlatCompat({
baseDirectory: __dirname,
recommendedConfig: js.configs.recommended,
allConfig: js.configs.all
});

export default [
{
ignores: ['eslint.config.mjs']
},
...compat.extends("eslint:recommended"),
js.configs.recommended,
{
languageOptions: {
globals: {
Expand Down Expand Up @@ -59,7 +48,7 @@ export default [
"no-labels": 2,
"no-with": 2,
"no-loop-func": 2,
"no-native-reassign": 2,
"no-global-assign": 2,

"no-redeclare": [2, {
builtinGlobals: true,
Expand Down
101 changes: 95 additions & 6 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import Big from 'big.js';
import { ChildProcess, SpawnOptionsWithoutStdio } from 'child_process';
import { Color } from 'colors';

type Level = number | null | boolean | string;

Expand Down Expand Up @@ -352,7 +351,7 @@ interface LocalesConfig {
format?: string
}

export module locales {
export namespace locales {
class Translator {
constructor(options: LocalesConfig);

Expand Down Expand Up @@ -409,6 +408,96 @@ export module locales {
function disable(): void;
}

/**
* The same typings as colors@1.4.0, the implementation is src/lib/colors.js
*/
interface Color {
(text: string): string;

strip: Color;
stripColors: Color;

black: Color;
red: Color;
green: Color;
yellow: Color;
blue: Color;
magenta: Color;
cyan: Color;
white: Color;
gray: Color;
grey: Color;

bgBlack: Color;
bgRed: Color;
bgGreen: Color;
bgYellow: Color;
bgBlue: Color;
bgMagenta: Color;
bgCyan: Color;
bgWhite: Color;

reset: Color;
bold: Color;
dim: Color;
italic: Color;
underline: Color;
inverse: Color;
hidden: Color;
strikethrough: Color;

rainbow: Color;
zebra: Color;
america: Color;
trap: Color;
random: Color;
zalgo: Color;
}

declare global {
interface String {
strip: string;
stripColors: string;

black: string;
red: string;
green: string;
yellow: string;
blue: string;
magenta: string;
cyan: string;
white: string;
gray: string;
grey: string;

bgBlack: string;
bgRed: string;
bgGreen: string;
bgYellow: string;
bgBlue: string;
bgMagenta: string;
bgCyan: string;
bgWhite: string;

reset: string;
// @ts-ignore
bold: string;
dim: string;
italic: string;
underline: string;
inverse: string;
hidden: string;
strikethrough: string;

rainbow: string;
zebra: string;
america: string;
trap: string;
random: string;
zalgo: string;
}
}

interface Printer {
colors: Color
/**
Expand Down Expand Up @@ -743,7 +832,7 @@ export namespace helper {
name: string,
}

module obj {
namespace obj {
function _flatten(obj: ObjectItem, sep?: string): ObjectItem;
function _flatten<T>(obj: T, sep: string): ObjectItem;
function _unflatten(obj: ObjectItem, sep: string): ObjectItem;
Expand All @@ -761,7 +850,7 @@ export namespace helper {
encoding?: string // default is 'utf8'
}

module str {
namespace str {
class Emitter {
config: EmitterConfig
constructor(options?: EmitterConfig)
Expand Down Expand Up @@ -875,7 +964,7 @@ export namespace helper {
* @param dict 0123456789abcdf
* @param len 8
*/
function _random(dict?: string, len?: number)
function _random(dict?: string, len?: number): string;

/**
* get length of string
Expand All @@ -896,7 +985,7 @@ export namespace helper {
length?: number
}

module convert {
namespace convert {
/**
* convert tree to array
* @param tree
Expand Down
36 changes: 15 additions & 21 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@axiosleo/cli-tool",
"version": "1.6.12",
"version": "2.0.0",
"description": "Design for quickly developing CLI applications using Node.js.",
"keywords": [
"cli",
Expand All @@ -22,7 +22,7 @@
"cli-tool": "./bin/cli-tool.js"
},
"scripts": {
"lint": "tsc ./index.d.ts && eslint --fix src/ tests/",
"lint": "tsc --noEmit --types node --skipDefaultLibCheck ./index.d.ts && eslint --fix src/ tests/",
"test": "mocha --reporter spec --timeout 3000 tests/*.tests.js",
"test-cov": "nyc -r=lcov -r=html -r=text -r=json mocha -t 10000 -R spec tests/*.tests.js",
"test-one": "mocha --reporter spec --timeout 3000",
Expand All @@ -31,32 +31,26 @@
},
"license": "MIT",
"dependencies": {
"big.js": "^6.2.1",
"big.js": "^7.0.1",
"clone-deep": "^4.0.1",
"colors": "1.4.0",
"enquirer": "^2.4.1",
"lcid": "~4.0.1",
"minimist": "^1.2.8",
"moment": "^2.30.1"
"minimist": "^1.2.8"
},
"repository": {
"type": "git",
"url": "https://github.com/AxiosLeo/node-cli"
},
"devDependencies": {
"@eslint/eslintrc": "^3.2.0",
"@eslint/js": "^9.17.0",
"@types/node": "18.14.2",
"chai": "4.3.7",
"chai-as-promised": "7.1.1",
"eslint": "^9.17.0",
"expect.js": "0.3.1",
"has-flag": "5.0.1",
"mm": "3.2.1",
"mocha": "10.2.0",
"mocha-sinon": "2.1.2",
"nyc": "15.1.0",
"sinon": "16.1.3",
"typescript": "4.9.5"
"@eslint/js": "^10.0.1",
"@types/big.js": "^7.0.0",
"@types/node": "26.6.6",
"chai": "6.3.0",
"chai-as-promised": "8.0.2",
"eslint": "^10.15.0",
"globals": "^17.14.0",
"mocha": "12.0.3",
"nyc": "18.0.0",
"sinon": "22.1.0",
"typescript": "7.0.2"
}
}
14 changes: 12 additions & 2 deletions src/debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,20 @@

const os = require('os');
const { prompt } = require('enquirer');
const moment = require('moment');

var count = 0;

/**
* current local time as "YYYY-MM-DD HH:mm:ss"
*/
function datetime() {
const now = new Date();
const pad = (n) => `${n}`.padStart(2, '0');
const date = [now.getFullYear(), pad(now.getMonth() + 1), pad(now.getDate())].join('-');
const time = [pad(now.getHours()), pad(now.getMinutes()), pad(now.getSeconds())].join(':');
return `${date} ${time}`;
}

function emit(data) {
// eslint-disable-next-line no-console
data.forEach(d => console.log(d));
Expand All @@ -28,7 +38,7 @@ function dump(...data) {
}

function log(...data) {
pos('log', '38;5;243', `\x1b[33m[${moment().format('YYYY-MM-DD HH:mm:ss')}]\x1b[0m `);
pos('log', '38;5;243', `\x1b[33m[${datetime()}]\x1b[0m `);
// eslint-disable-next-line no-console
console.log.apply(this, data);
}
Expand Down
1 change: 0 additions & 1 deletion src/helper/str.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ function _fixed(content, length = 10, fillPosition = 'r', fill = ' ') {
} else {
rightFill = fill.repeat(length - len);
}
fill = fill.repeat(length - len);
content = leftFill + content + rightFill;
}
return content;
Expand Down
3 changes: 1 addition & 2 deletions src/lib/camelcase.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,10 @@ const preserveCamelCase = (string, toLowerCase, toUpperCase, preserveConsecutive
let isLastCharLower = false;
let isLastCharUpper = false;
let isLastLastCharUpper = false;
let isLastLastCharPreserved = false;

for (let index = 0; index < string.length; index++) {
const character = string[index];
isLastLastCharPreserved = index > 2 ? string[index - 3] === '-' : true;
const isLastLastCharPreserved = index > 2 ? string[index - 3] === '-' : true;

if (isLastCharLower && UPPERCASE.test(character)) {
string = string.slice(0, index) + '-' + string.slice(index);
Expand Down
Loading
Loading