alex-c-line 1.27.0 → 1.28.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/configs/index.d.cts +13 -6
- package/dist/configs/index.d.ts +13 -6
- package/dist/configs/internal/index.d.cts +21 -8
- package/dist/configs/internal/index.d.ts +21 -8
- package/dist/index.cjs +54 -30
- package/dist/index.js +55 -31
- package/package.json +1 -1
package/dist/configs/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CreateEnumType } from "@alextheman/utility";
|
|
2
|
-
import { Result, TemplateExpression } from "execa";
|
|
2
|
+
import { Options, Result, TemplateExpression } from "execa";
|
|
3
3
|
|
|
4
4
|
//#region src/configs/types/CreatePullRequestTemplateConfig.d.ts
|
|
5
5
|
interface CreatePullRequestTemplateBaseConfig {
|
|
@@ -22,6 +22,17 @@ interface CreatePullRequestTemplateInfrastructureConfig extends CreatePullReques
|
|
|
22
22
|
}
|
|
23
23
|
type CreatePullRequestTemplateConfig = CreatePullRequestTemplateGeneralConfig | CreatePullRequestTemplateInfrastructureConfig;
|
|
24
24
|
//#endregion
|
|
25
|
+
//#region src/commands/pre-commit/createStepRunner.d.ts
|
|
26
|
+
interface BaseOptions {
|
|
27
|
+
stdio: "inherit";
|
|
28
|
+
reject: false;
|
|
29
|
+
}
|
|
30
|
+
interface StepRunner<ExecaOptions extends Options = BaseOptions> {
|
|
31
|
+
<NewOpts extends Options>(options: NewOpts): StepRunner<ExecaOptions & NewOpts>;
|
|
32
|
+
(command: string, args?: readonly string[]): Promise<Result<ExecaOptions>>;
|
|
33
|
+
(strings: TemplateStringsArray, ...interpolations: TemplateExpression[]): Promise<Result<ExecaOptions>>;
|
|
34
|
+
}
|
|
35
|
+
//#endregion
|
|
25
36
|
//#region src/configs/types/PreCommitConfig.d.ts
|
|
26
37
|
declare const PackageManager: {
|
|
27
38
|
readonly NPM: "npm";
|
|
@@ -32,10 +43,6 @@ interface PreCommitStepOptions {
|
|
|
32
43
|
/** Arguments to pass to the given script */
|
|
33
44
|
arguments?: string[];
|
|
34
45
|
}
|
|
35
|
-
interface StepRunner {
|
|
36
|
-
(command: string, args?: readonly string[]): Promise<Result>;
|
|
37
|
-
(strings: TemplateStringsArray, ...interpolations: TemplateExpression[]): Promise<Result>;
|
|
38
|
-
}
|
|
39
46
|
type StepFunction = (stepRunner: StepRunner) => void | Promise<void>;
|
|
40
47
|
interface PreCommitConfig<ScriptName extends string = string> {
|
|
41
48
|
/** The name of the package manager being used (can choose from `npm` or `pnpm`). If not provided, can be inferred from the packageManager field in package.json. */
|
|
@@ -116,4 +123,4 @@ interface PreCommitPrivateConfig<ScriptName extends string = string> {
|
|
|
116
123
|
//#region src/configs/helpers/definePreCommitPrivateConfig.d.ts
|
|
117
124
|
declare function definePreCommitPrivateConfig<ScriptName extends string = string>(config: PreCommitPrivateConfig<ScriptName>): PreCommitPrivateConfig<ScriptName>;
|
|
118
125
|
//#endregion
|
|
119
|
-
export { AlexCLineConfig, ConfigFileName, CreatePullRequestTemplateBaseConfig, CreatePullRequestTemplateConfig, CreatePullRequestTemplateGeneralConfig, CreatePullRequestTemplateInfrastructureConfig, DependencyGroup, PackageManager, PreCommitConfig, PreCommitStepOptions, PullRequestTemplateCategory, StepFunction,
|
|
126
|
+
export { AlexCLineConfig, ConfigFileName, CreatePullRequestTemplateBaseConfig, CreatePullRequestTemplateConfig, CreatePullRequestTemplateGeneralConfig, CreatePullRequestTemplateInfrastructureConfig, DependencyGroup, PackageManager, PreCommitConfig, PreCommitStepOptions, PullRequestTemplateCategory, StepFunction, defineAlexCLineConfig, defineAlexCLinePrivateConfig, defineCreatePullRequestTemplateConfig, definePreCommitConfig, definePreCommitPrivateConfig };
|
package/dist/configs/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { CreateEnumType } from "@alextheman/utility";
|
|
2
2
|
import z from "zod";
|
|
3
|
-
import { Result, TemplateExpression } from "execa";
|
|
3
|
+
import { Options, Result, TemplateExpression } from "execa";
|
|
4
4
|
|
|
5
5
|
//#region src/configs/types/CreatePullRequestTemplateConfig.d.ts
|
|
6
6
|
interface CreatePullRequestTemplateBaseConfig {
|
|
@@ -23,6 +23,17 @@ interface CreatePullRequestTemplateInfrastructureConfig extends CreatePullReques
|
|
|
23
23
|
}
|
|
24
24
|
type CreatePullRequestTemplateConfig = CreatePullRequestTemplateGeneralConfig | CreatePullRequestTemplateInfrastructureConfig;
|
|
25
25
|
//#endregion
|
|
26
|
+
//#region src/commands/pre-commit/createStepRunner.d.ts
|
|
27
|
+
interface BaseOptions {
|
|
28
|
+
stdio: "inherit";
|
|
29
|
+
reject: false;
|
|
30
|
+
}
|
|
31
|
+
interface StepRunner<ExecaOptions extends Options = BaseOptions> {
|
|
32
|
+
<NewOpts extends Options>(options: NewOpts): StepRunner<ExecaOptions & NewOpts>;
|
|
33
|
+
(command: string, args?: readonly string[]): Promise<Result<ExecaOptions>>;
|
|
34
|
+
(strings: TemplateStringsArray, ...interpolations: TemplateExpression[]): Promise<Result<ExecaOptions>>;
|
|
35
|
+
}
|
|
36
|
+
//#endregion
|
|
26
37
|
//#region src/configs/types/PreCommitConfig.d.ts
|
|
27
38
|
declare const PackageManager: {
|
|
28
39
|
readonly NPM: "npm";
|
|
@@ -33,10 +44,6 @@ interface PreCommitStepOptions {
|
|
|
33
44
|
/** Arguments to pass to the given script */
|
|
34
45
|
arguments?: string[];
|
|
35
46
|
}
|
|
36
|
-
interface StepRunner {
|
|
37
|
-
(command: string, args?: readonly string[]): Promise<Result>;
|
|
38
|
-
(strings: TemplateStringsArray, ...interpolations: TemplateExpression[]): Promise<Result>;
|
|
39
|
-
}
|
|
40
47
|
type StepFunction = (stepRunner: StepRunner) => void | Promise<void>;
|
|
41
48
|
interface PreCommitConfig<ScriptName extends string = string> {
|
|
42
49
|
/** The name of the package manager being used (can choose from `npm` or `pnpm`). If not provided, can be inferred from the packageManager field in package.json. */
|
|
@@ -117,4 +124,4 @@ interface PreCommitPrivateConfig<ScriptName extends string = string> {
|
|
|
117
124
|
//#region src/configs/helpers/definePreCommitPrivateConfig.d.ts
|
|
118
125
|
declare function definePreCommitPrivateConfig<ScriptName extends string = string>(config: PreCommitPrivateConfig<ScriptName>): PreCommitPrivateConfig<ScriptName>;
|
|
119
126
|
//#endregion
|
|
120
|
-
export { AlexCLineConfig, ConfigFileName, CreatePullRequestTemplateBaseConfig, CreatePullRequestTemplateConfig, CreatePullRequestTemplateGeneralConfig, CreatePullRequestTemplateInfrastructureConfig, DependencyGroup, PackageManager, PreCommitConfig, PreCommitStepOptions, PullRequestTemplateCategory, StepFunction,
|
|
127
|
+
export { AlexCLineConfig, ConfigFileName, CreatePullRequestTemplateBaseConfig, CreatePullRequestTemplateConfig, CreatePullRequestTemplateGeneralConfig, CreatePullRequestTemplateInfrastructureConfig, DependencyGroup, PackageManager, PreCommitConfig, PreCommitStepOptions, PullRequestTemplateCategory, StepFunction, defineAlexCLineConfig, defineAlexCLinePrivateConfig, defineCreatePullRequestTemplateConfig, definePreCommitConfig, definePreCommitPrivateConfig };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CreateEnumType } from "@alextheman/utility";
|
|
2
|
-
import { Result, TemplateExpression } from "execa";
|
|
2
|
+
import { Options, Result, TemplateExpression } from "execa";
|
|
3
3
|
|
|
4
4
|
//#region src/configs/types/CreatePullRequestTemplateConfig.d.ts
|
|
5
5
|
interface CreatePullRequestTemplateBaseConfig {
|
|
@@ -22,6 +22,17 @@ interface CreatePullRequestTemplateInfrastructureConfig extends CreatePullReques
|
|
|
22
22
|
}
|
|
23
23
|
type CreatePullRequestTemplateConfig = CreatePullRequestTemplateGeneralConfig | CreatePullRequestTemplateInfrastructureConfig;
|
|
24
24
|
//#endregion
|
|
25
|
+
//#region src/commands/pre-commit/createStepRunner.d.ts
|
|
26
|
+
interface BaseOptions {
|
|
27
|
+
stdio: "inherit";
|
|
28
|
+
reject: false;
|
|
29
|
+
}
|
|
30
|
+
interface StepRunner<ExecaOptions extends Options = BaseOptions> {
|
|
31
|
+
<NewOpts extends Options>(options: NewOpts): StepRunner<ExecaOptions & NewOpts>;
|
|
32
|
+
(command: string, args?: readonly string[]): Promise<Result<ExecaOptions>>;
|
|
33
|
+
(strings: TemplateStringsArray, ...interpolations: TemplateExpression[]): Promise<Result<ExecaOptions>>;
|
|
34
|
+
}
|
|
35
|
+
//#endregion
|
|
25
36
|
//#region src/configs/types/PreCommitConfig.d.ts
|
|
26
37
|
declare const PackageManager: {
|
|
27
38
|
readonly NPM: "npm";
|
|
@@ -32,10 +43,6 @@ interface PreCommitStepOptions {
|
|
|
32
43
|
/** Arguments to pass to the given script */
|
|
33
44
|
arguments?: string[];
|
|
34
45
|
}
|
|
35
|
-
interface StepRunner {
|
|
36
|
-
(command: string, args?: readonly string[]): Promise<Result>;
|
|
37
|
-
(strings: TemplateStringsArray, ...interpolations: TemplateExpression[]): Promise<Result>;
|
|
38
|
-
}
|
|
39
46
|
type StepFunction = (stepRunner: StepRunner) => void | Promise<void>;
|
|
40
47
|
interface PreCommitConfig<ScriptName extends string = string> {
|
|
41
48
|
/** The name of the package manager being used (can choose from `npm` or `pnpm`). If not provided, can be inferred from the packageManager field in package.json. */
|
|
@@ -92,10 +99,16 @@ declare const alexCLineConfig: AlexCLineConfig<keyof typeof scripts>;
|
|
|
92
99
|
//#region src/configs/internal/infrastructureConfig.d.ts
|
|
93
100
|
declare const infrastructureConfig: AlexCLineConfig<"format" | "lint">;
|
|
94
101
|
//#endregion
|
|
95
|
-
//#region src/configs/internal/
|
|
96
|
-
|
|
102
|
+
//#region src/configs/internal/PreCommitStep.d.ts
|
|
103
|
+
declare const PreCommitStep: {
|
|
104
|
+
readonly BUILD: "build";
|
|
105
|
+
readonly FORMAT: "format";
|
|
106
|
+
readonly LINT: "lint";
|
|
107
|
+
readonly TEST: "test";
|
|
108
|
+
};
|
|
109
|
+
type PreCommitStep = "build" | "format" | "lint" | "test";
|
|
97
110
|
//#endregion
|
|
98
111
|
//#region src/configs/internal/packageConfig.d.ts
|
|
99
|
-
declare function packageConfig(steps?:
|
|
112
|
+
declare function packageConfig<ScriptName extends string = PreCommitStep>(steps?: (StepFunction | ScriptName | PreCommitStep | [ScriptName | PreCommitStep, PreCommitStepOptions])[]): AlexCLineConfig<PreCommitStep>;
|
|
100
113
|
//#endregion
|
|
101
114
|
export { alexCLineConfig, infrastructureConfig, packageConfig };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CreateEnumType } from "@alextheman/utility";
|
|
2
|
-
import { Result, TemplateExpression } from "execa";
|
|
2
|
+
import { Options, Result, TemplateExpression } from "execa";
|
|
3
3
|
|
|
4
4
|
//#region src/configs/types/CreatePullRequestTemplateConfig.d.ts
|
|
5
5
|
interface CreatePullRequestTemplateBaseConfig {
|
|
@@ -22,6 +22,17 @@ interface CreatePullRequestTemplateInfrastructureConfig extends CreatePullReques
|
|
|
22
22
|
}
|
|
23
23
|
type CreatePullRequestTemplateConfig = CreatePullRequestTemplateGeneralConfig | CreatePullRequestTemplateInfrastructureConfig;
|
|
24
24
|
//#endregion
|
|
25
|
+
//#region src/commands/pre-commit/createStepRunner.d.ts
|
|
26
|
+
interface BaseOptions {
|
|
27
|
+
stdio: "inherit";
|
|
28
|
+
reject: false;
|
|
29
|
+
}
|
|
30
|
+
interface StepRunner<ExecaOptions extends Options = BaseOptions> {
|
|
31
|
+
<NewOpts extends Options>(options: NewOpts): StepRunner<ExecaOptions & NewOpts>;
|
|
32
|
+
(command: string, args?: readonly string[]): Promise<Result<ExecaOptions>>;
|
|
33
|
+
(strings: TemplateStringsArray, ...interpolations: TemplateExpression[]): Promise<Result<ExecaOptions>>;
|
|
34
|
+
}
|
|
35
|
+
//#endregion
|
|
25
36
|
//#region src/configs/types/PreCommitConfig.d.ts
|
|
26
37
|
declare const PackageManager: {
|
|
27
38
|
readonly NPM: "npm";
|
|
@@ -32,10 +43,6 @@ interface PreCommitStepOptions {
|
|
|
32
43
|
/** Arguments to pass to the given script */
|
|
33
44
|
arguments?: string[];
|
|
34
45
|
}
|
|
35
|
-
interface StepRunner {
|
|
36
|
-
(command: string, args?: readonly string[]): Promise<Result>;
|
|
37
|
-
(strings: TemplateStringsArray, ...interpolations: TemplateExpression[]): Promise<Result>;
|
|
38
|
-
}
|
|
39
46
|
type StepFunction = (stepRunner: StepRunner) => void | Promise<void>;
|
|
40
47
|
interface PreCommitConfig<ScriptName extends string = string> {
|
|
41
48
|
/** The name of the package manager being used (can choose from `npm` or `pnpm`). If not provided, can be inferred from the packageManager field in package.json. */
|
|
@@ -92,10 +99,16 @@ declare const alexCLineConfig: AlexCLineConfig<keyof typeof scripts>;
|
|
|
92
99
|
//#region src/configs/internal/infrastructureConfig.d.ts
|
|
93
100
|
declare const infrastructureConfig: AlexCLineConfig<"format" | "lint">;
|
|
94
101
|
//#endregion
|
|
95
|
-
//#region src/configs/internal/
|
|
96
|
-
|
|
102
|
+
//#region src/configs/internal/PreCommitStep.d.ts
|
|
103
|
+
declare const PreCommitStep: {
|
|
104
|
+
readonly BUILD: "build";
|
|
105
|
+
readonly FORMAT: "format";
|
|
106
|
+
readonly LINT: "lint";
|
|
107
|
+
readonly TEST: "test";
|
|
108
|
+
};
|
|
109
|
+
type PreCommitStep = "build" | "format" | "lint" | "test";
|
|
97
110
|
//#endregion
|
|
98
111
|
//#region src/configs/internal/packageConfig.d.ts
|
|
99
|
-
declare function packageConfig(steps?:
|
|
112
|
+
declare function packageConfig<ScriptName extends string = PreCommitStep>(steps?: (StepFunction | ScriptName | PreCommitStep | [ScriptName | PreCommitStep, PreCommitStepOptions])[]): AlexCLineConfig<PreCommitStep>;
|
|
100
113
|
//#endregion
|
|
101
114
|
export { alexCLineConfig, infrastructureConfig, packageConfig };
|
package/dist/index.cjs
CHANGED
|
@@ -698,6 +698,54 @@ function gitPostMergeCleanup(program) {
|
|
|
698
698
|
});
|
|
699
699
|
}
|
|
700
700
|
|
|
701
|
+
//#endregion
|
|
702
|
+
//#region src/commands/pre-commit/createStepRunner.ts
|
|
703
|
+
const runCommandAndLogToConsole = (0, execa.execa)({
|
|
704
|
+
stdio: "inherit",
|
|
705
|
+
reject: false
|
|
706
|
+
});
|
|
707
|
+
async function evaluateResult(program, promisedResult, failedCommand) {
|
|
708
|
+
const result = await promisedResult;
|
|
709
|
+
if (result.exitCode !== 0) program.error(`Command failed: ${failedCommand}`, {
|
|
710
|
+
exitCode: result.exitCode ?? 1,
|
|
711
|
+
code: "PRE_COMMIT_FAILED"
|
|
712
|
+
});
|
|
713
|
+
return result;
|
|
714
|
+
}
|
|
715
|
+
function bindStepRunner(program, boundOptions) {
|
|
716
|
+
function stepRunner(first, ...second) {
|
|
717
|
+
if (typeof first === "string") {
|
|
718
|
+
const command = first;
|
|
719
|
+
const args = second[0] ?? [];
|
|
720
|
+
return evaluateResult(program, runCommandAndLogToConsole(boundOptions)(command, args), `${command}${args.length ? ` ${args.join(" ")}` : ""}`);
|
|
721
|
+
}
|
|
722
|
+
if ((0, _alextheman_utility.isTemplateStringsArray)(first)) {
|
|
723
|
+
const args = (0, _alextheman_utility.getStringsAndInterpolations)(first, ...second);
|
|
724
|
+
return evaluateResult(program, runCommandAndLogToConsole(boundOptions)(...args), (0, _alextheman_utility.interpolate)(...args));
|
|
725
|
+
}
|
|
726
|
+
return bindStepRunner(program, {
|
|
727
|
+
...boundOptions,
|
|
728
|
+
...first
|
|
729
|
+
});
|
|
730
|
+
}
|
|
731
|
+
return stepRunner;
|
|
732
|
+
}
|
|
733
|
+
function createStepRunner(program) {
|
|
734
|
+
return bindStepRunner(program, {});
|
|
735
|
+
}
|
|
736
|
+
|
|
737
|
+
//#endregion
|
|
738
|
+
//#region src/commands/pre-commit/getCommandArguments.ts
|
|
739
|
+
function getCommandArguments(program, script, scripts, args) {
|
|
740
|
+
if (!(script in (scripts ?? {}))) program.error(`Could not find script \`${script}\` in package.json.`, {
|
|
741
|
+
exitCode: 1,
|
|
742
|
+
code: "SCRIPT_NOT_FOUND"
|
|
743
|
+
});
|
|
744
|
+
const result = script === "test" ? [script] : ["run", script];
|
|
745
|
+
if (args) result.push(...args);
|
|
746
|
+
return result;
|
|
747
|
+
}
|
|
748
|
+
|
|
701
749
|
//#endregion
|
|
702
750
|
//#region src/configs/types/PreCommitConfig.ts
|
|
703
751
|
const PackageManager = {
|
|
@@ -797,7 +845,7 @@ async function loadAlexCLineConfig(filePath) {
|
|
|
797
845
|
}
|
|
798
846
|
|
|
799
847
|
//#endregion
|
|
800
|
-
//#region src/commands/pre-commit-2.ts
|
|
848
|
+
//#region src/commands/pre-commit/pre-commit-2.ts
|
|
801
849
|
function preCommit2(program) {
|
|
802
850
|
program.command("pre-commit-2").description("Run the pre-commit scripts specified in the alex-c-line config (v2 experiment).").option("--allow-no-staged-changes", "Run even if nothing is staged").action(async ({ allowNoStagedChanges }) => {
|
|
803
851
|
const configPath = await findAlexCLineConfig(process.cwd());
|
|
@@ -810,12 +858,7 @@ function preCommit2(program) {
|
|
|
810
858
|
exitCode: 1,
|
|
811
859
|
code: "PRE_COMMIT_CONFIG_NOT_FOUND"
|
|
812
860
|
});
|
|
813
|
-
const
|
|
814
|
-
const runCommandAndLogToConsole = (0, execa.execa)({
|
|
815
|
-
reject: false,
|
|
816
|
-
stdio: "inherit"
|
|
817
|
-
});
|
|
818
|
-
const { exitCode: diffExitCode } = await execaNoFail`git diff --cached --quiet`;
|
|
861
|
+
const { exitCode: diffExitCode } = await (0, execa.execa)({ reject: false })`git diff --cached --quiet`;
|
|
819
862
|
switch (diffExitCode) {
|
|
820
863
|
case 128: program.error("Not currently in a Git repository", {
|
|
821
864
|
exitCode: 1,
|
|
@@ -826,34 +869,15 @@ function preCommit2(program) {
|
|
|
826
869
|
console.info("No staged changes found. Use --allow-no-staged-changes to run anyway.");
|
|
827
870
|
return;
|
|
828
871
|
}
|
|
829
|
-
async function stepRunner(first, ...second) {
|
|
830
|
-
const result = typeof first === "string" ? await runCommandAndLogToConsole(first, second[0]) : await runCommandAndLogToConsole(first, ...second);
|
|
831
|
-
if (result.exitCode !== 0) {
|
|
832
|
-
const errorMessage = typeof first === "string" ? `${first}${Array.isArray(second[0]) && second[0].length ? ` ${second[0].join(" ")}` : ""}` : (0, _alextheman_utility.interpolate)(first, ...second);
|
|
833
|
-
program.error(`Command failed: ${errorMessage}`, {
|
|
834
|
-
exitCode: result.exitCode ?? 1,
|
|
835
|
-
code: "PRE_COMMIT_FAILED"
|
|
836
|
-
});
|
|
837
|
-
}
|
|
838
|
-
return result;
|
|
839
|
-
}
|
|
840
872
|
const { packageManager: packagePackageManager, scripts } = JSON.parse(await (0, node_fs_promises.readFile)(node_path.default.join(process.cwd(), "package.json"), "utf8"));
|
|
841
873
|
const rawPackageManager = preCommitConfig.packageManager ?? (typeof packagePackageManager === "string" ? packagePackageManager.split("@")[0] : void 0);
|
|
842
874
|
const packageManager = (0, _alextheman_utility.parseZodSchema)(zod.default.enum(PackageManager), rawPackageManager, new _alextheman_utility.DataError(rawPackageManager, "UNSUPPORTED_PACKAGE_MANAGER", `This package manager is not currently supported. Only the following are supported: ${Object.values(PackageManager).join(", ")}`));
|
|
843
|
-
|
|
844
|
-
if (!(script in (scripts ?? {}))) program.error(`Could not find script \`${script}\` in package.json.`, {
|
|
845
|
-
exitCode: 1,
|
|
846
|
-
code: "SCRIPT_NOT_FOUND"
|
|
847
|
-
});
|
|
848
|
-
const result = script === "test" ? [script] : ["run", script];
|
|
849
|
-
if (args) result.push(...args);
|
|
850
|
-
return result;
|
|
851
|
-
}
|
|
875
|
+
const stepRunner = createStepRunner(program);
|
|
852
876
|
for (const step of preCommitConfig.steps) if (typeof step === "function") await step(stepRunner);
|
|
853
|
-
else if (typeof step === "string") await stepRunner(packageManager, getCommandArguments(step));
|
|
877
|
+
else if (typeof step === "string") await stepRunner(packageManager, getCommandArguments(program, step, scripts));
|
|
854
878
|
else {
|
|
855
879
|
const [script, options] = step;
|
|
856
|
-
await stepRunner(packageManager, getCommandArguments(script, options.arguments));
|
|
880
|
+
await stepRunner(packageManager, getCommandArguments(program, script, scripts, options.arguments));
|
|
857
881
|
}
|
|
858
882
|
await stepRunner`git update-index --again`;
|
|
859
883
|
});
|
|
@@ -1252,7 +1276,7 @@ function setReleaseStatus2(program) {
|
|
|
1252
1276
|
//#endregion
|
|
1253
1277
|
//#region package.json
|
|
1254
1278
|
var name = "alex-c-line";
|
|
1255
|
-
var version = "1.
|
|
1279
|
+
var version = "1.28.0";
|
|
1256
1280
|
var description = "Command-line tool with commands to streamline the developer workflow.";
|
|
1257
1281
|
var package_default = {
|
|
1258
1282
|
name,
|
package/dist/index.js
CHANGED
|
@@ -9,7 +9,7 @@ import path from "node:path";
|
|
|
9
9
|
import boxen from "boxen";
|
|
10
10
|
import chalk from "chalk";
|
|
11
11
|
import figlet from "figlet";
|
|
12
|
-
import { DataError, VersionNumber, VersionType, encryptWithKey, fillArray, interpolate, kebabToCamel, normaliseIndents, omitProperties, parseFilePath, parseVersionType, parseZodSchema, parseZodSchemaAsync, removeDuplicates, removeUndefinedFromObject, stringifyDotenv } from "@alextheman/utility";
|
|
12
|
+
import { DataError, VersionNumber, VersionType, encryptWithKey, fillArray, getStringsAndInterpolations, interpolate, isTemplateStringsArray, kebabToCamel, normaliseIndents, omitProperties, parseFilePath, parseVersionType, parseZodSchema, parseZodSchemaAsync, removeDuplicates, removeUndefinedFromObject, stringifyDotenv } from "@alextheman/utility";
|
|
13
13
|
import { ExecaError, execa } from "execa";
|
|
14
14
|
import dotenv, { parse } from "dotenv";
|
|
15
15
|
import dotenvStringify from "dotenv-stringify";
|
|
@@ -660,6 +660,54 @@ function gitPostMergeCleanup(program) {
|
|
|
660
660
|
});
|
|
661
661
|
}
|
|
662
662
|
|
|
663
|
+
//#endregion
|
|
664
|
+
//#region src/commands/pre-commit/createStepRunner.ts
|
|
665
|
+
const runCommandAndLogToConsole = execa({
|
|
666
|
+
stdio: "inherit",
|
|
667
|
+
reject: false
|
|
668
|
+
});
|
|
669
|
+
async function evaluateResult(program, promisedResult, failedCommand) {
|
|
670
|
+
const result = await promisedResult;
|
|
671
|
+
if (result.exitCode !== 0) program.error(`Command failed: ${failedCommand}`, {
|
|
672
|
+
exitCode: result.exitCode ?? 1,
|
|
673
|
+
code: "PRE_COMMIT_FAILED"
|
|
674
|
+
});
|
|
675
|
+
return result;
|
|
676
|
+
}
|
|
677
|
+
function bindStepRunner(program, boundOptions) {
|
|
678
|
+
function stepRunner(first, ...second) {
|
|
679
|
+
if (typeof first === "string") {
|
|
680
|
+
const command = first;
|
|
681
|
+
const args = second[0] ?? [];
|
|
682
|
+
return evaluateResult(program, runCommandAndLogToConsole(boundOptions)(command, args), `${command}${args.length ? ` ${args.join(" ")}` : ""}`);
|
|
683
|
+
}
|
|
684
|
+
if (isTemplateStringsArray(first)) {
|
|
685
|
+
const args = getStringsAndInterpolations(first, ...second);
|
|
686
|
+
return evaluateResult(program, runCommandAndLogToConsole(boundOptions)(...args), interpolate(...args));
|
|
687
|
+
}
|
|
688
|
+
return bindStepRunner(program, {
|
|
689
|
+
...boundOptions,
|
|
690
|
+
...first
|
|
691
|
+
});
|
|
692
|
+
}
|
|
693
|
+
return stepRunner;
|
|
694
|
+
}
|
|
695
|
+
function createStepRunner(program) {
|
|
696
|
+
return bindStepRunner(program, {});
|
|
697
|
+
}
|
|
698
|
+
|
|
699
|
+
//#endregion
|
|
700
|
+
//#region src/commands/pre-commit/getCommandArguments.ts
|
|
701
|
+
function getCommandArguments(program, script, scripts, args) {
|
|
702
|
+
if (!(script in (scripts ?? {}))) program.error(`Could not find script \`${script}\` in package.json.`, {
|
|
703
|
+
exitCode: 1,
|
|
704
|
+
code: "SCRIPT_NOT_FOUND"
|
|
705
|
+
});
|
|
706
|
+
const result = script === "test" ? [script] : ["run", script];
|
|
707
|
+
if (args) result.push(...args);
|
|
708
|
+
return result;
|
|
709
|
+
}
|
|
710
|
+
|
|
663
711
|
//#endregion
|
|
664
712
|
//#region src/configs/types/PreCommitConfig.ts
|
|
665
713
|
const PackageManager = {
|
|
@@ -759,7 +807,7 @@ async function loadAlexCLineConfig(filePath) {
|
|
|
759
807
|
}
|
|
760
808
|
|
|
761
809
|
//#endregion
|
|
762
|
-
//#region src/commands/pre-commit-2.ts
|
|
810
|
+
//#region src/commands/pre-commit/pre-commit-2.ts
|
|
763
811
|
function preCommit2(program) {
|
|
764
812
|
program.command("pre-commit-2").description("Run the pre-commit scripts specified in the alex-c-line config (v2 experiment).").option("--allow-no-staged-changes", "Run even if nothing is staged").action(async ({ allowNoStagedChanges }) => {
|
|
765
813
|
const configPath = await findAlexCLineConfig(process.cwd());
|
|
@@ -772,12 +820,7 @@ function preCommit2(program) {
|
|
|
772
820
|
exitCode: 1,
|
|
773
821
|
code: "PRE_COMMIT_CONFIG_NOT_FOUND"
|
|
774
822
|
});
|
|
775
|
-
const
|
|
776
|
-
const runCommandAndLogToConsole = execa({
|
|
777
|
-
reject: false,
|
|
778
|
-
stdio: "inherit"
|
|
779
|
-
});
|
|
780
|
-
const { exitCode: diffExitCode } = await execaNoFail`git diff --cached --quiet`;
|
|
823
|
+
const { exitCode: diffExitCode } = await execa({ reject: false })`git diff --cached --quiet`;
|
|
781
824
|
switch (diffExitCode) {
|
|
782
825
|
case 128: program.error("Not currently in a Git repository", {
|
|
783
826
|
exitCode: 1,
|
|
@@ -788,34 +831,15 @@ function preCommit2(program) {
|
|
|
788
831
|
console.info("No staged changes found. Use --allow-no-staged-changes to run anyway.");
|
|
789
832
|
return;
|
|
790
833
|
}
|
|
791
|
-
async function stepRunner(first, ...second) {
|
|
792
|
-
const result = typeof first === "string" ? await runCommandAndLogToConsole(first, second[0]) : await runCommandAndLogToConsole(first, ...second);
|
|
793
|
-
if (result.exitCode !== 0) {
|
|
794
|
-
const errorMessage = typeof first === "string" ? `${first}${Array.isArray(second[0]) && second[0].length ? ` ${second[0].join(" ")}` : ""}` : interpolate(first, ...second);
|
|
795
|
-
program.error(`Command failed: ${errorMessage}`, {
|
|
796
|
-
exitCode: result.exitCode ?? 1,
|
|
797
|
-
code: "PRE_COMMIT_FAILED"
|
|
798
|
-
});
|
|
799
|
-
}
|
|
800
|
-
return result;
|
|
801
|
-
}
|
|
802
834
|
const { packageManager: packagePackageManager, scripts } = JSON.parse(await readFile(path.join(process.cwd(), "package.json"), "utf8"));
|
|
803
835
|
const rawPackageManager = preCommitConfig.packageManager ?? (typeof packagePackageManager === "string" ? packagePackageManager.split("@")[0] : void 0);
|
|
804
836
|
const packageManager = parseZodSchema(z.enum(PackageManager), rawPackageManager, new DataError(rawPackageManager, "UNSUPPORTED_PACKAGE_MANAGER", `This package manager is not currently supported. Only the following are supported: ${Object.values(PackageManager).join(", ")}`));
|
|
805
|
-
|
|
806
|
-
if (!(script in (scripts ?? {}))) program.error(`Could not find script \`${script}\` in package.json.`, {
|
|
807
|
-
exitCode: 1,
|
|
808
|
-
code: "SCRIPT_NOT_FOUND"
|
|
809
|
-
});
|
|
810
|
-
const result = script === "test" ? [script] : ["run", script];
|
|
811
|
-
if (args) result.push(...args);
|
|
812
|
-
return result;
|
|
813
|
-
}
|
|
837
|
+
const stepRunner = createStepRunner(program);
|
|
814
838
|
for (const step of preCommitConfig.steps) if (typeof step === "function") await step(stepRunner);
|
|
815
|
-
else if (typeof step === "string") await stepRunner(packageManager, getCommandArguments(step));
|
|
839
|
+
else if (typeof step === "string") await stepRunner(packageManager, getCommandArguments(program, step, scripts));
|
|
816
840
|
else {
|
|
817
841
|
const [script, options] = step;
|
|
818
|
-
await stepRunner(packageManager, getCommandArguments(script, options.arguments));
|
|
842
|
+
await stepRunner(packageManager, getCommandArguments(program, script, scripts, options.arguments));
|
|
819
843
|
}
|
|
820
844
|
await stepRunner`git update-index --again`;
|
|
821
845
|
});
|
|
@@ -1214,7 +1238,7 @@ function setReleaseStatus2(program) {
|
|
|
1214
1238
|
//#endregion
|
|
1215
1239
|
//#region package.json
|
|
1216
1240
|
var name = "alex-c-line";
|
|
1217
|
-
var version = "1.
|
|
1241
|
+
var version = "1.28.0";
|
|
1218
1242
|
var description = "Command-line tool with commands to streamline the developer workflow.";
|
|
1219
1243
|
var package_default = {
|
|
1220
1244
|
name,
|