import { execSync } from 'child_process' ; import * as fs from 'fs' ; import * as nodegit from 'nodegit' ; import { config } from '../config/config' ; export const runCoreCommand = ( commandName , autodotPath = `${ config . autodotPath }` ) => { return new Promise ( ( resolve , reject ) => { fs . readFile ( `${ autodotPath }/autodot.json` , ( err , buf ) => { if ( err ) reject ( err ) ; const data = JSON . parse ( buf . toString ( ) ) ; const command = data . commands [ commandName ] ; if ( ! command ) { reject ( new Error ( `${ commandName } command not specified in autodot.json. Add this command manually or run autodot init.` ) ) ; } try { execSync ( command , { stdio : 'inherit' , cwd : `${ autodotPath }` } ) ; resolve ( 'success' ) ; } catch ( e ) { reject ( e ) ; } } ) ; } ) ; } ; export const runScript = ( scriptName , autodotPath = `${ config . autodotPath }` ) => { return new Promise ( ( resolve , reject ) => { fs . readFile ( `${ autodotPath }/autodot.json` , ( err , buf ) => { if ( err ) reject ( err ) ; const data = JSON . parse ( buf . toString ( ) ) ; const script = data . scripts [ scriptName ] ; if ( ! script ) { reject ( new Error ( `${ scriptName } script not specified in autodot.json. Add this command manually.` ) ) ; } try { execSync ( script , { stdio : 'inherit' , cwd : `${ autodotPath }` } ) ; resolve ( 'success' ) ; } catch ( e ) { reject ( e ) ; } } ) ; } ) ; } ; export const writeFileAsync = ( path , data ) => { return new Promise ( ( resolve , reject ) => { fs . writeFile ( path , data , err => { if ( err ) reject ( err ) ; resolve ( 'Success' ) ; } ) ; } ) ; } ; export const cloneAsync = ( link , path , cloneOptions ) => { return new Promise ( ( resolve , reject ) => { nodegit . Clone . clone ( link , path , cloneOptions ) . then ( ( repo ) => resolve ( repo ) ) . catch ( ( e ) => reject ( e ) ) ; } ) ; } ;