From 62ae2990a6a7b261ed1c605cd0f6baff94b6eea9 Mon Sep 17 00:00:00 2001 From: Timo Hocker Date: Thu, 18 Jun 2020 13:58:38 +0200 Subject: [PATCH] prompt will have to be self made, or extending more basic levels of enquirer --- AppTest.js | 2 +- Jenkinsfile | 2 +- .../Interactive/InteractiveSubSource.ts | 5 +-- lib/Sources/Interactive/PathCustomPrompt.ts | 45 +++++++++++-------- lib/Sources/Interactive/PathSubSource.ts | 5 ++- 5 files changed, 33 insertions(+), 26 deletions(-) diff --git a/AppTest.js b/AppTest.js index bdb2f01..df51c3d 100644 --- a/AppTest.js +++ b/AppTest.js @@ -33,7 +33,7 @@ const { const fld = await new FolderOption ({ name: 'fld' }) .parse (); - const data = { str, bool, num, arr, fld }; + const data = { /* str, bool, num, arr,*/ fld }; console.log (data); }) (); diff --git a/Jenkinsfile b/Jenkinsfile index 7dbbd6c..76705d3 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -5,7 +5,7 @@ pipeline { VERSION = VersionNumber([ versionNumberString: '${BUILDS_ALL_TIME}', - versionPrefix: '2.0.', + versionPrefix: '2.1.', worstResultForIncrement: 'SUCCESS' ]) } diff --git a/lib/Sources/Interactive/InteractiveSubSource.ts b/lib/Sources/Interactive/InteractiveSubSource.ts index 627b87d..7ece10b 100644 --- a/lib/Sources/Interactive/InteractiveSubSource.ts +++ b/lib/Sources/Interactive/InteractiveSubSource.ts @@ -17,10 +17,7 @@ export abstract class InteractiveSubSource { public async parse ():Promise { if (this.condition ()) { - await this.run () - .catch ((e) => { - console.log (e); - }); + await this.run (); return true; } return false; diff --git a/lib/Sources/Interactive/PathCustomPrompt.ts b/lib/Sources/Interactive/PathCustomPrompt.ts index da23c49..db46a90 100644 --- a/lib/Sources/Interactive/PathCustomPrompt.ts +++ b/lib/Sources/Interactive/PathCustomPrompt.ts @@ -1,25 +1,34 @@ -import { Prompt } from 'enquirer'; +/* eslint-disable no-sync */ +import { dirname, join, sep, basename } from 'path'; +import fs from 'fs-extra'; -export class PathPrompt extends Prompt { - private _index = 0; - private _value = ''; - - public constructor (options:Record = {}) { - super (options); +function read_dir (dir:string, exclude_files:boolean):string[] { + const contents = fs.readdirSync (dir); + contents.unshift ('..'); + if (exclude_files) { + return contents.filter ((c) => { + const full_path = join (dir, c); + try { + return fs.statSync (full_path) + .isDirectory (); + } + catch { + return false; + } + }); } + return contents; +} - public up (): void { - this._index--; - this.render (); - } +interface PathPromptOptions { + starting_dir?: string; + folders_only?: boolean; +} - public down (): void { - this._index++; - this.render (); - } +export class PathPrompt { + private _options: PathPromptOptions; - public render (): void { - this.clear (); - this.write (`${this.state.message}: ${this._value}`); + public constructor (options:PathPromptOptions) { + this._options = options; } } diff --git a/lib/Sources/Interactive/PathSubSource.ts b/lib/Sources/Interactive/PathSubSource.ts index b81c6fc..0c93507 100644 --- a/lib/Sources/Interactive/PathSubSource.ts +++ b/lib/Sources/Interactive/PathSubSource.ts @@ -14,8 +14,9 @@ export class PathSubSource extends InteractiveSubSource { await this.val.assign_arg ( this.opt, await new PathPrompt ({ - message: this.get_message (), - default: this.opt.default + message: this.get_message (), + default: this.opt.default, + folder_only: this.val.type_validation.option_type === 'folder' }) .run () );