feat(create-app): add custom template support via GitHub template sources#641
feat(create-app): add custom template support via GitHub template sources#641derrick-nuby wants to merge 3 commits intodhis2:masterfrom
Conversation
|
kabaros
left a comment
There was a problem hiding this comment.
Thanks a lot for this @derrick-nuby ! I left some comments here .. let me know if it's not clear, or you disagree
Thanks again for the great code, and taking initiative in adding this feature 🙏🏿
| reporter.info('Copying template files') | ||
| const templateFiles = getTemplateDirectory(selectedOptions.templateName) | ||
| fs.copySync(templateFiles, cwd) | ||
| const builtInTemplateMap = { |
There was a problem hiding this comment.
maybe for built-in templates, just resolve here in this module - no need to create a map, pass it and resolve it .. the getTemplateDirectory (renamed to getBuiltInTemplateDirectory) already does most of that responsibility.
So something like
let resolvedTemplate = getBuiltInTemplateDirectory(selectedOptions.templateSource)
if(!resolvedTemplate) {
// then do everything related to Git repos including cleanup
//
}no need to pass the map to resolveTemplateSource or make it aware of built-in tempaltes. (maybe rename the module to resolveExternalTemplates)
| parseGitTemplateSpecifier, | ||
| } = require('./isGitTemplateSpecifier') | ||
|
|
||
| const ensureTemplateDirectory = (templatePath, templateSource) => { |
There was a problem hiding this comment.
maybe better named validateTemplateDirectory?
- also could you move these helper methods into their own files (similar to
isGitTemplateSource) .. a lot if happening in this file now
| } | ||
| } | ||
|
|
||
| const resolveSubdirectory = (repoPath, subdir, templateSource) => { |
There was a problem hiding this comment.
is using a subdirectory a pattern that you, at HISP Rwanda, use? it just seems like it adds a lot of complexity to the code, and I feel like it's more than enough to support the other three other ways of defining repos



Summary
This PR adds support for using a GitHub repository as a template source in
@dhis2/create-app.In addition to built-in templates (
basic,react-router), users can now scaffold from public GitHub template repositories using shorthand or URL formats, including optional branch and subdirectory targeting.What Changed
templateSourceand ensure resolver cleanup infinally.Custom template from Git.Supported Template Formats
owner/repoowner/repo#refowner/repo#ref:subdirhttps://github.com/owner/repohttps://github.com/owner/repo#ref:subdirValidation
Executed local and smoke tests for:
owner/repo#ref.Notes