Skip to content

Commit

Permalink
✨ Generate subcommand
Browse files Browse the repository at this point in the history
Adds `gen` subcommand (aliased with `generate`). Preserves command-less
invocation as generate.

Tweaks pipeline tests to allow for new `gen` subcommand.

semver:minor
  • Loading branch information
connorjs committed Aug 4, 2024
1 parent bf68221 commit f876938
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 22 deletions.
18 changes: 9 additions & 9 deletions .github/workflows/pipeline.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -78,50 +78,50 @@ jobs:

- name: "Test 1: default case"
run: |
scripts/test.sh foo '' '*.css'
scripts/test.sh '' foo '' '*.css'
- name: "Test 2: localsConvention, first position"
if: success() || failure()
run: |
scripts/test.sh casing/casing '' '--localsConvention camelCaseOnly *.css' casing/camelCaseOnly
scripts/test.sh gen casing/casing '' '--localsConvention camelCaseOnly *.css' casing/camelCaseOnly
- name: "Test 3: localsConvention, second position"
if: success() || failure()
run: |
scripts/test.sh casing/casing '' '*.css --localsConvention camelCaseOnly' casing/camelCaseOnly
scripts/test.sh gen casing/casing '' '*.css --localsConvention camelCaseOnly' casing/camelCaseOnly
- name: "Test 4: relative outdir"
if: success() || failure()
run: |
scripts/test.sh foo '' '--outdir generated *.css' '' generated/
scripts/test.sh gen foo '' '--outdir generated *.css' '' generated/
- name: "Test 5: absolute outdir"
if: success() || failure()
run: |
scripts/test.sh foo "" "-o $GITHUB_WORKSPACE/generated *.css" "" "$GITHUB_WORKSPACE"/generated/
scripts/test.sh gen foo "" "-o $GITHUB_WORKSPACE/generated *.css" "" "$GITHUB_WORKSPACE"/generated/
# Note: This test uses double quotes, which expands differently.

- name: "Test 6: json file config"
if: success() || failure()
run: |
scripts/test.sh foo csstypedrc.json
scripts/test.sh gen foo csstypedrc.json
- name: "Test 7: yaml file config"
if: success() || failure()
run: |
scripts/test.sh foo csstypedrc.yaml '' '' generated/
scripts/test.sh gen foo csstypedrc.yaml '' '' generated/
- name: "Test 8: custom config path"
if: success() || failure()
run: |
scripts/test.sh foo css-typed-rc.yaml '-c .config/css-typed-rc.yaml'
scripts/test.sh gen foo css-typed-rc.yaml '-c .config/css-typed-rc.yaml'
- name: "Test 9: mjs file config"
if: matrix.platform.os != 'windows' && (success() || failure())
# Do not run on Windows due to Windows-only ESM import bug.
# This _could_ be an issue with css-typed, but could be a test/deps issue.
run: |
scripts/test.sh foo custom-config-path.config.mjs '-c .config/custom-config-path.config.mjs'
scripts/test.sh gen foo custom-config-path.config.mjs '-c .config/custom-config-path.config.mjs'
Publish:
if: ${{ github.ref == 'refs/heads/main' }}
Expand Down
27 changes: 15 additions & 12 deletions scripts/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,23 @@
set -eo pipefail # Removed `-u` which failed on macos for `options`
IFS=$' ' # We want space splitting for this script

# $1 is the input name, relative to `fixtures`. Required.
input=$1
# $1 is the subcommand to run
subcommand=$1

# $2 is the config file name, relative to `fixtures/config`. Defaults to $1.yaml.
config=${2:-$1.yaml}
# $2 is the input name, relative to `fixtures`. Required.
input=$2

# $3 is the options. Defaults to "".
read -r -a options <<< "${3:-}"
# $3 is the config file name, relative to `fixtures/config`. Defaults to $2.yaml.
config=${3:-$2.yaml}

# $4 is the output name, relative to `fixtures`. Defaults to $1.
output=${4:-$1}
# $4 is the options. Defaults to "".
read -r -a options <<< "${4:-}"

# $5 is the path prefix for output. Defaults to "".
prefix=${5:-}
# $5 is the output name, relative to `fixtures`. Defaults to $1.
output=${5:-$2}

# $6 is the path prefix for output. Defaults to "".
prefix=${6:-}

# Run from $RUNNER_TEMP for auto-cleanup.
cp fixtures/${input}.css $RUNNER_TEMP/test.css
Expand All @@ -31,9 +34,9 @@ pushd $RUNNER_TEMP > /dev/null || exit

# `./dist/main.js` is executing local `css-typed` as if installed (same as `bin`).
# But it is `$GITHUB_WORKSPACE/dist/main.js` b/c we `cd $RUNNER_TEMP`.
echo "css-typed " "${options[@]}"
echo "css-typed ${subcommand}" "${options[@]}"
# shellcheck disable=SC2068
$GITHUB_WORKSPACE/dist/main.js ${options[@]}
$GITHUB_WORKSPACE/dist/main.js ${subcommand} ${options[@]}

# Use `diff` to compare the files.
# Use `-I '//.*'` to ignore the first line (comment) which has generated path and timestamp.
Expand Down
10 changes: 9 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,16 @@ import { version } from "./version.ts";
await createCssTypedCommand()
.name(`css-typed`)
.description(
`TypeScript declaration generator for CSS files (and other stylesheets).`,
`TypeScript declaration generator for CSS files (and other stylesheets).\n\nRuns \`generate\` when no subcommand given.`,
)
.version(version)
.cssTypedAction(generate)
.helpCommand(`help [command]`, `Displays help for the given command.`)
.addCommand(
createCssTypedCommand()
.name(`gen`)
.alias(`generate`)
.description(`Generates TypeScript declaration files.`)
.cssTypedAction(generate),
)
.parseAsync();

0 comments on commit f876938

Please sign in to comment.