-
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added: added removing programming interface
- [Add] Added removing programming interface - [Change] changed mermaid graph from `TD` to `LR` in README.md
- Loading branch information
Showing
10 changed files
with
108 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters