-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(cli): add flag ai removal command #151
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "web", | ||
"version": "0.2.36", | ||
"version": "0.2.37", | ||
"private": true, | ||
"scripts": { | ||
"build": "next build", | ||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,58 @@ | ||||||||||||||||||||||||||||||||||||||
import { loadLocalConfig } from "./util"; | ||||||||||||||||||||||||||||||||||||||
import { globby } from "globby"; | ||||||||||||||||||||||||||||||||||||||
import { getUseFeatureFlagRegex } from "@tryabby/core"; | ||||||||||||||||||||||||||||||||||||||
import { readFile } from "fs/promises"; | ||||||||||||||||||||||||||||||||||||||
import chalk from "chalk"; | ||||||||||||||||||||||||||||||||||||||
import { HttpService } from "./http"; | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
export async function removeFlagInstance(options: { | ||||||||||||||||||||||||||||||||||||||
flagName: string; | ||||||||||||||||||||||||||||||||||||||
apiKey: string; | ||||||||||||||||||||||||||||||||||||||
path: string; | ||||||||||||||||||||||||||||||||||||||
host?: string; | ||||||||||||||||||||||||||||||||||||||
configPath?: string; | ||||||||||||||||||||||||||||||||||||||
}) { | ||||||||||||||||||||||||||||||||||||||
const files = await globby("**/*.tsx", { | ||||||||||||||||||||||||||||||||||||||
cwd: options.path ?? process.cwd(), | ||||||||||||||||||||||||||||||||||||||
absolute: true, | ||||||||||||||||||||||||||||||||||||||
gitignore: true, | ||||||||||||||||||||||||||||||||||||||
onlyFiles: true, | ||||||||||||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
const regex = getUseFeatureFlagRegex(options.flagName); | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
const filesToUse = ( | ||||||||||||||||||||||||||||||||||||||
await Promise.all( | ||||||||||||||||||||||||||||||||||||||
files.flatMap(async (filePath) => { | ||||||||||||||||||||||||||||||||||||||
const content = await readFile(filePath, "utf-8").then((content) => { | ||||||||||||||||||||||||||||||||||||||
const matches = content.match(regex); | ||||||||||||||||||||||||||||||||||||||
return matches ? content : null; | ||||||||||||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||||||||||||
if (!content) return []; | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
return { | ||||||||||||||||||||||||||||||||||||||
filePath, | ||||||||||||||||||||||||||||||||||||||
fileContent: content, | ||||||||||||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||||||||||||
}) | ||||||||||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||||||||||
).flat(); | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
await HttpService.getFilesWithFlagsRemoved({ | ||||||||||||||||||||||||||||||||||||||
apiKey: options.apiKey, | ||||||||||||||||||||||||||||||||||||||
files: filesToUse, | ||||||||||||||||||||||||||||||||||||||
flagName: options.flagName, | ||||||||||||||||||||||||||||||||||||||
apiUrl: options.host, | ||||||||||||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
try { | ||||||||||||||||||||||||||||||||||||||
const { mutableConfig, saveMutableConfig } = await loadLocalConfig( | ||||||||||||||||||||||||||||||||||||||
options.configPath | ||||||||||||||||||||||||||||||||||||||
); | ||||||||||||||||||||||||||||||||||||||
mutableConfig.flags = mutableConfig.flags.filter((flag: string) => flag !== options.flagName); | ||||||||||||||||||||||||||||||||||||||
await saveMutableConfig(); | ||||||||||||||||||||||||||||||||||||||
} catch (e) { | ||||||||||||||||||||||||||||||||||||||
// fail silently | ||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||
Comment on lines
+48
to
+56
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Handle specific exceptions for configuration update. The local configuration update is correctly implemented, but consider handling specific exceptions to provide more informative error messages. - } catch (e) {
- // fail silently
+ } catch (error) {
+ console.error(`Error updating configuration:`, error);
} Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||
console.log(chalk.green("Flag removed successfully")); | ||||||||||||||||||||||||||||||||||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,11 @@ | ||
# @tryabby/next | ||
|
||
## 5.1.2 | ||
|
||
### Patch Changes | ||
|
||
- @tryabby/react@5.2.1 | ||
|
||
## 5.1.1 | ||
|
||
### Patch Changes | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,11 @@ | ||
# @tryabby/next | ||
|
||
## 1.0.3 | ||
|
||
### Patch Changes | ||
|
||
- @tryabby/react@5.2.1 | ||
|
||
## 1.0.2 | ||
|
||
### Patch Changes | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ensure proper error handling for file reading.
The file reading and regex matching are correctly implemented, but consider adding error handling for potential file read errors.
Committable suggestion