Skip to content

Commit 4c603d2

Browse files
committed
refactor: restructure all examples to use directories.bin approach to command names
1 parent de7912e commit 4c603d2

41 files changed

Lines changed: 490 additions & 86 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

examples/dev-command/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ A distributable command-line app
44

55
# Notes
66

7-
- [Command.ts](./src/Command.ts) is a plugin that defines the command. See [@battis/qui-cli.plugin](../../packages/plugin/README.md#usage) for plugin documentation.
8-
- [index.ts](./src/index.ts) registers the `Command` plugin and run the app.
9-
- [package.json](./package.json) `bin` points to compiled script
7+
- [index.ts](./src/index.ts) implements the command.
8+
- [package.json](./package.json) `directories.bin` points to directory of registered scripts.
9+
- [bin/dev-command](./bin/dev-command) is executable (`chmod +x`) and has the standard node shebang, and imports the command -- this structure allows for reliable use of the command across different package managers.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/usr/bin/env node
2+
import '../dist/index.js';

examples/dev-command/package.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
"type": "module",
1515
"main": "./dist/index.js",
1616
"types": "./dist/index.d.ts",
17-
"bin": {
18-
"myCommand": "./dist/index.js"
17+
"directories": {
18+
"bin": "./bin"
1919
},
2020
"scripts": {
2121
"clean": "del ./dist",
@@ -26,8 +26,7 @@
2626
"dependencies": {
2727
"@battis/qui-cli.colors": "workspace:*",
2828
"@battis/qui-cli.core": "workspace:*",
29-
"@battis/qui-cli.log": "workspace:*",
30-
"@battis/qui-cli.plugin": "workspace:*"
29+
"@battis/qui-cli.log": "workspace:*"
3130
},
3231
"devDependencies": {
3332
"@tsconfig/node20": "^20.1.6",

examples/dev-command/src/Command.ts

Lines changed: 0 additions & 35 deletions
This file was deleted.

examples/dev-command/src/index.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,19 @@
1+
import { Colors } from '@battis/qui-cli.colors';
12
import { Core } from '@battis/qui-cli.core';
2-
import { register } from '@battis/qui-cli.plugin';
3-
import * as Command from './Command.js';
3+
import { Log } from '@battis/qui-cli.log';
4+
5+
const {
6+
values: { foo }
7+
} = await Core.init({
8+
opt: {
9+
foo: {
10+
description: 'Type of foo-ness'
11+
}
12+
}
13+
});
414

5-
await register(Command);
615
await Core.run();
16+
17+
Log.info(
18+
`The value of ${Colors.value('foo')} is ${Colors.quotedValue(`"${foo}"`)}`
19+
);

examples/dev-plugin/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Defines a reusable plugin package
1010

1111
- [src/MyPlugin.ts](./plugin-provider/src/MyPlugin.ts) defines a reusable plugin. See [@battis/qui-cli.plugin](../../packages/plugin/README.md#usage) for plugin documentation.
1212
- [src/index.ts](./plugin-provider/src/index.ts) registers and exports the plugin for re-use.
13-
- [package.json](./plugin-provider/package.json) defines its dependency on another plugin ([@battis/qui-cli.log](../../packages/log/)) as a peer with a more lenient version descriptor than the dev dependency that is used for local development, trusting semantic versioning.
13+
- [package.json](./plugin-provider/package.json) defines its dependency on another plugin ([@battis/qui-cli.log](../../packages/log/)) as a peer with a more lenient version descriptor than the dev dependency that is used for local development, trusting semantic versioning. Peering assures that this plugin and its dependencies will be hoisted to the same level when imported into other projects.
1414

1515
## Consumers
1616

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"name": "@examples/dev-plugin.conflict",
3+
"version": "0.0.0",
4+
"homepage": "https://github.com/battis/qui-cli/tree/main/examples/dev-plugin/plugin-conflict#readme",
5+
"repository": {
6+
"type": "git",
7+
"url": "https://github.com/battis/qui-cli.git",
8+
"directory": "examples/dev-plugin/plugin-conflict"
9+
},
10+
"author": {
11+
"name": "Seth Battis",
12+
"url": "https://github.com/battis"
13+
},
14+
"type": "module",
15+
"main": "./dist/index.js",
16+
"types": "./dist/index.d.ts",
17+
"directories": {
18+
"bin": ":./bin"
19+
},
20+
"scripts": {
21+
"clean": "del ./dist",
22+
"build": "run-s build:*",
23+
"build:clean": "run-s clean",
24+
"build:compile": "tsc"
25+
},
26+
"dependencies": {
27+
"@battis/qui-cli.core": "workspace:*",
28+
"@battis/qui-cli.log": "workspace:*",
29+
"@battis/qui-cli.plugin": "workspace:*",
30+
"@examples/dev-plugin.provider": "workspace:*"
31+
},
32+
"devDependencies": {
33+
"@tsconfig/node20": "^20.1.6",
34+
"del-cli": "^6.0.0",
35+
"npm-run-all": "^4.1.5",
36+
"typescript": "^5.8.3"
37+
}
38+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import { Log } from '@battis/qui-cli.log';
2+
import * as Plugin from '@battis/qui-cli.plugin';
3+
4+
export type Configuration = Plugin.Configuration & {
5+
foo?: string;
6+
};
7+
8+
export const name = 'my-plugin';
9+
10+
let foo = 'foob';
11+
let bar: string | undefined = undefined;
12+
let baz = false;
13+
14+
export function configure(config: Configuration = {}) {
15+
foo = Plugin.hydrate(config.foo, foo);
16+
}
17+
18+
export function options(): Plugin.Options {
19+
return {
20+
opt: {
21+
foo: {
22+
description: `Type of foo-ness (default ${foo})`,
23+
default: foo
24+
},
25+
bar: {
26+
description: 'Type of bar-ness'
27+
}
28+
},
29+
flag: {
30+
baz: {
31+
description: `Whether or not to baz (default ${baz})`,
32+
default: baz
33+
}
34+
}
35+
};
36+
}
37+
38+
export function init({ values }: Plugin.Arguments<ReturnType<typeof options>>) {
39+
foo = Plugin.hydrate(values.foo, foo);
40+
bar = Plugin.hydrate(values.bar, bar);
41+
baz = Plugin.hydrate(values.baz, baz);
42+
}
43+
44+
export function run() {
45+
Log.info(`${foo} ${bar} ${baz ? 'baz' : 'not-baz'}`);
46+
}
47+
48+
export function getFoo() {
49+
return foo;
50+
}
51+
52+
export function isBaz() {
53+
return baz;
54+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { register } from '@battis/qui-cli.plugin';
2+
import { MyPlugin } from '@examples/dev-plugin.provider';
3+
import { Core } from '../../../../packages/core/dist/index.js';
4+
import * as ConflictingPlugin from './ConflictingPlugin.js';
5+
6+
// no problem re-registering a plugin that has already been registered
7+
await register(MyPlugin);
8+
9+
// cannot register a _different_ plugin with the same name!
10+
await register(ConflictingPlugin);
11+
12+
await Core.run();
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"extends": "@tsconfig/node20/tsconfig.json",
3+
"compilerOptions": {
4+
"outDir": "./dist"
5+
},
6+
"include": ["./src"]
7+
}

0 commit comments

Comments
 (0)