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 package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@wshcmx/cli",
"version": "3.5.0",
"version": "3.6.0",
"main": "dist/index.js",
"type": "module",
"repository": "github:wshcmx/cli",
Expand Down
19 changes: 0 additions & 19 deletions src/commands/build.ts

This file was deleted.

10 changes: 0 additions & 10 deletions src/commands/help.ts

This file was deleted.

14 changes: 0 additions & 14 deletions src/commands/index.ts

This file was deleted.

8 changes: 0 additions & 8 deletions src/commands/watch.ts

This file was deleted.

21 changes: 0 additions & 21 deletions src/core/args.ts

This file was deleted.

9 changes: 4 additions & 5 deletions src/core/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { removeExports } from '../transformers/remove_exports.js';
import { convertTemplateStrings } from '../transformers/template_strings.js';
import { transformNamespaces } from '../transformers/transform_namespaces.js';
import { noDeclarationInLoop } from '../checks/no-declaration-in-loop.js';
import { logger } from './logger.js';

export function buildTypescriptFiles(configuration: ts.ParsedCommandLine) {
const program = ts.createProgram(configuration.fileNames, configuration.options);
Expand All @@ -23,9 +22,9 @@ export function buildTypescriptFiles(configuration: ts.ParsedCommandLine) {
if (diagnostic.file) {
const { line, character } = ts.getLineAndCharacterOfPosition(diagnostic.file, diagnostic.start!);
const message = ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n');
logger.error(`${diagnostic.file.fileName} (${line + 1},${character + 1}): ${message}`);
console.error(`${diagnostic.file.fileName} (${line + 1},${character + 1}): ${message}`);
} else {
logger.error(ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n'));
console.error(ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n'));
}
});

Expand All @@ -36,9 +35,9 @@ function reportDiagnostic(diagnostic: ts.Diagnostic) {
if (diagnostic.file) {
const { line, character } = ts.getLineAndCharacterOfPosition(diagnostic.file, diagnostic.start!);
const message = ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n');
logger.error(`${diagnostic.file.fileName} (${line + 1},${character + 1}): ${message}`);
console.error(`${diagnostic.file.fileName} (${line + 1},${character + 1}): ${message}`);
} else {
logger.error(ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n'));
console.error(ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n'));
}
}

Expand Down
8 changes: 3 additions & 5 deletions src/core/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,26 @@ import { dirname } from 'node:path';

import ts from 'typescript';

import { logger } from './logger.js';

export function getTSConfig(cwd: string, project: string = 'tsconfig.json'): ts.ParsedCommandLine {
const tsconfigPath = ts.findConfigFile(cwd, ts.sys.fileExists, project);

if (!tsconfigPath) {
logger.error(`There is no any configuration files at "${cwd}". Execute npx tsc -init to create a new one.`);
console.error(`There is no any configuration files at "${cwd}". Execute npx tsc -init to create a new one.`);
process.exit(1);
}

const { config, error } = ts.readConfigFile(tsconfigPath, ts.sys.readFile);

if (error) {
logger.error(error.messageText.toString());
console.error(error.messageText.toString());
process.exit(1);
}

const configFileContent = ts.parseJsonConfigFileContent(config, ts.sys, dirname(tsconfigPath), undefined, tsconfigPath);

if (configFileContent.errors.length > 0) {
configFileContent.errors.forEach(x => {
logger.error(x.messageText.toString());
console.error(x.messageText.toString());
});

process.exit(1);
Expand Down
34 changes: 0 additions & 34 deletions src/core/logger.ts

This file was deleted.

44 changes: 35 additions & 9 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,41 @@
#!/usr/bin/env node

import * as args from './core/args.js';
import { commands } from './commands/index.js';
import { help } from './commands/help.js';
import { parseArgs } from "node:util";

const cwd = process.cwd();
import { buildTypescriptFiles, watchTypescriptFiles } from './core/build.js';
import { getTSConfig } from './core/config.js';

const command = commands.get(args.command);
export const { values: args, positionals: [command] } = parseArgs({
options: {
help: { type: 'boolean', short: 'h', default: false },
version: { type: 'boolean', short: 'v', default: false },
project: { type: 'string', short: 'p', default: 'tsconfig.json' },
},
allowPositionals: true
});

if (command) {
command.callback(cwd);
const CWD = process.cwd();

if (command === 'build') {
console.log(`🔨 ${new Date().toLocaleTimeString()} Project building started`);
const configuration = getTSConfig(CWD, args['project']);

const result = buildTypescriptFiles(configuration);

if (result?.emitSkipped) {
console.error(`❌ ${new Date().toLocaleTimeString()} Project building failed`);
process.exit(1);
}

console.log(`✅ ${new Date().toLocaleTimeString()} Project building finished`);
} else if (command === 'watch') {
const configuration = getTSConfig(CWD, args['project']);
watchTypescriptFiles(configuration);
} else {
help();
}
console.warn('\n@wshcmx/cli plugin - CLI для работы с WebSoft HCM');
console.log(`
Команды для вызова:
build - сборка проекта

`);
}
99 changes: 0 additions & 99 deletions test/core/args/args.test.js

This file was deleted.