project

Access project metadata and paths.

Interface

await this.project.name
await this.project.rootPath
await this.project.config
await this.project.exists

Properties

PropertyDescription
nameProject name from package.json (or 'unknown')
rootPathAbsolute path to project root
configPathPath to package.json
configParsed package.json contents
existsBoolean - valid project found
entryPathMain entry point path
nodePathsArray of node_modules directories

Description

The project service provides access to project metadata from package.json. It walks up the directory tree to find the project root and parses configuration.

Examples

Basic Usage

export default {
    async run() {
        const projectName = await this.project.name;
        console.log(`Project: ${projectName}`);

        if (await this.project.exists) {
            console.log('Valid project detected');
        }
    }
}

Access Package.json

export default {
    async run() {
        const config = await this.project.config;

        console.log(`Version: ${config.version}`);
        console.log(`Description: ${config.description}`);
    }
}

Database Naming

export default {
    async normalizeDatabaseConfig(config) {
        const environment = process.env.NODE_ENV || 'development';

        return {
            ...config,
            database: `${this.inflector.snakeify(await this.project.name)}_${environment}`
        };
    }
}

Version Service

export default {
    create() {
        return this.defer(async () => {
            let version = await this.project.config.version || '0.1.0';

            if (await this.environment === 'development') {
                version += `.${Date.now()}`;
            }

            return version;
        });
    }
}

Notes

  • Uses deferred initialization (requires await)
  • Returns 'unknown' for name when not found
  • All paths are absolute and resolved
  • Singleton instance shared across application