Skip to content

Commit

Permalink
fix: windows support for cca
Browse files Browse the repository at this point in the history
  • Loading branch information
NorOldBurden committed Sep 12, 2024
1 parent 50c5a2a commit 2c6eae2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
13 changes: 7 additions & 6 deletions packages/create-cosmos-app/src/git-cca-template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as c from 'ansi-colors';
import { prompt } from './prompt';
import { join, dirname, basename, sep, relative } from 'path';
import { sync as mkdirp } from 'mkdirp';
import { sync as glob } from 'glob';
import { crossGlob as glob, toPosixPath } from './utils';
import * as fs from 'fs';
import {
cloneRepo,
Expand All @@ -14,14 +14,15 @@ import {
} from './utils';
import { CCA_URL } from './constants';

const posixPath = require('path').posix;
const requiredTools = ['git', 'yarn'];

const motd = (cmd: string, printCmd: boolean) => {
const commandSection = printCmd ? `Now, run this command:\n\n${c.bold.whiteBright(cmd)}` : '';
return `
| _ _
=== |.===. '\\-//\`
(o o) {}o o{} (o o)
=== |.===. '\\-//\`
(o o) {}o o{} (o o)
ooO--(_)--Ooo-ooO--(_)--Ooo-ooO--(_)--Ooo-
✨ Have fun! Now you can start on your project ⚛️
Expand Down Expand Up @@ -93,7 +94,7 @@ export const createGitApp = (repo: string, version: string) => {
// check version
await warnIfOutdated(repo, clonedRepoDir, version);

// get template
// get template
const list = shell.ls(`./${folderName}`);
const { template } = await prompt([
{
Expand Down Expand Up @@ -166,7 +167,7 @@ export const createGitApp = (repo: string, version: string) => {


// Construct the file path
const relativeFilePath = templateFile.split(join(folderName, template) + sep)[1];
const relativeFilePath = templateFile.split(toPosixPath(join(folderName, template) + '/'))[1];

// Replace keys in the entire file path
const replacedFilePath = Object.keys(results).reduce((filePath, key) => {
Expand Down Expand Up @@ -196,7 +197,7 @@ export const createGitApp = (repo: string, version: string) => {
const closestPkgJson = []
.concat(glob(join(currentDirectory, name, '**', 'package.json')))
.reduce((shortest, current) => {
return current.split(sep).length < shortest.split(sep).length ? current : shortest;
return current.split(posixPath.sep).length < shortest.split(posixPath.sep).length ? current : shortest;
}, fakeLongPath); // long string for kicks

if (closestPkgJson === fakeLongPath) {
Expand Down
12 changes: 12 additions & 0 deletions packages/create-cosmos-app/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ import { prompt } from './prompt';
import { join } from 'path';
import { sync as mkdirp } from 'mkdirp';
import { tmpdir } from 'os'
import { sync as globSync } from 'glob';
import * as fs from 'fs';

const posixPath = require('path').posix;
const dargs = require('dargs');


Expand Down Expand Up @@ -130,3 +133,12 @@ export const getPackageLicAndAccessInfo = async (results) => {
};
}

// Replace all \\ to / for windows support purpose
export const crossGlob = (input: string, options?: object) => {
return globSync(toPosixPath(input), options);
}

// Unify all the path to posixPath for windows support purpose
export const toPosixPath = (mixedPath): string => {
return mixedPath.replace(/\\/g, posixPath.sep);
}

0 comments on commit 2c6eae2

Please sign in to comment.