-
Notifications
You must be signed in to change notification settings - Fork 0
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/template #10
Feat/template #10
Conversation
package.json
Outdated
"dev": "node-dev src/index.ts", | ||
"dev": "node-dev src/write-yaml-template.ts", |
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.
to be removed in a later commit, I just didn't wanna have to run the wizard over and over to test this
src/write-yaml-template.ts
Outdated
const walk = (dir: string, prevResults?: string[]): string[] => { | ||
const list = fs.readdirSync(dir) | ||
const results = prevResults || [] | ||
list.forEach((file) => { | ||
file = path.resolve(dir, file) | ||
const stat = fs.statSync(file) | ||
if (stat && stat.isDirectory()) { | ||
walk(file, results) | ||
} else { | ||
results.push(file) | ||
} | ||
}) | ||
return results | ||
} |
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.
I sense this would be more testable if I removed the dependency on fs
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.
Co-authored-by: Rob Morgan <46483646+robmorgan-tab@users.noreply.github.com>
Co-authored-by: Rob Morgan <46483646+robmorgan-tab@users.noreply.github.com>
src/write-bin-template.ts
Outdated
} | ||
|
||
const makeBinTemplateSubdirectory = (jsonPath: string): void => { | ||
const { jsonBinPath, yamlBinPath } = getBinTargetPaths(jsonPath) |
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.
You could reduce duplication here
const createSubdirectory = (directoryPath: string): void => {
const directoryName = path.dirname(directoryPath)
const directoryStats = fs.statSync(directoryName, { throwIfNoEntry: false })
if (!directoryStats?.isDirectory()) {
fs.mkdirSync(directoryName)
}
}
const makeBinTemplateSubdirectories = (jsonPath: string): void => {
const { jsonBinPath, yamlBinPath } = getBinTargetPaths(jsonPath)
[jsonBinPath, yamlBinPath].forEach((binPath) => createSubdirectory(binPath))
}
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.
So this makeBinTemplateSubdirectories
function is one of the things that disappeared one I started refactoring in #15. Turns out what I actually wanted was some conditions around a mkdir so I can use the same function to make the top level bin/templates and the subdirectories.
The forEach
has given me the idea for a func that invokes getTemplateFileStrings
and getBinTargetPaths
and returns an array like { path: string, file: string }[]
, that should have better handing in writeFileToBin
, like
getWritables(jsonPath).forEach(({ path, file }) => {
makeDirectory(path.dirname(path))
fileSystem.writeFileSync(path, file)
})
Looking really good. |
Make template maker more testable
This PR: