@monorepo-utils/workspaces-to-typescript-project-references
Version:
Convert Workspaces to TypeScript's Project References
136 lines (128 loc) • 5.29 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.run = exports.cli = void 0;
const meow_1 = __importDefault(require("meow"));
const upath_1 = __importDefault(require("upath"));
const index_1 = require("./index");
exports.cli = (0, meow_1.default)(`
Usage
$ workspaces-to-typescript-project-references
Options
--root [Path:string] Root directory of the monorepo.
Default: current working directory
--check If set the flag, check only differences of tsconfig.json and does not update tsconfig.json.
If the check is failed, exit status 1. It is useful for testing.
--plugin [Path:string] Path to plugin script.
Load the plugin script as module and use it.
--tsconfigPath [Path:string] Use alternative config path inside the package. e.g.: tsconfig.test.json
Default: tsconfig.json
--includesRoot If set the flag, generate <root>/tsconfig.json that includes all references.
It is useful to check all packages at once.
--includesLocal If set the flag, includes ./tsconfig.*.json
Examples
# Update project references in tsconfig.json
$ workspaces-to-typescript-project-references
# Test on CI
$ workspaces-to-typescript-project-references --check
# Update <root>/tsconfig.json that includes all references to packages
$ workspaces-to-typescript-project-references --includesRoot
$ workspaces-to-typescript-project-references --includesRoot --check
`, {
flags: {
root: {
type: "string",
default: process.cwd()
},
includesRoot: {
type: "boolean",
default: false
},
includesLocal: {
type: "boolean",
default: false
},
check: {
type: "boolean",
default: false
},
plugin: {
type: "string",
isMultiple: true
},
tsconfigPath: {
type: "string",
default: index_1.DEFAULT_TSCONFIGPATH
}
},
autoHelp: true,
autoVersion: true
});
const run = (_input = exports.cli.input, flags = exports.cli.flags) => __awaiter(void 0, void 0, void 0, function* () {
const plugins = Array.isArray(flags.plugin)
? flags.plugin.map((pluginPath) => {
const plugin = require(upath_1.default.join(process.cwd(), pluginPath));
if (typeof plugin.plugin !== "function") {
throw new Error("plugin should export { plugin }.");
}
return plugin.plugin;
})
: undefined;
const customTsConfigFinder = (location) => {
return upath_1.default.join(location, flags.tsconfigPath);
};
// Update <package>/tsconfig.json
const projectResult = (0, index_1.toProjectReferences)({
rootDir: flags.root,
includesLocal: flags.includesLocal,
checkOnly: flags.check,
plugins,
tsConfigPath: flags.tsconfigPath,
tsConfigPathFinder: flags.tsconfigPath ? customTsConfigFinder : undefined
});
if (projectResult.aggregateError) {
return {
exitStatus: 1,
stdout: null,
stderr: projectResult.aggregateError.message + "\n\n" + projectResult.aggregateError.errors.join("\n")
};
}
// Update <root>/tsconfig.json
if (flags.includesRoot) {
const rootProjectResult = (0, index_1.toRootProjectReferences)({
rootDir: flags.root,
includesLocal: flags.includesLocal,
checkOnly: flags.check,
plugins,
tsConfigPath: flags.tsconfigPath,
tsConfigPathFinder: flags.tsconfigPath ? customTsConfigFinder : undefined
});
if (rootProjectResult.aggregateError) {
return {
exitStatus: 1,
stdout: null,
stderr: rootProjectResult.aggregateError.message +
"\n\n" +
rootProjectResult.aggregateError.errors.join("\n")
};
}
}
return {
exitStatus: 0,
stdout: flags.check ? "" : "Update Project References!",
stderr: null
};
});
exports.run = run;
//# sourceMappingURL=cli.js.map