From ab298c17ed005d6229f984ad315b1dc91401240f Mon Sep 17 00:00:00 2001 From: Elliott Marquez <5981958+e111077@users.noreply.github.com> Date: Mon, 18 Mar 2024 17:14:14 -0700 Subject: [PATCH] format --- .prettierignore | 3 + .../.vscode/launch.json | 50 ++++---- .../.vscode/settings.json | 18 +-- .../.vscode/tasks.json | 32 ++--- .../lit-dev-tutorial-plugin/src/extension.ts | 111 +++++++++++------- .../src/test/runTest.ts | 28 ++--- .../src/test/suite/extension.test.ts | 5 +- .../lit-dev-tutorial-plugin/src/test/util.ts | 4 +- .../src/tree-items/generic-file.ts | 4 +- .../src/tree-items/playground-file.ts | 4 +- .../src/tree-items/tutorial-step.ts | 17 +-- .../src/tree-items/tutorial.ts | 4 +- .../src/tree-provider.ts | 57 +++++---- .../lit-dev-tutorial-plugin/tsconfig.json | 30 +++-- 14 files changed, 202 insertions(+), 165 deletions(-) diff --git a/.prettierignore b/.prettierignore index 41c915fed..e260f6508 100644 --- a/.prettierignore +++ b/.prettierignore @@ -8,6 +8,9 @@ package-lock.json /packages/lit-dev-content/_dev/ /packages/lit-dev-content/_site/ /packages/lit-dev-content/rollupout/ +/packages/lit-dev-tutorial-plugin/.vscode-test/ +/packages/lit-dev-tutorial-plugin/.test-bin/ +/packages/lit-dev-tutorial-plugin/out/ # TODO(aomarks) Would be nice to format samples, but Prettier doesn't always do # a great job compared to our manual formatting. /packages/lit-dev-content/samples/ diff --git a/packages/lit-dev-tutorial-plugin/.vscode/launch.json b/packages/lit-dev-tutorial-plugin/.vscode/launch.json index 670d6e66c..1210201da 100644 --- a/packages/lit-dev-tutorial-plugin/.vscode/launch.json +++ b/packages/lit-dev-tutorial-plugin/.vscode/launch.json @@ -3,32 +3,26 @@ // Hover to view descriptions of existing attributes. // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 { - "version": "0.2.0", - "configurations": [ - { - "name": "Run Extension", - "type": "extensionHost", - "request": "launch", - "args": [ - "--extensionDevelopmentPath=${workspaceFolder}" - ], - "outFiles": [ - "${workspaceFolder}/out/**/*.js" - ], - "preLaunchTask": "${defaultBuildTask}" - }, - { - "name": "Extension Tests", - "type": "extensionHost", - "request": "launch", - "args": [ - "--extensionDevelopmentPath=${workspaceFolder}", - "--extensionTestsPath=${workspaceFolder}/out/test/suite/index" - ], - "outFiles": [ - "${workspaceFolder}/out/test/**/*.js" - ], - "preLaunchTask": "${defaultBuildTask}" - } - ] + "version": "0.2.0", + "configurations": [ + { + "name": "Run Extension", + "type": "extensionHost", + "request": "launch", + "args": ["--extensionDevelopmentPath=${workspaceFolder}"], + "outFiles": ["${workspaceFolder}/out/**/*.js"], + "preLaunchTask": "${defaultBuildTask}" + }, + { + "name": "Extension Tests", + "type": "extensionHost", + "request": "launch", + "args": [ + "--extensionDevelopmentPath=${workspaceFolder}", + "--extensionTestsPath=${workspaceFolder}/out/test/suite/index" + ], + "outFiles": ["${workspaceFolder}/out/test/**/*.js"], + "preLaunchTask": "${defaultBuildTask}" + } + ] } diff --git a/packages/lit-dev-tutorial-plugin/.vscode/settings.json b/packages/lit-dev-tutorial-plugin/.vscode/settings.json index 30bf8c2d3..ffeaf91cb 100644 --- a/packages/lit-dev-tutorial-plugin/.vscode/settings.json +++ b/packages/lit-dev-tutorial-plugin/.vscode/settings.json @@ -1,11 +1,11 @@ // Place your settings in this file to overwrite default and user settings. { - "files.exclude": { - "out": false // set this to true to hide the "out" folder with the compiled JS files - }, - "search.exclude": { - "out": true // set this to false to include "out" folder in search results - }, - // Turn off tsc task auto detection since we have the necessary tasks as npm scripts - "typescript.tsc.autoDetect": "off" -} \ No newline at end of file + "files.exclude": { + "out": false // set this to true to hide the "out" folder with the compiled JS files + }, + "search.exclude": { + "out": true // set this to false to include "out" folder in search results + }, + // Turn off tsc task auto detection since we have the necessary tasks as npm scripts + "typescript.tsc.autoDetect": "off" +} diff --git a/packages/lit-dev-tutorial-plugin/.vscode/tasks.json b/packages/lit-dev-tutorial-plugin/.vscode/tasks.json index 3b17e53b6..078ff7e01 100644 --- a/packages/lit-dev-tutorial-plugin/.vscode/tasks.json +++ b/packages/lit-dev-tutorial-plugin/.vscode/tasks.json @@ -1,20 +1,20 @@ // See https://go.microsoft.com/fwlink/?LinkId=733558 // for the documentation about the tasks.json format { - "version": "2.0.0", - "tasks": [ - { - "type": "npm", - "script": "watch", - "problemMatcher": "$tsc-watch", - "isBackground": true, - "presentation": { - "reveal": "never" - }, - "group": { - "kind": "build", - "isDefault": true - } - } - ] + "version": "2.0.0", + "tasks": [ + { + "type": "npm", + "script": "watch", + "problemMatcher": "$tsc-watch", + "isBackground": true, + "presentation": { + "reveal": "never" + }, + "group": { + "kind": "build", + "isDefault": true + } + } + ] } diff --git a/packages/lit-dev-tutorial-plugin/src/extension.ts b/packages/lit-dev-tutorial-plugin/src/extension.ts index 55b8ba098..82b293b21 100644 --- a/packages/lit-dev-tutorial-plugin/src/extension.ts +++ b/packages/lit-dev-tutorial-plugin/src/extension.ts @@ -5,18 +5,19 @@ */ import * as vscode from 'vscode'; -import { BeforeAfterDir } from './tree-items/before-after-dir.js'; -import { GenericFile } from './tree-items/generic-file.js'; -import { PlaygroundFile } from './tree-items/playground-file.js'; -import { TutorialStep } from './tree-items/tutorial-step.js'; -import { Tutorial } from './tree-items/tutorial.js'; +import {BeforeAfterDir} from './tree-items/before-after-dir.js'; +import {GenericFile} from './tree-items/generic-file.js'; +import {PlaygroundFile} from './tree-items/playground-file.js'; +import {TutorialStep} from './tree-items/tutorial-step.js'; +import {Tutorial} from './tree-items/tutorial.js'; import {LitDevTutorialTreeProvider, TutorialTreeItem} from './tree-provider.js'; export async function activate() { const rootPath = - vscode.workspace.workspaceFolders && vscode.workspace.workspaceFolders.length > 0 - ? vscode.workspace.workspaceFolders[0].uri.fsPath - : undefined; + vscode.workspace.workspaceFolders && + vscode.workspace.workspaceFolders.length > 0 + ? vscode.workspace.workspaceFolders[0].uri.fsPath + : undefined; if (!rootPath) { return; @@ -36,38 +37,68 @@ export async function activate() { vscode.commands.registerCommand('litDevTutorial.createTutorial', () => { provider.createTutorial(); }); - vscode.commands.registerCommand('litDevTutorial.addStep', (tutorial: Tutorial) => { - TutorialStep.create(tutorial); - }); - vscode.commands.registerCommand('litDevTutorial.moveStepUp', (step: TutorialStep) => { - step.moveUp(); - }); - vscode.commands.registerCommand('litDevTutorial.moveStepDown', (step: TutorialStep) => { - step.moveDown(); - }); - vscode.commands.registerCommand('litDevTutorial.addAfterStep', (step: TutorialStep) => { - BeforeAfterDir.create(step, 'after'); - }); - vscode.commands.registerCommand('litDevTutorial.delete', (item: TutorialTreeItem) => { - item.delete(); - }); - vscode.commands.registerCommand('litDevTutorial.makeSolvable', (item: TutorialStep) => { - item.solvable = true; - item.provider.refresh(); - }); - vscode.commands.registerCommand('litDevTutorial.makeUnsolvable', (item: TutorialStep) => { - item.solvable = false; - item.provider.refresh(); - }); - vscode.commands.registerCommand('litDevTutorial.createPlaygroundFile', (dir: BeforeAfterDir) => { - PlaygroundFile.create(dir); - }); - vscode.commands.registerCommand('litDevTutorial.revealInSidebar', (item: GenericFile | PlaygroundFile) => { - item.revealInSidebar(); - }); - vscode.commands.registerCommand('litDevTutorial.renameStep', (item: TutorialStep) => { - item.rename(); - }); + vscode.commands.registerCommand( + 'litDevTutorial.addStep', + (tutorial: Tutorial) => { + TutorialStep.create(tutorial); + } + ); + vscode.commands.registerCommand( + 'litDevTutorial.moveStepUp', + (step: TutorialStep) => { + step.moveUp(); + } + ); + vscode.commands.registerCommand( + 'litDevTutorial.moveStepDown', + (step: TutorialStep) => { + step.moveDown(); + } + ); + vscode.commands.registerCommand( + 'litDevTutorial.addAfterStep', + (step: TutorialStep) => { + BeforeAfterDir.create(step, 'after'); + } + ); + vscode.commands.registerCommand( + 'litDevTutorial.delete', + (item: TutorialTreeItem) => { + item.delete(); + } + ); + vscode.commands.registerCommand( + 'litDevTutorial.makeSolvable', + (item: TutorialStep) => { + item.solvable = true; + item.provider.refresh(); + } + ); + vscode.commands.registerCommand( + 'litDevTutorial.makeUnsolvable', + (item: TutorialStep) => { + item.solvable = false; + item.provider.refresh(); + } + ); + vscode.commands.registerCommand( + 'litDevTutorial.createPlaygroundFile', + (dir: BeforeAfterDir) => { + PlaygroundFile.create(dir); + } + ); + vscode.commands.registerCommand( + 'litDevTutorial.revealInSidebar', + (item: GenericFile | PlaygroundFile) => { + item.revealInSidebar(); + } + ); + vscode.commands.registerCommand( + 'litDevTutorial.renameStep', + (item: TutorialStep) => { + item.rename(); + } + ); } // this method is called when your extension is deactivated diff --git a/packages/lit-dev-tutorial-plugin/src/test/runTest.ts b/packages/lit-dev-tutorial-plugin/src/test/runTest.ts index 72d334a3e..d3bb4d710 100644 --- a/packages/lit-dev-tutorial-plugin/src/test/runTest.ts +++ b/packages/lit-dev-tutorial-plugin/src/test/runTest.ts @@ -6,24 +6,24 @@ import * as path from 'path'; -import { runTests } from '@vscode/test-electron'; +import {runTests} from '@vscode/test-electron'; async function main() { - try { - // The folder containing the Extension Manifest package.json - // Passed to `--extensionDevelopmentPath` - const extensionDevelopmentPath = path.resolve(__dirname, '../../'); + try { + // The folder containing the Extension Manifest package.json + // Passed to `--extensionDevelopmentPath` + const extensionDevelopmentPath = path.resolve(__dirname, '../../'); - // The path to test runner - // Passed to --extensionTestsPath - const extensionTestsPath = path.resolve(__dirname, './suite/index'); + // The path to test runner + // 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); - } + // 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/packages/lit-dev-tutorial-plugin/src/test/suite/extension.test.ts b/packages/lit-dev-tutorial-plugin/src/test/suite/extension.test.ts index 217eef725..bbe9b6043 100644 --- a/packages/lit-dev-tutorial-plugin/src/test/suite/extension.test.ts +++ b/packages/lit-dev-tutorial-plugin/src/test/suite/extension.test.ts @@ -30,7 +30,10 @@ suite('Tutorial Extension', () => { suite('startup', () => { test('recognizes lit.dev repo', async () => { - await vscode.commands.executeCommand('vscode.openFolder', vscode.Uri.file(litDevPath)); + await vscode.commands.executeCommand( + 'vscode.openFolder', + vscode.Uri.file(litDevPath) + ); console.log('opened!'); }); }); diff --git a/packages/lit-dev-tutorial-plugin/src/test/util.ts b/packages/lit-dev-tutorial-plugin/src/test/util.ts index 40c2c9232..ed1614cfd 100644 --- a/packages/lit-dev-tutorial-plugin/src/test/util.ts +++ b/packages/lit-dev-tutorial-plugin/src/test/util.ts @@ -198,7 +198,9 @@ export const prepopulateTutorial = async ( for (let i = options.tutorials.length - 1; i >= 0; i--) { const tutorial = options.tutorials[i]; - const tutorialSection = (tutorial as typeof tutorial & {category ?: 'Learn'|'Build'}).category ?? 'Learn'; + const tutorialSection = + (tutorial as typeof tutorial & {category?: 'Learn' | 'Build'}).category ?? + 'Learn'; const tutorialIndex = dataFileLines.findIndex((line) => line.includes(`// ${tutorialSection}`) ); diff --git a/packages/lit-dev-tutorial-plugin/src/tree-items/generic-file.ts b/packages/lit-dev-tutorial-plugin/src/tree-items/generic-file.ts index ea70ae277..354af39e7 100644 --- a/packages/lit-dev-tutorial-plugin/src/tree-items/generic-file.ts +++ b/packages/lit-dev-tutorial-plugin/src/tree-items/generic-file.ts @@ -72,6 +72,8 @@ export class GenericFile extends vscode.TreeItem { revealInSidebar() { vscode.commands.executeCommand('vscode.open', vscode.Uri.file(this.path)); - vscode.commands.executeCommand('workbench.files.action.showActiveFileInExplorer'); + vscode.commands.executeCommand( + 'workbench.files.action.showActiveFileInExplorer' + ); } } diff --git a/packages/lit-dev-tutorial-plugin/src/tree-items/playground-file.ts b/packages/lit-dev-tutorial-plugin/src/tree-items/playground-file.ts index 67529981c..49a200d67 100644 --- a/packages/lit-dev-tutorial-plugin/src/tree-items/playground-file.ts +++ b/packages/lit-dev-tutorial-plugin/src/tree-items/playground-file.ts @@ -127,6 +127,8 @@ export class PlaygroundFile extends vscode.TreeItem { revealInSidebar() { vscode.commands.executeCommand('vscode.open', vscode.Uri.file(this.path)); - vscode.commands.executeCommand('workbench.files.action.showActiveFileInExplorer'); + vscode.commands.executeCommand( + 'workbench.files.action.showActiveFileInExplorer' + ); } } diff --git a/packages/lit-dev-tutorial-plugin/src/tree-items/tutorial-step.ts b/packages/lit-dev-tutorial-plugin/src/tree-items/tutorial-step.ts index e59c521b1..50f912cac 100644 --- a/packages/lit-dev-tutorial-plugin/src/tree-items/tutorial-step.ts +++ b/packages/lit-dev-tutorial-plugin/src/tree-items/tutorial-step.ts @@ -18,7 +18,7 @@ export class TutorialStep extends vscode.TreeItem { private _hasAfter = false; checkable = false; beforeDir!: BeforeAfterDir; - afterDir: BeforeAfterDir|undefined = undefined; + afterDir: BeforeAfterDir | undefined = undefined; get dirName() { return `${this.step}`.padStart(2, '0'); @@ -68,10 +68,7 @@ export class TutorialStep extends vscode.TreeItem { this._hasAfter = value; - const tutorialJsonPath = path.join( - this.tutorial.path, - 'tutorial.json' - ); + const tutorialJsonPath = path.join(this.tutorial.path, 'tutorial.json'); let tutorialJson = getJson(tutorialJsonPath)!; if (value) { @@ -97,15 +94,11 @@ export class TutorialStep extends vscode.TreeItem { } this._solvable = solvable; - const tutorialJsonPath = path.join( - this.tutorial.path, - 'tutorial.json' - ); + const tutorialJsonPath = path.join(this.tutorial.path, 'tutorial.json'); let tutorialJson = getJson(tutorialJsonPath)!; if (solvable) { delete tutorialJson.steps[this.step].noSolve; - } else { this.hasAfter = false; tutorialJson = getJson(tutorialJsonPath)!; @@ -219,7 +212,7 @@ export class TutorialStep extends vscode.TreeItem { return; } - const isSolvableStr = await vscode.window.showQuickPick(['Yes', 'No'],{ + const isSolvableStr = await vscode.window.showQuickPick(['Yes', 'No'], { title: 'Should this step have a "solve" button?', }); @@ -231,7 +224,7 @@ export class TutorialStep extends vscode.TreeItem { let hasAfter = false; if (!hideSolve) { - const hasAfterStr = await vscode.window.showQuickPick(['Yes', 'No'],{ + const hasAfterStr = await vscode.window.showQuickPick(['Yes', 'No'], { title: 'Is "after" step the "before" of the next step?', }); diff --git a/packages/lit-dev-tutorial-plugin/src/tree-items/tutorial.ts b/packages/lit-dev-tutorial-plugin/src/tree-items/tutorial.ts index a4303adb5..c8292ee35 100644 --- a/packages/lit-dev-tutorial-plugin/src/tree-items/tutorial.ts +++ b/packages/lit-dev-tutorial-plugin/src/tree-items/tutorial.ts @@ -171,7 +171,9 @@ export class Tutorial extends vscode.TreeItem { } catch (_e) {} const dateObj = new Date(); - const date = `${dateObj.getFullYear()}-${dateObj.getMonth() + 1}-${dateObj.getDate()}`; + const date = `${dateObj.getFullYear()}-${ + dateObj.getMonth() + 1 + }-${dateObj.getDate()}`; const tutorialJson: TutorialJson = { header: name, diff --git a/packages/lit-dev-tutorial-plugin/src/tree-provider.ts b/packages/lit-dev-tutorial-plugin/src/tree-provider.ts index 7e152bfff..f20ab719b 100644 --- a/packages/lit-dev-tutorial-plugin/src/tree-provider.ts +++ b/packages/lit-dev-tutorial-plugin/src/tree-provider.ts @@ -13,7 +13,7 @@ import {TutorialStep} from './tree-items/tutorial-step'; import {getJson} from './fs-helpers'; import {BeforeAfterDir} from './tree-items/before-after-dir'; import {PlaygroundFile} from './tree-items/playground-file'; -import { TutorialJson } from './types'; +import {TutorialJson} from './types'; interface PackageJson { name?: string; @@ -140,15 +140,15 @@ export class LitDevTutorialTreeProvider file.isFile() ); - const tutorialJson = getJson(path.join(element.path, 'tutorial.json'))!; + const tutorialJson = getJson( + path.join(element.path, 'tutorial.json') + )!; const jsonSteps = tutorialJson.steps; - const steps = tutorialStepEntries.map( - (step, index) => { - const jsonStep = jsonSteps[index]; - return new TutorialStep(this, element, step.name, !jsonStep.noSolve) - } - ); + const steps = tutorialStepEntries.map((step, index) => { + const jsonStep = jsonSteps[index]; + return new TutorialStep(this, element, step.name, !jsonStep.noSolve); + }); const files = tutorialFileEntries.map( (file) => new GenericFile(this, path.join(tutorialPath, file.name)) ); @@ -158,23 +158,28 @@ export class LitDevTutorialTreeProvider private onTutorialStep(element: TutorialStep) { const tutorialPath = element.path; const tutorialEntries = fs.readdirSync(tutorialPath, {withFileTypes: true}); - const tutorialDirEntries = tutorialEntries.filter( - (file) => - (file.isDirectory() && file.name === 'before') || file.name === 'after' - ).reverse(); - - const beforeAfterDirs = tutorialDirEntries.map( - (entry) => { - const dir = new BeforeAfterDir(this, element, entry.name as 'before' | 'after') - if (entry.name === 'before') { - element.beforeDir = dir; - } else if (entry.name === 'after') { - element.afterDir = dir; - } - - return dir; + const tutorialDirEntries = tutorialEntries + .filter( + (file) => + (file.isDirectory() && file.name === 'before') || + file.name === 'after' + ) + .reverse(); + + const beforeAfterDirs = tutorialDirEntries.map((entry) => { + const dir = new BeforeAfterDir( + this, + element, + entry.name as 'before' | 'after' + ); + if (entry.name === 'before') { + element.beforeDir = dir; + } else if (entry.name === 'after') { + element.afterDir = dir; } - ); + + return dir; + }); const stepInstructionsMdFile = new GenericFile( this, @@ -206,7 +211,9 @@ export class LitDevTutorialTreeProvider }); const projectJsonFile = files.find((file) => file instanceof GenericFile)!; - const playgroundFiles = files.filter((file) => !(file instanceof GenericFile)); + const playgroundFiles = files.filter( + (file) => !(file instanceof GenericFile) + ); return [...playgroundFiles, projectJsonFile]; } diff --git a/packages/lit-dev-tutorial-plugin/tsconfig.json b/packages/lit-dev-tutorial-plugin/tsconfig.json index fe565bea9..fb305d5e8 100644 --- a/packages/lit-dev-tutorial-plugin/tsconfig.json +++ b/packages/lit-dev-tutorial-plugin/tsconfig.json @@ -1,18 +1,16 @@ { - "compilerOptions": { - "module": "commonjs", - "target": "ES2020", - "outDir": "out", - "lib": [ - "ES2020" - ], - "sourceMap": true, - "rootDir": "src", - "strict": true, /* enable all strict type-checking options */ - "skipLibCheck": true - /* Additional Checks */ - // "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */ - // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */ - // "noUnusedParameters": true, /* Report errors on unused parameters. */ - } + "compilerOptions": { + "module": "commonjs", + "target": "ES2020", + "outDir": "out", + "lib": ["ES2020"], + "sourceMap": true, + "rootDir": "src", + "strict": true /* enable all strict type-checking options */, + "skipLibCheck": true + /* Additional Checks */ + // "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */ + // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */ + // "noUnusedParameters": true, /* Report errors on unused parameters. */ + } }