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

feat: use template directory #3

Merged
merged 6 commits into from
Jul 10, 2023
Merged
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 .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package-lock=false
37 changes: 26 additions & 11 deletions .tmplr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ steps:

- read: project_name
prompt: 'Enter project name:'
default:
from: filesystem.rootdir

- read: project_description
prompt: 'Enter project description:'
Expand All @@ -30,39 +32,52 @@ steps:
eval: '{{ install_type | matches: dev }}'
steps:
- read: install_node
eval: 'node install --save-dev {{ project_name }}'
eval: 'npm install --save-dev {{ project_name }}'
- read: install_yarn
eval: 'yarn add --dev {{ project_name }}'

- if:
eval: '{{ install_type | matches: global }}'
steps:
- read: install_node
eval: 'node install --global {{ project_name }}'
eval: 'npm install --global {{ project_name }}'
- read: install_yarn
eval: 'yarn global add {{ project_name }}'

- if:
eval: '{{ install_type | matches: dep }}'
steps:
- read: install_node
eval: 'node install {{ project_name }}'
eval: 'npm install {{ project_name }}'
- read: install_yarn
eval: 'yarn add {{ project_name }}'

# setup project
# make sure to copy "hidden"/dot files (loreanvictor/tmplr#14)

- copy: ./template/**/*
to: ./

- update: src/cli.ts
- update: test/test.ts
- copy: ./template/**/.**/**/*
to: ./

- copy: package.tmplr.json
to: package.json
- copy: ./template/**/.*
to: ./

- copy: readme.tmplr.md
to: readme.md
- copy: ./template/**/.**/**/.*
to: ./

# finish
# temporaryily specify folders to remove (loreanvictor/tmplr#15)

- remove: ./template/**/*
- remove: ./template/**/.**/**/*
- remove: ./template/**/.*
- remove: ./template/**/.**/**/.*

- remove: ./template/.github
- remove: ./template/src
- remove: ./template/test
- remove: ./template

- remove: .tmplr.yml
- remove: package.tmplr.json
- remove: readme.tmplr.md
File renamed without changes.
88 changes: 0 additions & 88 deletions package.tmplr.json

This file was deleted.

2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ npx tmplr tommy-mitchell/cli-template
yarn install
```

Run inside of desired installation directory.
Run inside of desired installation directory, then add `test/tsconfig.json` to git exclude. Requires `tmplr` v0.2.4 or higher.
19 changes: 19 additions & 0 deletions template/.github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: CI
on:
- push
- pull_request
jobs:
test:
name: Node.js ${{ matrix.node-version }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
node-version: [16, 18, 20]
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- run: npm install
- run: npm run ci
1 change: 1 addition & 0 deletions .gitignore → template/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
node_modules
coverage
dist
package-lock.json
yarn.lock
17 changes: 17 additions & 0 deletions template/.xo-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"rules": {
"arrow-parens": "off",
"quotes": "off",
"@typescript-eslint/quotes": ["error", "double"],
"object-curly-spacing": "off",
"@typescript-eslint/object-curly-spacing": ["error", "always"],
"@typescript-eslint/no-confusing-void-expression": ["error", { "ignoreArrowShorthand": true }],
"object-shorthand": ["error", "always", { "avoidExplicitReturnArrows": false }],
"@typescript-eslint/keyword-spacing": ["error", { "overrides": {
"if": { "after": false },
"for": {"after": false },
"while": {"after": false },
"catch": {"after": false }
}}]
}
}
61 changes: 61 additions & 0 deletions template/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{
"name": "{{ tmplr.project_name }}",
"version": "0.0.0",
"description": "{{ tmplr.project_description }}",
"keywords": [
"cli",
"cli-app",
"command line"
],
"license": "MIT",
"repository": "tommy-mitchell/{{ tmplr.project_name | skip: @tommy-mitchell/ }}",
"author": {
"name": "Tommy Mitchell",
"url": "https://tommymitchell.io"
},
"type": "module",
"bin": {
"{{ tmplr.command_name }}": "dist/cli.js"
},
"files": [
"dist"
],
"scripts": {
"prepublishOnly": "npm run build",
"build": "tsc && chmodx --package",
"postbuild": "replace-in-files dist/cli.js --string='#!/usr/bin/env tsx' --replacement='#!/usr/bin/env node'",
"test": "listr xo 'c8 ava'"
},
"dependencies": {
"meow": "^12.0.1"
},
"devDependencies": {
"@johnowennixon/chmodx": "1.1.0",
"@tommy-mitchell/tsconfig": "^1.0.0",
"@types/node": "^16",
"ava": "^5.3.1",
"c8": "^8.0.0",
"execa": "^7.1.1",
"get-bin-path": "^10.0.0",
"is-executable": "^2.0.1",
"listr-cli": "^0.3.0",
"replace-in-files-cli": "^2.2.0",
"tsx": "^3.12.7",
"typescript": "~5.1.6",
"xo": "^0.54.2"
},
"engines": {
"node": ">=16"
},
"ava": {
"files": [
"test/*.ts"
],
"extensions": {
"ts": "module"
},
"nodeArguments": [
"--loader=tsx"
]
}
}
6 changes: 2 additions & 4 deletions readme.tmplr.md → template/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,19 @@
```
</details>

