Skip to content

Commit 662aa08

Browse files
Merge pull request #51 from contentstack/CL-1637
fix: allow --type flag to create new project without prompting to select provider
2 parents 90d4322 + 7c3a0c8 commit 662aa08

File tree

3 files changed

+54
-3
lines changed

3 files changed

+54
-3
lines changed

.talismanrc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
fileignoreconfig:
2+
- filename: src/commands/launch/index.test.ts
3+
checksum: 9db6c02ad35a0367343cd753b916dd64db4a9efd24838201d2e1113ed19c9b62
4+
version: "1.0"

src/commands/launch/index.test.ts

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,27 @@ import { BaseCommand } from '../../base-command';
33
import { FileUpload, GitHub, PreCheck } from '../../adapters';
44
import { cliux } from '@contentstack/cli-utilities';
55

6-
jest.mock('@contentstack/cli-utilities');
7-
86
jest.mock('../../base-command');
97

8+
jest.mock('@contentstack/cli-utilities', () => {
9+
const actual = jest.requireActual('@contentstack/cli-utilities');
10+
return {
11+
...actual,
12+
configHandler: {
13+
get: jest.fn((key) => {
14+
if (key === 'authtoken') return 'dummy-token';
15+
if (key === 'authorisationType') return 'OAuth';
16+
if (key === 'oauthAccessToken') return 'dummy-oauth-token';
17+
return undefined;
18+
}),
19+
},
20+
cliux: {
21+
...actual.cliux,
22+
inquire: jest.fn(), // mock `inquire` explicitly
23+
},
24+
};
25+
});
26+
1027
describe('Run', () => {
1128
let launchCommandInstance: Launch;
1229
let prepareApiClientsMock: jest.SpyInstance;
@@ -89,4 +106,18 @@ describe('Run', () => {
89106
message: 'Choose a project type to proceed',
90107
});
91108
});
109+
110+
it('should successfully run launch command when its a new project, and provider is passed as flag', async () => {
111+
const githubRunMock = jest.spyOn(GitHub.prototype, 'run').mockResolvedValueOnce(undefined);
112+
BaseCommand.prototype['sharedConfig'] = {isExistingProject: false} as any;
113+
BaseCommand.prototype['flags'] = { init: false, type: 'GitHub' };
114+
launchCommandInstance = new Launch([], {} as any);
115+
116+
await launchCommandInstance.run();
117+
118+
expect(prepareApiClientsMock).toHaveBeenCalled();
119+
expect(preCheckRunMock).toHaveBeenCalled();
120+
expect(githubRunMock).toHaveBeenCalled();
121+
expect(cliux.inquire).not.toHaveBeenCalled();
122+
});
92123
});

src/commands/launch/index.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,13 @@ export default class Launch extends BaseCommand<typeof Launch> {
2121
'<%= config.bin %> <%= command.id %> --data-dir <path/of/current/working/dir> --redeploy-last-upload',
2222
'<%= config.bin %> <%= command.id %> --config <path/to/launch/config/file> --type <options: GitHub|FileUpload>',
2323
'<%= config.bin %> <%= command.id %> --environment=<value> --redeploy-latest',
24+
// eslint-disable-next-line max-len
2425
'<%= config.bin %> <%= command.id %> --config <path/to/launch/config/file> --type <options: GitHub|FileUpload> --name=<value> --environment=<value> --branch=<value> --build-command=<value> --framework=<option> --org=<value> --out-dir=<value>',
26+
// eslint-disable-next-line max-len
2527
'<%= config.bin %> <%= command.id %> --config <path/to/launch/config/file> --type <options: GitHub|FileUpload> --name=<value> --environment=<value> --branch=<value> --build-command=<value> --framework=<option> --org=<value> --out-dir=<value> --server-command=<value>',
28+
// eslint-disable-next-line max-len
2629
'<%= config.bin %> <%= command.id %> --config <path/to/launch/config/file> --type <options: GitHub|FileUpload> --name=<value> --environment=<value> --branch=<value> --build-command=<value> --framework=<option> --org=<value> --out-dir=<value> --variable-type="Import variables from a stack" --alias=<value>',
30+
// eslint-disable-next-line max-len
2731
'<%= config.bin %> <%= command.id %> --config <path/to/launch/config/file> --type <options: GitHub|FileUpload> --name=<value> --environment=<value> --branch=<value> --build-command=<value> --framework=<option> --org=<value> --out-dir=<value> --variable-type="Manually add custom variables to the list" --env-variables="APP_ENV:prod, TEST_ENV:testVal"',
2832
];
2933

@@ -62,6 +66,7 @@ export default class Launch extends BaseCommand<typeof Launch> {
6266
'variable-type': Flags.string({
6367
options: [...config.variablePreparationTypeOptions],
6468
description:
69+
// eslint-disable-next-line max-len
6570
'[optional] Provide a variable type. <options: Import variables from a stack|Manually add custom variables to the list|Import variables from the .env.local file|Skip adding environment variables>',
6671
}),
6772
'show-variables': Flags.boolean({
@@ -79,6 +84,7 @@ export default class Launch extends BaseCommand<typeof Launch> {
7984
}),
8085
'env-variables': Flags.string({
8186
description:
87+
// eslint-disable-next-line max-len
8288
'[optional] Provide the environment variables in the key:value format, separated by comma. For example: APP_ENV:prod, TEST_ENV:testVal.',
8389
}),
8490
'redeploy-latest': Flags.boolean({
@@ -103,7 +109,7 @@ export default class Launch extends BaseCommand<typeof Launch> {
103109
// NOTE pre-check: manage flow and set the provider value
104110
await this.preCheckAndInitConfig();
105111
if (!this.sharedConfig.isExistingProject) {
106-
await this.selectProjectType();
112+
await this.setProviderType();
107113
}
108114
await this.manageFlowBasedOnProvider();
109115
}
@@ -182,4 +188,14 @@ export default class Launch extends BaseCommand<typeof Launch> {
182188

183189
this.sharedConfig.provider = selectedProvider;
184190
}
191+
192+
private async setProviderType(): Promise<void> {
193+
const providerTypeFlag = this.flags.type;
194+
195+
if (providerTypeFlag) {
196+
this.sharedConfig.provider = providerTypeFlag as Providers;
197+
return;
198+
}
199+
await this.selectProjectType();
200+
}
185201
}

0 commit comments

Comments
 (0)