Skip to content

Commit ce59780

Browse files
authored
Merge pull request #1994 from onflow/cf/cursorignore
Add cursor ignore
2 parents 03db4ac + 2539378 commit ce59780

3 files changed

Lines changed: 57 additions & 0 deletions

File tree

internal/accounts/create-interactive.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,11 @@ func createNetworkAccount(
158158
return nil, err
159159
}
160160

161+
err = util.AddToCursorIgnore(privateFile, state.ReaderWriter())
162+
if err != nil {
163+
return nil, err
164+
}
165+
161166
err = state.ReaderWriter().WriteFile(privateFile, []byte(key.String()), os.FileMode(0644))
162167
if err != nil {
163168
return nil, fmt.Errorf("failed saving private key: %w", err)

internal/super/setup.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,22 @@ func updateGitignore(targetDir string) error {
123123
return nil
124124
}
125125

126+
func updateCursorIgnore(targetDir string) error {
127+
cursorignorePath := filepath.Join(targetDir, ".cursorignore")
128+
f, err := os.OpenFile(cursorignorePath, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
129+
if err != nil {
130+
return err
131+
}
132+
defer f.Close()
133+
134+
_, err = f.WriteString("\n# flow\nemulator-account.pkey\n.env\n\n# Pay attention to imports directory\n!imports/**\n")
135+
if err != nil {
136+
return err
137+
}
138+
139+
return nil
140+
}
141+
126142
func createConfigOnly(targetDir string, readerWriter flowkit.ReaderWriter) error {
127143
params := config.InitConfigParameters{
128144
ServiceKeySigAlgo: "ECDSA_P256",
@@ -146,6 +162,11 @@ func createConfigOnly(targetDir string, readerWriter flowkit.ReaderWriter) error
146162
return err
147163
}
148164

165+
err = updateCursorIgnore(targetDir)
166+
if err != nil {
167+
return err
168+
}
169+
149170
return nil
150171
}
151172

@@ -277,6 +298,11 @@ func startInteractiveSetup(
277298
return "", err
278299
}
279300

301+
err = updateCursorIgnore(tempDir)
302+
if err != nil {
303+
return "", err
304+
}
305+
280306
// Move the temp directory to the target directory
281307
err = os.Rename(tempDir, targetDir)
282308
if err != nil {

internal/util/util.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,32 @@ func AddToGitIgnore(filename string, loader flowkit.ReaderWriter) error {
7171
)
7272
}
7373

74+
// AddToCursorIgnore adds a new line to the .cursorignore if one doesn't exist it creates it.
75+
func AddToCursorIgnore(filename string, loader flowkit.ReaderWriter) error {
76+
currentWd, err := os.Getwd()
77+
if err != nil {
78+
return err
79+
}
80+
cursorIgnorePath := filepath.Join(currentWd, ".cursorignore")
81+
cursorIgnoreFiles := ""
82+
filePermissions := os.FileMode(0644)
83+
84+
fileStat, err := os.Stat(cursorIgnorePath)
85+
if !os.IsNotExist(err) {
86+
cursorIgnoreFilesRaw, err := loader.ReadFile(cursorIgnorePath)
87+
if err != nil {
88+
return err
89+
}
90+
cursorIgnoreFiles = string(cursorIgnoreFilesRaw)
91+
filePermissions = fileStat.Mode().Perm()
92+
}
93+
return loader.WriteFile(
94+
cursorIgnorePath,
95+
fmt.Appendf(nil, "%s\n%s", cursorIgnoreFiles, filename),
96+
filePermissions,
97+
)
98+
}
99+
74100
// GetAddressNetwork returns the chain ID for an address.
75101
func GetAddressNetwork(address flow.Address) (flow.ChainID, error) {
76102
networks := []flow.ChainID{

0 commit comments

Comments
 (0)