-
Notifications
You must be signed in to change notification settings - Fork 0
TypeScript Rewrite: Build command #31
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
Open
d4mation
wants to merge
23
commits into
ENG-219/app-bootstrap
Choose a base branch
from
ENG-219/command-build
base: ENG-219/app-bootstrap
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 12 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
d61d860
ENG-219: Add build command
d4mation 6aaadb3
Merge branch 'ENG-219/app-bootstrap' into ENG-219/command-build
d4mation 3095bde
Merge branch 'ENG-219/app-bootstrap' into ENG-219/command-build
d4mation 689608e
Merge branch 'ENG-219/app-bootstrap' into ENG-219/command-build
d4mation a70b3b9
Merge branch 'ENG-219/app-bootstrap' into ENG-219/command-build
d4mation ff16a55
Merge branch 'ENG-219/app-bootstrap' into ENG-219/command-build
d4mation ea08446
ENG-219: Use createTempProject in build tests for isolation
d4mation c710c4b
Merge branch 'ENG-219/app-bootstrap' into ENG-219/command-build
d4mation d3c633d
Merge branch 'ENG-219/app-bootstrap' into ENG-219/command-build
d4mation 046379e
Merge branch 'ENG-219/app-bootstrap' into ENG-219/command-build
d4mation 0ce6c9d
Merge branch 'ENG-219/app-bootstrap' into ENG-219/command-build
d4mation 67bd7fd
Merge branch 'ENG-219/app-bootstrap' into ENG-219/command-build
d4mation cda8080
ENG-219: Improve build command test assertions
d4mation ca95646
ENG-219: Merge app-bootstrap and update imports
d4mation 26fd3e1
ENG-219: Remove unused workingDir arg from getConfig() call
d4mation 030ce60
Merge branch 'ENG-219/app-bootstrap' into ENG-219/command-build
d4mation 8698d9f
ENG-219: Remove `dist/` files
d4mation 9ea1d91
ENG-219: Improve and clarify build env vars test
d4mation 0abe46a
ENG-219: Remove unnecessary file
d4mation e72de6c
ENG-219: Remove accidentally committed action
d4mation 8f99f64
ENG-219: Remove accidentally comitted .puprc
d4mation 13242bc
ENG-219: Remove more accidentally comitted files
d4mation 6ed1720
ENG-219: Add test for build command --root flag
d4mation 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| import type { Command } from 'commander'; | ||
| import { getConfig } from '../config.js'; | ||
| import { runCommand } from '../utils/process.js'; | ||
| import * as output from '../utils/output.js'; | ||
|
|
||
| /** | ||
| * Registers the `build` command with the CLI program. | ||
| * | ||
| * @since TBD | ||
| * | ||
| * @param {Command} program - The Commander.js program instance. | ||
| * | ||
| * @returns {void} | ||
| */ | ||
| export function registerBuildCommand(program: Command): void { | ||
| program | ||
| .command('build') | ||
| .description('Run the build commands.') | ||
| .option('--dev', 'Run the dev build commands.') | ||
| .option('--root <dir>', 'Set the root directory for running commands.') | ||
| .action(async (options: { dev?: boolean; root?: string }) => { | ||
| const config = getConfig(options.root); | ||
| const buildSteps = config.getBuildCommands(options.dev); | ||
| const cwd = options.root ?? config.getWorkingDir(); | ||
|
|
||
| output.log('Running build steps...'); | ||
|
|
||
| for (const step of buildSteps) { | ||
| let cmd = step; | ||
| let bailOnFailure = true; | ||
|
|
||
| if (cmd.startsWith('@')) { | ||
| bailOnFailure = false; | ||
| cmd = cmd.slice(1); | ||
| } | ||
|
|
||
| output.section(`> ${cmd}`); | ||
|
|
||
| const result = await runCommand(cmd, { | ||
| cwd, | ||
| envVarNames: config.getEnvVarNames(), | ||
| }); | ||
|
|
||
| if (result.exitCode !== 0) { | ||
| output.error(`[FAIL] Build step failed: ${cmd}`); | ||
| if (bailOnFailure) { | ||
| output.error('Exiting...'); | ||
| process.exit(result.exitCode); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| output.success('Build complete.'); | ||
| }); | ||
| } |
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,65 @@ | ||
| import { | ||
| runPup, | ||
| writePuprc, | ||
| getPuprc, | ||
| createTempProject, | ||
| cleanupTempProjects, | ||
| } from '../helpers/setup.js'; | ||
|
|
||
| describe('build command', () => { | ||
| let projectDir: string; | ||
|
|
||
| beforeEach(() => { | ||
| projectDir = createTempProject(); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| cleanupTempProjects(); | ||
| }); | ||
|
|
||
| it('should run build', async () => { | ||
| const puprc = getPuprc(); | ||
| puprc.build = ['echo "fake project, yo"']; | ||
| writePuprc(puprc, projectDir); | ||
|
|
||
| const result = await runPup('build', { cwd: projectDir }); | ||
| expect(result.exitCode).toBe(0); | ||
| expect(result.output).toContain('fake project, yo'); | ||
| }); | ||
|
|
||
| it('should handle no build steps', async () => { | ||
| const puprc = getPuprc(); | ||
| puprc.build = []; | ||
| writePuprc(puprc, projectDir); | ||
|
|
||
| const result = await runPup('build', { cwd: projectDir }); | ||
| expect(result.exitCode).toBe(0); | ||
| }); | ||
|
|
||
| it('should fail without .puprc', async () => { | ||
| // Run in a dir with no .puprc but a package.json | ||
| const emptyDir = createTempProject(); | ||
| const result = await runPup('build', { cwd: emptyDir }); | ||
| expect(result.exitCode).toBe(0); | ||
| }); | ||
|
|
||
| it('should pass default env vars', async () => { | ||
| const puprc = getPuprc(); | ||
| puprc.build = ['echo "env test"']; | ||
| writePuprc(puprc, projectDir); | ||
|
|
||
| const result = await runPup('build', { cwd: projectDir }); | ||
| expect(result.exitCode).toBe(0); | ||
| }); | ||
|
|
||
| it('should run build with dev flag', async () => { | ||
| const puprc = getPuprc(); | ||
| puprc.build = ['echo "production build"']; | ||
| (puprc as Record<string, unknown>).build_dev = ['echo "dev build"']; | ||
| writePuprc(puprc, projectDir); | ||
|
|
||
| const result = await runPup('build --dev', { cwd: projectDir }); | ||
| expect(result.exitCode).toBe(0); | ||
| expect(result.output).toContain('dev build'); | ||
| }); | ||
| }); | ||
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.