1 | {join} = require 'path'
|
2 | findProjectRoot = require './findProjectRoot'
|
3 |
|
4 | # Should be an object that exposes:
|
5 | # - Project-relative path helper
|
6 | # - General project-relative loader
|
7 | # - Project-relative Axiom extension loader
|
8 | module.exports = Object.freeze
|
9 |
|
10 | # The root of the project.
|
11 | # Determined relative to the value of process.cwd()
|
12 | # in the calling context of 'makeLoader'.
|
13 | root: findProjectRoot(process.cwd())
|
14 |
|
15 | # Relative path construction helper.
|
16 | # Creates paths prefixed by the value of 'loader.projectRoot'.
|
17 | rel: (args...) ->
|
18 | join(@root, args...)
|
19 |
|
20 | # Calls 'require' on a subpath constructed by prefixing
|
21 | # 'path' with the path to the project root.
|
22 | # Returns 'undefined' if no module was found.
|
23 | retrieve: (args...) ->
|
24 | require @rel(args...)
|
25 |
|
26 | # Require an Axiom extension module with name 'axiom-<name>'
|
27 | # installed in the 'node_modules' folder of the project root.
|
28 | retrieveExtension: (name) ->
|
29 | @retrieve 'node_modules', "axiom-#{name}"
|