-
Notifications
You must be signed in to change notification settings - Fork 130
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4579 from Shopify/jm/env-var
[Themes] Add CLI environment configuration to exported theme pull and push commands
- Loading branch information
Showing
5 changed files
with
102 additions
and
0 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
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,67 @@ | ||
import {configureCLIEnvironment} from './cli-config.js' | ||
import {globalFlags} from '@shopify/cli-kit/node/cli' | ||
import colors from '@shopify/cli-kit/node/colors' | ||
import {describe, expect, beforeEach, afterAll, test} from 'vitest' | ||
|
||
describe('configureCLIEnvironment', () => { | ||
const originalEnv = process.env | ||
|
||
beforeEach(() => { | ||
process.env = {...originalEnv} | ||
colors.level = 1 | ||
}) | ||
|
||
afterAll(() => { | ||
process.env = originalEnv | ||
}) | ||
|
||
describe('verbose', () => { | ||
test('sets verbose environment variable when verbose is true', () => { | ||
// Given | ||
delete process.env[globalFlags.verbose.env!] | ||
|
||
// When | ||
configureCLIEnvironment({verbose: true}) | ||
|
||
// Then | ||
expect(process.env[globalFlags.verbose.env!]).toBe('true') | ||
}) | ||
|
||
test('does not set verbose environment variable when verbose is false', () => { | ||
// Given | ||
delete process.env[globalFlags.verbose.env!] | ||
|
||
// When | ||
configureCLIEnvironment({verbose: false}) | ||
|
||
// Then | ||
expect(process.env[globalFlags.verbose.env!]).toBeUndefined() | ||
}) | ||
}) | ||
|
||
describe('noColor', () => { | ||
test('sets no-color environment variable when noColor is true', () => { | ||
// Given | ||
delete process.env[globalFlags['no-color'].env!] | ||
|
||
// When | ||
configureCLIEnvironment({noColor: true}) | ||
|
||
// Then | ||
expect(colors.level).toBe(0) | ||
expect(process.env.FORCE_COLOR).toBe('0') | ||
}) | ||
|
||
test('does not set no-color environment variable when noColor is false', () => { | ||
// Given | ||
delete process.env[globalFlags['no-color'].env!] | ||
|
||
// When | ||
configureCLIEnvironment({noColor: false}) | ||
|
||
// Then | ||
expect(colors.level).toBe(1) | ||
expect(process.env.FORCE_COLOR).toBe('1') | ||
}) | ||
}) | ||
}) |
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,24 @@ | ||
import {globalFlags} from '@shopify/cli-kit/node/cli' | ||
import colors from '@shopify/cli-kit/node/colors' | ||
|
||
interface CLIConfigOptions { | ||
verbose?: boolean | ||
noColor?: boolean | ||
} | ||
|
||
/** | ||
* Emulates the environment setup that oCLI commands perform when executed theme commands are executed programmatically. | ||
* Source: packages/cli-kit/src/public/node/cli.ts | ||
* | ||
* @param options - Configuration options for the CLI environment | ||
*/ | ||
export function configureCLIEnvironment(options: CLIConfigOptions): void { | ||
if (options.verbose) { | ||
process.env[globalFlags.verbose.env!] = 'true' | ||
} | ||
|
||
if (options.noColor) { | ||
colors.level = 0 | ||
process.env.FORCE_COLOR = '0' | ||
} | ||
} |