@nx/remix
Version:
61 lines (58 loc) • 2.3 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 path_1 = require("path");
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");
const meta_impl_1 = require("../meta/meta.impl");
const style_impl_1 = require("../style/style.impl");
async function default_1(tree, options) {
const { artifactName: name, 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.`);
}
const { className: componentName } = (0, devkit_1.names)(name === '.' || name === '' ? (0, path_1.basename)((0, path_1.dirname)(routeFilePath)) : name);
if (tree.exists(routeFilePath))
throw new Error(`Path already exists: ${routeFilePath}`);
tree.write(routeFilePath, (0, devkit_1.stripIndents) `
export default function ${componentName}() {
${options.loader
? `
return (
<p>
Message: {data.message}
</p>
);
`
: `return (<p>${componentName} works!</p>)`}
}
`);
if (options.loader) {
await (0, loader_impl_1.default)(tree, {
path: routeFilePath,
});
}
if (options.meta) {
await (0, meta_impl_1.default)(tree, {
path: routeFilePath,
});
}
if (options.action) {
await (0, action_impl_1.default)(tree, {
path: routeFilePath,
});
}
if (options.style === 'css') {
await (0, style_impl_1.default)(tree, {
path: routeFilePath,
});
}
await (0, devkit_1.formatFiles)(tree);
}