'use strict' ; import { PackageJson } from 'type-fest' ; import CheckupFixturifyProject from './checkup-fixturify-project' ; const enum InRepoPackageType { Addon = 'addon' , Engine = 'engine' } type IndexablePackageJson = PackageJson & { [ key ] : any ; } ; const Project = require ( 'fixturify-project' ) ; param { any } addon function prepareAddon ( addon ) { addon . pkg . keywords . push ( 'ember-addon' ) ; addon . pkg [ 'ember-addon' ] = { } ; addon . files [ 'index.js' ] = 'module.exports = { name: require("./package").name };' ; } /**
 * An extension of  CheckupFixturifyProject that adds methods specific to creating
 * mock Ember projects.
 *
 *  class augments CheckupFixturifyProject export default class EmberCLIFixturifyProject extends CheckupFixturifyProject { addAddon ( name , version = '0.0.0' ) { return this . addDependency ( name , version , ( addon ) => { prepareAddon ( addon ) ; } ) ; } addDevAddon ( name , version = '0.0.0' ) { return this . addDevDependency ( name , version , ( addon ) => { prepareAddon ( addon ) ; } ) ; } addInRepoAddon ( name , version = '0.0.0' ) { this . createPackage ( name , version , InRepoPackageType . Addon ) ; } addInRepoEngine ( name , version = '0.0.0' ) { this . createPackage ( name , version , InRepoPackageType . Engine ) ; } private createPackage ( name , version = '0.0.0' , type ) { const inRepoPackage = new Project ( name , version , ( project ) => { project . pkg . keywords . push ( 'ember-addon' ) ; if ( type === InRepoPackageType . Engine ) { project . pkg . keywords . push ( 'ember-engine' ) ; } project . pkg [ 'ember-addon' ] = { } ; project . files [ 'index.js' ] = 'module.exports = { name: require("./package").name };' ; } ) ; let addon = ( ( < IndexablePackageJson > this . pkg ) [ 'ember-addon' ] = ( < IndexablePackageJson > this . pkg ) [ 'ember-addon' ] || { } ) ; addon . paths = addon . paths || [ ] ; const addonPath = `lib/${ name }` ; if ( addon . paths . some ( ( path ) => path . toLowerCase ( ) === addonPath . toLowerCase ( ) ) ) { throw new Error ( `project: ${ this . name } already contains the in-repo-addon: ${ name }` ) ; } addon . paths . push ( addonPath ) ; this . files . lib = this . files . lib || { } ; Object . assign ( this . files . lib , inRepoPackage . toJSON ( ) ) ; } }