-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #140 from alexkorban/watch-elm-json
Watch Elm package files and get the list of watched directories from them
- Loading branch information
Showing
6 changed files
with
176 additions
and
37 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,38 @@ | ||
const path = require('path') | ||
const fs = require('fs') | ||
|
||
const defaultElmDirs = ['**/*.elm'] | ||
|
||
function getSourceDirs(packageFilePath) { | ||
try { | ||
const elmPackage = JSON.parse(fs.readFileSync(packageFilePath)) | ||
const sourceDirs = elmPackage['source-directories'] | ||
if (sourceDirs !== undefined) { | ||
return sourceDirs.map(dir => path.join(dir, '/**/*.elm')) | ||
} | ||
else { | ||
return defaultElmDirs | ||
} | ||
} | ||
catch (e) { | ||
// Do nothing about the exception (in parsing JSON) because the Elm compiler | ||
// will also parse the file and report the error - and elm-live will show it | ||
// to the user. We don't want to report the same error twice. | ||
return defaultElmDirs | ||
} | ||
} | ||
|
||
module.exports = (workPath = process.cwd()) => { | ||
const elmJsonPath = path.join(workPath, 'elm.json') | ||
const elmPackageJsonPath = path.join(workPath, 'elm-package.json') | ||
|
||
if (fs.existsSync(elmJsonPath)) { | ||
return getSourceDirs(elmJsonPath) | ||
} | ||
else if (fs.existsSync(elmPackageJsonPath)) { | ||
return getSourceDirs(elmPackageJsonPath) | ||
} | ||
else { | ||
return defaultElmDirs | ||
} | ||
} |
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,16 @@ | ||
{ | ||
"version": "1.0.0", | ||
"summary": "Project", | ||
"repository": "https://github.com/user/project.git", | ||
"license": "BSD3", | ||
"source-directories": [ | ||
"src18", "../elsewhere18/src" | ||
], | ||
"exposed-modules": [], | ||
"dependencies": { | ||
"elm-lang/core": "5.1.1 <= v < 6.0.0", | ||
"elm-lang/html": "2.0.0 <= v < 3.0.0", | ||
"elm-lang/http": "1.0.0 <= v < 1.1.0" | ||
}, | ||
"elm-version": "0.18.0 <= v < 0.19.0" | ||
} |
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,24 @@ | ||
{ | ||
"type": "application", | ||
"source-directories": [ | ||
"src19", "../../elsewhere19" | ||
], | ||
"elm-version": "0.19.0", | ||
"dependencies": { | ||
"direct": { | ||
"elm/browser": "1.0.0", | ||
"elm/core": "1.0.0", | ||
"elm/html": "1.0.0" | ||
}, | ||
"indirect": { | ||
"elm/json": "1.0.0", | ||
"elm/time": "1.0.0", | ||
"elm/url": "1.0.0", | ||
"elm/virtual-dom": "1.0.2" | ||
} | ||
}, | ||
"test-dependencies": { | ||
"direct": {}, | ||
"indirect": {} | ||
} | ||
} |