Skip to content

Commit

Permalink
feat: ✨ change approach, the default command will generate a suggest …
Browse files Browse the repository at this point in the history
…command (#2)

* docs: 📚 add link github for npm package

* perf: 🚀 configurate typescript make more security and performance

* feat: ✨ implement give suggest command for tools

---------

Co-authored-by: Kiet Le <[email protected]>
  • Loading branch information
zenkiet and zenkiet authored Dec 10, 2024
1 parent f5f59ad commit e56d7d2
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 8 deletions.
1 change: 1 addition & 0 deletions buildcache/tsbuildinfo

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package-lock.json

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

4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
"bin": {
"optimize-icons": "./bin/cli.js"
},
"repository": {
"type": "git",
"url": "https://github.com/zenkiet/optimize-icons-cli"
},
"scripts": {
"build": "npx tsc",
"start": "node dist/cli.js",
Expand Down
12 changes: 10 additions & 2 deletions src/command/command-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,16 @@ Examples:

public async executeCommand(): Promise<void> {
this.program.parse();

const options = this.program.opts<Partial<OptimizeIconsOptions>>();
const optimizeCommand = new OptimizeCommand(options);
await optimizeCommand.execute();

if (Object.keys(options).length === 0) {
const optimizeCommand = new OptimizeCommand({});
const answers = await optimizeCommand.promptUserInput();
optimizeCommand.displayCommand(answers);
} else {
const optimizeCommand = new OptimizeCommand(options);
await optimizeCommand.execute();
}
}
}
27 changes: 25 additions & 2 deletions src/command/optimize-command.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import boxen from 'boxen';
import chalk from 'chalk';
import inquirer from 'inquirer';
import { ICONS_DIR, IGNORE_FILE, OUTPUT_DIR, VERBOSE_DEFAULT } from '../constants';
import IconOptimizer from '../core/icon-optimize';
Expand All @@ -7,7 +9,7 @@ import { BaseCommand } from './base-command';
export class OptimizeCommand implements BaseCommand {
constructor(private options: Partial<OptimizeIconsOptions>) {}

private async promptUserInput(): Promise<OptimizeIconsOptions> {
public async promptUserInput(): Promise<OptimizeIconsOptions> {
const answers = await inquirer.prompt<OptimizeIconsOptions>([
{
type: 'input',
Expand Down Expand Up @@ -38,7 +40,11 @@ export class OptimizeCommand implements BaseCommand {
name: 'ignoreFiles',
message: 'Enter files to ignore (comma separated):',
default: IGNORE_FILE.join(','),
filter: (input) => input.split(',').map((item: string) => item.trim()),
filter: (input) =>
input
.split(',')
.map((item: string) => item.trim())
.filter((item: string) => item.length > 0),
},
{
type: 'confirm',
Expand All @@ -65,4 +71,21 @@ export class OptimizeCommand implements BaseCommand {
const optimizer = new IconOptimizer(config);
await optimizer.optimize();
}

public displayCommand(options: OptimizeIconsOptions): void {
const command = `optimize-icons -o ${options.outputPath} -i ${options.iconsPath} ${
options.ignoreFiles && options.ignoreFiles.length > 0
? `-I ${options.ignoreFiles.join(' ')}`
: ''
} ${options.verbose ? '-v' : ''}`;

console.log(
boxen(chalk.green('Suggested command:\n\n') + chalk.yellow(command), {
padding: 1,
margin: 1,
borderStyle: 'round',
borderColor: 'green',
})
);
}
}
18 changes: 16 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,30 @@
"compilerOptions": {
"target": "ES2022",
"module": "CommonJS",
"incremental": true,
"tsBuildInfoFile": "./buildcache/tsbuildinfo",
"declaration": true,
"declarationMap": true,
"sourceMap": true,
"outDir": "./dist",
"rootDir": "./src",
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true
"forceConsistentCasingInFileNames": true,
"removeComments": true,
"preserveConstEnums": false,
"resolveJsonModule": true,
"baseUrl": "./src",
"paths": {
"*": ["*", "src/*"]
}
},
"include": ["src/**/*"],
"exclude": ["node_modules", "dist", "tests"]
"exclude": ["node_modules", "dist", "tests", "**/*.spec.ts", "**/*.test.ts"]
}

0 comments on commit e56d7d2

Please sign in to comment.