diff --git a/programs/create/steps/import-external-template.ts b/programs/create/steps/import-external-template.ts index 1884d926..618d5e02 100644 --- a/programs/create/steps/import-external-template.ts +++ b/programs/create/steps/import-external-template.ts @@ -13,30 +13,29 @@ import * as messages from '../lib/messages' export async function importExternalTemplate( projectPath: string, projectName: string, - template: string + templateName: string ) { const installationPath = path.dirname(projectPath) - const templateName = path.basename(template) const examplesUrl = 'https://github.com/extension-js/extension.js/tree/main/examples' - const templateUrl = `${examplesUrl}/${template}` + const templateUrl = `${examplesUrl}/${templateName}` try { // Ensure the project path exists await fs.mkdir(projectPath, {recursive: true}) - let templatePath = '' - + // Pull the template folder or copy locally depending on the environment if (process.env.EXTENSION_ENV === 'development') { - console.log(messages.installingFromTemplate(projectName, template)) - - templatePath = path.join(projectPath, templateName) - - await fs.cp( - path.join(__dirname, '..', '..', '..', 'examples', templateName), - templatePath, - {recursive: true} + console.log(messages.installingFromTemplate(projectName, templateName)) + const localTemplatePath = path.join( + __dirname, + '..', + '..', + '..', + 'examples', + templateName ) + await fs.cp(localTemplatePath, projectPath, {recursive: true}) } else { await goGitIt( templateUrl, @@ -44,41 +43,7 @@ export async function importExternalTemplate( messages.installingFromTemplate(projectName, templateName) ) - templatePath = path.join(installationPath, templateName) - } - - if (projectName !== templateName) { - // Instead of renaming, copy the contents and then remove the original folder - const destPath = path.join(installationPath, projectName) - - // Copy the contents from templatePath to destPath - await fs.mkdir(destPath, {recursive: true}) - const files = await fs.readdir(templatePath) - for (const file of files) { - await fs.rename( - path.join(templatePath, file), - path.join(destPath, file) - ) - } - - // Remove the original templatePath folder - await fs.rm(templatePath, {recursive: true, force: true}) - } else { - // Handle the templatePath/templateName situation - const tempPath = path.join(installationPath, projectName + '-temp') - await fs.rename(templatePath, tempPath) - - // Move the contents of the tempPath/templateName to projectName - const srcPath = path.join(tempPath, templateName) - const destPath = path.join(installationPath, projectName) - await fs.mkdir(destPath, {recursive: true}) - const files = await fs.readdir(srcPath) - for (const file of files) { - await fs.rename(path.join(srcPath, file), path.join(destPath, file)) - } - - // Remove the temporary directory - await fs.rm(tempPath, {recursive: true, force: true}) + await fs.rename(path.join(installationPath, templateName), projectPath) } } catch (error: any) { console.error(