import { findUp , resolveCwd } from 'flex-dev-utils/dist/fs' ; import { spawn } from 'flex-dev-utils/dist/spawn' ; import { camelCase , upperFirst } from 'flex-dev-utils/dist/lodash' ; import * as github from '../utils/github' ; import { FlexPluginArguments } from './create-flex-plugin' ; const pkg = require ( findUp ( __filename , 'package.json' ) ) ; param config { FlexPluginArguments } return { string } export const installDependencies = async ( config ) : Promise < string > => { const shellCmd = config . yarn ? 'yarn' : 'npm' ; const args = [ 'install' ] ; const options = { cwd : config . targetDirectory , shell : process . env . SHELL , } ; const { stdout , exitCode , stderr } = await spawn ( shellCmd , args , options ) ; if ( exitCode === 1 ) { throw new Error ( stderr ) ; } return stdout ; } ; param config { FlexPluginArguments } return { FlexPluginArguments } export const setupConfiguration = ( config ) : FlexPluginArguments => { const name = config . name || '' ; config . pluginClassName = `${ upperFirst ( camelCase ( name ) ) . replace ( 'Plugin' , '' ) }Plugin` ; config . pluginNamespace = name . toLowerCase ( ) . replace ( 'plugin-' , '' ) ; config . runtimeUrl = config . runtimeUrl || 'http://localhost:3000' ; config . targetDirectory = resolveCwd ( name ) ; config . flexSdkVersion = pkg . devDependencies [ '@twilio/flex-ui' ] ; config . pluginScriptsVersion = pkg . devDependencies [ 'flex-plugin-scripts' ] ; return config ; } ; param url { string } param dir { string } export const downloadFromGitHub = async ( url , dir ) : Promise < void > => { const info = await github . parseGitHubUrl ( url ) ; return github . downloadRepo ( info , dir ) ; } ;