Skip to content

Commit

Permalink
feat(cli): usage measurement (#3641)
Browse files Browse the repository at this point in the history
  • Loading branch information
ammarkarachi authored Jun 25, 2020
1 parent 3afb335 commit 30a7fe7
Show file tree
Hide file tree
Showing 70 changed files with 695 additions and 189 deletions.
1 change: 0 additions & 1 deletion .circleci/config.base.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ version: 2.1
machine:
environment:
PATH: '${PATH}:${HOME}/${CIRCLE_PROJECT_REPONAME}/node_modules/.bin'

defaults: &defaults
working_directory: ~/repo
docker:
Expand Down
1 change: 1 addition & 0 deletions packages/amplify-appsync-simulator/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export class AmplifyAppSyncSimulator {
} catch (e) {
console.log('Could not start AppSync mock endpoint');
console.log(e);
throw e;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,14 @@ module.exports = {
print.success('Some next steps:');
print.info('"amplify push" builds all of your local backend resources and provisions them in the cloud');
print.info(
'"amplify publish" builds all your local backend and front-end resources (if you have hosting category added) and provisions them in the cloud'
'"amplify publish" builds all your local backend and front-end resources (if you have hosting category added) and provisions them in the cloud',
);
print.info('');
})
.catch(err => {
context.print.info(err.stack);
context.print.error('There was an error adding the analytics resource');
context.telemetry.emitError(err);
});
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ module.exports = {
return amplify.pushResources(context, category, resourceName).catch(err => {
context.print.info(err.stack);
context.print.error('An error occurred when pushing the analytics resource');
context.telemetry.emitError(err);
});
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ module.exports = {
return amplify.removeResource(context, category, resourceName).catch(err => {
context.print.info(err.stack);
context.print.error('An error occurred when removing the analytics resource');
context.telemetry.emitError(err);
});
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ module.exports = {
.catch(err => {
context.print.info(err.stack);
context.print.error(`There was an error updating the ${category} resource`);
context.telemetry.emitError(err);
});
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ module.exports = {
answers.secretStoreArn,
answers.dbClusterArn,
answers.databaseName,
AWS
AWS,
);

/**
Expand Down Expand Up @@ -148,13 +148,14 @@ module.exports = {
print.success('Some next steps:');
print.info('"amplify push" will build all your local backend resources and provision it in the cloud');
print.info(
'"amplify publish" will build all your local backend and frontend resources (if you have hosting category added) and provision it in the cloud'
'"amplify publish" will build all your local backend and frontend resources (if you have hosting category added) and provision it in the cloud',
);
print.info('');
})
.catch(err => {
context.print.info(err.stack);
context.print.error('There was an error adding the datasource');
context.telemetry.emitError(err);
});
},
};
Expand Down
3 changes: 2 additions & 1 deletion packages/amplify-category-api/commands/api/add.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,14 @@ module.exports = {
print.success('Some next steps:');
print.info('"amplify push" will build all your local backend resources and provision it in the cloud');
print.info(
'"amplify publish" will build all your local backend and frontend resources (if you have hosting category added) and provision it in the cloud'
'"amplify publish" will build all your local backend and frontend resources (if you have hosting category added) and provision it in the cloud',
);
print.info('');
})
.catch(err => {
context.print.info(err.stack);
context.print.error('There was an error adding the API resource');
context.telemetry.emitError(err);
});
},
};
1 change: 1 addition & 0 deletions packages/amplify-category-api/commands/api/console.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ module.exports = {
.catch(err => {
context.print.error('Error opening console.');
context.print.info(err.message);
context.telemetry.emitError(err);
});
},
};
1 change: 1 addition & 0 deletions packages/amplify-category-api/commands/api/gql-compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ module.exports = {
});
} catch (err) {
context.print.error(err.toString());
context.telemetry.emitError(err);
}
},
};
1 change: 1 addition & 0 deletions packages/amplify-category-api/commands/api/push.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ module.exports = {
return amplify.pushResources(context, category, resourceName).catch(err => {
context.print.error('There was an error pushing the API resource');
context.print.error(err.toString());
context.telemetry.emitError(err);
});
},
};
1 change: 1 addition & 0 deletions packages/amplify-category-api/commands/api/remove.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ module.exports = {
.catch(err => {
context.print.info(err.stack);
context.print.error('There was an error removing the api resource');
context.telemetry.emitError(err);
});
},
};
1 change: 1 addition & 0 deletions packages/amplify-category-api/commands/api/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ module.exports = {
.catch(err => {
context.print.error(err.message);
console.log(err.stack);
context.telemetry.emitError(err);
});
},
};
1 change: 1 addition & 0 deletions packages/amplify-category-auth/commands/auth/enable.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ module.exports = {
.catch(err => {
context.print.info(err.stack);
context.print.error('There was an error adding the auth resource');
context.telemetry.emitError(err);
});
},
};
1 change: 1 addition & 0 deletions packages/amplify-category-auth/commands/auth/push.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ module.exports = {
.catch(err => {
context.print.info(err.stack);
context.print.error('There was an error pushing the auth resource');
context.telemetry.emitError(err);
});
},
};
1 change: 1 addition & 0 deletions packages/amplify-category-auth/commands/auth/remove.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ module.exports = {
return amplify.removeResource(context, category, resourceName).catch(err => {
context.print.info(err.stack);
context.print.error('There was an error removing the auth resource');
context.telemetry.emitError(err);
});
},
};
1 change: 1 addition & 0 deletions packages/amplify-category-auth/commands/auth/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ module.exports = {
.catch(err => {
context.print.info(err.stack);
context.print.error('There was an error adding the auth resource');
context.telemetry.emitError(err);
});
},
};
2 changes: 2 additions & 0 deletions packages/amplify-category-auth/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ async function add(context) {
.catch(err => {
context.print.info(err.stack);
context.print.error('There was an error adding the auth resource');
context.telemetry.emitError(err);
});
}

Expand Down Expand Up @@ -261,6 +262,7 @@ async function console(context) {
.catch(err => {
context.print.info(err.stack);
context.print.error('There was an error trying to open the auth web console.');
throw err;
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ async function uploadFile(s3Client, hostingBucketName, filePath, file) {
.promise()
.catch(e => {
console.log('e', e);
throw e;
});

return data;
Expand Down
3 changes: 3 additions & 0 deletions packages/amplify-category-auth/tests/commands/enable.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ describe('auth enable: ', () => {
info: jest.fn(),
error: jest.fn(),
},
telemetry: {
emitError: jest.fn(),
},
};

it('enable run method should exist', () => {
Expand Down
3 changes: 3 additions & 0 deletions packages/amplify-category-auth/tests/commands/update.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ describe('auth update: ', () => {
info: jest.fn(),
error: jest.fn(),
},
telemetry: {
emitError: jest.fn(),
},
};
const dependencies = ['analytics', 'api', 'function', 'storage'];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ module.exports = {
.catch(err => {
context.print.info(err.stack);
context.print.error('There was an error adding the function resource');
context.telemetry.emitError(err);
});
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ module.exports = {
return amplify.buildResources(context, categoryName, resourceName).catch(err => {
context.print.info(err.stack);
context.print.error('There was an error building the function resources');
context.telemetry.emitError(err);
});
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ module.exports = {
return amplify.pushResources(context, categoryName, resourceName).catch(err => {
context.print.info(err.stack);
context.print.error('An error occurred when pushing the function resource');
context.telemetry.emitError(err);
});
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ module.exports = {
return amplify.removeResource(context, categoryName, resourceName).catch(err => {
context.print.info(err.stack);
context.print.error('An error occurred when removing the function resource');
context.telemetry.emitError(err);
});
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ module.exports = {
.then(() => context.print.success('Successfully updated resource'))
.catch(err => {
context.print.error(err.stack);
context.telemetry.emitError(err);
});
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ export async function askExecRolePermissionsQuestions(context, allDefaultValues,
} catch (e) {
context.print.warning(`Policies cannot be added for ${category}`);
context.print.info(e.stack);
context.telemetry.emitError(e);
}
}

Expand Down
1 change: 1 addition & 0 deletions packages/amplify-category-hosting/commands/hosting/push.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ module.exports = {
return amplify.pushResources(context, category, resourceName).catch(err => {
context.print.info(err.stack);
context.print.error('There was an error pushing the hosting resource');
context.telemetry.emitError(err);
});
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ module.exports = {
} catch (err) {
context.print.info(err.stack);
context.print.error('There was an error removing the hosting resource');
context.telemetry.emitError(err);
}
} else {
process.exit(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ module.exports = {
.catch(err => {
context.print.info(err.stack);
context.print.error('There was an error adding the interactions resource');
context.telemetry.emitError(err);
});
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ module.exports = {
return amplify.pushResources(context, category, resourceName).catch(err => {
context.print.info(err.stack);
context.print.error('There was an error pushing the interactions resource');
context.telemetry.emitError(err);
});
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ module.exports = {
return amplify.removeResource(context, category, resourceName).catch(err => {
context.print.info(err.stack);
context.print.error('There was an error removing the interactions resource');
context.telemetry.emitError(err);
});
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ module.exports = {
.catch(err => {
context.print.info(err.stack);
context.print.error('There was an error updating the interactions resource');
context.telemetry.emitError(err);
});
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,13 @@ module.exports = {
print.success('Some next steps:');
print.info('"amplify push" builds all of your local backend resources and provisions them in the cloud');
print.info(
'"amplify publish" builds all of your local backend and front-end resources (if you added hosting category) and provisions them in the cloud'
'"amplify publish" builds all of your local backend and front-end resources (if you added hosting category) and provisions them in the cloud',
);
print.info('');
})
.catch(err => {
context.print.info(err.stack);
context.print.error('An error occurred when adding the predictions resource');
context.telemetry.emitError(err);
}),
};
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ module.exports = {
.catch(err => {
context.print.info(err.stack);
context.print.error('An error occurred when removing the predictions resource');
context.telemetry.emitError(err);
});
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@ module.exports = {
.catch(err => {
context.print.info(err.stack);
context.print.error('An error occurred when updating predictions resource!');
context.telemetry.emitError(err);
}),
};
1 change: 1 addition & 0 deletions packages/amplify-category-predictions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ async function console(context) {
.catch(err => {
context.print.error('Error opening console.');
context.print.info(err.message);
context.telemetry.emitError(err);
});
}

Expand Down
3 changes: 2 additions & 1 deletion packages/amplify-category-storage/commands/storage/add.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,14 @@ module.exports = {
print.success('Some next steps:');
print.info('"amplify push" builds all of your local backend resources and provisions them in the cloud');
print.info(
'"amplify publish" builds all of your local backend and front-end resources (if you added hosting category) and provisions them in the cloud'
'"amplify publish" builds all of your local backend and front-end resources (if you added hosting category) and provisions them in the cloud',
);
print.info('');
})
.catch(err => {
context.print.info(err.stack);
context.print.error('An error occurred when adding the storage resource');
context.telemetry.emitError(err);
});
},
};
1 change: 1 addition & 0 deletions packages/amplify-category-storage/commands/storage/push.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ module.exports = {
return amplify.pushResources(context, category, resourceName).catch(err => {
context.print.info(err.stack);
context.print.error('An error occurred when pushing the storage resource');
context.telemetry.emitError(err);
});
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ module.exports = {
return amplify.removeResource(context, category, resourceName).catch(err => {
context.print.info(err.stack);
context.print.error('An error occurred when removing the storage resource');
context.telemetry.emitError(err);
});
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ module.exports = {
.catch(err => {
context.print.info(err.stack);
context.print.error('An error occurred when updating the storage resource');
context.telemetry.emitError(err);
});
},
};
1 change: 1 addition & 0 deletions packages/amplify-category-xr/commands/xr/push.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ module.exports = {
return context.amplify.pushResources(context, category, resourceName).catch(err => {
context.print.info(err.stack);
context.print.error('There was an error pushing the XR resource');
context.telemetry.emitError(err);
});
},
};
Loading

0 comments on commit 30a7fe7

Please sign in to comment.