@o3r/schematics
Version:
Schematics module of the Otter framework
66 lines • 2.84 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.BASE_ROOT_FOLDERS_MAP = exports.DEFAULT_ROOT_FOLDERS = exports.APPLICATIONS_FOLDER_NAME = exports.LIBRARIES_FOLDER_NAME = void 0;
exports.findConfigFileRelativePath = findConfigFileRelativePath;
exports.isNxContext = isNxContext;
exports.isMultipackagesContext = isMultipackagesContext;
exports.getPackagesBaseRootFolder = getPackagesBaseRootFolder;
const path = require("node:path");
const collection_1 = require("./collection");
/**
* Find the relative path to a configuration file at the monorepo root
* @param tree
* @param files List of files to look for, the first of the list will be used
* @param originPath Path from where to calculate the relative path
*/
function findConfigFileRelativePath(tree, files, originPath) {
const foundFile = files.find((file) => tree.exists(`/${file}`));
if (foundFile === undefined) {
return '';
}
return path.posix.relative(originPath, `/${foundFile}`);
}
/**
* Determine if we are in an Nx Monorepo context
* @param tree
*/
function isNxContext(tree) {
return tree.exists('/nx.json');
}
/**
* Determine if we are in a project with multi packages
* @param tree
*/
function isMultipackagesContext(tree) {
return !!tree.readJson('/package.json').workspaces;
}
/** Default name of the folder where libraries will be generated inside monorepo */
exports.LIBRARIES_FOLDER_NAME = 'libs';
/** Default name of the folder where applications will be generated inside monorepo */
exports.APPLICATIONS_FOLDER_NAME = 'apps';
/** Default directories for generated apps/libs inside a monorepo */
exports.DEFAULT_ROOT_FOLDERS = {
libsDir: exports.LIBRARIES_FOLDER_NAME,
appsDir: exports.APPLICATIONS_FOLDER_NAME
};
/** Root folders map for apps/libs inside a monorepo */
exports.BASE_ROOT_FOLDERS_MAP = {
library: 'libsDir',
application: 'appsDir'
};
/**
* Retrieve the project base root generation folder, based on the given projectType.
* - The default project root will be returned if there is no project root found in nx.json or angular.json (in schematics options)
* - The root path '/' will be returned if no project type given
* @param tree
* @param context
* @param config
* @param projectType
*/
function getPackagesBaseRootFolder(tree, context, config, projectType) {
const configName = projectType && exports.BASE_ROOT_FOLDERS_MAP[projectType];
const nxExplicitDir = configName && isNxContext(tree) && tree.readJson('/nx.json')?.workspaceLayout[configName];
const schematicConfigDir = configName && (0, collection_1.getSchematicOptions)(config, context)?.[configName];
return schematicConfigDir || nxExplicitDir || ((projectType && configName) ? exports.DEFAULT_ROOT_FOLDERS[configName] : '.');
}
//# sourceMappingURL=monorepo.js.map