Skip to content
This repository has been archived by the owner on Feb 16, 2024. It is now read-only.

Commit

Permalink
chore: add codemod-registry Windows support (#559)
Browse files Browse the repository at this point in the history
* chore: add Windows support
  • Loading branch information
DmytroHryshyn authored Jan 17, 2024
1 parent 9a5a965 commit 7509802
Show file tree
Hide file tree
Showing 12 changed files with 354 additions and 92 deletions.
10 changes: 8 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [macos-latest, ubuntu-latest]
os: [macos-latest, ubuntu-latest, windows-latest]

steps:
- name: Check out Git repository
Expand All @@ -34,4 +34,10 @@ jobs:
run: pnpm install

- name: Run codemod unit tests
run: pnpm test
run: |
if [[ ${{ matrix.os }} == "windows-latest" ]]; then
pnpm test:win
else
pnpm test
fi
shell: bash
13 changes: 6 additions & 7 deletions codemods/cal.com/app-directory-boilerplate-calcom/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
import { posix } from 'node:path';
import { sep, parse, format } from 'node:path';
import tsmorph, { Identifier, Node, SourceFile, SyntaxKind } from 'ts-morph';
import type { HandleData, HandleFile, Filemod } from '@intuita-inc/filemod';

Expand Down Expand Up @@ -527,15 +526,15 @@ const getNewPagePath = (
newDirArr.push(fileName);
}

return newDirArr.join(posix.sep);
return newDirArr.join(sep);
};

const handleFile: Filemod<
Dependencies,
Record<string, never>
>['handleFile'] = async (api, path, options) => {
const parsedPath = posix.parse(path);
const directoryNames = parsedPath.dir.split(posix.sep);
const parsedPath = parse(path);
const directoryNames = parsedPath.dir.split(sep);
const endsWithPages =
directoryNames.length > 0 &&
directoryNames.lastIndexOf('pages') === directoryNames.length - 1;
Expand Down Expand Up @@ -581,7 +580,7 @@ const handleFile: Filemod<
const commands: FileCommand[] = [
{
kind: 'upsertFile',
path: posix.format({
path: format({
root: parsedPath.root,
dir: newPagePath,
ext: parsedPath.ext,
Expand All @@ -597,7 +596,7 @@ const handleFile: Filemod<
},
{
kind: 'upsertFile',
path: posix.format({
path: format({
root: parsedPath.root,
dir: parsedPath.dir,
ext: parsedPath.ext,
Expand Down
6 changes: 3 additions & 3 deletions codemods/cal.com/generate-metadata-tests-calcom/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Filemod, HandleData, HandleFile } from '@intuita-inc/filemod';
import { posix } from 'node:path';
import { parse, sep } from 'node:path';

export const buildData = (appPath: string) => `
import { expect } from "@playwright/test";
Expand Down Expand Up @@ -95,8 +95,8 @@ const handleFile: HandleFile<Dependencies, State> = async (
return [];
}

const parsedPath = posix.parse(path);
const directoryNames = parsedPath.dir.split(posix.sep);
const parsedPath = parse(path);
const directoryNames = parsedPath.dir.split(sep);
const endsWithPages =
directoryNames.length > 0 &&
directoryNames.lastIndexOf('pages') === directoryNames.length - 1;
Expand Down
6 changes: 3 additions & 3 deletions codemods/cal.com/generate-url-patterns/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type {
HandleFinish,
InitializeState,
} from '@intuita-inc/filemod';
import { posix } from 'node:path';
import { parse, sep } from 'node:path';
import type { JSCodeshift } from 'jscodeshift';
import type { TSAsExpressionKind } from 'ast-types/gen/kinds.js';

Expand Down Expand Up @@ -109,8 +109,8 @@ const handleFile: HandleFile<Dependencies, State> = async (
}

if (state.step === 'READING') {
const parsedPath = posix.parse(path);
const directoryNames = parsedPath.dir.split(posix.sep);
const parsedPath = parse(path);
const directoryNames = parsedPath.dir.split(sep);

if (!directoryNames.includes('app') || parsedPath.name !== 'page') {
return [];
Expand Down
10 changes: 4 additions & 6 deletions codemods/next/13/ab-test/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Filemod, HandleData, HandleFile } from '@intuita-inc/filemod';
import type { JSCodeshift } from 'jscodeshift';
import { posix } from 'node:path';
import { parse, sep } from 'node:path';

// zero dependency ab test middleware factory
const MIDDLEWARE_FACTORY_CONTENT = `
Expand Down Expand Up @@ -108,7 +108,7 @@ const handleFile: HandleFile<Dependencies, State> = async (
path,
options,
) => {
const parsedPath = posix.parse(path);
const parsedPath = parse(path);
if (parsedPath.name === 'middleware') {
return [
{
Expand All @@ -118,9 +118,7 @@ const handleFile: HandleFile<Dependencies, State> = async (
},
{
kind: 'upsertFile',
path: [parsedPath.dir, 'abTestMiddlewareFactory.ts'].join(
posix.sep,
),
path: [parsedPath.dir, 'abTestMiddlewareFactory.ts'].join(sep),
options,
},
];
Expand All @@ -130,7 +128,7 @@ const handleFile: HandleFile<Dependencies, State> = async (
};

const handleData: HandleData<Dependencies, State> = async (api, path, data) => {
const parsedPath = posix.parse(path);
const parsedPath = parse(path);
if (parsedPath.name === 'middleware') {
const { jscodeshift } = api.getDependencies();
const j = jscodeshift.withParser('tsx');
Expand Down
Loading

0 comments on commit 7509802

Please sign in to comment.