Skip to content

Commit

Permalink
Fix create not working on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
cezaraugusto committed Aug 27, 2024
1 parent 2933834 commit a02bb1f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 21 deletions.
48 changes: 28 additions & 20 deletions programs/create/steps/import-external-template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,29 +48,37 @@ export async function importExternalTemplate(
}

if (projectName !== templateName) {
await fs.rename(templatePath, path.join(installationPath, projectName))
} else {
// Here we are in a templatePath/templateName situation.
// We first rename the top-level path to projectName-temp
// and then rename the templateName folder to projectName.
// Instead of renaming, copy the contents and then remove the original folder
const destPath = path.join(installationPath, projectName)

// e.g. new-react/new-react is at this moment new-react-temp/new-react
await fs.rename(
templatePath,
path.join(installationPath, projectName + '-temp')
)
// 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)
)
}

// Copy the new-react-temp/new-react to new-react
await fs.cp(
path.join(installationPath, projectName + '-temp', templateName),
path.join(installationPath, projectName),
{recursive: true}
)
// 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 new-react-temp folder
await fs.rm(path.join(installationPath, projectName + '-temp'), {
recursive: true
})
// Remove the temporary directory
await fs.rm(tempPath, {recursive: true, force: true})
}
} catch (error: any) {
console.error(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import SetupFirefoxReloadClient from '../setup-firefox-reload-client'
import ApplyManifestDevDefaults from './apply-manifest-dev-defaults'
import TargetWebExtensionPlugin from './target-web-extension-plugin'
import {DevOptions} from '../../../../module'
import { CHROMIUM_BASED_BROWSERS } from '../../../lib/constants'
import {CHROMIUM_BASED_BROWSERS} from '../../../lib/constants'

class SetupReloadStrategy {
private readonly manifestPath: string
Expand Down

0 comments on commit a02bb1f

Please sign in to comment.