-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of github.com:tonik/stapler
- Loading branch information
Showing
14 changed files
with
801 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import fs from 'fs'; | ||
import path from 'path'; | ||
import { StaplerState } from '@tonik/create-stapler-app-core/types'; | ||
|
||
const MAX_DEPTH = 2; | ||
|
||
export interface UnfinishedProject { | ||
projectName: string; | ||
projectPath: string; | ||
state: StaplerState; | ||
} | ||
|
||
export const findUnfinishedProjects = ( | ||
dir: string, | ||
depth: number = 0, | ||
results: UnfinishedProject[] = [], | ||
): UnfinishedProject[] => { | ||
if (depth > MAX_DEPTH) return results; | ||
|
||
const files = fs.readdirSync(dir); | ||
|
||
for (const file of files) { | ||
const fullPath = path.join(dir, file); | ||
|
||
try { | ||
const stat = fs.statSync(fullPath); | ||
|
||
if (stat.isDirectory()) { | ||
// Recursively search subdirectories | ||
findUnfinishedProjects(fullPath, depth + 1, results); | ||
} else if (file === '.staplerrc') { | ||
// Found a .staplerrc file, check if the project is unfinished | ||
const data = fs.readFileSync(fullPath, 'utf-8'); | ||
const state: StaplerState = JSON.parse(data); | ||
|
||
if (isProjectUnfinished(state)) { | ||
results.push({ | ||
projectName: state.projectName || path.basename(dir), | ||
projectPath: dir, | ||
state, | ||
}); | ||
} | ||
} | ||
} catch (error) { | ||
console.error(`Error accessing ${fullPath}:`, error); | ||
} | ||
} | ||
|
||
return results; | ||
}; | ||
|
||
const isProjectUnfinished = (state: StaplerState): boolean => { | ||
return Object.values(state.stepsCompleted).some((completed) => !completed); | ||
}; |
Oops, something went wrong.