11import path from "node:path"
22import os from "node:os"
33import { log } from "./logger"
4- import { AsyncResolver , LogConfig , LogLevel , ScaffoldCmdConfig , ScaffoldConfigMap } from "./types"
4+ import { AsyncResolver , LogConfig , LogLevel , ScaffoldCmdConfig , ScaffoldConfig , ScaffoldConfigMap } from "./types"
55import { spawn } from "node:child_process"
6- import { wrapNoopResolver } from "./utils"
6+ import { resolve , wrapNoopResolver } from "./utils"
77
88export async function getGitConfig (
99 url : URL ,
@@ -15,7 +15,7 @@ export async function getGitConfig(
1515
1616 const tmpPath = path . resolve ( os . tmpdir ( ) , `scaffold-config-${ Date . now ( ) } ` )
1717
18- return new Promise ( ( resolve , reject ) => {
18+ return new Promise ( ( res , reject ) => {
1919 const clone = spawn ( "git" , [ "clone" , "--depth" , "1" , repoUrl , tmpPath ] )
2020
2121 clone . on ( "error" , reject )
@@ -24,18 +24,21 @@ export async function getGitConfig(
2424 log ( logConfig , LogLevel . Info , `Loading config from git repo: ${ repoUrl } ` )
2525 const hashPath = url . hash ?. replace ( "#" , "" ) || "scaffold.config.js"
2626 const absolutePath = path . resolve ( tmpPath , hashPath )
27- const loadedConfig = ( await import ( absolutePath ) ) . default as ScaffoldConfigMap
28- log ( logConfig , LogLevel . Info , `Loaded config from git` )
29- log ( logConfig , LogLevel . Debug , `Raw config:` , loadedConfig )
30- const fixedConfig : ScaffoldConfigMap = Object . fromEntries (
31- Object . entries ( loadedConfig ) . map ( ( [ k , v ] ) => [
32- k ,
33- // use absolute paths for template as config is necessarily in another directory
34- { ...v , templates : v . templates . map ( ( t ) => path . resolve ( tmpPath , t ) ) } ,
35- ] ) ,
27+ const loadedConfig = await resolve (
28+ async ( ) => ( await import ( absolutePath ) ) . default as ScaffoldConfigMap ,
29+ logConfig ,
3630 )
3731
38- resolve ( wrapNoopResolver ( fixedConfig ) )
32+ log ( logConfig , LogLevel . Info , `Loaded config from git` )
33+ log ( logConfig , LogLevel . Debug , `Raw config:` , loadedConfig )
34+ const fixedConfig : ScaffoldConfigMap = { }
35+ for ( const [ k , v ] of Object . entries ( loadedConfig ) ) {
36+ fixedConfig [ k ] = {
37+ ...v ,
38+ templates : v . templates . map ( ( t ) => path . resolve ( tmpPath , t ) ) ,
39+ }
40+ }
41+ res ( wrapNoopResolver ( fixedConfig ) )
3942 return
4043 }
4144
0 commit comments