Skip to content

Commit

Permalink
ci(linting-tools): Update package to use tsup build process
Browse files Browse the repository at this point in the history
  • Loading branch information
sullivanpj committed Jan 11, 2025
1 parent f5a2bbc commit 14eeb47
Show file tree
Hide file tree
Showing 10 changed files with 506 additions and 411 deletions.
2 changes: 1 addition & 1 deletion .vscode/cspell.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"import": ["../dist/packages/linting-tools/cspell/config.json"]
"import": ["../dist/packages/cspell/cspell-recommended.json"]
}
4 changes: 2 additions & 2 deletions packages/eslint/src/utils/banner-plugin.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ESLintUtils } from "@typescript-eslint/utils";
import { ESLint, Linter, Rule } from "eslint";
import { ESLint, Linter } from "eslint";
import os from "node:os";
import { CODE_FILE } from "./constants";
import { getFileBanner } from "./get-file-banner";
Expand Down Expand Up @@ -434,7 +434,7 @@ const plugin: ESLint.Plugin = {
},
configs: {} as Record<string, Linter.Config<Linter.RulesRecord>>,
rules: {
banner: bannerRule as Rule.RuleModule
banner: bannerRule as any
},
processors: {}
};
Expand Down
220 changes: 106 additions & 114 deletions packages/git-tools/src/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,120 +15,112 @@ import type { ReadMeOptions } from "../types";
let _config: Partial<StormConfig> = {};

