@nx/remix
Version:
35 lines (34 loc) • 1.62 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = default_1;
const devkit_1 = require("@nx/devkit");
const artifact_name_and_directory_utils_1 = require("@nx/devkit/src/generators/artifact-name-and-directory-utils");
const remix_route_utils_1 = require("../../utils/remix-route-utils");
const action_impl_1 = require("../action/action.impl");
const loader_impl_1 = require("../loader/loader.impl");
async function default_1(tree, options) {
const { filePath: routeFilePath } = await (0, artifact_name_and_directory_utils_1.determineArtifactNameAndDirectoryOptions)(tree, {
path: options.path.replace(/^\//, '').replace(/\/$/, ''),
allowedFileExtensions: ['ts', 'tsx'],
fileExtension: 'tsx',
});
if (!options.skipChecks && (0, remix_route_utils_1.checkRoutePathForErrors)(options.path)) {
throw new Error(`Your route path has an indicator of an un-escaped dollar sign for a route param. If this was intended, include the --skipChecks flag.`);
}
if (tree.exists(routeFilePath))
throw new Error(`Path already exists: ${options.path}`);
if (!options.loader && !options.action)
throw new Error('The resource route generator requires either `loader` or `action` to be true');
tree.write(routeFilePath, '');
if (options.loader) {
await (0, loader_impl_1.default)(tree, {
path: routeFilePath,
});
}
if (options.action) {
await (0, action_impl_1.default)(tree, {
path: routeFilePath,
});
}
await (0, devkit_1.formatFiles)(tree);
}