commit upgrade (#391)
This commit is contained in:
@@ -61,6 +61,8 @@ testSkipIfWindows("upgrade app to select component", async ({ po }) => {
|
|||||||
await po.expectNoAppUpgrades();
|
await po.expectNoAppUpgrades();
|
||||||
await po.snapshotAppFiles();
|
await po.snapshotAppFiles();
|
||||||
await po.clickOpenInChatButton();
|
await po.clickOpenInChatButton();
|
||||||
|
// There should be another version from the upgrade being committed.
|
||||||
|
await expect(po.page.getByText("Version 2")).toBeVisible();
|
||||||
|
|
||||||
await po.clickPreviewPickElement();
|
await po.clickPreviewPickElement();
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import { getDyadAppPath } from "../../paths/paths";
|
|||||||
import fs from "node:fs";
|
import fs from "node:fs";
|
||||||
import path from "node:path";
|
import path from "node:path";
|
||||||
import { spawn } from "node:child_process";
|
import { spawn } from "node:child_process";
|
||||||
|
import { gitAddAll, gitCommit } from "../utils/git_utils";
|
||||||
|
|
||||||
const logger = log.scope("app_upgrade_handlers");
|
const logger = log.scope("app_upgrade_handlers");
|
||||||
const handle = createLoggedHandler(logger);
|
const handle = createLoggedHandler(logger);
|
||||||
@@ -109,7 +110,7 @@ async function applyComponentTagger(appPath: string) {
|
|||||||
await fs.promises.writeFile(viteConfigPath, content);
|
await fs.promises.writeFile(viteConfigPath, content);
|
||||||
|
|
||||||
// Install the dependency
|
// Install the dependency
|
||||||
return new Promise<void>((resolve, reject) => {
|
await new Promise<void>((resolve, reject) => {
|
||||||
logger.info("Installing component-tagger dependency");
|
logger.info("Installing component-tagger dependency");
|
||||||
const process = spawn(
|
const process = spawn(
|
||||||
"pnpm add -D @dyad-sh/react-vite-component-tagger || npm install --save-dev --legacy-peer-deps @dyad-sh/react-vite-component-tagger",
|
"pnpm add -D @dyad-sh/react-vite-component-tagger || npm install --save-dev --legacy-peer-deps @dyad-sh/react-vite-component-tagger",
|
||||||
@@ -138,6 +139,22 @@ async function applyComponentTagger(appPath: string) {
|
|||||||
reject(err);
|
reject(err);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Commit changes
|
||||||
|
try {
|
||||||
|
logger.info("Staging and committing changes");
|
||||||
|
await gitAddAll({ path: appPath });
|
||||||
|
await gitCommit({
|
||||||
|
path: appPath,
|
||||||
|
message: "[dyad] add Dyad component tagger",
|
||||||
|
});
|
||||||
|
logger.info("Successfully committed changes");
|
||||||
|
} catch (err) {
|
||||||
|
logger.warn(
|
||||||
|
`Failed to commit changes. This may happen if the project is not in a git repository, or if there are no changes to commit.`,
|
||||||
|
err,
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function registerAppUpgradeHandlers() {
|
export function registerAppUpgradeHandlers() {
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ export async function gitStageToRevert({
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Safety: refuse to run if the work-tree isn’t clean.
|
// Safety: refuse to run if the work-tree isn't clean.
|
||||||
const { stdout: wtStatus } = await execAsync(
|
const { stdout: wtStatus } = await execAsync(
|
||||||
`git -C "${path}" status --porcelain`,
|
`git -C "${path}" status --porcelain`,
|
||||||
);
|
);
|
||||||
@@ -138,3 +138,13 @@ export async function gitStageToRevert({
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function gitAddAll({ path }: { path: string }): Promise<void> {
|
||||||
|
const settings = readSettings();
|
||||||
|
if (settings.enableNativeGit) {
|
||||||
|
await execAsync(`git -C "${path}" add .`);
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
return git.add({ fs, dir: path, filepath: "." });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user