'use strict' ; import { getComponentFiles , getComponentFolder , replicate } from 'generact' ; import * as vscode from 'vscode' ; export function activate ( context ) { const disposable = vscode . commands . registerCommand ( 'extension.generact' , async ( ) => { if ( ! vscode . workspace . workspaceFolders || vscode . workspace . workspaceFolders . length === 0 ) { vscode . window . showInformationMessage ( 'You must open a project first.' ) ; } else { projectPrompt ( ) . then ( ( projectItem ) => { if ( projectItem ) { const root = projectItem . description ; componentPrompt ( root ) . then ( async ( componentItem ) => { if ( componentItem ) { const name = ( await namePrompt ( componentItem . label ) ) || '' ; const folder = ( await folderPrompt ( getComponentFolder ( componentItem . description ) , name ) ) || getComponentFolder ( componentItem . description ) ; try { await replicate ( root + componentItem . description , { name , folder } , root ) ; } catch ( e ) { vscode . window . showWarningMessage ( 'An Error occured while writing.' ) ; console . log ( e ) ; } } } ) ; } } ) ; } } ) ; context . subscriptions . push ( disposable ) ; } function projectPrompt ( ) { const options = { placeHolder : 'Choose a project.' , } ; let projects = [ ] ; if ( vscode . workspace . workspaceFolders ) { projects = vscode . workspace . workspaceFolders . map ( f => ( { label : f . name , description : f . uri . fsPath , } ) ) ; } if ( projects . length === 1 ) { return Promise . resolve ( projects [ 0 ] ) ; } return vscode . window . showQuickPick ( projects , options ) ; } function componentPrompt ( projectRoot ) { const options = { matchOnDescription : true , placeHolder : 'Which component do you want to replicate?' , } ; const components = getComponentFiles ( projectRoot , '/' ) . then ( files => files . map ( f => ( { label : f . short , description : f . value . substring ( projectRoot . length ) , } ) ) ) ; return vscode . window . showQuickPick ( components , options ) ; } function namePrompt ( originalName ) { const options = { prompt : 'How do you want to name the component?' , value : originalName , } ; return vscode . window . showInputBox ( options ) ; } function folderPrompt ( originalFolder , newName ) { const options = { prompt : `In which folder do you want to put ${ newName } component?` , value : originalFolder , } ; return vscode . window . showInputBox ( options ) ; } export function deactivate ( ) { }