typescript-assistant
Version:
Combines and integrates professional Typescript tools into your project
182 lines • 5.88 kB
JavaScript
#!/usr/bin/env node
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const semver_1 = require("semver");
const yargsModule = require("yargs");
const assist_1 = require("./commands/assist");
const ci_1 = require("./commands/ci");
const clean_1 = require("./commands/clean");
const fix_1 = require("./commands/fix");
const fix_all_1 = require("./commands/fix-all");
const init_1 = require("./commands/init");
const lint_1 = require("./commands/lint");
const post_checkout_1 = require("./commands/post-checkout");
const post_merge_1 = require("./commands/post-merge");
const pre_commit_1 = require("./commands/pre-commit");
const pre_push_1 = require("./commands/pre-push");
const release_1 = require("./commands/release");
const dependency_injector_1 = require("./dependency-injector");
/* eslint-disable no-console */
if ((0, semver_1.gte)("v12.0.0", process.version)) {
console.error("Please update your version of Node.");
process.exit(1);
}
let inject = (0, dependency_injector_1.createDependencyInjector)();
let onSuccess = () => {
process.exit(0);
};
let onFailure = (error) => {
console.error(error);
process.exit(1);
};
let failIfUnsuccessful = (success) => {
if (!success) {
process.exit(1);
}
};
yargsModule.command(["assist", "*"], "Watches for file changes and outputs current errors and violations", {
port: {
describe: "the port to have the status server listen on",
},
format: {
describe: "check formatting during assist",
default: true,
boolean: true,
},
coverage: {
describe: "run tests with coverage",
boolean: true,
default: true,
},
project: {
describe: "provide tsconfigs to watch",
string: true,
type: "array",
},
testConfig: {
describe: "path to nyc config file",
string: true,
},
testsGlob: {
describe: "glob for test files",
string: true,
},
}, (yargs) => {
if (yargs._.length === 0 ||
(yargs._.length === 1 && yargs._[0] === "assist")) {
void inject(assist_1.createAssistCommand).execute({
statusServerPort: parseInt(yargs.port, 10) || 0,
format: yargs.format,
coverage: yargs.coverage,
projects: yargs.project,
testConfig: yargs.testConfig,
testsGlob: yargs.testsGlob,
});
}
else {
console.error("Unknown command");
process.exit(1);
}
});
yargsModule.command(["lint"], "Lints", {}, (yargs) => {
inject(lint_1.createLintCommand).execute().then(onSuccess, onFailure);
});
yargsModule.command(["fix", "f"], "Formats changed files and applies tslint fixes", {}, (yargs) => {
inject(fix_1.createFixCommand).execute().then(onSuccess, onFailure);
});
yargsModule.command(["fixall"], "Formats all files and applies tslint fixes", {}, (yargs) => {
inject(fix_all_1.createFixAllCommand).execute().then(onSuccess, onFailure);
});
yargsModule.command(["clean", "c"], "Deletes all output files and intermediate files", {}, (yargs) => {
void inject(clean_1.createCleanCommand).execute();
});
yargsModule.command(["release"], "Interactively makes a new version number, tags, pushes and publishes to npm", {}, (yargs) => {
inject(release_1.createReleaseCommand).execute().then(onSuccess, onFailure);
});
yargsModule.command(["ci"], "Runs all tools in parallel to find errors", {
tests: {
describe: "Run the test and coverage command",
boolean: true,
default: true,
},
format: {
describe: "check formatting during command",
boolean: true,
default: true,
},
coverage: {
describe: "run tests with coverage",
boolean: true,
default: true,
},
}, (yargs) => {
inject(ci_1.createCICommand)
.execute({
tests: yargs.tests,
format: yargs.format,
coverage: yargs.coverage,
})
.then(failIfUnsuccessful, onFailure);
});
yargsModule.command("init", "Initialize or repair all features of typescript-assistant in your project", {}, (yargs) => {
void inject(init_1.createInitCommand).execute(true);
});
yargsModule.command("pre-commit", "Pre-commit git hook for husky", (yargs) => {
return yargs.boolean("format").default("format", true);
}, (yargs) => {
inject(pre_commit_1.createPreCommitCommand)
.execute({
format: yargs.format,
})
.then(onSuccess, onFailure);
});
yargsModule.command("post-checkout", "Post-checkout git hook for husky", {
previous: {
describe: "The previous checkout head",
string: true,
demandOption: true,
},
new: {
describe: "The new checkout head",
string: true,
demandOption: true,
},
branch: {
coerce(arg) {
return arg === 1;
},
},
}, (yargs) => {
void inject(post_checkout_1.createPostCheckoutCommand).execute({
previousHead: yargs.previous,
newHead: yargs.new,
isBranch: yargs.branch,
});
});
yargsModule.command("post-merge", "Post-merge git hook for husky", {}, (yargs) => {
void inject(post_merge_1.createPostMergeCommand).execute();
});
yargsModule.command("pre-push", "Pre-push git hook for husky", {
disable: {
string: true,
type: "array",
},
testConfig: {
describe: "path to nyc config file",
string: true,
},
testsGlob: {
describe: "glob for test files",
string: true,
},
}, (yargs) => {
inject(pre_push_1.createPrePushCommand)
.execute({
disabledProjects: yargs.disable,
testConfig: yargs.testConfig,
testsGlob: yargs.testsGlob,
})
.then(failIfUnsuccessful, onFailure);
});
yargsModule.strict().argv;
//# sourceMappingURL=index.js.map