export function createProgram(config: StormConfig) {
try {
_config = config;
writeInfo("⚡ Running Storm Git Tools", config);

// const commander = await import("commander");

const root = findWorkspaceRootSafe(process.cwd());
process.env.STORM_WORKSPACE_ROOT ??= root;
process.env.NX_WORKSPACE_ROOT_PATH ??= root;
root && process.chdir(root);

const program = new Command("storm-git");
program.version("1.0.0", "-v --version", "display CLI version");

const commitConfig = new Option(
"--config <file>",
"The Commitizen config file path"
).default("@storm-software/git-tools/commit/config");

const commitDryRun = new Option(
"--dry-run",
"Should the commit be run in dry-run mode (no updates are made)"
);

program
.command("commit")
.description("Commit changes to git for the workspace.")
.addOption(commitConfig)
.addOption(commitDryRun)
.action(commitAction);

const readmeTemplatePath = new Option(
"--templates <path>",
"The templates directory to use when generating the README.md files."
).default("./tools/readme-templates");

const readmePackageName = new Option(
"--project <project>",
"The specific project to generate a README.md file for"
);

const readmeOutput = new Option(
"--output <path>",
"Where to output the generated README.md file"
);

const readmeClean = new Option(
"--clean",
"Should the output README.md file be cleaned before generation"
).default(true);

const readmePrettier = new Option(
"--prettier",
"Should the output README.md file have prettier applied to it"
).default(true);

program
.command("readme")
.description("Run the README.md generator using the templates provided.")
.addOption(readmeTemplatePath)
.addOption(readmePackageName)
.addOption(readmeOutput)
.addOption(readmeClean)
.addOption(readmePrettier)
.action(readmeAction);

const releasePackageName = new Option(
"--project <project>",
"The specific project to run release for"
);

const releaseBase = new Option("--base <base>", "Git base tag value");
const releaseHead = new Option("--head <head>", "Git head tag value");

const releaseDryRun = new Option(
"--dry-run",
"Should the release be run in dry-run mode (no updates are made)"
);

program
.command("release")
.description("Run release for a project in the workspace.")
.addOption(releasePackageName)
.addOption(releaseBase)
.addOption(releaseHead)
.addOption(releaseDryRun)
.action(releaseAction);

const commitMessage = new Option(
"--message <commit-message>",
"The commit message to lint"
).makeOptionMandatory(false);

const commitFile = new Option(
"--file <commit-file>",
"The commit message to lint"
).makeOptionMandatory(false);

program
.command("commitlint")
.description("Run commitlint for the workspace's commit message.")
.addOption(commitConfig)
.addOption(commitMessage)
.addOption(commitFile)
.action(commitLintAction);

return program;
} catch (error) {
writeFatal(
`A fatal error occurred while preparing the Storm Git-Tools program: \n\n${error.message}`,
config
);
throw new Error(error.message, { cause: error });
}
_config = config;
writeInfo("⚡ Running Storm Git Tools", config);

// const commander = await import("commander");

const root = findWorkspaceRootSafe(process.cwd());
process.env.STORM_WORKSPACE_ROOT ??= root;
process.env.NX_WORKSPACE_ROOT_PATH ??= root;
root && process.chdir(root);

const program = new Command("storm-git");
program.version("1.0.0", "-v --version", "display CLI version");

const commitConfig = new Option(
"--config <file>",
"The Commitizen config file path"
).default("@storm-software/git-tools/commit/config");

const commitDryRun = new Option(
"--dry-run",
"Should the commit be run in dry-run mode (no updates are made)"
);

program
.command("commit")
.description("Commit changes to git for the workspace.")
.addOption(commitConfig)
.addOption(commitDryRun)
.action(commitAction);

const readmeTemplatePath = new Option(
"--templates <path>",
"The templates directory to use when generating the README.md files."
).default("./tools/readme-templates");

const readmePackageName = new Option(
"--project <project>",
"The specific project to generate a README.md file for"
);

const readmeOutput = new Option(
"--output <path>",
"Where to output the generated README.md file"
);

const readmeClean = new Option(
"--clean",
"Should the output README.md file be cleaned before generation"
).default(true);

const readmePrettier = new Option(
"--prettier",
"Should the output README.md file have prettier applied to it"
).default(true);

program
.command("readme")
.description("Run the README.md generator using the templates provided.")
.addOption(readmeTemplatePath)
.addOption(readmePackageName)
.addOption(readmeOutput)
.addOption(readmeClean)
.addOption(readmePrettier)
.action(readmeAction);

const releasePackageName = new Option(
"--project <project>",
"The specific project to run release for"
);

const releaseBase = new Option("--base <base>", "Git base tag value");
const releaseHead = new Option("--head <head>", "Git head tag value");

const releaseDryRun = new Option(
"--dry-run",
"Should the release be run in dry-run mode (no updates are made)"
);

program
.command("release")
.description("Run release for a project in the workspace.")
.addOption(releasePackageName)
.addOption(releaseBase)
.addOption(releaseHead)
.addOption(releaseDryRun)
.action(releaseAction);

const commitMessage = new Option(
"--message <commit-message>",
"The commit message to lint"
).makeOptionMandatory(false);

const commitFile = new Option(
"--file <commit-file>",
"The commit message to lint"
).makeOptionMandatory(false);

program
.command("commitlint")
.description("Run commitlint for the workspace's commit message.")
.addOption(commitConfig)
.addOption(commitMessage)
.addOption(commitFile)
.action(commitLintAction);

return program;
}

export async function commitAction({
Expand Down
10 changes: 2 additions & 8 deletions packages/linting-tools/bin/lint.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env node

import {
exitWithError,
exitWithSuccess,
Expand All @@ -6,9 +8,6 @@ import {
writeFatal,
writeSuccess
} from "@storm-software/config-tools";
import { readJsonSync } from "fs-extra";
import { join } from "node:path";
import { register as registerTsConfigPaths } from "tsconfig-paths";
import { createProgram } from "../src/cli";

Error.stackTraceLimit = Infinity;
Expand All @@ -18,11 +17,6 @@ void (async () => {
try {
handleProcess(config);

const compilerOptions = readJsonSync(
join(config.workspaceRoot ?? "./", "tsconfig.base.json")
).compilerOptions;
registerTsConfigPaths(compilerOptions);

const program = await createProgram(config);
program.exitOverride();

Expand Down
Loading

0 comments on commit 14eeb47

Please sign in to comment.