Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VS Code launch configuration to debug the user's Indiekit installation #769

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
18 changes: 18 additions & 0 deletions packages/create-indiekit/files/template.vscode_launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Debug Indiekit",
"skipFiles": ["<node_internals>/**"],
"program": "${workspaceFolder}/node_modules/@indiekit/indiekit/bin/cli.js",
// "args": ["--config", "path/to/your/indiekit.config.js"]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this commented out code needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't sure which arguments were accepted by cli.js. Later I ended up using this:

"args": ["--config", "indiekit.config.js", "serve"]

"args": ["serve"],
"env": {
"GITHUB_TOKEN": "${env:GITHUB_TOKEN}",
"MONGO_URL": "${env:MONGO_URL}"
}
}
]
}
4 changes: 4 additions & 0 deletions packages/create-indiekit/lib/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 5 additions & 1 deletion packages/create-indiekit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"type": "module",
"main": "index.js",
"bin": {
"create-indiekit": "bin/create.js"
"create-indiekit": "bin/create.js delete-me"
Copy link
Collaborator

@paulrobertlloyd paulrobertlloyd Oct 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does delete-me do here? I need to revisit this, but I think this script is called when you run npm init indiekit [directory name] or npm create indiekit [directory name]. Does this interfere with that?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I was using delete-me as a placeholder for [directory name]

},
"files": [
"bin",
Expand All @@ -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",
Expand Down
28 changes: 15 additions & 13 deletions packages/create-indiekit/test/unit/files.js
Original file line number Diff line number Diff line change
@@ -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";

Expand All @@ -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 <https://getindiekit.com>\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 <https://getindiekit.com>\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 () => {
Expand All @@ -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");
});
});