53 lines
3.2 KiB
JavaScript
53 lines
3.2 KiB
JavaScript
#!/usr/bin/env node
|
|
import { _ as detectReactGrabConfigured, a as previewCdnTransform, f as detectFramework, g as detectReactGrab, h as detectProject, i as hasFrameworkEntryPoint, l as installSkill, m as detectPackageManager, n as installPackages, o as previewOptionsTransform, p as detectNextRouterType, r as applyTransform, s as previewTransform, t as getPackagesToInstall, u as removeSkill, v as detectUnsupportedFramework, y as findReactProjects } from "./install-Car5vKPk.js";
|
|
import { resolve } from "node:path";
|
|
//#region src/utils/install-react-grab.ts
|
|
var ReactGrabInstallError = class extends Error {
|
|
code;
|
|
constructor(message, code, options) {
|
|
super(message, options);
|
|
this.name = "ReactGrabInstallError";
|
|
this.code = code;
|
|
}
|
|
};
|
|
const installReactGrab = async (options = {}) => {
|
|
const project = await detectProject(resolve(options.cwd ?? process.cwd()));
|
|
const framework = options.framework ?? project.framework;
|
|
const packageManager = options.packageManager ?? project.packageManager;
|
|
if (project.unsupportedFramework && !options.framework) throw new ReactGrabInstallError(`${project.unsupportedFramework} is not supported by automatic setup.`, "unsupported-framework");
|
|
if (framework === "unknown") throw new ReactGrabInstallError("Could not detect a supported framework. Pass `framework` explicitly to override detection.", "unknown-framework");
|
|
const nextRouterType = options.nextRouterType ?? (framework === "next" && project.nextRouterType === "unknown" ? detectNextRouterType(project.projectRoot) : project.nextRouterType);
|
|
const alreadyConfigured = project.isReactGrabConfigured;
|
|
const transform = previewTransform(project.projectRoot, framework, nextRouterType, alreadyConfigured);
|
|
if (!transform.success && !options.skipTransform) throw new ReactGrabInstallError(transform.message, "transform-failed");
|
|
const didInstallPackage = !options.skipPackageInstall && !options.dryRun && !project.hasReactGrab;
|
|
if (didInstallPackage) try {
|
|
await installPackages(getPackagesToInstall(), {
|
|
...options.installPackageOptions,
|
|
cwd: project.projectRoot,
|
|
packageManager
|
|
});
|
|
} catch (error) {
|
|
throw new ReactGrabInstallError(error instanceof Error ? error.message : "Failed to install the react-grab package.", "install-failed", { cause: error });
|
|
}
|
|
const didChangeFile = !transform.noChanges && Boolean(transform.newContent) && !options.skipTransform && !options.dryRun;
|
|
if (didChangeFile) {
|
|
const writeResult = applyTransform(transform);
|
|
if (!writeResult.success) throw new ReactGrabInstallError(writeResult.error ?? `Failed to write to ${transform.filePath}`, "write-failed");
|
|
}
|
|
return {
|
|
projectRoot: project.projectRoot,
|
|
framework,
|
|
nextRouterType,
|
|
packageManager,
|
|
alreadyConfigured,
|
|
didInstallPackage,
|
|
didChangeFile,
|
|
dryRun: Boolean(options.dryRun),
|
|
transform
|
|
};
|
|
};
|
|
//#endregion
|
|
export { ReactGrabInstallError, applyTransform, detectFramework, detectNextRouterType, detectPackageManager, detectProject, detectReactGrab, detectReactGrabConfigured, detectUnsupportedFramework, findReactProjects, getPackagesToInstall, hasFrameworkEntryPoint, installPackages, installReactGrab, installSkill, previewCdnTransform, previewOptionsTransform, previewTransform, removeSkill };
|
|
|
|
//# sourceMappingURL=api.js.map
|