application-services
Version:
Out of the box application environment and configuration service.
24 lines • 1.05 kB
JavaScript
import { packageDirectory } from 'package-directory';
import { name, autoService, singleton, location } from 'knifecycle';
import { YError } from 'yerror';
import { noop } from 'common-services';
/**
* Initialize the PROJECT_DIR service
* @param {Object} services
* The services PROJECT_DIR depends on
* @param {Object} [services.log=noop]
* An optional logging service
* @return {Promise<Object>}
* A promise of a an object the actual configuration properties.
*/
async function initProjectDirectory({ log = noop, }) {
const theProjectDirectory = await packageDirectory();
if (theProjectDirectory) {
log('debug', '💡 - Found the project dir:', theProjectDirectory);
return theProjectDirectory;
}
log('error', '❌ - Could not find project directory, are you sure you run the script inside a Node project?');
throw new YError('E_NO_PROJECT_DIR');
}
export default location(singleton(name('PROJECT_DIR', autoService(initProjectDirectory))), import.meta.url);
//# sourceMappingURL=PROJECT_DIR.js.map