|
| 1 | +import type { CreateNodesV2, NxPlugin, TargetConfiguration } from '@nx/devkit'; |
| 2 | +import * as path from 'node:path'; |
| 3 | + |
| 4 | +const TSCONFIG_LIB_FILE = 'tsconfig.lib.json'; |
| 5 | +const BUILD_TARGET_NAME = 'build'; |
| 6 | + |
| 7 | +export function createBuildTargetConfig(): TargetConfiguration { |
| 8 | + return { |
| 9 | + dependsOn: ['^build'], |
| 10 | + inputs: ['production', '^production'], |
| 11 | + cache: true, |
| 12 | + executor: '@nx/js:tsc', |
| 13 | + outputs: ['{options.outputPath}'], |
| 14 | + options: { |
| 15 | + outputPath: '{projectRoot}/dist', |
| 16 | + main: '{projectRoot}/src/index.ts', |
| 17 | + tsConfig: `{projectRoot}/${TSCONFIG_LIB_FILE}`, |
| 18 | + assets: ['{projectRoot}/*.md'], |
| 19 | + }, |
| 20 | + }; |
| 21 | +} |
| 22 | + |
| 23 | +const createNodesV2: CreateNodesV2 = [ |
| 24 | + `**/${TSCONFIG_LIB_FILE}`, |
| 25 | + async configFilePaths => { |
| 26 | + return Promise.all( |
| 27 | + configFilePaths.map(async configFilePath => { |
| 28 | + const projectRoot = path.dirname(configFilePath); |
| 29 | + const normalizedProjectRoot = projectRoot === '.' ? '' : projectRoot; |
| 30 | + |
| 31 | + return [ |
| 32 | + configFilePath, |
| 33 | + { |
| 34 | + projects: { |
| 35 | + [normalizedProjectRoot]: { |
| 36 | + targets: { |
| 37 | + [BUILD_TARGET_NAME]: createBuildTargetConfig(), |
| 38 | + }, |
| 39 | + }, |
| 40 | + }, |
| 41 | + }, |
| 42 | + ] as const; |
| 43 | + }), |
| 44 | + ); |
| 45 | + }, |
| 46 | +]; |
| 47 | + |
| 48 | +const buildTargetPlugin: NxPlugin = { |
| 49 | + name: 'build-target-nx-plugin', |
| 50 | + createNodesV2, |
| 51 | +}; |
| 52 | + |
| 53 | +export default buildTargetPlugin; |
0 commit comments