From 0011da2bb14361c6da1286a26c3a348e73741776 Mon Sep 17 00:00:00 2001 From: tommy-mitchell Date: Thu, 31 Aug 2023 16:45:34 -0500 Subject: [PATCH] feat: conditionally include `.vscode` and `test/_fixtures`, styling fixes --- .tmplr.yml | 50 +++++++++++++------ template/.vscode/extensions.json | 7 +++ template/.vscode/settings.json | 14 ++++++ template/.vscode/snippets.code-snippets | 8 +++ template/package.json | 3 +- template/readme.md | 6 +-- template/src/cli.ts | 5 +- .../_fixtures/.gitkeep | 0 template/{test => test-fixtures}/_utils.ts | 0 template/test-fixtures/cli.ts | 37 ++++++++++++++ template/test/cli.ts | 4 +- 11 files changed, 110 insertions(+), 24 deletions(-) create mode 100644 template/.vscode/extensions.json create mode 100644 template/.vscode/settings.json create mode 100644 template/.vscode/snippets.code-snippets rename template/{test => test-fixtures}/_fixtures/.gitkeep (100%) rename template/{test => test-fixtures}/_utils.ts (100%) create mode 100644 template/test-fixtures/cli.ts diff --git a/.tmplr.yml b/.tmplr.yml index 36f15d0..353f2f4 100644 --- a/.tmplr.yml +++ b/.tmplr.yml @@ -26,6 +26,18 @@ steps: - 'global' - 'dep' + - read: include_dot_vscode + prompt: 'Include .vscode folder?' + choices: + - 'Yes' + - 'No' + + - read: include_test_fixtures + prompt: 'Include test fixtures?' + choices: + - 'Yes' + - 'No' + # get computed variables - if: @@ -53,31 +65,41 @@ steps: eval: 'yarn add {{ project_name }}' # setup project - # make sure to copy "hidden"/dot files (loreanvictor/tmplr#14) - - - copy: ./template/**/* - to: ./ - - copy: ./template/**/.**/**/* - to: ./ + - if: + eval: '{{ include_dot_vscode | matches: No }}' + steps: + - remove: ./template/.vscode - - copy: ./template/**/.* - to: ./ + - if: + eval: '{{ include_test_fixtures | matches: Yes }}' + steps: + - copy: ./template/test-fixtures/**/* + to: ./test + include hidden: true + - remove: ./template/test-fixtures + - remove: ./template/test + else: + steps: + - copy: ./template/test/**/* + to: ./test + include hidden: true + - remove: ./template/test + - remove: ./template/test-fixtures - - copy: ./template/**/.**/**/.* + - copy: ./template/**/* to: ./ + include hidden: true # finish - # temporaryily specify folders to remove (loreanvictor/tmplr#15) - remove: ./template/**/* - - remove: ./template/**/.**/**/* - - remove: ./template/**/.* - - remove: ./template/**/.**/**/.* + include hidden: true + # temporarily specify folders to remove (loreanvictor/tmplr#15) - remove: ./template/.github + - remove: ./template/.vscode - remove: ./template/src - - remove: ./template/test - remove: ./template - remove: .tmplr.yml diff --git a/template/.vscode/extensions.json b/template/.vscode/extensions.json new file mode 100644 index 0000000..0a9ab0d --- /dev/null +++ b/template/.vscode/extensions.json @@ -0,0 +1,7 @@ +{ + "recommendations": [ + "sculpt0r.vsc-ava-test-runner", + "samverschueren.linter-xo", + "dbaeumer.vscode-eslint" + ] +} diff --git a/template/.vscode/settings.json b/template/.vscode/settings.json new file mode 100644 index 0000000..90b5d70 --- /dev/null +++ b/template/.vscode/settings.json @@ -0,0 +1,14 @@ +{ + "xo.enable": true, + "xo.format.enable": true, + "xo.overrideSeverity": "warn", + "xo.debounce": 100, + "[javascript]": { + "editor.formatOnSave": true, + "editor.defaultFormatter": "samverschueren.linter-xo" + }, + "[typescript]": { + "editor.formatOnSave": true, + "editor.defaultFormatter": "samverschueren.linter-xo" + } +} diff --git a/template/.vscode/snippets.code-snippets b/template/.vscode/snippets.code-snippets new file mode 100644 index 0000000..6ccb0e2 --- /dev/null +++ b/template/.vscode/snippets.code-snippets @@ -0,0 +1,8 @@ +{ + "test.todo": { + "scope": "typescript", + "prefix": "todo", + "description": "Create an AVA todo test", + "body": "test.todo(\"$1\");", + } +} diff --git a/template/package.json b/template/package.json index 170fc30..e73835d 100644 --- a/template/package.json +++ b/template/package.json @@ -5,7 +5,7 @@ "keywords": [ "cli", "cli-app", - "command line" + "command-line" ], "license": "MIT", "repository": "tommy-mitchell/{{ tmplr.project_name | skip: @tommy-mitchell/ }}", @@ -35,7 +35,6 @@ "test/**/*.ts", "!test/_*" ], - "snapshotDir": "test/_snapshots", "extensions": { "ts": "module" }, diff --git a/template/readme.md b/template/readme.md index 1223f3b..6b7029d 100644 --- a/template/readme.md +++ b/template/readme.md @@ -19,13 +19,13 @@ ## Usage ```sh -$ {{ tmplr.command_name }} +$ {{ tmplr.command_name }} --help Usage $ {{ tmplr.command_name }} […] Options - + --help, -h Show this help message Examples $ {{ tmplr.command_name }} @@ -33,4 +33,4 @@ $ {{ tmplr.command_name }} ## Related -- []() +- [foo](https://github.com/foo/foo) - Does foo. diff --git a/template/src/cli.ts b/template/src/cli.ts index 4f14bfd..7b05324 100644 --- a/template/src/cli.ts +++ b/template/src/cli.ts @@ -1,5 +1,4 @@ #!/usr/bin/env tsx -import process from "node:process"; import meow from "meow"; const cli = meow(` @@ -7,7 +6,7 @@ const cli = meow(` $ {{ tmplr.command_name }} […] Options - + --help, -h Show this help message Examples $ {{ tmplr.command_name }} @@ -24,6 +23,6 @@ const cli = meow(` const { input, flags: { help: helpShortFlag } } = cli; -if(input.length === 0 || helpShortFlag) { +if (input.length === 0 || helpShortFlag) { cli.showHelp(0); } diff --git a/template/test/_fixtures/.gitkeep b/template/test-fixtures/_fixtures/.gitkeep similarity index 100% rename from template/test/_fixtures/.gitkeep rename to template/test-fixtures/_fixtures/.gitkeep diff --git a/template/test/_utils.ts b/template/test-fixtures/_utils.ts similarity index 100% rename from template/test/_utils.ts rename to template/test-fixtures/_utils.ts diff --git a/template/test-fixtures/cli.ts b/template/test-fixtures/cli.ts new file mode 100644 index 0000000..bea0f95 --- /dev/null +++ b/template/test-fixtures/cli.ts @@ -0,0 +1,37 @@ +import process from "node:process"; +import anyTest, { type TestFn } from "ava"; +import { Semaphore, type Permit } from "@shopify/semaphore"; +import { execa } from "execa"; +import { getBinPath } from "get-bin-path"; +import { isExecutable } from "is-executable"; +import { atFixture } from "./_utils.js"; + +const test = anyTest as TestFn<{ + binPath: string; + permit: Permit; +}>; + +test.before("setup context", async t => { + const binPath = await getBinPath(); + t.truthy(binPath, "No bin path found!"); + + t.context.binPath = binPath!.replace("dist", "src").replace(".js", ".ts"); + t.true(await isExecutable(t.context.binPath), "Source binary not executable!"); +}); + +// https://github.com/avajs/ava/discussions/3177 +const semaphore = new Semaphore(Number(process.env["concurrency"]) || 5); + +test.beforeEach("setup concurrency", async t => { + t.context.permit = await semaphore.acquire(); +}); + +test.afterEach.always(async t => { + await t.context.permit.release(); +}); + +test("main", async t => { + const {exitCode} = await execa(t.context.binPath); + + t.is(exitCode, 0); +}); diff --git a/template/test/cli.ts b/template/test/cli.ts index 897a479..a58aafd 100644 --- a/template/test/cli.ts +++ b/template/test/cli.ts @@ -1,9 +1,9 @@ +import process from "node:process"; import anyTest, { type TestFn } from "ava"; import { Semaphore, type Permit } from "@shopify/semaphore"; -import { execa, type ExecaError } from "execa"; +import { execa } from "execa"; import { getBinPath } from "get-bin-path"; import { isExecutable } from "is-executable"; -import { atFixture } from "./_utils.js"; const test = anyTest as TestFn<{ binPath: string;