From 8bd2e7bb20e22e5ac95817c4361613658f88c76f Mon Sep 17 00:00:00 2001 From: Giacomo Debidda Date: Tue, 15 Oct 2024 23:55:49 +0200 Subject: [PATCH] feat(create-indiekit): add config to debug Indiekit in VS Code --- package.json | 1 + .../files/template.vscode_launch.json | 18 ++++++++++++ packages/create-indiekit/lib/files.js | 4 +++ packages/create-indiekit/package.json | 6 +++- packages/create-indiekit/test/unit/files.js | 28 ++++++++++--------- 5 files changed, 43 insertions(+), 14 deletions(-) create mode 100644 packages/create-indiekit/files/template.vscode_launch.json diff --git a/package.json b/package.json index 4a3c233cd..316d7fd02 100644 --- a/package.json +++ b/package.json @@ -41,6 +41,7 @@ "lint:fix": "npm run lint:prettier:fix && npm run lint:js:fix && npm run lint:css:fix", "test": "node --test --test-reporter=spec", "test:coverage": "node --test --experimental-test-coverage", + "test:create-indiekit": "lerna run test --scope create-indiekit", "test:lcov": "node --test --experimental-test-coverage --test-reporter=lcov --test-reporter-destination=coverage/lcov.info" }, "workspaces": [ diff --git a/packages/create-indiekit/files/template.vscode_launch.json b/packages/create-indiekit/files/template.vscode_launch.json new file mode 100644 index 000000000..4d1edc247 --- /dev/null +++ b/packages/create-indiekit/files/template.vscode_launch.json @@ -0,0 +1,18 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "type": "node", + "request": "launch", + "name": "Debug Indiekit", + "skipFiles": ["/**"], + "program": "${workspaceFolder}/node_modules/@indiekit/indiekit/bin/cli.js", + // "args": ["--config", "path/to/your/indiekit.config.js"] + "args": ["serve"], + "env": { + "GITHUB_TOKEN": "${env:GITHUB_TOKEN}", + "MONGO_URL": "${env:MONGO_URL}" + } + } + ] +} diff --git a/packages/create-indiekit/lib/files.js b/packages/create-indiekit/lib/files.js index 03a7d3db4..7b576dfc9 100644 --- a/packages/create-indiekit/lib/files.js +++ b/packages/create-indiekit/lib/files.js @@ -39,6 +39,10 @@ export const getFiles = async (setup) => { path: ".gitignore", contents: await getFileContents("template.gitignore"), }, + { + path: path.join(".vscode", "launch.json"), + contents: await getFileContents("template.vscode_launch.json"), + }, ]; if (useDocker) { diff --git a/packages/create-indiekit/package.json b/packages/create-indiekit/package.json index 12f6cffec..da4d1179a 100644 --- a/packages/create-indiekit/package.json +++ b/packages/create-indiekit/package.json @@ -19,7 +19,7 @@ "type": "module", "main": "index.js", "bin": { - "create-indiekit": "bin/create.js" + "create-indiekit": "bin/create.js delete-me" }, "files": [ "bin", @@ -35,6 +35,10 @@ "url": "https://github.com/getindiekit/indiekit.git", "directory": "packages/create-indiekit" }, + "scripts": { + "create": "node bin/create.js", + "test": "node --test --test-reporter=spec" + }, "dependencies": { "@indiekit/preset-eleventy": "^1.0.0-beta.10", "@indiekit/preset-hugo": "^1.0.0-beta.10", diff --git a/packages/create-indiekit/test/unit/files.js b/packages/create-indiekit/test/unit/files.js index 73f4b29fb..9775d2b0d 100644 --- a/packages/create-indiekit/test/unit/files.js +++ b/packages/create-indiekit/test/unit/files.js @@ -1,4 +1,5 @@ import { strict as assert } from "node:assert"; +import path from "node:path"; import { describe, it, mock } from "node:test"; import { getFileContents, getFiles } from "../../lib/files.js"; @@ -23,16 +24,17 @@ describe("create-indiekit/lib/files", () => { it("Gets files to create", async () => { const result = await getFiles({ me: "https://website.example" }); - assert.deepEqual(result, [ - { - path: "README.md", - contents: `# Indiekit server for https://website.example\n\nLearn more at \n`, - }, - { - path: ".gitignore", - contents: "node_modules/\n", - }, - ]); + assert.deepEqual(result[0], { + path: "README.md", + contents: `# Indiekit server for https://website.example\n\nLearn more at \n`, + }); + + assert.deepEqual(result[1], { + path: ".gitignore", + contents: "node_modules/\n", + }); + + assert.equal(result[2].path, path.join(".vscode", "launch.json")); }); it("Gets files to create, including docker files", async () => { @@ -41,8 +43,8 @@ describe("create-indiekit/lib/files", () => { useDocker: true, }); - assert.equal(result[2].path, "docker-compose.yml"); - assert.equal(result[3].path, "Dockerfile"); - assert.equal(result[4].path, ".dockerignore"); + assert.equal(result[3].path, "docker-compose.yml"); + assert.equal(result[4].path, "Dockerfile"); + assert.equal(result[5].path, ".dockerignore"); }); });