- Notifications
You must be signed in to change notification settings - Fork 221
feat(bob): support custom target definitions #732
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits Select commit Hold shift + click to select a range
e70ad0d
feat: add script target
atlj 1aeef4d
feat: add clean to the script target
atlj 4469c09
docs: script target
atlj 50f4373
feat: rename script target to custom
atlj 135c8bc
feat: remove cwd
atlj 97c5e9f
feat: better logs
atlj 04283f9
fix: don't pass any output to the custom target
atlj 27b999e
Update prompts
atlj 0ef7b20
feat: warn user if clean path doesn't exist
atlj 898760f
refactor: rename packageManager to packageManagerExecutable
atlj File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,72 @@ | ||
import kleur from 'kleur'; | ||
import path from 'path'; | ||
import fs from 'fs-extra'; | ||
import type { Input } from '../types'; | ||
import { spawn } from '../utils/spawn'; | ||
import dedent from 'dedent'; | ||
import del from 'del'; | ||
| ||
type Options = Omit<Input, 'output'> & { | ||
options?: { | ||
script?: string; | ||
clean?: string; | ||
}; | ||
}; | ||
| ||
export default async function customTarget({ options, root, report }: Options) { | ||
if (options?.script == null) { | ||
report.error( | ||
dedent( | ||
`No script was provided with the custom target. | ||
Example: ${kleur.green('{["custom", { "script": "generateTypes" }}')}` | ||
) | ||
); | ||
process.exit(1); | ||
} | ||
| ||
const pathToClean = options.clean | ||
? path.relative(root, options.clean) | ||
: undefined; | ||
| ||
if (pathToClean) { | ||
report.info(`Cleaning up ${kleur.blue(pathToClean)}`); | ||
| ||
await del([path.resolve(root, pathToClean)]); | ||
} | ||
| ||
const packageManagerExecutable = process.env.npm_execpath ?? 'npm'; | ||
const packageManagerArgs = ['run', options.script]; | ||
| ||
// usr/bin/yarn -> yarn | ||
const packageManagerName = path.basename(packageManagerExecutable); | ||
report.info( | ||
`Running ${kleur.blue(packageManagerName)} ${kleur.blue( | ||
packageManagerArgs.join(' ') | ||
)}` | ||
); | ||
| ||
try { | ||
await spawn(packageManagerExecutable, packageManagerArgs, { | ||
stdio: ['ignore', 'ignore', 'inherit'], | ||
}); | ||
} catch (e) { | ||
report.error( | ||
`An error occurred when running ${kleur.blue(options.script)}` | ||
); | ||
process.exit(1); | ||
} | ||
| ||
report.success(`Ran the ${kleur.blue(options.script)} script succesfully`); | ||
| ||
if (options.clean && pathToClean && !(await fs.pathExists(pathToClean))) { | ||
report.warn( | ||
`Custom target with the ${kleur.blue( | ||
options.script | ||
)} script has ${kleur.blue(options.clean)} as the ${kleur.bold( | ||
'clean' | ||
)} option but this path wasn't created after running the script. Are you sure you've defined the ${kleur.bold( | ||
'clean' | ||
)} path correctly?` | ||
); | ||
} | ||
} |
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.