1
+ const Blueprint = require ( 'ember-cli/lib/models/blueprint' ) ;
2
+ const fs = require ( 'fs-extra' ) ;
3
+ const { join } = require ( 'path' ) ;
4
+
5
+ const appBlueprint = Blueprint . lookup ( 'app' ) ;
6
+
7
+ module . exports = {
8
+ locals ( options ) {
9
+ return appBlueprint . locals ( options ) ;
10
+ } ,
11
+ beforeInstall ( options ) {
12
+ if ( ! appBlueprint ) {
13
+ throw new Error ( 'Cannot find app blueprint for generating test-app!' ) ;
14
+ }
15
+
16
+ return appBlueprint . install ( {
17
+ ...options ,
18
+ skipGit : true ,
19
+ } ) ;
20
+ } ,
21
+
22
+ async afterInstall ( options ) {
23
+ // there doesn't seem to be a way to tell ember-cli to not prompt to override files that were added in the beforeInstall
24
+ // so I'm just copying a few over at this stage
25
+ await fs . copy ( join ( __dirname , 'files-override' ) , options . target , {
26
+ overwrite : true ,
27
+ } ) ;
28
+
29
+ // this.addPackagesToProject doesn't respect the packageManager that the blueprint specified 🙈 so we're skipping a level here
30
+ let installTask = this . taskFor ( 'npm-install' ) ;
31
+ await installTask . run ( {
32
+ 'save-dev' : true ,
33
+ verbose : false ,
34
+ packages : [
35
+ '@embroider/core@unstable' ,
36
+ '@embroider/vite@unstable' ,
37
+ '@embroider/compat@unstable' ,
38
+ '@embroider/test-setup@unstable' ,
39
+ 'vite' ,
40
+ '@rollup/plugin-babel'
41
+ ] ,
42
+ packageManager : options . packageManager ,
43
+ } ) ;
44
+
45
+ let uninstallTask = this . taskFor ( 'npm-uninstall' ) ;
46
+ await uninstallTask . run ( {
47
+ 'save-dev' : true ,
48
+ verbose : false ,
49
+ packages : [ 'ember-fetch' ] ,
50
+ packageManager : options . packageManager ,
51
+ } ) ;
52
+
53
+ let packageJson = join ( options . target , 'package.json' ) ;
54
+ let json = await fs . readJSON ( packageJson ) ;
55
+
56
+ json . scripts = {
57
+ ...json . scripts ,
58
+ "build" : "vite build" ,
59
+ "start" : "vite" ,
60
+ "test:ember" : "vite build --mode test && ember test --path dist"
61
+ } ;
62
+
63
+ await fs . writeFile ( packageJson , JSON . stringify ( json , null , 2 ) ) ;
64
+ } ,
65
+ }
0 commit comments