Skip to content

Commit

Permalink
feat: 🔧 add extension configuration and settings validation
Browse files Browse the repository at this point in the history
  • Loading branch information
ManuelGil committed Feb 4, 2024
1 parent 0880b5b commit 195f40f
Show file tree
Hide file tree
Showing 5 changed files with 126 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Add number helper to format numbers
- Add security helper to escape HTML and JavaScript
- Add text helper to format strings
- Add `@types/minimatch` to `devDependencies` to fix TypeScript error
- Add definition of constants for the extension
- Add class configuration to define the extension settings
- Add JSON schema for settings validation in `package.json` and `settings.schema.json`

### Changed

Expand Down
20 changes: 19 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,24 @@
"contributes": {
"configuration": {
"title": "Extension name",
"properties": {}
"properties": {
"extension-starter-kit.files.include": {
"type": "array",
"default": [
"**/*"
],
"scope": "resource",
"description": "Glob patterns to include in the package. The default is all files."
},
"extension-starter-kit.files.exclude": {
"type": "array",
"default": [
"**/node_modules/**"
],
"scope": "resource",
"description": "Glob patterns to exclude from the package. The default is node_modules."
}
}
},
"commands": [
{
Expand Down Expand Up @@ -99,6 +116,7 @@
"@commitlint/cli": "^18.6.0",
"@commitlint/config-conventional": "^18.6.0",
"@types/glob": "^8.1.0",
"@types/minimatch": "^3.0.3",
"@types/mocha": "^10.0.6",
"@types/node": "^20.11.16",
"@types/vscode": "^1.86.0",
Expand Down
19 changes: 18 additions & 1 deletion schemas/config.schema.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {}
"properties": {
"extension-starter-kit.files.includes": {
"type": "array",
"default": [
"**/*"
],
"scope": "resource",
"description": "Glob patterns to include in the package. The default is all files."
},
"extension-starter-kit.files.excludes": {
"type": "array",
"default": [
"**/node_modules/**"
],
"scope": "resource",
"description": "Glob patterns to exclude from the package. The default is node_modules."
}
}
}
51 changes: 51 additions & 0 deletions src/app/config/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { WorkspaceConfiguration } from 'vscode';
import { EXCLUDE, INCLUDE } from './constants';

/**
* The Config class.
*
* @class
* @classdesc The class that represents the configuration of the extension.
* @export
* @public
* @property {string[]} include - The files to include
* @property {string[]} exclude - The files to exclude
* @example
* const config = new Config(workspace.getConfiguration());
* console.log(config.include);
* console.log(config.exclude);
*/
export class Config {
// Public properties
/**
* The files to include.
* @type {string[]}
* @public
* @memberof Config
* @example
* const config = new Config(workspace.getConfiguration());
* console.log(config.include);
*/
include: string[];

/**
* The files to exclude.
* @type {string[]}
* @public
* @memberof Config
* @example
* const config = new Config(workspace.getConfiguration());
* console.log(config.exclude);
*/
exclude: string[];

/**
* Constructor for the Config class.
*
* @param {WorkspaceConfiguration} config - The workspace configuration
*/
constructor(config: WorkspaceConfiguration) {
this.include = config.get<string[]>('files.include') ?? INCLUDE;
this.exclude = config.get<string[]>('files.exclude') ?? EXCLUDE;
}
}
34 changes: 34 additions & 0 deletions src/app/config/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* EXTENSION_ID: The unique identifier of the extension.
* @type {string}
* @public
* @memberof Constants
* @example
* console.log(EXTENSION_ID);
*
* @returns {string} - The unique identifier of the extension
*/
export const EXTENSION_ID = 'extension-starter-kit';

/**
* INCLUDE: The files to include.
* @type {string[]}
* @public
* @memberof Constants
* @example
* console.log(INCLUDE);
*
* @returns {string[]} - The files to include
*/
export const INCLUDE = ['**/*'];
/**
* EXCLUDE: The files to exclude.
* @type {string[]}
* @public
* @memberof Constants
* @example
* console.log(EXCLUDE);
*
* @returns {string[]} - The files to exclude
*/
export const EXCLUDE = ['**/node_modules/**'];

0 comments on commit 195f40f

Please sign in to comment.