From 059493e852ffede4283a085ea6120673f3bc73c9 Mon Sep 17 00:00:00 2001 From: Drake Costa Date: Tue, 7 May 2024 18:26:53 -0700 Subject: [PATCH] fix: Add basic Windows development support (#1) Co-authored-by: cpojer --- .eslintrc.cjs | 8 +++++++- .github/workflows/test.yml | 12 +++++++++++- README.md | 11 +++++++++++ codegen/generate-campaign-names.tsx | 9 +++++---- codegen/generate-graphql.tsx | 8 ++++++-- codegen/generate-translations.tsx | 21 +++++++++++++-------- 6 files changed, 53 insertions(+), 16 deletions(-) diff --git a/.eslintrc.cjs b/.eslintrc.cjs index 4795cc7f..be6fd4f5 100644 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -85,7 +85,13 @@ module.exports = { .split('\n') .slice(1) .map((n) => - join(__dirname, n.replaceAll(/\s*-\s+/g, '').replaceAll("'", '')), + join( + __dirname, + n + .replaceAll(/\s*-\s+/g, '') + .replaceAll("'", '') + .replaceAll('\r', ''), + ), ), ), }, diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 46419ffe..97595917 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -10,7 +10,6 @@ on: jobs: action: - runs-on: 'ubuntu-latest' timeout-minutes: 20 permissions: contents: read @@ -18,6 +17,8 @@ jobs: strategy: matrix: node-version: [22] + os: [ubuntu-latest, windows-latest] + runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v3 @@ -27,6 +28,10 @@ jobs: with: node-version: ${{ matrix.node-version }} + - name: Use Git Bash + if: matrix.os == 'windows-latest' + run: npm config set script-shell "C:\\Program Files\\git\\bin\\bash.exe" + - name: Install pnpm uses: pnpm/action-setup@v2 id: pnpm-install @@ -61,4 +66,9 @@ jobs: run: pnpx playwright install --with-deps chromium - name: Run tests + if: matrix.os != 'windows-latest' run: pnpm test:ci + + - name: Run tests (Windows) + if: matrix.os == 'windows-latest' + run: pnpm vitest:run-ci diff --git a/README.md b/README.md index 67048a95..6d0a3e00 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,17 @@ If you like Athena Crisis, [please consider a sponsorship to support its develop Athena Crisis requires [Node.js](https://nodejs.org/en/download/package-manager) and the latest major version of [`pnpm`](https://pnpm.io/installation). +> [!NOTE] +> +>
Windows Specific Config +> Developers on Windows will want to ensure that they are using `bash` to run `package.json` scripts. You can configure npm to use git bash by default with the following: +> +> ```bash +> npm config set script-shell "C:\\Program Files\\git\\bin\\bash.exe" +> ``` +> +>
+ ```bash pnpm install && pnpm dev:setup pnpm dev diff --git a/codegen/generate-campaign-names.tsx b/codegen/generate-campaign-names.tsx index f0c99e78..b92eb99b 100755 --- a/codegen/generate-campaign-names.tsx +++ b/codegen/generate-campaign-names.tsx @@ -1,6 +1,7 @@ #!/usr/bin/env node --no-warnings --experimental-specifier-resolution=node --loader ts-node/esm import { writeFileSync } from 'node:fs'; -import { join } from 'node:path'; +import { join, posix, sep } from 'node:path'; +import { pathToFileURL } from 'node:url'; import toSlug from '@deities/hephaestus/toSlug.tsx'; import chalk from 'chalk'; import { globSync } from 'glob'; @@ -14,13 +15,13 @@ const globs: ReadonlyArray = [ './hermes/map-fixtures/*.tsx', './fixtures/map/*.tsx', ]; -const outputFile = join(root, 'hermes/CampaignMapName.tsx'); +const outputFile = join(root, './hermes/CampaignMapName.tsx'); const maps = ( await Promise.all( globs - .flatMap((path) => globSync(join(root, path))) - .map((file) => import(file)), + .flatMap((path) => globSync(join(root, path).split(sep).join(posix.sep))) + .map((file) => import(pathToFileURL(file).toString())), ) ) .filter((module) => module.metadata.tags?.includes('campaign')) diff --git a/codegen/generate-graphql.tsx b/codegen/generate-graphql.tsx index 2d413096..93e4cdc5 100755 --- a/codegen/generate-graphql.tsx +++ b/codegen/generate-graphql.tsx @@ -1,6 +1,6 @@ #!/usr/bin/env node --no-warnings --experimental-specifier-resolution=node --loader ts-node/esm import { writeFileSync } from 'node:fs'; -import { join, relative } from 'node:path'; +import { join, posix, relative, sep } from 'node:path'; import chalk from 'chalk'; import { globSync } from 'glob'; import { format } from 'prettier'; @@ -13,7 +13,11 @@ const root = process.cwd(); const path = join(root, 'artemis/graphql'); const outputFile = join(path, 'schemaImportMap.tsx'); -const files = (await Promise.all(globSync(`${path}/{nodes,mutations}/*.tsx`))) +const files = ( + await Promise.all( + globSync(`${path}/{nodes,mutations}/*.tsx`.split(sep).join(posix.sep)), + ) +) .map((file) => relative(path, file.slice(0, file.lastIndexOf('.')))) .sort((a, b) => String(a).localeCompare(String(b))); diff --git a/codegen/generate-translations.tsx b/codegen/generate-translations.tsx index 0bd43072..e6c5b29b 100755 --- a/codegen/generate-translations.tsx +++ b/codegen/generate-translations.tsx @@ -1,6 +1,7 @@ #!/usr/bin/env node --no-warnings --experimental-specifier-resolution=node --loader ts-node/esm import { writeFileSync } from 'node:fs'; -import { basename, extname, join } from 'node:path'; +import { basename, extname, join, posix, sep } from 'node:path'; +import { pathToFileURL } from 'node:url'; import getMessageKey from '@deities/apollo/lib/getMessageKey.tsx'; import { mapBuildings } from '@deities/athena/info/Building.tsx'; import { mapDecorators } from '@deities/athena/info/Decorator.tsx'; @@ -48,23 +49,27 @@ const globs: ReadonlyArray = [ ]; const maps = await Promise.all( globs.flatMap((path) => - globSync(join(root, path)) + globSync(join(root, path).split(sep).join(posix.sep)) .sort() .map((filename) => - (import(filename) as Promise).then((module) => ({ - id: basename(filename, extname(filename)), - module, - })), + (import(pathToFileURL(filename).toString()) as Promise).then( + (module) => ({ + id: basename(filename, extname(filename)), + module, + }), + ), ), ), ); const mapsById = new Map(maps.map(({ id, module }) => [id, module])); const campaigns = await Promise.all( - globSync(join(root, './fixtures/campaign/*.tsx')) + globSync(join(root, './fixtures/campaign/*.tsx').split(sep).join(posix.sep)) .sort() .map((filename) => - (import(filename) as Promise).then((module) => ({ + ( + import(pathToFileURL(filename).toString()) as Promise + ).then((module) => ({ id: basename(filename, extname(filename)), module, })),