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

fix: windows support for cca #205

Merged
merged 1 commit into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
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
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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sure to use the constant sep from 'const posixPath = require('path').posix;'

return current.split(posixPath.sep).length < shortest.split(posixPath.sep).length ? current : shortest;
}, fakeLongPath); // long string for kicks

if (closestPkgJson === fakeLongPath) {
Expand Down
21 changes: 21 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,21 @@ export const getPackageLicAndAccessInfo = async (results) => {
};
}

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

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