Skip to content

Commit 8c90690

Browse files
committed
feat(cli): add local runner helper and better UX for CLI
1 parent b4e19c2 commit 8c90690

File tree

3 files changed

+31
-6
lines changed

3 files changed

+31
-6
lines changed

examples/basic/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ yarn ts-node ./lib/cli.ts "examples/basic/**/*.scss" --includePaths examples/bas
1212
```
1313

1414
- The glob pattern is wrapped in quotes to pass it as a string and avoid executing.
15-
- `includePaths` with `examples/basic/core` so that `@import 'variables';` is found.
15+
- `includePaths` with `examples/basic/core` so that `@import 'variables'` is found.
1616
- `aliases` with `~alias: variables` meaning any `@import '~alias'` resolves to `@import 'variables'`.
1717
- No file will be output for `variables.scss` since there are no classes.

lib/cli.ts

+28-4
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,37 @@ import { main } from "./main";
66
const nameFormatDefault: NameFormat = "camel";
77

88
const { _: patterns, includePaths, aliases, nameFormat } = yargs
9-
.demandOption("_")
10-
.option("aliases", { coerce: (obj): Aliases => obj, alias: "a" })
9+
.usage(
10+
"Generate .scss.d.ts from CSS module .scss files.\nUsage: $0 <glob pattern> [options]"
11+
)
12+
.example(
13+
"$0 src/**/*.scss",
14+
"All .scss files at any level in the src directoy"
15+
)
16+
.example(
17+
"$0 src/**/*.scss --includePaths src/core src/variables",
18+
'Search the "core" and "variables" directory when resolving imports'
19+
)
20+
.example(
21+
"$0 src/**/*.scss --aliases.~name variables",
22+
'Replace all imports for "~name" with "variables"'
23+
)
24+
.demandCommand(1)
25+
.option("aliases", {
26+
coerce: (obj): Aliases => obj,
27+
alias: "a",
28+
describe: "Alias any import to any other value."
29+
})
1130
.option("nameFormat", {
1231
choices: NAME_FORMATS,
1332
default: nameFormatDefault,
14-
alias: "n"
33+
alias: "n",
34+
describe: "The name format that should be used to transform class names."
1535
})
16-
.option("includePaths", { array: true, string: true }).argv;
36+
.option("includePaths", {
37+
array: true,
38+
string: true,
39+
describe: "Additional paths to include when trying to resolve imports."
40+
}).argv;
1741

1842
main(patterns[0], { includePaths, aliases, nameFormat });

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
"author": "Spencer Miskoviak <smiskoviak@gmail.com>",
77
"license": "MIT",
88
"scripts": {
9-
"test": "jest"
9+
"test": "jest",
10+
"tsm": "ts-node ./lib/cli.ts"
1011
},
1112
"devDependencies": {
1213
"@types/camelcase": "^4.1.0",

0 commit comments

Comments
 (0)