Skip to content

Commit

Permalink
House cleaning. Closes: #248, #247 (#250)
Browse files Browse the repository at this point in the history
## 🎯 Aim

The aim is to do some house cleaning 

## ✅ What was done

- [X] added npm-shrinkwrap
- [X] removed no-unused-vars
- [X] added docs for commands
- [X] updated local build pipline to use `ci`

## 🔗 Related issue

Closes: #248, #247
  • Loading branch information
Adam-it committed Jun 11, 2024
1 parent 7cbdd74 commit 46545c6
Show file tree
Hide file tree
Showing 30 changed files with 262 additions and 125 deletions.
1 change: 0 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
"no-dupe-keys": "error",
"no-duplicate-case": "error",
"no-duplicate-imports": "error",
"no-unused-vars": "error",
"curly": "error",
"eqeqeq": "error",
"no-throw-literal": "warn",
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release-local.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
path: vscode-viva

- name: Install the dependencies
run: npm install
run: npm ci
working-directory: vscode-viva

- name: Checkout cli-microsoft365
Expand All @@ -36,7 +36,7 @@ jobs:
dir
- name: Restore dependencies for cli-microsoft365
run: npm install
run: npm i
working-directory: cli-microsoft365

- name: Build cli-microsoft365
Expand Down
19 changes: 3 additions & 16 deletions package-lock.json → npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion src/constants/ComponentTypes.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable no-unused-vars */
// eslint-disable-next-line no-shadow
export enum ComponentType {
adaptiveCardExtension = 'adaptiveCardExtension',
Expand Down
1 change: 0 additions & 1 deletion src/constants/ExtensionTypes.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable no-unused-vars */
// eslint-disable-next-line no-shadow
export enum ExtensionType {
application = 'ApplicationCustomizer',
Expand Down
1 change: 0 additions & 1 deletion src/constants/FrameworkTypes.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable no-unused-vars */
// eslint-disable-next-line no-shadow
export enum FrameworkType {
none = 'none',
Expand Down
1 change: 0 additions & 1 deletion src/constants/NodeVersionManagers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable no-unused-vars */
// eslint-disable-next-line no-shadow
export enum NodeVersionManagers {
nvm = 'nvm',
Expand Down
1 change: 0 additions & 1 deletion src/constants/ProjectFileContent.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable no-unused-vars */
// eslint-disable-next-line no-shadow
export enum ProjectFileContent {
init = 'init-project',
Expand Down
1 change: 0 additions & 1 deletion src/constants/WebViewTypes.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable no-unused-vars */
// eslint-disable-next-line no-shadow
export enum WebViewType {
samplesGallery = 'samplesGallery',
Expand Down
1 change: 0 additions & 1 deletion src/constants/WorkflowTypes.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable no-unused-vars */
// eslint-disable-next-line no-shadow
export enum WorkflowType {
gitHub = 'GitHub',
Expand Down
49 changes: 25 additions & 24 deletions src/providers/AuthProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ export class M365AuthenticationSession implements AuthenticationSession {
// Required for the session, but not for M365 CLI
public readonly accessToken: string = '';

// eslint-disable-next-line no-unused-vars
constructor(public readonly account: AuthenticationSessionAccountInformation) { }
}

Expand All @@ -31,7 +30,7 @@ export class AuthProvider implements AuthenticationProvider, Disposable {
private initializedDisposable: Disposable | undefined;

/**
* Register the authentication provider
* Registers the authentication provider and associated commands.
*/
public static register() {
const ext = Extension.getInstance();
Expand All @@ -56,60 +55,59 @@ export class AuthProvider implements AuthenticationProvider, Disposable {
}

/**
* Returns the auth instance
* @returns
* Returns the singleton instance of the AuthProvider class.
* @returns The singleton instance of the AuthProvider class.
*/
public static getInstance(): AuthProvider {
return AuthProvider.instance;
}

/**
* Verify if the user is logged in
* Verifies the authentication status.
* Calls the `login` method of the `AuthProvider` class with `false` as the argument.
*/
public static verify() {
AuthProvider.login(false);
}

/**
* Login to M365
* @param createIfNone
* @returns
* Logs in the user.
* @param createIfNone - A boolean indicating whether to create a new session if none exists.
*/
public static async login(createIfNone: boolean = true) {
await authentication.getSession(AuthProvider.id, [], { createIfNone });
}

/**
* Logout from M365
* Logs out the user by removing the session.
*/
public static async logout() {
AuthProvider.instance.removeSession('');
}

/**
* Event emitter for session changes
* Event that fires when the authentication sessions change.
*/
public get onDidChangeSessions(): Event<AuthenticationProviderAuthenticationSessionsChangeEvent> {
return this.onDidChangeEventEmit.event;
}

/**
* Get the current session
* @param scopes
* @returns
* Retrieves the authentication sessions for the specified scopes.
* If no scopes are provided, retrieves all authentication sessions.
* @param scopes - The scopes for which to retrieve authentication sessions.
* @returns A promise that resolves to an array of authentication sessions.
*/
// eslint-disable-next-line no-unused-vars
public async getSessions(scopes?: readonly string[]): Promise<readonly AuthenticationSession[]> {
const account = await this.getAccount();
return account ? [account] : [];
}

/**
* Create a new session
* @param _scopes
* @returns
* Creates a session for authentication.
* @param _scopes - The scopes for the session.
* @returns A promise that resolves to an AuthenticationSession.
*/
// eslint-disable-next-line no-unused-vars
public async createSession(_scopes: string[]): Promise<AuthenticationSession> {
return new Promise((resolve) => {
window.withProgress({
Expand Down Expand Up @@ -157,11 +155,10 @@ export class AuthProvider implements AuthenticationProvider, Disposable {
}

/**
* Remove a session
* @param _sessionId
* @returns
* Removes a session with the specified session ID.
* @param _sessionId - The ID of the session to remove.
* @returns A Promise that resolves when the session is successfully removed.
*/
// eslint-disable-next-line no-unused-vars
public async removeSession(_sessionId: string): Promise<void> {
const output = await executeCommand('logout', { output: 'text' });

Expand All @@ -183,8 +180,12 @@ export class AuthProvider implements AuthenticationProvider, Disposable {
}

/**
* Get the account that is currently signed in
* @returns
* Retrieves the M365 authentication session for the current account.
* If the account is not available, it tries to fetch the account information using the 'status' command.
* If successful, it returns a new M365AuthenticationSession object with the account details.
* If unsuccessful, it logs an error message and returns undefined.
* If the account is already available, it returns a new M365AuthenticationSession object with the account details.
* @returns A Promise that resolves to an M365AuthenticationSession object or undefined.
*/
public async getAccount(): Promise<M365AuthenticationSession | undefined> {
if (!EnvironmentInformation.account) {
Expand Down
5 changes: 4 additions & 1 deletion src/services/AdaptiveCardCheck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ import { parseYoRc } from '../utils/parseYoRc';


export class AdaptiveCardCheck {

/**
* Check if yo-rc has ACE component
* Validates the ACE (Adaptive Card Extension) component.
* If the required extension is not installed, prompts the user to install it.
* @returns A promise that resolves when the validation is complete.
*/
public static async validateACEComponent() {
try {
Expand Down
5 changes: 5 additions & 0 deletions src/services/CertificateActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ import { Uri, workspace } from 'vscode';

export class CertificateActions {

/**
* Generates a certificate and saves it as a PFX file in the workspace.
* @param certPassword - The password to protect the generated certificate.
* @returns A base64-encoded string representation of the generated PFX file.
*/
public static async generateCertificate(certPassword: string): Promise<string> {
try {
const keys = pki.rsa.generateKeyPair(2048);
Expand Down
Loading

0 comments on commit 46545c6

Please sign in to comment.