Skip to content

Commit

Permalink
feat: conditionally include .vscode and test/_fixtures, styling f…
Browse files Browse the repository at this point in the history
…ixes
  • Loading branch information
tommy-mitchell committed Aug 31, 2023
1 parent a94a6f0 commit 0011da2
Show file tree
Hide file tree
Showing 11 changed files with 110 additions and 24 deletions.
50 changes: 36 additions & 14 deletions .tmplr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
7 changes: 7 additions & 0 deletions template/.vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"recommendations": [
"sculpt0r.vsc-ava-test-runner",
"samverschueren.linter-xo",
"dbaeumer.vscode-eslint"
]
}
14 changes: 14 additions & 0 deletions template/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
8 changes: 8 additions & 0 deletions template/.vscode/snippets.code-snippets
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"test.todo": {
"scope": "typescript",
"prefix": "todo",
"description": "Create an AVA todo test",
"body": "test.todo(\"$1\");",
}
}
3 changes: 1 addition & 2 deletions template/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"keywords": [
"cli",
"cli-app",
"command line"
"command-line"
],
"license": "MIT",
"repository": "tommy-mitchell/{{ tmplr.project_name | skip: @tommy-mitchell/ }}",
Expand Down Expand Up @@ -35,7 +35,6 @@
"test/**/*.ts",
"!test/_*"
],
"snapshotDir": "test/_snapshots",
"extensions": {
"ts": "module"
},
Expand Down
6 changes: 3 additions & 3 deletions template/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,18 @@
## Usage

```sh
$ {{ tmplr.command_name }}
$ {{ tmplr.command_name }} --help

Usage
$ {{ tmplr.command_name }} […]

Options

--help, -h Show this help message

Examples
$ {{ tmplr.command_name }}
```

## Related

- []()
- [foo](https://github.com/foo/foo) - Does foo.
5 changes: 2 additions & 3 deletions template/src/cli.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
#!/usr/bin/env tsx
import process from "node:process";
import meow from "meow";

const cli = meow(`
Usage
$ {{ tmplr.command_name }} […]
Options
--help, -h Show this help message
Examples
$ {{ tmplr.command_name }}
Expand All @@ -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);
}
File renamed without changes.
File renamed without changes.
37 changes: 37 additions & 0 deletions template/test-fixtures/cli.ts
Original file line number Diff line number Diff line change
@@ -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);
});
4 changes: 2 additions & 2 deletions template/test/cli.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down

0 comments on commit 0011da2

Please sign in to comment.