diff --git a/.changeset/happy-seals-fly.md b/.changeset/happy-seals-fly.md new file mode 100644 index 0000000..e9b6a41 --- /dev/null +++ b/.changeset/happy-seals-fly.md @@ -0,0 +1,5 @@ +--- +"create-cardinal-app": patch +--- + +(cli): rewrite scaffolding logic for broken installers diff --git a/.github/canary-release.js b/.github/canary-release.js new file mode 100644 index 0000000..5ed40ee --- /dev/null +++ b/.github/canary-release.js @@ -0,0 +1,30 @@ +import fs from 'fs'; +import { exec } from 'child_process'; + +const pkgJsonPaths = [ + "cli/package.json" +] + +try { + exec("git rev-parse --short HEAD", (err, stdout) => { + if (err) { + console.log(err); + process.exit(1); + } + const commitHash = stdout.trim(); + + for (const pkgJsonPath of pkgJsonPaths) { + const pkg = JSON.parse(fs.readFileSync(pkgJsonPath, "utf-8")); + const oldVersion = pkg.version; + const [major, minor, patch] = oldVersion.split(".").map(Number); + const newVersion = `${major}.${minor}.${patch + 1}-canary.${commitHash}`; + pkg.version = newVersion; + const content = JSON.stringify(pkg, null, "\t") + "\n"; + + fs.writeFileSync(pkgJsonPath, content); + } + }); +} catch (error) { + console.error(error); + process.exit(1); +} \ No newline at end of file diff --git a/.github/workflows/canary_release.yaml b/.github/workflows/canary_release.yaml index be966df..66e0a1b 100644 --- a/.github/workflows/canary_release.yaml +++ b/.github/workflows/canary_release.yaml @@ -4,6 +4,9 @@ on: branches: - canary +permissions: + id-token: write + jobs: release-canary: if: ${{ github.repository_owner == 'ernesto-oss' }} @@ -45,31 +48,19 @@ jobs: - name: Build run: pnpm turbo --filter=create-cardinal-app build - - name: Create Version PR or Publish Canary to NPM - id: changeset - uses: changesets/action@v1 - with: - commit: "chore(release-canary): version packages" - title: "chore(release-canary): version packages" - version: "npx changeset version --snapshot canary" - publish: "npx changeset publish --no-git-tag --tag canary" + ## The change made to package.json here is ephemeral, as it will only run in CI + - name: Bump version to canary + run: node .github/canary-release.js + + - name: Install NPM + run: npm i -g npm@9.6.7 # need latest version for provenance + + - name: Authenticate to npm and publish env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} NPM_TOKEN: ${{ secrets.NPM_TOKEN }} - NODE_ENV: "production" - - - name: Get ID of latest Github release - id: releaseId - if: steps.changeset.outputs.published == 'true' run: | - releaseId="$(gh release view --json id -R ernesto-oss/cardinal --jq '.id')" - echo 'RELEASE_ID='$releaseId >> "$GITHUB_OUTPUT" - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - - name: Edit latest release to pre-release - if: steps.changeset.outputs.published == 'true' - uses: irongut/EditRelease@v1.2.0 - with: - token: ${{ secrets.GITHUB_TOKEN }} - id: ${{ steps.releaseId.outputs.releaseId }} + pnpm build:cli + echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc + cd ./cli + npm publish --provenance --access public --ignore-scripts --tag canary + diff --git a/cli/CHANGELOG.md b/cli/CHANGELOG.md index a60504d..96ca7eb 100644 --- a/cli/CHANGELOG.md +++ b/cli/CHANGELOG.md @@ -1,5 +1,3 @@ -# create-cardinal-app - ## 0.2.1 ### Patch Changes diff --git a/cli/src/installers/authInstaller.ts b/cli/src/installers/authInstaller.ts index a85b7f2..17c6497 100644 --- a/cli/src/installers/authInstaller.ts +++ b/cli/src/installers/authInstaller.ts @@ -9,7 +9,6 @@ import { authDependencyMap, type AvailableAuthDependenciesKeys, } from "@/helpers/addPackageDependency.js"; -import { removeArtifacts } from "@/helpers/removeArtifacts.js"; import { type ProjectOptions } from "@/index.js"; export const authInstaller = ({ @@ -23,13 +22,19 @@ export const authInstaller = ({ const authTemplateRoot = path.join(TEMPLATE_DIR, "auth"); const authDestination = path.join(projectDir, "packages/auth"); - const copyDir = (fileName: string) => - fs.copySync(path.join(authTemplateRoot, fileName), authDestination, { - filter: removeArtifacts, - }); + const getTemplateTypeDirectory = () => { + let templateTypeDirectory = ""; - if (databaseProvider === "planetscale" && frontendFramework === "next") - copyDir("auth-planetscale-next"); + if (databaseProvider === "planetscale" && frontendFramework === "next") + templateTypeDirectory = "auth-planetscale-next"; + + return templateTypeDirectory; + }; + + fs.copySync( + path.join(authTemplateRoot, getTemplateTypeDirectory()), + path.join(authDestination), + ); /* Write `tsconfig.json` */ const templateAuthTsConfig = fs.readJsonSync( diff --git a/cli/src/installers/databaseInstaller.ts b/cli/src/installers/databaseInstaller.ts index b950bb3..f4f0800 100644 --- a/cli/src/installers/databaseInstaller.ts +++ b/cli/src/installers/databaseInstaller.ts @@ -14,7 +14,6 @@ import { createPackageScripts, databaseScriptsMap, } from "@/helpers/createPackageScripts.js"; -import { removeArtifacts } from "@/helpers/removeArtifacts.js"; import { type ProjectOptions } from "@/index.js"; import { type PackageManager } from "@/utils/getUserPackageManager.js"; @@ -31,17 +30,21 @@ export const databaseInstaller = ({ const databaseTemplateRoot = path.join(TEMPLATE_DIR, "database"); const databaseDestination = path.join(projectDir, "packages/database"); - const copyDir = (fileName: string) => - fs.copySync( - path.join(databaseTemplateRoot, fileName), - databaseDestination, - { filter: removeArtifacts }, - ); + const getTemplateTypeDirectory = () => { + let templateTypeDirectory = ""; - if (databaseProvider === "planetscale") - authentication - ? copyDir("database-planetscale-auth") - : copyDir("database-planetscale"); + if (databaseProvider === "planetscale") + authentication + ? (templateTypeDirectory = "database-planetscale-auth") + : (templateTypeDirectory = "database-planetscale"); + + return templateTypeDirectory; + }; + + fs.copySync( + path.join(databaseTemplateRoot, getTemplateTypeDirectory()), + path.join(databaseDestination), + ); /* Write `tsconfig.json` */ const templateDatabaseTsConfig = fs.readJsonSync( diff --git a/cli/src/installers/graphqlInstaller.ts b/cli/src/installers/graphqlInstaller.ts index 68cfd21..ab38ae1 100644 --- a/cli/src/installers/graphqlInstaller.ts +++ b/cli/src/installers/graphqlInstaller.ts @@ -14,7 +14,6 @@ import { createPackageScripts, graphQLScriptsMap, } from "@/helpers/createPackageScripts.js"; -import { removeArtifacts } from "@/helpers/removeArtifacts.js"; import { type ProjectOptions } from "@/index.js"; import { type PackageManager } from "@/utils/getUserPackageManager.js"; @@ -36,19 +35,25 @@ export const graphQLInstaller = ({ const graphqlTemplateRoot = path.join(TEMPLATE_DIR, "graphql"); const graphQLDestination = path.join(projectDir, "packages/api"); - const copyDir = (fileName: string) => - fs.copySync(path.join(graphqlTemplateRoot, fileName), graphQLDestination, { - filter: removeArtifacts, - }); + const getTemplateTypeDirectory = () => { + let templateTypeDirectory = ""; - if (frontendFramework === "next") { - databaseProvider === "planetscale" && authentication - ? copyDir("graphql-next-planetscale-auth") - : null; - databaseProvider === "planetscale" && !authentication - ? copyDir("graphql-next-planetscale") - : null; - } + if (frontendFramework === "next") { + databaseProvider === "planetscale" && authentication + ? (templateTypeDirectory = "graphql-next-planetscale-auth") + : null; + databaseProvider === "planetscale" && !authentication + ? (templateTypeDirectory = "graphql-next-planetscale") + : null; + } + + return templateTypeDirectory; + }; + + fs.copySync( + path.join(graphqlTemplateRoot, getTemplateTypeDirectory()), + path.join(graphQLDestination), + ); /* Write `tsconfig.json` */ const templateGraphqlTsConfig = fs.readJsonSync( diff --git a/cli/src/installers/nextjsInstaller.ts b/cli/src/installers/nextjsInstaller.ts index 76ed77e..c31b57a 100644 --- a/cli/src/installers/nextjsInstaller.ts +++ b/cli/src/installers/nextjsInstaller.ts @@ -16,7 +16,6 @@ import { createPackageScripts, nextScriptsMap, } from "@/helpers/createPackageScripts.js"; -import { removeArtifacts } from "@/helpers/removeArtifacts.js"; import { type ProjectOptions } from "@/index.js"; import { type PackageManager } from "@/utils/getUserPackageManager.js"; @@ -33,14 +32,19 @@ export const nextjsInstaller = ({ const nextTemplateRoot = path.join(TEMPLATE_DIR, "next"); const nextDestination = path.join(projectDir, "packages/web"); - const copyDir = (fileName: string) => - fs.copySync(path.join(nextTemplateRoot, fileName), nextDestination, { - filter: removeArtifacts, - }); + const getTemplateTypeDirectory = () => { + if (backendType === "graphql") { + if (authentication) return "next-graphql-auth"; + return "next-graphql"; + } - if (backendType === "graphql") { - authentication ? copyDir("next-graphql-auth") : copyDir("next-graphql"); - } + return ""; + }; + + fs.copySync( + path.join(nextTemplateRoot, getTemplateTypeDirectory()), + path.join(nextDestination), + ); /* Write `tsconfig.json` */ const templateNextTsConfig = fs.readJsonSync(