diff --git a/.github/workflows/pipeline.yaml b/.github/workflows/pipeline.yaml index 9fe66a9..55d8861 100644 --- a/.github/workflows/pipeline.yaml +++ b/.github/workflows/pipeline.yaml @@ -53,11 +53,11 @@ jobs: matrix: node: - 20.x - - 22.x + #- 22.x platform: - os: ubuntu - - os: macos - - os: windows + #- os: macos + #- os: windows fail-fast: false steps: @@ -78,50 +78,55 @@ jobs: - name: "Test 1: default case" run: | - scripts/test.sh foo '' '*.css' + cp fixtures/foo.css $RUNNER_TEMP/test.css + cp fixtures/foo.d.css.ts $RUNNER_TEMP/expected.d.css.ts + + cd $RUNNER_TEMP + $GITHUB_WORKSPACE/dist/main.js "*.css" + diff --color=always --strip-trailing-cr -uI "//.*" expected.d.css.ts test.d.css.ts - name: "Test 2: localsConvention, first position" if: success() || failure() run: | - scripts/test.sh casing/casing '' '--localsConvention camelCaseOnly *.css' casing/camelCaseOnly + scripts/test-gen.sh 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-gen.sh 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-gen.sh 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-gen.sh 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-gen.sh foo csstypedrc.json - name: "Test 7: yaml file config" if: success() || failure() run: | - scripts/test.sh foo csstypedrc.yaml '' '' generated/ + scripts/test-gen.sh 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-gen.sh 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-gen.sh foo custom-config-path.config.mjs '-c .config/custom-config-path.config.mjs' Publish: if: ${{ github.ref == 'refs/heads/main' }} diff --git a/scripts/test.sh b/scripts/test-gen.sh similarity index 87% rename from scripts/test.sh rename to scripts/test-gen.sh index 4f2f526..b40fab7 100755 --- a/scripts/test.sh +++ b/scripts/test-gen.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -set -eo pipefail # Removed `-u` which failed on macos for `options` +set -exo 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. @@ -31,9 +31,8 @@ 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[@]}" -# shellcheck disable=SC2068 -$GITHUB_WORKSPACE/dist/main.js ${options[@]} +echo "css-typed gen" "${options[@]}" +$GITHUB_WORKSPACE/dist/main.js gen "${options[@]}" # Use `diff` to compare the files. # Use `-I '//.*'` to ignore the first line (comment) which has generated path and timestamp. diff --git a/src/cli/command-utils.ts b/src/cli/command-utils.ts index 8989da4..c592291 100644 --- a/src/cli/command-utils.ts +++ b/src/cli/command-utils.ts @@ -42,6 +42,11 @@ function cssTypedAction( ) { return this.action( async (cliPattern, { config: cliConfigPath, ...cliOptions }, program) => { + console.debug(`[debug] CLI input:`, `pattern=${cliPattern}`, { + config: cliConfigPath, + ...cliOptions, + }); + // Load file configuration first const configResult = await loadFileConfig(cliConfigPath); if (configResult?.filepath) { @@ -60,6 +65,7 @@ function cssTypedAction( // Resolve options from file config and CLI. CLI overrides file config. const options: Options = { ...fileConfig, ...cliOptions }; + console.debug(`[debug] Resolved options to`, options); // Pattern is required. CLI overrides file config. const pattern = cliPattern ?? filePattern; diff --git a/src/main.ts b/src/main.ts index 7500a94..6bcfd95 100755 --- a/src/main.ts +++ b/src/main.ts @@ -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();