Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use copy instead of rename if temp directory is on a different device #17

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions create-project.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { randomUUID } from 'crypto';
import { createWriteStream, existsSync, mkdirSync, readFileSync, renameSync, unlinkSync, writeFileSync } from 'fs'
import { randomUUID } from 'crypto'
import { createWriteStream, existsSync, mkdirSync, readFileSync, renameSync, unlinkSync, writeFileSync, cpSync, rmSync } from 'fs'
import { createRequire } from 'module'
import { tmpdir } from 'os'
import { isAbsolute, join, resolve } from 'path'
import { isAbsolute, join, resolve, parse } from 'path'
import https from 'https'
import tiny from 'tiny-json-http'
import tar from 'tar'
Expand Down Expand Up @@ -43,8 +43,23 @@ export async function createProject ({ dest, path, name }) {

// Extract starter project
tar.x({ C: temp, file: starterProjectArchive, sync: true })

// Move starter project to final destination
renameSync(join(temp, 'package'), projectDir)

// Check if the temp and projectDir are on the same file system
const tempRoot = parse(temp).root
const projectRoot = parse(projectDir).root
const isSameFileSystemRoot = tempRoot === projectRoot
const packageDir = join(temp, 'package')

if (!isSameFileSystemRoot) {
// if not, we need to copy the files instead of moving them
cpSync(packageDir, projectDir, { recursive: true })
rmSync(packageDir, { recursive: true })
} else {
renameSync(packageDir, projectDir)
}

// Clean up download
unlinkSync(starterProjectArchive)

Expand Down
Loading