Skip to content

Commit

Permalink
Added: added removing programming interface
Browse files Browse the repository at this point in the history
- [Add] Added removing programming interface
- [Change] changed mermaid graph from `TD` to `LR` in README.md
  • Loading branch information
imjuni committed Nov 14, 2023
1 parent fc8cb71 commit aa4df2a
Show file tree
Hide file tree
Showing 10 changed files with 108 additions and 69 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ npx ctix build
The graph below outlines the behavioral flow of `ctix`.

```mermaid
flowchart TD
flowchart LR
START(start) --> |execute cli|ctix
ctix --> |TypeScript Compiler API| INP01[Source Code files]
ctix --> |TypeScript Compiler API| INP02["tsconfig.json"]
Expand Down
65 changes: 4 additions & 61 deletions src/cli/commands/removeCommand.ts
Original file line number Diff line number Diff line change
@@ -1,78 +1,21 @@
import { askRemoveFiles } from '#/cli/questions/askRemoveFiles';
import { ProgressBar } from '#/cli/ux/ProgressBar';
import { Reasoner } from '#/cli/ux/Reasoner';
import { Spinner } from '#/cli/ux/Spinner';
import type { TCommandBuildArgvOptions } from '#/configs/interfaces/TCommandBuildArgvOptions';
import type { TCommandRemoveOptions } from '#/configs/interfaces/TCommandRemoveOptions';
import { createBuildOptions } from '#/configs/transforms/createBuildOptions';
import { getRemoveFileGlobPattern } from '#/modules/file/getRemoveFileGlobPattern';
import { unlinks } from '#/modules/file/unlinks';
import { IncludeContainer } from '#/modules/scope/IncludeContainer';
import chalk from 'chalk';
import { createRemoveOptions } from '#/configs/transforms/createRemoveOptions';
import { removing } from '#/modules/commands/removing';
import consola from 'consola';
import path from 'node:path';
import type yargs from 'yargs';

async function removeCommandCode(
argv: yargs.ArgumentsCamelCase<TCommandRemoveOptions & TCommandBuildArgvOptions>,
) {
Spinner.it.start(`'index.ts' file remove start`);

const options = await createBuildOptions(argv);
const patterns = await getRemoveFileGlobPattern(argv, options.options);

const include = new IncludeContainer({
config: { include: patterns.map((projectDir) => projectDir.pattern) },
});
const filePaths = include.files();

if (argv.forceYes) {
Spinner.it.succeed('enable force-yes, file removing without question');
Spinner.it.stop();

ProgressBar.it.start(filePaths.length);

await unlinks(filePaths, () => {
ProgressBar.it.increment();
});

ProgressBar.it.stop();

await filePaths.reduce(async (prevHandle: Promise<void>, filePath: string) => {
const handle = async () => {
Spinner.it.succeed(
`${chalk.redBright('removed:')} ${path.relative(process.cwd(), filePath)}`,
);
};

await prevHandle;
return handle();
}, Promise.resolve());

return;
}

Spinner.it.stop();
ProgressBar.it.start(filePaths.length);

const indexFiles = await askRemoveFiles(filePaths);

await unlinks(indexFiles, () => {
ProgressBar.it.increment();
});

ProgressBar.it.stop();

await filePaths.reduce(async (prevHandle: Promise<void>, filePath: string) => {
const handle = async () => {
Spinner.it.succeed(
`${chalk.redBright('removed:')} ${path.relative(process.cwd(), filePath)}`,
);
};
const removeOptions = createRemoveOptions(argv);

await prevHandle;
return handle();
}, Promise.resolve());
await removing({ ...options, ...removeOptions });
}

export async function removeCommand(
Expand Down
4 changes: 2 additions & 2 deletions src/comments/__tests__/inline.generation.style.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { CE_INLINE_COMMENT_KEYWORD } from '#/comments/const-enum/CE_INLINE_COMMENT_KEYWORD';
import { getInlineStyle } from '#/comments/getInlineStyle';
import { getSourceFileComments } from '#/comments/getSourceFileComments';
import { describe, expect, it, jest } from '@jest/globals';
import * as cp from 'comment-parser';
import { randomUUID } from 'node:crypto';
import path from 'node:path';
import * as tsm from 'ts-morph';
import { CE_INLINE_COMMENT_KEYWORD } from '../const-enum/CE_INLINE_COMMENT_KEYWORD';
import { getSourceFileComments } from '../getSourceFileComments';

const tsconfigPath = path.join(process.cwd(), 'example', 'tsconfig.example.json');
const context = {
Expand Down
2 changes: 1 addition & 1 deletion src/comments/__tests__/namespace.comment.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { getCommentNamespace } from '#/comments/getCommentNamespace';
import { getCommentNamespaces } from '#/comments/getCommentNamespaces';
import { describe, expect, it } from '@jest/globals';
import { getCommentNamespaces } from '../getCommentNamespaces';

describe('getCommentNamespace', () => {
it('ends-with ,', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/comments/getInlineExclude.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { getCommentNamespaces } from '#/comments/getCommentNamespaces';
import { getJsDocComment } from '#/comments/getJsDocComment';
import { getJsDocTag } from '#/comments/getJsDocTag';
import type { IInlineExcludeInfo } from '#/comments/interfaces/IInlineExcludeInfo';
import type { IStatementComments } from '#/comments/interfaces/IStatementComments';
import { parse } from 'comment-parser';
import { getCommentNamespaces } from './getCommentNamespaces';

export function getInlineExclude(params: {
comment: IStatementComments;
Expand Down
2 changes: 1 addition & 1 deletion src/comments/getInlineStyle.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { getCommentNamespaces } from '#/comments/getCommentNamespaces';
import { getJsDocComment } from '#/comments/getJsDocComment';
import { getJsDocTag } from '#/comments/getJsDocTag';
import type { IInlineGenerationStyleInfo } from '#/comments/interfaces/IInlineGenerationStyleInfo';
import type { IStatementComments } from '#/comments/interfaces/IStatementComments';
import { getGenerationStyle } from '#/templates/modules/getGenerationStyle';
import { parse } from 'comment-parser';
import { getCommentNamespaces } from './getCommentNamespaces';

export function getInlineStyle(params: {
comment: IStatementComments;
Expand Down
2 changes: 1 addition & 1 deletion src/compilers/__tests__/symbol.table.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { SymbolTable } from '#/compilers/SymbolTable';
import { describe, expect, it } from '@jest/globals';
import { randomUUID } from 'node:crypto';
import path from 'node:path';
import * as tsm from 'ts-morph';
import { SymbolTable } from '../SymbolTable';

const tsconfigPath = path.join(process.cwd(), 'example', 'tsconfig.example.json');
const context = {
Expand Down
25 changes: 25 additions & 0 deletions src/configs/transforms/createRemoveOptions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { CE_CTIX_COMMAND } from '#/configs/const-enum/CE_CTIX_COMMAND';
import type { TBundleOptions } from '#/configs/interfaces/TBundleOptions';
import type { TCommandBuildArgvOptions } from '#/configs/interfaces/TCommandBuildArgvOptions';
import type { TCommandRemoveOptions } from '#/configs/interfaces/TCommandRemoveOptions';
import type { TCreateOptions } from '#/configs/interfaces/TCreateOptions';
import type { ArgumentsCamelCase } from 'yargs';

export function createRemoveOptions(
argv: ArgumentsCamelCase<TCommandRemoveOptions & TCommandBuildArgvOptions> & {
options?: (TCreateOptions | TBundleOptions)[];
},
): TCommandRemoveOptions {
const options: TCommandRemoveOptions = {
$kind: CE_CTIX_COMMAND.REMOVE_COMMAND,
config: argv.config,
spinnerStream: argv.spinnerStream,
progressStream: argv.progressStream,
reasonerStream: argv.reasonerStream,
removeBackup: argv.removeBackup,
exportFilename: argv.exportFilename,
forceYes: argv.forceYes,
};

return options;
}
71 changes: 71 additions & 0 deletions src/modules/commands/removing.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import { askRemoveFiles } from '#/cli/questions/askRemoveFiles';
import { ProgressBar } from '#/cli/ux/ProgressBar';
import { Spinner } from '#/cli/ux/Spinner';
import type { TCommandBuildOptions } from '#/configs/interfaces/TCommandBuildOptions';
import type { TCommandRemoveOptions } from '#/configs/interfaces/TCommandRemoveOptions';
import { getRemoveFileGlobPattern } from '#/modules/file/getRemoveFileGlobPattern';
import { unlinks } from '#/modules/file/unlinks';
import { IncludeContainer } from '#/modules/scope/IncludeContainer';
import chalk from 'chalk';
import path from 'node:path';

export async function removing(
options: TCommandRemoveOptions & Omit<TCommandBuildOptions, '$kind'>,
) {
Spinner.it.start(`'index.ts' file remove start`);

const patterns = await getRemoveFileGlobPattern(options, options.options);

const include = new IncludeContainer({
config: { include: patterns.map((projectDir) => projectDir.pattern) },
});
const filePaths = include.files();

if (options.forceYes) {
Spinner.it.succeed('enable force-yes, file removing without question');
Spinner.it.stop();

ProgressBar.it.start(filePaths.length);

await unlinks(filePaths, () => {
ProgressBar.it.increment();
});

ProgressBar.it.stop();

await filePaths.reduce(async (prevHandle: Promise<void>, filePath: string) => {
const handle = async () => {
Spinner.it.succeed(
`${chalk.redBright('removed:')} ${path.relative(process.cwd(), filePath)}`,
);
};

await prevHandle;
return handle();
}, Promise.resolve());

return;
}

Spinner.it.stop();
ProgressBar.it.start(filePaths.length);

const indexFiles = await askRemoveFiles(filePaths);

await unlinks(indexFiles, () => {
ProgressBar.it.increment();
});

ProgressBar.it.stop();

await filePaths.reduce(async (prevHandle: Promise<void>, filePath: string) => {
const handle = async () => {
Spinner.it.succeed(
`${chalk.redBright('removed:')} ${path.relative(process.cwd(), filePath)}`,
);
};

await prevHandle;
return handle();
}, Promise.resolve());
}
2 changes: 1 addition & 1 deletion src/templates/__tests__/select.style.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import type { IStatementComments } from '#/comments/interfaces/IStatementComments';
import { CE_GENERATION_STYLE } from '#/configs/const-enum/CE_GENERATION_STYLE';
import { filenamify } from '#/modules/path/filenamify';
import { CE_AUTO_RENDER_CASE } from '#/templates/const-enum/CE_AUTO_RENDER_CASE';
import type { IIndexRenderData } from '#/templates/interfaces/IIndexRenderData';
import { getSelectStyle } from '#/templates/modules/getSelectStyle';
import { describe, expect, it } from '@jest/globals';
import copy from 'fast-copy';
import { randomUUID } from 'node:crypto';
import path from 'node:path';
import * as tsm from 'ts-morph';
import { CE_AUTO_RENDER_CASE } from '../const-enum/CE_AUTO_RENDER_CASE';

const uuid = randomUUID();
const filename = `${uuid}.ts`;
Expand Down

0 comments on commit aa4df2a

Please sign in to comment.