<!-- Please make sure you have read the submission guidelines before posting an PR --> <!-- https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr --> <!-- Please make sure that your commit message follows our format --> <!-- Example: `fix(nx): must begin with lowercase` --> <!-- If this is a particularly complex change or feature addition, you can request a dedicated Nx release for this pull request branch. Mention someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they will confirm if the PR warrants its own release for testing purposes, and generate it for you if appropriate. --> ## Current Behavior <!-- This is the behavior we have today --> ## Expected Behavior <!-- This is the behavior we should expect with the changes in this PR --> ## Related Issue(s) <!-- Please link the issue being fixed so it gets closed when this is merged. --> Fixes #
73 lines
1.8 KiB
TypeScript
73 lines
1.8 KiB
TypeScript
import { NormalizedSchema } from './normalize-options';
|
|
import {
|
|
addProjectConfiguration,
|
|
ProjectConfiguration,
|
|
readNxJson,
|
|
Tree,
|
|
} from '@nx/devkit';
|
|
import { addBuildTargetDefaults } from '@nx/devkit/src/generators/target-defaults-utils';
|
|
|
|
export function addProject(host: Tree, options: NormalizedSchema) {
|
|
const targets: Record<string, any> = {};
|
|
|
|
// Check if plugin exists in nx.json and if it doesn't then we can continue
|
|
// with the default targets.
|
|
|
|
const nxJson = readNxJson(host);
|
|
const hasPlugin = nxJson.plugins?.some((p) =>
|
|
typeof p === 'string'
|
|
? p === '@nx/next/plugin'
|
|
: p.plugin === '@nx/next/plugin'
|
|
);
|
|
|
|
if (!hasPlugin) {
|
|
addBuildTargetDefaults(host, '@nx/next:build');
|
|
|
|
targets.build = {
|
|
executor: '@nx/next:build',
|
|
outputs: ['{options.outputPath}'],
|
|
defaultConfiguration: 'production',
|
|
options: {
|
|
outputPath: options.outputPath,
|
|
},
|
|
configurations: {
|
|
development: {
|
|
outputPath: options.appProjectRoot,
|
|
},
|
|
production: {},
|
|
},
|
|
};
|
|
|
|
targets.serve = {
|
|
executor: '@nx/next:server',
|
|
defaultConfiguration: 'development',
|
|
options: {
|
|
buildTarget: `${options.projectName}:build`,
|
|
dev: true,
|
|
},
|
|
configurations: {
|
|
development: {
|
|
buildTarget: `${options.projectName}:build:development`,
|
|
dev: true,
|
|
},
|
|
production: {
|
|
buildTarget: `${options.projectName}:build:production`,
|
|
dev: false,
|
|
},
|
|
},
|
|
};
|
|
}
|
|
|
|
const project: ProjectConfiguration = {
|
|
root: options.appProjectRoot,
|
|
sourceRoot: options.appProjectRoot,
|
|
projectType: 'application',
|
|
targets,
|
|
tags: options.parsedTags,
|
|
};
|
|
|
|
addProjectConfiguration(host, options.projectName, {
|
|
...project,
|
|
});
|
|
}
|