-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(github-actions): use chosen pkg manager
- Loading branch information
1 parent
bd2bc47
commit 9462e37
Showing
6 changed files
with
1,631 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ import { execSync, spawnSync } from 'child_process' | |
import chalk from 'chalk' | ||
import fs from 'fs' | ||
import path from 'path' | ||
import { runBlockingCommand } from './utils/runBlockingCommand' | ||
import { runBlockingCommand } from './utils/getRunBlockingCommand' | ||
import { promptQuestions } from './utils/inquirer/promptQuestions' | ||
import { replacePlaceholders } from './utils/replacePlaceholders' | ||
import { yarnWorkspaceJSON } from './config/yarn-workspace' | ||
|
@@ -11,6 +11,8 @@ import { huskyCommitMsgHook } from './config/husky-commit-msg-hook' | |
import { CLIs } from './tinyClis' | ||
import { getInstallCommand } from './utils/getInstallCommands' | ||
import { transformScopedName } from './utils/transformScopedName' | ||
import { getPkgManagerLockFile } from './utils/getPkgManagerLockFile' | ||
import { getRunWithFrozenLockCMD } from './utils/runWithFrozenLockCMD' | ||
|
||
export const main = async () => { | ||
const answers = await promptQuestions() | ||
|
@@ -78,14 +80,31 @@ export const main = async () => { | |
|
||
// Replace placeholders | ||
const workflowPath = path.join(projectWorkdir, '.github/workflows/CI.yml') | ||
|
||
let pkgManagerLockFile = getPkgManagerLockFile(pkgManager) | ||
let runWithFrozenLockCMD = getRunWithFrozenLockCMD(pkgManager) | ||
let runCMD = `${pkgManager} run` | ||
|
||
fs.writeFileSync( | ||
workflowPath, | ||
fs | ||
.readFileSync(workflowPath, 'utf-8') | ||
.replace( | ||
/\$WORKING_DIR/g, | ||
usingWorkspaces ? './packages/generator' : '.', | ||
), | ||
) | ||
.replace( | ||
/\$SETUP_PNPM/, | ||
pkgManager == 'pnpm' | ||
? `- name: Setup PNPM | ||
uses: pnpm/[email protected] | ||
with: | ||
version: 6.23.6` | ||
: '', | ||
) | ||
.replace(/\$PKG_MANAGER_LOCK/g, pkgManagerLockFile) | ||
.replace(/\$INSTALL_CMD_WITH_FROZEN_LOCK/g, runWithFrozenLockCMD) | ||
.replace(/\$PKG_MANAGER_RUN_CMD/g, runCMD), | ||
) | ||
const dependabotPath = path.join(projectWorkdir, '.github/dependabot.yml') | ||
fs.writeFileSync( | ||
|
19 changes: 19 additions & 0 deletions
19
packages/create-prisma-generator/src/utils/getPkgManagerLockFile.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
export const getPkgManagerLockFile = ( | ||
pkgManager: 'npm' | 'yarn' | 'pnpm', | ||
): string => { | ||
let pkgManagerLockFile | ||
|
||
switch (pkgManager) { | ||
case 'npm': | ||
pkgManagerLockFile = 'package-lock.json' | ||
break | ||
case 'yarn': | ||
pkgManagerLockFile = 'yarn.lock' | ||
break | ||
case 'pnpm': | ||
pkgManagerLockFile = 'pnpm-lock.yaml' | ||
break | ||
} | ||
|
||
return pkgManagerLockFile | ||
} |
File renamed without changes.
19 changes: 19 additions & 0 deletions
19
packages/create-prisma-generator/src/utils/runWithFrozenLockCMD.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
export const getRunWithFrozenLockCMD = ( | ||
pkgManager: 'npm' | 'yarn' | 'pnpm', | ||
): string => { | ||
let installWithFronzenLockCMD | ||
|
||
switch (pkgManager) { | ||
case 'npm': | ||
installWithFronzenLockCMD = 'npm ci' | ||
break | ||
case 'yarn': | ||
installWithFronzenLockCMD = 'yarn install --frozen-lockfile' | ||
break | ||
case 'pnpm': | ||
installWithFronzenLockCMD = 'pnpm i --frozen-lockfile' | ||
break | ||
} | ||
|
||
return installWithFronzenLockCMD | ||
} |
Oops, something went wrong.