Skip to content

Commit

Permalink
use built in fs module functions to copy directory and remove temp files
Browse files Browse the repository at this point in the history
  • Loading branch information
bryanwood committed Jul 30, 2023
1 parent 7a9a180 commit 4a19b0e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
19 changes: 9 additions & 10 deletions create-project.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import { randomUUID } from 'crypto';
import { createWriteStream, existsSync, mkdirSync, readFileSync, renameSync, unlinkSync, writeFileSync } from 'fs'
import fsExtra from 'fs-extra'
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, parse } from 'path'
import https from 'https'
import tiny from 'tiny-json-http'
import tar from 'tar'

const { copySync } = fsExtra;

const require = createRequire(import.meta.url)

export async function createProject ({ dest, path, name }) {
Expand Down Expand Up @@ -50,15 +47,17 @@ export async function createProject ({ dest, path, name }) {
// Move starter project to final destination

// 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 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
copySync(join(temp, 'package'), projectDir)
cpSync(packageDir, projectDir, {recursive:true})
rmSync(packageDir, { recursive: true })
} else {
renameSync(join(temp, 'package'), projectDir)
renameSync(packageDir, projectDir)
}

// Clean up download
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
"tape": "^5.6.3"
},
"dependencies": {
"fs-extra": "^11.1.1",
"tar": "^6.1.14",
"tiny-json-http": "^7.5.1"
},
Expand Down

0 comments on commit 4a19b0e

Please sign in to comment.