Skip to content

Commit

Permalink
feat: add --dir option (#81)
Browse files Browse the repository at this point in the history
  • Loading branch information
zlalvani authored May 9, 2024
1 parent ec0403b commit f72edbe
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 7 deletions.
4 changes: 3 additions & 1 deletion apps/cli/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -184,11 +184,12 @@ const App = (props: {
version: string;
port: number;
upgrade: boolean;
dir?: string;
token?: string;
}) => {
const { exit } = useApp();

const { model, language, pkg, version, token, port, upgrade } = props;
const { model, language, pkg, version, token, port, upgrade, dir } = props;

const [columns, rows] = useStdoutDimensions();

Expand Down Expand Up @@ -256,6 +257,7 @@ const App = (props: {
`${port}`,
...(token ? ["-t", token] : []),
...(upgrade ? [] : ["-n"]),
...(dir ? ["-d", dir] : []),
],
{
shell: true,
Expand Down
9 changes: 6 additions & 3 deletions apps/cli/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,11 @@ const command = program
.option("-n, --no-upgrade", "skip applying the upgrade")
.option("-s, --simple", "simple mode")
.option("-i, --ipc", "run in ipc mode")
.option("-d, --dir <dir>", "target directory for the upgrade")
.parse();

const { model, language, port, ipc, simple, token, upgrade } = command.opts();
const { model, language, port, ipc, simple, token, upgrade, dir } =
command.opts();

let [pkg, version] = command.processedArgs;

Expand All @@ -65,7 +67,7 @@ if (!resolvedToken) {

const bumpFinder = makeBumpFinder({
language,
projectRoot: process.cwd(),
projectRoot: dir,
});

const available = await bumpFinder.list();
Expand Down Expand Up @@ -110,7 +112,7 @@ const bumpgen = makeBumpgen({
newVersion: version,
},
language,
projectRoot: process.cwd(),
projectRoot: dir,
});

if (simple) {
Expand Down Expand Up @@ -153,6 +155,7 @@ if (simple) {
token={token}
port={port}
upgrade={upgrade}
dir={dir}
/>,
);
await app.waitUntilExit();
Expand Down
9 changes: 7 additions & 2 deletions packages/bumpgen-core/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import path from "path";
import process from "process";
import { serializeError } from "serialize-error";
import { v4 } from "uuid";
Expand Down Expand Up @@ -436,6 +437,10 @@ const bumpgen = ({
data: errors,
};

if (errors.length === 0) {
break;
}

id = v4();
yield {
id,
Expand Down Expand Up @@ -559,7 +564,7 @@ export const makeBumpgen = ({
}) => {
model = model ?? "gpt-4-turbo-preview";
language = language ?? "typescript";
projectRoot = projectRoot ?? process.cwd();
projectRoot = projectRoot ? path.resolve(projectRoot) : process.cwd();
const languageService = injectLanguageService(language)();
const llm = injectLLMService({ llmApiKey, model })();
const graphService = injectGraphService();
Expand All @@ -586,7 +591,7 @@ export const makeBumpFinder = ({
projectRoot?: string;
}) => {
language = language ?? "typescript";
projectRoot = projectRoot ?? process.cwd();
projectRoot = projectRoot ? path.resolve(projectRoot) : process.cwd();
const languageService = injectLanguageService(language)();
return bumpFinder({
services: { language: languageService },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,11 @@ export const makeTypescriptService = (

return {
build: {
getErrors: async () => {
getErrors: async (projectRoot) => {
let tscOutput = await subprocess.spawn(
`npx tsc --noEmit --skipLibCheck --pretty`,
{
cwd: projectRoot,
rejectOnStderr: false,
},
);
Expand Down Expand Up @@ -228,6 +229,7 @@ export const makeTypescriptService = (
console.log("Applying upgrades...");

await subprocess.spawn(`${packageManager} install`, {
cwd: projectRoot,
rejectOnStderr: false,
rejectOnNonZeroExit: true,
});
Expand All @@ -239,6 +241,7 @@ export const makeTypescriptService = (
const { packageManager } = await findPackageManager(projectRoot);

return await subprocess.spawn(`${packageManager} install`, {
cwd: projectRoot,
rejectOnStderr: false,
});
},
Expand Down
2 changes: 2 additions & 0 deletions packages/bumpgen-core/src/services/subprocess/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,15 @@ export const createSubprocessService = (
spawn: async (
command: string,
options?: {
cwd?: string;
rejectOnStderr?: boolean;
rejectOnNonZeroExit?: boolean;
env?: typeof proc.env;
},
) => {
return await new Promise<string>((resolve, reject) => {
const child = childProcess.spawn(command, {
cwd: options?.cwd,
shell: true,
env: options?.env ?? proc.env,
});
Expand Down

0 comments on commit f72edbe

Please sign in to comment.