diff --git a/common/changes/@boostercloud/framework-core/main_2025-06-18-06-20.json b/common/changes/@boostercloud/framework-core/main_2025-06-18-06-20.json new file mode 100644 index 000000000..b5c0682ab --- /dev/null +++ b/common/changes/@boostercloud/framework-core/main_2025-06-18-06-20.json @@ -0,0 +1,10 @@ +{ + "changes": [ + { + "packageName": "@boostercloud/framework-core", + "comment": "Add automatic .vscode/launch.json generation for new projects", + "type": "patch" + } + ], + "packageName": "@boostercloud/framework-core" +} \ No newline at end of file diff --git a/packages/cli/src/services/project-initializer.ts b/packages/cli/src/services/project-initializer.ts index 79ea3fd97..2826b71d7 100644 --- a/packages/cli/src/services/project-initializer.ts +++ b/packages/cli/src/services/project-initializer.ts @@ -12,6 +12,7 @@ import * as configTs from '../templates/project/config-ts' import * as indexTs from '../templates/project/index-ts' import * as prettierRc from '../templates/project/prettierrc-yaml' import * as mochaRc from '../templates/project/mocharc-yml' +import * as launchJson from '../templates/project/launch-json' import { guardError, wrapExecError } from '../common/errors' import { PackageManagerService } from './package-manager' import { gen, mapError, pipe, unsafeRunEffect } from '@boostercloud/framework-types/dist/effect' @@ -53,6 +54,7 @@ export async function generateRootDirectory(config: ProjectInitializerConfig): P [srcDir, 'event-handlers'], [srcDir, 'read-models'], [srcDir, 'scheduled-commands'], + [projectDir(config), '.vscode'], ] await Promise.all(dirs.map(createDirectory)) } @@ -107,4 +109,5 @@ const filesToGenerate: Array<[Array, string]> = [ [['src', 'config', 'config.ts'], configTs.template], [['src', 'index.ts'], indexTs.template], [['.mocharc.yml'], mochaRc.template], + [['.vscode', 'launch.json'], launchJson.template], ] diff --git a/packages/cli/src/templates/project/launch-json.ts b/packages/cli/src/templates/project/launch-json.ts new file mode 100644 index 000000000..063ad3c78 --- /dev/null +++ b/packages/cli/src/templates/project/launch-json.ts @@ -0,0 +1,15 @@ +export const template = `{ + // 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 + "version": "0.2.0", + "configurations": [ + { + "command": "rushx test", + "name": "Unit Tests", + "request": "launch", + "type": "node-terminal", + "cwd": "\${workspaceFolder}", + }, + ] +}` \ No newline at end of file diff --git a/packages/cli/test/commands/new/project.test.ts b/packages/cli/test/commands/new/project.test.ts index 4d304ced2..161cd5fbd 100644 --- a/packages/cli/test/commands/new/project.test.ts +++ b/packages/cli/test/commands/new/project.test.ts @@ -25,6 +25,7 @@ describe('new', (): void => { expect(fs.mkdirs).to.have.been.calledWithMatch(`${projectName}/src/common`) expect(fs.mkdirs).to.have.been.calledWithMatch(`${projectName}/src/event-handlers`) expect(fs.mkdirs).to.have.been.calledWithMatch(`${projectName}/src/scheduled-commands`) + expect(fs.mkdirs).to.have.been.calledWithMatch(`${projectName}/.vscode`) expect(fs.outputFile).to.have.been.calledWithMatch(`${projectName}/.eslintignore`) expect(fs.outputFile).to.have.been.calledWithMatch(`${projectName}/.eslintrc.js`) expect(fs.outputFile).to.have.been.calledWithMatch(`${projectName}/.gitignore`) @@ -35,6 +36,7 @@ describe('new', (): void => { expect(fs.outputFile).to.have.been.calledWithMatch(`${projectName}/src/config/config.ts`) expect(fs.outputFile).to.have.been.calledWithMatch(`${projectName}/src/index.ts`) expect(fs.outputFile).to.have.been.calledWithMatch(`${projectName}/.mocharc.yml`) + expect(fs.outputFile).to.have.been.calledWithMatch(`${projectName}/.vscode/launch.json`) } const defaultProjectInitializerConfig = { diff --git a/packages/cli/test/services/project-initializer.test.ts b/packages/cli/test/services/project-initializer.test.ts index 9d680d165..8328645f0 100644 --- a/packages/cli/test/services/project-initializer.test.ts +++ b/packages/cli/test/services/project-initializer.test.ts @@ -55,6 +55,7 @@ describe('project initializer', (): void => { expect(fs.mkdirs).to.have.been.calledWithMatch(`${projectName}/src/common`) expect(fs.mkdirs).to.have.been.calledWithMatch(`${projectName}/src/event-handlers`) expect(fs.mkdirs).to.have.been.calledWithMatch(`${projectName}/src/scheduled-commands`) + expect(fs.mkdirs).to.have.been.calledWithMatch(`${projectName}/.vscode`) }) it('install dependencies', async () => { @@ -76,5 +77,6 @@ describe('project initializer', (): void => { expect(fs.outputFile).to.have.been.calledWithMatch(`${projectName}/src/config/config.ts`) expect(fs.outputFile).to.have.been.calledWithMatch(`${projectName}/src/index.ts`) expect(fs.outputFile).to.have.been.calledWithMatch(`${projectName}/.mocharc.yml`) + expect(fs.outputFile).to.have.been.calledWithMatch(`${projectName}/.vscode/launch.json`) }) })