diff --git a/nf-scil-extensions/test-data-treeview/.eslintrc.json b/nf-scil-extensions/test-data-treeview/.eslintrc.json index 86c86f37..10565a2e 100644 --- a/nf-scil-extensions/test-data-treeview/.eslintrc.json +++ b/nf-scil-extensions/test-data-treeview/.eslintrc.json @@ -5,15 +5,13 @@ "ecmaVersion": 6, "sourceType": "module" }, - "plugins": [ - "@typescript-eslint" - ], + "plugins": ["@typescript-eslint"], "rules": { "@typescript-eslint/naming-convention": [ "warn", { "selector": "import", - "format": [ "camelCase", "PascalCase" ] + "format": ["camelCase", "PascalCase"] } ], "@typescript-eslint/semi": "warn", @@ -22,9 +20,5 @@ "no-throw-literal": "warn", "semi": "off" }, - "ignorePatterns": [ - "out", - "dist", - "**/*.d.ts" - ] -} \ No newline at end of file + "ignorePatterns": ["out", "dist", "**/*.d.ts"] +} diff --git a/nf-scil-extensions/test-data-treeview/.vscode-test.mjs b/nf-scil-extensions/test-data-treeview/.vscode-test.mjs index b62ba25f..36a79aef 100644 --- a/nf-scil-extensions/test-data-treeview/.vscode-test.mjs +++ b/nf-scil-extensions/test-data-treeview/.vscode-test.mjs @@ -1,5 +1,5 @@ -import { defineConfig } from '@vscode/test-cli'; +import { defineConfig } from "@vscode/test-cli"; export default defineConfig({ - files: 'out/test/**/*.test.js', + files: "out/test/**/*.test.js", }); diff --git a/nf-scil-extensions/test-data-treeview/CHANGELOG.md b/nf-scil-extensions/test-data-treeview/CHANGELOG.md index c21eaea9..df400792 100644 --- a/nf-scil-extensions/test-data-treeview/CHANGELOG.md +++ b/nf-scil-extensions/test-data-treeview/CHANGELOG.md @@ -6,4 +6,4 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how ## [Unreleased] -- Initial release \ No newline at end of file +- Initial release diff --git a/nf-scil-extensions/test-data-treeview/README.md b/nf-scil-extensions/test-data-treeview/README.md index d2dc7cee..d6a9faa9 100644 --- a/nf-scil-extensions/test-data-treeview/README.md +++ b/nf-scil-extensions/test-data-treeview/README.md @@ -7,4 +7,3 @@ This extension is designed to provide a treeview of test data files for **nf-sci No release notes yet. --- - diff --git a/nf-scil-extensions/test-data-treeview/esbuild.js b/nf-scil-extensions/test-data-treeview/esbuild.js index cc2be598..95ab0413 100644 --- a/nf-scil-extensions/test-data-treeview/esbuild.js +++ b/nf-scil-extensions/test-data-treeview/esbuild.js @@ -1,56 +1,54 @@ const esbuild = require("esbuild"); -const production = process.argv.includes('--production'); -const watch = process.argv.includes('--watch'); +const production = process.argv.includes("--production"); +const watch = process.argv.includes("--watch"); /** * @type {import('esbuild').Plugin} */ const esbuildProblemMatcherPlugin = { - name: 'esbuild-problem-matcher', + name: "esbuild-problem-matcher", - setup(build) { - build.onStart(() => { - console.log('[watch] build started'); - }); - build.onEnd((result) => { - result.errors.forEach(({ text, location }) => { - console.error(`✘ [ERROR] ${text}`); - console.error(` ${location.file}:${location.line}:${location.column}:`); - }); - console.log('[watch] build finished'); - }); - }, + setup(build) { + build.onStart(() => { + console.log("[watch] build started"); + }); + build.onEnd((result) => { + result.errors.forEach(({ text, location }) => { + console.error(`✘ [ERROR] ${text}`); + console.error(` ${location.file}:${location.line}:${location.column}:`); + }); + console.log("[watch] build finished"); + }); + }, }; async function main() { - const ctx = await esbuild.context({ - entryPoints: [ - 'src/extension.ts' - ], - bundle: true, - format: 'cjs', - minify: production, - sourcemap: !production, - sourcesContent: false, - platform: 'node', - outfile: 'dist/extension.js', - external: ['vscode'], - logLevel: 'silent', - plugins: [ - /* add to the end of plugins array */ - esbuildProblemMatcherPlugin, - ], - }); - if (watch) { - await ctx.watch(); - } else { - await ctx.rebuild(); - await ctx.dispose(); - } + const ctx = await esbuild.context({ + entryPoints: ["src/extension.ts"], + bundle: true, + format: "cjs", + minify: production, + sourcemap: !production, + sourcesContent: false, + platform: "node", + outfile: "dist/extension.js", + external: ["vscode"], + logLevel: "silent", + plugins: [ + /* add to the end of plugins array */ + esbuildProblemMatcherPlugin, + ], + }); + if (watch) { + await ctx.watch(); + } else { + await ctx.rebuild(); + await ctx.dispose(); + } } -main().catch(e => { - console.error(e); - process.exit(1); +main().catch((e) => { + console.error(e); + process.exit(1); }); diff --git a/nf-scil-extensions/test-data-treeview/src/extension.ts b/nf-scil-extensions/test-data-treeview/src/extension.ts index 8e08cbe8..307b36c8 100644 --- a/nf-scil-extensions/test-data-treeview/src/extension.ts +++ b/nf-scil-extensions/test-data-treeview/src/extension.ts @@ -1,8 +1,8 @@ -'use strict'; +"use strict"; -import * as vscode from 'vscode'; +import * as vscode from "vscode"; -import { TestDataProvider } from './nfscilTestData'; +import { TestDataProvider } from "./nfscilTestData"; export function activate(context: vscode.ExtensionContext) { const rootPath = @@ -14,42 +14,34 @@ export function activate(context: vscode.ExtensionContext) { const testDataProvider = new TestDataProvider(rootPath, storagePath); - vscode.window.registerTreeDataProvider('nfscilTestData', testDataProvider); - - vscode.commands.registerCommand('nfscilTestData.refreshEntry', () => - testDataProvider.refresh() - ); - vscode.commands.registerCommand('nfscilTestData.clearCache', () => - testDataProvider.clear(false) - ); - vscode.commands.registerCommand('nfscilTestData.loadListing', () => { - vscode.window.showOpenDialog({ - canSelectFiles: true, - canSelectFolders: false, - canSelectMany: false, - openLabel: 'Load package listing', - filters: { - 'JSON files': ['json'] - }, - defaultUri: rootPath ? vscode.Uri.file(rootPath) : undefined - }).then((uri) => { - if (uri && uri[0]) { - testDataProvider.loadListing(uri[0].fsPath); - } - else { - vscode.window.showErrorMessage('No file selected'); - } - }); + vscode.window.registerTreeDataProvider("nfscilTestData", testDataProvider); + + vscode.commands.registerCommand("nfscilTestData.refreshEntry", () => testDataProvider.refresh()); + vscode.commands.registerCommand("nfscilTestData.clearCache", () => testDataProvider.clear(false)); + vscode.commands.registerCommand("nfscilTestData.loadListing", () => { + vscode.window + .showOpenDialog({ + canSelectFiles: true, + canSelectFolders: false, + canSelectMany: false, + openLabel: "Load package listing", + filters: { + "JSON files": ["json"], + }, + defaultUri: rootPath ? vscode.Uri.file(rootPath) : undefined, + }) + .then((uri) => { + if (uri && uri[0]) { + testDataProvider.loadListing(uri[0].fsPath); + } else { + vscode.window.showErrorMessage("No file selected"); + } + }); }); - vscode.commands.registerCommand('nfscilTestData.forceDownloadListing', () => - testDataProvider.forceDownloadListing() + vscode.commands.registerCommand("nfscilTestData.forceDownloadListing", () => + testDataProvider.forceDownloadListing(), ); - vscode.commands.registerCommand('nfscilTestData.openInEditor', (element) => - testDataProvider.openInEditor(element) - ); - vscode.commands.registerCommand('nfscilTestData.saveAs', (element) => - testDataProvider.saveAs(element) - ); + vscode.commands.registerCommand("nfscilTestData.openInEditor", (element) => testDataProvider.openInEditor(element)); + vscode.commands.registerCommand("nfscilTestData.saveAs", (element) => testDataProvider.saveAs(element)); } - diff --git a/nf-scil-extensions/test-data-treeview/src/nfscilTestData.ts b/nf-scil-extensions/test-data-treeview/src/nfscilTestData.ts index dcbdca39..8a23e630 100644 --- a/nf-scil-extensions/test-data-treeview/src/nfscilTestData.ts +++ b/nf-scil-extensions/test-data-treeview/src/nfscilTestData.ts @@ -1,10 +1,9 @@ -import * as vscode from 'vscode'; -import * as fs from 'fs'; -import * as https from 'https'; -import * as fpath from 'path'; -import * as url from 'url'; -import AdmZip = require('adm-zip'); - +import * as vscode from "vscode"; +import * as fs from "fs"; +import * as https from "https"; +import * as fpath from "path"; +import * as url from "url"; +import AdmZip = require("adm-zip"); const NFSCIL_REPOSITORY = "AlexVCaron/nf-scil"; const NFSCIL_REF_BRANCH = "test/data"; @@ -13,18 +12,18 @@ const TEST_DATA_REPOSITORY = "scil_test_data/dvc-store/files/md5"; const NFSCIL_RAW_URL = url.format({ protocol: "https", hostname: "raw.githubusercontent.com", - pathname: NFSCIL_REPOSITORY + pathname: NFSCIL_REPOSITORY, }); const TEST_DATA_URL = url.format({ protocol: "https", hostname: "scil.usherbrooke.ca", - pathname: TEST_DATA_REPOSITORY + pathname: TEST_DATA_REPOSITORY, }); - export class TestDataProvider implements vscode.TreeDataProvider { - - private _onDidChangeTreeData: vscode.EventEmitter = new vscode.EventEmitter(); + private _onDidChangeTreeData: vscode.EventEmitter = new vscode.EventEmitter< + TestDataItem | undefined | void + >(); readonly onDidChangeTreeData: vscode.Event = this._onDidChangeTreeData.event; temp: string; @@ -35,7 +34,10 @@ export class TestDataProvider implements vscode.TreeDataProvider { listing: string = ""; pullOnline: boolean = true; - constructor(private workspaceRoot: string | undefined, storagePath: string) { + constructor( + private workspaceRoot: string | undefined, + storagePath: string, + ) { // Get temporary directory to store transitory files this.workspaceRoot = workspaceRoot; this.storagePath = storagePath; @@ -89,7 +91,7 @@ export class TestDataProvider implements vscode.TreeDataProvider { loadListing(listing: string) { if (!fs.existsSync(listing)) { - vscode.window.showErrorMessage('Listing does not exist'); + vscode.window.showErrorMessage("Listing does not exist"); return; } @@ -119,72 +121,67 @@ export class TestDataProvider implements vscode.TreeDataProvider { } const file = fs.createWriteStream(target); - console.log('Downloading file from: ' + source); + console.log("Downloading file from: " + source); return new Promise((resolve, reject) => { - const request = https.get(source, function(response) { - response.on('error', (err) => { + const request = https + .get(source, function (response) { + response + .on("error", (err) => { + fs.unlink(target, () => { + console.log("Failed to download file: " + err.message); + vscode.window.showErrorMessage("Failed to download file: " + source); + }); + reject(err); + }) + .pipe(file); + file.on("finish", () => { + file.close(() => { + console.log("Downloaded file to: " + target); + }); + resolve(); + }); + }) + .on("error", (err) => { fs.unlink(target, () => { - console.log('Failed to download file: ' + err.message); - vscode.window.showErrorMessage('Failed to download file: ' + source); + console.log("Failed to download file: " + err.message); + vscode.window.showErrorMessage("Failed to download file: " + source); }); reject(err); - }).pipe(file); - file.on('finish', () => { - file.close(() => { - console.log('Downloaded file to: ' + target); - }); - resolve(); - }); - }).on('error', (err) => { - fs.unlink(target, () => { - console.log('Failed to download file: ' + err.message); - vscode.window.showErrorMessage('Failed to download file: ' + source); }); - reject(err); - }); request.end(); }); } loadTestDataListing(listing?: string): Thenable | void { if (this.workspaceRoot) { - let listingPromise : Promise; + let listingPromise: Promise; if (listing && fs.existsSync(listing)) { listingPromise = Promise.resolve(listing); - } - else if (this.pullOnline) { - console.log('Fetching listing from nf-scil/' + NFSCIL_REF_BRANCH); + } else if (this.pullOnline) { + console.log("Fetching listing from nf-scil/" + NFSCIL_REF_BRANCH); const listing = fpath.join(this.temp, "test_data.json"); fs.rmSync(listing, { force: true }); - listingPromise = new Promise(resolve => { + listingPromise = new Promise((resolve) => { this.downloadFile( fpath.join(NFSCIL_RAW_URL, NFSCIL_REF_BRANCH, "tests", "config", "test_data.json"), - listing + listing, ).then(() => { resolve(listing); }); }); - } - else { + } else { return Promise.resolve([]); } - return listingPromise.then(listing => { + return listingPromise.then((listing) => { const testPackages: TestDataPackage[] = []; - const data = JSON.parse(fs.readFileSync(listing, 'utf8')); + const data = JSON.parse(fs.readFileSync(listing, "utf8")); for (const key in data) { const value = data[key]; - testPackages.push( - new TestDataPackage( - key, - vscode.TreeItemCollapsibleState.Collapsed, - "", - value - ) - ); + testPackages.push(new TestDataPackage(key, vscode.TreeItemCollapsibleState.Collapsed, "", value)); } return testPackages; @@ -209,9 +206,8 @@ export class TestDataProvider implements vscode.TreeDataProvider { try { zip.extractAllTo(this.contentPath, true); resolve(content); - } - catch (err) { - vscode.window.showErrorMessage('Failed to unpack archive: ' + name + '.zip'); + } catch (err) { + vscode.window.showErrorMessage("Failed to unpack archive: " + name + ".zip"); reject(err); } }); @@ -227,9 +223,7 @@ export class TestDataProvider implements vscode.TreeDataProvider { if (stat.isFile()) { contents.push(new TestDataFile(file, vscode.TreeItemCollapsibleState.None, relPath)); } else if (stat.isDirectory()) { - contents.push( - new TestDataFolder(file, vscode.TreeItemCollapsibleState.Collapsed, relPath) - ); + contents.push(new TestDataFolder(file, vscode.TreeItemCollapsibleState.Collapsed, relPath)); } } @@ -240,48 +234,45 @@ export class TestDataProvider implements vscode.TreeDataProvider { const location = fpath.join(element.md5sum.substring(0, 2), element.md5sum.substring(2)); const packagePath = fpath.join(this.packagePath, element.label); - return new Promise(resolve => { + return new Promise((resolve) => { this.downloadFile(fpath.join(TEST_DATA_URL, location), packagePath).then(() => { this.unpackArchive(packagePath).then((location) => { resolve(this.getFolderContents(location)); }); }); }); - } getChildrenItems(element: TestDataItem): Thenable { if (element instanceof TestDataPackage) { return this.getTestDataPackageContents(element); - } - else if (element instanceof TestDataFolder) { - return Promise.resolve( - this.getFolderContents(fpath.join(this.contentPath, element.path)) - ); + } else if (element instanceof TestDataFolder) { + return Promise.resolve(this.getFolderContents(fpath.join(this.contentPath, element.path))); } return Promise.resolve([]); } openInEditor(element: TestDataItem): void { - Promise.resolve(vscode.commands.executeCommand( - 'vscode.open', - vscode.Uri.file(fpath.join(this.contentPath, element.path)) - )); + Promise.resolve( + vscode.commands.executeCommand("vscode.open", vscode.Uri.file(fpath.join(this.contentPath, element.path))), + ); } saveAs(element: TestDataItem): void { if (this.workspaceRoot) { - vscode.window.showSaveDialog({ - defaultUri: vscode.Uri.file(this.workspaceRoot), - filters: { - 'All files': ['*'] - } - }).then((uri) => { - if (uri) { - fs.copyFileSync(fpath.join(this.contentPath, element.path), uri.fsPath); - } - }); + vscode.window + .showSaveDialog({ + defaultUri: vscode.Uri.file(this.workspaceRoot), + filters: { + "All files": ["*"], + }, + }) + .then((uri) => { + if (uri) { + fs.copyFileSync(fpath.join(this.contentPath, element.path), uri.fsPath); + } + }); } } } @@ -291,25 +282,24 @@ export abstract class TestDataItem extends vscode.TreeItem { public readonly label: string, public readonly collapsibleState: vscode.TreeItemCollapsibleState, public readonly path: string, - public readonly command?: vscode.Command + public readonly command?: vscode.Command, ) { super(label, collapsibleState); this.path = path; } - abstract iconPath: { light: string; dark: string; } | string; + abstract iconPath: { light: string; dark: string } | string; - contextValue = 'testDataItem'; + contextValue = "testDataItem"; } - export class TestDataPackage extends TestDataItem { constructor( public readonly label: string, public readonly collapsibleState: vscode.TreeItemCollapsibleState, public readonly path: string, public readonly md5sum: string, - public readonly command?: vscode.Command + public readonly command?: vscode.Command, ) { super(label, collapsibleState, path, command); this.md5sum = md5sum; @@ -323,6 +313,6 @@ export class TestDataFolder extends TestDataItem { } export class TestDataFile extends TestDataItem { - contextValue = 'testDataFile'; + contextValue = "testDataFile"; iconPath = "$(file)"; } diff --git a/nf-scil-extensions/test-data-treeview/src/test/extension.test.ts b/nf-scil-extensions/test-data-treeview/src/test/extension.test.ts index 4ca0ab41..8bcfbcdb 100644 --- a/nf-scil-extensions/test-data-treeview/src/test/extension.test.ts +++ b/nf-scil-extensions/test-data-treeview/src/test/extension.test.ts @@ -1,15 +1,15 @@ -import * as assert from 'assert'; +import * as assert from "assert"; // You can import and use all API from the 'vscode' module // as well as import your extension to test it -import * as vscode from 'vscode'; +import * as vscode from "vscode"; // import * as myExtension from '../../extension'; -suite('Extension Test Suite', () => { - vscode.window.showInformationMessage('Start all tests.'); +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)); - }); + test("Sample test", () => { + assert.strictEqual(-1, [1, 2, 3].indexOf(5)); + assert.strictEqual(-1, [1, 2, 3].indexOf(0)); + }); }); diff --git a/nf-scil-extensions/test-data-treeview/tsconfig.json b/nf-scil-extensions/test-data-treeview/tsconfig.json index e5fada0f..081d57c6 100644 --- a/nf-scil-extensions/test-data-treeview/tsconfig.json +++ b/nf-scil-extensions/test-data-treeview/tsconfig.json @@ -1,15 +1,12 @@ { - "compilerOptions": { - "module": "commonjs", - "target": "es2020", - "lib": ["es2020"], - "outDir": "out", - "sourceMap": true, - "rootDir": "src", - "strict": true - }, - "exclude": [ - "node_modules", - ".vscode-test" - ] + "compilerOptions": { + "module": "commonjs", + "target": "es2020", + "lib": ["es2020"], + "outDir": "out", + "sourceMap": true, + "rootDir": "src", + "strict": true + }, + "exclude": ["node_modules", ".vscode-test"] } diff --git a/nf-scil-extensions/test-data-treeview/vsc-extension-quickstart.md b/nf-scil-extensions/test-data-treeview/vsc-extension-quickstart.md index f518bb84..e2d793c2 100644 --- a/nf-scil-extensions/test-data-treeview/vsc-extension-quickstart.md +++ b/nf-scil-extensions/test-data-treeview/vsc-extension-quickstart.md @@ -2,47 +2,45 @@ ## What's in the folder -* This folder contains all of the files necessary for your extension. -* `package.json` - this is the manifest file in which you declare your extension and command. - * The sample plugin registers a command and defines its title and command name. With this information VS Code can show the command in the command palette. It doesn’t yet need to load the plugin. -* `src/extension.ts` - this is the main file where you will provide the implementation of your command. - * The file exports one function, `activate`, which is called the very first time your extension is activated (in this case by executing the command). Inside the `activate` function we call `registerCommand`. - * We pass the function containing the implementation of the command as the second parameter to `registerCommand`. +- This folder contains all of the files necessary for your extension. +- `package.json` - this is the manifest file in which you declare your extension and command. + - The sample plugin registers a command and defines its title and command name. With this information VS Code can show the command in the command palette. It doesn’t yet need to load the plugin. +- `src/extension.ts` - this is the main file where you will provide the implementation of your command. + - The file exports one function, `activate`, which is called the very first time your extension is activated (in this case by executing the command). Inside the `activate` function we call `registerCommand`. + - We pass the function containing the implementation of the command as the second parameter to `registerCommand`. ## Setup -* install the recommended extensions (amodio.tsl-problem-matcher, ms-vscode.extension-test-runner, and dbaeumer.vscode-eslint) - +- install the recommended extensions (amodio.tsl-problem-matcher, ms-vscode.extension-test-runner, and dbaeumer.vscode-eslint) ## Get up and running straight away -* Press `F5` to open a new window with your extension loaded. -* Run your command from the command palette by pressing (`Ctrl+Shift+P` or `Cmd+Shift+P` on Mac) and typing `Hello World`. -* Set breakpoints in your code inside `src/extension.ts` to debug your extension. -* Find output from your extension in the debug console. +- Press `F5` to open a new window with your extension loaded. +- Run your command from the command palette by pressing (`Ctrl+Shift+P` or `Cmd+Shift+P` on Mac) and typing `Hello World`. +- Set breakpoints in your code inside `src/extension.ts` to debug your extension. +- Find output from your extension in the debug console. ## Make changes -* You can relaunch the extension from the debug toolbar after changing code in `src/extension.ts`. -* You can also reload (`Ctrl+R` or `Cmd+R` on Mac) the VS Code window with your extension to load your changes. - +- You can relaunch the extension from the debug toolbar after changing code in `src/extension.ts`. +- You can also reload (`Ctrl+R` or `Cmd+R` on Mac) the VS Code window with your extension to load your changes. ## Explore the API -* You can open the full set of our API when you open the file `node_modules/@types/vscode/index.d.ts`. +- You can open the full set of our API when you open the file `node_modules/@types/vscode/index.d.ts`. ## Run tests -* Install the [Extension Test Runner](https://marketplace.visualstudio.com/items?itemName=ms-vscode.extension-test-runner) -* Run the "watch" task via the **Tasks: Run Task** command. Make sure this is running, or tests might not be discovered. -* Open the Testing view from the activity bar and click the Run Test" button, or use the hotkey `Ctrl/Cmd + ; A` -* See the output of the test result in the Test Results view. -* Make changes to `src/test/extension.test.ts` or create new test files inside the `test` folder. - * The provided test runner will only consider files matching the name pattern `**.test.ts`. - * You can create folders inside the `test` folder to structure your tests any way you want. +- Install the [Extension Test Runner](https://marketplace.visualstudio.com/items?itemName=ms-vscode.extension-test-runner) +- Run the "watch" task via the **Tasks: Run Task** command. Make sure this is running, or tests might not be discovered. +- Open the Testing view from the activity bar and click the Run Test" button, or use the hotkey `Ctrl/Cmd + ; A` +- See the output of the test result in the Test Results view. +- Make changes to `src/test/extension.test.ts` or create new test files inside the `test` folder. + - The provided test runner will only consider files matching the name pattern `**.test.ts`. + - You can create folders inside the `test` folder to structure your tests any way you want. ## Go further -* Reduce the extension size and improve the startup time by [bundling your extension](https://code.visualstudio.com/api/working-with-extensions/bundling-extension). -* [Publish your extension](https://code.visualstudio.com/api/working-with-extensions/publishing-extension) on the VS Code extension marketplace. -* Automate builds by setting up [Continuous Integration](https://code.visualstudio.com/api/working-with-extensions/continuous-integration). +- Reduce the extension size and improve the startup time by [bundling your extension](https://code.visualstudio.com/api/working-with-extensions/bundling-extension). +- [Publish your extension](https://code.visualstudio.com/api/working-with-extensions/publishing-extension) on the VS Code extension marketplace. +- Automate builds by setting up [Continuous Integration](https://code.visualstudio.com/api/working-with-extensions/continuous-integration).