Skip to content

Commit

Permalink
chore: update types, use Enum
Browse files Browse the repository at this point in the history
  • Loading branch information
zhamujun committed Sep 19, 2023
1 parent 6309b05 commit 87530a6
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 15 deletions.
3 changes: 1 addition & 2 deletions packages/cli/src/commands/sandbox/sandbox_command.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { ArgumentsCamelCase, Argv, CommandModule } from 'yargs';
import { formatChoices } from '@aws-amplify/client-config';
import { SandboxDeleteCommand } from './sandbox-delete/sandbox_delete_command.js';
import fs from 'fs';
import { AmplifyPrompter } from '../prompter/amplify_prompts.js';
import { SandboxSingletonFactory } from '@aws-amplify/sandbox';

export const formatChoices = ['js', 'json', 'ts'] as const;

export type SandboxCommandOptions = {
dirToWatch: string | undefined;
exclude: string[] | undefined;
Expand Down
13 changes: 10 additions & 3 deletions packages/client-config/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,17 @@ export type ClientConfig = Partial<AuthClientConfig & GraphqlClientConfig & Stor
export const configFileName = "amplifyconfiguration";

// @public (undocumented)
export const formatChoices: readonly ["js", "json", "ts"];
export const formatChoices: FormatOption[];

This comment has been minimized.

Copy link
@Amplifiyer

Amplifiyer Sep 19, 2023

Contributor

Stay consistent with naming, it's either Choice or an Option. I prefer formatOption


// @public (undocumented)
export type FormatOption = (typeof formatChoices)[number];
export enum FormatOption {
// (undocumented)
JS = "js",
// (undocumented)
JSON = "json",
// (undocumented)
TS = "ts"
}

// @public
export const generateClientConfig: (credentialProvider: AwsCredentialIdentityProvider, backendIdentifier: BackendIdentifier) => Promise<ClientConfig>;
Expand All @@ -44,7 +51,7 @@ export const generateClientConfig: (credentialProvider: AwsCredentialIdentityPro
export const generateClientConfigToFile: (credentialProvider: AwsCredentialIdentityProvider, backendIdentifier: BackendIdentifier, targetPath: string) => Promise<void>;

// @public
export const getConfigPath: (out: string | undefined, format?: FormatOption) => string;
export const getConfigPath: (out: string | undefined, format: (typeof formatChoices)[number] | undefined) => string;

// @public
export type GraphqlClientConfig = {
Expand Down
12 changes: 8 additions & 4 deletions packages/client-config/src/get_config_path.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import path from 'path';

export const formatChoices = ['js', 'json', 'ts'] as const;
export const configFileName = 'amplifyconfiguration';
export type FormatOption = (typeof formatChoices)[number];
export enum FormatOption {
JS = 'js',
JSON = 'json',
TS = 'ts',
}
export const formatChoices = Object.values(FormatOption);

/**
* Get path to config file
Expand All @@ -12,11 +16,11 @@ export type FormatOption = (typeof formatChoices)[number];
*/
export const getConfigPath = (
out: string | undefined,
format: FormatOption = 'js'
format: (typeof formatChoices)[number] | undefined
) => {
const defaultArgs = {
out: process.cwd(),
format: 'js',
format: FormatOption.JS,
};

let targetPath: string;
Expand Down
5 changes: 2 additions & 3 deletions packages/sandbox/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
```ts

// @public (undocumented)
export const formatChoices: readonly ["js", "json", "ts"];
import { formatChoices } from '@aws-amplify/client-config';

// @public
export type Sandbox = {
Expand All @@ -24,7 +23,7 @@ export type SandboxOptions = {
dir?: string;
exclude?: string[];
name?: string;
format?: (typeof formatChoices)[number];
format?: typeof formatChoices[number];
profile?: string;
clientConfigFilePath?: string;
};
Expand Down
7 changes: 4 additions & 3 deletions packages/sandbox/src/file_watching_sandbox.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { afterEach, beforeEach, describe, it, mock } from 'node:test';
import watcher from '@parcel/watcher';
import { FormatOption } from '@aws-amplify/client-config';
import { FileWatchingSandbox } from './file_watching_sandbox.js';
import assert from 'node:assert';
import { AmplifySandboxExecutor } from './sandbox_executor.js';
Expand Down Expand Up @@ -251,7 +252,7 @@ describe('Sandbox with user provided app name', () => {
dir: 'testDir',
exclude: ['exclude1', 'exclude2'],
name: 'customSandboxName',
format: 'ts',
format: FormatOption.TS,
clientConfigFilePath: path.join('test', 'location'),
});
if (
Expand Down Expand Up @@ -370,7 +371,7 @@ describe('Sandbox with absolute output path', () => {
dir: 'testDir',
exclude: ['exclude1', 'exclude2'],
name: 'customSandboxName',
format: 'json',
format: FormatOption.JSON,
clientConfigFilePath: path.join('test', 'location'),
profile: 'amplify-sandbox',
});
Expand Down Expand Up @@ -455,7 +456,7 @@ describe('Sandbox ignoring paths in .gitignore', () => {
dir: 'testDir',
exclude: ['customer_exclude1', 'customer_exclude2'],
name: 'customSandboxName',
format: 'ts',
format: FormatOption.TS,
clientConfigFilePath: '',
});
if (
Expand Down

0 comments on commit 87530a6

Please sign in to comment.