@@ -23,8 +23,10 @@ import {
2323 getTemplateFileInfo ,
2424 logInitStep ,
2525 logInputFile ,
26+ parseConfig ,
2627} from "./utils"
27- import { LogLevel , ScaffoldConfig } from "./types"
28+ import { LogLevel , ScaffoldCmdConfig , ScaffoldConfig } from "./types"
29+ import { OptionsBase } from "massarg/types"
2830
2931/**
3032 * Create a scaffold using given `options`.
@@ -50,6 +52,7 @@ import { LogLevel, ScaffoldConfig } from "./types"
5052 * For available default values, see {@link DefaultHelpers}.
5153 *
5254 * @param {ScaffoldConfig } config The main configuration object
55+ * @return {Promise<void> } A promise that resolves when the scaffold is complete
5356 *
5457 * @see {@link DefaultHelpers }
5558 * @see {@link CaseHelpers }
@@ -101,6 +104,40 @@ export async function Scaffold(config: ScaffoldConfig): Promise<void> {
101104 throw e
102105 }
103106}
107+
108+ /**
109+ * Create a scaffold based on a config file or URL.
110+ *
111+ * @param {string } pathOrUrl The path or URL to the config file
112+ * @param {Record<string, string> } config Information needed before loading the config
113+ * @param {Partial<Omit<ScaffoldConfig, 'name'>> } overrides Any overrides to the loaded config
114+ *
115+ * @see {@link Scaffold }
116+ * @category Main
117+ * @return {Promise<void> } A promise that resolves when the scaffold is complete
118+ */
119+ Scaffold . fromConfig = async function (
120+ pathOrUrl : string ,
121+ config : Pick < ScaffoldCmdConfig , "name" | "key" > ,
122+ overrides ?: Partial < Omit < ScaffoldConfig , "name" > > ,
123+ ) : Promise < void > {
124+ const _cmdConfig : ScaffoldCmdConfig & OptionsBase = {
125+ dryRun : false ,
126+ output : process . cwd ( ) ,
127+ verbose : LogLevel . Info ,
128+ overwrite : false ,
129+ templates : [ ] ,
130+ createSubFolder : false ,
131+ quiet : false ,
132+ help : false ,
133+ extras : [ ] ,
134+ config : pathOrUrl ,
135+ ...config ,
136+ }
137+ const _config = await parseConfig ( _cmdConfig )
138+ return Scaffold ( { ..._config , ...overrides } )
139+ }
140+
104141async function handleTemplateFile (
105142 config : ScaffoldConfig ,
106143 { templatePath, basePath } : { templatePath : string ; basePath : string } ,
0 commit comments