import * as path from 'path' ; import Crate from './crate' ; import Target from './target' ; import BuildSettings from './build-settings' ; import log from './log' ; import { spawn } from './async/child_process' ; import * as rust from './rust' ; export type ProjectOptions = { crate ? : string ; } ; /** A Neon project and its directory tree. */ export default class Project { readonly root : string ; readonly crate : Crate ; constructor ( root , options = { } ) { let { crate = 'native' } = options ; this . root = root ; this . crate = new Crate ( this , { subdirectory : crate } ) ; } async build ( toolchain , release , abi ) { let target = new Target ( this . crate , { release : release } ) ; let settings = BuildSettings . current ( toolchain ) ; if ( ! target . inState ( settings ) ) { log ( "forcing rebuild for new build settings" ) ; await target . clean ( ) ; } log ( "running cargo" ) ; await target . build ( toolchain , settings , abi ) ; log ( "generating " + path . join ( this . crate . subdirectory , this . crate . nodefile ) ) ; await this . crate . finish ( target . dylib ) ; } async clean ( ) { log ( "cargo clean" ) ; await spawn ( "cargo" , [ "clean" ] , { cwd : this . crate . root , stdio : 'inherit' } ) ; log ( "remove " + path . join ( this . crate . subdirectory , this . crate . nodefile ) ) ; await this . crate . removeAddon ( ) ; this . crate . resetArtifacts ( ) ; this . crate . saveArtifacts ( ) ; } } ;