Skip to content

Commit

Permalink
fix(cli): change in usage data ux and revert usage data disable (#4791)
Browse files Browse the repository at this point in the history
  • Loading branch information
ammarkarachi authored Jul 13, 2020
1 parent 20a8dec commit 28328a3
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 44 deletions.
32 changes: 16 additions & 16 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -769,37 +769,37 @@ jobs:
when: always
- store_artifacts:
path: ../uitest_android_results
api_1-amplify_e2e_tests:
api_2-amplify_e2e_tests:
working_directory: ~/repo
docker: *ref_0
resource_class: large
steps: *ref_1
environment:
TEST_SUITE: src/__tests__/api_1.test.ts
TEST_SUITE: src/__tests__/api_2.test.ts
CLI_REGION: us-east-2
api_2-amplify_e2e_tests:
auth_1-amplify_e2e_tests:
working_directory: ~/repo
docker: *ref_0
resource_class: large
steps: *ref_1
environment:
TEST_SUITE: src/__tests__/api_2.test.ts
TEST_SUITE: src/__tests__/auth_1.test.ts
CLI_REGION: us-west-2
auth_1-amplify_e2e_tests:
auth_2-amplify_e2e_tests:
working_directory: ~/repo
docker: *ref_0
resource_class: large
steps: *ref_1
environment:
TEST_SUITE: src/__tests__/auth_1.test.ts
TEST_SUITE: src/__tests__/auth_2.test.ts
CLI_REGION: eu-west-2
auth_2-amplify_e2e_tests:
api_1-amplify_e2e_tests:
working_directory: ~/repo
docker: *ref_0
resource_class: large
steps: *ref_1
environment:
TEST_SUITE: src/__tests__/auth_2.test.ts
TEST_SUITE: src/__tests__/api_1.test.ts
CLI_REGION: eu-central-1
function_1-amplify_e2e_tests:
working_directory: ~/repo
Expand Down Expand Up @@ -1018,16 +1018,16 @@ workflows:
- amplify_console_integration_tests
- amplify_migration_tests_latest
- amplify_migration_tests_v4
- api_1-amplify_e2e_tests
- api_2-amplify_e2e_tests
- plugin-amplify_e2e_tests
- hostingPROD-amplify_e2e_tests
- api_2-amplify_e2e_tests
- auth_1-amplify_e2e_tests
- datastore-modegen-amplify_e2e_tests
- predictions-amplify_e2e_tests
- auth_1-amplify_e2e_tests
- auth_2-amplify_e2e_tests
- interactions-amplify_e2e_tests
- delete-amplify_e2e_tests
- auth_2-amplify_e2e_tests
- api_1-amplify_e2e_tests
- hosting-amplify_e2e_tests
- storage-amplify_e2e_tests
- function_1-amplify_e2e_tests
Expand All @@ -1044,7 +1044,7 @@ workflows:
- release
- master
- beta
- api_1-amplify_e2e_tests:
- api_2-amplify_e2e_tests:
filters: &ref_2
branches:
only:
Expand All @@ -1060,7 +1060,7 @@ workflows:
filters: *ref_2
requires:
- publish_to_local_registry
- api_2-amplify_e2e_tests:
- auth_1-amplify_e2e_tests:
filters: *ref_2
requires:
- publish_to_local_registry
Expand All @@ -1072,7 +1072,7 @@ workflows:
filters: *ref_2
requires:
- publish_to_local_registry
- auth_1-amplify_e2e_tests:
- auth_2-amplify_e2e_tests:
filters: *ref_2
requires:
- publish_to_local_registry
Expand All @@ -1084,7 +1084,7 @@ workflows:
filters: *ref_2
requires:
- publish_to_local_registry
- auth_2-amplify_e2e_tests:
- api_1-amplify_e2e_tests:
filters: *ref_2
requires:
- publish_to_local_registry
Expand Down
12 changes: 12 additions & 0 deletions packages/amplify-cli/scripts/post-install.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,18 @@ console.log(EOL);
console.log(chalk.green('iOS Getting Started - https://docs.amplify.aws/start/q/integration/ios'));
console.log(EOL);

console.log(
chalk.blue(
`Amplify CLI collects anonymized usage data, which is used to help understand${EOL}\
how to improve the product. If you don't wish to send anonymized Amplify CLI${EOL}\
usage data to AWS, run `,
) +
chalk.blue.italic.bgWhite('amplify configure --usage-data-off ') +
chalk.blue(` to opt-out.${EOL}${EOL}\
Learn more - https://docs.amplify.aws/cli/reference/usage-data`),
);
console.log(EOL);

if (fs.existsSync('../lib/plugin-manager.js')) {
require('../lib/plugin-manager').scan();
}
24 changes: 1 addition & 23 deletions packages/amplify-cli/src/__tests__/context-manager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,11 @@ describe('test attachUsageData', () => {
mockContext.pluginPlatform = new PluginPlatform();
mockContext.pluginPlatform.plugins['core'] = [new PluginInfo('', version, '', new PluginManifest('', ''))];

beforeAll(() => {
process.env.AMPLIFY_CLI_ENABLE_USAGE_DATA = 'true';
});
beforeAll(() => {});
afterEach(() => {
jest.clearAllMocks();
});

afterAll(() => {
delete process.env.AMPLIFY_CLI_ENABLE_USAGE_DATA;
});

it('constructContext', () => {
const context = constructContext(mockContext.pluginPlatform, mockContext.input);
expect(context).toBeDefined();
Expand Down Expand Up @@ -81,20 +75,4 @@ describe('test attachUsageData', () => {
attachUsageData(mockContext);
expect(UsageData.NoUsageData.Instance.init).toBeCalledWith(returnValue.usageDataConfig.installationUuid, version, mockContext.input);
});

it('test with AMPLIFY_CLI_ENABLE_USAGE_DATA set to falsy', () => {
delete process.env.AMPLIFY_CLI_ENABLE_USAGE_DATA;
const returnValue = {
usageDataConfig: {
installationUuid: 'uuid',
isUsageTrackingEnabled: true,
},
setValues: jest.fn(),
};
const mockedInit = appConfig.init as jest.Mock;
mockedInit.mockReturnValue(returnValue);
attachUsageData(mockContext);
expect(UsageData.NoUsageData.Instance.init).toBeCalledWith(returnValue.usageDataConfig.installationUuid, version, mockContext.input);
process.env.AMPLIFY_CLI_ENABLE_USAGE_DATA = 'true';
});
});
12 changes: 8 additions & 4 deletions packages/amplify-cli/src/commands/configure.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,19 @@ import { write } from '../app-config';
module.exports = {
name: 'configure',
run: async context => {
if (!context.parameters.first) {
await configureNewUser.run(context);
}

if (context.parameters.options['usage-data-off']) {
write(context, { usageDataConfig: { isUsageTrackingEnabled: false } });
context.print.success('Usage Data has been turned off');
return;
}
if (context.parameters.options['usage-data-on']) {
write(context, { usageDataConfig: { isUsageTrackingEnabled: true } });
context.print.success('Usage Data has been turned on');
return;
}

if (!context.parameters.first) {
await configureNewUser.run(context);
}

if (context.parameters.first === 'project') {
Expand Down
4 changes: 3 additions & 1 deletion packages/amplify-cli/src/context-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ export function constructContext(pluginPlatform: PluginPlatform, input: Input):
export function attachUsageData(context: Context) {
const { AMPLIFY_CLI_ENABLE_USAGE_DATA } = process.env;
const config = init(context);
const usageTrackingEnabled = !AMPLIFY_CLI_ENABLE_USAGE_DATA ? false : config.usageDataConfig.isUsageTrackingEnabled;
const usageTrackingEnabled = AMPLIFY_CLI_ENABLE_USAGE_DATA
? AMPLIFY_CLI_ENABLE_USAGE_DATA === 'true'
: config.usageDataConfig.isUsageTrackingEnabled;
if (usageTrackingEnabled) {
context.usageData = UsageData.Instance;
} else {
Expand Down

0 comments on commit 28328a3

Please sign in to comment.