From 0f0b55488f2fedb5b12712b06f20e8dc0f43285c Mon Sep 17 00:00:00 2001 From: Vachmara <55046446+vachmara@users.noreply.github.com> Date: Mon, 24 Jul 2023 13:39:28 +0200 Subject: [PATCH] fix: app store cli windows compatibility issue #10324 (#10326) * fix: app-store-cli windows support issue #10324 * fix: app-store-cli windows support issue #10324 - remove yarn.lock * fix: app-store-cli windows support issue #10324 * refactor: instead of repeating code, use constant to know if it is windows platform --- packages/app-store-cli/src/constants.ts | 2 ++ packages/app-store-cli/src/core.ts | 10 +++++----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/packages/app-store-cli/src/constants.ts b/packages/app-store-cli/src/constants.ts index 500c973154..f23c8ff97f 100644 --- a/packages/app-store-cli/src/constants.ts +++ b/packages/app-store-cli/src/constants.ts @@ -1,4 +1,6 @@ import path from "path"; +import os from "os"; export const APP_STORE_PATH = path.join(__dirname, "..", "..", "app-store"); export const TEMPLATES_PATH = path.join(APP_STORE_PATH, "templates"); +export const IS_WINDOWS_PLATFORM = os.platform() === "win32"; \ No newline at end of file diff --git a/packages/app-store-cli/src/core.ts b/packages/app-store-cli/src/core.ts index cec46792da..e80d88630b 100644 --- a/packages/app-store-cli/src/core.ts +++ b/packages/app-store-cli/src/core.ts @@ -1,7 +1,7 @@ import fs from "fs"; import path from "path"; -import { APP_STORE_PATH, TEMPLATES_PATH } from "./constants"; +import { APP_STORE_PATH, TEMPLATES_PATH, IS_WINDOWS_PLATFORM} from "./constants"; import execSync from "./utils/execSync"; const slugify = (str: string) => { @@ -69,8 +69,8 @@ export const BaseAppFork = { }) { const appDirPath = getAppDirPath(slug, isTemplate); if (!editMode) { - await execSync(`mkdir -p ${appDirPath}`); - await execSync(`cp -r ${TEMPLATES_PATH}/${template}/* ${appDirPath}`); + await execSync(IS_WINDOWS_PLATFORM ? `mkdir ${appDirPath}` : `mkdir -p ${appDirPath}`); + await execSync(IS_WINDOWS_PLATFORM ? `xcopy "${TEMPLATES_PATH}\\${template}\\*" "${appDirPath}" /e /i` : `cp -r ${TEMPLATES_PATH}/${template}/* ${appDirPath}`); } else { if (!oldSlug) { throw new Error("oldSlug is required when editMode is true"); @@ -79,7 +79,7 @@ export const BaseAppFork = { // We need to rename only if they are different const oldAppDirPath = getAppDirPath(oldSlug, isTemplate); - await execSync(`mv ${oldAppDirPath} ${appDirPath}`); + await execSync(IS_WINDOWS_PLATFORM ? `move ${oldAppDirPath} ${appDirPath}` : `mv ${oldAppDirPath} ${appDirPath}`); } } updatePackageJson({ slug, appDirPath, appDescription: description }); @@ -126,7 +126,7 @@ export const BaseAppFork = { delete: async function ({ slug, isTemplate }: { slug: string; isTemplate: boolean }) { const appDirPath = getAppDirPath(slug, isTemplate); - await execSync(`rm -rf ${appDirPath}`); + await execSync(IS_WINDOWS_PLATFORM ? `rd /s /q ${appDirPath}` : `rm -rf ${appDirPath}`); }, };