Skip to content

Commit

Permalink
Fix async write file loop
Browse files Browse the repository at this point in the history
Using Promise.all is better than Array.prototype.forEach for the
purposes of writing multiple files to disk.
  • Loading branch information
macklinu committed Mar 8, 2019
1 parent b62c8e9 commit fba34b6
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions bin/create-action.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,15 +154,14 @@ const createAction = async (argv) => {
const dockerfile = await createDockerfile(metadata)
const packageJson = createPackageJson(directoryName)
const entrypoint = await readTemplate('entrypoint.js')
const files = [
await Promise.all([
['package.json', JSON.stringify(packageJson, null, 2)],
['Dockerfile', dockerfile],
['entrypoint.js', entrypoint]
]
files.forEach(async ([filename, contents]) => {
].map(async ([filename, contents]) => {
console.log(`Creating ${filename}...`)
await writeFile(path.join(base, filename), contents)
})
}))

console.log(`\nDone! Enjoy building your GitHub Action! Get started with:\n\ncd ${directoryName} && npm install`)
}
Expand Down

0 comments on commit fba34b6

Please sign in to comment.