Skip to content
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

🐈🐈🐈 #657

Merged
merged 10 commits into from
Aug 30, 2023
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 6 additions & 21 deletions source/config.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import { pathToFileURL } from "url"
findInDir = (dirPath) ->
dir = await fs.opendir dirPath
for await entry from dir
if entry.isDirectory() and entry.name is '.config' # scan for ./config.civet as well as ./.config/config.civet
if entry.isDirectory() and entry.name is '.config' # scan for ./civet.json as well as ./.config/civet.json
return findInDir path.join dirPath, entry.name
if entry.isFile()
name = entry.name.replace(/^\./, '') # allow both .civetconfig.civet and civetconfig.civet
if name in ['config.civet', 'civet.json', 'civetconfig.civet', 'civetconfig.json']
return path.join dirPath, entry.name
if entry.isFile()
name = entry.name.replace(/^\./, '') # allow both .civetconfig.civet and civetconfig.civet
if name in ['🐈.json', 'civet.json', 'civetconfig.json']
return path.join dirPath, entry.name
null

export findConfig = (startDir) ->
Expand All @@ -25,19 +25,4 @@ export findConfig = (startDir) ->
null

export loadConfig = (path) ->
config = await fs.readFile path, 'utf8'
if path.endsWith '.json'
JSON.parse config
else
js = compile config, js: true

tmpPath = path + ".civet-tmp-#{Date.now()}.mjs"
await fs.writeFile tmpPath, js
try
exports = await import(pathToFileURL(tmpPath))
finally
await fs.unlink tmpPath
if typeof exports.default isnt 'object' or exports.default is null
throw new Error "civet config file must export an object"
exports.default

JSON.parse await fs.readFile path, 'utf8'