diff --git a/.eslintrc.json b/.eslintrc.json index 1acaea7..86c86f3 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,25 +1,30 @@ { - "env": { - "browser": false, - "commonjs": true, - "es6": true, - "node": true, - "mocha": true - }, + "root": true, + "parser": "@typescript-eslint/parser", "parserOptions": { - "ecmaVersion": 2018, - "ecmaFeatures": { - "jsx": true - }, + "ecmaVersion": 6, "sourceType": "module" }, + "plugins": [ + "@typescript-eslint" + ], "rules": { - "no-const-assign": "warn", - "no-this-before-super": "warn", - "no-undef": "warn", - "no-unreachable": "warn", - "no-unused-vars": "warn", - "constructor-super": "warn", - "valid-typeof": "warn" - } -} + "@typescript-eslint/naming-convention": [ + "warn", + { + "selector": "import", + "format": [ "camelCase", "PascalCase" ] + } + ], + "@typescript-eslint/semi": "warn", + "curly": "warn", + "eqeqeq": "warn", + "no-throw-literal": "warn", + "semi": "off" + }, + "ignorePatterns": [ + "out", + "dist", + "**/*.d.ts" + ] +} \ No newline at end of file diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 871abba..3881337 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -9,3 +9,5 @@ on: jobs: Lint: uses: dennykorsukewitz/dennykorsukewitz/.github/workflows/reusable.lint.yml@dev + with: + VALIDATE_TYPESCRIPT_STANDARD: false diff --git a/.github/workflows/unittest.yml b/.github/workflows/unittest.yml index e166849..a46381d 100644 --- a/.github/workflows/unittest.yml +++ b/.github/workflows/unittest.yml @@ -17,22 +17,21 @@ jobs: # os: [ubuntu-latest, windows-latest, macos-latest] runs-on: ${{ matrix.os }} steps: - - name: Checkout - uses: actions/checkout@v2 - - name: Install Node.js - uses: actions/setup-node@v1 - with: - node-version: 16.x - - run: npm install + - name: Checkout + uses: actions/checkout@v2 + - name: Install Node.js + uses: actions/setup-node@v1 + with: + node-version: 16.x + - run: npm install - # - if: runner.os == 'MacOS' - # run: | - # npm i gulp gulp-cli -g - # gulp + # - if: runner.os == 'MacOS' + # run: | + # npm i gulp gulp-cli -g + # gulp - # - if: runner.os == 'Linux' - # run: xvfb-run -a npm test - - # - if: runner.os != 'Linux' - - run: npm run test + # - if: runner.os == 'Linux' + # run: xvfb-run -a npm test + # - if: runner.os != 'Linux' + - run: npm run test diff --git a/.gitignore b/.gitignore index 1a84bfa..22f6ac2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,12 @@ .env coverage node_modules -.vscode-test/** +.vscode-test* +out/ +dist/ **/*.map +**/*test.js +**/*test.js.map package-lock.json .vscode/settings.json *.vsix diff --git a/.vscode/launch.json b/.vscode/launch.json index 9590299..6c16ed5 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -1,4 +1,4 @@ -// A launch configuration that launches the extension inside a new window +// A launch configuration that compiles the extension and then opens it inside a new window // Use IntelliSense to learn about possible attributes. // Hover to view descriptions of existing attributes. // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 @@ -11,16 +11,38 @@ "request": "launch", "args": [ "--extensionDevelopmentPath=${workspaceFolder}" - ] + ], + "outFiles": [ + "${workspaceFolder}/out/**/*.js" + ], + "preLaunchTask": "npm: compile" }, { - "name": "Run Extension Tests", + "name": "Run Web Extension", "type": "extensionHost", + "debugWebWorkerHost": true, "request": "launch", "args": [ "--extensionDevelopmentPath=${workspaceFolder}", - "--extensionTestsPath=${workspaceFolder}/test/suite/index" - ] + "--extensionDevelopmentKind=web" + ], + "outFiles": [ + "${workspaceFolder}/out/web/**/*.js" + ], + "preLaunchTask": "npm: compile-web" + }, + { + "name": "Run Tests", + "type": "node-terminal", + "request": "launch", + "command": "npm run test", + }, + { + "name": "Debug Current Test File", + "type": "node-terminal", + "request": "launch", + "command": "npm run test -- ${fileBasenameNoExtension}", + "cwd": "${fileDirname}" } ] -} \ No newline at end of file +} diff --git a/.vscodeignore b/.vscodeignore index 6eb7fd0..382da5b 100644 --- a/.vscodeignore +++ b/.vscodeignore @@ -1,15 +1,18 @@ -.vscode/** -.vscode-test/** -test/** -.gitignore -.yarnrc -vsc-extension-quickstart.md -**/jsconfig.json -**/*.map -**/.eslintrc.json - .env +.github +.vscode +.vscode-test* coverage +node_modules +out/ +src/ +dist/test +.gitignore +.eslintrc.json +**/*test.js +**/*test.js.map +tsconfig.json +package-lock.json *.vsix -TODO.md -snippets/_Test_/** \ No newline at end of file +*.ts +TODO.md \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 640720e..31c2cfb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,24 @@ All notable changes to the "GitHubFileFetcher" extension will be documented in this file. +## [Unreleased] + +## [2.0.0] + +### Refactoring + +- Changed source language to TypeScript. +- Added esbuild to get Browser Editor support. +- Refactored code. + +### Added + +The GitHub API is limited to 60 requests per hour for non authorized requests. You can provide your GitHub username and an access token to push this limit to 5000 requests per hour. Please see the [official GitHub doc](https://docs.github.com/en/free-pro-team@latest/rest/rate-limit/rate-limit?apiVersion=2022-11-28) for further information. +You can generate the access token in your [GitHub settings](https://github.com/settings/tokens). + +- Added gitHubFileFetcher.githubUsername setting. +- Added gitHubFileFetcher.githubToken setting. + ## [1.0.2] ### Maintenance diff --git a/README.md b/README.md index de452ee..76f7404 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ | Status | | ------ | -| [![GitHub commits since tagged version](https://img.shields.io/github/commits-since/dennykorsukewitz/VSCode-GitHubFileFetcher/1.0.1/dev)](https://github.com/dennykorsukewitz/VSCode-GitHubFileFetcher/compare/1.0.1...dev) ![GitHub Workflow Lint](https://github.com/dennykorsukewitz/VSCode-GitHubFileFetcher/actions/workflows/lint.yml/badge.svg?branch=dev&style=flat&label=Lint) ![GitHub Workflow Pages](https://github.com/dennykorsukewitz/VSCode-GitHubFileFetcher/actions/workflows/pages.yml/badge.svg?branch=dev&style=flat&label=GitHub%20Pages) | +| [![GitHub commits since tagged version](https://img.shields.io/github/commits-since/dennykorsukewitz/VSCode-GitHubFileFetcher/2.0.0/dev)](https://github.com/dennykorsukewitz/VSCode-GitHubFileFetcher/compare/2.0.0...dev) ![GitHub Workflow Lint](https://github.com/dennykorsukewitz/VSCode-GitHubFileFetcher/actions/workflows/lint.yml/badge.svg?branch=dev&style=flat&label=Lint) ![GitHub Workflow Pages](https://github.com/dennykorsukewitz/VSCode-GitHubFileFetcher/actions/workflows/pages.yml/badge.svg?branch=dev&style=flat&label=GitHub%20Pages) | ## Feature @@ -62,6 +62,11 @@ The following steps are performed one after the other. | - | - | - | | gitHubFileFetcher.informationMessages | Information messages will be displayed. | true | | gitHubFileFetcher.repositories | List of possible GitHub repositories. GitHub {owner}/{repo}. | dennykorsukewitz/VSCode-GitHubFileFetcher | +| gitHubFileFetcher.githubUsername | GitHub username | dennykorsukewitz | +| gitHubFileFetcher.githubToken | GitHub token | 123xxx789 | + +The GitHub API is limited to 60 requests per hour for non authorized requests. You can provide your GitHub username and an access token to push this limit to 5000 requests per hour. Please see the [official GitHub doc](https://docs.github.com/en/free-pro-team@latest/rest/rate-limit/rate-limit?apiVersion=2022-11-28) for further information. +You can generate the access token in your [GitHub settings](https://github.com/settings/tokens). ![Settings](doc/images/settings.png) diff --git a/RELEASE.md b/RELEASE.md index 1209475..618f6f0 100644 --- a/RELEASE.md +++ b/RELEASE.md @@ -1,4 +1,15 @@ -# [1.0.2] +# [2.0.0] -- Tidied code. -- Saves the new manually entered repository globally. +## Refactoring + +- Changed source language to TypeScript. +- Added esbuild to get Browser Editor support. +- Refactored code. + +## Added + +The GitHub API is limited to 60 requests per hour for non authorized requests. You can provide your GitHub username and an access token to push this limit to 5000 requests per hour. Please see the [official GitHub doc](https://docs.github.com/en/free-pro-team@latest/rest/rate-limit/rate-limit?apiVersion=2022-11-28) for further information. +You can generate the access token in your [GitHub settings](https://github.com/settings/tokens). + +- Added gitHubFileFetcher.githubUsername setting. +- Added gitHubFileFetcher.githubToken setting. diff --git a/jsconfig.json b/jsconfig.json deleted file mode 100644 index 96616fe..0000000 --- a/jsconfig.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "compilerOptions": { - "module": "commonjs", - "target": "ES2020", - "checkJs": true, - "lib": [ - "ES2020" - ] - }, - "exclude": [ - "node_modules" - ] -} diff --git a/package.json b/package.json index c4af96c..46c3902 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "GitHubFileFetcher", "displayName": "GitHub File Fetcher", "description": "This extension searches and fetches files from GitHub.", - "version": "1.0.1", + "version": "2.0.0", "publisher": "dennykorsukewitz", "icon": "doc/images/icon.png", "license": "SEE LICENSE IN LICENSE", @@ -33,33 +33,43 @@ "Other" ], "engines": { - "vscode": "^1.74.0" + "vscode": "^1.85.0" }, - "activationEvents": [ - "onCommand:gitHubFileFetcher" - ], - "main": "./src/extension", + "activationEvents": [], + "main": "./dist/extension.js", + "browser": "./dist/extension.js", "scripts": { - "lint": "eslint .", - "lint-fix": "eslint . --fix", - "test": "node ./test/runTest.js" + "vscode:prepublish": "npm run esbuild-base -- --minify", + "esbuild-base": "esbuild ./src/extension.ts --bundle --outfile=dist/extension.js --external:vscode --format=cjs --platform=node", + "esbuild": "npm run esbuild-base -- --sourcemap", + "esbuild-watch": "npm run esbuild-base -- --sourcemap --watch", + "watch": "tsc -watch -p ./", + "compile": "tsc -p ./", + "compile-web": "npm run esbuild-base -- --sourcemap", + "lint": "eslint src --ext ts", + "lint-fix": "eslint src --ext ts --fix", + "pretest": "rm -Rf .vscode-test && npm run compile && npm run lint", + "test": "node ./dist/test/runTest.js", + "open-in-browser": "npm run compile-web && npx @vscode/test-web --extensionDevelopmentPath=." + }, + "dependencies": { + "base64-to-uint8array": "^1.0.0" }, "devDependencies": { + "@types/glob": "^8.1.0", "@types/mocha": "^10.0.1", - "@types/node": "16.x", - "@types/vscode": "^1.74.0", - "@vscode/test-electron": "^2.2.0", - "eslint": "^8.28.0", - "mocha": "^10.1.0", - "typescript": "^4.9.3" - }, - "dependencies": { - "glob": "^8.1.0", - "node-fetch": "^2.6.9", - "path": "^0.12.7" + "@types/node": "^18.19.14", + "@types/vscode": "^1.85.0", + "@typescript-eslint/eslint-plugin": "^6.15.0", + "@typescript-eslint/parser": "^6.20.0", + "esbuild": "^0.20.0", + "eslint": "^8.56.0", + "mocha": "^10.2.0", + "typescript": "^5.3.3" }, - "vsce": { - "dependencies": true + "overrides": { + "minimatch": "5.1.2", + "glob": "8.1.0" }, "contributes": { "commands": [ @@ -80,6 +90,7 @@ "title": "GitHub File Fetcher", "properties": { "gitHubFileFetcher.informationMessages": { + "order": 1, "type": "string", "description": "Information messages will be displayed.", "default": "true", @@ -95,6 +106,7 @@ ] }, "gitHubFileFetcher.repositories": { + "order": 2, "type": "array", "items": { "type": "string" @@ -103,8 +115,18 @@ "default": [ "dennykorsukewitz/VSCode-GitHubFileFetcher" ] + }, + "gitHubFileFetcher.githubUsername": { + "order": 3, + "type": "string", + "description": "The GitHub API is limited to 60 requests per hour for non authorized requests. You can provide your GitHub username and an access token to push this limit to 5000 requests per hour." + }, + "gitHubFileFetcher.githubToken": { + "order": 4, + "type": "string", + "description": "The GitHub API is limited to 60 requests per hour for non authorized requests. You can provide your GitHub username and an access token to push this limit to 5000 requests per hour." } } } } -} \ No newline at end of file +} diff --git a/src/extension.js b/src/extension.ts similarity index 68% rename from src/extension.js rename to src/extension.ts index 632cb07..403a7e4 100644 --- a/src/extension.js +++ b/src/extension.ts @@ -1,13 +1,11 @@ -// The module 'vscode' contains the VS Code extensibility API -// Import the module and reference it with the alias vscode in your code below -const vscode = require('vscode'); -const { default: fetch } = require('node-fetch'); -require('buffer'); +import * as vscode from 'vscode'; + +const toUint8Array = require('base64-to-uint8array'); /** * @param {vscode.ExtensionContext} context */ -function activate(context) { +export function activate(context: vscode.ExtensionContext) { // Use the console to output diagnostic information (console.log) and errors (console.error) // This line of code will only be executed once when your extension is activated @@ -17,14 +15,14 @@ function activate(context) { initGitHubFileFetcher(context); } -function initGitHubFileFetcher(context) { +function initGitHubFileFetcher(context: vscode.ExtensionContext) { const gitHubFileFetcherId = 'gitHubFileFetcher'; context.subscriptions.push(vscode.commands.registerCommand(gitHubFileFetcherId, async () => { // Return if no workspaceFolder is available if (!vscode.workspace.workspaceFolders) { - vscode.window.showWarningMessage(`GitHubFileFetcher: No Workspace Folder is available. Please open a folder before.`) + vscode.window.showWarningMessage(`GitHubFileFetcher: No Workspace Folder is available. Please open a folder before.`); vscode.commands.executeCommand('workbench.action.addRootFolder'); return; } @@ -32,13 +30,26 @@ function initGitHubFileFetcher(context) { // Get Config. let url, response, - json, - newRepoFound = 0, - searchOwnerString = '-- Search Owner --', - searchRepoString = '-- Search Repository --', + json: any, + newRepoFound : Boolean = false, + searchOwnerString : string = '-- Search Owner --', + searchRepoString : string = '-- Search Repository --', + options : any = {}, config = vscode.workspace.getConfiguration('gitHubFileFetcher'), repositories = Object.assign([], config.repositories); + if ( + config.githubUsername + && config.githubToken + && config.githubUsername.length > 0 + && config.githubToken.length > 0 + ){ + let credentials = btoa(`${config.githubUsername}:${config.githubToken}`); + options = { + headers: {'Authorization': `Basic ${credentials}`} + }; + } + if (!repositories.includes(searchRepoString)) { repositories.unshift(searchRepoString); } @@ -48,7 +59,7 @@ function initGitHubFileFetcher(context) { } // Create Owner/Repository Selection. - if (config.informationMessages != 'false') { + if (config.informationMessages !== 'false') { vscode.window.showInformationMessage(`GitHubFileFetcher (1/6): Fetching GitHub repositories.`); } let ownerRepository = await vscode.window.showQuickPick(repositories, { @@ -57,21 +68,21 @@ function initGitHubFileFetcher(context) { canPickMany: false, }); - if (!ownerRepository) return; + if (!ownerRepository) {return;} - let foundRepositories = []; - if (ownerRepository == searchOwnerString || ownerRepository == searchRepoString) { + let foundRepositories: any[] = []; + if (ownerRepository === searchOwnerString || ownerRepository === searchRepoString) { - let message, - value, - placeHolder, - url = `https://api.github.com/search/repositories?q=`; + let message : string = '', + value : string = '', + placeHolder : string = '', + url : string = `https://api.github.com/search/repositories?q=`; - if (ownerRepository == searchOwnerString) { + if (ownerRepository === searchOwnerString) { value = 'Owner'; message = `Enter GitHub ${value}. Example: dennykorsukewitz`; } - else if (ownerRepository == searchRepoString) { + else if (ownerRepository === searchRepoString) { value = 'Repositories'; message = `Enter GitHub ${value} Example: VSCode-GitHubFileFetcher`; } @@ -84,18 +95,18 @@ function initGitHubFileFetcher(context) { prompt: message, }); - if (ownerRepository == searchOwnerString) { + if (ownerRepository === searchOwnerString) { searchString += '/'; } url += `${searchString}`; // Log. - if (config.informationMessages == 'verbose') { + if (config.informationMessages === 'verbose') { vscode.window.showInformationMessage(`GitHubFileFetcher: Fetching ${value} from url: "${url}".`); } - response = await fetch(url); + response = await fetch(url, options); json = await response.json(); Object.keys(json.items).forEach(function (index) { @@ -108,26 +119,26 @@ function initGitHubFileFetcher(context) { placeHolder: 'GitHubFileFetcher: Select GitHub repositories...', canPickMany: false, }); - if (!ownerRepository) return; - newRepoFound = 1; + if (!ownerRepository) {return;} + newRepoFound = true; } } - if (!ownerRepository) return; + if (!ownerRepository) {return;} // Create Branch Selection. url = `https://api.github.com/repos/${ownerRepository}/branches`; - if (config.informationMessages != 'false') { + if (config.informationMessages !== 'false') { let message = `GitHubFileFetcher (2/6): Fetching branches.`; - if (config.informationMessages == 'verbose') { + if (config.informationMessages === 'verbose') { message = `GitHubFileFetcher (2/6): Fetching branches from "${url}".`; } vscode.window.showInformationMessage(message); } - response = await fetch(url); + response = await fetch(url, options); json = await response.json(); - let branches = []; + let branches: string[] = []; if (json.message) { vscode.window.showErrorMessage(`GitHubFileFetcher: ${json.message}.`); @@ -143,30 +154,30 @@ function initGitHubFileFetcher(context) { placeHolder: 'GitHubFileFetcher: Select branch...', canPickMany: false, }); - if (!branch) return; + if (!branch) {return;} // Get all possible files. - url = `https://api.github.com/repos/${ownerRepository}/git/trees/${branch}?recursive=1` + url = `https://api.github.com/repos/${ownerRepository}/git/trees/${branch}?recursive=1`; - if (config.informationMessages != 'false') { + if (config.informationMessages !== 'false') { let message = `GitHubFileFetcher (3/6): Fetching files.`; - if (config.informationMessages == 'verbose') { + if (config.informationMessages === 'verbose') { message = `GitHubFileFetcher (3/6): Fetching files from "${url}".`; } - vscode.window.showInformationMessage(message) + vscode.window.showInformationMessage(message); } - response = await fetch(url); + response = await fetch(url, options); json = await response.json(); - let files = []; + let files : string[] = []; if (json.message) { vscode.window.showErrorMessage(`GitHubFileFetcher: ${json.message}.`); return; } - json.tree.forEach(function (file) { - if (file.type == 'tree') return false; + json.tree.forEach(function (file: any) { + if (file.type === 'tree') {return false;} files.push(file.path); }); @@ -175,15 +186,15 @@ function initGitHubFileFetcher(context) { placeHolder: 'GitHubFileFetcher: Select file...', canPickMany: false, }); - if (!file) return; + if (!file) {return;} - // Get all workspace foldes. - let workspaceFolders = []; + // Get all workspace folders. + let workspaceFolders : string[] = []; vscode.workspace.workspaceFolders.forEach(workspaceFolder => { - workspaceFolders.push(workspaceFolder.uri.path) - }) + workspaceFolders.push(workspaceFolder.uri.path); + }); - if (config.informationMessages != 'false') { + if (config.informationMessages !== 'false') { vscode.window.showInformationMessage(`GitHubFileFetcher (4/6): Fetching destination workspace.`); } @@ -201,29 +212,34 @@ function initGitHubFileFetcher(context) { url = `https://api.github.com/repos/${ownerRepository}/contents/${file}?ref=${branch}`; // Log. - if (config.informationMessages == 'verbose') { + if (config.informationMessages === 'verbose') { vscode.window.showInformationMessage(`GitHubFileFetcher: Fetching file data for file: "${file}" from branch: "${branch}" from url: "${url}".`); } - response = await fetch(url); + response = await fetch(url, options); json = await response.json(); if (json.message) { vscode.window.showErrorMessage(`GitHubFileFetcher: ${json.message}.`); return; } - let content = Buffer.from(json['content'], 'base64').toString('utf-8'); + + const writeBytes = toUint8Array(json.content); + const content = new Uint8Array(writeBytes); + if (!content) { vscode.window.showErrorMessage(`GitHubFileFetcher: No file content exists.`); return; } // Log. - if (config.informationMessages == 'verbose') { + if (config.informationMessages === 'verbose') { vscode.window.showInformationMessage(`GitHubFileFetcher: Decoded file: "${file}" from branch: "${branch}".`); } - const wsEdit = new vscode.WorkspaceEdit(); + if (config.informationMessages !== 'false') { + vscode.window.showInformationMessage(`GitHubFileFetcher (5/6): Enter destination file path.`); + } file = await vscode.window.showInputBox({ title: 'GitHubFileFetcher (5/6)', @@ -235,17 +251,19 @@ function initGitHubFileFetcher(context) { const filePath = vscode.Uri.file(workspaceFolder + '/' + file); if (!filePath) { - vscode.window.showErrorMessage(`GitHubFileFetcher: No filePath exists.`) + vscode.window.showErrorMessage(`GitHubFileFetcher: No filePath exists.`); return; } - wsEdit.createFile(filePath, { ignoreIfExists: true }); - wsEdit.insert(filePath, new vscode.Position(0, 0), content); + try { + await vscode.workspace.fs.writeFile(filePath, content); - // Apply all changes. - vscode.workspace.applyEdit(wsEdit); - if (config.informationMessages != 'false') { - vscode.window.showInformationMessage(`GitHubFileFetcher (6/6): Added file ${filePath.path} `); + if (config.informationMessages !== 'false') { + vscode.window.showInformationMessage(`GitHubFileFetcher (6/6): Added file ${filePath.path}`); + } + } catch (err) { + console.error(err); + vscode.window.showErrorMessage(`GitHubFileFetcher: ${err}.`); } if (newRepoFound) { @@ -255,7 +273,7 @@ function initGitHubFileFetcher(context) { canPickMany: false, }); - if (addNewRepoToConfig == 'yes') { + if (addNewRepoToConfig === 'yes') { let configRepositories = config.repositories; configRepositories.push(ownerRepository); @@ -263,13 +281,8 @@ function initGitHubFileFetcher(context) { await vscode.workspace.getConfiguration().update('gitHubFileFetcher.repositories', configRepositories, true); } } - })) + })); } // This method is called when your extension is deactivated. -function deactivate() { } - -module.exports = { - activate, - deactivate -} +export function deactivate() { } diff --git a/test/runTest.js b/test/runTest.js deleted file mode 100644 index 56d5fab..0000000 --- a/test/runTest.js +++ /dev/null @@ -1,23 +0,0 @@ -const path = require('path'); - -const { runTests } = require('@vscode/test-electron'); - -async function main() { - try { - // The folder containing the Extension Manifest package.json - // Passed to `--extensionDevelopmentPath` - const extensionDevelopmentPath = path.resolve(__dirname, '../'); - - // The path to the extension test script - // Passed to --extensionTestsPath - const extensionTestsPath = path.resolve(__dirname, './suite/index'); - - // Download VS Code, unzip it and run the integration test - await runTests({ extensionDevelopmentPath, extensionTestsPath }); - } catch (err) { - console.error('Failed to run tests'); - process.exit(1); - } -} - -main(); diff --git a/test/suite/extension.test.js b/test/suite/extension.test.js deleted file mode 100644 index abc4623..0000000 --- a/test/suite/extension.test.js +++ /dev/null @@ -1,15 +0,0 @@ -const assert = require('assert'); - -// You can import and use all API from the 'vscode' module -// as well as import your extension to test it -const vscode = require('vscode'); -// const myExtension = require('../extension'); - -suite('Extension Test Suite', () => { - vscode.window.showInformationMessage('Start all tests.'); - - test('Sample test', () => { - assert.strictEqual(-1, [1, 2, 3].indexOf(5)); - assert.strictEqual(-1, [1, 2, 3].indexOf(0)); - }); -}); diff --git a/test/suite/index.js b/test/suite/index.js deleted file mode 100644 index 2808e86..0000000 --- a/test/suite/index.js +++ /dev/null @@ -1,42 +0,0 @@ -const path = require('path'); -const Mocha = require('mocha'); -const glob = require('glob'); - -function run() { - // Create the mocha test - const mocha = new Mocha({ - ui: 'tdd', - color: true - }); - - const testsRoot = path.resolve(__dirname, '..'); - - return new Promise((c, e) => { - glob('**/**.test.js', { cwd: testsRoot }, (err, files) => { - if (err) { - return e(err); - } - - // Add files to the test suite - files.forEach(f => mocha.addFile(path.resolve(testsRoot, f))); - - try { - // Run the mocha test - mocha.run(failures => { - if (failures > 0) { - e(new Error(`${failures} tests failed.`)); - } else { - c(); - } - }); - } catch (err) { - console.error(err); - e(err); - } - }); - }); -} - -module.exports = { - run -}; diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..b185f8b --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,18 @@ +{ + "compilerOptions": { + "module": "CommonJS", + "target": "ES2022", + "outDir": "dist", + "lib": [ + "ES2022" + ], + "sourceMap": true, + "rootDir": "src", + "strict": true + }, + "include": [ + "**/*.ts", + "src/*.ts", + "src/**/*.ts" + ] +} \ No newline at end of file