@nx/next
Version:
86 lines (85 loc) • 2.99 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.addProject = addProject;
const devkit_1 = require("@nx/devkit");
const target_defaults_utils_1 = require("@nx/devkit/src/generators/target-defaults-utils");
const versions_1 = require("../../../utils/versions");
const react_1 = require("@nx/react");
function addProject(host, options) {
const targets = {};
// Check if plugin exists in nx.json and if it doesn't then we can continue
// with the default targets.
const nxJson = (0, devkit_1.readNxJson)(host);
const hasPlugin = nxJson.plugins?.some((p) => typeof p === 'string'
? p === '@nx/next/plugin'
: p.plugin === '@nx/next/plugin');
if (!hasPlugin) {
(0, target_defaults_utils_1.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 = {
root: options.appProjectRoot,
sourceRoot: options.appProjectRoot,
projectType: 'application',
targets,
tags: options.parsedTags,
};
const packageJson = {
name: options.importPath,
version: '0.0.1',
private: true,
dependencies: {
next: versions_1.nextVersion,
react: react_1.reactVersion,
'react-dom': react_1.reactDomVersion,
},
};
if (!options.useProjectJson) {
if (options.projectName !== options.importPath) {
packageJson.nx = { name: options.projectName };
}
if (options.parsedTags?.length) {
packageJson.nx ??= {};
packageJson.nx.tags = options.parsedTags;
}
}
else {
(0, devkit_1.addProjectConfiguration)(host, options.projectName, {
...project,
});
}
if (!options.useProjectJson || options.isTsSolutionSetup) {
(0, devkit_1.writeJson)(host, (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'package.json'), packageJson);
}
}