-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
124 additions
and
46 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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { GluegunToolbox } from 'gluegun' | ||
|
||
module.exports = (toolbox: GluegunToolbox) => { | ||
const { patching, print } = toolbox | ||
|
||
toolbox.addScript = async (name: string, command: string) => { | ||
await patching.update('package.json', (config) => { | ||
if (!config.scripts[name]) { | ||
config.scripts[name] = command | ||
|
||
print.info(`✔ Added script "${name}": "${command}" to package.json.`) | ||
} | ||
|
||
return config | ||
}) | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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,38 @@ | ||
import { GluegunToolbox } from 'gluegun' | ||
|
||
module.exports = (toolbox: GluegunToolbox) => { | ||
const { filesystem, packageManager, print } = toolbox | ||
|
||
const isInstalled = (name: string, dev: boolean) => { | ||
const packageJSON = filesystem.read('package.json', 'json') | ||
return ( | ||
(!dev && packageJSON?.dependencies[name]) || | ||
(dev && packageJSON?.devDependencies[name]) | ||
) | ||
} | ||
|
||
toolbox.dependencies = { | ||
isInstalled, | ||
|
||
addDependency: async (name: string, ver: string, dev: boolean) => { | ||
if (isInstalled(name, dev)) { | ||
print.info(`${name} already installed, skipping adding dependency.`) | ||
return | ||
} | ||
|
||
const fullName = !ver ? name : `${name}@${ver}` | ||
|
||
const spinner = print.spin( | ||
`📦 Installing ${fullName} as ${ | ||
dev ? 'devDependency' : 'dependency' | ||
}...` | ||
) | ||
|
||
await packageManager.add(fullName, { dev }) | ||
|
||
spinner.stop() | ||
|
||
print.info(`✔ Installed ${fullName}.`) | ||
}, | ||
} | ||
} |
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,39 @@ | ||
import { confirm } from '@clack/prompts' | ||
import { Toolbox } from 'gluegun/build/types/domain/toolbox' | ||
|
||
const COMMAND = 'jest' | ||
|
||
const execute = () => async (toolbox: Toolbox) => { | ||
toolbox.dependencies.addDependency('jest', '', true) | ||
|
||
toolbox.addScript('test', 'jest') | ||
|
||
await toolbox.template.generate({ | ||
template: 'jest.ejf', | ||
target: `.github/workflows/jest.yml`, | ||
}) | ||
|
||
toolbox.print.info('✔ Created Jest workflow.') | ||
|
||
return `--${COMMAND}` | ||
} | ||
|
||
const run = async ( | ||
toolbox: Toolbox | ||
): Promise<(toolbox: Toolbox) => Promise<string> | null> => { | ||
if (toolbox.skipInteractiveForCommand(COMMAND)) { | ||
return execute() | ||
} | ||
|
||
const proceed = await confirm({ | ||
message: 'Do you want to run Jest on your project on every PR?', | ||
}) | ||
|
||
if (!proceed) { | ||
return | ||
} | ||
|
||
return execute() | ||
} | ||
|
||
export default run |
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
name: Run Jest tests | ||
on: [pull_request] | ||
|
||
jobs: | ||
test: | ||
name: Jest | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: 📦 Install dependencies | ||
run: yarn | ||
|
||
- name: 🎭 Run Jest | ||
run: yarn test |