*Uses top-level await. Requires Node 14.8 or higher.*

## Usage

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

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

Options


Examples

$ {{ tmplr.command_name }}
```

## Related
13 changes: 9 additions & 4 deletions src/cli.ts → template/src/cli.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
#!/usr/bin/env node
import process from "node:process";
import meow from "meow";

const cli = meow(`
Usage
$ {{ tmplr.command_name }}
$ {{ tmplr.command_name }} […]

Options


Examples

$ {{ tmplr.command_name }}
`, {
importMeta: import.meta,
description: false,
help: {
type: "boolean",
shortFlag: "h",
}
});

const {input} = cli;
const {help: helpShortFlag} = cli.flags;
const { input, flags: { help: helpShortFlag } } = cli;

if(input.length === 0 || helpShortFlag) {
cli.showHelp(0);
Expand Down
7 changes: 7 additions & 0 deletions template/test/_utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { fileURLToPath } from "node:url";
import path from "node:path";
import { type Options as ExecaOptions } from "execa";

export const __dirname = path.dirname(fileURLToPath(import.meta.url));

export const atFixture = (name: string): ExecaOptions => ({cwd: `${__dirname}/fixtures/${name}`});
26 changes: 26 additions & 0 deletions template/test/cli.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import anyTest, { type TestFn } from "ava";
import { getBinPath } from "get-bin-path";
import { isExecutable } from "is-executable";
import {execa, type ExecaError} from "execa";
import { __dirname, atFixture } from "./_utils.js";

const test = anyTest as TestFn<{
binPath: string;
helpText: string[];
}>;

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!");

t.context.helpText = [];
});

test("main", async t => {
const {exitCode} = await execa(t.context.binPath);

t.is(exitCode, 0);
});
Empty file added template/test/fixtures/.gitkeep
Empty file.
3 changes: 3 additions & 0 deletions template/test/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "../tsconfig.test.json"
}
9 changes: 9 additions & 0 deletions template/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "@tommy-mitchell/tsconfig",
"exclude": ["node_modules", "coverage", "dist"],
"include": ["src"],
"compilerOptions": {
"outDir": "dist",
"declaration": false
},
}
9 changes: 9 additions & 0 deletions template/tsconfig.test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "./tsconfig.json",
"exclude": ["src"],
"include": ["test"],
"compilerOptions": {
"noEmit": true,
"noUnusedLocals": false,
},
}
9 changes: 0 additions & 9 deletions test/test.ts

This file was deleted.

Loading